Search in sources :

Example 1 with ModifiedHandle

use of org.mycore.common.MCRCache.ModifiedHandle in project mycore by MyCoRe-Org.

the class MCRMetadataManager method getDerivateIds.

/**
 * Returns a list of MCRObjectID of the derivates contained in the object with the given ID.
 *
 * @param objectId
 *            objectId
 * @param expire
 *            when should lastModified information expire
 * @return null if object with objectId does not exist
 * @see #getObjectId(MCRObjectID, long, TimeUnit)
 */
public static List<MCRObjectID> getDerivateIds(final MCRObjectID objectId, final long expire, final TimeUnit unit) {
    ModifiedHandle modifiedHandle = XML_MANAGER.getLastModifiedHandle(objectId, expire, unit);
    List<MCRObjectID> derivateIds = null;
    try {
        derivateIds = objectDerivateMap.getIfUpToDate(objectId, modifiedHandle);
    } catch (IOException e) {
        LOGGER.warn("Could not determine last modified timestamp of derivate {}", objectId);
    }
    if (derivateIds != null) {
        return derivateIds;
    }
    derivateIds = MCRObjectUtils.getDerivates(objectId);
    if (!derivateIds.isEmpty()) {
        return derivateIds;
    } else {
        if (exists(objectId)) {
            MCRObject mcrObject = MCRMetadataManager.retrieveMCRObject(objectId);
            List<MCRMetaLinkID> derivates = mcrObject.getStructure().getDerivates();
            for (MCRMetaLinkID der : derivates) {
                derivateIds.add(der.getXLinkHrefID());
            }
        }
    }
    return derivateIds;
}
Also used : ModifiedHandle(org.mycore.common.MCRCache.ModifiedHandle) IOException(java.io.IOException)

Example 2 with ModifiedHandle

use of org.mycore.common.MCRCache.ModifiedHandle 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 3 with ModifiedHandle

use of org.mycore.common.MCRCache.ModifiedHandle in project mycore by MyCoRe-Org.

the class MCRMetadataManager method getObjectId.

/**
 * Returns the MCRObjectID of the object containing derivate with the given ID.
 *
 * @param derivateID
 *            derivateID
 * @param expire
 *            when should lastModified information expire
 * @return null if derivateID has no object referenced
 * @see #getDerivateIds(MCRObjectID, long, TimeUnit)
 */
public static MCRObjectID getObjectId(final MCRObjectID derivateID, final long expire, TimeUnit unit) {
    ModifiedHandle modifiedHandle = XML_MANAGER.getLastModifiedHandle(derivateID, expire, unit);
    MCRObjectID mcrObjectID = null;
    try {
        mcrObjectID = derivateObjectMap.getIfUpToDate(derivateID, modifiedHandle);
    } catch (IOException e) {
        LOGGER.warn("Could not determine last modified timestamp of derivate {}", derivateID);
    }
    if (mcrObjectID != null) {
        return mcrObjectID;
    }
    // one cheap db query
    Collection<String> list = MCRLinkTableManager.instance().getSourceOf(derivateID, MCRLinkTableManager.ENTRY_TYPE_DERIVATE);
    if (!(list == null || list.isEmpty())) {
        mcrObjectID = MCRObjectID.getInstance(list.iterator().next());
    } else {
        // one expensive process
        if (exists(derivateID)) {
            mcrObjectID = MCRMetadataManager.retrieveMCRDerivate(derivateID).getOwnerID();
        }
    }
    if (mcrObjectID == null) {
        return null;
    }
    derivateObjectMap.put(derivateID, mcrObjectID);
    return mcrObjectID;
}
Also used : ModifiedHandle(org.mycore.common.MCRCache.ModifiedHandle) IOException(java.io.IOException)

Example 4 with ModifiedHandle

use of org.mycore.common.MCRCache.ModifiedHandle in project mycore by MyCoRe-Org.

the class MCRMODSEmbargoUtils method getCachedEmbargo.

public static String getCachedEmbargo(final MCRObjectID objectId) {
    ModifiedHandle modifiedHandle = MCRXMLMetadataManager.instance().getLastModifiedHandle(objectId, 10, TimeUnit.MINUTES);
    String embargo = null;
    try {
        embargo = embargoCache.getIfUpToDate(objectId, modifiedHandle);
    } catch (IOException e) {
        LOGGER.warn("Could not determine last modified timestamp of object {}", objectId);
    }
    if (embargo != null) {
        return embargo == EMPTY_VALUE ? null : embargo;
    }
    MCRMODSWrapper modsWrapper = new MCRMODSWrapper(MCRMetadataManager.retrieveMCRObject(objectId));
    embargo = modsWrapper.getElementValue("mods:accessCondition[@type='embargo']");
    embargoCache.put(objectId, embargo != null ? embargo : EMPTY_VALUE);
    return embargo;
}
Also used : ModifiedHandle(org.mycore.common.MCRCache.ModifiedHandle) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)4 ModifiedHandle (org.mycore.common.MCRCache.ModifiedHandle)4 JDOMException (org.jdom2.JDOMException)1 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)1 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)1 SAXException (org.xml.sax.SAXException)1