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;
}
Aggregations