Merge pull request #621 from umd-lib/ezid-metadata-mapping

DS-2119. EZID IdentifierProvider Metadata Mapping.
In the interest of time, merging this despite a problem with the transform, for which I already have a solution.  A separate PR will provide that solution.
This commit is contained in:
Mark H. Wood
2014-11-06 11:08:45 -05:00
4 changed files with 160 additions and 12 deletions

View File

@@ -0,0 +1,105 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.identifier;
import org.apache.log4j.Logger;
import org.dspace.content.DSpaceObject;
import org.dspace.content.crosswalk.DisseminationCrosswalk;
import org.dspace.core.PluginManager;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
/**
* Provide XML based metadata crosswalk for EZID Identifier provider module.
*
* @author mohideen
*/
public class DataCiteXMLCreator
{
/** log4j category */
private static Logger log = Logger.getLogger(DataCiteXMLCreator.class);
/**
* Name of crosswalk to convert metadata into DataCite Metadata Scheme.
*/
protected String CROSSWALK_NAME = "DataCite";
/**
* DisseminationCrosswalk to map local metadata into DataCite metadata. The
* name of the crosswalk is set by {@link setDisseminationCrosswalk(String)
* setDisseminationCrosswalk} which instantiates the crosswalk.
*/
protected DisseminationCrosswalk xwalk;
public String getXMLString(DSpaceObject dso)
{
if (dso == null)
{
log.info("Invalid object: " + dso);
return null;
}
this.prepareXwalk();
if (!this.xwalk.canDisseminate(dso))
{
log.error("Crosswalk " + this.CROSSWALK_NAME
+ " cannot disseminate DSO with type " + dso.getType()
+ " and ID " + dso.getID() + ".");
return null;
}
Element root = null;
try
{
root = xwalk.disseminateElement(dso);
}
catch (Exception e)
{
log.error(
"Exception while crosswolking DSO " + "with type "
+ dso.getType() + " and ID " + dso.getID() + ".", e);
return null;
}
XMLOutputter xOut = new XMLOutputter();
return xOut.outputString(root);
}
/**
* Set the name of the dissemination crosswalk used to convert the metadata
* into DataCite Metadata Schema. Used by spring dependency injection.
*
* @param CROSSWALK_NAME
* The name of the dissemination crosswalk to use.
*/
public void setDisseminationCrosswalkName(String CROSSWALK_NAME)
{
this.CROSSWALK_NAME = CROSSWALK_NAME;
}
protected void prepareXwalk()
{
if (null != this.xwalk)
return;
this.xwalk = (DisseminationCrosswalk) PluginManager.getNamedPlugin(
DisseminationCrosswalk.class, this.CROSSWALK_NAME);
if (this.xwalk == null)
{
throw new RuntimeException("Can't find crosswalk '"
+ CROSSWALK_NAME + "'!");
}
}
}

View File

