use of org.folio.rmapi.result.PackageCollectionResult in project mod-kb-ebsco-java by folio-org.
the class EholdingsProvidersImpl method getEholdingsProvidersPackagesByProviderId.
@Override
@Validate
@HandleValidationErrors
public void getEholdingsProvidersPackagesByProviderId(String providerId, String q, List<String> filterTags, List<String> filterAccessType, String filterSelected, String filterType, String sort, int page, int count, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
RMAPITemplate template = templateFactory.createTemplate(okapiHeaders, asyncResultHandler);
Filter filter = Filter.builder().recordType(RecordType.PACKAGE).query(q).filterTags(filterTags).providerId(providerId).filterAccessType(filterAccessType).filterSelected(filterSelected).filterType(filterType).sort(sort).page(page).count(count).build();
if (filter.isTagsFilter()) {
template.requestAction(context -> filteredEntitiesLoader.fetchPackagesByTagFilter(filter.createTagFilter(), context));
} else if (filter.isAccessTypeFilter()) {
template.requestAction(context -> filteredEntitiesLoader.fetchPackagesByAccessTypeFilter(filter.createAccessTypeFilter(), context).thenApply(packages -> new PackageCollectionResult(packages, emptyList())));
} else {
template.requestAction(context -> context.getPackagesService().retrievePackages(filter.getFilterSelected(), filterType, packagesSearchType, filter.getProviderId(), q, page, count, filter.getSort()).thenCompose(packages -> loadTags(packages, context)));
}
template.addErrorMapper(ResourceNotFoundException.class, exception -> GetEholdingsProvidersPackagesByProviderIdResponse.respond404WithApplicationVndApiJson(ErrorUtil.createError(GET_PROVIDER_NOT_FOUND_MESSAGE))).executeWithResult(PackageCollection.class);
}
use of org.folio.rmapi.result.PackageCollectionResult in project mod-kb-ebsco-java by folio-org.
the class EholdingsProvidersImpl method loadTags.
private CompletableFuture<PackageCollectionResult> loadTags(Packages packages, RMAPITemplateContext context) {
UUID credentialsId = toUUID(context.getCredentialsId());
String tenant = context.getOkapiData().getTenant();
return packageRepository.findByIds(getPackageIds(packages), credentialsId, tenant).thenApply(dbPackages -> new PackageCollectionResult(packages, dbPackages));
}
use of org.folio.rmapi.result.PackageCollectionResult in project mod-kb-ebsco-java by folio-org.
the class FilteredEntitiesLoaderImpl method fetchPackagesByTagFilter.
@Override
public CompletableFuture<PackageCollectionResult> fetchPackagesByTagFilter(TagFilter tagFilter, RMAPITemplateContext context) {
String tenant = context.getOkapiData().getTenant();
UUID credentialsId = toUUID(context.getCredentialsId());
PackageServiceImpl packagesService = context.getPackagesService();
return tagRepository.countRecordsByTagFilter(tagFilter, tenant).thenCompose(packageCount -> packageRepository.findByTagFilter(tagFilter, credentialsId, tenant).thenCompose(dbPackages -> packagesService.retrievePackages(getPackageIds(dbPackages)).thenApply(packages -> toPackageCollectionResult(packages, dbPackages, packageCount))));
}
Aggregations