use of org.folio.rest.jaxrs.model.TenantJob in project raml-module-builder by folio-org.
the class TenantAPIIT method tenantPost.
public String tenantPost(TenantAPI api, TestContext context, TenantAttributes tenantAttributes) {
Async async = context.async();
StringBuilder id = new StringBuilder();
api.postTenant(tenantAttributes, okapiHeaders, onSuccess(context, res1 -> {
TenantJob job = (TenantJob) res1.getEntity();
id.append(job.getId());
api.getTenantByOperationId(job.getId(), TIMER_WAIT, okapiHeaders, onSuccess(context, res2 -> {
TenantJob o = (TenantJob) res2.getEntity();
context.assertTrue(o.getComplete());
api.tenantExists(Vertx.currentContext(), tenantId).onComplete(onSuccess(context, bool -> {
context.assertTrue(bool, "tenant exists after post");
async.complete();
}));
}), vertx.getOrCreateContext());
}), vertx.getOrCreateContext());
async.await();
return id.toString();
}
use of org.folio.rest.jaxrs.model.TenantJob in project raml-module-builder by folio-org.
the class TenantAPI method postTenant.
private void postTenant(boolean async, TenantAttributes tenantAttributes, Map<String, String> headers, Handler<AsyncResult<Response>> handler, Context context) {
String tenantId = TenantTool.tenantId(headers);
String id = UUID.randomUUID().toString();
TenantJob job = new TenantJob();
job.setId(id);
job.setTenant(tenantId);
job.setTenantAttributes(tenantAttributes);
job.setComplete(false);
String location = "/_/tenant/" + id;
tenantExists(context, tenantId).compose(exists -> sqlFile(context, tenantId, tenantAttributes, exists)).onFailure(cause -> {
log.error(cause.getMessage(), cause);
handler.handle(Future.succeededFuture(PostTenantResponse.respond400WithTextPlain(cause.getMessage())));
}).onSuccess(files -> postgresClient(context).runSQLFile(files[0], true).compose(res -> {
if (!res.isEmpty()) {
return Future.failedFuture(res.get(0));
}
if (files.length == 1) {
// not saving job for disable or purge
return Future.succeededFuture();
}
return saveJob(job, tenantId, id, context);
}).onFailure(cause -> {
log.error(cause.getMessage(), cause);
handler.handle(Future.succeededFuture(PostTenantResponse.respond400WithTextPlain(cause.getMessage())));
}).onSuccess(result -> {
if (files.length == 1) {
// disable or purge?
PostgresClient.closeAllClients(tenantId);
handler.handle(Future.succeededFuture(PostTenantResponse.respond204()));
return;
}
if (async) {
handler.handle(Future.succeededFuture(PostTenantResponse.respond201WithApplicationJson(job, PostTenantResponse.headersFor201().withLocation(location))));
}
runAsync(tenantAttributes, files[1], job, headers, context).onComplete(res -> {
log.info("job {} completed", id);
if (async) {
completeJob(job, context);
} else {
if (job.getError() != null) {
handler.handle(Future.succeededFuture(PostTenantResponse.respond400WithTextPlain(job.getError())));
return;
}
handler.handle(Future.succeededFuture(PostTenantResponse.respond204()));
}
});
}));
}
Aggregations