Skip to content

Commit

Permalink
EASY-2607: convert relations with xsi-type (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanheest authored Feb 12, 2020
1 parent e718211 commit 25fc022
Show file tree
Hide file tree
Showing 19 changed files with 267 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,51 @@ private void putRelationHandlers() {
map.put("/dcterms:isFormatOf", new TermsIsFormatOfHandler());
map.put("/dcterms:hasFormat", new TermsHasFormatHandler());

map.put("ISBN/dcterms:relation", new DcRelationHandler("ISBN"));
map.put("ISBN/dcterms:conformsTo", new TermsConformsToHandler("ISBN"));
map.put("ISBN/dcterms:isVersionOf", new TermsIsVersionOfHandler("ISBN"));
map.put("ISBN/dcterms:hasVersion", new TermsHasVersionHandler("ISBN"));
map.put("ISBN/dcterms:isReplacedBy", new TermsIsReplacedByHandler("ISBN"));
map.put("ISBN/dcterms:replaces", new TermsReplacesHandler("ISBN"));
map.put("ISBN/dcterms:isRequiredBy", new TermsIsRequiredByHandler("ISBN"));
map.put("ISBN/dcterms:requires", new TermsRequiresHandler("ISBN"));
map.put("ISBN/dcterms:isPartOf", new TermsIsPartOfHandler("ISBN"));
map.put("ISBN/dcterms:hasPart", new TermsHasPartHandler("ISBN"));
map.put("ISBN/dcterms:isReferencedBy", new TermsIsReferencedByHandler("ISBN"));
map.put("ISBN/dcterms:references", new TermsReferencesHandler("ISBN"));
map.put("ISBN/dcterms:isFormatOf", new TermsIsFormatOfHandler("ISBN"));
map.put("ISBN/dcterms:hasFormat", new TermsHasFormatHandler("ISBN"));

map.put("ISSN/dcterms:relation", new DcRelationHandler("ISSN"));
map.put("ISSN/dcterms:conformsTo", new TermsConformsToHandler("ISSN"));
map.put("ISSN/dcterms:isVersionOf", new TermsIsVersionOfHandler("ISSN"));
map.put("ISSN/dcterms:hasVersion", new TermsHasVersionHandler("ISSN"));
map.put("ISSN/dcterms:isReplacedBy", new TermsIsReplacedByHandler("ISSN"));
map.put("ISSN/dcterms:replaces", new TermsReplacesHandler("ISSN"));
map.put("ISSN/dcterms:isRequiredBy", new TermsIsRequiredByHandler("ISSN"));
map.put("ISSN/dcterms:requires", new TermsRequiresHandler("ISSN"));
map.put("ISSN/dcterms:isPartOf", new TermsIsPartOfHandler("ISSN"));
map.put("ISSN/dcterms:hasPart", new TermsHasPartHandler("ISSN"));
map.put("ISSN/dcterms:isReferencedBy", new TermsIsReferencedByHandler("ISSN"));
map.put("ISSN/dcterms:references", new TermsReferencesHandler("ISSN"));
map.put("ISSN/dcterms:isFormatOf", new TermsIsFormatOfHandler("ISSN"));
map.put("ISSN/dcterms:hasFormat", new TermsHasFormatHandler("ISSN"));

map.put("NWO-PROJECTNR/dcterms:relation", new DcRelationHandler("NWO-PROJECTNR"));
map.put("NWO-PROJECTNR/dcterms:conformsTo", new TermsConformsToHandler("NWO-PROJECTNR"));
map.put("NWO-PROJECTNR/dcterms:isVersionOf", new TermsIsVersionOfHandler("NWO-PROJECTNR"));
map.put("NWO-PROJECTNR/dcterms:hasVersion", new TermsHasVersionHandler("NWO-PROJECTNR"));
map.put("NWO-PROJECTNR/dcterms:isReplacedBy", new TermsIsReplacedByHandler("NWO-PROJECTNR"));
map.put("NWO-PROJECTNR/dcterms:replaces", new TermsReplacesHandler("NWO-PROJECTNR"));
map.put("NWO-PROJECTNR/dcterms:isRequiredBy", new TermsIsRequiredByHandler("NWO-PROJECTNR"));
map.put("NWO-PROJECTNR/dcterms:requires", new TermsRequiresHandler("NWO-PROJECTNR"));
map.put("NWO-PROJECTNR/dcterms:isPartOf", new TermsIsPartOfHandler("NWO-PROJECTNR"));
map.put("NWO-PROJECTNR/dcterms:hasPart", new TermsHasPartHandler("NWO-PROJECTNR"));
map.put("NWO-PROJECTNR/dcterms:isReferencedBy", new TermsIsReferencedByHandler("NWO-PROJECTNR"));
map.put("NWO-PROJECTNR/dcterms:references", new TermsReferencesHandler("NWO-PROJECTNR"));
map.put("NWO-PROJECTNR/dcterms:isFormatOf", new TermsIsFormatOfHandler("NWO-PROJECTNR"));
map.put("NWO-PROJECTNR/dcterms:hasFormat", new TermsHasFormatHandler("NWO-PROJECTNR"));

map.put("/ddm:relation", new DdmRelationHandler());
map.put("/ddm:conformsTo", new DdmConformsToHandler());
map.put("/ddm:isVersionOf", new DdmIsVersionOfHandler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,26 @@
import org.xml.sax.SAXException;

public abstract class BasicIdentifierHandler extends CrosswalkHandler<EasyMetadata> {

private final String scheme;

public BasicIdentifierHandler() {
this(null);
}

public BasicIdentifierHandler(String scheme) {
super();
this.scheme = scheme;
}

protected BasicIdentifier createIdentifier(final String uri, final String localName) throws SAXException {
final String value = getCharsSinceStart().trim();
if (value.length() != 0) {
try {
return new BasicIdentifier(value.trim());
BasicIdentifier identifier = new BasicIdentifier(value.trim());
if (scheme != null)
identifier.setScheme(scheme);
return identifier;
}
catch (final InvalidLanguageTokenException e) {
error(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,33 @@
package nl.knaw.dans.pf.language.ddm.relationhandlers;

import nl.knaw.dans.pf.language.ddm.handlertypes.BasicStringHandler;
import nl.knaw.dans.pf.language.emd.types.BasicIdentifier;
import nl.knaw.dans.pf.language.emd.types.BasicString;
import org.xml.sax.SAXException;

public class DcRelationHandler extends BasicStringHandler {

private final String scheme;

public DcRelationHandler() {
this(null);
}

public DcRelationHandler(String scheme) {
this.scheme = scheme;
}

@Override
public void finishElement(final String uri, final String localName) throws SAXException {
final BasicString relation = createBasicString(uri, localName);
if (relation != null)
if (relation != null) {
this.setScheme(relation);
getTarget().getEmdRelation().getDcRelation().add(relation);
}
}

protected void setScheme(BasicString relation) {
if (scheme != null)
relation.setScheme(scheme);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
import nl.knaw.dans.pf.language.emd.types.BasicIdentifier;

public class TermsConformsToHandler extends BasicIdentifierHandler {

public TermsConformsToHandler() {
this(null);
}

public TermsConformsToHandler(String scheme) {
super(scheme);
}

@Override
public void finishElement(final String uri, final String localName) throws SAXException {
final BasicIdentifier relation = createIdentifier(uri, localName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
import nl.knaw.dans.pf.language.emd.types.BasicIdentifier;

public class TermsHasFormatHandler extends BasicIdentifierHandler {

public TermsHasFormatHandler() {
this(null);
}

public TermsHasFormatHandler(String scheme) {
super(scheme);
}

@Override
public void finishElement(final String uri, final String localName) throws SAXException {
final BasicIdentifier relation = createIdentifier(uri, localName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
import nl.knaw.dans.pf.language.emd.types.BasicIdentifier;

public class TermsHasPartHandler extends BasicIdentifierHandler {

public TermsHasPartHandler() {
this(null);
}

public TermsHasPartHandler(String scheme) {
super(scheme);
}

@Override
public void finishElement(final String uri, final String localName) throws SAXException {
final BasicIdentifier relation = createIdentifier(uri, localName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
import nl.knaw.dans.pf.language.emd.types.BasicIdentifier;

public class TermsHasVersionHandler extends BasicIdentifierHandler {

public TermsHasVersionHandler() {
this(null);
}

public TermsHasVersionHandler(String scheme) {
super(scheme);
}

@Override
public void finishElement(final String uri, final String localName) throws SAXException {
final BasicIdentifier relation = createIdentifier(uri, localName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
import nl.knaw.dans.pf.language.emd.types.BasicIdentifier;

public class TermsIsFormatOfHandler extends BasicIdentifierHandler {

public TermsIsFormatOfHandler() {
this(null);
}

public TermsIsFormatOfHandler(String scheme) {
super(scheme);
}

@Override
public void finishElement(final String uri, final String localName) throws SAXException {
final BasicIdentifier relation = createIdentifier(uri, localName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
import nl.knaw.dans.pf.language.emd.types.BasicIdentifier;

public class TermsIsPartOfHandler extends BasicIdentifierHandler {

public TermsIsPartOfHandler() {
this(null);
}

public TermsIsPartOfHandler(String scheme) {
super(scheme);
}

@Override
public void finishElement(final String uri, final String localName) throws SAXException {
final BasicIdentifier relation = createIdentifier(uri, localName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
import nl.knaw.dans.pf.language.emd.types.BasicIdentifier;

public class TermsIsReferencedByHandler extends BasicIdentifierHandler {

public TermsIsReferencedByHandler() {
this(null);
}

public TermsIsReferencedByHandler(String scheme) {
super(scheme);
}

@Override
public void finishElement(final String uri, final String localName) throws SAXException {
final BasicIdentifier relation = createIdentifier(uri, localName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
import nl.knaw.dans.pf.language.emd.types.BasicIdentifier;

public class TermsIsReplacedByHandler extends BasicIdentifierHandler {

public TermsIsReplacedByHandler() {
this(null);
}

public TermsIsReplacedByHandler(String scheme) {
super(scheme);
}

@Override
public void finishElement(final String uri, final String localName) throws SAXException {
final BasicIdentifier relation = createIdentifier(uri, localName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
import nl.knaw.dans.pf.language.emd.types.BasicIdentifier;

public class TermsIsRequiredByHandler extends BasicIdentifierHandler {

public TermsIsRequiredByHandler() {
this(null);
}

public TermsIsRequiredByHandler(String scheme) {
super(scheme);
}

@Override
public void finishElement(final String uri, final String localName) throws SAXException {
final BasicIdentifier relation = createIdentifier(uri, localName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
import org.xml.sax.SAXException;

public class TermsIsVersionOfHandler extends BasicIdentifierHandler {

public TermsIsVersionOfHandler() {
this(null);
}

public TermsIsVersionOfHandler(String scheme) {
super(scheme);
}

@Override
public void finishElement(final String uri, final String localName) throws SAXException {
final BasicIdentifier relation = createIdentifier(uri, localName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
import nl.knaw.dans.pf.language.emd.types.BasicIdentifier;

public class TermsReferencesHandler extends BasicIdentifierHandler {

public TermsReferencesHandler() {
this(null);
}

public TermsReferencesHandler(String scheme) {
super(scheme);
}

@Override
public void finishElement(final String uri, final String localName) throws SAXException {
final BasicIdentifier relation = createIdentifier(uri, localName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
import nl.knaw.dans.pf.language.emd.types.BasicIdentifier;

public class TermsReplacesHandler extends BasicIdentifierHandler {

public TermsReplacesHandler() {
this(null);
}

public TermsReplacesHandler(String scheme) {
super(scheme);
}

@Override
public void finishElement(final String uri, final String localName) throws SAXException {
final BasicIdentifier relation = createIdentifier(uri, localName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
import nl.knaw.dans.pf.language.emd.types.BasicIdentifier;

public class TermsRequiresHandler extends BasicIdentifierHandler {

public TermsRequiresHandler() {
this(null);
}

public TermsRequiresHandler(String scheme) {
super(scheme);
}

@Override
public void finishElement(final String uri, final String localName) throws SAXException {
final BasicIdentifier relation = createIdentifier(uri, localName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public static Collection<Object[]> data() {
{ "languageWithSchemeAndIdToEmdCode" },
{ "license" },
{ "normalRelation" },
{ "relations" },
{ "SMP.char" },
{ "SMP.char.many" },
{ "spatialBox" },
Expand Down
25 changes: 25 additions & 0 deletions src/test/resources/ddm2emdCrosswalk/relations.input.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version='1.0' encoding='utf-8'?>
<ddm:DDM xsi:schemaLocation="http://easy.dans.knaw.nl/schemas/md/ddm/ https://easy.dans.knaw.nl/schemas/md/ddm/ddm.xsd"
xmlns:ddm="http://easy.dans.knaw.nl/schemas/md/ddm/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ddm:dcmiMetadata>
<ddm:references scheme="id-type:DOI" href="https://doi.org/10.17026/test-doi-related-identifier">10.17026/test-doi-related-identifier</ddm:references>
<ddm:replaces scheme="id-type:URN" href="http://persistent-identifier.nl/urn:nbn:nl:ui:test-urn-related-identifier">
urn:nbn:nl:ui:test-urn-related-identifier
</ddm:replaces>
<dcterms:requires xsi:type="id-type:ISBN">my-isbn-related-identifier</dcterms:requires>
<dcterms:hasVersion xsi:type="id-type:ISSN">my-issn-related-identifier</dcterms:hasVersion>
<dcterms:isFormatOf xsi:type="id-type:NWO-PROJECTNR">my-nwo-related-identifier</dcterms:isFormatOf>
<dcterms:isPartOf>my own related identifier</dcterms:isPartOf>
<ddm:relation xml:lang="eng" href="https://www.google.com">Google</ddm:relation>
<ddm:isFormatOf scheme="id-type:DOI" href="https://doi.org/10.17026/test-doi-alternative-identifier">10.17026/test-doi-alternative-identifier</ddm:isFormatOf>
<ddm:isFormatOf scheme="id-type:URN" href="http://persistent-identifier.nl/urn:nbn:nl:ui:test-urn-alternative-identifier">
urn:nbn:nl:ui:test-urn-alternative-identifier
</ddm:isFormatOf>
<dcterms:isFormatOf xsi:type="id-type:ISBN">my-isbn-alternative-identifier</dcterms:isFormatOf>
<dcterms:isFormatOf xsi:type="id-type:ISSN">my-issn-alternative-identifier</dcterms:isFormatOf>
<dcterms:isFormatOf xsi:type="id-type:NWO-PROJECTNR">my-nwo-alternative-identifier</dcterms:isFormatOf>
<dcterms:isFormatOf>my own alternative identifier</dcterms:isFormatOf>
</ddm:dcmiMetadata>
</ddm:DDM>
Loading

0 comments on commit 25fc022

Please sign in to comment.