Skip to content

Commit

Permalink
DBT-373 use objectID for DNBURN
Browse files Browse the repository at this point in the history
  • Loading branch information
yagee-de committed Jun 19, 2024
1 parent b97d6b0 commit c6b2c40
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 9 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mycore</groupId>
<artifactId>mycore-pi</artifactId>
</dependency>
<dependency>
<groupId>org.mycore</groupId>
<artifactId>mycore-solr</artifactId>
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/de/urmel_dl/dbt/pi/DBTMapObjectIDURNGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.urmel_dl.dbt.pi;

import java.util.Optional;

import org.mycore.datamodel.metadata.MCRBase;
import org.mycore.datamodel.metadata.MCRObjectID;
import org.mycore.pi.MCRPIGenerator;
import org.mycore.pi.exceptions.MCRPersistentIdentifierException;
import org.mycore.pi.urn.MCRDNBURN;
import org.mycore.pi.urn.MCRDNBURNParser;

public class DBTMapObjectIDURNGenerator extends MCRPIGenerator<MCRDNBURN> {
//last char will be replaced by checksum
private static final String CHECKSUM_PART = "-$";
private static final MCRDNBURNParser DNBURN_PARSER = new MCRDNBURNParser();
private static final String URN_NBN_DE = "urn:nbn:de:";

public MCRDNBURN generate(MCRBase mcrObj, String additional) throws MCRPersistentIdentifierException {
return buildURN(mcrObj.getId(), additional);
}

public String getNamespace(String prefix) {
if (prefix.startsWith(URN_NBN_DE)) {
return prefix;
}
return "urn:nbn:de:" + prefix;
}

protected MCRDNBURN buildURN(MCRObjectID mcrObjectID, String s)
throws MCRPersistentIdentifierException {
return Optional.ofNullable(getProperties().get("Prefix." + mcrObjectID.getBase()))
.map(this::getNamespace)
.map(prefix -> prefix + mcrObjectID.getNumberAsInteger() + CHECKSUM_PART)
.flatMap(DNBURN_PARSER::parse).map(MCRDNBURN.class::cast)
.orElseThrow(() -> new MCRPersistentIdentifierException("Prefix." + mcrObjectID.getBase() +
" is not defined in " + getGeneratorID() + "."));
}

}
17 changes: 8 additions & 9 deletions src/main/resources/config/dbt/mycore.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ MIR.EditorForms.CustomIncludes=webapp:editor/editor-dbt.xed
# URN/DOI configuration
######################################################################

MCR.PI.Generator.TypeYearCountURN.Namespace=urn:nbn:de:gbv:27-dbt-
MCR.PI.Generator.TypeYearCountURN.GeneralPattern=%MCR.PI.Generator.TypeYearCountURN.Namespace%$ObjectDate-$Count
MCR.PI.Generator.TypeYearCountURN.DateFormat=yyyyMMdd-HHmmss
MCR.PI.Generator.TypeYearCountURN.CountPrecision=2
MCR.PI.Service.DNBURN.Generator=MapObjectIDURN
MCR.PI.Generator.MapObjectIDURN=de.urmel_dl.dbt.pi.DBTMapObjectIDURNGenerator
MCR.PI.Generator.MapObjectIDURN.Prefix.dbt_mods=%MCR.PI.Generator.MapObjectIDURN.Namespace%dbt-
MCR.PI.Generator.MapObjectIDURN.Namespace=urn:nbn:de:gbv:27-
MCR.PI.Generator.MapObjectIDURN.Type=dnbUrn

MIR.registerDOI=true
MCR.DOI.Prefix=10.22032
Expand Down Expand Up @@ -71,11 +72,9 @@ MCR.PI.Service.Uni-Weimar-Datacite.HostingInstitution=Bauhaus-Universit\u00E4t W
MCR.PI.Service.Uni-Weimar-Datacite.Namespace=http://datacite.org/schema/kernel-4
MCR.PI.Service.Uni-Weimar-Datacite.Schema=xsd/datacite/v4.3/metadata.xsd

MCR.PI.Generator.Uni-Weimar-URN=org.mycore.pi.MCRGenericPIGenerator
MCR.PI.Generator.Uni-Weimar-URN.CountPrecision=2
MCR.PI.Generator.Uni-Weimar-URN.DateFormat=yyyyMMdd-HHmmss
MCR.PI.Generator.Uni-Weimar-URN.GeneralPattern=%MCR.PI.Generator.Uni-Weimar-URN.Namespace%$ObjectDate-$Count
MCR.PI.Generator.Uni-Weimar-URN.Namespace=%MCR.PI.MetadataService.Uni-Weimar-MODSURN.Prefix%dbt-
MCR.PI.Generator.Uni-Weimar-URN=de.urmel_dl.dbt.pi.DBTMapObjectIDURNGenerator
MCR.PI.Generator.Uni-Weimar-URN.Prefix.dbt_mods=%MCR.PI.Generator.Uni-Weimar-URN.Namespace%dbt-
MCR.PI.Generator.Uni-Weimar-URN.Namespace=%MCR.PI.MetadataService.Uni-Weimar-MODSURN.Prefix%
MCR.PI.Generator.Uni-Weimar-URN.Type=dnbUrn

MCR.PI.Service.Uni-Weimar-DNBURN=org.mycore.pi.urn.MCRURNOAIService
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package de.urmel_dl.dbt.pi;

import java.util.Map;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mycore.common.MCRTestCase;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.datamodel.metadata.MCRObjectID;
import org.mycore.pi.exceptions.MCRPersistentIdentifierException;
import org.mycore.pi.urn.MCRDNBURN;

public class DBTMapObjectIDURNGeneratorTest extends MCRTestCase {

private static final String CONFIG_PREFIX = "MCR.PI.Generator.Test";
DBTMapObjectIDURNGenerator generator;

@Override
protected Map<String, String> getTestProperties() {
Map<String, String> testProperties = super.getTestProperties();
testProperties.put(CONFIG_PREFIX, "");
testProperties.put(CONFIG_PREFIX+".Prefix.dbt_mods", "urn:nbn:de:test-dbt-");
return testProperties;
}

@Before
public void setUp() throws Exception {
super.setUp();
generator = new DBTMapObjectIDURNGenerator();
generator.init(CONFIG_PREFIX);
Map<String, String> subPropertiesMap = MCRConfiguration2.getSubPropertiesMap(CONFIG_PREFIX+".");
System.out.println(subPropertiesMap);
generator.setProperties(subPropertiesMap);
}

@Test
public void getNamespace() {
Assert.assertEquals("urn:nbn:de:test",generator.getNamespace("test"));
Assert.assertEquals("urn:nbn:de:test",generator.getNamespace("urn:nbn:de:test"));
}

@Test
public void buildURN() throws MCRPersistentIdentifierException {
MCRObjectID mcrObjectID=MCRObjectID.getInstance("dbt_mods_4711");
MCRDNBURN urn = generator.buildURN(mcrObjectID, "");
Assert.assertEquals("urn:nbn:de:test-dbt-4711-2",urn.asString());
}
}

0 comments on commit c6b2c40

Please sign in to comment.