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