use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRObjectServlet method getMCRObjectID.
private MCRObjectID getMCRObjectID(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
final String pathInfo = req.getPathInfo();
final String id = pathInfo == null ? null : pathInfo.substring(1);
MCRObjectID mcrid = null;
if (id != null) {
try {
// create Object with given ID, only ID syntax check performed
mcrid = MCRObjectID.getInstance(id);
} catch (final MCRException e) {
// handle exception: invalid ID syntax, set HTTP error 400 "Invalid request"
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, getErrorI18N(I18N_ERROR_PREFIX, "invalidID", id));
// sorry, no object to return
return null;
}
}
return mcrid;
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRCreateObjectServlet method createObject.
/**
* Adds a new mycore object to the persistence backend.
* @param doc
* MyCoRe object as XML
* @return
* MCRObjectID of the newly created object.
* @throws MCRActiveLinkException
* If links from or to other objects will fail.
* @throws JDOMException
* from {@link MCRPersistenceHelper#getMCRObject(Document)}
* @throws IOException
* from {@link MCRPersistenceHelper#getMCRObject(Document)}
* @throws SAXParseException
* @throws MCRException
* @throws MCRAccessException
*/
private MCRObjectID createObject(Document doc) throws MCRActiveLinkException, JDOMException, IOException, MCRException, SAXParseException, MCRAccessException {
MCRObject mcrObject = MCRPersistenceHelper.getMCRObject(doc);
MCRObjectID objectId = mcrObject.getId();
// noinspection SynchronizeOnNonFinalField
checkCreatePrivilege(objectId);
synchronized (this) {
if (objectId.getNumberAsInteger() == 0) {
String objId = mcrObject.getId().toString();
objectId = MCRObjectID.getNextFreeId(objectId.getBase());
if (mcrObject.getLabel().equals(objId))
mcrObject.setLabel(objectId.toString());
mcrObject.setId(objectId);
}
}
MCRMetadataManager.create(mcrObject);
return objectId;
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRCreateObjectServlet method handlePersistenceOperation.
@Override
void handlePersistenceOperation(HttpServletRequest request, HttpServletResponse response) throws MCRAccessException, ServletException, MCRActiveLinkException, SAXParseException, JDOMException, IOException {
Document editorSubmission = MCRPersistenceHelper.getEditorSubmission(request, false);
MCRObjectID objectID;
if (editorSubmission != null) {
objectID = createObject(editorSubmission);
} else {
// editorSubmission is null, when editor input is absent (redirect to editor form in render phase)
String projectID = getProperty(request, "project");
String type = getProperty(request, "type");
String formattedId = MCRObjectID.formatID(projectID + "_" + type, 0);
objectID = MCRObjectID.getInstance(formattedId);
}
checkCreatePrivilege(objectID);
request.setAttribute(OBJECT_ID_KEY, objectID);
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRCreateObjectServlet method redirectToCreateObject.
/**
* redirects to new mcrobject form.
*
* At least "type" HTTP parameter is required to succeed.
* <dl>
* <dt>type</dt>
* <dd>object type of the new object (required)</dd>
* <dt>project</dt>
* <dd>project ID part of object ID (required)</dd>
* <dt>layout</dt>
* <dd>special editor form layout</dd>
* </dl>
*/
private void redirectToCreateObject(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
MCRObjectID objectID = (MCRObjectID) request.getAttribute(OBJECT_ID_KEY);
StringBuilder sb = new StringBuilder();
sb.append("editor_form_author").append('-').append(objectID.getTypeId());
String layout = getProperty(request, "layout");
if (layout != null && layout.length() != 0) {
sb.append('-').append(layout);
}
String base_name = sb.toString();
String form = MCRPersistenceHelper.getWebPage(getServletContext(), base_name + ".xed", base_name + ".xml");
Properties params = new Properties();
params.put("cancelUrl", MCRPersistenceHelper.getCancelUrl(request));
params.put("mcrid", objectID.toString());
Enumeration<String> e = request.getParameterNames();
while (e.hasMoreElements()) {
String name = e.nextElement();
String value = request.getParameter(name);
params.put(name, value);
}
response.sendRedirect(response.encodeRedirectURL(buildRedirectURL(MCRFrontendUtil.getBaseURL() + form, params)));
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRCreateObjectServlet method displayResult.
@Override
void displayResult(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// return to object itself if created, else call editor form
MCRObjectID returnID = (MCRObjectID) request.getAttribute(OBJECT_ID_KEY);
if (returnID.getNumberAsInteger() == 0) {
redirectToCreateObject(request, response);
} else {
Properties params = MCRPersistenceHelper.getXSLProperties(request);
if (this.appendDerivate) {
params.put("id", returnID.toString());
params.put("cancelURL", MCRFrontendUtil.getBaseURL() + "receive/" + returnID);
response.sendRedirect(response.encodeRedirectURL(buildRedirectURL(MCRFrontendUtil.getBaseURL() + "servlets/derivate/create", params)));
} else {
response.sendRedirect(response.encodeRedirectURL(buildRedirectURL(MCRFrontendUtil.getBaseURL() + "receive/" + returnID, params)));
}
}
}
Aggregations