use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRObjectServlet method getMCRObjectID.
private MCRObjectID getMCRObjectID(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
final String pathInfo = req.getPathInfo();
final String id = pathInfo == null ? null : pathInfo.substring(1);
MCRObjectID mcrid = null;
if (id != null) {
try {
// create Object with given ID, only ID syntax check performed
mcrid = MCRObjectID.getInstance(id);
} catch (final MCRException e) {
// handle exception: invalid ID syntax, set HTTP error 400 "Invalid request"
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, getErrorI18N(I18N_ERROR_PREFIX, "invalidID", id));
// sorry, no object to return
return null;
}
}
return mcrid;
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRCompressServlet method think.
@Override
protected void think(MCRServletJob job) throws Exception {
HttpServletRequest req = job.getRequest();
// id parameter for backward compatibility
String paramid = getProperty(req, "id");
if (paramid == null) {
String pathInfo = req.getPathInfo();
if (pathInfo != null) {
paramid = pathInfo.substring(1);
}
}
if (paramid == null) {
job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "What should I do?");
return;
}
Matcher ma = PATH_INFO_PATTERN.matcher(paramid);
// path & directory
MCRObjectID id;
String path;
try {
if (ma.find()) {
id = MCRObjectID.getInstance(ma.group(1));
path = ma.group(2);
} else {
id = MCRObjectID.getInstance(paramid);
path = null;
}
} catch (MCRException e) {
String objId = ma.find() ? ma.group(1) : paramid;
job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "ID is not valid: " + objId);
return;
}
boolean readPermission = id.getTypeId().equals("derivate") ? MCRAccessManager.checkPermissionForReadingDerivate(id.toString()) : MCRAccessManager.checkPermission(id, PERMISSION_READ);
if (!readPermission) {
job.getResponse().sendError(HttpServletResponse.SC_FORBIDDEN, "You may not read " + id);
return;
}
req.setAttribute(KEY_OBJECT_ID, id);
req.setAttribute(KEY_PATH, path);
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRFixedUserCallable method call.
@Override
public V call() throws Exception {
final boolean hasSession = MCRSessionMgr.hasCurrentSession();
this.session = MCRSessionMgr.getCurrentSession();
try {
MCRUserInformation currentUser = this.session.getUserInformation();
if (hasSession) {
if (!currentUser.equals(userInfo)) {
throw new MCRException("MCRFixedUserCallable is bound to " + currentUser.getUserID() + " and not to " + userInfo.getUserID() + ".");
}
} else {
this.session.setUserInformation(userInfo);
}
return super.call();
} finally {
if (!hasSession && this.session != null) {
this.session.close();
}
}
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRPackerManager method startPacking.
/**
* Creates and starts a new PackagingJob.
* <p>The rights you need to start a Packer depends on the implementation!</p>
* @param jobParameters the parameters which will be passed to the job. (Should include a packer)
* @return the created MCRJob
* @throws MCRUsageException if invalid parameters are passed to the packer
* @throws MCRAccessException if the current user doesn't have the rights to use the packer(on a specific object).
*/
public static MCRJob startPacking(Map<String, String> jobParameters) throws MCRUsageException, MCRAccessException {
String packer = jobParameters.get("packer");
if (packer == null) {
LOGGER.error("No Packer parameter found!");
return null;
}
checkPacker(packer, jobParameters);
MCRJob mcrJob = new MCRJob(MCRPackerJobAction.class);
mcrJob.setParameters(jobParameters);
if (!PACKER_JOB_QUEUE.offer(mcrJob)) {
throw new MCRException("Could not add Job to Queue!");
}
return mcrJob;
}
use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.
the class MCRMetsIIIFPresentationImpl method getManifest.
@Override
public MCRIIIFManifest getManifest(String id) {
try {
Document metsDocument = getMets(id);
LOGGER.info(new XMLOutputter(Format.getPrettyFormat()).outputString(metsDocument));
return getConverter(id, metsDocument).convert();
} catch (IOException | JDOMException | SAXException e) {
throw new MCRException(e);
}
}
Aggregations