use of org.mycore.common.MCRPersistenceException 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;
}
Aggregations