Search in sources :

Example 6 with MCRBase

use of org.mycore.datamodel.metadata.MCRBase in project mycore by MyCoRe-Org.

the class MCRPURLJobRegistrationService method update.

@Override
protected void update(MCRPersistentUniformResourceLocator purl, MCRBase obj, String additional) throws MCRPersistentIdentifierException {
    if (!hasRegistrationStarted(obj.getId(), additional)) {
        Predicate<MCRBase> registrationCondition = getRegistrationCondition(obj.getId().getTypeId());
        if (registrationCondition.test(obj)) {
            this.updateStartRegistrationDate(obj.getId(), "", new Date());
            startRegisterJob(obj, purl);
        }
    } else {
        if (isRegistered(obj.getId(), "")) {
            startUpdateJob(obj, purl);
        }
    }
}
Also used : MCRBase(org.mycore.datamodel.metadata.MCRBase) Date(java.util.Date)

Example 7 with MCRBase

use of org.mycore.datamodel.metadata.MCRBase in project mycore by MyCoRe-Org.

the class MCRPICommands method removeControlFromObject.

@MCRCommand(syntax = "remove control {0} with service {1} with additional {2}", help = "This commands removes the " + "pi control from the object {0}(object id) with the serivce {1}(service id) and the additional {2}")
public static void removeControlFromObject(String objectIDString, String serviceID, String additional) throws MCRAccessException, MCRActiveLinkException, MCRPersistentIdentifierException {
    MCRObjectID objectID = MCRObjectID.getInstance(objectIDString);
    MCRPI mcrpi = MCRPersistentIdentifierManager.getInstance().get(serviceID, objectIDString, additional != null ? additional.trim() : null);
    MCRPersistentIdentifierManager.getInstance().delete(mcrpi.getMycoreID(), mcrpi.getAdditional(), mcrpi.getType(), mcrpi.getService());
    MCRBase base = MCRMetadataManager.retrieve(objectID);
    if (MCRPIRegistrationService.removeFlagFromObject(base, mcrpi) == null) {
        throw new MCRPersistentIdentifierException("Could not delete Flag of object (flag not found)!");
    }
    MCRMetadataManager.update(base);
}
Also used : MCRPI(org.mycore.pi.backend.MCRPI) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 8 with MCRBase

use of org.mycore.datamodel.metadata.MCRBase 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 9 with MCRBase

use of org.mycore.datamodel.metadata.MCRBase in project mycore by MyCoRe-Org.

the class MCRIdentifierXSLUtils method getPIServiceInformation.

/**
 * Gets all available services which are configured.
 * e.g.
 *   <ul>
 *     <li>&lt;service id="service1" inscribed="false" permission="true" type="urn" /&gt;</li>
 *     <li>&lt;service id="service2" inscribed="true" permission="false" type="doi" /&gt;</li>
 *   </ul>
 *
 * @param objectID the object
 * @return a Nodelist
 * @throws JDOMException
 */
