Search in sources :

Example 1 with AccessTypeMapping

use of org.folio.repository.accesstypes.AccessTypeMapping in project mod-kb-ebsco-java by folio-org.

the class EholdingsPackagesTest method shouldUpdateAllAttributesInCustomPackageAndCreateNewAccessTypeMapping.

@Test
public void shouldUpdateAllAttributesInCustomPackageAndCreateNewAccessTypeMapping() throws URISyntaxException, IOException {
    List<AccessType> accessTypes = insertAccessTypes(testData(configuration.getId()), vertx);
    String accessTypeId = accessTypes.get(0).getId();
    boolean updatedSelected = true;
    boolean updatedHidden = true;
    String updatedBeginCoverage = "2003-01-01";
    String updatedEndCoverage = "2004-01-01";
    String updatedPackageName = "name of the ages forever and ever";
    EqualToJsonPattern putBodyPattern = new EqualToJsonPattern(readFile("requests/rmapi/packages/put-package-custom.json"), true, true);
    PackageByIdData packageData = mapper.readValue(getFile(CUSTOM_PACKAGE_STUB_FILE), PackageByIdData.class);
    packageData = packageData.toByIdBuilder().isSelected(updatedSelected).visibilityData(packageData.getVisibilityData().toBuilder().isHidden(updatedHidden).build()).customCoverage(CoverageDates.builder().beginCoverage(updatedBeginCoverage).endCoverage(updatedEndCoverage).build()).packageName(updatedPackageName).contentType("streamingmedia").build();
    String updatedPackageValue = mapper.writeValueAsString(packageData);
    mockUpdateScenario(readFile(CUSTOM_PACKAGE_STUB_FILE), updatedPackageValue);
    String putBody = String.format(readFile("requests/kb-ebsco/package/put-package-custom-with-access-type.json"), accessTypeId);
    Package aPackage = putWithOk(PACKAGES_PATH, putBody, STUB_TOKEN_HEADER).as(Package.class);
    verify(putRequestedFor(PACKAGE_URL_PATTERN).withRequestBody(putBodyPattern));
    assertEquals(updatedSelected, aPackage.getData().getAttributes().getIsSelected());
    assertEquals(updatedHidden, aPackage.getData().getAttributes().getVisibilityData().getIsHidden());
    assertEquals(updatedBeginCoverage, aPackage.getData().getAttributes().getCustomCoverage().getBeginCoverage());
    assertEquals(updatedEndCoverage, aPackage.getData().getAttributes().getCustomCoverage().getEndCoverage());
    assertEquals(updatedPackageName, aPackage.getData().getAttributes().getName());
    assertEquals(ContentType.STREAMING_MEDIA, aPackage.getData().getAttributes().getContentType());
    List<AccessTypeMapping> accessTypeMappingsInDB = getAccessTypeMappings(vertx);
    assertEquals(1, accessTypeMappingsInDB.size());
    assertEquals(aPackage.getData().getId(), accessTypeMappingsInDB.get(0).getRecordId());
    assertEqualsUUID(accessTypeId, accessTypeMappingsInDB.get(0).getAccessTypeId());
    assertEquals(PACKAGE, accessTypeMappingsInDB.get(0).getRecordType());
    assertNotNull(aPackage.getIncluded());
    assertEquals(accessTypeId, aPackage.getData().getRelationships().getAccessType().getData().getId());
    assertEquals(accessTypeId, ((LinkedHashMap<?, ?>) aPackage.getIncluded().get(0)).get("id"));
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) Package(org.folio.rest.jaxrs.model.Package) PackagesTestUtil.buildDbPackage(org.folio.util.PackagesTestUtil.buildDbPackage) DbPackage(org.folio.repository.packages.DbPackage) PackagesTestUtil.savePackage(org.folio.util.PackagesTestUtil.savePackage) AccessTypesTestUtil.insertAccessTypeMapping(org.folio.util.AccessTypesTestUtil.insertAccessTypeMapping) AccessTypeMapping(org.folio.repository.accesstypes.AccessTypeMapping) AccessType(org.folio.rest.jaxrs.model.AccessType) AccessTypesTestUtil.insertAccessType(org.folio.util.AccessTypesTestUtil.insertAccessType) PackageByIdData(org.folio.holdingsiq.model.PackageByIdData) Test(org.junit.Test)

Example 2 with AccessTypeMapping

