use of org.mycore.pi.MCRPersistentIdentifier in project mycore by MyCoRe-Org.
the class MCRMODSDOIPersistentIdentifierMetadataManager method getIdentifier.
@Override
public Optional<MCRPersistentIdentifier> getIdentifier(MCRBase base, String additional) throws MCRPersistentIdentifierException {
MCRObject object = checkObject(base);
MCRMODSWrapper wrapper = new MCRMODSWrapper(object);
Element element = wrapper.getElement("mods:identifier[@type='doi']");
if (element == null) {
return Optional.empty();
}
String doiText = element.getTextNormalize();
return new MCRDOIParser().parse(doiText).filter(Objects::nonNull).map(MCRPersistentIdentifier.class::cast);
}
use of org.mycore.pi.MCRPersistentIdentifier in project mycore by MyCoRe-Org.
the class MCRUUIDDOIGenerator method generate.
@Override
public MCRDigitalObjectIdentifier generate(MCRObjectID mcrID, String additional) {
Optional<MCRDigitalObjectIdentifier> parse = mcrdoiParser.parse(prefix + "/" + UUID.randomUUID());
MCRPersistentIdentifier doi = parse.get();
return (MCRDigitalObjectIdentifier) doi;
}
use of org.mycore.pi.MCRPersistentIdentifier in project mycore by MyCoRe-Org.
the class MCRPersistentIdentifierRegistrationResource method register.
@POST
@Path("service/{serviceName}/{mycoreId}")
@Produces(MediaType.APPLICATION_JSON)
public Response register(@PathParam("serviceName") String serviceName, @PathParam("mycoreId") String mycoreId, @DefaultValue("") @QueryParam("additional") String additional) {
if (!MCRPIRegistrationServiceManager.getInstance().getServiceIDList().contains(serviceName)) {
return Response.status(Response.Status.BAD_REQUEST).entity(buildErrorJSON("No Registration Service found for " + serviceName)).build();
}
MCRPIRegistrationService<MCRPersistentIdentifier> registrationService = MCRPIRegistrationServiceManager.getInstance().getRegistrationService(serviceName);
MCRObjectID mycoreIDObject;
try {
mycoreIDObject = MCRObjectID.getInstance(mycoreId);
} catch (MCRException e) {
LOGGER.error(e);
return Response.status(Response.Status.BAD_REQUEST).entity(buildErrorJSON("The provided id " + mycoreId + " seems to be invalid!", e)).build();
}
MCRPersistentIdentifier identifier;
MCRBase object = MCRMetadataManager.retrieve(mycoreIDObject);
try {
identifier = registrationService.register(object, additional, true);
} catch (MCRPersistentIdentifierException | MCRActiveLinkException e) {
LOGGER.error(e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(buildErrorJSON("Error while register new identifier!", e)).build();
} catch (MCRAccessException e) {
LOGGER.error(e);
return Response.status(Response.Status.FORBIDDEN).entity(buildErrorJSON("Error while register new identifier!", e)).build();
}
return Response.status(Response.Status.CREATED).entity(buildIdentifierObject(identifier)).build();
}
use of org.mycore.pi.MCRPersistentIdentifier in project mycore by MyCoRe-Org.
the class MCRPICommands method controlObjectWithServiceAndAdditional.
@MCRCommand(syntax = "try to control {0} with service {1} with additional {2}", help = "This command tries to" + " read a pi from the object {0} with the MetadataManager from the specified service {1}." + " If the service configuration is right then the pi is under control of MyCoRe.")
public static void controlObjectWithServiceAndAdditional(String objectIDString, String serviceID, final String additional) throws MCRAccessException, MCRActiveLinkException, IOException {
String trimAdditional = additional.trim();
MCRPIRegistrationService<MCRPersistentIdentifier> service = MCRPIRegistrationServiceManager.getInstance().getRegistrationService(serviceID);
MCRPersistentIdentifierMetadataManager<MCRPersistentIdentifier> metadataManager = service.getMetadataManager();
MCRObjectID objectID = MCRObjectID.getInstance(objectIDString);
MCRBase mcrBase = MCRMetadataManager.retrieve(objectID);
Optional<MCRPersistentIdentifier> identifier;
try {
identifier = metadataManager.getIdentifier(mcrBase, trimAdditional);
} catch (MCRPersistentIdentifierException e) {
LOGGER.info("Could not detect any identifier with service {}", serviceID, e);
return;
}
if (!identifier.isPresent()) {
LOGGER.info("Could not detect any identifier with service {}", serviceID);
return;
}
MCRPersistentIdentifier persistentIdentifier = identifier.get();
if (service.isRegistered(objectID, trimAdditional)) {
LOGGER.info("Already present in Database: {}", serviceID);
return;
}
MCRPI mcrpi = service.insertIdentifierToDatabase(mcrBase, trimAdditional, persistentIdentifier);
MCRPIRegistrationService.addFlagToObject(mcrBase, mcrpi);
MCRMetadataManager.update(mcrBase);
LOGGER.info("{}:{} is now under control of {}", objectID, trimAdditional, serviceID);
}
use of org.mycore.pi.MCRPersistentIdentifier in project mycore by MyCoRe-Org.
the class MCRCreateDateDOIGenerator method generate.
@Override
public MCRDigitalObjectIdentifier generate(MCRObjectID mcrID, String additional) throws MCRPersistentIdentifierException {
Date createdate = MCRMetadataManager.retrieveMCRObject(mcrID).getService().getDate("createdate");
if (createdate != null) {
MCRISO8601Date mcrdate = new MCRISO8601Date();
mcrdate.setDate(createdate);
String format = mcrdate.format(DATE_PATTERN, Locale.ENGLISH);
Optional<MCRDigitalObjectIdentifier> parse = mcrdoiParser.parse(prefix + "/" + format);
MCRPersistentIdentifier doi = parse.get();
return (MCRDigitalObjectIdentifier) doi;
} else {
throw new MCRPersistenceException("The object " + mcrID + " doesn't have a createdate!");
}
}
Aggregations