Search in sources :

Example 1 with CacheLoadingException

use of org.folio.inventory.dataimport.exceptions.CacheLoadingException 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 CacheLoadingException

use of org.folio.inventory.dataimport.exceptions.CacheLoadingException in project mod-inventory by folio-org.

the class ProfileSnapshotCache method loadJobProfileSnapshot.

@SneakyThrows
private CompletableFuture<Optional<ProfileSnapshotWrapper>> loadJobProfileSnapshot(String profileSnapshotId, Context context) {
    LOGGER.debug("Trying to load jobProfileSnapshot by id  '{}' for cache, okapi url: {}, tenantId: {}", profileSnapshotId, 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() + "/data-import-profiles/jobProfileSnapshots/" + profileSnapshotId).toCompletableFuture().thenCompose(httpResponse -> {
        if (httpResponse.getStatusCode() == HttpStatus.SC_OK) {
            LOGGER.info("JobProfileSnapshot was loaded by id '{}'", profileSnapshotId);
            return CompletableFuture.completedFuture(Optional.of(Json.decodeValue(httpResponse.getBody(), (ProfileSnapshotWrapper.class))));
        } else if (httpResponse.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            LOGGER.warn("JobProfileSnapshot was not found by id '{}'", profileSnapshotId);
            return CompletableFuture.completedFuture(Optional.empty());
        } else {
            String message = String.format("Error loading jobProfileSnapshot by id: '%s', status code: %s, response message: %s", profileSnapshotId, 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) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) SneakyThrows(lombok.SneakyThrows)

Aggregations

URL (java.net.URL)2 SneakyThrows (lombok.SneakyThrows)2 CacheLoadingException (org.folio.inventory.dataimport.exceptions.CacheLoadingException)2 OkapiHttpClient (org.folio.inventory.support.http.client.OkapiHttpClient)2 ProfileSnapshotWrapper (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper)1