use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRURNGranularOAIRegistrationService method registerSingleURN.
private MCRDNBURN registerSingleURN(MCRBase obj, String additional, MCRObjectDerivate derivate) throws MCRPersistentIdentifierException {
MCRDNBURN newURN;
LOGGER.info("Add single urn to {} / {}", obj.getId(), additional);
Session session = MCRHIBConnection.instance().getSession();
MCRPath filePath;
if (!Files.exists(filePath = MCRPath.getPath(obj.getId().toString(), additional))) {
throw new MCRPersistentIdentifierException("Invalid path : " + additional);
}
int count = Math.toIntExact(derivate.getFileMetadata().stream().filter(file -> file.getUrn() != null).count());
MCRDNBURN dnbURN = newURN = (MCRDNBURN) MCRPersistentIdentifierManager.getInstance().get(derivate.getURN()).findFirst().get();
String setID = obj.getId().getNumberAsString();
MCRDNBURN urntoAssign = dnbURN.toGranular(setID, count + 1, count + 1);
derivate.getOrCreateFileMetadata(filePath, urntoAssign.asString()).setUrn(urntoAssign.asString());
MCRPI databaseEntry = new MCRPI(urntoAssign.asString(), getType(), obj.getId().toString(), additional, this.getRegistrationServiceID(), new Date());
session.save(databaseEntry);
return newURN;
}
Aggregations