Search in sources :

Example 91 with MCRObjectID

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

the class MCRMetadataHistoryManager method getHighestStoredID.

public static Optional<MCRObjectID> getHighestStoredID(String project, String type) {
    String looksLike = Objects.requireNonNull(project) + "\\_" + Objects.requireNonNull(type) + "%";
    EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
    TypedQuery<MCRObjectID> query = em.createNamedQuery("MCRMetaHistory.getHighestID", MCRObjectID.class);
    query.setParameter("looksLike", looksLike);
    return Optional.ofNullable(query.getSingleResult());
}
Also used : EntityManager(javax.persistence.EntityManager) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 92 with MCRObjectID

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

the class MCRBasketPersistence method updateBasket.

/**
 * Updates the basket's data in the persistent store by saving its XML representation
 * to a file in a derivate. The ID of the derivate is given in the basket's properties.
 */
public static void updateBasket(MCRBasket basket) throws Exception {
    String derivateID = basket.getDerivateID();
    MCRObjectID derivateOID = MCRObjectID.getInstance(derivateID);
    MCRDerivate derivate = MCRMetadataManager.retrieveMCRDerivate(derivateOID);
    MCRPath file = getBasketFile(derivateID);
    writeBasketToFile(basket, derivate, file);
}
Also used : MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRPath(org.mycore.datamodel.niofs.MCRPath)

Example 93 with MCRObjectID

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

the class MCRBasketPersistence method createDerivateWithBasket.

/**
 * Creates a new derivate including a file basket.xml which stores the persistent
 * data of the given basket.
 *
 * @param basket the basket to store in a new file in a new derivate
 * @param ownerID the ID of the MCRObject owning the new derivate
 * @throws MCRAccessException see {@link MCRMetadataManager#create(MCRDerivate)}
 * @throws MCRPersistenceException
 */
public static void createDerivateWithBasket(MCRBasket basket, MCRObjectID ownerID) throws IOException, MCRPersistenceException, MCRAccessException {
    String base = ownerID.getProjectId() + "_derivate";
    MCRObjectID derivateOID = MCRObjectID.getNextFreeId(base);
    String derivateID = derivateOID.toString();
    MCRDerivate derivate = createNewDerivate(ownerID, derivateOID);
    basket.setDerivateID(derivateID);
    writeBasketToFile(basket, derivate, getBasketFile(derivateID));
}
Also used : MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 94 with MCRObjectID

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

the class MCRDefaultMetadataShareAgent method receiveMetadata.

/* (non-Javadoc)
     * @see org.mycore.datamodel.metadata.share.MCRMetadataShareAgent#inheritMetadata(org.mycore.datamodel.metadata.MCRObject, org.mycore.datamodel.metadata.MCRObject)
     */
@Override
public void receiveMetadata(MCRObject child) {
    MCRObjectID parentID = child.getStructure().getParentID();
    if (parentID == null) {
        return;
    }
    LOGGER.debug("Parent ID = {}", parentID);
    MCRObject parent = MCRMetadataManager.retrieveMCRObject(parentID);
    // remove already embedded inherited tags
    child.getMetadata().removeInheritedMetadata();
    // insert heritable tags
    child.getMetadata().appendMetadata(parent.getMetadata().getHeritableMetadata());
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 95 with MCRObjectID

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

the class MCRViewerResource method getContent.

protected MCRContent getContent(final HttpServletRequest req) throws Exception {
    // get derivate id from request object
    String derivate = MCRViewerConfiguration.getDerivate(req);
    if (derivate == null) {
        MCRJerseyUtil.throwException(Status.BAD_REQUEST, "Could not locate derivate identifer in path.");
    }
    // get mycore object id
    final MCRObjectID derivateID = MCRObjectID.getInstance(derivate);
    if (!MCRMetadataManager.exists(derivateID)) {
        String errorMessage = MCRTranslation.translate("component.viewer.MCRIViewClientServlet.object.not.found", derivateID);
        MCRJerseyUtil.throwException(Status.NOT_FOUND, errorMessage);
    }
    // check permission
    if (IVIEW_ACL_PROVDER != null && !IVIEW_ACL_PROVDER.checkAccess(req.getSession(), derivateID)) {
        String errorMessage = MCRTranslation.translate("component.viewer.MCRIViewClientServlet.noRights", derivateID);
        MCRJerseyUtil.throwException(Status.UNAUTHORIZED, errorMessage);
    }
    // build configuration object
    MCRViewerConfigurationStrategy configurationStrategy = MCRConfiguration.instance().getInstanceOf("MCR.Viewer.configuration.strategy", new MCRViewerDefaultConfigurationStrategy());
    MCRJDOMContent source = new MCRJDOMContent(buildResponseDocument(configurationStrategy.get(req)));
    MCRParameterCollector parameter = new MCRParameterCollector(req);
    MCRContentTransformer transformer = getContentTransformer(source.getDocType(), parameter);
    return transformer.transform(source);
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) MCRViewerConfigurationStrategy(org.mycore.viewer.configuration.MCRViewerConfigurationStrategy) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRViewerDefaultConfigurationStrategy(org.mycore.viewer.configuration.MCRViewerDefaultConfigurationStrategy) MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer) 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