Search in sources :

Example 1 with MCRPersistentIdentifier

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);
}
Also used : MCRDOIParser(org.mycore.pi.doi.MCRDOIParser) MCRObject(org.mycore.datamodel.metadata.MCRObject) Element(org.jdom2.Element) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper) MCRPersistentIdentifier(org.mycore.pi.MCRPersistentIdentifier)

Example 2 with MCRPersistentIdentifier

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;
}
Also used : MCRPersistentIdentifier(org.mycore.pi.MCRPersistentIdentifier)

Example 3 with MCRPersistentIdentifier

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();
}
Also used : MCRException(org.mycore.common.MCRException) MCRActiveLinkException(org.mycore.datamodel.common.MCRActiveLinkException) MCRAccessException(org.mycore.access.MCRAccessException) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRPersistentIdentifier(org.mycore.pi.MCRPersistentIdentifier) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 4 with MCRPersistentIdentifier

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);
}
Also used : MCRPI(org.mycore.pi.backend.MCRPI) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRPersistentIdentifier(org.mycore.pi.MCRPersistentIdentifier) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 5 with MCRPersistentIdentifier

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!");
    }
}
Also used : MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date) MCRPersistentIdentifier(org.mycore.pi.MCRPersistentIdentifier) MCRPersistenceException(org.mycore.common.MCRPersistenceException) MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date) Date(java.util.Date)

Aggregations

MCRPersistentIdentifier (org.mycore.pi.MCRPersistentIdentifier)7 MCRPersistentIdentifierException (org.mycore.pi.exceptions.MCRPersistentIdentifierException)3 Element (org.jdom2.Element)2 MCRBase (org.mycore.datamodel.metadata.MCRBase)2 MCRObject (org.mycore.datamodel.metadata.MCRObject)2 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)2 MCRMODSWrapper (org.mycore.mods.MCRMODSWrapper)2 Date (java.util.Date)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Document (org.jdom2.Document)1 Text (org.jdom2.Text)1 XPathFactory (org.jdom2.xpath.XPathFactory)1 MCRAccessException (org.mycore.access.MCRAccessException)1 MCRException (org.mycore.common.MCRException)1 MCRPersistenceException (org.mycore.common.MCRPersistenceException)1 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)1 MCRISO8601Date (org.mycore.datamodel.common.MCRISO8601Date)1 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)1