Search in sources :

Example 6 with MCRSwordCollectionProvider

use of org.mycore.sword.application.MCRSwordCollectionProvider in project mycore by MyCoRe-Org.

the class MCRSwordContainerHandler method replaceMetadata.

/**
 * Replaces the metadata of an existing object.
 * @param object  The object with the metadata to replace
 * @param deposit the deposit with the new metadata
 * @return a new {@link DepositReceipt} with the new metadata
 */
public DepositReceipt replaceMetadata(MCRObject object, Deposit deposit) throws SwordError, SwordServerException {
    final MCRSwordCollectionProvider collection = MCRSword.getCollection(this.lifecycleConfiguration.getCollection());
    collection.getIngester().updateMetadata(object, deposit, true);
    return collection.getMetadataProvider().provideMetadata(object);
}
Also used : MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider)

Example 7 with MCRSwordCollectionProvider

use of org.mycore.sword.application.MCRSwordCollectionProvider in project mycore by MyCoRe-Org.

the class MCRSwordContainerHandler method addObject.

public DepositReceipt addObject(Deposit deposit) throws SwordError, SwordServerException {
    final MCRSwordCollectionProvider collection = MCRSword.getCollection(this.lifecycleConfiguration.getCollection());
    final MCRObjectID idOfIngested = collection.getIngester().ingestMetadata(deposit);
    final MCRObject createdObject = (MCRObject) MCRMetadataManager.retrieve(idOfIngested);
    return collection.getMetadataProvider().provideMetadata(createdObject);
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 8 with MCRSwordCollectionProvider

use of org.mycore.sword.application.MCRSwordCollectionProvider in project mycore by MyCoRe-Org.

the class MCRSwordContainerHandler method replaceMetadataAndResources.

public DepositReceipt replaceMetadataAndResources(MCRObject object, Deposit deposit) throws SwordError, SwordServerException {
    final MCRSwordCollectionProvider collection = MCRSword.getCollection(this.lifecycleConfiguration.getCollection());
    collection.getIngester().updateMetadataResources(object, deposit);
    return collection.getMetadataProvider().provideMetadata(object);
}
Also used : MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider)

Example 9 with MCRSwordCollectionProvider

use of org.mycore.sword.application.MCRSwordCollectionProvider in project mycore by MyCoRe-Org.

the class MCRSwordContainerHandler method addObjectWithDerivate.

public DepositReceipt addObjectWithDerivate(String objectIdString, Deposit deposit) throws SwordError, SwordServerException {
    final MCRSwordCollectionProvider collection = MCRSword.getCollection(this.lifecycleConfiguration.getCollection());
    final MCRObjectID idOfIngested = collection.getIngester().ingestMetadataResources(deposit);
    final MCRObject createdObject = (MCRObject) MCRMetadataManager.retrieve(idOfIngested);
    return collection.getMetadataProvider().provideMetadata(createdObject);
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 10 with MCRSwordCollectionProvider

use of org.mycore.sword.application.MCRSwordCollectionProvider in project mycore by MyCoRe-Org.

the class MCRSwordCollectionManager method listCollectionContents.

@Override
public Feed listCollectionContents(IRI collectionIRI, AuthCredentials authCredentials, SwordConfiguration config) throws SwordServerException, SwordAuthException, SwordError {
    String collection = MCRSwordUtil.ParseLinkUtil.CollectionIRI.getCollectionNameFromCollectionIRI(collectionIRI);
    String path = collectionIRI.getPath();
    LOGGER.info(MessageFormat.format("List Collection: {0}", collection));
    Feed feed = new Abdera().newFeed();
    if (MCRSword.getCollectionNames().contains(collection)) {
        MCRSwordCollectionProvider collectionProvider = MCRSword.getCollection(collection);
        collectionProvider.getAuthHandler().authentication(authCredentials);
        if (collectionProvider.isVisible()) {
            Integer paginationFromIRI = MCRSwordUtil.ParseLinkUtil.CollectionIRI.getPaginationFromCollectionIRI(collectionIRI);
            final int start = (paginationFromIRI - 1) * MCRSwordConstants.MAX_ENTRYS_PER_PAGE;
            collectionProvider.getIDSupplier().get(start, MCRSwordConstants.MAX_ENTRYS_PER_PAGE).stream().map(id -> {
                try {
                    return collectionProvider.getMetadataProvider().provideListMetadata(id);
                } catch (SwordError swordError) {
                    LOGGER.warn("Error while creating feed for [{}]! (Will be removed from List)", id);
                    return null;
                }
            }).filter(Objects::nonNull).forEach(feed::addEntry);
            MCRSwordUtil.BuildLinkUtil.addPaginationLinks(collectionIRI, collection, feed, collectionProvider);
        }
    } else {
        throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_NOT_FOUND, "The collection '" + collection + "' does not exist!");
    }
    return feed;
}
Also used : SwordError(org.swordapp.server.SwordError) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) Feed(org.apache.abdera.model.Feed) Abdera(org.apache.abdera.Abdera)

Aggregations

MCRSwordCollectionProvider (org.mycore.sword.application.MCRSwordCollectionProvider)15 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)7 IRI (org.apache.abdera.i18n.iri.IRI)6 MCRBase (org.mycore.datamodel.metadata.MCRBase)5 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 MCRObject (org.mycore.datamodel.metadata.MCRObject)2 SwordError (org.swordapp.server.SwordError)2 AbstractMap (java.util.AbstractMap)1 Collections (java.util.Collections)1 Hashtable (java.util.Hashtable)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Abdera (org.apache.abdera.Abdera)1 Feed (org.apache.abdera.model.Feed)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 MCRConfiguration (org.mycore.common.config.MCRConfiguration)1 MCRFrontendUtil (org.mycore.frontend.MCRFrontendUtil)1