Search in sources :

Example 1 with MCRISO8601Date

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;
}
Also used : MCRCache(org.mycore.common.MCRCache) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date) MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date) Date(java.util.Date)

Example 2 with MCRISO8601Date

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());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) ProviderMismatchException(java.nio.file.ProviderMismatchException) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference) MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date) Date(java.util.Date) HashSet(java.util.HashSet)

Example 3 with MCRISO8601Date

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);
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Element(org.jdom2.Element) MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date) Document(org.jdom2.Document)

Example 4 with MCRISO8601Date

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 "?";
    }
}
Also used : Locale(java.util.Locale) MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date)

Example 5 with MCRISO8601Date

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);
        }
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date) MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date) Date(java.util.Date)

Aggregations

MCRISO8601Date (org.mycore.datamodel.common.MCRISO8601Date)10 Date (java.util.Date)4 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)3 Document (org.jdom2.Document)2 Element (org.jdom2.Element)2 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)2 ProviderMismatchException (java.nio.file.ProviderMismatchException)1 DateTimeException (java.time.DateTimeException)1 LocalDate (java.time.LocalDate)1 HashSet (java.util.HashSet)1 Locale (java.util.Locale)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 Attribute (org.jdom2.Attribute)1 MCRCache (org.mycore.common.MCRCache)1 MCRPersistenceException (org.mycore.common.MCRPersistenceException)1 MCRCategLinkReference (org.mycore.datamodel.classifications2.MCRCategLinkReference)1 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)1 MCRPath (org.mycore.datamodel.niofs.MCRPath)1 MCRPersistentIdentifier (org.mycore.pi.MCRPersistentIdentifier)1