use of org.mycore.pi.urn.MCRDNBURN in project mycore by MyCoRe-Org.
the class MCRURNGranularRESTRegistrationService method createNewURN.
public MCRDNBURN createNewURN(MCRDerivate deriv) {
MCRObjectID derivID = deriv.getId();
try {
MCRDNBURN derivURN = getNewIdentifier(derivID, "");
deriv.getDerivate().setURN(derivURN.asString());
persistURNStr(deriv, new Date()).accept(derivURN::asString, "");
if (Boolean.valueOf(getProperties().getOrDefault("supportDfgViewerURN", "false"))) {
String suffix = "dfg";
persistURNStr(deriv, null, getRegistrationServiceID() + "-" + suffix).accept(() -> derivURN.withNamespaceSuffix(suffix + "-").asString(), "");
}
return derivURN;
} catch (MCRPersistentIdentifierException e) {
throw new MCRPICreationException("Could not create new URN for " + derivID, e);
}
}
use of org.mycore.pi.urn.MCRDNBURN in project mycore by MyCoRe-Org.
the class MCRURNGranularRESTRegistrationService method registerURN.
private MCRDNBURN registerURN(MCRDerivate deriv, String filePath) {
MCRObjectID derivID = deriv.getId();
Function<String, Integer> countCreatedPI = s -> MCRPersistentIdentifierManager.getInstance().getCreatedIdentifiers(derivID, getType(), getRegistrationServiceID()).size();
int seed = Optional.of(filePath).filter(p -> !"".equals(p)).map(countCreatedPI).map(count -> count + 1).orElse(1);
MCRDNBURN derivURN = Optional.ofNullable(deriv.getDerivate()).map(MCRObjectDerivate::getURN).flatMap(new MCRDNBURNParser()::parse).orElseGet(() -> createNewURN(deriv));
String setID = derivID.getNumberAsString();
GranularURNGenerator granularURNGen = new GranularURNGenerator(seed, derivURN, setID);
Function<MCRPath, Supplier<String>> generateURN = p -> granularURNGen.getURNSupplier();
derivateFileStream.apply(deriv).filter(notInIgnoreList().and(matchFile(filePath))).sorted().collect(Collectors.toMap(generateURN, p -> p, (m1, m2) -> m1, LinkedHashMap::new)).forEach(createFileMetadata(deriv).andThen(persistURN(deriv)));
try {
MCRMetadataManager.update(deriv);
} catch (MCRPersistenceException | MCRAccessException e) {
LOGGER.error("Error while updating derivate {}", derivID, e);
}
EntityTransaction transaction = MCREntityManagerProvider.getCurrentEntityManager().getTransaction();
if (!transaction.isActive()) {
transaction.begin();
}
transaction.commit();
return derivURN;
}
Aggregations