Search in sources :

Example 1 with Resource

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)));
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) ResourcePutRequest(org.folio.rest.jaxrs.model.ResourcePutRequest) DbResource(org.folio.repository.resources.DbResource) Resource(org.folio.rest.jaxrs.model.Resource) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 2 with Resource

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;
    });
}
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 3 with Resource

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"));
}
Also used : ResourceResult(org.folio.rmapi.result.ResourceResult) Resource(org.folio.rest.jaxrs.model.Resource) Title(org.folio.holdingsiq.model.Title) Coverage(org.folio.rest.jaxrs.model.Coverage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 4 with Resource

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;
}
Also used : Resource(org.folio.rest.jaxrs.model.Resource)

Example 5 with 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));
}
Also used : DbResource(org.folio.repository.resources.DbResource) Resource(org.folio.rest.jaxrs.model.Resource) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

Resource (org.folio.rest.jaxrs.model.Resource)5 Test (org.junit.Test)3 DbResource (org.folio.repository.resources.DbResource)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 EqualToJsonPattern (com.github.tomakehurst.wiremock.matching.EqualToJsonPattern)1 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)1 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)1 CustomerResources (org.folio.holdingsiq.model.CustomerResources)1 PackageByIdData (org.folio.holdingsiq.model.PackageByIdData)1 Title (org.folio.holdingsiq.model.Title)1 VendorById (org.folio.holdingsiq.model.VendorById)1 AccessType (org.folio.rest.jaxrs.model.AccessType)1 Coverage (org.folio.rest.jaxrs.model.Coverage)1 ResourceCollectionItem (org.folio.rest.jaxrs.model.ResourceCollectionItem)1 ResourcePutRequest (org.folio.rest.jaxrs.model.ResourcePutRequest)1 ResourceResult (org.folio.rmapi.result.ResourceResult)1