Search in sources :

Example 1 with OkapiHttpClient

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));
        }
    });
}
Also used : OkapiHttpClient(org.folio.inventory.support.http.client.OkapiHttpClient) CacheLoadingException(org.folio.inventory.dataimport.exceptions.CacheLoadingException) URL(java.net.URL) SneakyThrows(lombok.SneakyThrows)

Example 2 with OkapiHttpClient

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())));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) ResourceClient(api.support.http.ResourceClient) OkapiHttpClient(org.folio.inventory.support.http.client.OkapiHttpClient) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID)

Example 3 with OkapiHttpClient

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");
}
Also used : OkapiHttpClient(org.folio.inventory.support.http.client.OkapiHttpClient) ControlledVocabularyPreparation(api.support.ControlledVocabularyPreparation) URL(java.net.URL)

Example 4 with OkapiHttpClient

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");
}
Also used : OkapiHttpClient(org.folio.inventory.support.http.client.OkapiHttpClient) ControlledVocabularyPreparation(api.support.ControlledVocabularyPreparation) URL(java.net.URL)

Example 5 with OkapiHttpClient

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");
}
Also used : OkapiHttpClient(org.folio.inventory.support.http.client.OkapiHttpClient) ControlledVocabularyPreparation(api.support.ControlledVocabularyPreparation) URL(java.net.URL)

Aggregations

OkapiHttpClient (org.folio.inventory.support.http.client.OkapiHttpClient)16 URL (java.net.URL)12 MalformedURLException (java.net.MalformedURLException)7 ControlledVocabularyPreparation (api.support.ControlledVocabularyPreparation)6 CollectionResourceClient (org.folio.inventory.storage.external.CollectionResourceClient)6 JsonObject (io.vertx.core.json.JsonObject)5 JsonArray (io.vertx.core.json.JsonArray)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 WebContext (org.folio.inventory.common.WebContext)3 Response (org.folio.inventory.support.http.client.Response)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 SneakyThrows (lombok.SneakyThrows)2 CacheLoadingException (org.folio.inventory.dataimport.exceptions.CacheLoadingException)2 ClientErrorResponse (org.folio.inventory.support.http.server.ClientErrorResponse)2 ForwardResponse (org.folio.inventory.support.http.server.ForwardResponse)2 JsonResponse (org.folio.inventory.support.http.server.JsonResponse)2 ServerErrorResponse (org.folio.inventory.support.http.server.ServerErrorResponse)2 SuccessResponse (org.folio.inventory.support.http.server.SuccessResponse)2 HoldingRequestBuilder (api.support.builders.HoldingRequestBuilder)1 ItemRequestBuilder (api.support.builders.ItemRequestBuilder)1