public static NodeList getPIServiceInformation(String objectID) throws JDOMException {
    Element e = new Element("list");
    MCRBase obj = MCRMetadataManager.retrieve(MCRObjectID.getInstance(objectID));
    MCRConfiguration.instance().getPropertiesMap("MCR.PI.Registration.").keySet().stream().map(s -> s.substring("MCR.PI.Registration.".length())).filter(id -> !id.contains(".")).map((serviceID) -> MCRPIRegistrationServiceManager.getInstance().getRegistrationService(serviceID)).map((rs -> {
        Element service = new Element("service");
        service.setAttribute("id", rs.getRegistrationServiceID());
        // Check if the inscriber of this service can read a PI
        try {
            if (rs.getMetadataManager().getIdentifier(obj, "").isPresent()) {
                service.setAttribute("inscribed", "true");
            } else {
                service.setAttribute("inscribed", "false");
            }
        } catch (MCRPersistentIdentifierException e1) {
            LOGGER.warn("Error happened while try to read PI from object: {}", objectID, e1);
            service.setAttribute("inscribed", "false");
        }
        // rights
        String permission = "register-" + rs.getRegistrationServiceID();
        Boolean canRegister = MCRAccessManager.checkPermission(objectID, "writedb") && MCRAccessManager.checkPermission(obj.getId(), permission);
        service.setAttribute("permission", canRegister.toString().toLowerCase(Locale.ROOT));
        // add the type
        service.setAttribute("type", rs.getType());
        return service;
    })).forEach(e::addContent);
    return new DOMOutputter().output(e).getElementsByTagName("service");
}
Also used : MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRMetadataManager(org.mycore.datamodel.metadata.MCRMetadataManager) NodeList(org.w3c.dom.NodeList) DOMOutputter(org.jdom2.output.DOMOutputter) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) MCRConfiguration(org.mycore.common.config.MCRConfiguration) MCRPersistentIdentifier(org.mycore.pi.MCRPersistentIdentifier) MCRAccessManager(org.mycore.access.MCRAccessManager) MCRPIRegistrationService(org.mycore.pi.MCRPIRegistrationService) Logger(org.apache.logging.log4j.Logger) JDOMException(org.jdom2.JDOMException) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Locale(java.util.Locale) MCRPersistentIdentifierManager(org.mycore.pi.MCRPersistentIdentifierManager) LogManager(org.apache.logging.log4j.LogManager) MCRPIRegistrationServiceManager(org.mycore.pi.MCRPIRegistrationServiceManager) Element(org.jdom2.Element) DOMOutputter(org.jdom2.output.DOMOutputter) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRPIRegistrationService(org.mycore.pi.MCRPIRegistrationService) Locale(java.util.Locale) Element(org.jdom2.Element) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException)

Example 10 with MCRBase

use of org.mycore.datamodel.metadata.MCRBase in project mycore by MyCoRe-Org.

the class MCRSwordContainerManager method replaceMetadataAndMediaResource.

@Override
public DepositReceipt replaceMetadataAndMediaResource(String editIRI, Deposit deposit, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordError, SwordServerException, SwordAuthException {
    IRI iri = new IRI(editIRI);
    String collection = MCRSwordUtil.ParseLinkUtil.EditIRI.getCollectionFromEditIRI(iri);
    String objectIdString = MCRSwordUtil.ParseLinkUtil.EditIRI.getObjectFromEditIRI(iri);
    final MCRSwordCollectionProvider collectionProvider = MCRSword.getCollection(collection);
    LOGGER.info(MessageFormat.format("REQUEST: Replace metadata and resource of {0} from {1} !", objectIdString, collection));
    collectionProvider.getAuthHandler().authentication(authCredentials);
    MCRObjectID objectId = MCRObjectID.getInstance(objectIdString);
    if (!MCRMetadataManager.exists(objectId)) {
        throwObjectDoesNotExist(objectIdString);
    }
    MCRBase retrievedMCRBase = MCRMetadataManager.retrieve(objectId);
    return collectionProvider.getContainerHandler().replaceMetadataAndResources((MCRObject) retrievedMCRBase, deposit);
}
Also used : IRI(org.apache.abdera.i18n.iri.IRI) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Aggregations

MCRBase (org.mycore.datamodel.metadata.MCRBase)18 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)13 MCRPersistentIdentifierException (org.mycore.pi.exceptions.MCRPersistentIdentifierException)9 IRI (org.apache.abdera.i18n.iri.IRI)5 MCRException (org.mycore.common.MCRException)5 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)5 MCRSwordCollectionProvider (org.mycore.sword.application.MCRSwordCollectionProvider)5 MCRAccessException (org.mycore.access.MCRAccessException)4 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)4 MCRPersistentIdentifier (org.mycore.pi.MCRPersistentIdentifier)4 MCRPI (org.mycore.pi.backend.MCRPI)4 MCRMetadataManager (org.mycore.datamodel.metadata.MCRMetadataManager)3 IOException (java.io.IOException)2 Date (java.util.Date)2 List (java.util.List)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 Document (org.jdom2.Document)2 Element (org.jdom2.Element)2 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)2