Search in sources :

Example 1 with MetaTotalResults

use of org.folio.rest.jaxrs.model.MetaTotalResults in project mod-kb-ebsco-java by folio-org.

the class PackageCollectionResultConverter method convert.

@Override
public PackageCollection convert(@NonNull PackageCollectionResult packagesResult) {
    Packages packages = packagesResult.getPackages();
    List<DbPackage> dbPackages = packagesResult.getDbPackages();
    List<PackageCollectionItem> packageList = mapItems(packages.getPackagesList(), packageData -> {
        PackageCollectionItem item = packageCollectionItemConverter.convert(packageData);
        item.getAttributes().withTags(new Tags().withTagList(getTagsById(dbPackages, createPackageId(packageData))));
        return item;
    });
    return new PackageCollection().withJsonapi(RestConstants.JSONAPI).withMeta(new MetaTotalResults().withTotalResults(packages.getTotalResults())).withData(packageList);
}
Also used : PackageCollectionItem(org.folio.rest.jaxrs.model.PackageCollectionItem) Packages(org.folio.holdingsiq.model.Packages) DbPackage(org.folio.repository.packages.DbPackage) MetaTotalResults(org.folio.rest.jaxrs.model.MetaTotalResults) PackageCollection(org.folio.rest.jaxrs.model.PackageCollection) Tags(org.folio.rest.jaxrs.model.Tags)

Example 2 with MetaTotalResults

use of org.folio.rest.jaxrs.model.MetaTotalResults 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)

Example 3 with MetaTotalResults

use of org.folio.rest.jaxrs.model.MetaTotalResults in project mod-kb-ebsco-java by folio-org.

the class EholdingsPackagesTest method shouldReturnFilteredResourcesWithNonEmptyCustomerResourceList.

@Test
public void shouldReturnFilteredResourcesWithNonEmptyCustomerResourceList() throws IOException, URISyntaxException {
    mockResourceById(RESOURCES_BY_PACKAGE_ID_EMPTY_CUSTOMER_RESOURCE_LIST_STUB_FILE);
    final ResourceCollection resourceCollection = getWithOk(PACKAGE_RESOURCES_PATH, STUB_TOKEN_HEADER).as(ResourceCollection.class);
    final MetaTotalResults metaTotalResults = resourceCollection.getMeta();
    assertThat(metaTotalResults.getTotalResults(), equalTo(3));
}
Also used : MetaTotalResults(org.folio.rest.jaxrs.model.MetaTotalResults) ResourceCollection(org.folio.rest.jaxrs.model.ResourceCollection) Test(org.junit.Test)

Aggregations

MetaTotalResults (org.folio.rest.jaxrs.model.MetaTotalResults)3 ResourceCollection (org.folio.rest.jaxrs.model.ResourceCollection)2 Tags (org.folio.rest.jaxrs.model.Tags)2 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 ListUtils.mapItems (org.folio.common.ListUtils.mapItems)1 Packages (org.folio.holdingsiq.model.Packages)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 DbPackage (org.folio.repository.packages.DbPackage)1 DbResource (org.folio.repository.resources.DbResource)1 PackageCollection (org.folio.rest.jaxrs.model.PackageCollection)1 PackageCollectionItem (org.folio.rest.jaxrs.model.PackageCollectionItem)1 ResourceCollectionItem (org.folio.rest.jaxrs.model.ResourceCollectionItem)1 RestConstants (org.folio.rest.util.RestConstants)1 ResourceCollectionResult (org.folio.rmapi.result.ResourceCollectionResult)1 Test (org.junit.Test)1