Search in sources :

Example 86 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID 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)

Example 87 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.

the class MCRClassificationUtils method isInCollection.

public static boolean isInCollection(String mcrId, String collection) {
    MCRObjectID mcrObjectID = MCRObjectID.getInstance(mcrId);
    MCRCategoryID collectionID = new MCRCategoryID(MCRConstants.COLLECTION_CLASS_ID.getRootID(), collection);
    MCRCategLinkReference reference = new MCRCategLinkReference(mcrObjectID);
    return LINK_SERVICE.isInCategory(reference, collectionID);
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference)

Example 88 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.

the class MCRClassificationUtils method getCollectionFromDerivate.

private static String getCollectionFromDerivate(MCRObjectID mcrObjectID) {
    Collection<String> sourceOf = LINK_TABLE.getSourceOf(mcrObjectID, MCRLinkTableManager.ENTRY_TYPE_DERIVATE);
    if (sourceOf.isEmpty()) {
        return null;
    }
    MCRObjectID metaObjectID = MCRObjectID.getInstance(sourceOf.iterator().next());
    return getCollectionFromObject(metaObjectID);
}
Also used : MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 89 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.

the class MCRMetadataHistoryCommands method buildSingleHistory.

@MCRCommand(syntax = "build metadata history of id {0}", help = "build metadata history of object/derivate with id {0}")
public static void buildSingleHistory(String mcrId) {
    MCRObjectID objId = MCRObjectID.getInstance(mcrId);
    EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
    getHistoryItems(objId).sequential().forEach(em::persist);
}
Also used : EntityManager(javax.persistence.EntityManager) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 90 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID 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)

Aggregations

MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)144 IOException (java.io.IOException)37 MCRObject (org.mycore.datamodel.metadata.MCRObject)32 MCRException (org.mycore.common.MCRException)30 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)30 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)29 MCRPath (org.mycore.datamodel.niofs.MCRPath)25 MCRAccessException (org.mycore.access.MCRAccessException)22 Document (org.jdom2.Document)20 MCRPersistenceException (org.mycore.common.MCRPersistenceException)18 MCRMetaLinkID (org.mycore.datamodel.metadata.MCRMetaLinkID)16 JDOMException (org.jdom2.JDOMException)15 MCRBase (org.mycore.datamodel.metadata.MCRBase)15 SAXException (org.xml.sax.SAXException)15 Date (java.util.Date)14 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)13 MCRSession (org.mycore.common.MCRSession)11 MCRContent (org.mycore.common.content.MCRContent)11 MCRPersistentIdentifierException (org.mycore.pi.exceptions.MCRPersistentIdentifierException)11 URISyntaxException (java.net.URISyntaxException)10