Search in sources :

Example 6 with MCRMetadataStore

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

the class MCRMetadataHistoryCommands method buildHistory.

@MCRCommand(syntax = "build metadata history of base {0}", help = "build metadata history of all objects with base id {0}")
public static List<String> buildHistory(String baseId) {
    MCRMetadataStore store = MCRXMLMetadataManager.instance().getStore(baseId);
    if (store instanceof MCRVersioningMetadataStore) {
        LogManager.getLogger().info("Verify SVN history of {}", baseId);
        ((MCRVersioningMetadataStore) store).verify();
    }
    ExecutorService executorService = Executors.newWorkStealingPool();
    MCRSession currentSession = MCRSessionMgr.getCurrentSession();
    int maxId = store.getHighestStoredID();
    AtomicInteger completed = new AtomicInteger(maxId);
    IntStream.rangeClosed(1, maxId).parallel().mapToObj(i -> MCRObjectID.formatID(baseId, i)).map(MCRObjectID::getInstance).map(id -> new MCRTransactionableCallable<>(Executors.callable(() -> {
        EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
        getHistoryItems(id).sequential().forEach(em::persist);
        completed.decrementAndGet();
    }), currentSession)).forEach(executorService::submit);
    executorService.shutdown();
    boolean waitToFinish = true;
    while (!executorService.isTerminated() && waitToFinish) {
        LogManager.getLogger().info("Waiting for history of {} objects/derivates.", completed.get());
        try {
            executorService.awaitTermination(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            waitToFinish = false;
        }
    }
    return Collections.emptyList();
}
Also used : IntStream(java.util.stream.IntStream) MCRTransactionableCallable(org.mycore.util.concurrent.MCRTransactionableCallable) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) ArrayList(java.util.ArrayList) JDOMException(org.jdom2.JDOMException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) MCRXMLMetadataManager(org.mycore.datamodel.common.MCRXMLMetadataManager) CriteriaDelete(javax.persistence.criteria.CriteriaDelete) MCRCommandGroup(org.mycore.frontend.cli.annotation.MCRCommandGroup) MCRCreatorCache(org.mycore.datamodel.common.MCRCreatorCache) ExecutorService(java.util.concurrent.ExecutorService) Root(javax.persistence.criteria.Root) MCRMetadataVersion(org.mycore.datamodel.ifs2.MCRMetadataVersion) MCRMetadataManager(org.mycore.datamodel.metadata.MCRMetadataManager) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) MCREntityManagerProvider(org.mycore.backend.jpa.MCREntityManagerProvider) MCRVersionedMetadata(org.mycore.datamodel.ifs2.MCRVersionedMetadata) List(java.util.List) Stream(java.util.stream.Stream) MCRSystemUserInformation(org.mycore.common.MCRSystemUserInformation) MCRVersioningMetadataStore(org.mycore.datamodel.ifs2.MCRVersioningMetadataStore) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand) MCRSession(org.mycore.common.MCRSession) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRSessionMgr(org.mycore.common.MCRSessionMgr) MCRObject(org.mycore.datamodel.metadata.MCRObject) SAXException(org.xml.sax.SAXException) Optional(java.util.Optional) MCRMetadataStore(org.mycore.datamodel.ifs2.MCRMetadataStore) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) MCRTransactionableCallable(org.mycore.util.concurrent.MCRTransactionableCallable) MCRMetadataStore(org.mycore.datamodel.ifs2.MCRMetadataStore) EntityManager(javax.persistence.EntityManager) MCRSession(org.mycore.common.MCRSession) MCRVersioningMetadataStore(org.mycore.datamodel.ifs2.MCRVersioningMetadataStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 7 with MCRMetadataStore

use of org.mycore.datamodel.ifs2.MCRMetadataStore 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 8 with MCRMetadataStore

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

the class MCRXMLMetadataManager method getVersionedMetaData.

public MCRVersionedMetadata getVersionedMetaData(MCRObjectID id) throws IOException {
    if (id == null) {
        return null;
    }
    MCRMetadataStore metadataStore = getStore(id);
    if (!(metadataStore instanceof MCRVersioningMetadataStore)) {
        return null;
    }
    MCRVersioningMetadataStore verStore = (MCRVersioningMetadataStore) metadataStore;
    return verStore.retrieve(id.getNumberAsInteger());
}
Also used : MCRVersioningMetadataStore(org.mycore.datamodel.ifs2.MCRVersioningMetadataStore) MCRMetadataStore(org.mycore.datamodel.ifs2.MCRMetadataStore)

Example 9 with MCRMetadataStore

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

the class MCRXMLMetadataManager method listIDsForBase.

/**
 * Lists all MCRObjectIDs stored for the given base, which is {project}_{type}
 *
 * @param base the MCRObjectID base, e.g. DocPortal_document
 */
public List<String> listIDsForBase(String base) {
    MCRMetadataStore store = getStore(base);
    List<String> list = new ArrayList<>();
    Iterator<Integer> it = store.listIDs(MCRStore.ASCENDING);
    String[] idParts = MCRObjectID.getIDParts(base);
    while (it.hasNext()) {
        list.add(MCRObjectID.formatID(idParts[0], idParts[1], it.next()));
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) 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