use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRMETSDefaultGenerator method generate.
@Override
public Mets generate() throws MCRException {
try {
Mets mets = createMets();
MCRDerivate owner = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(getOwner()));
mets.getLogicalStructMap().getDivContainer().setLabel(MCRTranslation.exists("MCR.Mets.LogicalStructMap.Default.Label") ? MCRTranslation.translate("MCR.Mets.LogicalStructMap.Default.Label") : owner.getId().toString());
Map<String, String> urnFileMap = owner.getUrnMap();
if (urnFileMap.size() > 0) {
try {
MCRMetsSave.updateURNsInMetsDocument(mets, urnFileMap);
} catch (Exception e) {
LOGGER.error("error while adding urnĀ“s to new Mets file", e);
}
}
return mets;
} catch (Exception ioExc) {
throw new MCRException("Unable to create mets.xml of " + getOwner(), ioExc);
}
}
use of org.mycore.datamodel.metadata.MCRDerivate 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.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRUpdateMetsOnDerivateChangeEventHandler method checkUpdateMets.
/**
* Checks if the mets.xml should be updated.
*
* @param evt the mcr event
* @param file the file which was changed
* @param attrs the file attributes
* @return true if the mets shoud be updated, otherwise false
*/
protected boolean checkUpdateMets(MCREvent evt, Path file, BasicFileAttributes attrs) {
// don't update if no MCRPath
if (!(file instanceof MCRPath)) {
return false;
}
// don't update if mets.xml is deleted
Path fileName = file.getFileName();
if (fileName != null && fileName.toString().equals(mets)) {
return false;
}
MCRPath mcrPath = MCRPath.toMCRPath(file);
String derivateId = mcrPath.getOwner();
// don't update if mets.xml does not exist
if (Files.notExists(MCRPath.getPath(derivateId, '/' + mets))) {
return false;
}
// don't update if derivate or mycore object is marked for deletion
MCRObjectID mcrDerivateId = MCRObjectID.getInstance(derivateId);
MCRDerivate mcrDerivate = MCRMetadataManager.retrieveMCRDerivate(mcrDerivateId);
return !MCRMarkManager.instance().isMarkedForDeletion(mcrDerivate);
}
use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRMetadataHistoryCommands method buildDerivateHistory.
private static Stream<MCRMetaHistoryItem> buildDerivateHistory(MCRObjectID derId, List<MCRMetadataVersion> versions) throws IOException {
boolean exist = false;
LogManager.getLogger().debug("Complete history rebuild of {} should be possible", derId);
ArrayList<MCRMetaHistoryItem> items = new ArrayList<>(100);
for (MCRMetadataVersion version : versions) {
String user = version.getUser();
Instant revDate = version.getDate().toInstant();
if (version.getType() == MCRMetadataVersion.DELETED) {
if (exist) {
items.add(delete(derId, user, revDate));
exist = false;
}
} else {
// created or updated
int timeOffset = 0;
if (version.getType() == MCRMetadataVersion.CREATED && !exist) {
items.add(create(derId, user, revDate));
timeOffset = 1;
exist = true;
}
try {
MCRDerivate derivate = new MCRDerivate(version.retrieve().asXML());
boolean derivateIsHidden = !derivate.getDerivate().isDisplayEnabled();
if (derivateIsHidden && exist) {
items.add(delete(derId, user, revDate.plusMillis(timeOffset)));
exist = false;
} else if (!derivateIsHidden && !exist) {
items.add(create(derId, user, revDate.plusMillis(timeOffset)));
exist = true;
}
} catch (JDOMException | SAXException e) {
LogManager.getLogger().error("Error while reading revision {} of {}", version.getRevision(), derId, e);
}
}
}
return items.stream();
}
use of org.mycore.datamodel.metadata.MCRDerivate in project mycore by MyCoRe-Org.
the class MCRMetadataHistoryCommands method buildSimpleDerivateHistory.
private static Stream<MCRMetaHistoryItem> buildSimpleDerivateHistory(MCRObjectID derId) throws IOException {
boolean exist = false;
LogManager.getLogger().debug("Store of {} has no old revisions. History rebuild is limited", derId);
if (MCRMetadataManager.exists(derId)) {
MCRDerivate der = MCRMetadataManager.retrieveMCRDerivate(derId);
Instant lastModified = Instant.ofEpochMilli(MCRXMLMetadataManager.instance().getLastModified(derId));
String creator;
try {
creator = MCRCreatorCache.getCreator(der.getId());
} catch (ExecutionException e) {
LogManager.getLogger().warn("Error while getting creator of {}", derId, e);
creator = null;
}
String user = Optional.ofNullable(creator).orElseGet(() -> MCRSystemUserInformation.getSystemUserInstance().getUserID());
MCRMetaHistoryItem create = create(derId, user, lastModified);
exist = true;
boolean objectIsHidden = !der.getDerivate().isDisplayEnabled();
if (objectIsHidden && exist) {
return Stream.of(create, delete(derId, user, lastModified.plusMillis(1)));
}
return Stream.of(create);
} else {
return Stream.of(delete(derId, null, Instant.now()));
}
}
Aggregations