Search in sources :

Example 1 with ResourcePut

use of org.folio.holdingsiq.model.ResourcePut 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 2 with ResourcePut

use of org.folio.holdingsiq.model.ResourcePut in project mod-kb-ebsco-java by folio-org.

the class ResourceRequestConverter method convertToRMAPICustomResourcePutRequest.

public ResourcePut convertToRMAPICustomResourcePutRequest(ResourcePutRequest entity, Title oldTitle) {
    ResourcePutDataAttributes attributes = entity.getData().getAttributes();
    // Map common attributes for custom/managed resources to RM API fields
    ResourcePut.ResourcePutBuilder builder = convertCommonAttributesToResourcePutRequest(attributes, oldTitle);
    // Map attributes specific to custom resources to RM API fields
    builder.titleName(oldTitle.getTitleName());
    builder.publisherName(oldTitle.getPublisherName());
    builder.edition(oldTitle.getEdition());
    builder.description(oldTitle.getDescription());
    builder.identifiersList(oldTitle.getIdentifiersList());
    builder.contributorsList(oldTitle.getContributorsList());
    return builder.build();
}
Also used : ResourcePutDataAttributes(org.folio.rest.jaxrs.model.ResourcePutDataAttributes) ResourcePut(org.folio.holdingsiq.model.ResourcePut)

Example 3 with ResourcePut

use of org.folio.holdingsiq.model.ResourcePut in project mod-kb-ebsco-java by folio-org.

the class TitlePutRequestConverter method convertToRMAPICustomResourcePutRequest.

public ResourcePut convertToRMAPICustomResourcePutRequest(TitlePutRequest entity, CustomerResources oldResource) {
    TitleCommonRequestAttributes attributes = entity.getData().getAttributes();
    ResourcePut.ResourcePutBuilder builder = ResourcePut.builder();
    Proxy proxy = null;
    if (oldResource.getProxy() != null && oldResource.getProxy().getId() != null) {
        proxy = Proxy.builder().inherited(false).id(oldResource.getProxy().getId()).build();
    }
    builder.proxy(proxy);
    builder.isHidden(oldResource.getVisibilityData().getIsHidden());
    builder.coverageStatement(oldResource.getCoverageStatement());
    builder.customEmbargoPeriod(oldResource.getCustomEmbargoPeriod());
    builder.customCoverageList(oldResource.getCustomCoverageList());
    builder.url(oldResource.getUrl());
    builder.isSelected(true);
    if (attributes.getPublicationType() != null) {
        builder.pubType(ConverterConsts.publicationTypes.inverseBidiMap().get(attributes.getPublicationType()));
    }
    builder.isPeerReviewed(attributes.getIsPeerReviewed());
    builder.titleName(attributes.getName());
    builder.publisherName(attributes.getPublisherName());
    builder.edition(attributes.getEdition());
    builder.description(attributes.getDescription());
    builder.identifiersList(toIdentifiersConverter.convert(attributes.getIdentifiers()));
    builder.contributorsList(toContributorsConverter.convert(attributes.getContributors()));
    builder.userDefinedFields(UserDefinedFields.builder().userDefinedField1(oldResource.getUserDefinedFields().getUserDefinedField1()).userDefinedField2(oldResource.getUserDefinedFields().getUserDefinedField2()).userDefinedField3(oldResource.getUserDefinedFields().getUserDefinedField3()).userDefinedField4(oldResource.getUserDefinedFields().getUserDefinedField4()).userDefinedField5(oldResource.getUserDefinedFields().getUserDefinedField5()).build());
    return builder.build();
}
Also used : Proxy(org.folio.holdingsiq.model.Proxy) TitleCommonRequestAttributes(org.folio.rest.model.TitleCommonRequestAttributes) ResourcePut(org.folio.holdingsiq.model.ResourcePut)

Example 4 with ResourcePut

use of org.folio.holdingsiq.model.ResourcePut in project mod-kb-ebsco-java by folio-org.

the class TitlePutRequestConverterTest method shouldCreateRequestToUpdatePublisherNameForCustomResource.

@Test
public void shouldCreateRequestToUpdatePublisherNameForCustomResource() {
    TitlePutRequest request = createEmptyTitlePutRequest();
    request.getData().getAttributes().setPublisherName("test pub name");
    ResourcePut resourcePut = converter.convertToRMAPICustomResourcePutRequest(request, ResourcesTestData.createResourceData().getTitle().getCustomerResourcesList().get(0));
    assertEquals("test pub name", resourcePut.getPublisherName());
}
Also used : TitlePutRequest(org.folio.rest.jaxrs.model.TitlePutRequest) ResourcePut(org.folio.holdingsiq.model.ResourcePut) Test(org.junit.Test)

Example 5 with ResourcePut

use of org.folio.holdingsiq.model.ResourcePut in project mod-kb-ebsco-java by folio-org.

the class TitlePutRequestConverterTest method shouldCreateRequestToUpdateResourceNameForCustomResource.

@Test
public void shouldCreateRequestToUpdateResourceNameForCustomResource() {
    TitlePutRequest request = createEmptyTitlePutRequest();
    request.getData().getAttributes().setName("test name");
    ResourcePut resourcePut = converter.convertToRMAPICustomResourcePutRequest(request, ResourcesTestData.createResourceData().getTitle().getCustomerResourcesList().get(0));
    assertEquals("test name", resourcePut.getTitleName());
}
Also used : TitlePutRequest(org.folio.rest.jaxrs.model.TitlePutRequest) ResourcePut(org.folio.holdingsiq.model.ResourcePut) Test(org.junit.Test)

Aggregations

ResourcePut (org.folio.holdingsiq.model.ResourcePut)22 Test (org.junit.Test)19 ResourcePutDataAttributes (org.folio.rest.jaxrs.model.ResourcePutDataAttributes)14 TitlePutRequest (org.folio.rest.jaxrs.model.TitlePutRequest)7 CustomerResources (org.folio.holdingsiq.model.CustomerResources)2 EmbargoPeriod (org.folio.rest.jaxrs.model.EmbargoPeriod)2 Proxy (org.folio.rest.jaxrs.model.Proxy)2 VisibilityData (org.folio.rest.jaxrs.model.VisibilityData)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