use of org.folio.rest.jaxrs.model.Resource in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImplTest method shouldDeselectManagedResourceOnPutWithSelectedFalse.
@Test
public void shouldDeselectManagedResourceOnPutWithSelectedFalse() throws IOException, URISyntaxException, JSONException {
String stubResponseFile = "responses/rmapi/resources/get-managed-resource-updated-response-is-selected-false.json";
String expectedResourceFile = "responses/kb-ebsco/resources/expected-managed-resource.json";
ResourcePutRequest request = readJsonFile("requests/kb-ebsco/resource/put-managed-resource-is-not-selected.json", ResourcePutRequest.class);
request.getData().getAttributes().setIsSelected(false);
String actualResponse = mockUpdateResourceScenario(stubResponseFile, MANAGED_RESOURCE_ENDPOINT, STUB_MANAGED_RESOURCE_ID, Json.encode(request));
Resource expectedResource = readJsonFile(expectedResourceFile, Resource.class);
expectedResource.getData().getAttributes().setIsSelected(false);
JSONAssert.assertEquals(Json.encode(expectedResource), actualResponse, false);
verify(1, putRequestedFor(new UrlPathPattern(new RegexPattern(MANAGED_RESOURCE_ENDPOINT), true)).withRequestBody(new EqualToJsonPattern(readFile("requests/rmapi/resources/put-managed-resource-is-not-selected.json"), true, true)));
}
use of org.folio.rest.jaxrs.model.Resource 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.rest.jaxrs.model.Resource in project mod-kb-ebsco-java by folio-org.
the class PackageResponseConverterTest method shouldReturnCustomCoverageInDescendingOrder.
@Test
public void shouldReturnCustomCoverageInDescendingOrder() throws URISyntaxException, IOException {
ObjectMapper mapper = new ObjectMapper();
Title title = mapper.readValue(getFile("responses/rmapi/titles/get-custom-title-with-coverage-dates-asc.json"), Title.class);
final ResourceResult resourceResult = new ResourceResult(title, null, null, false);
final Resource resource = conversionService.convert(resourceResult, Resource.class);
final List<Coverage> customCoverages = resource.getData().getAttributes().getCustomCoverages();
assertThat(customCoverages.size(), equalTo(2));
assertThat(customCoverages.get(0).getBeginCoverage(), equalTo("2004-03-01"));
assertThat(customCoverages.get(0).getEndCoverage(), equalTo("2004-03-04"));
assertThat(customCoverages.get(1).getBeginCoverage(), equalTo("2001-01-01"));
assertThat(customCoverages.get(1).getEndCoverage(), equalTo("2004-02-01"));
}
use of org.folio.rest.jaxrs.model.Resource in project mod-kb-ebsco-java by folio-org.
the class ResourceConverter method convert.
@Override
public Resource convert(@NonNull ResourceResult resourceResult) {
Resource resource = requireNonNull(resultListConverter.convert(resourceResult)).get(0);
resource.getData().getAttributes().setTags(resourceResult.getTags());
return resource;
}
use of org.folio.rest.jaxrs.model.Resource in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImplTest method shouldReturnResourceWithTags.
@Test
public void shouldReturnResourceWithTags() throws IOException, URISyntaxException {
saveTag(vertx, STUB_MANAGED_RESOURCE_ID, RecordType.RESOURCE, STUB_TAG_VALUE);
String stubResponseFile = "responses/rmapi/resources/get-resource-by-id-success-response.json";
mockResource(stubResponseFile);
Resource resource = getWithOk(STUB_MANAGED_RESOURCE_PATH, STUB_TOKEN_HEADER).as(Resource.class);
assertTrue(resource.getData().getAttributes().getTags().getTagList().contains(STUB_TAG_VALUE));
}
Aggregations