use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRCompressServlet method think.
@Override
protected void think(MCRServletJob job) throws Exception {
HttpServletRequest req = job.getRequest();
// id parameter for backward compatibility
String paramid = getProperty(req, "id");
if (paramid == null) {
String pathInfo = req.getPathInfo();
if (pathInfo != null) {
paramid = pathInfo.substring(1);
}
}
if (paramid == null) {
job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "What should I do?");
return;
}
Matcher ma = PATH_INFO_PATTERN.matcher(paramid);
// path & directory
MCRObjectID id;
String path;
try {
if (ma.find()) {
id = MCRObjectID.getInstance(ma.group(1));
path = ma.group(2);
} else {
id = MCRObjectID.getInstance(paramid);
path = null;
}
} catch (MCRException e) {
String objId = ma.find() ? ma.group(1) : paramid;
job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "ID is not valid: " + objId);
return;
}
boolean readPermission = id.getTypeId().equals("derivate") ? MCRAccessManager.checkPermissionForReadingDerivate(id.toString()) : MCRAccessManager.checkPermission(id, PERMISSION_READ);
if (!readPermission) {
job.getResponse().sendError(HttpServletResponse.SC_FORBIDDEN, "You may not read " + id);
return;
}
req.setAttribute(KEY_OBJECT_ID, id);
req.setAttribute(KEY_PATH, path);
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRPersistenceHelper method getMCRObject.
/**
* creates a MCRObject instance on base of JDOM document
* @param doc
* MyCoRe object as XML.
* @return
* @throws JDOMException
* exception from underlying {@link MCREditorOutValidator}
* @throws IOException
* exception from underlying {@link MCREditorOutValidator} or {@link XMLOutputter}
* @throws SAXParseException
* @throws MCRException
*/
static MCRObject getMCRObject(Document doc) throws JDOMException, IOException, MCRException, SAXParseException {
String id = doc.getRootElement().getAttributeValue("ID");
MCRObjectID objectID = MCRObjectID.getInstance(id);
MCREditorOutValidator ev = new MCREditorOutValidator(doc, objectID);
Document jdom_out = ev.generateValidMyCoReObject();
if (ev.getErrorLog().size() > 0 && LOGGER.isDebugEnabled()) {
XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
StringWriter swOrig = new StringWriter();
xout.output(doc, swOrig);
LOGGER.debug("Input document \n{}", swOrig);
for (String logMsg : ev.getErrorLog()) {
LOGGER.debug(logMsg);
}
StringWriter swClean = new StringWriter();
xout.output(jdom_out, swClean);
LOGGER.debug("Results in \n{}", swClean);
}
return new MCRObject(jdom_out);
}
use of org.mycore.datamodel.metadata.MCRObjectID 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.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRUpdateObjectServlet method handlePersistenceOperation.
@Override
void handlePersistenceOperation(HttpServletRequest request, HttpServletResponse response) throws MCRAccessException, ServletException, MCRActiveLinkException, SAXParseException, JDOMException, IOException {
MCRObjectID objectID = updateObject(MCRPersistenceHelper.getEditorSubmission(request, true));
request.setAttribute(OBJECT_ID_KEY, objectID);
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRObjectIDLockTable method getLockingUserName.
public static String getLockingUserName(String objectId) {
MCRObjectID objId = MCRObjectID.getInstance(objectId);
MCRSession locker = MCRObjectIDLockTable.getLocker(objId);
if (locker == null) {
return null;
}
return locker.getUserInformation().getUserID();
}
Aggregations