View Javadoc

1   /*
2    * #%L
3    * Bitrepository Access
4    * 
5    * $Id$
6    * $HeadURL$
7    * %%
8    * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark
9    * %%
10   * This program is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU Lesser General Public License as 
12   * published by the Free Software Foundation, either version 2.1 of the 
13   * License, or (at your option) any later version.
14   * 
15   * This program is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   * GNU General Lesser Public License for more details.
19   * 
20   * You should have received a copy of the GNU General Lesser Public 
21   * License along with this program.  If not, see
22   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
23   * #L%
24   */
25  package org.bitrepository.access.getfileids;
26  
27  import org.bitrepository.access.ContributorQuery;
28  import org.bitrepository.access.ContributorQueryUtils;
29  import org.bitrepository.access.getfileids.conversation.GetFileIDsConversationContext;
30  import org.bitrepository.access.getfileids.conversation.IdentifyPillarsForGetFileIDs;
31  import org.bitrepository.client.AbstractClient;
32  import org.bitrepository.client.conversation.mediator.ConversationMediator;
33  import org.bitrepository.client.eventhandler.EventHandler;
34  import org.bitrepository.common.ArgumentValidator;
35  import org.bitrepository.common.settings.Settings;
36  import org.bitrepository.common.utils.SettingsUtils;
37  import org.bitrepository.protocol.messagebus.MessageBus;
38  import org.slf4j.Logger;
39  import org.slf4j.LoggerFactory;
40  
41  import java.net.URL;
42  import java.util.Arrays;
43  
44  /**
45   * The reference implementation of the client side of the GetFileIDs identification and operation.
46   * The default <code>GetFileIDsClient</code>
47   *
48   * This class is just a thin wrapper which creates a conversion each time a operation is started. The conversations 
49   * takes over the rest of the operation handling.
50   */
51  public class ConversationBasedGetFileIDsClient extends AbstractClient implements GetFileIDsClient {
52      private final Logger log = LoggerFactory.getLogger(getClass());
53  
54      /**
55       * @see AbstractClient
56       */
57      public ConversationBasedGetFileIDsClient(MessageBus messageBus, ConversationMediator conversationMediator,
58                                               Settings settings, String clientID) {
59          super(settings, conversationMediator, messageBus, clientID);
60      }
61  
62      @Override
63      public void getFileIDs(
64              String collectionID,
65              ContributorQuery[] contributorQueries,
66              String fileID,
67              URL addressForResult,
68              EventHandler eventHandler) {
69          ArgumentValidator.checkNotNullOrEmpty(collectionID, "collectionID");
70          validateFileID(fileID);
71          if (contributorQueries == null) {
72              contributorQueries = ContributorQueryUtils.createFullContributorQuery(
73                      SettingsUtils.getPillarIDsForCollection(collectionID));
74          }
75  
76          log.info("Requesting the fileIDs for file '" + fileID + "' with query "+
77                  Arrays.asList(contributorQueries) + ". " +
78                  (addressForResult != null ?  "The result should be uploaded to '" + addressForResult + "'." : ""));
79  
80          GetFileIDsConversationContext context = new GetFileIDsConversationContext(
81                  collectionID, contributorQueries, fileID, addressForResult, settings, messageBus, clientID,
82                  ContributorQueryUtils.getContributors(contributorQueries), eventHandler);
83  
84          startConversation(context, new IdentifyPillarsForGetFileIDs(context));
85      }
86  }