use of org.mycore.pi.urn.MCRDNBURNParser 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;
}
use of org.mycore.pi.urn.MCRDNBURNParser in project mycore by MyCoRe-Org.
the class MCRMODSURNPersistentIdentifierMetadataManager method getIdentifier.
@Override
public Optional<MCRPersistentIdentifier> getIdentifier(MCRBase obj, String additional) throws MCRPersistentIdentifierException {
MCRObject object = checkObject(obj);
MCRMODSWrapper wrapper = new MCRMODSWrapper(object);
Element element = wrapper.getElement(MODS_IDENTIFIER_TYPE_URN);
if (element == null) {
return Optional.empty();
}
String urnText = element.getTextNormalize();
return new MCRDNBURNParser().parse(urnText).filter(Objects::nonNull).map(MCRPersistentIdentifier.class::cast);
}
Aggregations