Search in sources :

Example 51 with MCRObjectID

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

the class MCRViewerMetadataConfiguration method setup.

@Override
public MCRViewerConfiguration setup(HttpServletRequest request) {
    super.setup(request);
    String derivate = getDerivate(request);
    MCRObjectID derivateID = MCRObjectID.getInstance(derivate);
    final MCRObjectID objectID = MCRMetadataManager.getObjectId(derivateID, EXPIRE_METADATA_CACHE_TIME, TimeUnit.SECONDS);
    if (objectID == null) {
        String errorMessage = MCRTranslation.translate("component.viewer.MCRIViewClientServlet.object.not.found", objectID);
        // TODO: we should not throw an webapplication exc. here -> instead throw something líke ConfigException
        throw new WebApplicationException(Response.status(Status.NOT_FOUND).entity(errorMessage).build());
    }
    // properties
    setProperty("objId", objectID.toString());
    String urlFormat = "%sreceive/%s?XSL.Transformer=%s";
    MCRConfiguration mcrConfiguration = MCRConfiguration.instance();
    String transformer = mcrConfiguration.getString("MCR.Viewer.metadata.transformer", null);
    if (transformer != null) {
        setProperty("metadataURL", String.format(Locale.ROOT, urlFormat, MCRFrontendUtil.getBaseURL(), objectID, transformer));
    }
    // script
    addLocalScript("iview-client-metadata.js", isDebugParameterSet(request));
    return this;
}
Also used : MCRConfiguration(org.mycore.common.config.MCRConfiguration) WebApplicationException(javax.ws.rs.WebApplicationException) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 52 with MCRObjectID

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

the class MCRURLRetriever method getURLforID.

public static String getURLforID(String action, String mcrID, boolean absolute) {
    final MCRObjectID objID = MCRObjectID.getInstance(mcrID);
    String collectionName = MCRClassificationUtils.getCollection(mcrID);
    return getURL(action, collectionName, new MCRCategLinkReference(objID), absolute);
}
Also used : MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference)

Example 53 with MCRObjectID

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

the class MCRXMLFunctions method isWorldReadable.

/**
 * Checks if the given object is readable to guest user.
 * @param objId MCRObjectID as String
 */
public static boolean isWorldReadable(String objId) {
    if (objId == null || !MCRObjectID.isValid(objId)) {
        return false;
    }
    MCRObjectID mcrObjectID = MCRObjectID.getInstance(objId);
    CompletableFuture<Boolean> permission = MCRAccessManager.checkPermission(MCRSystemUserInformation.getGuestInstance(), () -> MCRAccessManager.checkPermission(mcrObjectID, MCRAccessManager.PERMISSION_READ));
    try {
        return permission.join();
    } catch (CancellationException | CompletionException e) {
        LOGGER.error("Error while retriving ACL information for Object {}", objId, e);
        return false;
    }
}
Also used : CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 54 with MCRObjectID

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

the class MCRXMLFunctions method isDisplayedEnabledDerivate.

public static boolean isDisplayedEnabledDerivate(String derivateId) {
    MCRObjectID derId = MCRObjectID.getInstance(derivateId);
    ModifiedHandle modifiedHandle = MCRXMLMetaDataManagerHolder.instance.getLastModifiedHandle(derId, 30, TimeUnit.SECONDS);
    Boolean result;
    try {
        result = DISPLAY_DERIVATE_CACHE.getIfUpToDate(derivateId, modifiedHandle);
    } catch (IOException e) {
        LOGGER.warn("Error while determining when {} was last modified.", derId, e);
        return false;
    }
    if (result != null) {
        return result;
    }
    MCRDerivate der;
    try {
        org.jdom2.Document derDoc = MCRXMLMetaDataManagerHolder.instance.retrieveXML(derId);
        if (derDoc == null) {
            LOGGER.error("Derivate \"{}\" does not exist", derId);
            return false;
        }
        der = new MCRDerivate(derDoc);
    } catch (SAXException | JDOMException | IOException | RuntimeException e) {
        LOGGER.warn("Error while loading derivate: {}", derId, e);
        return false;
    }
    org.jdom2.Element derivateElem = der.getDerivate().createXML();
    String display = derivateElem.getAttributeValue("display", "true");
    Boolean returnValue = Boolean.valueOf(display);
    DISPLAY_DERIVATE_CACHE.put(derivateId, returnValue);
    return returnValue;
}
Also used : ModifiedHandle(org.mycore.common.MCRCache.ModifiedHandle) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) SAXException(org.xml.sax.SAXException) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 55 with MCRObjectID

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

the class MCRObjectServlet method getContent.

@Override
public MCRContent getContent(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final MCRObjectID mcrid = getMCRObjectID(req, resp);
    if (mcrid == null) {
        return null;
    }
    if (!MCRAccessManager.checkPermission(mcrid, PERMISSION_READ)) {
        // check read permission for ID
        final MCRSession currentSession = MCRSessionMgr.getCurrentSession();
        resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, getErrorI18N(I18N_ERROR_PREFIX, "accessDenied", mcrid.toString(), currentSession.getUserInformation().getUserID(), currentSession.getCurrentIP()));
        return null;
    }
    long rev = REV_CURRENT;
    final String revision = getProperty(req, "r");
    if (revision != null) {
        rev = Long.parseLong(revision);
    }
    MCRContent localObject = (rev == REV_CURRENT) ? requestLocalObject(mcrid, resp) : requestVersionedObject(mcrid, resp, rev);
    if (localObject == null) {
        return null;
    }
    try {
        return getLayoutService().getTransformedContent(req, resp, localObject);
    } catch (TransformerException | SAXException e) {
        throw new IOException(e);
    }
}
Also used : MCRSession(org.mycore.common.MCRSession) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) IOException(java.io.IOException) MCRContent(org.mycore.common.content.MCRContent) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

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