use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRTransferPackageUtil method importDerivate.
/**
* Imports a derivate from the given target directory path.
*
* @param targetDirectory path to the extracted *.tar archive
* @param derivateId the derivate to import
* @throws JDOMException derivate xml couldn't be read
* @throws IOException some file system stuff went wrong
* @throws MCRAccessException you do not have the permissions to do the import
*/
public static void importDerivate(Path targetDirectory, String derivateId) throws JDOMException, IOException, MCRAccessException {
SAXBuilder sax = new SAXBuilder();
Path derivateDirectory = targetDirectory.resolve(CONTENT_DIRECTORY).resolve(derivateId);
Path derivatePath = derivateDirectory.resolve(derivateId + ".xml");
LOGGER.info(MessageFormat.format("Importing {0}", derivatePath.toAbsolutePath().toString()));
MCRDerivate der = new MCRDerivate(sax.build(derivatePath.toFile()));
MCRMetadataManager.update(der);
MCRDirectory dir = MCRDirectory.getRootDirectory(der.getId().toString());
if (dir == null) {
LOGGER.info("Creating missing {} {}", MCRFilesystemNode.class.getSimpleName(), der.getId());
final MCRDirectory difs = new MCRDirectory(der.getId().toString());
der.getDerivate().getInternals().setIFSID(difs.getID());
MCRMetadataManager.update(der);
}
try (Stream<Path> stream = Files.find(derivateDirectory, 5, filterDerivateDirectory(derivateId, derivateDirectory))) {
stream.forEach(path -> {
String targetPath = derivateDirectory.relativize(path).toString();
try (InputStream in = Files.newInputStream(path)) {
Files.copy(in, MCRPath.getPath(derivateId, targetPath), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException ioExc) {
throw new MCRException("Unable to add file " + path.toAbsolutePath() + " to derivate " + derivateId, ioExc);
}
});
}
}
use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRMetsIIIFPresentationImpl method getMets.
public Document getMets(String id) throws IOException, JDOMException, SAXException {
String objectid = MCRLinkTableManager.instance().getSourceOf(id).iterator().next();
MCRContentTransformer transformer = getTransformer();
MCRParameterCollector parameter = new MCRParameterCollector();
if (objectid != null && objectid.length() != 0) {
MCRDerivate derObj = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(id));
MCRObjectID ownerID = derObj.getOwnerID();
objectid = ownerID.toString();
parameter.setParameter("objectID", objectid);
parameter.setParameter("derivateID", id);
}
MCRPath metsPath = MCRPath.getPath(id, "mets.xml");
if (!Files.exists(metsPath)) {
throw new MCRException("File not found: " + id);
}
MCRPathContent source = new MCRPathContent(metsPath);
MCRContent content = transformer instanceof MCRParameterizedTransformer ? ((MCRParameterizedTransformer) transformer).transform(source, parameter) : transformer.transform(source);
return content.asXML();
}
use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRIFSTest method createDerivate.
public static MCRDerivate createDerivate(MCRObjectID objectHrefId) {
MCRDerivate derivate = new MCRDerivate();
derivate.setId(MCRObjectID.getNextFreeId("mycore_derivate"));
derivate.setSchema("datamodel-derivate.xsd");
MCRMetaIFS ifs = new MCRMetaIFS();
ifs.setSubTag("internal");
ifs.setSourcePath(null);
derivate.getDerivate().setInternals(ifs);
MCRMetaLinkID mcrMetaLinkID = new MCRMetaLinkID();
mcrMetaLinkID.setReference(objectHrefId.toString(), null, null);
derivate.getDerivate().setLinkMeta(mcrMetaLinkID);
return derivate;
}
use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRMODSCommands method createDerivate.
private static MCRDerivate createDerivate(MCRObjectID documentID, File fileDir) throws MCRPersistenceException, IOException, MCRAccessException {
MCRDerivate derivate = new MCRDerivate();
derivate.setId(MCRObjectID.getNextFreeId(documentID.getProjectId(), "derivate"));
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(fileDir.getAbsolutePath());
derivate.getDerivate().setInternals(ifs);
LOGGER.debug("Creating new derivate with ID {}", derivate.getId());
MCRMetadataManager.create(derivate);
setDefaultPermissions(derivate.getId());
return derivate;
}
use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRDFGLinkServlet method doGetPost.
@Override
protected void doGetPost(MCRServletJob job) throws Exception {
HttpServletRequest request = job.getRequest();
HttpServletResponse response = job.getResponse();
String filePath = request.getParameter("file") == null ? "" : request.getParameter("file");
String derivateID = request.getParameter("deriv") == null ? "" : request.getParameter("deriv");
if (derivateID.equals("")) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Derivate is not set");
}
String encodedMetsURL = URLEncoder.encode(MCRServlet.getServletBaseURL() + "MCRMETSServlet/" + derivateID + "?XSL.Style=dfg", "UTF-8");
LOGGER.info(request.getPathInfo());
MCRPath rootPath = MCRPath.getPath(derivateID, "/");
if (!Files.isDirectory(rootPath)) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, MessageFormat.format("Derivate {0} does not exist.", derivateID));
return;
}
request.setAttribute("XSL.derivateID", derivateID);
Collection<String> linkList = MCRLinkTableManager.instance().getSourceOf(derivateID);
if (linkList.isEmpty()) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, MessageFormat.format("Derivate {0} is not linked with a MCRObject. Please contact an administrator.", derivateID));
return;
}
// TODO: this seems very very wrong
if (filePath == "") {
MCRDerivate derivate = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(derivateID));
filePath = derivate.getDerivate().getInternals().getMainDoc();
}
MCRPath metsPath = (MCRPath) rootPath.resolve("mets.xml");
int imageNumber = -2;
if (Files.exists(metsPath)) {
imageNumber = getOrderNumber(new MCRPathContent(metsPath).asXML(), filePath);
} else {
MCRContent metsContent = getMetsSource(job, useExistingMets(request), derivateID);
imageNumber = getOrderNumber(metsContent.asXML(), filePath);
}
String dfgURL = "";
switch(imageNumber) {
case -1:
response.sendError(HttpServletResponse.SC_CONFLICT, MessageFormat.format("Image \"{0}\" not found in the MCRDerivate. Please contact an administrator.", filePath));
return;
case -2:
dfgURL = "http://dfg-viewer.de/show/?set[mets]=" + encodedMetsURL;
break;
default:
dfgURL = "http://dfg-viewer.de/show/?set[mets]=" + encodedMetsURL + "&set[image]=" + imageNumber;
break;
}
response.sendRedirect(dfgURL);
}
Aggregations