use of org.folio.holdingsiq.model.PackageId in project mod-kb-ebsco-java by folio-org.
the class EholdingsTitlesImpl method postEholdingsTitles.
@Override
@HandleValidationErrors
public void postEholdingsTitles(String contentType, TitlePostRequest entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
titlesPostBodyValidator.validate(entity);
TitlePost titlePost = titlePostRequestConverter.convert(entity);
PackageId packageId = parsePackageId(entity.getIncluded().get(0).getAttributes().getPackageId());
templateFactory.createTemplate(okapiHeaders, asyncResultHandler).requestAction(context -> context.getTitlesService().postTitle(titlePost, packageId).thenCompose(title -> completedFuture(toTitleResult(title, false))).thenCompose(titleResult -> updateTags(titleResult, context, entity.getData().getAttributes().getTags()))).executeWithResult(Title.class);
}
use of org.folio.holdingsiq.model.PackageId 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.holdingsiq.model.PackageId 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);
}
use of org.folio.holdingsiq.model.PackageId in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesImpl method deleteTags.
private CompletableFuture<Void> deleteTags(PackageId packageId, RMAPITemplateContext context) {
UUID credentialsId = toUUID(context.getCredentialsId());
String tenant = context.getOkapiData().getTenant();
return packageRepository.delete(packageId, credentialsId, tenant).thenCompose(o -> tagRepository.deleteRecordTags(tenant, packageIdToString(packageId), RecordType.PACKAGE)).thenCompose(aBoolean -> completedFuture(null));
}
use of org.folio.holdingsiq.model.PackageId in project mod-kb-ebsco-java by folio-org.
the class ResourcesServiceImpl method retrieveResource.
public CompletableFuture<ResourceResult> retrieveResource(ResourceId resourceId, List<String> includes, boolean useCache) {
CompletableFuture<Title> titleFuture;
CompletableFuture<PackageByIdData> packageFuture;
CompletableFuture<VendorResult> vendorFuture;
if (useCache) {
titleFuture = retrieveResourceWithCache(resourceId, tenantId, configuration);
} else {
titleFuture = super.retrieveResource(resourceId);
}
if (includes.contains(INCLUDE_PROVIDER_VALUE)) {
vendorFuture = providerService.retrieveProvider(resourceId.getProviderIdPart(), "");
} else {
vendorFuture = completedFuture(new VendorResult(null, null));
}
if (includes.contains(INCLUDE_PACKAGE_VALUE)) {
PackageId id = PackageId.builder().providerIdPart(resourceId.getProviderIdPart()).packageIdPart(resourceId.getPackageIdPart()).build();
packageFuture = packagesService.retrievePackage(id);
} else {
packageFuture = completedFuture(null);
}
boolean includeTitle = includes.contains("title");
return CompletableFuture.allOf(titleFuture, vendorFuture, packageFuture).thenCompose(o -> completedFuture(new ResourceResult(titleFuture.join(), vendorFuture.join().getVendor(), packageFuture.join(), includeTitle)));
}
Aggregations