use of io.vertx.core.json.JsonArray in project okapi by folio-org.
the class PostgresTable method insert.
public void insert(T dd, Handler<ExtendedAsyncResult<Void>> fut) {
PostgresQuery q = pg.getQuery();
final String sql = "INSERT INTO " + table + "(" + jsonColumn + ") VALUES (?::JSONB)";
String s = Json.encode(dd);
JsonObject doc = new JsonObject(s);
JsonArray jsa = new JsonArray();
jsa.add(doc.encode());
q.queryWithParams(sql, jsa, res -> {
if (res.failed()) {
fut.handle(new Failure<>(res.getType(), res.cause()));
} else {
q.close();
fut.handle(new Success<>());
}
});
}
use of io.vertx.core.json.JsonArray in project okapi by folio-org.
the class PostgresTable method update.
public void update(T md, Handler<ExtendedAsyncResult<Void>> fut) {
PostgresQuery q = pg.getQuery();
String sql = "INSERT INTO " + table + "(" + jsonColumn + ") VALUES (?::JSONB)" + " ON CONFLICT ((" + idIndex + ")) DO UPDATE SET " + jsonColumn + "= ?::JSONB";
String s = Json.encode(md);
JsonObject doc = new JsonObject(s);
JsonArray jsa = new JsonArray();
jsa.add(doc.encode());
jsa.add(doc.encode());
q.updateWithParams(sql, jsa, res -> {
if (res.failed()) {
fut.handle(new Failure<>(INTERNAL, res.cause()));
} else {
q.close();
fut.handle(new Success<>());
}
});
}
use of io.vertx.core.json.JsonArray in project okapi by folio-org.
the class PostgresTable method delete.
public void delete(String id, Handler<ExtendedAsyncResult<Void>> fut) {
PostgresQuery q = pg.getQuery();
String sql = "DELETE FROM " + table + " WHERE " + idSelect;
JsonArray jsa = new JsonArray();
jsa.add(id);
q.updateWithParams(sql, jsa, res -> {
if (res.failed()) {
fut.handle(new Failure<>(INTERNAL, res.cause()));
} else {
UpdateResult result = res.result();
if (result.getUpdated() > 0) {
fut.handle(new Success<>());
} else {
fut.handle(new Failure<>(NOT_FOUND, id));
}
q.close();
}
});
}
use of io.vertx.core.json.JsonArray in project okapi by folio-org.
the class TenantStorePostgres method updateModuleR.
private void updateModuleR(PostgresQuery q, String id, SortedMap<String, Boolean> enabled, Iterator<JsonObject> it, Handler<ExtendedAsyncResult<Void>> fut) {
if (it.hasNext()) {
JsonObject r = it.next();
String sql = "UPDATE " + TABLE + " SET " + JSON_COLUMN + " = ? WHERE " + ID_SELECT;
String tj = r.getString(JSON_COLUMN);
Tenant t = Json.decodeValue(tj, Tenant.class);
t.setEnabled(enabled);
String s = Json.encode(t);
JsonObject doc = new JsonObject(s);
JsonArray jsa = new JsonArray();
jsa.add(doc.encode());
jsa.add(id);
q.queryWithParams(sql, jsa, res -> {
if (res.failed()) {
fut.handle(new Failure<>(INTERNAL, res.cause()));
} else {
updateModuleR(q, id, enabled, it, fut);
}
});
} else {
fut.handle(new Success<>());
q.close();
}
}
use of io.vertx.core.json.JsonArray in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testCookieFormNoexplodeArray.
/**
* Test: cookie_form_noexplode_array
* Expected parameters sent:
* color: color=blue,black,brown
* Expected response: {"color":["blue","black","brown"]}
* @throws Exception
*/
@Test
public void testCookieFormNoexplodeArray() throws Exception {
routerFactory.addHandlerByOperationId("cookie_form_noexplode_array", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_cookie = params.cookieParameter("color");
assertNotNull(color_cookie);
assertTrue(color_cookie.isArray());
res.put("color", new JsonArray(color_cookie.getArray().stream().map(param -> param.getString()).collect(Collectors.toList())));
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
CountDownLatch latch = new CountDownLatch(1);
List<Object> color_cookie;
color_cookie = new ArrayList<>();
color_cookie.add("blue");
color_cookie.add("black");
color_cookie.add("brown");
startServer();
apiClient.cookieFormNoexplodeArray(color_cookie, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").equals(ar.result().bodyAsJsonObject()));
} else {
assertTrue(ar.cause().getMessage(), false);
}
latch.countDown();
});
awaitLatch(latch);
}
Aggregations