Package org.dlese.dpc.ndr
Class NdrUtils
java.lang.Object
org.dlese.dpc.ndr.NdrUtils
Collection of static methods for setting up NDR proxy and performing
operations on the NDR.
NOTE: many NDR proxy functions require a ndrPrivateKey. Edit this file to set the "ndrPrivateKeyFile" attribute to a key file accessible to your filesystem to enable these functions.
- Author:
- ostwald
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic SimpleDateFormatFormats and parses dates according to utcDateFormatString.static String"yyyy-MM-dd'T'HH:mm:ss'Z'"static SimpleDateFormatNOT YET DOCUMENTEDstatic StringNOT YET DOCUMENTED -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidactivateObject(String handle) Set state to "Active" for NDR Object corresponding to handle.static voiddeactivateObject(String handle) Set state to "Inactive" for NDR Object corresponding to handle.static voiddeleteCollection(String collection) Removes the metadataProvider and all Metadata Objects associated with given key from the NDR.static voiddeleteNDRCollection(String mdpHandle) Removes the metadataProvider, all Metadata Objects, and the aggregator associated with the given mdpHandle from the NDR.static InfoXMLdeleteNDRObject(String handle) Marks the object corresponding to the provided handle as "deleted" in the NDR.static InfoXMLdeleteNDRObject(String handle, boolean cascade) Marks the object corresponding to the provided handle, as well as all subordinate objects (when cascade is true), as "deleted" in the NDR.static ListfindDeletedMetadataObjects(String mdpHandle) Returns deleted metadata objects for specified metadataProvider.static ListfindFinalValidResources(String mdpHandle) Retrieve list of metadata objects provided by specified metadataProvider whose metadata is valid and whose status is Final.static StringfindResource(String url) Return the handle of the resource for the given url if one is found, null otherwise.static StringfindResourceOld(String url) Finds the handle of the resource associated with provided url.static StringformattedDate(Date date) Converts a Date object to String of form "yyyy-MM-dd".static ListGets the aggregatorHandles attribute of the NdrUtils classstatic ListgetAggregatorHandles(String agentHandle) Gets the aggregatorHandles attribute of the NdrUtils classstatic org.dom4j.DocumentgetCollectionRecord(String collection) Retrieves the CollectionRecord stored in the NDR for the given collection key.static ListGets List of handles for MetadataProviders having no items.static StringgetInfoLink(String mdHandle) Gets the "link" value that goes into the nsdl_dc_info stream for metadata recordsstatic ListGets all MetadataProvider handles associated with the DleseAgentstatic ListgetMDPHandles(String agentHandle) Gets the handles for all MetadataProvider objects associated with the aggent associated with specified agentHandle (which defaults to the dleseAgent).static MetadataProviderReadergetMetadataProvider(String collection) Gets the metadataProvider stored in the NDR associated with given collection key.static org.dom4j.DocumentgetNDRObjectDoc(String handle) Performs a "get" request on the NDR with the provided object handle and returns the result as a dom4j.Document.static org.dom4j.DocumentgetNDRObjectDoc(URL handleUrl) Retrieves the provided "handleUrl" (a complete URL including ndrApi and a handle to a specific object) as a dom4j.Document.static final StringReturns null if the string is null or empty, or the original string otherwise.static ListgetRecentMDPHandles(Date thresholdDate) Gets handles of MetadataProvider Objects in the NDR that have been modified since specified threshold date.static ListgetStaleMDPHandles(Date thresholdDate) Gets List of MDP handles that have not been modified since provided threshold Date.static voidinitProp()Sets TransformerFactory to a XSL 1.0 version so the localizers don't complain.static booleanisNDRCollectionMDP1(String mdpHandle) Returns true if the provided handle is for a MetadataProvider that is part of a NDR Collection Definition (as opposed to a MDP that is used to group metadata for an NCS collection that is not seen by the NDR).static booleanisNDRCollectionMetadataProvider(String mdpHandle) Returns true if the provided handle is for a MetadataProvider that is part of a NDR Collection Definition (as opposed to a MDP that is used to group metadata for an NCS collection that is not seen by the NDR).static voidThe main program for the NdrUtils classstatic StringnormalizeUrl(String urlStr) Stand in for the official NDR normalizing routine.static DateparseDateString(String dateStr, SimpleDateFormat dateFormat) Formats given date string using given dateFormat.static DateparseNdrDateString(String dateStr) Converts String of form used by NDR ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") into a Date object.static DateparseSimpleDateString(String dateStr) Converts date string of form "yyyy-MM-dd" to Date object.static voidNOT YET DOCUMENTEDstatic voidpp(org.dom4j.Node node) Pretty-prints a dom4j.Node.static voidNOT YET DOCUMENTEDstatic voidsetDebug(boolean bool) Sets the debug attribute of the NdrUtils classstatic voidsetObjectState(String handle, NDRConstants.ObjectState state) Sets the state of the NDR Object corresponding to provided handle.static voidsetObjectState(NdrObjectReader reader, NDRConstants.ObjectState state) Sets the objectState attribute of the NdrUtils classstatic voidSets configuration parameters from provided properties file to communicate with an NDR instancestatic voidConfigures system to communicate with specified ndrServer (on read-only basis)static voidIntialize NDR Constants to enable interaction with NDR.
-
Field Details
-
ndrDateFormatString
"yyyy-MM-dd'T'HH:mm:ss'Z'" -
ndrDateFormat
Formats and parses dates according to utcDateFormatString. -
simpleDateFormatString
NOT YET DOCUMENTED -
simpleDateFormat
NOT YET DOCUMENTED
-
-
Constructor Details
-
NdrUtils
public NdrUtils()
-
-
Method Details
-
normalizeUrl
Stand in for the official NDR normalizing routine. Ensures a trailing slash if the url is simply a domain (with no path or query parts)- Parameters:
urlStr- NOT YET DOCUMENTED- Returns:
- NOT YET DOCUMENTED
-
setup
Configures system to communicate with specified ndrServer (on read-only basis)- Parameters:
ndrServer- the ndr server api url (e.g., "http://ndrtest.nsdl.org/api")
-
setup
Sets configuration parameters from provided properties file to communicate with an NDR instanceProperties:
- ndr.api.base.url (e.g., "http://ndrtest.nsdl.org/api") - required
- ncs.agent.handle - required for signed operations
- ndr.private.key - (path to privatekey file for ncs.agent.handle) required for signed operations
- Parameters:
propsFile- the properties file
-
setup
Intialize NDR Constants to enable interaction with NDR.- Parameters:
ndrServer- NOT YET DOCUMENTEDncsAgentHandle- NOT YET DOCUMENTEDkeyPath- NOT YET DOCUMENTED
-
getNonEmpyStringOrNull
Returns null if the string is null or empty, or the original string otherwise. Used to ensure a value is either null or has value.- Parameters:
s- NOT YET DOCUMENTED- Returns:
- The nonEmpyStringOrNull value
-
isNDRCollectionMDP1
Returns true if the provided handle is for a MetadataProvider that is part of a NDR Collection Definition (as opposed to a MDP that is used to group metadata for an NCS collection that is not seen by the NDR).NOTE: This is not a general solution, but instead depends upon an NCS relationship. See isNDRCollectionMetadataProvider for a general solution.
- Parameters:
mdpHandle- NOT YET DOCUMENTED- Returns:
- The nDRCollectionMDP1 value
- Throws:
Exception- NOT YET DOCUMENTED
-
isNDRCollectionMetadataProvider
Returns true if the provided handle is for a MetadataProvider that is part of a NDR Collection Definition (as opposed to a MDP that is used to group metadata for an NCS collection that is not seen by the NDR).Algorithm:
- obtain the aggregatorFor the provided MDP
- find the resource that is "associatedWith" the aggregator
- if there is a metadata object that is "metadataFor" BOTH the aggregator and the resource, then the mdp was an NDR Collection MetadataProvider.
- Parameters:
mdpHandle- NOT YET DOCUMENTED- Returns:
- The nDRCollectionMetadataProvider value
-
findFinalValidResources
Retrieve list of metadata objects provided by specified metadataProvider whose metadata is valid and whose status is Final.- Parameters:
mdpHandle- handle of metadataProvider owning desired metadata- Returns:
- list of handles for final and valid metadata
- Throws:
Exception- when ndrRequest results in error from NDR
-
findResourceOld
Finds the handle of the resource associated with provided url.- Parameters:
url- resource url to find- Returns:
- resource handle or null if resource is not found
-
deactivateObject
Set state to "Inactive" for NDR Object corresponding to handle.- Parameters:
handle- handle of object to activate- Throws:
Exception- NOT YET DOCUMENTED
-
activateObject
Set state to "Active" for NDR Object corresponding to handle.NOTE: will not activate an object with an NCS status that is not final.
- Parameters:
handle- handle of object to activate- Throws:
Exception- NOT YET DOCUMENTED
-
setObjectState
Sets the state of the NDR Object corresponding to provided handle.- Parameters:
handle- handle for NDR Objectstate- The new objectState value- Throws:
Exception- if NDR Object not found for handle
-
setObjectState
public static void setObjectState(NdrObjectReader reader, NDRConstants.ObjectState state) throws Exception Sets the objectState attribute of the NdrUtils class- Parameters:
reader- NDR reader for object for which state will be setstate- The new objectState value- Throws:
Exception
-
getInfoLink
Gets the "link" value that goes into the nsdl_dc_info stream for metadata records- Parameters:
mdHandle- NOT YET DOCUMENTED- Returns:
- The infoLink value
- Throws:
Exception- NOT YET DOCUMENTED
-
findResource
Return the handle of the resource for the given url if one is found, null otherwise.- Parameters:
url- url for which object will be found- Returns:
- NOT YET DOCUMENTED
-
findDeletedMetadataObjects
Returns deleted metadata objects for specified metadataProvider.- Parameters:
mdpHandle- handle for a metadataProvider object- Returns:
- list of metadata object handles
-
getMetadataProvider
Gets the metadataProvider stored in the NDR associated with given collection key.- Parameters:
collection- collection key- Returns:
- metadataProviderReader instance for given collection
- Throws:
Exception- NOT YET DOCUMENTED
-
getCollectionRecord
Retrieves the CollectionRecord stored in the NDR for the given collection key.- Parameters:
collection- collectionKey associated with a collection stored in the NDR.- Returns:
- CollectionRecord (dlese_collect format)
- Throws:
Exception- NOT YET DOCUMENTED
-
getNDRObjectDoc
Performs a "get" request on the NDR with the provided object handle and returns the result as a dom4j.Document.- Parameters:
handle- handle to an ndrObject- Returns:
- NDR response representing object for handle
- Throws:
Exception- if handle is not provided, or url does not resolve to well-formed xml.
-
getNDRObjectDoc
Retrieves the provided "handleUrl" (a complete URL including ndrApi and a handle to a specific object) as a dom4j.Document.- Parameters:
handleUrl- NOT YET DOCUMENTED- Returns:
- Response from NDR
- Throws:
Exception- If url does not resolve to well-formed xml.
-
getMDPHandles
Gets all MetadataProvider handles associated with the DleseAgent- Returns:
- The mDPHandles value
- Throws:
Exception- NOT YET DOCUMENTED
-
getMDPHandles
Gets the handles for all MetadataProvider objects associated with the aggent associated with specified agentHandle (which defaults to the dleseAgent).Relies on "Find" request, which requires authentication and therefore uses NDRAPIProxy.
- Parameters:
agentHandle- agent for which we are retrieving mdpHandles- Returns:
- The mDPHandles associated with this agent
- Throws:
Exception- NOT YET DOCUMENTED
-
getAggregatorHandles
Gets the aggregatorHandles attribute of the NdrUtils class- Returns:
- The aggregatorHandles value
- Throws:
Exception- NOT YET DOCUMENTED
-
getAggregatorHandles
Gets the aggregatorHandles attribute of the NdrUtils class- Parameters:
agentHandle- NOT YET DOCUMENTED- Returns:
- The aggregatorHandles value
- Throws:
Exception- NOT YET DOCUMENTED
-
initProp
Sets TransformerFactory to a XSL 1.0 version so the localizers don't complain.- Throws:
Exception- NOT YET DOCUMENTED
-
main
The main program for the NdrUtils class- Parameters:
args- The command line arguments- Throws:
Exception- NOT YET DOCUMENTED
-
getEmtpyMDPHandles
Gets List of handles for MetadataProviders having no items.- Returns:
- The emtpyMDPHandles value
- Throws:
Exception- NOT YET DOCUMENTED
-
getRecentMDPHandles
Gets handles of MetadataProvider Objects in the NDR that have been modified since specified threshold date.- Parameters:
thresholdDate- NOT YET DOCUMENTED- Returns:
- The recentMDPHandles value
-
getStaleMDPHandles
Gets List of MDP handles that have not been modified since provided threshold Date.- Parameters:
thresholdDate- NOT YET DOCUMENTED- Returns:
- The staleMDPHandles value
-
deleteNDRObject
Marks the object corresponding to the provided handle as "deleted" in the NDR.- Parameters:
handle- handle of Object to be deleted.- Returns:
- response object as InfoXML instance
- Throws:
Exception- if NDR object cannot be deleted
-
deleteNDRObject
Marks the object corresponding to the provided handle, as well as all subordinate objects (when cascade is true), as "deleted" in the NDR.- Parameters:
handle- handle of Object to be deletedcascade- flag to delete all dependent objects (not working in NDR)- Returns:
- response object as InfoXML instance
- Throws:
Exception- if NDR object cannot be deleted
-
deleteCollection
Removes the metadataProvider and all Metadata Objects associated with given key from the NDR.- Parameters:
collection- collectionKey- Throws:
Exception- if NDR objects cannot be deleted
-
deleteNDRCollection
Removes the metadataProvider, all Metadata Objects, and the aggregator associated with the given mdpHandle from the NDR.- Parameters:
mdpHandle- MetadataProvider object handle.- Throws:
Exception- if NDR objects cannot be deleted
-
parseDateString
Formats given date string using given dateFormat.- Parameters:
dateStr- Date in string form to be converted to a Date ObjectdateFormat- NOT YET DOCUMENTED- Returns:
- Date object for dateStr, or Date corresponding to 0 milliseconds if the dateStr cannot be parsed.
-
parseNdrDateString
Converts String of form used by NDR ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") into a Date object.- Parameters:
dateStr-- Returns:
- NOT YET DOCUMENTED
-
parseSimpleDateString
Converts date string of form "yyyy-MM-dd" to Date object.- Parameters:
dateStr- NOT YET DOCUMENTED- Returns:
- NOT YET DOCUMENTED
-
formattedDate
Converts a Date object to String of form "yyyy-MM-dd".- Parameters:
date- NOT YET DOCUMENTED- Returns:
- NOT YET DOCUMENTED
-
pp
public static void pp(org.dom4j.Node node) Pretty-prints a dom4j.Node.- Parameters:
node- NOT YET DOCUMENTED
-
pp
NOT YET DOCUMENTED- Parameters:
xml- NOT YET DOCUMENTED
-
setDebug
public static void setDebug(boolean bool) Sets the debug attribute of the NdrUtils class- Parameters:
bool- The new debug value
-
prtln
NOT YET DOCUMENTED- Parameters:
s- NOT YET DOCUMENTEDprefix- NOT YET DOCUMENTED
-