Search in sources :

Example 6 with MCRMetadataVersion

use of org.mycore.datamodel.ifs2.MCRMetadataVersion in project mycore by MyCoRe-Org.

the class MCRMetadataHistoryCommands method buildObjectHistory.

private static Stream<MCRMetaHistoryItem> buildObjectHistory(MCRObjectID objId) {
    try {
        List<MCRMetadataVersion> versions = Collections.emptyList();
        MCRMetadataStore store = MCRXMLMetadataManager.instance().getStore(objId);
        if (store instanceof MCRVersioningMetadataStore) {
            MCRVersionedMetadata versionedMetadata = ((MCRVersioningMetadataStore) store).retrieve(objId.getNumberAsInteger());
            versions = versionedMetadata.listVersions();
        }
        if (versions.isEmpty()) {
            return buildSimpleObjectHistory(objId);
        } else {
            return buildObjectHistory(objId, versions);
        }
    } catch (IOException e) {
        LogManager.getLogger().error("Error while getting history of {}", objId);
        return Stream.empty();
    }
}
Also used : MCRVersionedMetadata(org.mycore.datamodel.ifs2.MCRVersionedMetadata) MCRMetadataVersion(org.mycore.datamodel.ifs2.MCRMetadataVersion) MCRVersioningMetadataStore(org.mycore.datamodel.ifs2.MCRVersioningMetadataStore) IOException(java.io.IOException) MCRMetadataStore(org.mycore.datamodel.ifs2.MCRMetadataStore)

Example 7 with MCRMetadataVersion

use of org.mycore.datamodel.ifs2.MCRMetadataVersion in project mycore by MyCoRe-Org.

the class MCRObjectCommands method listRevisions.

/**
 * List revisions of an MyCoRe Object.
 *
 * @param id
 *            id of MyCoRe Object
 */
@MCRCommand(syntax = "list revisions of {0}", help = "List revisions of MCRObject.", order = 260)
public static void listRevisions(String id) {
    MCRObjectID mcrId = MCRObjectID.getInstance(id);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ROOT);
    try {
        StringBuilder log = new StringBuilder("Revisions:\n");
        List<MCRMetadataVersion> revisions = MCRXMLMetadataManager.instance().listRevisions(mcrId);
        for (MCRMetadataVersion revision : revisions) {
            log.append(revision.getRevision()).append(" ");
            log.append(revision.getType()).append(" ");
            log.append(sdf.format(revision.getDate())).append(" ");
            log.append(revision.getUser());
            log.append("\n");
        }
        LOGGER.info(log.toString());
    } catch (Exception exc) {
        LOGGER.error("While print revisions.", exc);
    }
}
Also used : MCRMetadataVersion(org.mycore.datamodel.ifs2.MCRMetadataVersion) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) SimpleDateFormat(java.text.SimpleDateFormat) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom2.JDOMException) MCRPersistenceException(org.mycore.common.MCRPersistenceException) SAXException(org.xml.sax.SAXException) MCRActiveLinkException(org.mycore.datamodel.common.MCRActiveLinkException) TransformerException(javax.xml.transform.TransformerException) MCRException(org.mycore.common.MCRException) MCRAccessException(org.mycore.access.MCRAccessException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Aggregations

MCRMetadataVersion (org.mycore.datamodel.ifs2.MCRMetadataVersion)7 IOException (java.io.IOException)3 JDOMException (org.jdom2.JDOMException)3 MCRVersionedMetadata (org.mycore.datamodel.ifs2.MCRVersionedMetadata)3 SAXException (org.xml.sax.SAXException)3 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 MCRMetadataStore (org.mycore.datamodel.ifs2.MCRMetadataStore)2 MCRVersioningMetadataStore (org.mycore.datamodel.ifs2.MCRVersioningMetadataStore)2 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)2 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)2 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)2 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 MCRAccessException (org.mycore.access.MCRAccessException)1 MCRException (org.mycore.common.MCRException)1 MCRPersistenceException (org.mycore.common.MCRPersistenceException)1