Search in sources :

Example 21 with MCRPI

use of org.mycore.pi.backend.MCRPI in project mycore by MyCoRe-Org.

the class MCRDOIRegistrationService method insertIdentifierToDatabase.

@Override
public MCRPI insertIdentifierToDatabase(MCRBase obj, String additional, MCRDigitalObjectIdentifier identifier) {
    Date registrationStarted = null;
    if (getRegistrationCondition(obj.getId().getTypeId()).test(obj)) {
        registrationStarted = new Date();
        startRegisterJob(obj, identifier);
    }
    MCRPI databaseEntry = new MCRPI(identifier.asString(), getType(), obj.getId().toString(), additional, this.getRegistrationServiceID(), provideRegisterDate(obj, additional), registrationStarted);
    MCRHIBConnection.instance().getSession().save(databaseEntry);
    return databaseEntry;
}
Also used : MCRPI(org.mycore.pi.backend.MCRPI) Date(java.util.Date)

Example 22 with MCRPI

use of org.mycore.pi.backend.MCRPI in project mycore by MyCoRe-Org.

the class MCRPURLJobRegistrationService method insertIdentifierToDatabase.

@Override
public MCRPI insertIdentifierToDatabase(MCRBase obj, String additional, MCRPersistentUniformResourceLocator identifier) {
    Date registrationStarted = null;
    if (getRegistrationCondition(obj.getId().getTypeId()).test(obj)) {
        registrationStarted = new Date();
        startRegisterJob(obj, identifier);
    }
    MCRPI databaseEntry = new MCRPI(identifier.asString(), getType(), obj.getId().toString(), additional, this.getRegistrationServiceID(), provideRegisterDate(obj, additional), registrationStarted);
    MCRHIBConnection.instance().getSession().save(databaseEntry);
    return databaseEntry;
}
Also used : MCRPI(org.mycore.pi.backend.MCRPI) Date(java.util.Date)

Example 23 with MCRPI

use of org.mycore.pi.backend.MCRPI 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;
}
Also used : MCRPI(org.mycore.pi.backend.MCRPI) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) Date(java.util.Date) Session(org.hibernate.Session)

Aggregations

MCRPI (org.mycore.pi.backend.MCRPI)23 Date (java.util.Date)8 EntityManager (javax.persistence.EntityManager)6 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 MCRPersistentIdentifierException (org.mycore.pi.exceptions.MCRPersistentIdentifierException)6 MCRBase (org.mycore.datamodel.metadata.MCRBase)4 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)4 Session (org.hibernate.Session)3 MCRAccessException (org.mycore.access.MCRAccessException)3 MCRException (org.mycore.common.MCRException)3 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)3 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)3 MCRObject (org.mycore.datamodel.metadata.MCRObject)3 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 Test (org.junit.Test)2