use of org.mycore.datamodel.metadata.MCRDerivate 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.MCRDerivate in project mycore by MyCoRe-Org.
the class MCREventHandlerBase method undoHandleEvent.
/**
* This method roll back all calls for EventHandler for the event types
* MCRObject, MCRDerivate and MCRFile.
*
* @param evt
* The MCREvent object
*/
public void undoHandleEvent(MCREvent evt) {
if (evt.getObjectType().equals(MCREvent.OBJECT_TYPE)) {
MCRObject obj = (MCRObject) evt.get("object");
if (obj != null) {
logger.debug("{} handling {} {}", getClass().getName(), obj.getId(), evt.getEventType());
switch(evt.getEventType()) {
case MCREvent.CREATE_EVENT:
undoObjectCreated(evt, obj);
break;
case MCREvent.UPDATE_EVENT:
undoObjectUpdated(evt, obj);
break;
case MCREvent.DELETE_EVENT:
undoObjectDeleted(evt, obj);
break;
case MCREvent.REPAIR_EVENT:
undoObjectRepaired(evt, obj);
break;
default:
logger.warn("Can't find method for an object data handler for event type {}", evt.getEventType());
break;
}
return;
}
logger.warn("Can't find method for " + MCREvent.OBJECT_TYPE + " for event type {}", evt.getEventType());
return;
}
if (evt.getObjectType().equals(MCREvent.DERIVATE_TYPE)) {
MCRDerivate der = (MCRDerivate) evt.get("derivate");
if (der != null) {
logger.debug("{} handling {}{}", getClass().getName(), der.getId(), evt.getEventType());
switch(evt.getEventType()) {
case MCREvent.CREATE_EVENT:
undoDerivateCreated(evt, der);
break;
case MCREvent.UPDATE_EVENT:
undoDerivateUpdated(evt, der);
break;
case MCREvent.DELETE_EVENT:
undoDerivateDeleted(evt, der);
break;
case MCREvent.REPAIR_EVENT:
undoDerivateRepaired(evt, der);
break;
default:
logger.warn("Can't find method for a derivate data handler for event type {}", evt.getEventType());
break;
}
return;
}
logger.warn("Can't find method for " + MCREvent.DERIVATE_TYPE + " for event type {}", evt.getEventType());
return;
}
if (evt.getObjectType().equals(MCREvent.PATH_TYPE)) {
Path path = (Path) evt.get(MCREvent.PATH_KEY);
if (path != null) {
if (!path.isAbsolute()) {
logger.warn("Cannot handle path events on non absolute paths: {}", path);
}
logger.debug("{} handling {} {}", getClass().getName(), path, evt.getEventType());
BasicFileAttributes attrs = (BasicFileAttributes) evt.get(MCREvent.FILEATTR_KEY);
if (attrs == null && !evt.getEventType().equals(MCREvent.DELETE_EVENT)) {
logger.warn("BasicFileAttributes for {} was not given. Resolving now.", path);
try {
attrs = Files.getFileAttributeView(path, BasicFileAttributeView.class).readAttributes();
} catch (IOException e) {
logger.error("Could not get BasicFileAttributes from path: {}", path, e);
}
}
switch(evt.getEventType()) {
case MCREvent.CREATE_EVENT:
undoPathCreated(evt, path, attrs);
break;
case MCREvent.UPDATE_EVENT:
undoPathUpdated(evt, path, attrs);
break;
case MCREvent.DELETE_EVENT:
undoPathDeleted(evt, path, attrs);
break;
case MCREvent.REPAIR_EVENT:
undoPathRepaired(evt, path, attrs);
break;
default:
logger.warn("Can't find method for Path data handler for event type {}", evt.getEventType());
break;
}
return;
}
logger.warn("Can't find method for " + MCREvent.PATH_TYPE + " for event type {}", evt.getEventType());
return;
}
if (evt.getObjectType().equals(MCREvent.CLASS_TYPE)) {
MCRCategory obj = (MCRCategory) evt.get("class");
if (obj != null) {
logger.debug("{} handling {} {}", getClass().getName(), obj.getId(), evt.getEventType());
switch(evt.getEventType()) {
case MCREvent.CREATE_EVENT:
undoClassificationCreated(evt, obj);
break;
case MCREvent.UPDATE_EVENT:
undoClassificationUpdated(evt, obj);
break;
case MCREvent.DELETE_EVENT:
undoClassificationDeleted(evt, obj);
break;
case MCREvent.REPAIR_EVENT:
undoClassificationRepaired(evt, obj);
break;
default:
logger.warn("Can't find method for an classification data handler for event type {}", evt.getEventType());
break;
}
return;
}
logger.warn("Can't find method for " + MCREvent.CLASS_TYPE + " for event type {}", evt.getEventType());
}
}
use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRUpdateDerivateServlet method updateDerivateXML.
/**
* Updates derivate xml in the persistence backend
* @param editorSubmission
* MyCoRe derivate as XML
* @return
* MCRObjectID of the MyCoRe object
* @throws SAXParseException
* @throws MCRAccessException
*/
private MCRObjectID updateDerivateXML(Document editorSubmission) throws SAXParseException, IOException, MCRAccessException {
MCRObjectID objectID;
Element root = editorSubmission.getRootElement();
root.setAttribute("noNamespaceSchemaLocation", "datamodel-derivate.xsd", XSI_NAMESPACE);
root.addNamespaceDeclaration(XLINK_NAMESPACE);
root.addNamespaceDeclaration(XSI_NAMESPACE);
byte[] xml = new MCRJDOMContent(editorSubmission).asByteArray();
MCRDerivate der = new MCRDerivate(xml, true);
MCRObjectID derivateID = der.getId();
// store entry of derivate xlink:title in object
objectID = der.getDerivate().getMetaLink().getXLinkHrefID();
MCRObject obj = MCRMetadataManager.retrieveMCRObject(objectID);
MCRObjectStructure structure = obj.getStructure();
MCRMetaLinkID linkID = structure.getDerivateLink(derivateID);
linkID.setXLinkTitle(der.getLabel());
try {
MCRMetadataManager.update(obj);
MCRMetadataManager.update(der);
} catch (MCRPersistenceException | MCRAccessException e) {
throw new MCRPersistenceException("Can't store label of derivate " + derivateID + " in derivate list of object " + objectID + ".", e);
}
return objectID;
}
use of org.mycore.datamodel.metadata.MCRDerivate 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));
}
}
use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRIView2Tools method getSupportedMainFile.
/**
* @param derivateID
* ID of derivate
* @return empty String or absolute path to main file of derivate if file is supported.
*/
public static String getSupportedMainFile(String derivateID) {
try {
MCRDerivate deriv = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(derivateID));
String nameOfMainFile = deriv.getDerivate().getInternals().getMainDoc();
// verify support
if (nameOfMainFile != null && !nameOfMainFile.equals("")) {
MCRPath mainFile = MCRPath.getPath(derivateID, '/' + nameOfMainFile);
if (mainFile != null && isFileSupported(mainFile))
return mainFile.getRoot().relativize(mainFile).toString();
}
} catch (Exception e) {
LOGGER.warn("Could not get main file of derivate.", e);
}
return "";
}
Aggregations