Search in sources :

Example 21 with SwordError

use of org.swordapp.server.SwordError 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

SwordError (org.swordapp.server.SwordError)21 Dataset (edu.harvard.iq.dataverse.Dataset)10 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)10 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)10 Dataverse (edu.harvard.iq.dataverse.Dataverse)9 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)6 DepositReceipt (org.swordapp.server.DepositReceipt)5 UpdateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)4 IOException (java.io.IOException)4 List (java.util.List)4 EJBException (javax.ejb.EJBException)4 MCRPath (org.mycore.datamodel.niofs.MCRPath)4 SwordServerException (org.swordapp.server.SwordServerException)4 DataFile (edu.harvard.iq.dataverse.DataFile)3 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)3 InputStream (java.io.InputStream)3 URISyntaxException (java.net.URISyntaxException)3 CommandExecutionException (edu.harvard.iq.dataverse.engine.command.exception.CommandExecutionException)2 GetDraftDatasetVersionCommand (edu.harvard.iq.dataverse.engine.command.impl.GetDraftDatasetVersionCommand)2 URI (java.net.URI)2