use of org.folio.repository.accesstypes.AccessTypeMapping in project mod-kb-ebsco-java by folio-org.

the class EholdingsResourcesImplTest method shouldCreateNewAccessTypeMappingOnSuccessfulPut.

@Test
public void shouldCreateNewAccessTypeMappingOnSuccessfulPut() throws IOException, URISyntaxException, JSONException {
    List<AccessType> accessTypes = insertAccessTypes(testData(configuration.getId()), vertx);
    String accessTypeId = accessTypes.get(0).getId();
    String stubResponseFile = "responses/rmapi/resources/get-managed-resource-updated-response.json";
    String expectedResourceFile = "responses/kb-ebsco/resources/expected-resource-by-id-with-access-type.json";
    String requestBody = format(readFile("requests/kb-ebsco/resource/put-resource-with-access-type.json"), accessTypeId);
    String actualResponse = mockUpdateResourceScenario(stubResponseFile, MANAGED_RESOURCE_ENDPOINT, STUB_MANAGED_RESOURCE_ID, requestBody);
    String expectedJson = format(readFile(expectedResourceFile), accessTypeId, accessTypeId);
    JSONAssert.assertEquals(expectedJson, actualResponse, false);
    verify(1, putRequestedFor(new UrlPathPattern(new RegexPattern(MANAGED_RESOURCE_ENDPOINT), true)).withRequestBody(equalToJson(readFile("requests/rmapi/resources/put-managed-resource-is-selected-multiple-attributes.json"))));
    List<AccessTypeMapping> accessTypeMappingsInDB = getAccessTypeMappings(vertx);
    assertEquals(1, accessTypeMappingsInDB.size());
    assertEquals(accessTypeId, accessTypeMappingsInDB.get(0).getAccessTypeId().toString());
    assertEquals(RESOURCE, accessTypeMappingsInDB.get(0).getRecordType());
}
Also used : UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) AccessTypeMapping(org.folio.repository.accesstypes.AccessTypeMapping) AccessTypesTestUtil.insertAccessTypeMapping(org.folio.util.AccessTypesTestUtil.insertAccessTypeMapping) AccessType(org.folio.rest.jaxrs.model.AccessType) Test(org.junit.Test)

Example 3 with AccessTypeMapping

use of org.folio.repository.accesstypes.AccessTypeMapping in project mod-kb-ebsco-java by folio-org.

the class FilteredEntitiesLoaderImpl method fetchAccessTypeMappings.