@@ -53,16 +53,25 @@ import org.springframework.beans.factory.annotation.Required;
* *
* <p>Then there are properties injected using Spring:</p> * <p>Then there are properties injected using Spring:</p>
* <ul> * <ul>
* <li>There is a Map (with the property name "crosswalk") from EZID * <li>There is a Map (with the property name "crosswalk") from EZID metadata
* metadata field names into DSpace field names, injected by Spring. Specify * field names into DSpace field names, injected by Spring. Specify the
* the fully-qualified names of all metadata fields to be looked up on a DSpace * fully-qualified names of all metadata fields to be looked up on a DSpace
* object and their values set on mapped fully-qualified names in the object's * object and their values set on mapped fully-qualified names in the object's
* DataCite metadata.</li> * DataCite metadata.</li>
* *
* <li>A second map ("crosswalkTransform") provides Transform instances * <li>A second map ("crosswalkTransform") provides Transform instances mapped
* mapped from EZID metadata field names. This allows the crosswalk to rewrite * from EZID metadata field names. This allows the crosswalk to rewrite field
* field values where the form maintained by DSpace is not directly usable in * values where the form maintained by DSpace is not directly usable in EZID
* EZID metadata.</li> * metadata.</li>
*
* <li>Optional: A boolean property ("generateDataciteXML") that controls the
* creation and inclusion of DataCite xml schema during the metadata
* crosswalking. The default "DataCite" dissemination plugin uses
* DIM2DataCite.xsl for crosswalking. Default value: false.</li>
*
* <li>Optional: A string property ("disseminationCrosswalkName") that can be
* used to set the name of the dissemination crosswalk plugin for metadata
* crosswalking. Default value: "DataCite".</li>
* </ul> * </ul>
* *
* @author mwood * @author mwood
@@ -90,6 +99,10 @@ public class EZIDIdentifierProvider
private static final String DOI_SCHEME = "doi:"; private static final String DOI_SCHEME = "doi:";
protected boolean GENERATE_DATACITE_XML = false;
protected String DATACITE_XML_CROSSWALK = "DataCite";
/** Map DataCite metadata into local metadata. */ /** Map DataCite metadata into local metadata. */
private static Map<String, String> crosswalk = new HashMap<>(); private static Map<String, String> crosswalk = new HashMap<>();
@@ -592,8 +605,17 @@ public class EZIDIdentifierProvider
} }
} }
if (GENERATE_DATACITE_XML == true)
{
DataCiteXMLCreator xmlGen = new DataCiteXMLCreator();
xmlGen.setDisseminationCrosswalkName(DATACITE_XML_CROSSWALK);
String xmlString = xmlGen.getXMLString(dso);
mapped.put("datacite", xmlString);
}
// Supply a default publisher, if the Item has none. // Supply a default publisher, if the Item has none.
if (!mapped.containsKey(DATACITE_PUBLISHER)) if (!mapped.containsKey(DATACITE_PUBLISHER)
&& !mapped.containsKey("datacite"))
{ {
String publisher = configurationService.getPropertyAsType(CFG_PUBLISHER, "unknown"); String publisher = configurationService.getPropertyAsType(CFG_PUBLISHER, "unknown");
log.info("Supplying default publisher: {}", publisher); log.info("Supplying default publisher: {}", publisher);
@@ -601,7 +623,8 @@ public class EZIDIdentifierProvider
} }
// Supply current year as year of publication, if the Item has none. // Supply current year as year of publication, if the Item has none.
if (!mapped.containsKey(DATACITE_PUBLICATION_YEAR)) if (!mapped.containsKey(DATACITE_PUBLICATION_YEAR)
&& !mapped.containsKey("datacite"))
{ {
String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
log.info("Supplying default publication year: {}", year); log.info("Supplying default publication year: {}", year);
@@ -625,6 +648,16 @@ public class EZIDIdentifierProvider
transforms = transformMap; transforms = transformMap;
} }
public void setGenerateDataciteXML(boolean GENERATE_DATACITE_XML)
{
this.GENERATE_DATACITE_XML = GENERATE_DATACITE_XML;
}
public void setDisseminationCrosswalkName(String DATACITE_XML_CROSSWALK)
{
this.DATACITE_XML_CROSSWALK = DATACITE_XML_CROSSWALK;
}
@Required @Required
public static void setRequestFactory(EZIDRequestFactory aRequestFactory) public static void setRequestFactory(EZIDRequestFactory aRequestFactory)
{ {

View File

@@ -838,6 +838,8 @@ org.dspace.app.batchitemimport.work.dir = ${dspace.dir}/imports
#identifier.doi.ezid.user = apitest #identifier.doi.ezid.user = apitest
#identifier.doi.ezid.password = apitest #identifier.doi.ezid.password = apitest
# A default publisher, for Items not previously published. # A default publisher, for Items not previously published.
# (If generateDataciteXML bean property is enabled. Set default publisher in the
# XSL file configured by: crosswalk.dissemination.DataCite.stylesheet file.)
#identifier.doi.ezid.publisher = a publisher #identifier.doi.ezid.publisher = a publisher

View File

@@ -67,6 +67,11 @@
<!-- Provider to mint and register DOIs using EZID as the registrar. <!-- Provider to mint and register DOIs using EZID as the registrar.
--> -->
<!--
Set generateDataciteXML to true to send metadata in DataCite xml schema for EZID DOI mint requests.
When generateDataciteXML is enabled, EZIDIdentifierProvider uses
dspace.cfg:crosswalk.dissemination.DataCite.stylesheet XSL configuration for metadata mapping
-->
<!-- Uncomment to enable DOI using EZID <!-- Uncomment to enable DOI using EZID
<bean id="org.dspace.identifier.EZIDIdentifierProvider" <bean id="org.dspace.identifier.EZIDIdentifierProvider"
class="org.dspace.identifier.EZIDIdentifierProvider" class="org.dspace.identifier.EZIDIdentifierProvider"
@@ -97,6 +102,9 @@
</entry> </entry>
</map> </map>
</property> </property>
<property name='generateDataciteXML' value='false'/>
<property name='disseminationCrosswalkName' value='DataCite'/>
</bean> </bean>
--> -->