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