private CompletableFuture<Collection<AccessTypeMapping>> fetchAccessTypeMappings(AccessTypeFilter accessTypeFilter, RMAPITemplateContext context, AtomicInteger totalCount) {
    Map<String, String> okapiHeaders = context.getOkapiData().getHeaders();
    String credentialsId = context.getCredentialsId();
    RecordType recordType = accessTypeFilter.getRecordType();
    String recordIdPrefix = createRecordIdPrefix(accessTypeFilter);
    return accessTypesService.findByNames(accessTypeFilter.getAccessTypeNames(), credentialsId, okapiHeaders).thenApply(this::extractAccessTypeIds).thenCombine(accessTypeMappingsService.countByRecordPrefix(recordIdPrefix, recordType, credentialsId, okapiHeaders), (accessTypeIds, mappingCount) -> {
        accessTypeFilter.setAccessTypeIds(accessTypeIds);
        accessTypeFilter.setRecordIdPrefix(recordIdPrefix);
        accessTypeIds.forEach(id -> totalCount.getAndAdd(mappingCount.getOrDefault(id, 0)));
        return accessTypeFilter;
    }).thenCompose(filter -> accessTypeMappingsService.findByAccessTypeFilter(filter, okapiHeaders));
}
Also used : RecordType(org.folio.repository.RecordType) AccessTypeFilter(org.folio.rest.model.filter.AccessTypeFilter) PackageCollectionResult(org.folio.rmapi.result.PackageCollectionResult) IdParser.resourceIdsToStrings(org.folio.rest.util.IdParser.resourceIdsToStrings) TagRepository(org.folio.repository.tag.TagRepository) ResourceCollectionResult(org.folio.rmapi.result.ResourceCollectionResult) Autowired(org.springframework.beans.factory.annotation.Autowired) TitlesRepository(org.folio.repository.titles.TitlesRepository) CompletableFuture(java.util.concurrent.CompletableFuture) IdParser.dbResourcesToIdStrings(org.folio.rest.util.IdParser.dbResourcesToIdStrings) AccessTypeMappingsService(org.folio.service.accesstypes.AccessTypeMappingsService) StringUtils(org.apache.commons.lang3.StringUtils) PackageServiceImpl(org.folio.rmapi.PackageServiceImpl) PackageId(org.folio.holdingsiq.model.PackageId) DbPackage(org.folio.repository.packages.DbPackage) AccessType(org.folio.rest.jaxrs.model.AccessType) Vendors(org.folio.holdingsiq.model.Vendors) IdParser.getTitleIds(org.folio.rest.util.IdParser.getTitleIds) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) RowSetUtils(org.folio.db.RowSetUtils) AccessTypeCollection(org.folio.rest.jaxrs.model.AccessTypeCollection) AccessTypeMapping(org.folio.repository.accesstypes.AccessTypeMapping) AccessTypesService(org.folio.service.accesstypes.AccessTypesService) IdParser.getResourceIds(org.folio.rest.util.IdParser.getResourceIds) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ResourceRepository(org.folio.repository.resources.ResourceRepository) ResourceId(org.folio.holdingsiq.model.ResourceId) Title(org.folio.holdingsiq.model.Title) ProvidersServiceImpl(org.folio.rmapi.ProvidersServiceImpl) TitlesServiceImpl(org.folio.rmapi.TitlesServiceImpl) IdParser(org.folio.rest.util.IdParser) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) DbResource(org.folio.repository.resources.DbResource) Titles(org.folio.holdingsiq.model.Titles) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) UUID(java.util.UUID) HoldingsService(org.folio.service.holdings.HoldingsService) TagFilter(org.folio.rest.model.filter.TagFilter) Collectors(java.util.stream.Collectors) PackageRepository(org.folio.repository.packages.PackageRepository) List(java.util.List) Component(org.springframework.stereotype.Component) Packages(org.folio.holdingsiq.model.Packages) IdParser.getPackageIds(org.folio.rest.util.IdParser.getPackageIds) RMAPITemplateContext(org.folio.rest.util.template.RMAPITemplateContext) ProviderRepository(org.folio.repository.providers.ProviderRepository) RecordType(org.folio.repository.RecordType)

Example 4 with AccessTypeMapping

use of org.folio.repository.accesstypes.AccessTypeMapping in project mod-kb-ebsco-java by folio-org.

the class AccessTypeMappingsServiceImpl method update.

@Override
public CompletableFuture<Void> update(AccessType accessType, String recordId, RecordType recordType, String credentialsId, Map<String, String> okapiHeaders) {
    if (accessType == null) {
        return mappingRepository.deleteByRecord(recordId, recordType, toUUID(credentialsId), tenantId(okapiHeaders));
    }
    return mappingRepository.findByRecord(recordId, recordType, toUUID(credentialsId), tenantId(okapiHeaders)).thenCompose(dbMapping -> {
        UUID accessTypeId = UUID.fromString(accessType.getId());
        AccessTypeMapping mapping;
        if (dbMapping.isPresent()) {
            mapping = dbMapping.get().toBuilder().accessTypeId(accessTypeId).build();
        } else {
            mapping = createAccessTypeMapping(recordId, recordType, accessTypeId);
        }
        return mappingRepository.save(mapping, tenantId(okapiHeaders)).thenApply(nothing());
    });
}
Also used : AccessTypeMapping(org.folio.repository.accesstypes.AccessTypeMapping) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) UUID(java.util.UUID)

Example 5 with AccessTypeMapping

use of org.folio.repository.accesstypes.AccessTypeMapping in project mod-kb-ebsco-java by folio-org.

the class EholdingsPackagesTest method shouldUpdateAllAttributesInCustomPackageAndDeleteAccessTypeMapping.

