Class DDSServicesToolkit
java.lang.Object
org.dlese.dpc.services.dds.toolkit.DDSServicesToolkit
Toolkit for working with DDS repository Search and Update Web Services (DDSWS and DDSUpdateWS) for read
and write operations. All methods use only local variables and are thread safe but are not synchronized.
See DDSWS documentation
and
DDSUpdateWS documentation
- Author:
- John Weatherley
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intIndicates the optional sort order for search results should be ascendingstatic intIndicates the optional sort order for search results should be descendingstatic intIndicates no sorting should be applied to search results -
Constructor Summary
ConstructorsConstructorDescriptionDDSServicesToolkit(String ddsServicesUrl, String clientName) Constructor for the DDSServicesToolkit object -
Method Summary
Modifier and TypeMethodDescriptionprotected String[]checkForErrorResponseDDSUpdateWS(org.dom4j.Document ddsupdateResponse) Checks for the existance of an error response from a DDS update service request (DDSUpdateWS).protected String[]checkForErrorResponseDDSWS(org.dom4j.Document ddswsResponse) Checks for the existance of an error response from a DDS service request (DDSWS).deleteRecord(String recordId) Deletes a record from a DDS repository.protected static final StringReturn a string for the current time and date, sutiable for display in log files and output to standout:Gets the index version, which can be useful to determine if a service response cache needs to be updated.getRecord(String id, String showRelation, String xmlFormat, Map additionalRequestParams, boolean soAllRecords, boolean localizeXml) Performs a GetRecord request from a DDSWS repository.booleanhasCollection(String collectionKey, String xmlFormat) Determines whether the given collection is in this DDS repository.booleanDetermines whether the given record is in this DDS repository.listCollections(boolean localizeXml) Performs a ListCollections request from a DDSWS repository.listFields(boolean localizeXml) Performs a ListFields request from a DDSWS repository.Performs a ListTerms request from a DDSWS repository.putCollection(String collectionKey, String xmlFormat, String collectionName, String collectionDescription) Puts a collection into a DDS repository.org.dom4j.DocumentPuts a record into a DDS repository.search(String query, String xmlFormat, int startOffset, int numReturns, String sortByField, int sortOrder, String showRelation, Map additionalRequestParams, boolean soAllRecords, boolean localizeXml) Performs a Search request from a DDSWS repository.serviceInfo(boolean localizeXml) Performs a ServiceInfo request from a DDSWS repository.static voidsetDebug(boolean db) Sets the debug attribute of the object
-
Field Details
-
SORT_ORDER_ASCENDING
public static int SORT_ORDER_ASCENDINGIndicates the optional sort order for search results should be ascending -
SORT_ORDER_DESCENDING
public static int SORT_ORDER_DESCENDINGIndicates the optional sort order for search results should be descending -
SORT_ORDER_NO_SORT
public static int SORT_ORDER_NO_SORTIndicates no sorting should be applied to search results
-
-
Constructor Details
-
DDSServicesToolkit
Constructor for the DDSServicesToolkit object- Parameters:
ddsServicesUrl- Common baseUrl for DDS services, for example http://www.dlese.org/dds/services/clientName- The client name, or null to send none
-
-
Method Details
-
getRecord
public DDSServicesResponse getRecord(String id, String showRelation, String xmlFormat, Map additionalRequestParams, boolean soAllRecords, boolean localizeXml) throws DDSServiceErrorResponseException, Exception Performs a GetRecord request from a DDSWS repository.- Parameters:
id- Record IDshowRelation- The relation data to include in the response for example isAnnotatedBy, or null for nonexmlFormat- The XML format to return, or null for native formatadditionalRequestParams- A Map that contains param/value pairs. Values must be of type String to indicate a single value, or a String [] to indicate multiple values. Map may be null for none.soAllRecords- True to search all records including non-discoverable ones (client must be authorized by IP)localizeXml- True to localize the response- Returns:
- The service response
- Throws:
DDSServiceErrorResponseException- Standard service error if one was returnedException- If other error occurs
-
hasRecord
public boolean hasRecord(String id, String xmlFormat) throws DDSServiceErrorResponseException, Exception Determines whether the given record is in this DDS repository. If a format is specified, then also determines if the record can be dissiminated in the given format.- Parameters:
id- The record idxmlFormat- The XML format to check availability for, or null for any/all- Returns:
- True if the given record is in the repository
- Throws:
DDSServiceErrorResponseException- If service errorException- If other error
-
search
public DDSServicesResponse search(String query, String xmlFormat, int startOffset, int numReturns, String sortByField, int sortOrder, String showRelation, Map additionalRequestParams, boolean soAllRecords, boolean localizeXml) throws DDSServiceErrorResponseException, Exception Performs a Search request from a DDSWS repository.- Parameters:
query- The search query, or nullxmlFormat- The xmlFormat for which results must be dissiminated, or null for any/allstartOffset- Starting offset in the returnsnumReturns- Number of records to returnsortByField- Indicates the search field to sort the results by, or null for nonesortOrder- The sort order to apply (ascending, descending). Ignored if no sortByField has been indicatedshowRelation- The relation data to include in the response for example isAnnotatedBy, or null for noneadditionalRequestParams- A Map that contains param/value pairs. Values must be of type String to indicate a single value, or a String [] to indicate multiple values. Map may be null for none.soAllRecords- True to search all records including non-discoverable ones (client must be authorized by IP)localizeXml- True to localize the response- Returns:
- The service response
- Throws:
DDSServiceErrorResponseException- Standard service error if one was returnedException- If other error occurs
-
listCollections
public DDSServicesResponse listCollections(boolean localizeXml) throws DDSServiceErrorResponseException, Exception Performs a ListCollections request from a DDSWS repository.- Parameters:
localizeXml- True to localize the response XML- Returns:
- The service response
- Throws:
DDSServiceErrorResponseException- Standard service error if one was returnedException- If other error occurs
-
serviceInfo
public DDSServicesResponse serviceInfo(boolean localizeXml) throws DDSServiceErrorResponseException, Exception Performs a ServiceInfo request from a DDSWS repository.- Parameters:
localizeXml- True to localize the response XML- Returns:
- The service response
- Throws:
DDSServiceErrorResponseException- Standard service error if one was returnedException- If other error occurs
-
getIndexVersion
Gets the index version, which can be useful to determine if a service response cache needs to be updated.- Returns:
- The indexVersion value
- Throws:
DDSServiceErrorResponseException- If DDSServiceErrorResponseException errorException- If exception
-
listFields
public DDSServicesResponse listFields(boolean localizeXml) throws DDSServiceErrorResponseException, Exception Performs a ListFields request from a DDSWS repository.- Parameters:
localizeXml- True to localize the response XML- Returns:
- The service response
- Throws:
DDSServiceErrorResponseException- Standard service error if one was returnedException- If other error occurs
-
listTerms
public DDSServicesResponse listTerms(String[] fields, boolean localizeXml) throws DDSServiceErrorResponseException, Exception Performs a ListTerms request from a DDSWS repository. The request accepts one or more fields to list the terms data for. Note that this request is much less efficient when more than one field is requested.- Parameters:
fields- One or more fields to list terms forlocalizeXml- True to localize the response XML- Returns:
- The service response
- Throws:
DDSServiceErrorResponseException- Standard service error if one was returnedException- If other error occurs
-
hasCollection
public boolean hasCollection(String collectionKey, String xmlFormat) throws DDSServiceErrorResponseException, Exception Determines whether the given collection is in this DDS repository.- Parameters:
collectionKey- The collection key, for example 'dcc'xmlFormat- The xml format for this collection, for example 'adn'- Returns:
- True if the given collection is in the repository with the given
- Throws:
DDSServiceErrorResponseException- If service errorException- If other error
-
checkForErrorResponseDDSWS
Checks for the existance of an error response from a DDS service request (DDSWS). If no error was recieved, this method returns null, otherwise returns the error code and message.- Parameters:
ddswsResponse- The service response- Returns:
- The error code and message [code,message], or null if none
-
putRecord
public org.dom4j.Document putRecord(String recordId, String recordXml, String collectionKey, String xmlFormat) throws DDSServiceErrorResponseException, Exception Puts a record into a DDS repository.- Parameters:
recordId- recordIdrecordXml- recordXmlcollectionKey- collectionKeyxmlFormat- xmlFormat- Returns:
- The service response
- Throws:
Exception- If errorDDSServiceErrorResponseException- Standard service error if one was returned
-
deleteRecord
public DDSServicesResponse deleteRecord(String recordId) throws DDSServiceErrorResponseException, Exception Deletes a record from a DDS repository.- Parameters:
recordId- recordId- Returns:
- The service response
- Throws:
DDSServiceErrorResponseException- Standard service error if one was returnedException- If other error occurs
-
putCollection
public DDSServicesResponse putCollection(String collectionKey, String xmlFormat, String collectionName, String collectionDescription) throws DDSServiceErrorResponseException, Exception Puts a collection into a DDS repository.- Parameters:
collectionKey- The collection key, for example 'dcc'xmlFormat- The xml format, for example 'adn'collectionName- The name of the collectioncollectionDescription- Description of the collection- Returns:
- The service response
- Throws:
DDSServiceErrorResponseException- Standard service error if one was returnedException- If other error occurs
-
checkForErrorResponseDDSUpdateWS
Checks for the existance of an error response from a DDS update service request (DDSUpdateWS). If no error was recieved, this method returns null, otherwise returns the error code and message.- Parameters:
ddsupdateResponse- The DDS response- Returns:
- The error code and message [code,message], or null if none
-
getDateStamp
Return a string for the current time and date, sutiable for display in log files and output to standout:- Returns:
- The dateStamp value
-
setDebug
public static void setDebug(boolean db) Sets the debug attribute of the object- Parameters:
db- The new debug value
-