Search in sources :

Example 16 with MCRBase

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

the class MCRPIRegistrationService method updateFlag.

public void updateFlag(MCRObjectID id, String additional, MCRPI mcrpi) {
    MCRBase obj = MCRMetadataManager.retrieve(id);
    MCRObjectService service = obj.getService();
    ArrayList<String> flags = service.getFlags(MCRPIRegistrationService.PI_FLAG);
    Gson gson = getGson();
    String stringFlag = flags.stream().filter(_stringFlag -> {
        MCRPI flag = gson.fromJson(_stringFlag, MCRPI.class);
        return flag.getAdditional().equals(additional) && flag.getIdentifier().equals(mcrpi.getIdentifier());
    }).findAny().orElseThrow(() -> new MCRException(new MCRPersistentIdentifierException("Could find flag to update (" + id + "," + additional + "," + mcrpi.getIdentifier() + ")")));
    int flagIndex = service.getFlagIndex(stringFlag);
    service.removeFlag(flagIndex);
    addFlagToObject(obj, mcrpi);
    try {
        MCRMetadataManager.update(obj);
    } catch (Exception e) {
        throw new MCRException("Could not update flags of object " + id, e);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRObjectService(org.mycore.datamodel.metadata.MCRObjectService) Gson(com.google.gson.Gson) MCRPI(org.mycore.pi.backend.MCRPI) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) MCRException(org.mycore.common.MCRException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) MCRAccessException(org.mycore.access.MCRAccessException) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MCRActiveLinkException(org.mycore.datamodel.common.MCRActiveLinkException)

Example 17 with MCRBase

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

the class MCRPICommands method addFlagsToObjects.

@MCRCommand(syntax = "add PI Flags to objects", help = "Should only be used if you used mycore-pi pre 2016 lts!")
public static void addFlagsToObjects() {
    MCRPersistentIdentifierManager.getInstance().getList().forEach(registrationInfo -> {
        if (registrationInfo.getMcrRevision() <= 35726) {
            String mycoreID = registrationInfo.getMycoreID();
            MCRObjectID objectID = MCRObjectID.getInstance(mycoreID);
            MCRBase base = MCRMetadataManager.retrieve(objectID);
            LOGGER.info("Add PI-Flag to {}", mycoreID);
            MCRPIRegistrationService.addFlagToObject(base, (MCRPI) registrationInfo);
            try {
                MCRMetadataManager.update(base);
            } catch (Exception e) {
                throw new MCRException(e);
            }
        }
    });
}
Also used : MCRException(org.mycore.common.MCRException) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRException(org.mycore.common.MCRException) MCRAccessException(org.mycore.access.MCRAccessException) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) IOException(java.io.IOException) MCRActiveLinkException(org.mycore.datamodel.common.MCRActiveLinkException) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 18 with MCRBase

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

the class MCRURNObjectXPathMetadataManager method insertIdentifier.

@Override
public void insertIdentifier(MCRDNBURN identifier, MCRBase obj, String additional) throws MCRPersistentIdentifierException {
    String xpath = getProperties().get("Xpath");
    Document xml = obj.createXML();
    MCRNodeBuilder nb = new MCRNodeBuilder();
    try {
        nb.buildElement(xpath, identifier.asString(), xml);
        MCRBase object = new MCRObject(xml);
        MCRMetadataManager.update(object);
    } catch (Exception e) {
        throw new MCRException("Error while inscribing URN to " + obj.getId(), e);
    }
}
Also used : MCRNodeBuilder(org.mycore.common.xml.MCRNodeBuilder) MCRException(org.mycore.common.MCRException) MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRBase(org.mycore.datamodel.metadata.MCRBase) Document(org.jdom2.Document) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) MCRException(org.mycore.common.MCRException)

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