use of org.folio.rest.aspect.HandleValidationErrors in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesImpl method getEholdingsPackagesResourcesByPackageId.
@Override
@Validate
@HandleValidationErrors
public void getEholdingsPackagesResourcesByPackageId(String packageId, List<String> filterTags, List<String> filterAccessType, String filterSelected, String filterType, String filterName, String filterIsxn, String filterSubject, String filterPublisher, String sort, int page, int count, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
Filter filter = Filter.builder().recordType(RecordType.RESOURCE).filterTags(filterTags).packageId(packageId).filterAccessType(filterAccessType).filterSelected(filterSelected).filterType(filterType).filterName(filterName).filterIsxn(filterIsxn).filterSubject(filterSubject).filterPublisher(filterPublisher).sort(sort).page(page).count(count).build();
RMAPITemplate template = templateFactory.createTemplate(okapiHeaders, asyncResultHandler);
if (filter.isTagsFilter()) {
template.requestAction(context -> filteredEntitiesLoader.fetchResourcesByTagFilter(filter.createTagFilter(), context));
} else if (filter.isAccessTypeFilter()) {
template.requestAction(context -> filteredEntitiesLoader.fetchResourcesByAccessTypeFilter(filter.createAccessTypeFilter(), context));
} else {
template.requestAction(context -> {
PackageId pkgId = filter.getPackageId();
long providerIdPart = pkgId.getProviderIdPart();
long packageIdPart = pkgId.getPackageIdPart();
return context.getTitlesService().retrieveTitles(providerIdPart, packageIdPart, filter.createFilterQuery(), searchProperties.getTitlesSearchType(), filter.getSort(), page, count).thenApply(titles -> titleCollectionConverter.convert(titles)).thenCompose(loadResourceTags(context));
});
}
template.addErrorMapper(ResourceNotFoundException.class, exception -> GetEholdingsPackagesResourcesByPackageIdResponse.respond404WithApplicationVndApiJson(ErrorUtil.createError(PACKAGE_NOT_FOUND_MESSAGE))).executeWithResult(ResourceCollection.class);
}
use of org.folio.rest.aspect.HandleValidationErrors in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesImpl method deleteEholdingsPackagesByPackageId.
@Override
@HandleValidationErrors
public void deleteEholdingsPackagesByPackageId(String packageId, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
PackageId parsedPackageId = parsePackageId(packageId);
templateFactory.createTemplate(okapiHeaders, asyncResultHandler).requestAction(context -> context.getPackagesService().retrievePackage(parsedPackageId).thenCompose(packageData -> {
if (BooleanUtils.isNotTrue(packageData.getIsCustom())) {
throw new InputValidationException(INVALID_PACKAGE_TITLE, INVALID_PACKAGE_DETAILS);
}
return context.getPackagesService().deletePackage(parsedPackageId).thenCompose(aVoid -> deleteAssignedResources(parsedPackageId, context));
})).execute();
}
use of org.folio.rest.aspect.HandleValidationErrors 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.rest.aspect.HandleValidationErrors in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImpl method postEholdingsResources.
@Override
@HandleValidationErrors
public void postEholdingsResources(String contentType, ResourcePostRequest entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
postValidator.validate(entity);
ResourcePostDataAttributes attributes = entity.getData().getAttributes();
long titleId = parseTitleId(attributes.getTitleId());
PackageId packageId = parsePackageId(attributes.getPackageId());
templateFactory.createTemplate(okapiHeaders, asyncResultHandler).requestAction(context -> (CompletableFuture<?>) getObjectsForPostResource(titleId, packageId, context.getTitlesService(), context.getPackagesService()).thenCompose(result -> {
Title title = result.getTitle();
postValidator.validateRelatedObjects(result.getPackageData(), title, result.getTitles());
ResourceSelectedPayload postRequest = new ResourceSelectedPayload(true, title.getTitleName(), title.getPubType(), attributes.getUrl());
ResourceId resourceId = ResourceId.builder().providerIdPart(packageId.getProviderIdPart()).packageIdPart(packageId.getPackageIdPart()).titleIdPart(titleId).build();
return context.getResourcesService().postResource(postRequest, resourceId);
}).thenCompose(title -> CompletableFuture.completedFuture(new ResourceResult(title, null, null, false)))).addErrorMapper(InputValidationException.class, error422InputValidationMapper()).executeWithResult(Resource.class);
}
use of org.folio.rest.aspect.HandleValidationErrors in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImpl method getEholdingsResourcesByResourceId.
@Override
@HandleValidationErrors
public void getEholdingsResourcesByResourceId(String resourceId, String include, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
ResourceId parsedResourceId = parseResourceId(resourceId);
List<String> includedObjects = parseByComma(include);
templateFactory.createTemplate(okapiHeaders, asyncResultHandler).requestAction(context -> context.getResourcesService().retrieveResource(parsedResourceId, includedObjects).thenCompose(result -> loadRelatedEntities(result, context))).addErrorMapper(ResourceNotFoundException.class, error404ResourceNotFoundMapper()).executeWithResult(Resource.class);
}
Aggregations