Commit e4bbe2b6 authored by bourgesl's avatar bourgesl
Browse files

Fixed support for schema 4.1 (xslt for fundingReference / geoLocation) +...

Fixed support for schema 4.1 (xslt for fundingReference / geoLocation) + upgrade metadata in templates
parent dd525ea9
......@@ -161,7 +161,8 @@
<xsl:apply-templates select="./d:subjects"/>
<xsl:apply-templates select="./d:geoLocations"/>
<xsl:apply-templates select="./d:dates"/>
<xsl:apply-templates select="./d:contributors"/>
<xsl:apply-templates select="./d:fundingReferences"/>
<!-- remaining meta data -->
<xsl:apply-templates select="./*[not(local-name() = 'identifier'
......@@ -175,6 +176,8 @@
or local-name() = 'subjects'
or local-name() = 'geoLocations'
or local-name() = 'dates'
or local-name() = 'contributors'
or local-name() = 'fundingReferences'
)]"/>
</tbody>
</table>
......@@ -580,17 +583,24 @@
<xsl:template match="d:geoLocations/d:geoLocation">
<li>
<!-- TODO: tokenize and display properly point and box -->
<xsl:choose>
<xsl:when test="d:geoLocationPlace">
<xsl:value-of select="d:geoLocationPlace" />
</xsl:when>
<xsl:when test="d:geoLocationPoint">
<xsl:value-of select="d:geoLocationPoint" />
<xsl:value-of select="d:geoLocationPoint/d:pointLatitude" />
<xsl:text> </xsl:text>
<xsl:value-of select="d:geoLocationPoint/d:pointLongitude" />
<xsl:text> (N. E.)</xsl:text>
</xsl:when>
<xsl:when test="d:geoLocationBox">
<xsl:value-of select="d:geoLocationBox" />
<xsl:value-of select="d:geoLocationBox/d:southBoundLatitude" />
<xsl:text> </xsl:text>
<xsl:value-of select="d:geoLocationBox/d:westBoundLongitude" />
<xsl:text> </xsl:text>
<xsl:value-of select="d:geoLocationBox/d:northBoundLatitude" />
<xsl:text> </xsl:text>
<xsl:value-of select="d:geoLocationBox/d:eastBoundLongitude" />
<xsl:text> (S. W. N. E.)</xsl:text>
</xsl:when>
</xsl:choose>
......@@ -598,6 +608,33 @@
</xsl:template>
<!-- 7. FundingReference(s) -->
<xsl:template match="d:fundingReferences">
<tr>
<th class="flabel" colspan="2">Funding References</th>
</tr>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="d:fundingReferences/d:fundingReference">
<tr class="no-border">
<td/>
<td>
<xsl:value-of select="d:funderName"/>
<xsl:if test="./d:awardTitle">
:<b>
<br/>
<xsl:value-of select="./d:awardTitle/text()" />
<xsl:text> (</xsl:text>
<xsl:value-of select="./d:awardNumber/text()" />
<xsl:text>)</xsl:text>
</b>
</xsl:if>
</td>
</tr>
</xsl:template>
<!-- utility templates -->
......
......@@ -377,12 +377,50 @@
<xsl:if test="text()">
<geoLocation>
<xsl:element name="{@key}">
<xsl:value-of select="text()"/>
<xsl:choose>
<xsl:when test="@key = 'geoLocationPoint' or @key = 'geoLocationBox'">
<xsl:variable name="tokens">
<xsl:call-template name="split">
<xsl:with-param name="string" select="text()"/>
<xsl:with-param name="pattern" select="' '" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="nodes" select="exsl:node-set($tokens)/token"/>
<xsl:choose>
<xsl:when test="@key = 'geoLocationPoint'">
<pointLatitude>
<xsl:value-of select="$nodes[1]/text()"/>
</pointLatitude>
<pointLongitude>
<xsl:value-of select="$nodes[2]/text()"/>
</pointLongitude>
</xsl:when>
<xsl:when test="@key = 'geoLocationBox'">
<southBoundLatitude>
<xsl:value-of select="$nodes[1]/text()"/>
</southBoundLatitude>
<westBoundLongitude>
<xsl:value-of select="$nodes[2]/text()"/>
</westBoundLongitude>
<northBoundLatitude>
<xsl:value-of select="$nodes[3]/text()"/>
</northBoundLatitude>
<eastBoundLongitude>
<xsl:value-of select="$nodes[4]/text()"/>
</eastBoundLongitude>
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</geoLocation>
</xsl:if>
</xsl:template>
<!-- fundingReference (4.0) -->
<xsl:template match="property" mode="funder">
<xsl:if test="text()">
<fundingReference>
......@@ -426,6 +464,7 @@
</xsl:if>
</xsl:template>
<!-- fundingReference attributes (4.0) -->
<xsl:template match="attribute" mode="awardNumber">
<xsl:if test="text()">
<awardNumber>
......@@ -442,4 +481,61 @@
</xsl:if>
</xsl:template>
<!-- split pattern -->
<xsl:template name="split">
<xsl:param name="string" select="''" />
<xsl:param name="pattern" select="' '" />
<xsl:choose>
<xsl:when test="not($string)" />
<xsl:when test="not($pattern)">
<xsl:call-template name="_split-characters">
<xsl:with-param name="string" select="$string" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="_split-pattern">
<xsl:with-param name="string" select="$string" />
<xsl:with-param name="pattern" select="$pattern" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="_split-characters">
<xsl:param name="string" />
<xsl:if test="$string">
<token>
<xsl:value-of select="substring($string, 1, 1)" />
</token>
<xsl:call-template name="_split-characters">
<xsl:with-param name="string" select="substring($string, 2)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="_split-pattern">
<xsl:param name="string" />
<xsl:param name="pattern" />
<xsl:choose>
<xsl:when test="contains($string, $pattern)">
<xsl:if test="not(starts-with($string, $pattern))">
<token>
<xsl:value-of select="substring-before($string, $pattern)" />
</token>
</xsl:if>
<xsl:call-template name="_split-pattern">
<xsl:with-param name="string" select="substring-after($string, $pattern)" />
<xsl:with-param name="pattern" select="$pattern" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<token>
<xsl:value-of select="$string" />
</token>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
......@@ -15,7 +15,7 @@ public interface Const {
public final static float F_SCHEMA_VERSION_4_1 = Float.valueOf(SCHEMA_VERSION_4_1);
/** datacite schema version '3.1' or '4.1' */
public final static String SCHEMA_VERSION = SCHEMA_VERSION_3_1;
public final static String SCHEMA_VERSION = SCHEMA_VERSION_4_1;
public final static float F_SCHEMA_VERSION = Float.valueOf(SCHEMA_VERSION);
public final static String DOI_PREFIX_TEST = "10.5072";
......
......@@ -40,6 +40,9 @@ public final class DoiTemplates {
logger.debug("initialize: [{}] \n{}", data.getFilePath(), data);
}
// Upgrade metadata:
ProcessPipeline.upgradeData(data, templatePath);
final String doiId = data.getDoiId();
if (doiId != null) {
final DoiCsvData prevData = identifiers.put(doiId, data);
......
......@@ -254,7 +254,7 @@ public final class ProcessPipeline extends AbstractPipeline<ProcessPipelineData>
}
// Upgrade metadata:
upgradeData(data, doiData);
upgradeData(data, doiData.getDoiId());
// Validate metadata:
validateData(projectConfig, data, doiData);
......@@ -458,9 +458,9 @@ public final class ProcessPipeline extends AbstractPipeline<ProcessPipelineData>
pipeData.addRefs(doiData.getDoiId(), refs);
}
private void upgradeData(final DoiCsvData data, final ProcessPipelineDoiData doiData) throws IOException {
public static void upgradeData(final DoiCsvData data, final String id) throws IOException {
if (Const.F_SCHEMA_VERSION >= Const.F_SCHEMA_VERSION_4_1) {
logger.debug("upgradeData [{}] to schema {}", doiData.getDoiId(), Const.SCHEMA_VERSION);
logger.debug("upgradeData[{}] to schema {}", id, Const.SCHEMA_VERSION);
for (ListIterator<String[]> it = data.getRows().listIterator(); it.hasNext();) {
String[] cols = it.next();
......@@ -470,7 +470,7 @@ public final class ProcessPipeline extends AbstractPipeline<ProcessPipelineData>
// Convert 'contributorName:Funder' (deprecated ContributorType=Funder) to 'funderName' (fundingReference)
if (Const.KEY_CONTRIBUTOR_FUNDER_NAME.equals(key)) {
if (cols.length > 2) {
logger.warn("upgradeData [{}] : Complex Contributor::Funder = {}", Arrays.toString(cols));
logger.warn("upgradeData[{}] : Complex Contributor::Funder = {}", Arrays.toString(cols));
// trim (optional attributes like affiliation or orcid)
final String value = cols[1];
cols = new String[2];
......@@ -478,12 +478,11 @@ public final class ProcessPipeline extends AbstractPipeline<ProcessPipelineData>
}
cols[0] = Const.KEY_FUNDER_NAME;
logger.info("upgradeData [{}]: Fixed Funder = {}", doiData.getDoiId(), cols[1]);
logger.info("upgradeData[{}]: Fixed Funder: '{}'", id, cols[1]);
it.set(cols);
}
}
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment