use of org.folio.inventory.support.http.client.OkapiHttpClient in project mod-inventory by folio-org.
the class MappingMetadataCache method loadJobProfileSnapshot.
@SneakyThrows
private CompletableFuture<Optional<MappingMetadataDto>> loadJobProfileSnapshot(String jobExecutionId, Context context) {
LOGGER.debug("Trying to load MappingMetadata by jobExecutionId '{}' for cache, okapi url: {}, tenantId: {}", jobExecutionId, context.getOkapiLocation(), context.getTenantId());
OkapiHttpClient client = new OkapiHttpClient(WebClient.wrap(httpClient), new URL(context.getOkapiLocation()), context.getTenantId(), context.getToken(), null, null, null);
return client.get(context.getOkapiLocation() + "/mapping-metadata/" + jobExecutionId).toCompletableFuture().thenCompose(httpResponse -> {
if (httpResponse.getStatusCode() == HttpStatus.SC_OK) {
LOGGER.info("MappingMetadata was loaded by jobExecutionId '{}'", jobExecutionId);
return CompletableFuture.completedFuture(Optional.of(Json.decodeValue(httpResponse.getBody(), MappingMetadataDto.class)));
} else if (httpResponse.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
LOGGER.warn("MappingMetadata was not found by jobExecutionId '{}'", jobExecutionId);
return CompletableFuture.completedFuture(Optional.empty());
} else {
String message = String.format("Error loading MappingMetadata by id: '%s', status code: %s, response message: %s", jobExecutionId, httpResponse.getStatusCode(), httpResponse.getBody());
LOGGER.warn(message);
return CompletableFuture.failedFuture(new CacheLoadingException(message));
}
});
}
use of org.folio.inventory.support.http.client.OkapiHttpClient in project mod-inventory by folio-org.
the class ApiTestSuite method createLocations.
private static void createLocations() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
final OkapiHttpClient client = createOkapiHttpClient();
ResourceClient institutionsClient = ResourceClient.forInstitutions(client);
nottinghamUniversityInstitution = createReferenceRecord(institutionsClient, "Nottingham University", "NOTT");
ResourceClient campusesClient = ResourceClient.forCampuses(client);
jubileeCampus = createReferenceRecord(campusesClient, new JsonObject().put("name", "Jubilee Campus").put("institutionId", nottinghamUniversityInstitution.toString()).put("code", "JUBILEE"));
ResourceClient librariesClient = ResourceClient.forLibraries(client);
djanoglyLibrary = createReferenceRecord(librariesClient, new JsonObject().put("name", "Djanogly Learning Resource Centre").put("campusId", jubileeCampus.toString()).put("code", "DJANOGLY"));
businessLibrary = createReferenceRecord(librariesClient, new JsonObject().put("name", "Business Library").put("campusId", jubileeCampus.toString()).put("code", "BUSINESS"));
ResourceClient locationsClient = ResourceClient.forLocations(client);
final UUID fakeServicePointId = UUID.randomUUID();
thirdFloorLocationId = createReferenceRecord(locationsClient, new JsonObject().put("name", "3rd Floor").put("code", "NU/JC/DL/3F").put("institutionId", nottinghamUniversityInstitution.toString()).put("campusId", jubileeCampus.toString()).put("libraryId", djanoglyLibrary.toString()).put("primaryServicePoint", fakeServicePointId.toString()).put("servicePointIds", new JsonArray().add(fakeServicePointId.toString())));
mezzanineDisplayCaseLocationId = createReferenceRecord(locationsClient, new JsonObject().put("name", "Display Case, Mezzanine").put("code", "NU/JC/BL/DM").put("institutionId", nottinghamUniversityInstitution.toString()).put("campusId", jubileeCampus.toString()).put("libraryId", businessLibrary.toString()).put("primaryServicePoint", fakeServicePointId.toString()).put("servicePointIds", new JsonArray().add(fakeServicePointId.toString())));
readingRoomLocationId = createReferenceRecord(locationsClient, new JsonObject().put("name", "Reading Room").put("code", "NU/JC/BL/PR").put("institutionId", nottinghamUniversityInstitution.toString()).put("campusId", jubileeCampus.toString()).put("libraryId", businessLibrary.toString()).put("primaryServicePoint", fakeServicePointId.toString()).put("servicePointIds", new JsonArray().add(fakeServicePointId.toString())));
// Need to create a main library location otherwise MODS ingestion will fail
// TODO: Need to remove this when MODS uses different example location
mainLibraryLocationId = createReferenceRecord(locationsClient, new JsonObject().put("name", "Main Library").put("code", "NU/JC/DL/ML").put("institutionId", nottinghamUniversityInstitution.toString()).put("campusId", jubileeCampus.toString()).put("libraryId", djanoglyLibrary.toString()).put("primaryServicePoint", fakeServicePointId.toString()).put("servicePointIds", new JsonArray().add(fakeServicePointId.toString())));
}
use of org.folio.inventory.support.http.client.OkapiHttpClient in project mod-inventory by folio-org.
the class ApiTestSuite method createInstanceTypes.
private static void createInstanceTypes() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
OkapiHttpClient client = createOkapiHttpClient();
URL instanceTypes = new URL(String.format("%s/instance-types", storageOkapiUrl()));
ControlledVocabularyPreparation instanceTypesPreparation = new ControlledVocabularyPreparation(client, instanceTypes, "instanceTypes");
textInstanceTypeId = instanceTypesPreparation.createOrReferenceTerm("text", "txt", "rdacontent");
}
use of org.folio.inventory.support.http.client.OkapiHttpClient in project mod-inventory by folio-org.
the class ApiTestSuite method createIdentifierTypes.
private static void createIdentifierTypes() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
OkapiHttpClient client = createOkapiHttpClient();
URL identifierTypesUrl = new URL(String.format("%s/identifier-types", storageOkapiUrl()));
ControlledVocabularyPreparation identifierTypesPreparation = new ControlledVocabularyPreparation(client, identifierTypesUrl, "identifierTypes");
isbnIdentifierTypeId = identifierTypesPreparation.createOrReferenceTerm("ISBN");
asinIdentifierTypeId = identifierTypesPreparation.createOrReferenceTerm("ASIN");
}
use of org.folio.inventory.support.http.client.OkapiHttpClient in project mod-inventory by folio-org.
the class ApiTestSuite method createContributorNameTypes.
private static void createContributorNameTypes() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
OkapiHttpClient client = createOkapiHttpClient();
URL contributorNameTypes = new URL(String.format("%s/contributor-name-types", storageOkapiUrl()));
ControlledVocabularyPreparation contributorNameTypesPreparation = new ControlledVocabularyPreparation(client, contributorNameTypes, "contributorNameTypes");
personalContributorNameTypeId = contributorNameTypesPreparation.createOrReferenceTerm("Personal name");
}
Aggregations