Search in sources :

Example 51 with MCRException

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;
}
Also used : MCRException(org.mycore.common.MCRException) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 52 with MCRException

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MCRException(org.mycore.common.MCRException) Matcher(java.util.regex.Matcher) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 53 with MCRException

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();
        }
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRUserInformation(org.mycore.common.MCRUserInformation)

Example 54 with MCRException

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;
}
Also used : MCRException(org.mycore.common.MCRException) MCRJob(org.mycore.services.queuedjob.MCRJob)

Example 55 with MCRException

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);
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) MCRException(org.mycore.common.MCRException) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) SAXException(org.xml.sax.SAXException)

Aggregations

MCRException (org.mycore.common.MCRException)131 IOException (java.io.IOException)39 Element (org.jdom2.Element)26 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)19 Document (org.jdom2.Document)18 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)18 File (java.io.File)15 MCRConfigurationException (org.mycore.common.config.MCRConfigurationException)12 MCRObject (org.mycore.datamodel.metadata.MCRObject)12 ArrayList (java.util.ArrayList)11 JDOMException (org.jdom2.JDOMException)11 MCRAccessException (org.mycore.access.MCRAccessException)11 MCRPath (org.mycore.datamodel.niofs.MCRPath)10 SAXException (org.xml.sax.SAXException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 List (java.util.List)7 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)7 SAXParseException (org.xml.sax.SAXParseException)7 URI (java.net.URI)6 Path (java.nio.file.Path)6