[15222] | 1 | /**
|
---|
| 2 | *#########################################################################
|
---|
| 3 | * GS3ServicesAPIA.java - part of the demo-client for Greenstone 3, of the
|
---|
| 4 | * Greenstone digital library suite from the New Zealand Digital Library
|
---|
| 5 | * Project at the * University of Waikato, New Zealand.
|
---|
| 6 | * <BR><BR>
|
---|
| 7 | * Copyright (C) 2008 New Zealand Digital Library Project
|
---|
| 8 | * <BR><BR>
|
---|
| 9 | * This program is free software; you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | * <BR><BR>
|
---|
| 14 | * This program is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *########################################################################
|
---|
| 19 | */
|
---|
| 20 |
|
---|
| 21 | package org.greenstone.gs3client.dlservices;
|
---|
| 22 |
|
---|
| 23 | import javax.swing.JOptionPane;
|
---|
| 24 |
|
---|
| 25 | import java.util.HashMap;
|
---|
| 26 | import java.util.Map;
|
---|
| 27 |
|
---|
| 28 | import java.io.IOException;
|
---|
| 29 | import java.net.MalformedURLException;
|
---|
| 30 | import javax.xml.parsers.ParserConfigurationException;
|
---|
| 31 | import javax.xml.rpc.ServiceException;
|
---|
| 32 | import org.xml.sax.SAXException;
|
---|
| 33 |
|
---|
| 34 | import org.greenstone.gs3client.data.DocumentNodeData;
|
---|
| 35 |
|
---|
| 36 | import org.apache.log4j.Logger; //Import log4j classes
|
---|
| 37 | import java.util.Properties;
|
---|
| 38 |
|
---|
| 39 | /**
|
---|
| 40 | * GS3ServicesAPIA does two things:
|
---|
| 41 | * - it implements DigitalLibraryServicesAPIA for enabling the Java-client
|
---|
| 42 | * to access Greenstone's repository of collections and documents. It
|
---|
| 43 | * makes this possible through use of Greenstone 3's web services.
|
---|
| 44 | * - it inherits from GS3WebServicesQBRAPI, which means it inherits all the
|
---|
| 45 | * methods that deal with invoking the Greenstone 3 web services
|
---|
| 46 | * functionality (through use of Apache Axis' Service and Call objects).
|
---|
| 47 | * It therefore provides an equivalent method to each Greenstone 3 web
|
---|
| 48 | * service operation, even if some of these web service operations are
|
---|
| 49 | * never called by the Java-client and therefore not prescribed by the
|
---|
| 50 | * DigitalLibraryServicesAPIA interface.
|
---|
| 51 | * @author ak19
|
---|
| 52 | */
|
---|
| 53 | public class GS3ServicesAPIA extends GS3WebServicesQBRAPI
|
---|
| 54 | implements DigitalLibraryServicesAPIA
|
---|
| 55 | {
|
---|
| 56 | /** The Logger for this class */
|
---|
| 57 | static Logger LOG = Logger.getLogger(GS3ServicesAPIA.class);
|
---|
| 58 |
|
---|
| 59 | /** Storing language settings for requests and responses*/
|
---|
| 60 | protected String language;
|
---|
| 61 |
|
---|
| 62 | /** Displays a dialog to get user input for the location of the Greenstone 3
|
---|
| 63 | * web services' WSDL file */
|
---|
| 64 | public GS3ServicesAPIA()
|
---|
| 65 | throws ServiceException, MalformedURLException,
|
---|
| 66 | ParserConfigurationException, IOException, Exception
|
---|
| 67 | {
|
---|
| 68 | this(showWsdlInputDialog());
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | /** GS3ServicesAPIA constructor, which, given the url to the wsdl file,
|
---|
| 72 | * finds either service and port or the service's endpoint of the GS3 Web
|
---|
| 73 | * Services and instantiates the associated Service and Call objects.
|
---|
| 74 | * @param wsdlURLName - location of the WSDL for Greenstone 3's
|
---|
| 75 | * web services */
|
---|
| 76 | public GS3ServicesAPIA(String wsdlURLName)
|
---|
| 77 | throws ServiceException, MalformedURLException,
|
---|
| 78 | ParserConfigurationException, IOException, SAXException
|
---|
| 79 | {
|
---|
| 80 | super(wsdlURLName);
|
---|
| 81 | // Very important to initialise member language to some value, in
|
---|
| 82 | // this case, it is set to "" (which Greenstone takes as English).
|
---|
| 83 | this.language = "";
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /** Static method that displays a dialog requesting the user to
|
---|
| 87 | * input the location of Greenstone 3 web services' WSDL file.
|
---|
| 88 | * @return a String representing the URL location of Greenstone 3 web
|
---|
| 89 | * services' WSDL file */
|
---|
| 90 | public static String showWsdlInputDialog()
|
---|
| 91 | throws Exception
|
---|
| 92 | {
|
---|
| 93 | String wsdlURL = "";
|
---|
| 94 | Properties properties = new Properties();
|
---|
| 95 |
|
---|
| 96 | // set default values from any properties file
|
---|
| 97 | try {
|
---|
| 98 | if(DigitalLibraryServicesAPIA.propertiesFile.exists()) {
|
---|
| 99 | properties.load(new java.io.FileInputStream(
|
---|
| 100 | DigitalLibraryServicesAPIA.propertiesFile));
|
---|
| 101 | }
|
---|
| 102 | } catch(Exception e) {
|
---|
| 103 | LOG.warn("Exception loading properties from file "
|
---|
| 104 | + DigitalLibraryServicesAPIA.propertiesFile
|
---|
| 105 | + ": " + e);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | // Show the dialog and get input for the wsdlURL property
|
---|
| 109 | // It will display GS3WebServicesQBRAPI.defaultWsdlURL in the input
|
---|
| 110 | // field if it can not find a wsdlURL property in the propertiesFile
|
---|
| 111 | wsdlURL = JOptionPane.showInputDialog(
|
---|
| 112 | "Please enter the URL for the GS3 Web Services wsdl file",
|
---|
| 113 | properties.getProperty("wsdlURL", GS3WebServicesQBRAPI.defaultWsdlURL)
|
---|
| 114 | );
|
---|
| 115 | if(wsdlURL == null) { // cancel pressed
|
---|
| 116 | throw new CancelException(
|
---|
| 117 | "User cancelled out of connecting to GS3 Web Services");
|
---|
| 118 | } else { // if ok clicked, update properties with the input value
|
---|
| 119 | properties.setProperty("wsdlURL", wsdlURL);
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | // Store the user-entered URL for future use, so it is loaded next time
|
---|
| 123 | try {
|
---|
| 124 | java.io.FileOutputStream out = new java.io.FileOutputStream(
|
---|
| 125 | DigitalLibraryServicesAPIA.propertiesFile);
|
---|
| 126 | properties.store(out, "GS3ServicesAPIA");
|
---|
| 127 | out.close();
|
---|
| 128 | } catch(Exception e) {
|
---|
| 129 | LOG.warn("Exception writing properties to file "
|
---|
| 130 | + DigitalLibraryServicesAPIA.propertiesFile
|
---|
| 131 | + ": " + e);
|
---|
| 132 | }
|
---|
| 133 | return wsdlURL;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | //************DigitalLibraryServicesAPIA METHOD IMPLEMENTATIONS************//
|
---|
| 137 | /** @return the name of this digital library for displaying in the client */
|
---|
| 138 | public String getDisplayName() {
|
---|
| 139 | return "Greenstone3";
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 143 | * contract.
|
---|
| 144 | * Sets the preferred language (code) for metadata and other content to be
|
---|
| 145 | * returned on request messages. If the preferred language is not available,
|
---|
| 146 | * the implementation may choose to send English back instead, or failing
|
---|
| 147 | * that, send the data in any other available language.
|
---|
| 148 | * @param language has to be a language code as recognised by Greenstone3
|
---|
| 149 | * (the language codes used by W3C probably). E.g. "en" for English. */
|
---|
| 150 | public void setLanguage(String language) { this.language = language; }
|
---|
| 151 |
|
---|
| 152 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 153 | * contract.
|
---|
| 154 | * Gets the language that's set as the preferred language.
|
---|
| 155 | * @return the language code as recognised by Greenstone3 (which are the
|
---|
| 156 | * language codes used by W3C probably). E.g. "en" for English. */
|
---|
| 157 | public String getLanguage() { return language; }
|
---|
| 158 |
|
---|
| 159 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 160 | * contract.
|
---|
| 161 | * @return the overall directory path for associated files (not including
|
---|
| 162 | * the document's nodeID/pid). This can be used to *formulate* the base url
|
---|
| 163 | * of JEditorPane's HTML documents. If the documents from any digital library
|
---|
| 164 | * do not contain relative paths, or otherwise deal with the resolution of
|
---|
| 165 | * relative urls themselves, then return "" from here. */
|
---|
| 166 | public String getAssocFileBaseURL() { return ""; }
|
---|
| 167 |
|
---|
| 168 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 169 | * contract.
|
---|
| 170 | * @return the directory path to the associated files of the given document
|
---|
| 171 | * node. For instance, the base url of a JEditorPane's HTML documents can be
|
---|
| 172 | * set to this. */
|
---|
| 173 | public String getAssocFileBaseURL(DocumentNodeData docNode) {
|
---|
| 174 | return "_httpdocimg_/"; // for now.
|
---|
| 175 | // TODO:
|
---|
| 176 | /*DocumentNodeData root = docNode.getRoot();
|
---|
| 177 | if(root != null)
|
---|
| 178 | return root.getAssocFilePath();
|
---|
| 179 | else return "";*/
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 183 | * contract
|
---|
| 184 | * @return Greenstone3 XML describe response message originating from
|
---|
| 185 | * the Message Router, describing the Collections, ServiceRacks
|
---|
| 186 | * and Services supported by the Message Router for all collections. */
|
---|
| 187 | public String describe() {
|
---|
| 188 | return this.describe(language, "");
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 192 | * contract.
|
---|
| 193 | * @param collection is the name of the collection to be described.
|
---|
| 194 | * @return Greenstone3 XML describe response message originating from a
|
---|
| 195 | * collection, describing the collection (display items) as well as
|
---|
| 196 | * listing any services supported specifically by the collection.
|
---|
| 197 | */
|
---|
| 198 | public String describeCollection(String collection) {
|
---|
| 199 | return this.describeCollection(collection, language, "");
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 203 | * contract.
|
---|
| 204 | * @param collection is the name of the collection to be described.
|
---|
| 205 | * @param service is the name of the collection's service to be described.
|
---|
| 206 | * @return Greenstone3 XML describe response message originating from a
|
---|
| 207 | * collection's service, describing the service (display items).
|
---|
| 208 | */
|
---|
| 209 | public String describeCollectionService(String collection, String service) {
|
---|
| 210 | return this.describeCollectionService(collection, service, language, "");
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 214 | * contract.
|
---|
| 215 | * @param service is the name of the collection's service to be described.
|
---|
| 216 | * @return Greenstone3 XML describe response message originating from a
|
---|
| 217 | * general (non-collection specific) service, describing the requested
|
---|
| 218 | * service (for example with GS3 display items).
|
---|
| 219 | */
|
---|
| 220 | public String describeService(String service) {
|
---|
| 221 | return this.describeService(service, language, "");
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 225 | * contract.
|
---|
| 226 | * @param collection is the name of the collection.
|
---|
| 227 | * @param docIDs is an array of document identifiers of documents whose (text)
|
---|
| 228 | * contents are requested.
|
---|
| 229 | * @return a String representing Greenstone3 DocumentContentRetrieve XML
|
---|
| 230 | * containing the document contents of the documents indicated by docIDs
|
---|
| 231 | */
|
---|
| 232 | public String retrieveDocumentContent(String collection, String[] docIDs) {
|
---|
| 233 | return this.retrieveDocumentContent(collection, language, docIDs);
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 237 | * contract.
|
---|
| 238 | * @param collection is the name of the collection.
|
---|
| 239 | * @param docID is the document identifier of the document whose (text)
|
---|
| 240 | * content is requested.
|
---|
| 241 | * @return a String representing Greenstone3 DocumentContentRetrieve XML
|
---|
| 242 | * containing the document contents of the document indicated by docID
|
---|
| 243 | */
|
---|
| 244 | public String retrieveDocumentContent(String collection, String docID) {
|
---|
| 245 | return this.retrieveDocumentContent(collection, language,
|
---|
| 246 | new String[]{ docID });
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 250 | * contract.
|
---|
| 251 | * @param collection is the name of the collection.
|
---|
| 252 | * @param docIDs is an array of document identifiers of documents whose
|
---|
| 253 | * metadata is requested.
|
---|
| 254 | * @return a String representing Greenstone3 DocumentMetadataRetrieve XML
|
---|
| 255 | * containing all the metadata of all the documents indicated by docIDs
|
---|
| 256 | */
|
---|
| 257 | public String retrieveDocumentMetadata(String collection, String[] docIDs) {
|
---|
| 258 | return this.retrieveAllDocumentMetadata(collection, language, docIDs);
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 262 | * contract.
|
---|
| 263 | * @param collection is the name of the collection.
|
---|
| 264 | * @param docID is the document identifier of the document whose metadata is
|
---|
| 265 | * requested.
|
---|
| 266 | * @return a String representing Greenstone3 DocumentMetadataRetrieve XML
|
---|
| 267 | * containing all the metadata of the document denoted by docID
|
---|
| 268 | */
|
---|
| 269 | public String retrieveDocumentMetadata(String collection, String docID) {
|
---|
| 270 | return this.retrieveAllDocumentMetadata(collection, language,
|
---|
| 271 | new String[] { docID });
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 275 | * contract.
|
---|
| 276 | * @param collection is the name of the collection.
|
---|
| 277 | * @param docIDs is an array of document identifiers of documents whose titles
|
---|
| 278 | * are requested
|
---|
| 279 | * @return a String representing Greenstone3 DocumentMetadataRetrieve XML
|
---|
| 280 | * containing only the title metadata of the documents denoted by docIDs
|
---|
| 281 | */
|
---|
| 282 | public String retrieveTitleMetadata(String collection, String[] docIDs) {
|
---|
| 283 | final String[] titleMetaName = {"Title"};
|
---|
| 284 | return this.retrieveDocumentMetadata(collection, language, docIDs,
|
---|
| 285 | titleMetaName);
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 289 | * contract.
|
---|
| 290 | * @return a String representing Greenstone3 DocumentMetadataRetrieve XML
|
---|
| 291 | * containing only the title metadata of the document denoted by docID
|
---|
| 292 | * @param collection is the name of the collection
|
---|
| 293 | * @param docID is the document identifier of the document whose titles is
|
---|
| 294 | * requested */
|
---|
| 295 | public String retrieveTitleMetadata(String collection, String docID) {
|
---|
| 296 | final String[] titleMetaName = {"Title"};
|
---|
| 297 | return this.retrieveDocumentMetadata(collection, language,
|
---|
| 298 | new String[] { docID }, titleMetaName);
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 302 | * contract.
|
---|
| 303 | * @return a String representing Greenstone3 DocumentMetadataRetrieve XML
|
---|
| 304 | * containing the document structure of the documents indicated by docIDs:
|
---|
| 305 | * this means all their descendants
|
---|
| 306 | * @param collection is the name of the collection
|
---|
| 307 | * @param docIDs is an array of document identifiers of documents whose
|
---|
| 308 | * hierarchical structures are requested */
|
---|
| 309 | public String retrieveDocumentStructure(String collection, String[] docIDs) {
|
---|
| 310 | return this.retrieveEntireDocumentStructure(collection, language, docIDs);
|
---|
| 311 | }
|
---|
| 312 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 313 | * contract.
|
---|
| 314 | * @return a String representing Greenstone3 DocumentMetadataRetrieve XML
|
---|
| 315 | * containing the document structure of the document indicated by docID:
|
---|
| 316 | * this means all its descendants
|
---|
| 317 | * @param collection is the name of the collection
|
---|
| 318 | * @param docID is the document identifier of the document whose hierarchical
|
---|
| 319 | * structure is requested*/
|
---|
| 320 | public String retrieveDocumentStructure(String collection, String docID) {
|
---|
| 321 | return this.retrieveEntireDocumentStructure(collection, language,
|
---|
| 322 | new String[] { docID });
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 326 | * contract.
|
---|
| 327 | * @return a String representing Greenstone3 DocumentMetadataRetrieve XML
|
---|
| 328 | * containing a view of the document structure of the documents denoted by
|
---|
| 329 | * docs where only the requested documents and their direct children are
|
---|
| 330 | * returned.
|
---|
| 331 | * @param collection is the name of the collection
|
---|
| 332 | * @param docIDs is an array of document identifiers of documents whose
|
---|
| 333 | * hierarchical structures are requested */
|
---|
| 334 | public String retrieveDocumentChildren(String collection, String[] docIDs) {
|
---|
| 335 | return this.retrieveDocumentStructure(collection, collection, docIDs,
|
---|
| 336 | new String[] { "children" }, null);
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 340 | * contract.
|
---|
| 341 | * @return a String representing Greenstone3 DocumentMetadataRetrieve XML
|
---|
| 342 | * containing a view of the document structure of the document denoted by
|
---|
| 343 | * docID where only the document and its direct children are returned.
|
---|
| 344 | * @param collection is the name of the collection
|
---|
| 345 | * @param docID is the document identifier of the document whose hierarchical
|
---|
| 346 | * structure is requested */
|
---|
| 347 | public String retrieveDocumentChildren(String collection, String docID) {
|
---|
| 348 | return this.retrieveDocumentStructure(collection, collection,
|
---|
| 349 | new String[] { docID }, new String[] { "children" }, null);
|
---|
| 350 | }
|
---|
| 351 |
|
---|
| 352 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 353 | * contract.
|
---|
| 354 | * @return a String representing Greenstone3 ClassifierBrowse XML
|
---|
| 355 | * giving the entire *structure* of the classification denoted by
|
---|
| 356 | * classifierID (including the structures of document descendants of
|
---|
| 357 | * the classifier).
|
---|
| 358 | * @param classifierID is of the form CL# where the number (#) marks
|
---|
| 359 | * out structured sections like CL1.1.3 or CL2
|
---|
| 360 | * @param collection is the name of the collection
|
---|
| 361 | * @param service is the name of the browse service (=ClassifierBrowse usually)
|
---|
| 362 | */
|
---|
| 363 | public String retrieveBrowseStructure(
|
---|
| 364 | String collection, String service, String classifierID)
|
---|
| 365 | {
|
---|
| 366 | String[] classifierIDs = { classifierID };
|
---|
| 367 | return this.browseDescendants(collection, service,
|
---|
| 368 | language, classifierIDs );
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 372 | * contract.
|
---|
| 373 | * @return a String representing Greenstone3
|
---|
| 374 | * ClassifierBrowseMetadataRetrieve XML giving all the metadata for
|
---|
| 375 | * all the subclassifiers denoted by nodeIDs.
|
---|
| 376 | * @param nodeIDs is of the form CL#.# where the number (#) marks
|
---|
| 377 | * out structured sections like CL2.1.3. NodeIDs are generally subsections
|
---|
| 378 | * of top-level classifierNodes (CL#, e.g. CL3).
|
---|
| 379 | * @param collection is the name of the collection
|
---|
| 380 | * @param service is the name of the Browse's MetadataRetrieve service
|
---|
| 381 | * (usually the browse service is ClassifierBrowse, in which case it always
|
---|
| 382 | * has a retrieve service called ClassifierBrowseMetadataRetrieve) */
|
---|
| 383 | public String retrieveBrowseMetadata(
|
---|
| 384 | String collection, String service, String[] nodeIDs)
|
---|
| 385 | {
|
---|
| 386 | return this.retrieveAllBrowseMetadata(collection, service,
|
---|
| 387 | language, nodeIDs);
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 | /** Part of the GS3 Java-Client's DigitalLibraryServicesAPIA interface
|
---|
| 391 | * contract.
|
---|
| 392 | * @return a String representing Greenstone3 XML for a query process
|
---|
| 393 | * response returning the results for the query denoted by parameter
|
---|
| 394 | * nameValParamsMap.
|
---|
| 395 | * @param nameValParamsMap is a Map of name and value pairs for all the
|
---|
| 396 | * query field data values. The names match the field names that
|
---|
| 397 | * describeCollectionService() would have returned for the query service.
|
---|
| 398 | * @param collection is the name of the collection
|
---|
| 399 | * @param service is the name of the query service
|
---|
| 400 | */
|
---|
| 401 | public String query(String collection, String service, Map nameValParamsMap)
|
---|
| 402 | {
|
---|
| 403 | return this.query(collection, service, language, nameValParamsMap);
|
---|
| 404 | }
|
---|
| 405 |
|
---|
| 406 | /*public static void main(String args[]) {
|
---|
| 407 | try{
|
---|
| 408 | GS3ServicesAPIA ws = new GS3ServicesAPIA();
|
---|
| 409 |
|
---|
| 410 | // (1) trying 4 describe methods
|
---|
| 411 | System.out.println(ws.describe("", ""));
|
---|
| 412 | System.out.println(ws.describeCollectionOrServiceRack("gs2mgppdemo", "", ""));
|
---|
| 413 | System.out.println(ws.describeCollectionService("gs2mgppdemo", "AdvancedFieldQuery", "", ""));
|
---|
| 414 | System.out.println(ws.describeService("AddItem", "", ""));
|
---|
| 415 |
|
---|
| 416 |
|
---|
| 417 | // (2) try 3 query methods (simplerFieldQuery twice) + getFieldNameMappings()
|
---|
| 418 | Map map = new HashMap();
|
---|
| 419 | map.put("maxDocs", "100");
|
---|
| 420 | map.put("level", "Sec");
|
---|
| 421 | map.put("accent", "1");
|
---|
| 422 | map.put("matchMode", "some");
|
---|
| 423 | map.put("fqf", "ZZ,ZZ,ZZ,ZZ");
|
---|
| 424 | map.put("case", "1");
|
---|
| 425 | map.put("sortBy", "1");
|
---|
| 426 | map.put("fqv", "snail,water,,");
|
---|
| 427 |
|
---|
| 428 | String response = ws.query("gs2mgppdemo", "FieldQuery", "", map);
|
---|
| 429 | System.out.println("Regular query: " + response);
|
---|
| 430 |
|
---|
| 431 | System.out.println("Field mappings: " + ws.getFieldNameMappings());
|
---|
| 432 | response = ws.simplerFieldNameQuery(
|
---|
| 433 | "gs2mgppdemo", "FieldQuery", "", map);
|
---|
| 434 | System.out.println("response:\n" + response);
|
---|
| 435 |
|
---|
| 436 | // trying the same with special field names
|
---|
| 437 | map.clear();
|
---|
| 438 |
|
---|
| 439 | map.put("maxDocs", "100");
|
---|
| 440 | map.put("level", "Sec");
|
---|
| 441 | map.put("accent", "on");
|
---|
| 442 | map.put("matchMode", "some");
|
---|
| 443 | map.put("fields", "all fields,all fields,all fields,all fields");
|
---|
| 444 | map.put("case", "on");
|
---|
| 445 | map.put("sortBy", "on");
|
---|
| 446 | map.put("values", "snail,water,,");
|
---|
| 447 |
|
---|
| 448 | response = ws.simplerFieldNameQuery(
|
---|
| 449 | "gs2mgppdemo", "FieldQuery", "", map);
|
---|
| 450 | System.out.println("response:\n" + response);
|
---|
| 451 |
|
---|
| 452 | // trying query - array version
|
---|
| 453 | String[] names = {"maxDocs", "level", "accent", "matchMode", "fqf",
|
---|
| 454 | "case", "sortBy", "fqv"};
|
---|
| 455 | String[] values = {"100", "Sec", "1", "some", "ZZ,ZZ,ZZ,ZZ",
|
---|
| 456 | "1", "1", "snail,water,,"};
|
---|
| 457 | System.out.println(ws.query("gs2mgppdemo", "FieldQuery", "", names, values));
|
---|
| 458 |
|
---|
| 459 |
|
---|
| 460 | // (3) try 2 browse
|
---|
| 461 | System.out.println("describe browse:\n"
|
---|
| 462 | + ws.describeCollectionService("gs2mgppdemo", "ClassifierBrowse", "", ""));
|
---|
| 463 |
|
---|
| 464 | System.out.println("browse children of CL1-CL4:\n" +
|
---|
| 465 | ws.browse("gs2mgppdemo", "ClassifierBrowse", "",
|
---|
| 466 | new String[]{"CL1", "CL2", "CL3", "CL4"}, new String[]{"children"}));
|
---|
| 467 |
|
---|
| 468 | System.out.println("browse descendants of CL2.3:\n" +
|
---|
| 469 | ws.browseDescendants("gs2mgppdemo", "ClassifierBrowse", "",
|
---|
| 470 | new String[]{"CL2.3"}));
|
---|
| 471 |
|
---|
| 472 |
|
---|
| 473 | // (4) try 2 DocStructure
|
---|
| 474 | System.out.println("retrieve ancestors and children structure of HASH016193b2847874f3c956d22e.4:\n" +
|
---|
| 475 | ws.retrieveDocumentStructure("gs2mgppdemo", "",
|
---|
| 476 | new String[]{"HASH016193b2847874f3c956d22e.4"},
|
---|
| 477 | new String[]{"ancestors", "children"}, new String[]{"numSiblings"}));
|
---|
| 478 |
|
---|
| 479 |
|
---|
| 480 | System.out.println("retrieve entire structure of HASH016193b2847874f3c956d22e.4.1:\n" +
|
---|
| 481 | ws.retrieveEntireDocumentStructure(
|
---|
| 482 | "gs2mgppdemo", "", new String[]{"HASH016193b2847874f3c956d22e.4.1"}));
|
---|
| 483 |
|
---|
| 484 |
|
---|
| 485 | // (5) try the 1 DocumentContent retrieve
|
---|
| 486 | System.out.println("retrieve content of HASH016193b2847874f3c956d22e.4:\n" +
|
---|
| 487 | ws.retrieveDocumentContent("gs2mgppdemo", "",
|
---|
| 488 | new String[]{"HASH016193b2847874f3c956d22e.4", "HASH016193b2847874f3c956d22e.4.1",
|
---|
| 489 | "HASH016193b2847874f3c956d22e.4.2"}));
|
---|
| 490 |
|
---|
| 491 |
|
---|
| 492 | // (6) try 2 DocumentMeta
|
---|
| 493 | System.out.println("retrieve title meta of HASH016193b2847874f3c956d22e.4 children:\n" +
|
---|
| 494 | ws.retrieveDocumentMetadata("gs2mgppdemo", "",
|
---|
| 495 | new String[]{"HASH016193b2847874f3c956d22e.4.1", "HASH016193b2847874f3c956d22e.4.2",
|
---|
| 496 | "HASH016193b2847874f3c956d22e.4.3"}, new String[]{"Title"}));
|
---|
| 497 |
|
---|
| 498 | System.out.println("retrieve all meta of HASH016193b2847874f3c956d22e.4 children:\n" +
|
---|
| 499 | ws.retrieveAllDocumentMetadata("gs2mgppdemo", "",
|
---|
| 500 | new String[]{"HASH016193b2847874f3c956d22e.4",
|
---|
| 501 | "HASH016193b2847874f3c956d22e.4.1", "HASH016193b2847874f3c956d22e.4.2",
|
---|
| 502 | "HASH016193b2847874f3c956d22e.4.3"}));
|
---|
| 503 |
|
---|
| 504 | // (7) try 2 BrowseMeta
|
---|
| 505 | System.out.println("retrieve all browse meta of CL1, CL2, CL2.1, CL3:\n" +
|
---|
| 506 | ws.retrieveAllBrowseMetadata("gs2mgppdemo", "", "",
|
---|
| 507 | new String[]{"CL1", "CL2",
|
---|
| 508 | "CL2.1", "CL3"}));
|
---|
| 509 |
|
---|
| 510 | System.out.println("retrieve Title, hastxt browse meta of CL1, CL2, CL2.1, CL3:\n" +
|
---|
| 511 | ws.retrieveBrowseMetadata("gs2mgppdemo", "", "",
|
---|
| 512 | new String[]{"CL1", "CL2","CL2.1", "CL3"}, new String[]{"Title", "hastxt"}));
|
---|
| 513 |
|
---|
| 514 | // (8) try process:
|
---|
| 515 | String requestXMLMessage = "<message>"
|
---|
| 516 | + "<request lang='' to='gs2mgppdemo/ClassifierBrowseMetadataRetrieve' type='process' uid=''>"
|
---|
| 517 | + "<paramList>" + "<param name='metadata' value='Title' />"
|
---|
| 518 | + "<param name='metadata' value='hastxt' /></paramList>"
|
---|
| 519 | + "<classifierNodeList><classifierNode nodeID='CL1' /><classifierNode nodeID='CL2' />"
|
---|
| 520 | + "<classifierNode nodeID='CL2.1' /><classifierNode nodeID='CL3' /></classifierNodeList>"
|
---|
| 521 | + "</request></message>";
|
---|
| 522 | System.out.println(ws.process(requestXMLMessage));
|
---|
| 523 |
|
---|
| 524 |
|
---|
| 525 | // (9) activate, deactivate and the 2 reconfigures
|
---|
| 526 | System.out.println("activate:\n" + ws.activate("collection", "gs2mgppdemo"));
|
---|
| 527 | System.out.println("deactivate:\n" + ws.deactivate("site", "site1"));
|
---|
| 528 | System.out.println("configure MR:\n" + ws.reconfigure());
|
---|
| 529 | System.out.println("configure:\n" + ws.reconfigure("collectionList"));
|
---|
| 530 |
|
---|
| 531 | // (10) 1 format
|
---|
| 532 | System.out.println("format:\n" + ws.format("gs2mgppdemo", "FieldQuery", ""));
|
---|
| 533 |
|
---|
| 534 | // (11) 2 processType: build/NewCollection, build/ImportCollection
|
---|
| 535 | System.out.println("describe build/NewCollection:\n"
|
---|
| 536 | + ws.describeService("build/NewCollection", "", ""));
|
---|
| 537 |
|
---|
| 538 | Map params = new HashMap(10);
|
---|
| 539 | params.put("creator", "me@home");
|
---|
| 540 | params.put("collName", "the demo collection");
|
---|
| 541 | params.put("collShortName", "demo");
|
---|
| 542 |
|
---|
| 543 | System.out.println("processType build/NewCollection:\n"
|
---|
| 544 | + ws.processTypeService("build/NewCollection", "", params));
|
---|
| 545 |
|
---|
| 546 | params.clear();
|
---|
| 547 | params.put("collection", "demo");
|
---|
| 548 | System.out.println("processType build/ImportCollection:\n"
|
---|
| 549 | + ws.processTypeService("build/ImportCollection", "", params));
|
---|
| 550 |
|
---|
| 551 | // (12) Test status(), if possible
|
---|
| 552 | System.out.println("status:\n" + ws.status("build/NewCollection", "", "1"));
|
---|
| 553 |
|
---|
| 554 |
|
---|
| 555 | // (13) One applet-type service:
|
---|
| 556 | //Map params = new HashMap(10);
|
---|
| 557 | params.clear();
|
---|
| 558 | params.put("pc", "1");
|
---|
| 559 | params.put("pptext", "health");
|
---|
| 560 | params.put("pfe", "0");
|
---|
| 561 | params.put("ple", "10");
|
---|
| 562 | params.put("pfd", "0");
|
---|
| 563 | params.put("pld", "10");
|
---|
| 564 | params.put("pfl", "0");
|
---|
| 565 | params.put("pll", "10");
|
---|
| 566 | System.out.println("appletTypeService:\n"
|
---|
| 567 | + ws.appletTypeService("gs2mgppdemo", "PhindApplet", "query", params));
|
---|
| 568 | // no PhindApplet service deployed in gs2mgppdemo anymore, so maybe that's
|
---|
| 569 | // why it doesn't work. The request matches what's in the manual (p.50) though.
|
---|
| 570 |
|
---|
| 571 |
|
---|
| 572 | // (14) One enrich service:
|
---|
| 573 | params.clear();
|
---|
| 574 | params.put("annotationType", "Date,Location");
|
---|
| 575 | String[] nodeIDs = {"HASHac0a04dd14571c60d7fbfd"};
|
---|
| 576 | String[] nodeContents = { "FOOD AND AGRICULTURE ORGANIZATION OF THE UNITED NATIONS\n"
|
---|
| 577 | + "Rome 1986\nP-69\nISBN 92-5-102397-2\nFAO 1986"};
|
---|
| 578 | System.out.println("enrich:\n"
|
---|
| 579 | + ws.enrich("GatePOSTag", "en", params, nodeIDs, nodeContents));
|
---|
| 580 | // no GatePOSTag service deployed in gs2mgppdemo anymore, so maybe that's
|
---|
| 581 | // why it doesn't work. The request matches what's in the manual (p.50) though.
|
---|
| 582 |
|
---|
| 583 | // (16) try help
|
---|
| 584 | System.out.println(ws.help());
|
---|
| 585 | System.out.println(ws.help("describe"));
|
---|
| 586 |
|
---|
| 587 | }catch(Exception e) {
|
---|
| 588 | System.out.println("Problem accessing service\n" + e.getMessage());
|
---|
| 589 | e.printStackTrace();
|
---|
| 590 | }
|
---|
| 591 | }*/
|
---|
| 592 | } |
---|