List of usage examples for io.vertx.core.json JsonObject getLong
public Long getLong(String key)
From source file:com.diabolicallabs.process.manager.service.ProcessServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {// www. j av a 2 s . co m JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "abort": { service.abort(json.getValue("processInstanceId") == null ? null : (json.getLong("processInstanceId").longValue()), createHandler(msg)); break; } case "create": { service.create((java.lang.String) json.getValue("processId"), res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { String proxyAddress = UUID.randomUUID().toString(); ProxyHelper.registerService(ProcessInstanceService.class, vertx, res.result(), proxyAddress, false, timeoutSeconds); msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress)); } }); break; } case "createWithVariables": { service.createWithVariables((java.lang.String) json.getValue("processId"), (io.vertx.core.json.JsonObject) json.getValue("variables"), res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { String proxyAddress = UUID.randomUUID().toString(); ProxyHelper.registerService(ProcessInstanceService.class, vertx, res.result(), proxyAddress, false, timeoutSeconds); msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress)); } }); break; } case "signalEvent": { service.signalEvent((java.lang.String) json.getValue("eventName"), (io.vertx.core.json.JsonObject) json.getValue("data"), createHandler(msg)); break; } case "signalEventForProcess": { service.signalEventForProcess((java.lang.String) json.getValue("eventName"), json.getValue("processInstanceId") == null ? null : (json.getLong("processInstanceId").longValue()), (io.vertx.core.json.JsonObject) json.getValue("data"), createHandler(msg)); break; } case "startProcess": { service.startProcess((java.lang.String) json.getValue("processId"), res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { String proxyAddress = UUID.randomUUID().toString(); ProxyHelper.registerService(ProcessInstanceService.class, vertx, res.result(), proxyAddress, false, timeoutSeconds); msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress)); } }); break; } case "startProcessWithVariables": { service.startProcessWithVariables((java.lang.String) json.getValue("processId"), (io.vertx.core.json.JsonObject) json.getValue("jsonObject"), res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { String proxyAddress = UUID.randomUUID().toString(); ProxyHelper.registerService(ProcessInstanceService.class, vertx, res.result(), proxyAddress, false, timeoutSeconds); msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress)); } }); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
From source file:com.diabolicallabs.process.manager.service.TaskServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {/*ww w . ja va2s .c o m*/ JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "addComment": { service.addComment(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()), (java.lang.String) json.getValue("userId"), (java.lang.String) json.getValue("comment"), createHandler(msg)); break; } case "claim": { service.claim(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()), (java.lang.String) json.getValue("userId"), createHandler(msg)); break; } case "complete": { service.complete(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()), (java.lang.String) json.getValue("userId"), (io.vertx.core.json.JsonObject) json.getValue("data"), createHandler(msg)); break; } case "delegate": { service.delegate(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()), (java.lang.String) json.getValue("userId"), (java.lang.String) json.getValue("newUserId"), createHandler(msg)); break; } case "exit": { service.exit(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()), (java.lang.String) json.getValue("userId"), createHandler(msg)); break; } case "fail": { service.fail(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()), (java.lang.String) json.getValue("userId"), (io.vertx.core.json.JsonObject) json.getValue("data"), createHandler(msg)); break; } case "forward": { service.forward(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()), (java.lang.String) json.getValue("userId"), (java.lang.String) json.getValue("newUserId"), createHandler(msg)); break; } case "getContent": { service.getContent(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()), createHandler(msg)); break; } case "release": { service.release(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()), (java.lang.String) json.getValue("userId"), createHandler(msg)); break; } case "resume": { service.resume(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()), (java.lang.String) json.getValue("userId"), createHandler(msg)); break; } case "skip": { service.skip(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()), (java.lang.String) json.getValue("userId"), createHandler(msg)); break; } case "start": { service.start(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()), (java.lang.String) json.getValue("userId"), createHandler(msg)); break; } case "stop": { service.stop(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()), (java.lang.String) json.getValue("userId"), createHandler(msg)); break; } case "suspend": { service.suspend(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()), (java.lang.String) json.getValue("userId"), createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
From source file:com.github.jackygurui.vertxredissonrepository.handler.Impl.CallInMessageHandlerImpl.java
License:Apache License
@Override public void handle(Message<JsonObject> m) { JsonObject jBody = m.body(); String from = jBody.getString("from"); String to = jBody.getString("to"); Long requestTime = jBody.getLong("requestTime"); String userData = jBody.getString("userData"); AtomicReference<String> cId = new AtomicReference(); AtomicReference<Customer.PersonalDetails> p = new AtomicReference(); Async.waterfall().<String>task(t -> { personalDetailsRepo.searchUniqueIndex("phoneNumber", from, t); }).<Customer.PersonalDetails>task((id, t) -> { cId.set(id);/*from ww w . ja v a 2 s . c o m*/ personalDetailsRepo.get(id, t); }).<Customer.AddressDetails>task((c, t) -> { p.set(c); addressDetailsRepo.get(cId.get(), t); }).run(r -> { CallIn ci; if (r.failed()) { ci = CallIn.builder().callTime(requestTime).callType(numberTypeMap.get(to)).comments(userData) .fullName("??").phoneNumber(from).build(); } else { Customer.PersonalDetails cpd = p.get(); Customer.AddressDetails cad = r.result(); ci = CallIn.builder().address(cad.getFullAddress()).area(cpd.getArea()).birthDay(cpd.getBirthDay()) .callTime(requestTime).callType(numberTypeMap.get(to)).city(cpd.getCity()) .comments(userData).customerId(cId.get()).fullName(cpd.getFullName()) .gender(cpd.getGender()).phoneNumber(from).province(cpd.getProvince()).type(cpd.getType()) .build(); } callInRepo.create(Json.encode(ci), c -> { m.reply(c.result()); ci.setId(c.result()); vertx.eventBus().publish("client.notification.inComingCall", Json.encode(ci)); }); }); }
From source file:com.glencoesoftware.omero.ms.thumbnail.ThumbnailVerticle.java
License:Open Source License
/** * Render thumbnail event handler. Responds with a <code>image/jpeg</code> * body on success or a failure./*from w w w. j av a 2 s. co m*/ * @param message JSON encoded event data. Required keys are * <code>omeroSessionKey</code> (String), <code>longestSide</code> * (Integer), and <code>imageId</code> (Long). */ private void renderThumbnail(Message<String> message) { JsonObject data = new JsonObject(message.body()); String omeroSessionKey = data.getString("omeroSessionKey"); int longestSide = data.getInteger("longestSide"); long imageId = data.getLong("imageId"); Optional<Long> renderingDefId = Optional.ofNullable(data.getLong("renderingDefId")); log.debug("Render thumbnail request Image:{} longest side {} RenderingDef:{}", imageId, longestSide, renderingDefId.orElse(null)); try (OmeroRequest request = new OmeroRequest(host, port, omeroSessionKey)) { byte[] thumbnail = request .execute(new ThumbnailRequestHandler(longestSide, imageId, renderingDefId)::renderThumbnail); if (thumbnail == null) { message.fail(404, "Cannot find Image:" + imageId); } else { message.reply(thumbnail); } } 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:com.hpe.sw.cms.verticle.MongoStoreVerticle.java
License:Apache License
@Override public void start() throws Exception { super.start(); client = MongoClient.createShared(vertx, config().getJsonObject("mongo")); vertx.eventBus().consumer(Events.GET_IMAGES.name(), msg -> { JsonObject param = (JsonObject) msg.body(); JsonObject query = new JsonObject(); if (param != null && param.getString("timestamp") != null) { Long timestamp = Long.parseLong(param.getString("timestamp")); query.put(Image.TIMESTAMP, new JsonObject().put("$gte", timestamp)); } else if (param != null && param.getString("imageid") != null) { query.put(Image.IMAGE_ID, param.getString(Image.IMAGE_ID)); }//from w w w . j a va2 s. com if (!query.containsKey(Image.IMAGE_ID) && (param == null || param.getString("include") == null || !"all".equals(param.getString("include")))) { query.put(Image.IMAGE_ID, new JsonObject().put("$exists", true)); } JsonArray images = new JsonArray(); client.find("images", query, res -> { if (res.succeeded()) { List<JsonObject> result = res.result(); for (JsonObject dbImage : result) { images.add(Image.cloneImage(dbImage)); } msg.reply(images); } }); }); vertx.eventBus().consumer(Events.DOWNLOAD_FILE.name(), msg -> { JsonObject query = (JsonObject) msg.body(); LOG.debug("DOWNLOAD_FILE query is " + query); client.find("images", query, res -> { if (res.succeeded()) { List<JsonObject> result = res.result(); LOG.debug("DOWNLOAD_FILE result is " + result.size()); if (result.size() > 0) { msg.reply(result.get(0)); } else { msg.reply(null); } } }); }); vertx.eventBus().consumer(Events.IMAGES_UPDATED.name(), msg -> { JsonArray updates = new JsonArray(); JsonObject query = new JsonObject(); query.put(Image.IS_SCANNED, false); int fetchSize = Integer.valueOf(String.valueOf(msg.body())); FindOptions options = new FindOptions(); JsonObject sort = new JsonObject(); sort.put(Image.TIMESTAMP, -1); options.setLimit(fetchSize).setSort(sort); client.findWithOptions("images", query, options, res -> { if (res.succeeded()) { List<JsonObject> result = res.result(); for (JsonObject update : result) { updates.add(update); LOG.debug("get image from DB :" + Image.getImageKey(update)); } LOG.debug("IMAGES_UPDATED reply updates size " + updates.size()); msg.reply(updates); } }); }); vertx.eventBus().consumer(Events.SCANFILE_UPLOADED.name(), msg -> { JsonObject upFile = (JsonObject) msg.body(); JsonObject query = new JsonObject(); query.put(Image.HOST, upFile.getString(Image.HOST)).put(Image.NAME, upFile.getString(Image.NAME)) .put(Image.TAG, upFile.getString(Image.TAG)); client.find("images", query, res -> { if (res.succeeded()) { List<JsonObject> result = res.result(); if (result.size() == 0) { LOG.error("no mapped image in DB for " + Image.getImageKey(upFile)); return; } for (JsonObject dbImage : result) { if (upFile.getBoolean("isScanFailed")) { //Failed in scanning. LOG.info("store failed scan to DB " + Image.getImageKey(upFile)); dbImage.put(Image.IS_SCANNED, true); dbImage.put(Image.IS_SCANNED_FAILED, true); } else { //successfully in scanning. LOG.info("store scanfile to DB " + Image.getImageKey(upFile)); dbImage.put(Image.IS_SCANNED, true); dbImage.put(Image.IS_SCANNED_FAILED, false); dbImage.put(Image.IMAGE_ID, upFile.getString(Image.IMAGE_ID)); dbImage.put(Image.SCANNED_FILE, upFile.getBinary(Image.SCANNED_FILE)); } client.save("images", dbImage, h -> { if (h.succeeded()) { LOG.info("SCANFILE_UPLOADED:Image " + Image.getImageKey(dbImage) + " updated !"); } else { h.cause().printStackTrace(); } }); } } }); }); vertx.eventBus().consumer(Events.ENRICHFILE_UPLOADED.name(), msg -> { JsonArray upFiles = (JsonArray) msg.body(); for (Object upFileObj : upFiles) { JsonObject upFile = (JsonObject) upFileObj; if (upFile.getBinary("enrichedFile") == null) { LOG.info("enrichedFile is emptry for " + upFile.getString("imageid")); continue; } LOG.info("store enrichfile to DB " + upFile.getString("imageid")); JsonObject query = new JsonObject(); query.put(Image.IMAGE_ID, upFile.getString(Image.IMAGE_ID)); client.find("images", query, res -> { if (res.succeeded()) { List<JsonObject> result = res.result(); for (JsonObject dbImage : result) { dbImage.put(Image.IS_ENRICHED, true); dbImage.put(Image.ENRICHED_FILE, upFile.getBinary(Image.ENRICHED_FILE)); client.save("images", dbImage, h -> { if (h.succeeded()) { LOG.info("ENRICHFILE_UPLOADED:Image " + Image.getImageKey(dbImage) + " updated !"); } else { h.cause().printStackTrace(); } }); } } }); } }); vertx.eventBus().consumer(Events.IMAGE_TO_ENRICH.name(), msg -> { JsonObject query = new JsonObject(); query.put(Image.IS_SCANNED, true).put(Image.IS_SCANNED_FAILED, false).put(Image.IS_ENRICHED, false); client.find("images", query, res -> { if (res.succeeded()) { List<JsonObject> result = res.result(); msg.reply(new JsonArray(result)); } }); }); vertx.eventBus().consumer(Events.NEW_IMAGE.name(), msg -> { //to store events in JsonObject obj = (JsonObject) msg.body(); JsonObject query = new JsonObject(); query.put(Image.HOST, obj.getString(Image.HOST)).put(Image.NAME, obj.getString(Image.NAME)) .put(Image.TAG, obj.getString(Image.TAG)); client.find("images", query, res -> { if (res.succeeded()) { List<JsonObject> result = res.result(); if (result.isEmpty()) { //inserted client.insert("images", obj, h -> { if (h.succeeded()) { LOG.info("IMAGES_COMMING :Image " + Image.getImageKey(obj) + " inserted !"); } else { h.cause().printStackTrace(); } }); } else if (result.size() == 1) { JsonObject toUpdate = result.get(0); if (!obj.getString(Image.SIGN).equals(toUpdate.getString(Image.SIGN))) { toUpdate.put(Image.TIMESTAMP, obj.getLong(Image.TIMESTAMP)) .put(Image.SIGN, obj.getString(Image.SIGN)) .put(Image.IS_SCANNED, obj.getBoolean(Image.IS_SCANNED)) .put(Image.IS_ENRICHED, obj.getBoolean(Image.IS_ENRICHED)); //saved client.save("images", toUpdate, h -> { if (h.succeeded()) { LOG.info("IMAGES_COMMING :Image " + Image.getImageKey(obj) + " updated !"); } else { h.cause().printStackTrace(); } }); } else { LOG.info("IMAGES_COMMING :Image " + Image.getImageKey(obj) + " has the same sign with the coming image, so will not update to DB !"); } } else { throw new RuntimeException( "IMAGES_COMMING :Found " + result.size() + " image for " + Image.getImageKey(obj)); } } }); }); }
From source file:com.hpe.sw.cms.verticle.WatcherVerticle.java
License:Apache License
private void populateAndSendImage(JsonObject imageObj) { try {/*from w w w .j a v a 2 s . c o m*/ String protocol = config().getString("registry.protocol"); String host = config().getString("registry.host"); httpClient.getAbs(protocol + host + "/v2/" + imageObj.getString("name") + "/manifests/" + imageObj.getString("tag"), new Handler<HttpClientResponse>() { @Override public void handle(HttpClientResponse httpClientResponse) { httpClientResponse.bodyHandler(new Handler<Buffer>() { @Override public void handle(Buffer buffer) { JsonObject maniFestLib = buffer.toJsonObject(); JsonArray signs = maniFestLib.getJsonArray("signatures"); if (signs != null && signs.size() > 0) { StringBuffer fullSign = new StringBuffer(); for (Object sign : signs.getList()) { fullSign.append(((Map) sign).get("signature")).append("|"); } imageObj.put(Image.SIGN, fullSign); imageObj.put(Image.IS_SCANNED, false); imageObj.put(Image.IS_ENRICHED, false); imageObj.put(Image.IS_SCANNED_FAILED, false); if (imageObj.getLong(Image.TIMESTAMP) == null) { imageObj.put(Image.TIMESTAMP, new Date().getTime()); } vertx.eventBus().publish(Events.NEW_IMAGE.name(), imageObj); LOG.info("Event Image with populateSignToImage", imageObj); } } }); } }).end(); } catch (Exception e) { LOG.error("error in populateSignToImage", e); } }
From source file:com.hubrick.vertx.s3.client.S3ClientOptions.java
License:Apache License
public S3ClientOptions(final JsonObject json) { super(json);/*from ww w . ja va 2 s .c om*/ setSignPayload(json.getBoolean("signPayload")); setAwsAccessKey(json.getString("awsAccessKey")); setAwsSecretKey(json.getString("awsSecretKey")); setAwsRegion(json.getString("awsRegion")); setAwsServiceName(json.getString("awsServiceName")); setGlobalTimeoutMs(json.getLong("globalTimeoutMs")); setHostnameOverride(json.getString("hostnameOverride")); }
From source file:com.pluralsight.dockerproductionaws.portfolio.PortfolioServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {//from w ww. java 2 s . co m JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "getPortfolio": { service.getPortfolio(res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { msg.reply(res.result() == null ? null : res.result().toJson()); } }); break; } case "buy": { service.buy(json.getValue("amount") == null ? null : (json.getLong("amount").intValue()), (io.vertx.core.json.JsonObject) json.getValue("quote"), res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { msg.reply(res.result() == null ? null : res.result().toJson()); } }); break; } case "sell": { service.sell(json.getValue("amount") == null ? null : (json.getLong("amount").intValue()), (io.vertx.core.json.JsonObject) json.getValue("quote"), res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { msg.reply(res.result() == null ? null : res.result().toJson()); } }); break; } case "evaluate": { service.evaluate(createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
From source file:com.reachauto.account.AccountServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {/*from w w w .j av a 2s.c o m*/ JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "addAccount": { service.addAccount( json.getJsonObject("account") == null ? null : new com.reachauto.account.Account(json.getJsonObject("account")), createHandler(msg)); break; } case "deleteAccount": { service.deleteAccount(json.getValue("id") == null ? null : (json.getLong("id").intValue()), createHandler(msg)); break; } case "updateAccount": { service.updateAccount(json.getJsonObject("account") == null ? null : new com.reachauto.account.Account(json.getJsonObject("account")), res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { msg.reply(res.result() == null ? null : res.result().toJson()); } }); break; } case "retrieveAccount": { service.retrieveAccount(json.getValue("id") == null ? null : (json.getLong("id").intValue()), res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { msg.reply(res.result() == null ? null : res.result().toJson()); } }); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
From source file:com.reachauto.product.ProductServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {/*from w ww.ja va 2s. c o m*/ JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "addProduct": { service.addProduct( json.getJsonObject("product") == null ? null : new com.reachauto.product.Product(json.getJsonObject("product")), createHandler(msg)); break; } case "deleteProduct": { service.deleteProduct(json.getValue("id") == null ? null : (json.getLong("id").intValue()), createHandler(msg)); break; } case "updateProduct": { service.updateProduct(json.getJsonObject("product") == null ? null : new com.reachauto.product.Product(json.getJsonObject("product")), res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { msg.reply(res.result() == null ? null : res.result().toJson()); } }); break; } case "retrieveProduct": { service.retrieveProduct(json.getValue("id") == null ? null : (json.getLong("id").intValue()), res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { msg.reply(res.result() == null ? null : res.result().toJson()); } }); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }