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()));
}
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());
}
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();
}
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);
}
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());
}
Aggregations