use of org.mycore.access.MCRAccessException in project mycore by MyCoRe-Org.
the class MCRMODSMetadataShareAgent method distributeMetadata.
/* (non-Javadoc)
* @see org.mycore.datamodel.metadata.share.MCRMetadataShareAgent#inheritMetadata(org.mycore.datamodel.metadata.MCRObject)
*/
@Override
public void distributeMetadata(MCRObject holder) throws MCRPersistenceException, MCRAccessException {
MCRMODSWrapper holderWrapper = new MCRMODSWrapper(holder);
List<MCRMetaLinkID> children = holder.getStructure().getChildren();
if (!children.isEmpty()) {
LOGGER.info("Update inherited metadata");
for (MCRMetaLinkID childIdRef : children) {
MCRObjectID childId = childIdRef.getXLinkHrefID();
if (MCRMODSWrapper.isSupported(childId)) {
LOGGER.info("Update: {}", childIdRef);
MCRObject child = MCRMetadataManager.retrieveMCRObject(childId);
MCRMODSWrapper childWrapper = new MCRMODSWrapper(child);
inheritToChild(holderWrapper, childWrapper);
LOGGER.info("Saving: {}", childIdRef);
try {
MCRMetadataManager.update(child);
} catch (MCRPersistenceException | MCRAccessException e) {
throw new MCRPersistenceException("Error while updating inherited metadata", e);
}
}
}
}
Collection<String> recipientIds = MCRLinkTableManager.instance().getSourceOf(holder.getId(), MCRLinkTableManager.ENTRY_TYPE_REFERENCE);
for (String rId : recipientIds) {
MCRObjectID recipientId = MCRObjectID.getInstance(rId);
if (MCRMODSWrapper.isSupported(recipientId)) {
LOGGER.info("distribute metadata to {}", rId);
MCRObject recipient = MCRMetadataManager.retrieveMCRObject(recipientId);
MCRMODSWrapper recipientWrapper = new MCRMODSWrapper(recipient);
for (Element relatedItem : recipientWrapper.getLinkedRelatedItems()) {
String holderId = relatedItem.getAttributeValue("href", MCRConstants.XLINK_NAMESPACE);
if (holder.getId().toString().equals(holderId)) {
@SuppressWarnings("unchecked") Filter<Content> sharedMetadata = (Filter<Content>) Filters.element("part", MCRConstants.MODS_NAMESPACE).negate();
relatedItem.removeContent(sharedMetadata);
relatedItem.addContent(holderWrapper.getMODS().cloneContent());
LOGGER.info("Saving: {}", recipientId);
try {
MCRMetadataManager.update(recipient);
} catch (MCRPersistenceException | MCRAccessException e) {
throw new MCRPersistenceException("Error while updating shared metadata", e);
}
}
}
}
}
}
use of org.mycore.access.MCRAccessException in project mycore by MyCoRe-Org.
the class MCRRestAPIUploadHelper method deleteDerivate.
/**
* deletes a whole derivate
* @param info - the Jersey UriInfo object
* @param request - the HTTPServletRequest object
* @param pathParamMcrObjID - the MyCoRe Object ID
* @param pathParamMcrDerID - the MyCoRe Derivate ID
* @return a Jersey Response Object
* @throws MCRRestAPIException
*/
public static Response deleteDerivate(UriInfo info, HttpServletRequest request, String pathParamMcrObjID, String pathParamMcrDerID) throws MCRRestAPIException {
Response response = Response.status(Status.INTERNAL_SERVER_ERROR).build();
SignedJWT signedJWT = MCRJSONWebTokenUtil.retrieveAuthenticationToken(request);
String base64Signature = request.getHeader("X-MyCoRe-RestAPI-Signature");
if (base64Signature == null) {
// ToDo error handling
}
try (MCRJPATransactionWrapper mtw = new MCRJPATransactionWrapper()) {
// MCRSession session = MCRServlet.getSession(request);
MCRSession session = MCRSessionMgr.getCurrentSession();
MCRUserInformation currentUser = session.getUserInformation();
session.setUserInformation(MCRUserManager.getUser(MCRJSONWebTokenUtil.retrieveUsernameFromAuthenticationToken(signedJWT)));
MCRObjectID objID = MCRObjectID.getInstance(pathParamMcrObjID);
MCRObjectID derID = MCRObjectID.getInstance(pathParamMcrDerID);
// MCRAccessManager.checkPermission() uses CACHE, which seems to be dirty from other calls????
MCRAccessManager.invalidPermissionCache(derID.toString(), PERMISSION_DELETE);
if (MCRAccessManager.checkPermission(derID.toString(), PERMISSION_DELETE)) {
try {
MCRMetadataManager.deleteMCRDerivate(derID);
} catch (MCRPersistenceException pe) {
// dir does not exist - do nothing
} catch (MCRAccessException e) {
LOGGER.error(e);
}
}
session.setUserInformation(currentUser);
response = Response.created(info.getBaseUriBuilder().path("v1/objects/" + objID + "/derivates").build()).type("application/xml; charset=UTF-8").header(HEADER_NAME_AUTHORIZATION, "Bearer " + MCRJSONWebTokenUtil.createJWTAuthorizationHeader(signedJWT)).build();
}
return response;
}
use of org.mycore.access.MCRAccessException in project mycore by MyCoRe-Org.
the class MCRURNGranularOAIRegistrationService method register.
@Override
public MCRDNBURN register(MCRBase obj, String additional, boolean updateObject) throws MCRAccessException, MCRActiveLinkException, MCRPersistentIdentifierException {
this.validateRegistration(obj, additional);
MCRObjectDerivate derivate = ((MCRDerivate) obj).getDerivate();
MCRDNBURN newURN;
if (additional.equals("")) {
/* Multiple URN for entire Derivate... */
newURN = registerURNsDerivate(obj, additional, derivate);
} else {
/* Single URN to one File... */
newURN = registerSingleURN(obj, additional, derivate);
}
try {
MCRMetadataManager.update(obj);
} catch (Exception e) {
throw new MCRPersistentIdentifierException("Error while updating derivate " + obj.getId(), e);
}
return newURN;
}
Aggregations