Search in sources :

Example 1 with CustomerResources

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);
}
Also used : RecordKey(org.folio.repository.RecordKey) CustomerResources(org.folio.holdingsiq.model.CustomerResources)

Example 2 with CustomerResources

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);
}
Also used : RMAPITemplateFactory(org.folio.rest.util.template.RMAPITemplateFactory) Filter(org.folio.rest.model.filter.Filter) TagRepository(org.folio.repository.tag.TagRepository) TitleCollectionResult(org.folio.rmapi.result.TitleCollectionResult) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Autowired(org.springframework.beans.factory.annotation.Autowired) Context(io.vertx.core.Context) PackageId(org.folio.holdingsiq.model.PackageId) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors) Map(java.util.Map) TitlesPostBodyValidator(org.folio.rest.validator.TitlesPostBodyValidator) TitlePutRequest(org.folio.rest.jaxrs.model.TitlePutRequest) EholdingsTitles(org.folio.rest.jaxrs.resource.EholdingsTitles) IdParser.parseTitleId(org.folio.rest.util.IdParser.parseTitleId) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Response(javax.ws.rs.core.Response) ErrorUtil(org.folio.rest.util.ErrorUtil) TitlePostRequest(org.folio.rest.jaxrs.model.TitlePostRequest) RMAPITemplateContext(org.folio.rest.util.template.RMAPITemplateContext) ListUtils(org.folio.common.ListUtils) RecordKey(org.folio.repository.RecordKey) FilteredEntitiesLoader(org.folio.service.loader.FilteredEntitiesLoader) RecordType(org.folio.repository.RecordType) IdParser.parsePackageId(org.folio.rest.util.IdParser.parsePackageId) IdParser.parseResourceId(org.folio.rest.util.IdParser.parseResourceId) Tags(org.folio.rest.jaxrs.model.Tags) TitlesRepository(org.folio.repository.titles.TitlesRepository) CompletableFuture(java.util.concurrent.CompletableFuture) BooleanUtils(org.apache.commons.lang3.BooleanUtils) DbTitle(org.folio.repository.titles.DbTitle) SpringContextUtil(org.folio.spring.SpringContextUtil) TitlePost(org.folio.holdingsiq.model.TitlePost) Title(org.folio.rest.jaxrs.model.Title) RelatedEntitiesLoader(org.folio.service.loader.RelatedEntitiesLoader) AsyncResult(io.vertx.core.AsyncResult) SearchProperties(org.folio.properties.common.SearchProperties) Converter(org.springframework.core.convert.converter.Converter) TitleCommonRequestAttributesValidator(org.folio.rest.validator.TitleCommonRequestAttributesValidator) IdParser(org.folio.rest.util.IdParser) Vertx(io.vertx.core.Vertx) ResourceNotFoundException(org.folio.holdingsiq.service.exception.ResourceNotFoundException) Titles(org.folio.holdingsiq.model.Titles) Validate(org.folio.rest.annotations.Validate) CustomerResources(org.folio.holdingsiq.model.CustomerResources) TitlePutRequestConverter(org.folio.rest.converter.titles.TitlePutRequestConverter) TitleResult(org.folio.rmapi.result.TitleResult) TitleCollection(org.folio.rest.jaxrs.model.TitleCollection) ResourcePut(org.folio.holdingsiq.model.ResourcePut) Handler(io.vertx.core.Handler) CustomerResources(org.folio.holdingsiq.model.CustomerResources) ResourcePut(org.folio.holdingsiq.model.ResourcePut) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors)

Example 3 with CustomerResources

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;
    });
}
Also used : Resource(org.folio.rest.jaxrs.model.Resource) ResourceCollectionItem(org.folio.rest.jaxrs.model.ResourceCollectionItem) Resource(org.folio.rest.jaxrs.model.Resource) PackageByIdData(org.folio.holdingsiq.model.PackageByIdData) VendorById(org.folio.holdingsiq.model.VendorById) CustomerResources(org.folio.holdingsiq.model.CustomerResources) AccessType(org.folio.rest.jaxrs.model.AccessType)

Example 4 with CustomerResources

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());
}
Also used : ResourcePutDataAttributes(org.folio.rest.jaxrs.model.ResourcePutDataAttributes) CustomerResources(org.folio.holdingsiq.model.CustomerResources) Title(org.folio.holdingsiq.model.Title) ResourcePut(org.folio.holdingsiq.model.ResourcePut) Test(org.junit.Test)

Aggregations

CustomerResources (org.folio.holdingsiq.model.CustomerResources)4 ResourcePut (org.folio.holdingsiq.model.ResourcePut)2 RecordKey (org.folio.repository.RecordKey)2 AsyncResult (io.vertx.core.AsyncResult)1 Context (io.vertx.core.Context)1 Handler (io.vertx.core.Handler)1 Vertx (io.vertx.core.Vertx)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 Collectors (java.util.stream.Collectors)1 Response (javax.ws.rs.core.Response)1 BooleanUtils (org.apache.commons.lang3.BooleanUtils)1 ListUtils (org.folio.common.ListUtils)1 RowSetUtils.toUUID (org.folio.db.RowSetUtils.toUUID)1 PackageByIdData (org.folio.holdingsiq.model.PackageByIdData)1 PackageId (org.folio.holdingsiq.model.PackageId)1