Search in sources :

Example 1 with DbResource

use of org.folio.repository.resources.DbResource in project mod-kb-ebsco-java by folio-org.

the class ResourceCollectionResultConverter method convert.

@Override
public ResourceCollection convert(@NonNull ResourceCollectionResult resourceCollectionResult) {
    final Titles titles = resourceCollectionResult.getTitles();
    final List<DbResource> resources = resourceCollectionResult.getTitlesList();
    final List<DbHoldingInfo> holdings = resourceCollectionResult.getHoldings();
    final List<ResourceCollectionItem> resourceCollectionItems = mapItems(titles.getTitleList(), title -> mapResourceCollectionItem(resources, resourceCollectionItemConverter.convert(title), createResourceId(title)));
    final List<ResourceCollectionItem> holdingCollectionItems = mapItems(holdings, dbHolding -> mapResourceCollectionItem(resources, holdingCollectionItemConverter.convert(dbHolding), createResourceId(dbHolding)));
    resourceCollectionItems.addAll(holdingCollectionItems);
    resourceCollectionItems.sort(Comparator.comparing(o -> o.getAttributes().getName()));
    return new ResourceCollection().withJsonapi(RestConstants.JSONAPI).withMeta(new MetaTotalResults().withTotalResults(titles.getTotalResults())).withData(resourceCollectionItems);
}
Also used : Converter(org.springframework.core.convert.converter.Converter) RestConstants(org.folio.rest.util.RestConstants) MetaTotalResults(org.folio.rest.jaxrs.model.MetaTotalResults) ResourceCollectionResult(org.folio.rmapi.result.ResourceCollectionResult) DbResource(org.folio.repository.resources.DbResource) Tags(org.folio.rest.jaxrs.model.Tags) Autowired(org.springframework.beans.factory.annotation.Autowired) Titles(org.folio.holdingsiq.model.Titles) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) List(java.util.List) Component(org.springframework.stereotype.Component) ListUtils.mapItems(org.folio.common.ListUtils.mapItems) ResourceCollection(org.folio.rest.jaxrs.model.ResourceCollection) NonNull(org.springframework.lang.NonNull) Comparator(java.util.Comparator) ResourceId(org.folio.holdingsiq.model.ResourceId) Title(org.folio.holdingsiq.model.Title) Collections(java.util.Collections) ResourceCollectionItem(org.folio.rest.jaxrs.model.ResourceCollectionItem) DbResource(org.folio.repository.resources.DbResource) MetaTotalResults(org.folio.rest.jaxrs.model.MetaTotalResults) ResourceCollectionItem(org.folio.rest.jaxrs.model.ResourceCollectionItem) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) Titles(org.folio.holdingsiq.model.Titles) ResourceCollection(org.folio.rest.jaxrs.model.ResourceCollection)

Aggregations

Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 ListUtils.mapItems (org.folio.common.ListUtils.mapItems)1 ResourceId (org.folio.holdingsiq.model.ResourceId)1 Title (org.folio.holdingsiq.model.Title)1 Titles (org.folio.holdingsiq.model.Titles)1 DbHoldingInfo (org.folio.repository.holdings.DbHoldingInfo)1 DbResource (org.folio.repository.resources.DbResource)1 MetaTotalResults (org.folio.rest.jaxrs.model.MetaTotalResults)1 ResourceCollection (org.folio.rest.jaxrs.model.ResourceCollection)1 ResourceCollectionItem (org.folio.rest.jaxrs.model.ResourceCollectionItem)1 Tags (org.folio.rest.jaxrs.model.Tags)1 RestConstants (org.folio.rest.util.RestConstants)1 ResourceCollectionResult (org.folio.rmapi.result.ResourceCollectionResult)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Converter (org.springframework.core.convert.converter.Converter)1 NonNull (org.springframework.lang.NonNull)1 Component (org.springframework.stereotype.Component)1