use of org.folio.rmapi.result.PackageResult 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.rmapi.result.PackageResult in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesImpl method getEholdingsPackagesByPackageId.
@Override
@HandleValidationErrors
public void getEholdingsPackagesByPackageId(String packageId, String include, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
PackageId parsedPackageId = parsePackageId(packageId);
List<String> includedObjects = parseByComma(include);
templateFactory.createTemplate(okapiHeaders, asyncResultHandler).requestAction((context -> context.getPackagesService().retrievePackage(parsedPackageId, includedObjects).thenCompose(packageResult -> {
RecordKey recordKey = RecordKey.builder().recordId(packageIdToString(parsedPackageId)).recordType(RecordType.PACKAGE).build();
return CompletableFuture.allOf(relatedEntitiesLoader.loadAccessType(packageResult, recordKey, context), relatedEntitiesLoader.loadTags(packageResult, recordKey, context)).thenApply(aVoid -> packageResult);
}))).executeWithResult(Package.class);
}
use of org.folio.rmapi.result.PackageResult in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesImpl method postEholdingsPackages.
@Override
@HandleValidationErrors
public void postEholdingsPackages(String contentType, PackagePostRequest entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
packagesPostBodyValidator.validate(entity);
RMAPITemplate template = templateFactory.createTemplate(okapiHeaders, asyncResultHandler);
PackagePost packagePost = packagePostRequestConverter.convert(entity);
String accessTypeId = entity.getData().getAttributes().getAccessTypeId();
if (accessTypeId == null) {
template.requestAction(context -> postCustomPackage(packagePost, context));
} else {
template.requestAction(context -> accessTypesService.findByCredentialsAndAccessTypeId(context.getCredentialsId(), accessTypeId, okapiHeaders).thenCompose(accessType -> postCustomPackage(packagePost, context).thenCompose(packageResult -> updateAccessTypeMapping(accessType, packageResult, context))));
}
template.addErrorMapper(NotFoundException.class, error400NotFoundMapper()).executeWithResult(Package.class);
}
use of org.folio.rmapi.result.PackageResult in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesImpl method putEholdingsPackagesByPackageId.
@Override
@HandleValidationErrors
public void putEholdingsPackagesByPackageId(String packageId, String contentType, PackagePutRequest entity, 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(packageByIdData -> fetchAccessType(entity, context).thenCompose(accessType -> processUpdateRequest(entity, packageByIdData, context).thenCompose(voidEntity -> {
CompletableFuture<PackageByIdData> future = context.getPackagesService().retrievePackage(parsedPackageId);
return handleDeletedPackage(future, parsedPackageId, context);
}).thenApply(packageById -> new PackageResult(packageById, null, null)).thenCompose(packageResult -> updateAccessTypeMapping(accessType, packageResult, context))))).addErrorMapper(NotFoundException.class, error400NotFoundMapper()).addErrorMapper(InputValidationException.class, error422InputValidationMapper()).executeWithResult(Package.class);
}
Aggregations