use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MetsResource method get.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/crud/{derivateId}")
public String get(@PathParam("derivateId") String derivateId) {
MCRObjectID derivateIdObject = MCRObjectID.getInstance(derivateId);
checkDerivateExists(derivateIdObject);
checkDerivateAccess(derivateIdObject, MCRAccessManager.PERMISSION_READ);
MCRPath rootPath = MCRPath.getPath(derivateId, "/");
if (!Files.isDirectory(rootPath)) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
MCRPath metsPath = MCRPath.getPath(derivateId, METS_XML_PATH);
try {
return MCRSimpleModelJSONConverter.toJSON(MCRXMLSimpleModelConverter.fromXML(getMetsDocument(metsPath)));
} catch (Exception e) {
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MetsResource method save.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/crud/{derivateId}")
public String save(@PathParam("derivateId") String derivateId, String data) {
MCRObjectID derivateIdObject = MCRObjectID.getInstance(derivateId);
checkDerivateExists(derivateIdObject);
checkDerivateAccess(derivateIdObject, MCRAccessManager.PERMISSION_WRITE);
MCRMetsSimpleModel model = MCRJSONSimpleModelConverter.toSimpleModel(data);
Document document = MCRSimpleModelXMLConverter.toXML(model);
XMLOutputter o = new XMLOutputter();
try (OutputStream out = Files.newOutputStream(MCRPath.getPath(derivateId, METS_XML_PATH), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
o.output(document, out);
} catch (IOException e) {
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
return "{ \"success\": true }";
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MetsResource method startEditor.
@GET
@Path("/editor/start/{derivateId}")
@Produces(MediaType.TEXT_HTML)
public String startEditor(@PathParam("derivateId") String derivateId) {
MCRObjectID derivateIdObject = MCRObjectID.getInstance(derivateId);
checkDerivateExists(derivateIdObject);
checkDerivateAccess(derivateIdObject, MCRAccessManager.PERMISSION_WRITE);
InputStream resourceAsStream = MetsResource.class.getClassLoader().getResourceAsStream("mets-editor.html");
try {
StringWriter writer = new StringWriter();
IOUtils.copy(resourceAsStream, writer, Charset.forName("UTF-8"));
String htmlTemplate = writer.toString();
// add additional javascript code
String js = MCRConfiguration.instance().getString("MCR.Mets.Editor.additional.javascript", null);
if (js != null && !js.isEmpty()) {
htmlTemplate = htmlTemplate.replace("<link rel=\"additionalJS\" />", js);
}
// replace variables
htmlTemplate = htmlTemplate.replaceAll("\\{baseURL\\}", MCRFrontendUtil.getBaseURL()).replaceAll("\\{derivateID\\}", derivateId);
return htmlTemplate;
} catch (IOException e) {
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRMETSServlet method doGetPost.
@Override
protected void doGetPost(MCRServletJob job) throws Exception {
HttpServletRequest request = job.getRequest();
HttpServletResponse response = job.getResponse();
LOGGER.info(request.getPathInfo());
String derivate = getOwnerID(request.getPathInfo());
MCRPath rootPath = MCRPath.getPath(derivate, "/");
if (!Files.isDirectory(rootPath)) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, MessageFormat.format("Derivate {0} does not exist.", derivate));
return;
}
request.setAttribute("XSL.derivateID", derivate);
Collection<String> linkList = MCRLinkTableManager.instance().getSourceOf(derivate);
if (linkList.isEmpty()) {
MCRDerivate derivate2 = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(derivate));
MCRObjectID ownerID = derivate2.getOwnerID();
if (ownerID != null && ownerID.toString().length() != 0) {
linkList.add(ownerID.toString());
} else {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, MessageFormat.format("Derivate {0} is not linked with a MCRObject. Please contact an administrator.", derivate));
return;
}
}
request.setAttribute("XSL.objectID", linkList.iterator().next());
response.setContentType("text/xml");
long lastModified = Files.getLastModifiedTime(rootPath).toMillis();
MCRFrontendUtil.writeCacheHeaders(response, (long) CACHE_TIME, lastModified, useExpire);
long start = System.currentTimeMillis();
MCRContent metsContent = getMetsSource(job, useExistingMets(request), derivate);
MCRLayoutService.instance().doLayout(request, response, metsContent);
LOGGER.info("Generation of code by {} took {} ms", this.getClass().getSimpleName(), System.currentTimeMillis() - start);
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRMetsLock method doLock.
/**
* Locks a Derivate with the current SessionId
* @param derivateIdString the Derivate to lock
* @return True if the derivate is locked. False if the derivate could not be locked.
*/
public static synchronized boolean doLock(String derivateIdString) {
MCRObjectID derivateId = MCRObjectID.getInstance(derivateIdString);
if (isLocked(derivateIdString) && MCRMetsLock.metsAccessSessionTable.get(derivateId) != MCRSessionMgr.getCurrentSessionID()) {
LOGGER.info(MessageFormat.format("Could not lock {0}, because its already locked.", derivateIdString));
return false;
} else {
LOGGER.info(MessageFormat.format("{0} is now locked", derivateIdString));
MCRMetsLock.metsAccessSessionTable.put(derivateId, MCRSessionMgr.getCurrentSessionID());
return true;
}
}
Aggregations