use of org.folio.rest.client.DataImportProfilesClient in project mod-invoice by folio-org.
the class JobProfileSnapshotCache method loadJobProfileSnapshot.
private CompletableFuture<Optional<ProfileSnapshotWrapper>> loadJobProfileSnapshot(String profileSnapshotId, Map<String, String> okapiHeaders) {
String okapiUrl = okapiHeaders.get(RestConstants.OKAPI_URL);
String tenant = okapiHeaders.get(RestVerticle.OKAPI_HEADER_TENANT);
logger.debug("Trying to load jobProfileSnapshot by id '{}' for cache, okapi url: {}, tenantId: {}", profileSnapshotId, okapiUrl, tenant);
DataImportProfilesClient client = new DataImportProfilesClient(okapiUrl, tenant, okapiHeaders.get(OKAPI_HEADER_TOKEN));
return client.getDataImportProfilesJobProfileSnapshotsById(profileSnapshotId).toCompletionStage().toCompletableFuture().thenCompose(httpResponse -> {
if (httpResponse.statusCode() == HttpStatus.HTTP_OK.toInt()) {
logger.info("JobProfileSnapshot was loaded by id '{}'", profileSnapshotId);
return CompletableFuture.completedFuture(Optional.of(httpResponse.bodyAsJson(ProfileSnapshotWrapper.class)));
} else if (httpResponse.statusCode() == HttpStatus.HTTP_NOT_FOUND.toInt()) {
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.statusCode(), httpResponse.bodyAsString());
logger.warn(message);
return CompletableFuture.failedFuture(new CacheLoadingException(message));
}
});
}
use of org.folio.rest.client.DataImportProfilesClient in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method createJobProfileSnapshotWrapper.
private Future<ProfileSnapshotWrapper> createJobProfileSnapshotWrapper(JobProfileInfo jobProfile, OkapiConnectionParams params) {
Promise<ProfileSnapshotWrapper> promise = Promise.promise();
DataImportProfilesClient client = new DataImportProfilesClient(params.getOkapiUrl(), params.getTenantId(), params.getToken());
client.postDataImportProfilesJobProfileSnapshotsById(jobProfile.getId(), response -> {
if (response.result().statusCode() == HTTP_CREATED.toInt()) {
promise.handle(Try.itGet(() -> response.result().bodyAsJsonObject().mapTo(ProfileSnapshotWrapper.class)));
} else {
String message = String.format("Error creating ProfileSnapshotWrapper by JobProfile id '%s', response code %s", jobProfile.getId(), response.result().statusCode());
LOGGER.error(message);
promise.fail(message);
}
});
return promise.future();
}
use of org.folio.rest.client.DataImportProfilesClient in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method loadJobProfileById.
private Future<JobProfile> loadJobProfileById(String jobProfileId, OkapiConnectionParams params) {
Promise<JobProfile> promise = Promise.promise();
DataImportProfilesClient client = new DataImportProfilesClient(params.getOkapiUrl(), params.getTenantId(), params.getToken());
client.getDataImportProfilesJobProfilesById(jobProfileId, false, null, response -> {
if (response.result().statusCode() == HTTP_OK.toInt()) {
promise.handle(Try.itGet(() -> response.result().bodyAsJsonObject().mapTo(JobProfile.class)));
} else {
String message = String.format("Error loading JobProfile by JobProfile id '%s', response code %s", jobProfileId, response.result().statusCode());
LOGGER.error(message);
promise.fail(message);
}
});
return promise.future();
}
Aggregations