View Javadoc

1   /*
2    * #%L
3    * Bitrepository Webclient
4    * %%
5    * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 2.1 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
20   * #L%
21   */
22  package org.bitrepository;
23  
24  import org.bitrepository.common.settings.Settings;
25  import org.bitrepository.protocol.messagebus.MessageBusManager;
26  import org.bitrepository.settings.repositorysettings.Collection;
27  import org.bitrepository.settings.repositorysettings.RepositorySettings;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  import javax.jms.JMSException;
32  import java.util.ArrayList;
33  import java.util.List;
34  
35  public class BasicClient {
36      private Settings settings;
37      private final Logger log = LoggerFactory.getLogger(getClass());
38  
39      public BasicClient(Settings settings) {
40          log.debug("---- Basic client instantiating ----");
41          this.settings = settings;
42          log.debug("---- Basic client instantiated ----");
43  
44      }
45      
46      public List<String> getCollectionIDs() {
47          List<String> collections = new ArrayList<String>();
48          for(Collection collection : settings.getRepositorySettings().getCollections().getCollection()) {
49              collections.add(collection.getID());
50          }
51          return collections;
52      }
53  
54      public void shutdown() {
55          try {
56              MessageBusManager.getMessageBus().close();
57          } catch (JMSException e) {
58              log.warn("Failed to shutdown message bus cleanly, " + e.getMessage());
59          }
60      }
61  
62      public String getSettingsSummary() {
63          StringBuilder sb = new StringBuilder();
64          RepositorySettings repositorySettings = settings.getRepositorySettings();
65          sb.append("Collections:<br>");
66          for (Collection collection: settings.getCollections()) {
67              sb.append("<i>ID:" + collection.getID());
68              sb.append("<i>Pillars:");
69              for (String pillarID: collection.getPillarIDs().getPillarID()) {
70                  sb.append("&nbsp; " + pillarID);
71              }
72          }
73          sb.append("</i><br>");
74          sb.append("</i>");
75          sb.append("Messagebus URL: <br> &nbsp;&nbsp;&nbsp; <i>"); 
76          sb.append(repositorySettings.getProtocolSettings().getMessageBusConfiguration().getURL() + "</i><br>");
77          return sb.toString();
78      }
79      
80      public Settings getSettings() {
81          return settings;
82      }
83  }