Search in sources :

Example 61 with MCRObjectID

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

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

the class MCRPersistenceHelper method getMCRObject.

/**
 * creates a MCRObject instance on base of JDOM document
 * @param doc
 *  MyCoRe object as XML.
 * @return
 * @throws JDOMException
 *  exception from underlying {@link MCREditorOutValidator}
 * @throws IOException
 *  exception from underlying {@link MCREditorOutValidator} or {@link XMLOutputter}
 * @throws SAXParseException
 * @throws MCRException
 */
static MCRObject getMCRObject(Document doc) throws JDOMException, IOException, MCRException, SAXParseException {
    String id = doc.getRootElement().getAttributeValue("ID");
    MCRObjectID objectID = MCRObjectID.getInstance(id);
    MCREditorOutValidator ev = new MCREditorOutValidator(doc, objectID);
    Document jdom_out = ev.generateValidMyCoReObject();
    if (ev.getErrorLog().size() > 0 && LOGGER.isDebugEnabled()) {
        XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
        StringWriter swOrig = new StringWriter();
        xout.output(doc, swOrig);
        LOGGER.debug("Input document \n{}", swOrig);
        for (String logMsg : ev.getErrorLog()) {
            LOGGER.debug(logMsg);
        }
        StringWriter swClean = new StringWriter();
        xout.output(jdom_out, swClean);
        LOGGER.debug("Results in \n{}", swClean);
    }
    return new MCRObject(jdom_out);
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) MCRObject(org.mycore.datamodel.metadata.MCRObject) StringWriter(java.io.StringWriter) MCREditorOutValidator(org.mycore.datamodel.metadata.validator.MCREditorOutValidator) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Document(org.jdom2.Document)

Example 63 with MCRObjectID

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

the class MCRUpdateDerivateServlet method updateDerivateXML.

/**
 * Updates derivate xml in the persistence backend
 * @param editorSubmission
 *  MyCoRe derivate as XML
 * @return
 *  MCRObjectID of the MyCoRe object
 * @throws SAXParseException
 * @throws MCRAccessException
 */
private MCRObjectID updateDerivateXML(Document editorSubmission) throws SAXParseException, IOException, MCRAccessException {
    MCRObjectID objectID;
    Element root = editorSubmission.getRootElement();
    root.setAttribute("noNamespaceSchemaLocation", "datamodel-derivate.xsd", XSI_NAMESPACE);
    root.addNamespaceDeclaration(XLINK_NAMESPACE);
    root.addNamespaceDeclaration(XSI_NAMESPACE);
    byte[] xml = new MCRJDOMContent(editorSubmission).asByteArray();
    MCRDerivate der = new MCRDerivate(xml, true);
    MCRObjectID derivateID = der.getId();
    // store entry of derivate xlink:title in object
    objectID = der.getDerivate().getMetaLink().getXLinkHrefID();
    MCRObject obj = MCRMetadataManager.retrieveMCRObject(objectID);
    MCRObjectStructure structure = obj.getStructure();
    MCRMetaLinkID linkID = structure.getDerivateLink(derivateID);
    linkID.setXLinkTitle(der.getLabel());
    try {
        MCRMetadataManager.update(obj);
        MCRMetadataManager.update(der);
    } catch (MCRPersistenceException | MCRAccessException e) {
        throw new MCRPersistenceException("Can't store label of derivate " + derivateID + " in derivate list of object " + objectID + ".", e);
    }
    return objectID;
}
Also used : MCRObjectStructure(org.mycore.datamodel.metadata.MCRObjectStructure) MCRObject(org.mycore.datamodel.metadata.MCRObject) Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRAccessException(org.mycore.access.MCRAccessException) MCRMetaLinkID(org.mycore.datamodel.metadata.MCRMetaLinkID) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRPersistenceException(org.mycore.common.MCRPersistenceException)

Example 64 with MCRObjectID

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

the class MCRUpdateObjectServlet method handlePersistenceOperation.

@Override
void handlePersistenceOperation(HttpServletRequest request, HttpServletResponse response) throws MCRAccessException, ServletException, MCRActiveLinkException, SAXParseException, JDOMException, IOException {
    MCRObjectID objectID = updateObject(MCRPersistenceHelper.getEditorSubmission(request, true));
    request.setAttribute(OBJECT_ID_KEY, objectID);
}
Also used : MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 65 with MCRObjectID

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

the class MCRObjectIDLockTable method getLockingUserName.

public static String getLockingUserName(String objectId) {
    MCRObjectID objId = MCRObjectID.getInstance(objectId);
    MCRSession locker = MCRObjectIDLockTable.getLocker(objId);
    if (locker == null) {
        return null;
    }
    return locker.getUserInformation().getUserID();
}
Also used : MCRSession(org.mycore.common.MCRSession) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

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