@Test
public void shouldUpdateAllAttributesInCustomPackageAndDeleteAccessTypeMapping() throws URISyntaxException, IOException {
    List<AccessType> accessTypes = insertAccessTypes(testData(configuration.getId()), vertx);
    String accessTypeId = accessTypes.get(0).getId();
    insertAccessTypeMapping(FULL_PACKAGE_ID, PACKAGE, accessTypeId, vertx);
    boolean updatedSelected = true;
    boolean updatedHidden = true;
    String updatedBeginCoverage = "2003-01-01";
    String updatedEndCoverage = "2004-01-01";
    String updatedPackageName = "name of the ages forever and ever";
    EqualToJsonPattern putBodyPattern = new EqualToJsonPattern(readFile("requests/rmapi/packages/put-package-custom.json"), true, true);
    PackageByIdData packageData = mapper.readValue(getFile(CUSTOM_PACKAGE_STUB_FILE), PackageByIdData.class);
    packageData = packageData.toByIdBuilder().isSelected(updatedSelected).visibilityData(packageData.getVisibilityData().toBuilder().isHidden(updatedHidden).build()).customCoverage(CoverageDates.builder().beginCoverage(updatedBeginCoverage).endCoverage(updatedEndCoverage).build()).packageName(updatedPackageName).contentType("streamingmedia").build();
    String updatedPackageValue = mapper.writeValueAsString(packageData);
    mockUpdateScenario(readFile(CUSTOM_PACKAGE_STUB_FILE), updatedPackageValue);
    String putBody = readFile("requests/kb-ebsco/package/put-package-custom-multiple-attributes.json");
    Package aPackage = putWithOk(PACKAGES_PATH, putBody, STUB_TOKEN_HEADER).as(Package.class);
    verify(putRequestedFor(PACKAGE_URL_PATTERN).withRequestBody(putBodyPattern));
    assertEquals(updatedSelected, aPackage.getData().getAttributes().getIsSelected());
    assertEquals(updatedHidden, aPackage.getData().getAttributes().getVisibilityData().getIsHidden());
    assertEquals(updatedBeginCoverage, aPackage.getData().getAttributes().getCustomCoverage().getBeginCoverage());
    assertEquals(updatedEndCoverage, aPackage.getData().getAttributes().getCustomCoverage().getEndCoverage());
    assertEquals(updatedPackageName, aPackage.getData().getAttributes().getName());
    assertEquals(ContentType.STREAMING_MEDIA, aPackage.getData().getAttributes().getContentType());
    List<AccessTypeMapping> accessTypeMappingsInDB = getAccessTypeMappings(vertx);
    assertEquals(0, accessTypeMappingsInDB.size());
    assertNotNull(aPackage.getIncluded());
    assertEquals(0, aPackage.getIncluded().size());
    assertNull(aPackage.getData().getRelationships().getAccessType());
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) Package(org.folio.rest.jaxrs.model.Package) PackagesTestUtil.buildDbPackage(org.folio.util.PackagesTestUtil.buildDbPackage) DbPackage(org.folio.repository.packages.DbPackage) PackagesTestUtil.savePackage(org.folio.util.PackagesTestUtil.savePackage) AccessTypesTestUtil.insertAccessTypeMapping(org.folio.util.AccessTypesTestUtil.insertAccessTypeMapping) AccessTypeMapping(org.folio.repository.accesstypes.AccessTypeMapping) AccessType(org.folio.rest.jaxrs.model.AccessType) AccessTypesTestUtil.insertAccessType(org.folio.util.AccessTypesTestUtil.insertAccessType) PackageByIdData(org.folio.holdingsiq.model.PackageByIdData) Test(org.junit.Test)

Aggregations

AccessTypeMapping (org.folio.repository.accesstypes.AccessTypeMapping)12 AccessTypesTestUtil.insertAccessTypeMapping (org.folio.util.AccessTypesTestUtil.insertAccessTypeMapping)10 Matchers.containsString (org.hamcrest.Matchers.containsString)10 Test (org.junit.Test)10 AccessType (org.folio.rest.jaxrs.model.AccessType)8 EqualToJsonPattern (com.github.tomakehurst.wiremock.matching.EqualToJsonPattern)7 DbPackage (org.folio.repository.packages.DbPackage)6 PackageByIdData (org.folio.holdingsiq.model.PackageByIdData)5 Package (org.folio.rest.jaxrs.model.Package)5 AccessTypesTestUtil.insertAccessType (org.folio.util.AccessTypesTestUtil.insertAccessType)4 PackagesTestUtil.buildDbPackage (org.folio.util.PackagesTestUtil.buildDbPackage)4 PackagesTestUtil.savePackage (org.folio.util.PackagesTestUtil.savePackage)4 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)3 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)2 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)2 UUID (java.util.UUID)2 RowSetUtils.toUUID (org.folio.db.RowSetUtils.toUUID)2 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1