Search in sources :

Example 1 with MCRMetadataStore

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

the class MCRXMLMetadataManager method getStore.

/**
 * Returns IFS2 MCRMetadataStore for the given project and object type
 *
 * @param project the project, e.g. DocPortal
 * @param type the object type, e.g. document
 */
public MCRMetadataStore getStore(String project, String type) {
    String projectType = getStoryKey(project, type);
    String prefix = "MCR.IFS2.Store." + projectType + ".";
    String forceXML = MCRConfiguration.instance().getString(prefix + "ForceXML", null);
    if (forceXML == null) {
        synchronized (this) {
            forceXML = MCRConfiguration.instance().getString(prefix + "ForceXML", null);
            if (forceXML == null) {
                try {
                    setupStore(project, type, prefix);
                } catch (ReflectiveOperationException e) {
                    throw new MCRPersistenceException(MessageFormat.format("Could not instantiate store for project {0} and object type {1}.", project, type), e);
                }
            }
        }
    }
    MCRMetadataStore store = MCRStoreManager.getStore(projectType, MCRMetadataStore.class);
    if (store == null) {
        throw new MCRPersistenceException(MessageFormat.format("Metadata store for project {0} and object type {1} is unconfigured.", project, type));
    }
    return store;
}
Also used : MCRPersistenceException(org.mycore.common.MCRPersistenceException) MCRMetadataStore(org.mycore.datamodel.ifs2.MCRMetadataStore)

Example 2 with MCRMetadataStore

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

the class MCRXMLMetadataManager method getLastModified.

/**
 * Returns the time when the xml data of a MCRObject was last modified.
 * @return output of {@link MCRStoredMetadata#getLastModified()}
 * @throws IOException thrown by {@link MCRMetadataStore#retrieve(int)}
 */
public long getLastModified(MCRObjectID id) throws IOException {
    MCRMetadataStore store = getStore(id);
    MCRStoredMetadata metadata = store.retrieve(id.getNumberAsInteger());
    if (metadata != null) {
        return metadata.getLastModified().getTime();
    }
    return -1;
}
Also used : MCRStoredMetadata(org.mycore.datamodel.ifs2.MCRStoredMetadata) MCRMetadataStore(org.mycore.datamodel.ifs2.MCRMetadataStore)

Example 3 with MCRMetadataStore

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

the class MCRMetadataHistoryCommands method buildDerivateHistory.

private static Stream<MCRMetaHistoryItem> buildDerivateHistory(MCRObjectID derId) {
    try {
        List<MCRMetadataVersion> versions = Collections.emptyList();
        MCRMetadataStore store = MCRXMLMetadataManager.instance().getStore(derId);
        if (store instanceof MCRVersioningMetadataStore) {
            MCRVersionedMetadata versionedMetadata = ((MCRVersioningMetadataStore) store).retrieve(derId.getNumberAsInteger());
            versions = versionedMetadata.listVersions();
        }
        if (versions.isEmpty()) {
            return buildSimpleDerivateHistory(derId);
        } else {
            return buildDerivateHistory(derId, versions);
        }
    } catch (IOException e) {
        LogManager.getLogger().error("Error while getting history of {}", derId);
        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 4 with MCRMetadataStore

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

the class MCRMODSLinkedMetadataTest method tearDown.

@After
public void tearDown() throws Exception {
    MCRMetadataManager.deleteMCRObject(bookID);
    MCRMetadataManager.deleteMCRObject(seriesID);
    MCRMetadataStore metadataStore = MCRXMLMetadataManager.instance().getStore(seriesID);
    MCRStoreManager.removeStore(metadataStore.getID());
    super.tearDown();
}
Also used : MCRMetadataStore(org.mycore.datamodel.ifs2.MCRMetadataStore) After(org.junit.After)

Example 5 with MCRMetadataStore

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

the class MCRObjectServlet method requestVersionedObject.

private MCRContent requestVersionedObject(final MCRObjectID mcrid, final HttpServletResponse resp, final long rev) throws IOException {
    MCRXMLMetadataManager xmlMetadataManager = MCRXMLMetadataManager.instance();
    MCRMetadataStore metadataStore = xmlMetadataManager.getStore(mcrid);
    if (metadataStore instanceof MCRVersioningMetadataStore) {
        MCRContent content = xmlMetadataManager.retrieveContent(mcrid, rev);
        if (content != null) {
            return content;
        }
        resp.sendError(HttpServletResponse.SC_NOT_FOUND, getErrorI18N(I18N_ERROR_PREFIX, "revisionNotFound", rev, mcrid));
        return null;
    }
    resp.sendError(HttpServletResponse.SC_BAD_REQUEST, getErrorI18N(I18N_ERROR_PREFIX, "noVersions", mcrid));
    return null;
}
Also used : MCRVersioningMetadataStore(org.mycore.datamodel.ifs2.MCRVersioningMetadataStore) MCRXMLMetadataManager(org.mycore.datamodel.common.MCRXMLMetadataManager) MCRContent(org.mycore.common.content.MCRContent) MCRMetadataStore(org.mycore.datamodel.ifs2.MCRMetadataStore)

Aggregations

MCRMetadataStore (org.mycore.datamodel.ifs2.MCRMetadataStore)9 MCRVersioningMetadataStore (org.mycore.datamodel.ifs2.MCRVersioningMetadataStore)5 IOException (java.io.IOException)3 MCRMetadataVersion (org.mycore.datamodel.ifs2.MCRMetadataVersion)3 MCRVersionedMetadata (org.mycore.datamodel.ifs2.MCRVersionedMetadata)3 ArrayList (java.util.ArrayList)2 MCRXMLMetadataManager (org.mycore.datamodel.common.MCRXMLMetadataManager)2 Instant (java.time.Instant)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 EntityManager (javax.persistence.EntityManager)1