use of org.folio.rest.persist.Criteria.Criterion in project raml-module-builder by folio-org.
the class JobAPI method putJobsJobconfsByJobconfsIdJobsByJobId.
@Validate
@Override
public void putJobsJobconfsByJobconfsIdJobsByJobId(String jobId, String jobconfsId, String lang, Job entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
System.out.println("sending... putJobsJobconfsByJobconfsId");
try {
Criteria c = new Criteria();
c.addField("_id");
c.setOperation("=");
c.setValue(jobId);
c.setJSONB(false);
Criteria d = new Criteria();
d.addField("job_conf_id");
d.setOperation("=");
d.setValue(jobconfsId);
d.setJSONB(false);
vertxContext.runOnContext(v -> {
try {
PostgresClient.getInstance(vertxContext.owner()).update(RTFConsts.JOBS_COLLECTION, entity, new Criterion().addCriterion(c, "AND", d), true, reply -> {
if (reply.succeeded() && reply.result().getUpdated() == 0) {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainNotFound(jobId)));
} else {
try {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdJobsByJobIdResponse.withNoContent()));
} catch (Exception e) {
log.error(e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
}
});
} catch (Exception e) {
log.error(e.getMessage(), e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
});
} catch (Exception e) {
log.error(e.getMessage(), e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
}
use of org.folio.rest.persist.Criteria.Criterion in project raml-module-builder by folio-org.
the class PostgresClientTransactionsIT method deleteTransaction.
private void deleteTransaction(TestContext context, String schema) {
PostgresClient c1 = PostgresClient.getInstance(vertx, TENANT);
Async async = context.async();
// create connection
c1.startTx(handler -> {
if (handler.succeeded()) {
Criteria c = new Criteria();
c.addField("'id'").setOperation(Criteria.OP_EQUAL).setValue("2");
c1.delete(handler, "z", new Criterion(c), reply -> {
if (reply.succeeded()) {
// make sure record is deleted when querying using this connection
// but since not committed yet we should still get it back
// when sending the query on a different connection
c1.get(handler, "z", SimplePojo.class, new Criterion(c), true, true, reply2 -> {
if (!reply2.succeeded()) {
context.fail(reply2.cause());
async.complete();
} else {
try {
int size = reply2.result().getResults().size();
context.assertEquals(0, size);
// call get() without the connection. since we did not commit yet
// this should still return the deleted record
c1.get("z", SimplePojo.class, new Criterion(c), true, true, reply3 -> {
if (!reply3.succeeded()) {
context.fail(reply3.cause());
async.complete();
} else {
int size2 = reply3.result().getResults().size();
context.assertEquals(1, size2);
// end transaction / commit
// doesnt seem like a good idea to reuse the handler within the get()
// which lives outside of this connection, but for testing ok.
c1.endTx(handler, done -> {
if (done.succeeded()) {
// record should have been deleted, so only one record should return
// not both
c1.select("SELECT jsonb FROM " + schema + ".z;", selectReply -> {
if (!selectReply.succeeded()) {
context.fail(selectReply.cause());
async.complete();
} else {
try {
int size3 = selectReply.result().getResults().size();
context.assertEquals(1, size3);
} catch (Exception e) {
e.printStackTrace();
context.fail(e.getMessage());
}
async.complete();
}
});
} else {
context.fail(done.cause());
}
});
}
});
} catch (Exception e) {
e.printStackTrace();
context.fail(e.getMessage());
async.complete();
}
}
});
} else {
context.fail(reply.cause());
}
});
} else {
context.fail(handler.cause());
}
});
async.await();
c1.closeClient(context.asyncAssertSuccess());
}
Aggregations