use of org.folio.holdingsiq.model.PackageId 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.holdingsiq.model.PackageId 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.holdingsiq.model.PackageId 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.holdingsiq.model.PackageId in project mod-kb-ebsco-java by folio-org.
the class PackageServiceImpl method retrievePackagesBulk.
public CompletableFuture<PackageBulkResult> retrievePackagesBulk(Set<String> packageIds) {
Set<CompletableFuture<Result<PackageResult, String>>> futures = new HashSet<>();
packageIds.forEach(inputId -> {
try {
PackageId id = IdParser.parsePackageId(inputId);
futures.add(retrievePackageForBulk(id));
} catch (ValidationException e) {
futures.add(completedFuture(new Failure<>(inputId)));
}
});
return allOfSucceeded(futures, throwable -> LOG.warn(throwable.getMessage(), throwable)).thenApply(this::mapToPackageBulk);
}
use of org.folio.holdingsiq.model.PackageId in project mod-kb-ebsco-java by folio-org.
the class PackageServiceImplTest method shouldReturnCachedPackage.
@Test
public void shouldReturnCachedPackage() throws IOException, URISyntaxException {
RegexPattern getPackagePattern = new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/" + STUB_VENDOR_ID + "/packages/" + STUB_PACKAGE_ID);
Configuration configuration = Configuration.builder().url("http://127.0.0.1:" + userMockServer.port()).customerId(STUB_CUSTOMER_ID).apiKey("API KEY").build();
PackageServiceImpl service = new PackageServiceImpl(configuration, Vertx.vertx(), STUB_TENANT, null, null, new VertxCache<>(Vertx.vertx(), 60, "packageCache"), null);
mockGet(getPackagePattern, CUSTOM_PACKAGE_STUB_FILE);
PackageId packageId = PackageId.builder().packageIdPart(STUB_PACKAGE_ID).providerIdPart(STUB_VENDOR_ID).build();
service.retrievePackage(packageId, Collections.emptyList(), true).join();
service.retrievePackage(packageId, Collections.emptyList(), true).join();
verify(1, getRequestedFor(new UrlPattern(getPackagePattern, true)));
}
Aggregations