use of org.mycore.datamodel.common.MCRISO8601Date in project mycore by MyCoRe-Org.
the class MCRSolrFileIndexBaseAccumulator method getDerivateModified.
/**
* returns ISO8601 formated string of when derivate was last modified
*
* @param derivateID
* @throws IOException
* thrown by {@link MCRCache.ModifiedHandle#getLastModified()}
*/
private static String getDerivateModified(final String derivateID) throws IOException {
MCRObjectID derID = MCRObjectID.getInstance(derivateID);
MCRCache.ModifiedHandle modifiedHandle = XML_MANAGER.getLastModifiedHandle(derID, 30, TimeUnit.SECONDS);
String modified = derivateModified.getIfUpToDate(derivateID, modifiedHandle);
if (modified == null) {
Date date = new Date(modifiedHandle.getLastModified());
MCRISO8601Date date2 = new MCRISO8601Date();
date2.setDate(date);
modified = date2.getISOString();
derivateModified.put(derivateID, modified);
}
return modified;
}
use of org.mycore.datamodel.common.MCRISO8601Date in project mycore by MyCoRe-Org.
the class MCRSolrFileIndexBaseAccumulator method accumulate.
@Override
public void accumulate(SolrInputDocument doc, Path input, BasicFileAttributes attr) throws IOException {
doc.setField("id", input.toUri().toString());
String absolutePath = '/' + input.subpath(0, input.getNameCount()).toString();
try {
// check if this is an MCRPath -> more metadata
MCRPath mcrPath = MCRPath.toMCRPath(input);
MCRObjectID mcrObjID = MCRMetadataManager.getObjectId(MCRObjectID.getInstance(mcrPath.getOwner()), 10, TimeUnit.SECONDS);
if (mcrObjID == null) {
LOGGER.warn("Could not determine MCRObject for file {}", absolutePath);
doc.setField("returnId", mcrPath.getOwner());
} else {
doc.setField("returnId", mcrObjID.toString());
doc.setField("objectProject", mcrObjID.getProjectId());
}
String ownerID = mcrPath.getOwner();
doc.setField("derivateID", ownerID);
doc.setField("derivateModified", getDerivateModified(ownerID));
Collection<MCRCategoryID> linksFromReference = MCRCategLinkServiceFactory.getInstance().getLinksFromReference(new MCRCategLinkReference(mcrPath));
HashSet<MCRCategoryID> linkedCategories = new HashSet<>(linksFromReference);
for (MCRCategoryID category : linksFromReference) {
for (MCRCategory parent : CATEGORY_DAO.getParents(category)) {
linkedCategories.add(parent.getId());
}
}
for (MCRCategoryID category : linkedCategories) {
doc.addField("fileCategory", category.toString());
}
} catch (ProviderMismatchException e) {
LOGGER.warn("Cannot build all fields as input is not an instance of MCRPath: {}", input);
}
doc.setField("objectType", "data_file");
doc.setField("fileName", input.getFileName().toString());
doc.setField("filePath", absolutePath);
doc.setField("stream_size", attr.size());
doc.setField("stream_name", absolutePath);
doc.setField("stream_source_info", input.toString());
doc.setField("stream_content_type", MCRContentTypes.probeContentType(input));
doc.setField("extension", Files.getFileExtension(input.getFileName().toString()));
MCRISO8601Date iDate = new MCRISO8601Date();
iDate.setDate(new Date(attr.lastModifiedTime().toMillis()));
doc.setField("modified", iDate.getISOString());
}
use of org.mycore.datamodel.common.MCRISO8601Date in project mycore by MyCoRe-Org.
the class MCRFile method createXML.
/**
* Build a XML representation of all technical metadata of this MCRFile and its MCRAudioVideoExtender, if present. That xml can be used for indexing this
* data.
*/
public Document createXML() {
Element root = new Element("file");
root.setAttribute("id", getID());
root.setAttribute("owner", getOwnerID());
root.setAttribute("name", getName());
String absolutePath = getAbsolutePath();
root.setAttribute("path", absolutePath);
root.setAttribute("size", Long.toString(getSize()));
root.setAttribute("extension", getExtension());
root.setAttribute("contentTypeID", getContentTypeID());
root.setAttribute("contentType", getContentType().getLabel());
root.setAttribute("returnId", getMCRObjectID().toString());
Collection<MCRCategoryID> linksFromReference = MCRCategLinkServiceFactory.getInstance().getLinksFromReference(getCategLinkReference(MCRObjectID.getInstance(getOwnerID()), absolutePath));
for (MCRCategoryID category : linksFromReference) {
Element catEl = new Element("category");
catEl.setAttribute("id", category.toString());
root.addContent(catEl);
}
MCRISO8601Date iDate = new MCRISO8601Date();
iDate.setDate(getLastModified().getTime());
root.setAttribute("modified", iDate.getISOString());
if (hasAudioVideoExtender()) {
MCRAudioVideoExtender ext = getAudioVideoExtender();
root.setAttribute("bitRate", String.valueOf(ext.getBitRate()));
root.setAttribute("frameRate", String.valueOf(ext.getFrameRate()));
root.setAttribute("duration", ext.getDurationTimecode());
root.setAttribute("mediaType", (ext.hasVideoStream() ? "video" : "audio"));
}
return new Document(root);
}
use of org.mycore.datamodel.common.MCRISO8601Date in project mycore by MyCoRe-Org.
the class MCRXMLFunctions method formatISODate.
public static String formatISODate(String isoDate, String isoFormat, String simpleFormat, String iso639Language, String timeZone) throws ParseException {
if (LOGGER.isDebugEnabled()) {
String sb = "isoDate=" + isoDate + ", simpleFormat=" + simpleFormat + ", isoFormat=" + isoFormat + ", iso649Language=" + iso639Language + ", timeZone=" + timeZone;
LOGGER.debug(sb);
}
Locale locale = new Locale(iso639Language);
MCRISO8601Date mcrdate = new MCRISO8601Date();
mcrdate.setFormat(isoFormat);
mcrdate.setDate(isoDate);
try {
String formatted = mcrdate.format(simpleFormat, locale, timeZone);
return formatted == null ? "?" + isoDate + "?" : formatted;
} catch (RuntimeException iae) {
LOGGER.error("Unable to format date {} to {} with locale {} and timezone {}", mcrdate.getISOString(), simpleFormat, locale, timeZone, iae);
return "?";
}
}
use of org.mycore.datamodel.common.MCRISO8601Date in project mycore by MyCoRe-Org.
the class MCRCompressServlet method render.
@Override
protected void render(MCRServletJob job, Exception ex) throws Exception {
if (ex != null) {
// we cannot handle it ourself
throw ex;
}
if (job.getResponse().isCommitted()) {
return;
}
MCRObjectID id = (MCRObjectID) job.getRequest().getAttribute(KEY_OBJECT_ID);
String path = (String) job.getRequest().getAttribute(KEY_PATH);
try (ServletOutputStream sout = job.getResponse().getOutputStream()) {
StringBuffer requestURL = job.getRequest().getRequestURL();
if (job.getRequest().getQueryString() != null) {
requestURL.append('?').append(job.getRequest().getQueryString());
}
MCRISO8601Date mcriso8601Date = new MCRISO8601Date();
mcriso8601Date.setDate(new Date());
String comment = "Created by " + requestURL + " at " + mcriso8601Date.getISOString();
try (T container = createContainer(sout, comment)) {
job.getResponse().setContentType(getMimeType());
String filename = getFileName(id, path);
job.getResponse().addHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
if (id.getTypeId().equals("derivate")) {
sendDerivate(id, path, container);
} else {
sendObject(id, job, container);
}
disposeContainer(container);
}
}
}
Aggregations