Search in sources :

Example 36 with MCRObject

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

the class MCRSwordMediaManager method replaceMediaResource.

public DepositReceipt replaceMediaResource(String editMediaIRI, Deposit deposit, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordError, SwordServerException, SwordAuthException {
    LOGGER.info("replaceMediaResource: {}", editMediaIRI);
    final IRI mediaEditIRI = new IRI(editMediaIRI);
    final String requestDerivateID = MCRSwordUtil.ParseLinkUtil.MediaEditIRI.getDerivateFromMediaEditIRI(mediaEditIRI);
    final String requestFilePath = MCRSwordUtil.ParseLinkUtil.MediaEditIRI.getFilePathFromMediaEditIRI(mediaEditIRI);
    final String collection = MCRSwordUtil.ParseLinkUtil.MediaEditIRI.getCollectionFromMediaEditIRI(mediaEditIRI);
    doAuthentication(authCredentials, collection);
    checkObject(requestDerivateID);
    getMediaProvider(collection).replaceMediaResource(requestDerivateID, requestFilePath, deposit);
    final MCRObject mcrObject = MCRSwordUtil.getMcrObjectForDerivateID(requestDerivateID);
    return MCRSword.getCollection(collection).getMetadataProvider().provideMetadata(mcrObject);
}
Also used : IRI(org.apache.abdera.i18n.iri.IRI) MCRObject(org.mycore.datamodel.metadata.MCRObject)

Example 37 with MCRObject

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

the class MCRSwordContainerHandler method deleteObject.

public void deleteObject(MCRObject object) throws SwordServerException {
    try {
        object.getStructure().getDerivates().stream().map(MCRMetaLinkID::getXLinkHrefID).forEach(id -> {
            try {
                MCRMetadataManager.deleteMCRDerivate(id);
            } catch (Exception e) {
                throw new MCRException(e);
            }
        });
        MCRMetadataManager.delete(object);
    } catch (MCRActiveLinkException | MCRAccessException | MCRException e) {
        Throwable ex = e;
        if (e instanceof MCRException && Optional.ofNullable(e.getCause()).map(Object::getClass).filter(MCRAccessException.class::isAssignableFrom).isPresent()) {
            // unwrapp
            ex = e.getCause();
        }
        throw new SwordServerException("Error while deleting Object.", ex);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRActiveLinkException(org.mycore.datamodel.common.MCRActiveLinkException) SwordServerException(org.swordapp.server.SwordServerException) MCRAccessException(org.mycore.access.MCRAccessException) MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRException(org.mycore.common.MCRException) SwordServerException(org.swordapp.server.SwordServerException) MCRActiveLinkException(org.mycore.datamodel.common.MCRActiveLinkException) MCRAccessException(org.mycore.access.MCRAccessException)

Example 38 with MCRObject

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

the class MCRSwordContainerHandler method addObject.

public DepositReceipt addObject(Deposit deposit) throws SwordError, SwordServerException {
    final MCRSwordCollectionProvider collection = MCRSword.getCollection(this.lifecycleConfiguration.getCollection());
    final MCRObjectID idOfIngested = collection.getIngester().ingestMetadata(deposit);
    final MCRObject createdObject = (MCRObject) MCRMetadataManager.retrieve(idOfIngested);
    return collection.getMetadataProvider().provideMetadata(createdObject);
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 39 with MCRObject

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

the class MCRSwordContainerHandler method addObjectWithDerivate.

public DepositReceipt addObjectWithDerivate(String objectIdString, Deposit deposit) throws SwordError, SwordServerException {
    final MCRSwordCollectionProvider collection = MCRSword.getCollection(this.lifecycleConfiguration.getCollection());
    final MCRObjectID idOfIngested = collection.getIngester().ingestMetadataResources(deposit);
    final MCRObject createdObject = (MCRObject) MCRMetadataManager.retrieve(idOfIngested);
    return collection.getMetadataProvider().provideMetadata(createdObject);
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 40 with MCRObject

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

the class MCRMetadataHistoryCommands method buildSimpleObjectHistory.

private static Stream<MCRMetaHistoryItem> buildSimpleObjectHistory(MCRObjectID objId) throws IOException {
    boolean exist = false;
    LogManager.getLogger().debug("Store of {} has no old revisions. History rebuild is limited", objId);
    if (MCRMetadataManager.exists(objId)) {
        MCRObject obj = MCRMetadataManager.retrieveMCRObject(objId);
        Instant lastModified = Instant.ofEpochMilli(MCRXMLMetadataManager.instance().getLastModified(objId));
        String creator;
        try {
            creator = MCRCreatorCache.getCreator(obj.getId());
        } catch (ExecutionException e) {
            LogManager.getLogger().warn("Error while getting creator of {}", objId, e);
            creator = null;
        }
        String user = Optional.ofNullable(creator).orElseGet(() -> MCRSystemUserInformation.getSystemUserInstance().getUserID());
        MCRMetaHistoryItem create = create(objId, user, lastModified);
        exist = true;
        boolean objectIsHidden = MCRMetadataHistoryManager.objectIsHidden(obj);
        if (objectIsHidden && exist) {
            return Stream.of(create, delete(objId, user, lastModified.plusMillis(1)));
        }
        return Stream.of(create);
    } else {
        return Stream.of(delete(objId, null, Instant.now()));
    }
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) Instant(java.time.Instant) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

MCRObject (org.mycore.datamodel.metadata.MCRObject)71 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)33 Document (org.jdom2.Document)18 Element (org.jdom2.Element)17 MCRException (org.mycore.common.MCRException)16 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)14 MCRMetaLinkID (org.mycore.datamodel.metadata.MCRMetaLinkID)14 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)12 IOException (java.io.IOException)11 MCRAccessException (org.mycore.access.MCRAccessException)11 MCRMODSWrapper (org.mycore.mods.MCRMODSWrapper)9 MCRPersistenceException (org.mycore.common.MCRPersistenceException)7 Date (java.util.Date)6 JDOMException (org.jdom2.JDOMException)6 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)6 MCRPersistentIdentifierException (org.mycore.pi.exceptions.MCRPersistentIdentifierException)6 SAXException (org.xml.sax.SAXException)6 URI (java.net.URI)5 URISyntaxException (java.net.URISyntaxException)5 ArrayList (java.util.ArrayList)5