Search in sources :

Example 1 with TitlePutRequest

use of org.folio.rest.jaxrs.model.TitlePutRequest in project mod-kb-ebsco-java by folio-org.

the class EholdingsTitlesTest method shouldUpdateOnlyTagsOnPutForNonCustomTitle.

@Test
public void shouldUpdateOnlyTagsOnPutForNonCustomTitle() throws IOException, URISyntaxException {
    String resourceResponse = "responses/rmapi/resources/get-managed-resource-updated-response.json";
    ObjectMapper mapper = new ObjectMapper();
    TitlePutRequest request = mapper.readValue(readFile("requests/kb-ebsco/title/put-title.json"), TitlePutRequest.class);
    List<String> newTags = Arrays.asList(STUB_TAG_VALUE, STUB_TAG_VALUE_2);
    request.getData().getAttributes().setTags(new Tags().withTagList(newTags));
    stubFor(get(new UrlPathPattern(new RegexPattern(CUSTOM_TITLE_ENDPOINT), false)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(resourceResponse))));
    putWithOk(EHOLDINGS_TITLES_PATH + "/" + STUB_CUSTOM_TITLE_ID, mapper.writeValueAsString(request), STUB_TOKEN_HEADER);
    List<String> tags = TagsTestUtil.getTags(vertx);
    assertThat(tags, containsInAnyOrder(newTags.toArray()));
    WireMock.verify(0, putRequestedFor(anyUrl()));
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) TitlePutRequest(org.folio.rest.jaxrs.model.TitlePutRequest) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tags(org.folio.rest.jaxrs.model.Tags) Test(org.junit.Test)

Example 2 with TitlePutRequest

use of org.folio.rest.jaxrs.model.TitlePutRequest in project mod-kb-ebsco-java by folio-org.

the class EholdingsTitlesTest method shouldUpdateTitleDataOnSecondPut.

@Test
public void shouldUpdateTitleDataOnSecondPut() throws IOException, URISyntaxException {
    String newName = "new name";
    String updatedResponse = "responses/rmapi/resources/get-custom-resource-updated-title-name-response.json";
    putTitle(readFile(updatedResponse), Collections.singletonList(STUB_TAG_VALUE));
    ObjectMapper mapper = new ObjectMapper();
    TitlePutRequest request = mapper.readValue(readFile("requests/kb-ebsco/title/put-title.json"), TitlePutRequest.class);
    request.getData().getAttributes().withName(newName);
    stubFor(get(new UrlPathPattern(new RegexPattern(CUSTOM_TITLE_ENDPOINT), false)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(updatedResponse))));
    putWithOk(EHOLDINGS_TITLES_PATH + "/" + STUB_CUSTOM_TITLE_ID, mapper.writeValueAsString(request), STUB_TOKEN_HEADER);
    List<DbTitle> titles = TitlesTestUtil.getTitles(vertx);
    assertEquals(1, titles.size());
    assertEqualsLong(titles.get(0).getId());
    assertEquals(newName, titles.get(0).getName());
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) TitlePutRequest(org.folio.rest.jaxrs.model.TitlePutRequest) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) DbTitle(org.folio.repository.titles.DbTitle) Matchers.containsString(org.hamcrest.Matchers.containsString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with TitlePutRequest

use of org.folio.rest.jaxrs.model.TitlePutRequest in project mod-kb-ebsco-java by folio-org.

the class EholdingsTitlesTest method putTitle.

private String putTitle(String updatedResourceResponse, List<String> tags) throws IOException, URISyntaxException {
    stubFor(get(new UrlPathPattern(new RegexPattern(CUSTOM_TITLE_ENDPOINT), false)).willReturn(new ResponseDefinitionBuilder().withBody(updatedResourceResponse)));
    stubFor(put(new UrlPathPattern(new RegexPattern(CUSTOM_RESOURCE_ENDPOINT), true)).willReturn(new ResponseDefinitionBuilder().withStatus(SC_NO_CONTENT)));
    ObjectMapper mapper = new ObjectMapper();
    TitlePutRequest titleToBeUpdated = mapper.readValue(readFile("requests/kb-ebsco/title/put-title.json"), TitlePutRequest.class);
    if (tags != null) {
        titleToBeUpdated.getData().getAttributes().setTags(new Tags().withTagList(tags));
    }
    return putWithOk(EHOLDINGS_TITLES_PATH + "/" + STUB_CUSTOM_TITLE_ID, mapper.writeValueAsString(titleToBeUpdated), STUB_TOKEN_HEADER).asString();
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) TitlePutRequest(org.folio.rest.jaxrs.model.TitlePutRequest) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tags(org.folio.rest.jaxrs.model.Tags)

Example 4 with TitlePutRequest

use of org.folio.rest.jaxrs.model.TitlePutRequest 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 5 with TitlePutRequest

use of org.folio.rest.jaxrs.model.TitlePutRequest 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)

Aggregations

TitlePutRequest (org.folio.rest.jaxrs.model.TitlePutRequest)11 Test (org.junit.Test)8 ResourcePut (org.folio.holdingsiq.model.ResourcePut)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)3 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)3 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)3 Tags (org.folio.rest.jaxrs.model.Tags)3 DbTitle (org.folio.repository.titles.DbTitle)2 Matchers.containsString (org.hamcrest.Matchers.containsString)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