use of org.folio.holdingsiq.model.CustomerResources in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImpl method loadRelatedEntities.
private CompletableFuture<ResourceResult> loadRelatedEntities(ResourceResult result, RMAPITemplateContext context) {
CustomerResources resource = result.getTitle().getCustomerResourcesList().get(0);
RecordKey recordKey = RecordKey.builder().recordId(getResourceId(resource)).recordType(RecordType.RESOURCE).build();
return CompletableFuture.allOf(relatedEntitiesLoader.loadAccessType(result, recordKey, context), relatedEntitiesLoader.loadTags(result, recordKey, context)).thenApply(aVoid -> result);
}
use of org.folio.holdingsiq.model.CustomerResources in project mod-kb-ebsco-java by folio-org.
the class EholdingsTitlesImpl method putEholdingsTitlesByTitleId.
@Override
@HandleValidationErrors
public void putEholdingsTitlesByTitleId(String titleId, String contentType, TitlePutRequest entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
titleCommonRequestAttributesValidator.validate(entity.getData().getAttributes());
Long parsedTitleId = parseTitleId(titleId);
templateFactory.createTemplate(okapiHeaders, asyncResultHandler).requestAction(context -> context.getTitlesService().retrieveTitle(parsedTitleId).thenCompose(title -> {
if (BooleanUtils.isNotTrue(title.getIsTitleCustom())) {
return completedFuture(null);
}
CustomerResources resource = title.getCustomerResourcesList().get(0);
ResourcePut resourcePutRequest = titlePutRequestConverter.convertToRMAPICustomResourcePutRequest(entity, resource);
String resourceId = resource.getVendorId() + "-" + resource.getPackageId() + "-" + resource.getTitleId();
return context.getResourcesService().updateResource(parseResourceId(resourceId), resourcePutRequest);
}).thenCompose(o -> context.getTitlesService().retrieveTitle(parsedTitleId)).thenCompose(title -> updateTags(toTitleResult(title, false), context, entity.getData().getAttributes().getTags()))).executeWithResult(Title.class);
}
use of org.folio.holdingsiq.model.CustomerResources in project mod-kb-ebsco-java by folio-org.
the class ResourceResultConverter method convert.
@Override
public List<Resource> convert(@NonNull ResourceResult resourceResult) {
org.folio.holdingsiq.model.Title rmapiTitle = resourceResult.getTitle();
PackageByIdData packageData = resourceResult.getPackageData();
VendorById vendor = resourceResult.getVendor();
AccessType accessType = resourceResult.getAccessType();
boolean includeTitle = resourceResult.isIncludeTitle();
List<CustomerResources> customerResourcesList = rmapiTitle.getCustomerResourcesList();
boolean titleHasSelectedResources = matchesAny(customerResourcesList, CustomerResources::getIsSelected);
return mapItems(customerResourcesList, resource -> {
Resource resultResource = new org.folio.rest.jaxrs.model.Resource().withData(new ResourceCollectionItem().withId(resource.getVendorId() + "-" + resource.getPackageId() + "-" + resource.getTitleId()).withType(ResourceCollectionItem.Type.RESOURCES).withAttributes(commonResourceConverter.createResourceDataAttributes(rmapiTitle, resource)).withRelationships(createEmptyRelationship())).withIncluded(null).withJsonapi(RestConstants.JSONAPI);
resultResource.getData().getAttributes().setTitleHasSelectedResources(titleHasSelectedResources);
resultResource.setIncluded(new ArrayList<>());
if (includeTitle) {
includeTitle(rmapiTitle, resultResource);
}
if (vendor != null) {
includeVendor(vendor, resultResource);
}
if (packageData != null) {
includePackage(packageData, resultResource);
}
if (accessType != null) {
includeAccessType(accessType, resultResource);
}
return resultResource;
});
}
use of org.folio.holdingsiq.model.CustomerResources in project mod-kb-ebsco-java by folio-org.
the class ResourceRequestConverterTest method shouldCreateRequestToUpdateUrlForCustomResource.
@Test
public void shouldCreateRequestToUpdateUrlForCustomResource() {
CustomerResources.CustomerResourcesBuilder customerResourcesBuilder = resourceData.getCustomerResourcesList().get(0).toBuilder();
CustomerResources resources = customerResourcesBuilder.isPackageCustom(true).build();
Title title = resourceData.toBuilder().customerResourcesList(Collections.singletonList(resources)).build();
ResourcePut resourcePut = resourcesConverter.convertToRMAPICustomResourcePutRequest(ResourcesTestData.getResourcePutRequest(new ResourcePutDataAttributes().withIsSelected(true).withUrl("test url")), title);
assertEquals("test url", resourcePut.getUrl());
}
Aggregations