Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions ubo-common/src/main/resources/xsl/import/duepublico2mods.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
<xsl:copy-of select="mods:role" />
<xsl:copy-of select="mods:namePart" />
<xsl:apply-templates select="@valueURI" />
<xsl:copy-of select="mods:nameIdentifier[@type='lsf']" />
<xsl:copy-of select="mods:nameIdentifier[@type='gnd']" />
<xsl:copy-of select="mods:nameIdentifier[@type='orcid']" />
<xsl:apply-templates select="mods:nameIdentifier[@type='lsf']" />
<xsl:apply-templates select="mods:nameIdentifier[@type='gnd']" />
<xsl:apply-templates select="mods:nameIdentifier[@type='orcid']" />
</mods:name>
</xsl:template>

Expand Down Expand Up @@ -120,6 +120,12 @@
</xsl:copy>
</xsl:template>

<xsl:template match="mods:nameIdentifier">
<xsl:copy>
<xsl:copy-of select="@type|text()" />
</xsl:copy>
</xsl:template>

<xsl:template match="mods:abstract">
<xsl:if test="string-length(text()) &gt; 0">
<xsl:copy>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.mycore.ubo.importer;

import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.junit.Test;
import org.mycore.common.MCRConstants;
import org.mycore.common.MCRTestCase;
import org.mycore.common.xml.MCRURIResolver;
import org.mycore.common.xsl.MCRLazyStreamSource;

import javax.xml.transform.TransformerException;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class ImportJobTest extends MCRTestCase {

public static final String DUEPUBLICO_IMPORT_CALL = "xslStyle:import/duepublico2mods:resource:ImportJobTest/duepublico_mods_00000001.xml";

/**
* Tests the stylesheet import/duepublico2mods.xsl.
*/
@Test
public void testResolveDuepublico2Mods() throws TransformerException, IOException, JDOMException {
MCRLazyStreamSource content = (MCRLazyStreamSource) MCRURIResolver
.obtainInstance().resolve(DUEPUBLICO_IMPORT_CALL, null);
Element mods = new SAXBuilder().build(content.getInputStream()).getRootElement();
Element duepublicoIdentifier = mods.getChild("identifier", MCRConstants.MODS_NAMESPACE);
assertEquals("duepublico2", duepublicoIdentifier.getAttribute("type").getValue());
assertEquals("duepublico_mods_00000001", duepublicoIdentifier.getText());
Element modsName = mods.getChild("name", MCRConstants.MODS_NAMESPACE);
List<Element> nameIdentifiers = modsName.getChildren("nameIdentifier", MCRConstants.MODS_NAMESPACE);
assertEquals(3, nameIdentifiers.size());

// no other attributes like typeURI
nameIdentifiers.forEach(element -> {
assertEquals(1, element.getAttributes().size());
assertNotNull(element.getAttribute("type"));
});

Set<String> expectedTypes = Set.of("lsf", "gnd", "orcid");
Set<String> actualTypes = nameIdentifiers.stream()
.map(element -> element.getAttributeValue("type"))
.collect(Collectors.toSet());
assertEquals(expectedTypes, actualTypes);

Set<String> expectedValues = Set.of("1000000000", "0000-0000-0000-0001", "00000");
Set<String> actualValues = nameIdentifiers.stream()
.map(Element::getText)
.collect(Collectors.toSet());
assertEquals(expectedValues, actualValues);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<mycoreobject xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="datamodel-mods.xsd" ID="duepublico_mods_00000001">
<metadata>
<def.modsContainer class="MCRMetaXML" heritable="false" notinherit="true">
<modsContainer inherited="0">
<mods:mods xmlns:mods="http://www.loc.gov/mods/v3">
<mods:name type="personal" xlink:type="simple">
<mods:nameIdentifier type="gnd" typeURI="http://d-nb.info/gnd/">1000000000</mods:nameIdentifier>
<mods:nameIdentifier type="viaf" typeURI="http://www.viaf.org/">0000000000000000000001</mods:nameIdentifier>
<mods:nameIdentifier type="lsf" typeURI="https://www.uni-due.de/">00000</mods:nameIdentifier>
<mods:nameIdentifier type="orcid" typeURI="http://orcid.org/">0000-0000-0000-0001</mods:nameIdentifier>
<mods:namePart type="family">Müller</mods:namePart>
<mods:namePart type="given">Peter</mods:namePart>
</mods:name>
</mods:mods>
</modsContainer>
</def.modsContainer>
</metadata>
</mycoreobject>