Search in sources :

Example 1 with Packages

use of org.folio.holdingsiq.model.Packages 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);
}
Also used : EholdingsProviders(org.folio.rest.jaxrs.resource.EholdingsProviders) RMAPITemplateFactory(org.folio.rest.util.template.RMAPITemplateFactory) Filter(org.folio.rest.model.filter.Filter) TagRepository(org.folio.repository.tag.TagRepository) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Autowired(org.springframework.beans.factory.annotation.Autowired) ProviderPutRequest(org.folio.rest.jaxrs.model.ProviderPutRequest) Context(io.vertx.core.Context) JSONAPI(org.folio.rest.util.RestConstants.JSONAPI) IdParser.parseProviderId(org.folio.rest.util.IdParser.parseProviderId) ProviderPutDataAttributes(org.folio.rest.jaxrs.model.ProviderPutDataAttributes) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors) Map(java.util.Map) OkapiData(org.folio.holdingsiq.model.OkapiData) DbProvider(org.folio.repository.providers.DbProvider) Collections.emptyList(java.util.Collections.emptyList) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) UUID(java.util.UUID) Future(io.vertx.core.Future) ProviderCollection(org.folio.rest.jaxrs.model.ProviderCollection) Objects(java.util.Objects) PackageCollection(org.folio.rest.jaxrs.model.PackageCollection) ProviderTagsItem(org.folio.rest.jaxrs.model.ProviderTagsItem) List(java.util.List) Response(javax.ws.rs.core.Response) ErrorUtil(org.folio.rest.util.ErrorUtil) IdParser.getPackageIds(org.folio.rest.util.IdParser.getPackageIds) RMAPITemplateContext(org.folio.rest.util.template.RMAPITemplateContext) UserKbCredentialsService(org.folio.service.kbcredentials.UserKbCredentialsService) RecordKey(org.folio.repository.RecordKey) FilteredEntitiesLoader(org.folio.service.loader.FilteredEntitiesLoader) RecordType(org.folio.repository.RecordType) PackageCollectionResult(org.folio.rmapi.result.PackageCollectionResult) Tags(org.folio.rest.jaxrs.model.Tags) CompletableFuture(java.util.concurrent.CompletableFuture) Provider(org.folio.rest.jaxrs.model.Provider) VendorPut(org.folio.holdingsiq.model.VendorPut) InputValidationException(org.folio.rest.exception.InputValidationException) SpringContextUtil(org.folio.spring.SpringContextUtil) Value(org.springframework.beans.factory.annotation.Value) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ProviderPutBodyValidator(org.folio.rest.validator.ProviderPutBodyValidator) RelatedEntitiesLoader(org.folio.service.loader.RelatedEntitiesLoader) AsyncResult(io.vertx.core.AsyncResult) RMAPITemplate(org.folio.rest.util.template.RMAPITemplate) VendorById(org.folio.holdingsiq.model.VendorById) Converter(org.springframework.core.convert.converter.Converter) ProviderTagsPutRequest(org.folio.rest.jaxrs.model.ProviderTagsPutRequest) ProviderTags(org.folio.rest.jaxrs.model.ProviderTags) ExceptionMappers.error422InputValidationMapper(org.folio.rest.util.ExceptionMappers.error422InputValidationMapper) Vertx(io.vertx.core.Vertx) ResourceNotFoundException(org.folio.holdingsiq.service.exception.ResourceNotFoundException) ErrorHandler(org.folio.rest.util.ErrorHandler) ProviderTagsPutBodyValidator(org.folio.rest.validator.ProviderTagsPutBodyValidator) VendorResult(org.folio.rmapi.result.VendorResult) Validate(org.folio.rest.annotations.Validate) ProviderTagsDataAttributes(org.folio.rest.jaxrs.model.ProviderTagsDataAttributes) PackageRepository(org.folio.repository.packages.PackageRepository) Packages(org.folio.holdingsiq.model.Packages) TAGS_TYPE(org.folio.rest.util.RestConstants.TAGS_TYPE) Handler(io.vertx.core.Handler) ProviderRepository(org.folio.repository.providers.ProviderRepository) Filter(org.folio.rest.model.filter.Filter) PackageCollectionResult(org.folio.rmapi.result.PackageCollectionResult) ResourceNotFoundException(org.folio.holdingsiq.service.exception.ResourceNotFoundException) RMAPITemplate(org.folio.rest.util.template.RMAPITemplate) Validate(org.folio.rest.annotations.Validate) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors)

