Commit 88be6135 authored by Gerrit Hübbers's avatar Gerrit Hübbers 🃏
Browse files

Introduce internal.dda.flags filteraway concept

parent 90daa216
......@@ -182,23 +182,32 @@ public class XsltTransformerOaiPmhBundlesStreamSource implements BundlesStreamSo
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
InputStream convertedXmlInputStream = new ByteArrayInputStream(xsltConvertedXmlOutput.getBytes(StandardCharsets.UTF_8) );
Bundle currentPartBundle = (Bundle) unmarshaller.unmarshal(convertedXmlInputStream);
bundleMetadata.addAll( currentPartBundle.getMetadata() );
// STEP 4: extract lastModifiedDate
StringReader sr = new StringReader(getRecordXmlDocumentResponseString);
//LOG.info("sr=\n{}", getRecordXmlDocumentResponseString);
JAXBContext oaiPmhjaxbContext = JAXBContext.newInstance(OAIPMHtype.class);
Unmarshaller oaiPmhUnmarshaller = oaiPmhjaxbContext.createUnmarshaller();
boolean shallFilterAway = currentPartBundle.getMetadata().stream().anyMatch(m -> "internal.dda.flags".equals( m.getKey() ) && m.getValue().contains("filteraway") );
if (shallFilterAway) {
resultBundle = null;
}
else {
Set<Metadatum> filteredMetadata = currentPartBundle.getMetadata().stream().filter(m -> !"internal.dda.flags".equals( m.getKey() )).collect(Collectors.toSet() );
bundleMetadata.addAll( filteredMetadata );
// STEP 4: extract lastModifiedDate
StringReader sr = new StringReader(getRecordXmlDocumentResponseString);
//LOG.info("sr=\n{}", getRecordXmlDocumentResponseString);
JAXBContext oaiPmhjaxbContext = JAXBContext.newInstance(OAIPMHtype.class);
Unmarshaller oaiPmhUnmarshaller = oaiPmhjaxbContext.createUnmarshaller();
@SuppressWarnings("unchecked")
JAXBElement<OAIPMHtype> wrappedResponseObject = (JAXBElement<OAIPMHtype>) oaiPmhUnmarshaller.unmarshal(sr);
OAIPMHtype response = wrappedResponseObject.getValue();
lastModifiedString = response.getGetRecord().getRecord().getHeader().getDatestamp();
// STEP 5: add identifier metadatum
Metadatum reference = new SimpleMetadatum("internal.dda.reference", oaiPmhEndpoint + "@@" + oaiPmhIdentifier);
bundleMetadata.add(reference);
resultBundle = BundleBuilder.create().withMetadata(bundleMetadata).withLastModifiedString(lastModifiedString).build();
}
@SuppressWarnings("unchecked")
JAXBElement<OAIPMHtype> wrappedResponseObject = (JAXBElement<OAIPMHtype>) oaiPmhUnmarshaller.unmarshal(sr);
OAIPMHtype response = wrappedResponseObject.getValue();
lastModifiedString = response.getGetRecord().getRecord().getHeader().getDatestamp();
// STEP 5: add identifier metadatum
Metadatum reference = new SimpleMetadatum("internal.dda.reference", oaiPmhEndpoint + "@@" + oaiPmhIdentifier);
bundleMetadata.add(reference);
resultBundle = BundleBuilder.create().withMetadata(bundleMetadata).withLastModifiedString(lastModifiedString).build();
}
}
......
......@@ -2,6 +2,7 @@ package org.gesis.dda.publishing.domain.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
......@@ -650,17 +651,41 @@ public class XsltTransformerOaiPmhBundlesStreamSourceTest {
assertTrue( metadata.contains( new SimpleMetadatum("dc.identifier.doi", "https://doi.org/10.12924/johs2013.09010004") ) );
assertTrue( metadata.contains( new SimpleMetadatum("internal.dda.reference", "http://www.librelloph.com/journalofhumansecurity/oai/@@oai:ojs.www.librelloph.com:article/18") ) );
assertTrue( metadata.contains( new SimpleMetadatum("dc.publisher.country", "CHE") ) );
assertFalse( metadata.stream().anyMatch(m -> m.getKey().equals("internal.dda.flags")) );
LOG.info("---------------------------------------");
bundle = bss.getBundle("oai:ojs.www.librelloph.com:article/320");
bundle = bss.getBundle("oai:ojs.www.librelloph.com:article/252");
LOG.info("{}", bundle);
metadata = bundle.getMetadata();
metadata.stream().map(Object::toString).forEach(LOG::info);
assertTrue( metadata.contains( new SimpleMetadatum("dc.title", "en", "Editorial Volume 13") ) );
assertTrue( metadata.contains( new SimpleMetadatum("dc.title", "en", "Review of On-Scene Management of Mass-Casualty Attacks") ) );
assertTrue( metadata.contains( new SimpleMetadatum("dc.description.review", "2") ) );
assertEquals(1, metadata.stream().filter(m -> m.getKey().equals("dc.description.review") ).count() );
}
@Test
public void filterAwayUninterestingJohsPublications() throws IOException {
Map<String, String> map = new HashMap<>();
String xMetaDissPlusXsltString = IOUtils.toString(
getClass().
getClassLoader().
getResourceAsStream("xslt/johs-nlm-2-xmlbundle.xslt"), StandardCharsets.UTF_8);
map.put("nlm", xMetaDissPlusXsltString);
String oaiDcXsltString = IOUtils.toString(
getClass().
getClassLoader().
getResourceAsStream("xslt/johs-oai_dc-2-xmlbundle.xslt"), StandardCharsets.UTF_8);
map.put("oai_dc", oaiDcXsltString);
XsltTransformerOaiPmhBundlesStreamSource bss = new XsltTransformerOaiPmhBundlesStreamSource("http://www.librelloph.com/journalofhumansecurity/oai/", map);
Bundle bundle = bss.getBundle("oai:ojs.www.librelloph.com:article/138");
assertNull(bundle);
}
@Test
public void getSinglePublicationCis() throws IOException {
Map<String, String> map = new HashMap<>();
......
......@@ -78,6 +78,12 @@
<xsl:with-param name="value" select="'CHE'"/>
</xsl:call-template>
<xsl:call-template name="new-metadatum">
<xsl:with-param name="key" select="'ssoar.urn.registration'"/>
<xsl:with-param name="language" select="''"/>
<xsl:with-param name="value" select="'false'"/>
</xsl:call-template>
</xsl:element>
</xsl:element>
</xsl:template>
......@@ -210,7 +216,7 @@
<!-- guard against multiple set assignments such as 'journalofhumansecurity:ART' AND 'driver' -->
<xsl:if test="starts-with( text(), 'journalofhumansecurity:' )">
<xsl:choose>
<xsl:when test="text() = 'journalofhumansecurity:ART'">
<xsl:when test="contains( text(), 'journalofhumansecurity:ART' )">
<xsl:call-template name="new-metadatum">
<xsl:with-param name="key" select="'dc.description.review'"/>
<xsl:with-param name="language" select="''"/>
......@@ -225,6 +231,14 @@
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="contains( text(), 'journalofhumansecurity:EDT' )">
<!-- we are not interested in editorials -->
<xsl:call-template name="new-metadatum">
<xsl:with-param name="key" select="'internal.dda.flags'"/>
<xsl:with-param name="language" select="''"/>
<xsl:with-param name="value" select="'filteraway'"/>
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:template>
......
Markdown is supported
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