Search in sources :

Example 66 with MCRObjectID

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

the class MCRDerivateServlet method setMainFile.

/**
 * The method set the main file of a derivate object that is stored in the
 * server. The method use the input parameter: <b>type</b>,<b>step</b>
 * <b>se_mcrid</b> and <b>re_mcrid</b>. Access rights must be 'writedb'.
 */
private void setMainFile(String derivateId, String file, HttpServletResponse response) throws IOException {
    if (MCRAccessManager.checkPermission(derivateId, PERMISSION_WRITE)) {
        MCRObjectID mcrid = MCRObjectID.getInstance(derivateId);
        MCRDerivate der = MCRMetadataManager.retrieveMCRDerivate(mcrid);
        der.getDerivate().getInternals().setMainDoc(file);
        MCRMetadataManager.updateMCRDerivateXML(der);
    } else {
        response.sendError(HttpServletResponse.SC_FORBIDDEN, MessageFormat.format("User has not the \"" + PERMISSION_WRITE + "\" permission on object {0}.", derivateId));
    }
}
Also used : MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 67 with MCRObjectID

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

the class MCRMETSHierarchyGenerator method setup.

/**
 * Initializes the derivate and the root object.
 *
 * @param derivateId the derivate id to setup
 */
protected void setup(String derivateId) {
    // get derivate
    MCRObjectID derId = MCRObjectID.getInstance(derivateId);
    this.mcrDer = MCRMetadataManager.retrieveMCRDerivate(derId);
    // get mycore object
    MCRObjectID objId = this.mcrDer.getDerivate().getMetaLink().getXLinkHrefID();
    this.rootObj = MCRMetadataManager.retrieveMCRObject(objId);
}
Also used : MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 68 with MCRObjectID

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

the class MCRMETSHierarchyGenerator method newLogicalStructMap.

protected LogicalStructMap newLogicalStructMap() {
    LogicalStructMap lstr = new LogicalStructMap();
    MCRObjectID objId = this.rootObj.getId();
    // create main div
    String amdId = this.amdSection.getId();
    String dmdId = this.dmdSection.getId();
    LogicalDiv logicalDiv = new LogicalDiv(objId.toString(), getType(this.rootObj), getLabel(this.rootObj), amdId, dmdId);
    lstr.setDivContainer(logicalDiv);
    // run through all children
    newLogicalStructMap(this.rootObj, logicalDiv);
    // remove not linked logical divs
    logicalDiv.getChildren().removeIf(child -> !validateLogicalStruct(child));
    return lstr;
}
Also used : LogicalStructMap(org.mycore.mets.model.struct.LogicalStructMap) LogicalDiv(org.mycore.mets.model.struct.LogicalDiv) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 69 with MCRObjectID

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

the class MCRMetsResolver method resolve.

@Override
public Source resolve(String href, String base) throws TransformerException {
    String id = href.substring(href.indexOf(":") + 1);
    LOGGER.debug("Reading METS for ID {}", id);
    MCRObjectID objId = MCRObjectID.getInstance(id);
    if (!objId.getTypeId().equals("derivate")) {
        String derivateID = getDerivateFromObject(id);
        if (derivateID == null) {
            return new JDOMSource(new Element("mets", Namespace.getNamespace("mets", "http://www.loc.gov/METS/")));
        }
        id = derivateID;
    }
    MCRPath metsPath = MCRPath.getPath(id, "/mets.xml");
    try {
        if (Files.exists(metsPath)) {
            // ignoreNodes.add(metsFile);
            return new MCRPathContent(metsPath).getSource();
        }
        Document mets = MCRMETSGeneratorFactory.create(MCRPath.getPath(id, "/")).generate().asDocument();
        return new JDOMSource(mets);
    } catch (Exception e) {
        throw new TransformerException(e);
    }
}
Also used : Element(org.jdom2.Element) MCRPathContent(org.mycore.common.content.MCRPathContent) JDOMSource(org.jdom2.transform.JDOMSource) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRPath(org.mycore.datamodel.niofs.MCRPath) Document(org.jdom2.Document) TransformerException(javax.xml.transform.TransformerException) TransformerException(javax.xml.transform.TransformerException)

Example 70 with MCRObjectID

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

the class MCRMetsSave method updateMetsOnFileAdd.

/**
 * Updates the mets.xml belonging to the given derivate. Adds the file to
 * the mets document (updates file sections and stuff within the mets.xml)
 *
 * @param file
 *            a handle for the file to add to the mets.xml
 */
public static void updateMetsOnFileAdd(MCRPath file) throws Exception {
    MCRObjectID derivateID = MCRObjectID.getInstance(file.getOwner());
    Document mets = getCurrentMets(derivateID.toString());
    if (mets == null) {
        LOGGER.info("Derivate with id \"{}\" has no mets file. Nothing to do", derivateID);
        return;
    }
    mets = MCRMetsSave.updateOnFileAdd(mets, file);
    if (mets != null) {
        MCRMetsSave.saveMets(mets, derivateID);
    }
}
Also used : MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Document(org.jdom2.Document)

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