List of usage examples for io.vertx.core.json JsonArray getLong
public Long getLong(int pos)
From source file:com.glencoesoftware.omero.ms.thumbnail.ThumbnailVerticle.java
License:Open Source License
/** * Get thumbnails event handler. Responds with a JSON dictionary of Base64 * encoded <code>image/jpeg</code> thumbnails keyed by {@link Image} * identifier. Each dictionary value is prefixed with * <code>data:image/jpeg;base64,</code> so that it can be used with * <a href="http://caniuse.com/#feat=datauri">data URIs</a>. * @param message JSON encoded event data. Required keys are * <code>omeroSessionKey</code> (String), <code>longestSide</code> * (Integer), and <code>imageIds</code> (List<Long>). */// w ww .j av a2s .c o m private void getThumbnails(Message<String> message) { JsonObject data = new JsonObject(message.body()); String omeroSessionKey = data.getString("omeroSessionKey"); int longestSide = data.getInteger("longestSide"); JsonArray imageIdsJson = data.getJsonArray("imageIds"); List<Long> imageIds = new ArrayList<Long>(); for (int i = 0; i < imageIdsJson.size(); i++) { imageIds.add(imageIdsJson.getLong(i)); } log.debug("Render thumbnail request ImageIds:{} longest side {}", imageIds, longestSide); try (OmeroRequest request = new OmeroRequest(host, port, omeroSessionKey)) { Map<Long, byte[]> thumbnails = request .execute(new ThumbnailsRequestHandler(longestSide, imageIds)::renderThumbnails); if (thumbnails == null) { message.fail(404, "Cannot find one or more Images"); } else { Map<Long, String> thumbnailsJson = new HashMap<Long, String>(); for (Entry<Long, byte[]> v : thumbnails.entrySet()) { thumbnailsJson.put(v.getKey(), "data:image/jpeg;base64," + Base64.encode(v.getValue())); } message.reply(Json.encode(thumbnailsJson)); } } catch (PermissionDeniedException | CannotCreateSessionException e) { String v = "Permission denied"; log.debug(v); message.fail(403, v); } catch (Exception e) { String v = "Exception while retrieving thumbnail"; log.error(v, e); message.fail(500, v); } }
From source file:org.azrul.langmera.DecisionService.java
private void getHistory(RoutingContext routingContext) { final HistoryRequest req = Json.decodeValue(routingContext.getBodyAsString(), HistoryRequest.class); List<HistoryResponseElement> histResponses = new ArrayList<>(); String driver = config.getProperty("jdbc.driver", String.class); String url = config.getProperty("jdbc.url", String.class); String username = config.getProperty("jdbc.username", String.class); String password = config.getProperty("jdbc.password", String.class); JDBCClient client = JDBCClient.createShared(vertx, new JsonObject().put("url", url) .put("driver_class", driver).put("user", username).put("password", password)); JsonArray param = new JsonArray(); param.add(req.getContext()).add(req.getFrom()).add(req.getTo()); // for (int i = 0; i < InMemoryDB.store.get(0).size(); i++) { // HistoryResponseElement resp = new HistoryResponseElement(); // String context = (String) InMemoryDB.store.get(0).get(i); // if (context.equals(req.getContext())) { // Date time = (Date) InMemoryDB.store.get(3).get(i); // if (time.after(req.getFrom()) && time.before(req.getTo())) { // resp.setContext(context); // resp.setDecision((String) InMemoryDB.store.get(1).get(i)); // resp.setInterest((Double) InMemoryDB.store.get(2).get(i)); // resp.setTime(time); // histResponses.add(resp); // } // } // }// w w w . j av a2s . c o m client.getConnection(ar -> { SQLConnection connection = ar.result(); connection.queryWithParams( "SELECT * FROM Trace ORDER BY decisiontime desc where context=? and decisiontime between ? and ?", param, r -> { if (r.succeeded()) { for (JsonArray row : r.result().getResults()) { HistoryResponseElement respElement = new HistoryResponseElement(); respElement.setContext(row.getString(1)); respElement.setDecision(row.getString(6)); respElement.setInterest(row.getDouble(8)); respElement.setTime(new Date(row.getLong(5))); histResponses.add(respElement); } HistoryResponse resp = new HistoryResponse(); resp.setElements(histResponses); routingContext.response().setStatusCode(201) .putHeader("content-type", "application/json; charset=utf-8") .exceptionHandler(ex -> { logger.log(Level.SEVERE, "Problem encountered when making decision", ex); }).end(Json.encodePrettily(resp)); } connection.close(); }); }); }
From source file:org.entcore.common.sql.SqlResult.java
License:Open Source License
public static Long countResult(Message<JsonObject> res) { if ("ok".equals(res.body().getString("status"))) { JsonArray values = res.body().getJsonArray("results"); if (values != null && values.size() == 1) { JsonArray row = values.getJsonArray(0); if (row != null && row.size() == 1) { return row.getLong(0); }// ww w . java2 s .c o m } } return null; }
From source file:org.perfcake.reporting.destination.c3chart.C3ChartData.java
License:Apache License
/** * Mixes two charts together sorted according to the first index column. Missing data for any index values in either chart are replaced with null. * Records with only null values are skipped. The existing chart data are not changed, a new instance is created. * * @param otherData/*from www .jav a2 s . c o m*/ * The other chart data to be mixed with this chart data. * @return A new chart data combining both input charts. */ @SuppressWarnings("unchecked") C3ChartData combineWith(final C3ChartData otherData) { final List<JsonArray> newData = new LinkedList<>(); int idx1 = getDataStart(); int idx2 = otherData.getDataStart(); if (idx1 == -1) { if (idx2 == -1) { return new C3ChartData(target, newData); } else { return new C3ChartData(target, new LinkedList<>(otherData.data)); } } else if (idx2 == -2) { return new C3ChartData(target, new LinkedList<>(data)); } int size1 = data.get(0).size(); List nullList1 = getNullList(size1 - 1); int size2 = otherData.data.get(0).size(); List nullList2 = getNullList(size2 - 1); while (idx1 < data.size() || idx2 < otherData.data.size()) { JsonArray a1 = idx1 < data.size() ? data.get(idx1) : null; JsonArray a2 = idx2 < otherData.data.size() ? otherData.data.get(idx2) : null; long p1 = a1 != null ? a1.getLong(0) : Long.MAX_VALUE; long p2 = a2 != null ? a2.getLong(0) : Long.MAX_VALUE; List raw = new LinkedList<>(); if (p1 == p2) { if (!isAllNull(a1) || !isAllNull(a2)) { raw.add(p1); raw.addAll(a1.getList().subList(1, size1)); raw.addAll(a2.getList().subList(1, size2)); } idx1++; idx2++; } else if (p1 < p2) { if (!isAllNull(a1)) { raw.add(p1); raw.addAll(a1.getList().subList(1, size1)); raw.addAll(nullList2); } idx1++; } else { if (!isAllNull(a2)) { raw.add(p2); raw.addAll(nullList1); raw.addAll(a2.getList().subList(1, size2)); } idx2++; } if (raw.size() > 0) { newData.add(new JsonArray(raw)); } } return new C3ChartData(target, newData); }