DLESE Tools
v1.6.0

org.dlese.dpc.ndr
Class NdrUtils

java.lang.Object
  extended by org.dlese.dpc.ndr.NdrUtils

public class NdrUtils
extends Object

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
static SimpleDateFormat ndrDateFormat
          Formats and parses dates according to utcDateFormatString.
static String ndrDateFormatString
          "yyyy-MM-dd'T'HH:mm:ss'Z'"
static SimpleDateFormat simpleDateFormat
          NOT YET DOCUMENTED
static String simpleDateFormatString
          NOT YET DOCUMENTED
 
Constructor Summary
NdrUtils()
           
 
Method Summary
static void activateObject(String handle)
          Set state to "Active" for NDR Object corresponding to handle.
static void deactivateObject(String handle)
          Set state to "Inactive" for NDR Object corresponding to handle.
static void deleteCollection(String collection)
          Removes the metadataProvider and all Metadata Objects associated with given key from the NDR.
static void deleteNDRCollection(String mdpHandle)
          Removes the metadataProvider, all Metadata Objects, and the aggregator associated with the given mdpHandle from the NDR.
static InfoXML deleteNDRObject(String handle)
          Marks the object corresponding to the provided handle as "deleted" in the NDR.
static InfoXML deleteNDRObject(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 List findDeletedMetadataObjects(String mdpHandle)
          Returns deleted metadata objects for specified metadataProvider.
static List findFinalValidResources(String mdpHandle)
          Retrieve list of metadata objects provided by specified metadataProvider whose metadata is valid and whose status is Final.
static String findResource(String url)
          Return the handle of the resource for the given url if one is found, null otherwise.
static String findResourceOld(String url)
          Finds the handle of the resource associated with provided url.
static String formattedDate(Date date)
          Converts a Date object to String of form "yyyy-MM-dd".
static List getAggregatorHandles()
          Gets the aggregatorHandles attribute of the NdrUtils class
static List getAggregatorHandles(String agentHandle)
          Gets the aggregatorHandles attribute of the NdrUtils class
static Document getCollectionRecord(String collection)
          Retrieves the CollectionRecord stored in the NDR for the given collection key.
static List getEmtpyMDPHandles()
          Gets List of handles for MetadataProviders having no items.
static String getInfoLink(String mdHandle)
          Gets the "link" value that goes into the nsdl_dc_info stream for metadata records
static List getMDPHandles()
          Gets all MetadataProvider handles associated with the DleseAgent
static List getMDPHandles(String agentHandle)
          Gets the handles for all MetadataProvider objects associated with the aggent associated with specified agentHandle (which defaults to the dleseAgent).
static MetadataProviderReader getMetadataProvider(String collection)
          Gets the metadataProvider stored in the NDR associated with given collection key.
static Document getNDRObjectDoc(String handle)
          Performs a "get" request on the NDR with the provided object handle and returns the result as a dom4j.Document.
static Document getNDRObjectDoc(URL handleUrl)
          Retrieves the provided "handleUrl" (a complete URL including ndrApi and a handle to a specific object) as a dom4j.Document.
static String getNonEmpyStringOrNull(String s)
          Returns null if the string is null or empty, or the original string otherwise.
static List getRecentMDPHandles(Date thresholdDate)
          Gets handles of MetadataProvider Objects in the NDR that have been modified since specified threshold date.
static List getStaleMDPHandles(Date thresholdDate)
          Gets List of MDP handles that have not been modified since provided threshold Date.
static void initProp()
          Sets TransformerFactory to a XSL 1.0 version so the localizers don't complain.
static boolean isNDRCollectionMDP1(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 boolean isNDRCollectionMetadataProvider(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 void main(String[] args)
          The main program for the NdrUtils class
static String normalizeUrl(String urlStr)
          Stand in for the official NDR normalizing routine.
static Date parseDateString(String dateStr, SimpleDateFormat dateFormat)
          Formats given date string using given dateFormat.
static Date parseNdrDateString(String dateStr)
          Converts String of form used by NDR ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") into a Date object.
static Date parseSimpleDateString(String dateStr)
          Converts date string of form "yyyy-MM-dd" to Date object.
static void pp(Node node)
          Pretty-prints a dom4j.Node.
static void pp(String xml)
          NOT YET DOCUMENTED
static void prtln(String s, String prefix)
          NOT YET DOCUMENTED
static void setDebug(boolean bool)
          Sets the debug attribute of the NdrUtils class
static void setObjectState(NdrObjectReader reader, NDRConstants.ObjectState state)
          Sets the objectState attribute of the NdrUtils class
static void setObjectState(String handle, NDRConstants.ObjectState state)
          Sets the state of the NDR Object corresponding to provided handle.
static void setup(File propsFile)
          Sets configuration parameters from provided properties file to communicate with an NDR instance
static void setup(String ndrServer)
          Configures system to communicate with specified ndrServer (on read-only basis)
static void setup(String ndrServer, String ncsAgentHandle, String keyPath)
          Intialize NDR Constants to enable interaction with NDR.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ndrDateFormatString

public static String ndrDateFormatString
"yyyy-MM-dd'T'HH:mm:ss'Z'"


ndrDateFormat

public static SimpleDateFormat ndrDateFormat
Formats and parses dates according to utcDateFormatString.


simpleDateFormatString

public static String simpleDateFormatString
NOT YET DOCUMENTED


simpleDateFormat

public static SimpleDateFormat simpleDateFormat
NOT YET DOCUMENTED

Constructor Detail

NdrUtils

public NdrUtils()
Method Detail

normalizeUrl

public static String normalizeUrl(String urlStr)
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

public static void setup(String ndrServer)
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

public static void setup(File propsFile)
Sets configuration parameters from provided properties file to communicate with an NDR instance

Properties:

Parameters:
propsFile - the properties file

setup

public static void setup(String ndrServer,
                         String ncsAgentHandle,
                         String keyPath)
Intialize NDR Constants to enable interaction with NDR.

Parameters:
ndrServer - NOT YET DOCUMENTED
ncsAgentHandle - NOT YET DOCUMENTED
keyPath - NOT YET DOCUMENTED

getNonEmpyStringOrNull

public static final String getNonEmpyStringOrNull(String s)
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

public static boolean isNDRCollectionMDP1(String mdpHandle)
                                   throws Exception
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

public static boolean isNDRCollectionMetadataProvider(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).

Algorithm:

  1. obtain the aggregatorFor the provided MDP
  2. find the resource that is "associatedWith" the aggregator
  3. 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

public static List findFinalValidResources(String mdpHandle)
                                    throws Exception
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

public static String findResourceOld(String url)
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

public static void deactivateObject(String handle)
                             throws Exception
Set state to "Inactive" for NDR Object corresponding to handle.

Parameters:
handle - handle of object to activate
Throws:
Exception - NOT YET DOCUMENTED

activateObject

public static void activateObject(String handle)
                           throws Exception
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

public static void setObjectState(String handle,
                                  NDRConstants.ObjectState state)
                           throws Exception
Sets the state of the NDR Object corresponding to provided handle.

Parameters:
handle - handle for NDR Object
state - 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 set
state - The new objectState value
Throws:
Exception

getInfoLink

public static String getInfoLink(String mdHandle)
                          throws Exception
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

public static String findResource(String url)
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

public static List findDeletedMetadataObjects(String mdpHandle)
Returns deleted metadata objects for specified metadataProvider.

Parameters:
mdpHandle - handle for a metadataProvider object
Returns:
list of metadata object handles

getMetadataProvider

public static MetadataProviderReader getMetadataProvider(String collection)
                                                  throws Exception
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

public static Document getCollectionRecord(String collection)
                                    throws Exception
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

public static Document getNDRObjectDoc(String handle)
                                throws Exception
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

public static Document getNDRObjectDoc(URL handleUrl)
                                throws Exception
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

public static List getMDPHandles()
                          throws Exception
Gets all MetadataProvider handles associated with the DleseAgent

Returns:
The mDPHandles value
Throws:
Exception - NOT YET DOCUMENTED

getMDPHandles

public static List getMDPHandles(String agentHandle)
                          throws Exception
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

public static List getAggregatorHandles()
                                 throws Exception
Gets the aggregatorHandles attribute of the NdrUtils class

Returns:
The aggregatorHandles value
Throws:
Exception - NOT YET DOCUMENTED

getAggregatorHandles

public static List getAggregatorHandles(String agentHandle)
                                 throws Exception
Gets the aggregatorHandles attribute of the NdrUtils class

Parameters:
agentHandle - NOT YET DOCUMENTED
Returns:
The aggregatorHandles value
Throws:
Exception - NOT YET DOCUMENTED

initProp

public static void initProp()
                     throws Exception
Sets TransformerFactory to a XSL 1.0 version so the localizers don't complain.

Throws:
Exception - NOT YET DOCUMENTED

main

public static void main(String[] args)
                 throws Exception
The main program for the NdrUtils class

Parameters:
args - The command line arguments
Throws:
Exception - NOT YET DOCUMENTED

getEmtpyMDPHandles

public static List getEmtpyMDPHandles()
                               throws Exception
Gets List of handles for MetadataProviders having no items.

Returns:
The emtpyMDPHandles value
Throws:
Exception - NOT YET DOCUMENTED

getRecentMDPHandles

public static List getRecentMDPHandles(Date thresholdDate)
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

public static List getStaleMDPHandles(Date thresholdDate)
Gets List of MDP handles that have not been modified since provided threshold Date.

Parameters:
thresholdDate - NOT YET DOCUMENTED
Returns:
The staleMDPHandles value

deleteNDRObject

public static InfoXML deleteNDRObject(String handle)
                               throws Exception
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

public static InfoXML deleteNDRObject(String handle,
                                      boolean cascade)
                               throws Exception
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 deleted
cascade - 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

public static void deleteCollection(String collection)
                             throws Exception
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

public static void deleteNDRCollection(String mdpHandle)
                                throws Exception
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

public static Date parseDateString(String dateStr,
                                   SimpleDateFormat dateFormat)
Formats given date string using given dateFormat.

Parameters:
dateStr - Date in string form to be converted to a Date Object
dateFormat - NOT YET DOCUMENTED
Returns:
Date object for dateStr, or Date corresponding to 0 milliseconds if the dateStr cannot be parsed.

parseNdrDateString

public static Date parseNdrDateString(String dateStr)
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

public static Date parseSimpleDateString(String dateStr)
Converts date string of form "yyyy-MM-dd" to Date object.

Parameters:
dateStr - NOT YET DOCUMENTED
Returns:
NOT YET DOCUMENTED

formattedDate

public static String formattedDate(Date date)
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(Node node)
Pretty-prints a dom4j.Node.

Parameters:
node - NOT YET DOCUMENTED

pp

public static void pp(String xml)
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

public static void prtln(String s,
                         String prefix)
NOT YET DOCUMENTED

Parameters:
s - NOT YET DOCUMENTED
prefix - NOT YET DOCUMENTED

DLESE Tools
v1.6.0