public class NdrUtils
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
static java.text.SimpleDateFormat |
ndrDateFormat
Formats and parses dates according to utcDateFormatString.
|
static java.lang.String |
ndrDateFormatString
"yyyy-MM-dd'T'HH:mm:ss'Z'"
|
static java.text.SimpleDateFormat |
simpleDateFormat
NOT YET DOCUMENTED
|
static java.lang.String |
simpleDateFormatString
NOT YET DOCUMENTED
|
Constructor and Description |
---|
NdrUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
activateObject(java.lang.String handle)
Set state to "Active" for NDR Object corresponding to handle.
|
static void |
deactivateObject(java.lang.String handle)
Set state to "Inactive" for NDR Object corresponding to handle.
|
static void |
deleteCollection(java.lang.String collection)
Removes the metadataProvider and all Metadata Objects associated with given
key from the NDR.
|
static void |
deleteNDRCollection(java.lang.String mdpHandle)
Removes the metadataProvider, all Metadata Objects, and the aggregator
associated with the given mdpHandle from the NDR.
|
static InfoXML |
deleteNDRObject(java.lang.String handle)
Marks the object corresponding to the provided handle as "deleted" in the
NDR.
|
static InfoXML |
deleteNDRObject(java.lang.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 java.util.List |
findDeletedMetadataObjects(java.lang.String mdpHandle)
Returns deleted metadata objects for specified metadataProvider.
|
static java.util.List |
findFinalValidResources(java.lang.String mdpHandle)
Retrieve list of metadata objects provided by specified metadataProvider
whose metadata is valid and whose status is Final.
|
static java.lang.String |
findResource(java.lang.String url)
Return the handle of the resource for the given url if one is found, null
otherwise.
|
static java.lang.String |
findResourceOld(java.lang.String url)
Finds the handle of the resource associated with provided url.
|
static java.lang.String |
formattedDate(java.util.Date date)
Converts a Date object to String of form "yyyy-MM-dd".
|
static java.util.List |
getAggregatorHandles()
Gets the aggregatorHandles attribute of the NdrUtils class
|
static java.util.List |
getAggregatorHandles(java.lang.String agentHandle)
Gets the aggregatorHandles attribute of the NdrUtils class
|
static org.dom4j.Document |
getCollectionRecord(java.lang.String collection)
Retrieves the CollectionRecord stored in the NDR for the given collection
key.
|
static java.util.List |
getEmtpyMDPHandles()
Gets List of handles for MetadataProviders having no items.
|
static java.lang.String |
getInfoLink(java.lang.String mdHandle)
Gets the "link" value that goes into the nsdl_dc_info stream for metadata
records
|
static java.util.List |
getMDPHandles()
Gets all MetadataProvider handles associated with the DleseAgent
|
static java.util.List |
getMDPHandles(java.lang.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(java.lang.String collection)
Gets the metadataProvider stored in the NDR associated with given
collection key.
|
static org.dom4j.Document |
getNDRObjectDoc(java.lang.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.Document |
getNDRObjectDoc(java.net.URL handleUrl)
Retrieves the provided "handleUrl" (a complete URL including ndrApi and a
handle to a specific object) as a dom4j.Document.
|
static java.lang.String |
getNonEmpyStringOrNull(java.lang.String s)
Returns null if the string is null or empty, or the original string
otherwise.
|
static java.util.List |
getRecentMDPHandles(java.util.Date thresholdDate)
Gets handles of MetadataProvider Objects in the NDR that have been modified
since specified threshold date.
|
static java.util.List |
getStaleMDPHandles(java.util.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(java.lang.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(java.lang.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(java.lang.String[] args)
The main program for the NdrUtils class
|
static java.lang.String |
normalizeUrl(java.lang.String urlStr)
Stand in for the official NDR normalizing routine.
|
static java.util.Date |
parseDateString(java.lang.String dateStr,
java.text.SimpleDateFormat dateFormat)
Formats given date string using given dateFormat.
|
static java.util.Date |
parseNdrDateString(java.lang.String dateStr)
Converts String of form used by NDR ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") into a
Date object.
|
static java.util.Date |
parseSimpleDateString(java.lang.String dateStr)
Converts date string of form "yyyy-MM-dd" to Date object.
|
static void |
pp(org.dom4j.Node node)
Pretty-prints a dom4j.Node.
|
static void |
pp(java.lang.String xml)
NOT YET DOCUMENTED
|
static void |
prtln(java.lang.String s,
java.lang.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(java.lang.String handle,
NDRConstants.ObjectState state)
Sets the state of the NDR Object corresponding to provided handle.
|
static void |
setup(java.io.File propsFile)
Sets configuration parameters from provided properties file to communicate
with an NDR instance
|
static void |
setup(java.lang.String ndrServer)
Configures system to communicate with specified ndrServer (on read-only
basis)
|
static void |
setup(java.lang.String ndrServer,
java.lang.String ncsAgentHandle,
java.lang.String keyPath)
Intialize NDR Constants to enable interaction with NDR.
|
public static java.lang.String ndrDateFormatString
public static java.text.SimpleDateFormat ndrDateFormat
public static java.lang.String simpleDateFormatString
public static java.text.SimpleDateFormat simpleDateFormat
public static java.lang.String normalizeUrl(java.lang.String urlStr)
urlStr
- NOT YET DOCUMENTEDpublic static void setup(java.lang.String ndrServer)
ndrServer
- the ndr server api url (e.g., "http://ndrtest.nsdl.org/api")public static void setup(java.io.File propsFile)
Properties:
propsFile
- the properties filepublic static void setup(java.lang.String ndrServer, java.lang.String ncsAgentHandle, java.lang.String keyPath)
ndrServer
- NOT YET DOCUMENTEDncsAgentHandle
- NOT YET DOCUMENTEDkeyPath
- NOT YET DOCUMENTEDpublic static final java.lang.String getNonEmpyStringOrNull(java.lang.String s)
s
- NOT YET DOCUMENTEDpublic static boolean isNDRCollectionMDP1(java.lang.String mdpHandle) throws java.lang.Exception
NOTE: This is not a general solution, but instead depends upon an NCS relationship. See isNDRCollectionMetadataProvider for a general solution.
mdpHandle
- NOT YET DOCUMENTEDjava.lang.Exception
- NOT YET DOCUMENTEDpublic static boolean isNDRCollectionMetadataProvider(java.lang.String mdpHandle)
Algorithm:
mdpHandle
- NOT YET DOCUMENTEDpublic static java.util.List findFinalValidResources(java.lang.String mdpHandle) throws java.lang.Exception
mdpHandle
- handle of metadataProvider owning desired metadatajava.lang.Exception
- when ndrRequest results in error from NDRpublic static java.lang.String findResourceOld(java.lang.String url)
url
- resource url to findpublic static void deactivateObject(java.lang.String handle) throws java.lang.Exception
handle
- handle of object to activatejava.lang.Exception
- NOT YET DOCUMENTEDpublic static void activateObject(java.lang.String handle) throws java.lang.Exception
NOTE: will not activate an object with an NCS status that is not final.
handle
- handle of object to activatejava.lang.Exception
- NOT YET DOCUMENTEDpublic static void setObjectState(java.lang.String handle, NDRConstants.ObjectState state) throws java.lang.Exception
handle
- handle for NDR Objectstate
- The new objectState valuejava.lang.Exception
- if NDR Object not found for handlepublic static void setObjectState(NdrObjectReader reader, NDRConstants.ObjectState state) throws java.lang.Exception
reader
- NDR reader for object for which state will be setstate
- The new objectState valuejava.lang.Exception
public static java.lang.String getInfoLink(java.lang.String mdHandle) throws java.lang.Exception
mdHandle
- NOT YET DOCUMENTEDjava.lang.Exception
- NOT YET DOCUMENTEDpublic static java.lang.String findResource(java.lang.String url)
url
- url for which object will be foundpublic static java.util.List findDeletedMetadataObjects(java.lang.String mdpHandle)
mdpHandle
- handle for a metadataProvider objectpublic static MetadataProviderReader getMetadataProvider(java.lang.String collection) throws java.lang.Exception
collection
- collection keyjava.lang.Exception
- NOT YET DOCUMENTEDpublic static org.dom4j.Document getCollectionRecord(java.lang.String collection) throws java.lang.Exception
collection
- collectionKey associated with a collection stored in
the NDR.java.lang.Exception
- NOT YET DOCUMENTEDpublic static org.dom4j.Document getNDRObjectDoc(java.lang.String handle) throws java.lang.Exception
handle
- handle to an ndrObjectjava.lang.Exception
- if handle is not provided, or url does not resolve to
well-formed xml.public static org.dom4j.Document getNDRObjectDoc(java.net.URL handleUrl) throws java.lang.Exception
handleUrl
- NOT YET DOCUMENTEDjava.lang.Exception
- If url does not resolve to well-formed xml.public static java.util.List getMDPHandles() throws java.lang.Exception
java.lang.Exception
- NOT YET DOCUMENTEDpublic static java.util.List getMDPHandles(java.lang.String agentHandle) throws java.lang.Exception
Relies on "Find" request, which requires authentication and therefore uses NDRAPIProxy.
agentHandle
- agent for which we are retrieving mdpHandlesjava.lang.Exception
- NOT YET DOCUMENTEDpublic static java.util.List getAggregatorHandles() throws java.lang.Exception
java.lang.Exception
- NOT YET DOCUMENTEDpublic static java.util.List getAggregatorHandles(java.lang.String agentHandle) throws java.lang.Exception
agentHandle
- NOT YET DOCUMENTEDjava.lang.Exception
- NOT YET DOCUMENTEDpublic static void initProp() throws java.lang.Exception
java.lang.Exception
- NOT YET DOCUMENTEDpublic static void main(java.lang.String[] args) throws java.lang.Exception
args
- The command line argumentsjava.lang.Exception
- NOT YET DOCUMENTEDpublic static java.util.List getEmtpyMDPHandles() throws java.lang.Exception
java.lang.Exception
- NOT YET DOCUMENTEDpublic static java.util.List getRecentMDPHandles(java.util.Date thresholdDate)
thresholdDate
- NOT YET DOCUMENTEDpublic static java.util.List getStaleMDPHandles(java.util.Date thresholdDate)
thresholdDate
- NOT YET DOCUMENTEDpublic static InfoXML deleteNDRObject(java.lang.String handle) throws java.lang.Exception
handle
- handle of Object to be deleted.java.lang.Exception
- if NDR object cannot be deletedpublic static InfoXML deleteNDRObject(java.lang.String handle, boolean cascade) throws java.lang.Exception
handle
- handle of Object to be deletedcascade
- flag to delete all dependent objects (not working in
NDR)java.lang.Exception
- if NDR object cannot be deletedpublic static void deleteCollection(java.lang.String collection) throws java.lang.Exception
collection
- collectionKeyjava.lang.Exception
- if NDR objects cannot be deletedpublic static void deleteNDRCollection(java.lang.String mdpHandle) throws java.lang.Exception
mdpHandle
- MetadataProvider object handle.java.lang.Exception
- if NDR objects cannot be deletedpublic static java.util.Date parseDateString(java.lang.String dateStr, java.text.SimpleDateFormat dateFormat)
dateStr
- Date in string form to be converted to a Date ObjectdateFormat
- NOT YET DOCUMENTEDpublic static java.util.Date parseNdrDateString(java.lang.String dateStr)
dateStr
- public static java.util.Date parseSimpleDateString(java.lang.String dateStr)
dateStr
- NOT YET DOCUMENTEDpublic static java.lang.String formattedDate(java.util.Date date)
date
- NOT YET DOCUMENTEDpublic static void pp(org.dom4j.Node node)
node
- NOT YET DOCUMENTEDpublic static void pp(java.lang.String xml)
xml
- NOT YET DOCUMENTEDpublic static void setDebug(boolean bool)
bool
- The new debug valuepublic static void prtln(java.lang.String s, java.lang.String prefix)
s
- NOT YET DOCUMENTEDprefix
- NOT YET DOCUMENTED