Example 2 with Packages

use of org.folio.holdingsiq.model.Packages 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 3 with Packages

use of org.folio.holdingsiq.model.Packages 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))));
}
Also used : RecordType(org.folio.repository.RecordType) AccessTypeFilter(org.folio.rest.model.filter.AccessTypeFilter) PackageCollectionResult(org.folio.rmapi.result.PackageCollectionResult) IdParser.resourceIdsToStrings(org.folio.rest.util.IdParser.resourceIdsToStrings) TagRepository(org.folio.repository.tag.TagRepository) ResourceCollectionResult(org.folio.rmapi.result.ResourceCollectionResult) Autowired(org.springframework.beans.factory.annotation.Autowired) TitlesRepository(org.folio.repository.titles.TitlesRepository) CompletableFuture(java.util.concurrent.CompletableFuture) IdParser.dbResourcesToIdStrings(org.folio.rest.util.IdParser.dbResourcesToIdStrings) AccessTypeMappingsService(org.folio.service.accesstypes.AccessTypeMappingsService) StringUtils(org.apache.commons.lang3.StringUtils) PackageServiceImpl(org.folio.rmapi.PackageServiceImpl) PackageId(org.folio.holdingsiq.model.PackageId) DbPackage(org.folio.repository.packages.DbPackage) AccessType(org.folio.rest.jaxrs.model.AccessType) Vendors(org.folio.holdingsiq.model.Vendors) IdParser.getTitleIds(org.folio.rest.util.IdParser.getTitleIds) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) RowSetUtils(org.folio.db.RowSetUtils) AccessTypeCollection(org.folio.rest.jaxrs.model.AccessTypeCollection) AccessTypeMapping(org.folio.repository.accesstypes.AccessTypeMapping) AccessTypesService(org.folio.service.accesstypes.AccessTypesService) IdParser.getResourceIds(org.folio.rest.util.IdParser.getResourceIds) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ResourceRepository(org.folio.repository.resources.ResourceRepository) ResourceId(org.folio.holdingsiq.model.ResourceId) Title(org.folio.holdingsiq.model.Title) ProvidersServiceImpl(org.folio.rmapi.ProvidersServiceImpl) TitlesServiceImpl(org.folio.rmapi.TitlesServiceImpl) IdParser(org.folio.rest.util.IdParser) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) DbResource(org.folio.repository.resources.DbResource) Titles(org.folio.holdingsiq.model.Titles) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) UUID(java.util.UUID) HoldingsService(org.folio.service.holdings.HoldingsService) TagFilter(org.folio.rest.model.filter.TagFilter) Collectors(java.util.stream.Collectors) PackageRepository(org.folio.repository.packages.PackageRepository) List(java.util.List) Component(org.springframework.stereotype.Component) Packages(org.folio.holdingsiq.model.Packages) IdParser.getPackageIds(org.folio.rest.util.IdParser.getPackageIds) RMAPITemplateContext(org.folio.rest.util.template.RMAPITemplateContext) ProviderRepository(org.folio.repository.providers.ProviderRepository) PackageServiceImpl(org.folio.rmapi.PackageServiceImpl) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) UUID(java.util.UUID)

Aggregations

Packages (org.folio.holdingsiq.model.Packages)3 Collections.emptyList (java.util.Collections.emptyList)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 RowSetUtils.toUUID (org.folio.db.RowSetUtils.toUUID)2 RecordType (org.folio.repository.RecordType)2 DbPackage (org.folio.repository.packages.DbPackage)2 PackageRepository (org.folio.repository.packages.PackageRepository)2 ProviderRepository (org.folio.repository.providers.ProviderRepository)2 TagRepository (org.folio.repository.tag.TagRepository)2 PackageCollection (org.folio.rest.jaxrs.model.PackageCollection)2 Tags (org.folio.rest.jaxrs.model.Tags)2 AsyncResult (io.vertx.core.AsyncResult)1 Context (io.vertx.core.Context)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 Vertx (io.vertx.core.Vertx)1 Collection (java.util.Collection)1