Search in sources :

Example 56 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID 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 57 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.

the class MCRCreateObjectServlet method createObject.

/**
 * Adds a new mycore object to the persistence backend.
 * @param doc
 *  MyCoRe object as XML
 * @return
 *  MCRObjectID of the newly created object.
 * @throws MCRActiveLinkException
 *  If links from or to other objects will fail.
 * @throws JDOMException
 *  from {@link MCRPersistenceHelper#getMCRObject(Document)}
 * @throws IOException
 *  from {@link MCRPersistenceHelper#getMCRObject(Document)}
 * @throws SAXParseException
 * @throws MCRException
 * @throws MCRAccessException
 */
private MCRObjectID createObject(Document doc) throws MCRActiveLinkException, JDOMException, IOException, MCRException, SAXParseException, MCRAccessException {
    MCRObject mcrObject = MCRPersistenceHelper.getMCRObject(doc);
    MCRObjectID objectId = mcrObject.getId();
    // noinspection SynchronizeOnNonFinalField
    checkCreatePrivilege(objectId);
    synchronized (this) {
        if (objectId.getNumberAsInteger() == 0) {
            String objId = mcrObject.getId().toString();
            objectId = MCRObjectID.getNextFreeId(objectId.getBase());
            if (mcrObject.getLabel().equals(objId))
                mcrObject.setLabel(objectId.toString());
            mcrObject.setId(objectId);
        }
    }
    MCRMetadataManager.create(mcrObject);
    return objectId;
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 58 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.

the class MCRCreateObjectServlet method handlePersistenceOperation.

@Override
void handlePersistenceOperation(HttpServletRequest request, HttpServletResponse response) throws MCRAccessException, ServletException, MCRActiveLinkException, SAXParseException, JDOMException, IOException {
    Document editorSubmission = MCRPersistenceHelper.getEditorSubmission(request, false);
    MCRObjectID objectID;
    if (editorSubmission != null) {
        objectID = createObject(editorSubmission);
    } else {
        // editorSubmission is null, when editor input is absent (redirect to editor form in render phase)
        String projectID = getProperty(request, "project");
        String type = getProperty(request, "type");
        String formattedId = MCRObjectID.formatID(projectID + "_" + type, 0);
        objectID = MCRObjectID.getInstance(formattedId);
    }
    checkCreatePrivilege(objectID);
    request.setAttribute(OBJECT_ID_KEY, objectID);
}
Also used : MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Document(org.jdom2.Document)

Example 59 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.

the class MCRCreateObjectServlet method redirectToCreateObject.

/**
 * redirects to new mcrobject form.
 *
 * At least "type" HTTP parameter is required to succeed.
 * <dl>
 *   <dt>type</dt>
 *   <dd>object type of the new object (required)</dd>
 *   <dt>project</dt>
 *   <dd>project ID part of object ID (required)</dd>
 *   <dt>layout</dt>
 *   <dd>special editor form layout</dd>
 * </dl>
 */
private void redirectToCreateObject(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    MCRObjectID objectID = (MCRObjectID) request.getAttribute(OBJECT_ID_KEY);
    StringBuilder sb = new StringBuilder();
    sb.append("editor_form_author").append('-').append(objectID.getTypeId());
    String layout = getProperty(request, "layout");
    if (layout != null && layout.length() != 0) {
        sb.append('-').append(layout);
    }
    String base_name = sb.toString();
    String form = MCRPersistenceHelper.getWebPage(getServletContext(), base_name + ".xed", base_name + ".xml");
    Properties params = new Properties();
    params.put("cancelUrl", MCRPersistenceHelper.getCancelUrl(request));
    params.put("mcrid", objectID.toString());
    Enumeration<String> e = request.getParameterNames();
    while (e.hasMoreElements()) {
        String name = e.nextElement();
        String value = request.getParameter(name);
        params.put(name, value);
    }
    response.sendRedirect(response.encodeRedirectURL(buildRedirectURL(MCRFrontendUtil.getBaseURL() + form, params)));
}
Also used : MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Properties(java.util.Properties)

Example 60 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.

the class MCRCreateObjectServlet method displayResult.

@Override
void displayResult(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // return to object itself if created, else call editor form
    MCRObjectID returnID = (MCRObjectID) request.getAttribute(OBJECT_ID_KEY);
    if (returnID.getNumberAsInteger() == 0) {
        redirectToCreateObject(request, response);
    } else {
        Properties params = MCRPersistenceHelper.getXSLProperties(request);
        if (this.appendDerivate) {
            params.put("id", returnID.toString());
            params.put("cancelURL", MCRFrontendUtil.getBaseURL() + "receive/" + returnID);
            response.sendRedirect(response.encodeRedirectURL(buildRedirectURL(MCRFrontendUtil.getBaseURL() + "servlets/derivate/create", params)));
        } else {
            response.sendRedirect(response.encodeRedirectURL(buildRedirectURL(MCRFrontendUtil.getBaseURL() + "receive/" + returnID, params)));
        }
    }
}
Also used : MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Properties(java.util.Properties)

Aggregations

MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)144 IOException (java.io.IOException)37 MCRObject (org.mycore.datamodel.metadata.MCRObject)32 MCRException (org.mycore.common.MCRException)30 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)30 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)29 MCRPath (org.mycore.datamodel.niofs.MCRPath)25 MCRAccessException (org.mycore.access.MCRAccessException)22 Document (org.jdom2.Document)20 MCRPersistenceException (org.mycore.common.MCRPersistenceException)18 MCRMetaLinkID (org.mycore.datamodel.metadata.MCRMetaLinkID)16 JDOMException (org.jdom2.JDOMException)15 MCRBase (org.mycore.datamodel.metadata.MCRBase)15 SAXException (org.xml.sax.SAXException)15 Date (java.util.Date)14 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)13 MCRSession (org.mycore.common.MCRSession)11 MCRContent (org.mycore.common.content.MCRContent)11 MCRPersistentIdentifierException (org.mycore.pi.exceptions.MCRPersistentIdentifierException)11 URISyntaxException (java.net.URISyntaxException)10