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;
}
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);
}
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;
}
}
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;
}
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);
}
}
Aggregations