use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRUploadHandlerIFS method createDerivate.
private MCRDerivate createDerivate(MCRObjectID derivateID) throws MCRPersistenceException, IOException, MCRAccessException {
MCRDerivate derivate = new MCRDerivate();
derivate.setId(derivateID);
derivate.setLabel("data object from " + documentID);
String schema = CONFIG.getString("MCR.Metadata.Config.derivate", "datamodel-derivate.xml").replaceAll(".xml", ".xsd");
derivate.setSchema(schema);
MCRMetaLinkID linkId = new MCRMetaLinkID();
linkId.setSubTag("linkmeta");
linkId.setReference(documentID, null, null);
derivate.getDerivate().setLinkMeta(linkId);
MCRMetaIFS ifs = new MCRMetaIFS();
ifs.setSubTag("internal");
ifs.setSourcePath(null);
derivate.getDerivate().setInternals(ifs);
LOGGER.debug("Creating new derivate with ID {}", this.derivateID);
MCRMetadataManager.create(derivate);
setDefaultPermissions(derivateID);
return derivate;
}
use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRDisplayHideDerivateServlet method doGetPost.
@Override
protected void doGetPost(MCRServletJob job) throws Exception {
String derivate = job.getRequest().getParameter("derivate");
if (derivate == null || (!derivate.contains("_derivate_"))) {
LOGGER.error("Cannot toogle display attribute. No derivate id provided.");
job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "You must provide a proper derivate id");
return;
}
if (!MCRAccessManager.checkPermission(MCRObjectID.getInstance(derivate), PERMISSION_WRITE)) {
job.getResponse().sendError(HttpServletResponse.SC_FORBIDDEN, "You have to be logged in.");
return;
}
LOGGER.info("Toggling display attribute of {}", derivate);
MCRDerivate obj = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(derivate));
toggleDisplay(obj);
String url = MCRFrontendUtil.getBaseURL() + "receive/" + getParentHref(obj);
job.getResponse().sendRedirect(job.getResponse().encodeRedirectURL(url));
}
use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRDisplayHideDerivateServlet method toggleDisplay.
/**
* Toggles the display attribute value of the derivate element.
*/
private void toggleDisplay(MCRDerivate derObj) throws Exception {
Document xml = derObj.createXML();
Element derivateNode = xml.getRootElement().getChild("derivate");
Attribute displayAttr = derivateNode.getAttribute("display");
/* the attributs is not existing, user wants to hide derivate */
if (displayAttr == null) {
displayAttr = new Attribute("display", "false");
derivateNode.setAttribute(displayAttr);
} else /* attribute exists, thus toggle the attribute value */
{
String oldVal = displayAttr.getValue();
String newVal = oldVal.equals(String.valueOf(true)) ? String.valueOf(false) : String.valueOf(true);
displayAttr.setValue(newVal);
LOGGER.info("Setting display attribute of derivate with id {} to {}", derObj.getId(), newVal);
}
MCRDerivate updated = new MCRDerivate(xml);
MCRMetadataManager.updateMCRDerivateXML(updated);
}
use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRSwordMediaHandler method deleteMediaResource.
public void deleteMediaResource(String derivateId, String requestFilePath) throws SwordError, SwordServerException {
if (!MCRAccessManager.checkPermission(derivateId, MCRAccessManager.PERMISSION_DELETE)) {
throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "You dont have the right to delete (from) the derivate!");
}
if (requestFilePath == null || requestFilePath.equals("/")) {
final MCRObjectID derivateID = MCRObjectID.getInstance(derivateId);
if (MCRMetadataManager.exists(derivateID)) {
final MCRDerivate mcrDerivate = MCRMetadataManager.retrieveMCRDerivate(derivateID);
try {
MCRMetadataManager.delete(mcrDerivate);
} catch (MCRAccessException e) {
throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, e);
}
} else {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_NOT_FOUND, "The requested Object '" + requestFilePath + "' does not exists.");
}
} else {
final MCRPath path = MCRPath.getPath(derivateId, requestFilePath);
checkFile(path);
try {
if (Files.isDirectory(path)) {
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
} else {
Files.delete(path);
}
} catch (IOException e) {
throw new SwordServerException("Error while deleting media resource!", e);
}
}
}
use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRSwordUtil method createDerivate.
public static MCRDerivate createDerivate(String documentID) throws MCRPersistenceException, IOException, MCRAccessException {
final String projectId = MCRObjectID.getInstance(documentID).getProjectId();
MCRObjectID oid = MCRObjectID.getNextFreeId(projectId, "derivate");
final String derivateID = oid.toString();
MCRDerivate derivate = new MCRDerivate();
derivate.setId(oid);
derivate.setLabel("data object from " + documentID);
String schema = CONFIG.getString("MCR.Metadata.Config.derivate", "datamodel-derivate.xml").replaceAll(".xml", ".xsd");
derivate.setSchema(schema);
MCRMetaLinkID linkId = new MCRMetaLinkID();
linkId.setSubTag("linkmeta");
linkId.setReference(documentID, null, null);
derivate.getDerivate().setLinkMeta(linkId);
MCRMetaIFS ifs = new MCRMetaIFS();
ifs.setSubTag("internal");
ifs.setSourcePath(null);
derivate.getDerivate().setInternals(ifs);
LOGGER.debug("Creating new derivate with ID {}", derivateID);
MCRMetadataManager.create(derivate);
if (CONFIG.getBoolean("MCR.Access.AddDerivateDefaultRule", true)) {
MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
Collection<String> configuredPermissions = AI.getAccessPermissionsFromConfiguration();
for (String permission : configuredPermissions) {
MCRAccessManager.addRule(derivateID, permission, MCRAccessManager.getTrueRule(), "default derivate rule");
}
}
final MCRPath rootDir = MCRPath.getPath(derivateID, "/");
if (Files.notExists(rootDir)) {
rootDir.getFileSystem().createRoot(derivateID);
}
return derivate;
}
Aggregations