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);
}
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);
}
}
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);
}
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);
}
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()));
}
}
Aggregations