@CodeTranslate public void putBooleanFromIdentifier() throws Exception { JsonObject obj = new JsonObject(); obj.put("_true", true); obj.put("_false", false); JsonTest.o = JsonConverter.toJsonObject(obj); }
@Override public void onExecute(int what, JsonObject resultJO) { if (resultJO.containsKey("result_code") && resultJO.getInteger("result_code") == -1) { request.response().end(resultJO.toString()); return; } JsonObject rs = new JsonObject(); switch (what) { case WrapDAO.getSession: if (resultJO.getString("results").length() < 1) { rs.put("result_code", -1); rs.put("result_msg", "login please"); request.response().end(rs.toString()); break; } wrapDAO.getApp(this, Util.getUserId(params.getString("token"))); break; case WrapDAO.getApp: rs.put("result_code", 0); rs.put("result_msg", "app list"); rs.put("list_app", resultJO.getJsonArray("results")); request.response().end(rs.toString()); } }
public <T extends PersistableEvent<? extends SourcedEvent>> Observable<T> insert(final T event) { final JsonObject document = new JsonObject(); document.put("_id", event.getId()); document.put("dateCreated", new Date().getTime()); document.put("clazz", event.getClazz().getCanonicalName()); document.put("payload", new JsonObject(event.getPayload())); return mongoClient.insertObservable("events", document).flatMap(s -> Observable.just(event)); }
@Override protected JsonObject createAuthServiceConfig() { JsonObject js = new JsonObject(); js.put( MongoAuth.PROPERTY_COLLECTION_NAME, createCollectionName(MongoAuth.DEFAULT_COLLECTION_NAME)); js.put(MongoAuth.PROPERTY_SALT_STYLE, HashSaltStyle.EXTERNAL); return js; }
private static JsonObject makeExoJson(String line) { JsonObject jsonObject = new JsonObject(); Path path = Paths.get(line); if (Files.exists(path)) { jsonObject.put("full", line); String id = path.getFileName().toString(); id = id.substring(0, id.indexOf('.')); jsonObject.put("id", id); } return jsonObject; }
// Add some information on a deployment in the cluster so other nodes know about it private void addToHA( String deploymentID, String verticleName, DeploymentOptions deploymentOptions) { String encoded; synchronized (haInfo) { JsonObject verticleConf = new JsonObject().put("dep_id", deploymentID); verticleConf.put("verticle_name", verticleName); verticleConf.put("options", deploymentOptions.toJson()); JsonArray haMods = haInfo.getJsonArray("verticles"); haMods.add(verticleConf); encoded = haInfo.encode(); clusterMap.put(nodeID, encoded); } }
@Override public void execute(HttpServerRequest request) { init(request); wrapDAO.getSession(this, params.getString("token")); if (params.isEmpty() || !checkValidation(params)) { JsonObject rs = new JsonObject(); rs.put("result_code", -1); rs.put("result_msg", "params error"); request.response().end(rs.toString()); } }
/** * Convert to JSON * * @return the JSON */ public JsonObject toJson() { JsonObject mongoClientUpdateResultJson = new JsonObject(); if (docMatched != DEFAULT_DOCMATCHED) { mongoClientUpdateResultJson.put(DOC_MATCHED, docMatched); } if (docUpsertedId != null) { mongoClientUpdateResultJson.put(UPSERTED_ID, docUpsertedId); } if (docModified != DEFAULT_DOCMODIFIED) { mongoClientUpdateResultJson.put(DOC_MODIFIED, docModified); } return mongoClientUpdateResultJson; }
/* * TotalDebt = MarginDebt + DfDebt+dfOustandingDebt +accumulatedDepositFee + overdueDepositFee */ public Optional<JsonObject> parse(String json) { try { final JsonObject body = new JsonObject(json); final String type = body.getString(ATDAccountMastKey.MSG_TYPE); if (!isATDAccountMastMessage(type)) return Optional.empty(); System.out.println(body); final JsonObject jsonData = body.getJsonObject("data"); if (jsonData == null) return Optional.empty(); JsonObject result = new JsonObject(); result .put(ATDAccountMastKey.ACCOUNT, jsonData.getString(ATDAccountMastKey.ACCOUNT)) .put( ATDAccountMastKey.RECEIVING, string2Double(jsonData.getString(ATDAccountMastKey.RECEIVING))) .put( ATDAccountMastKey.BALANCE, string2Double(jsonData.getString(ATDAccountMastKey.BALANCE))) .put( ATDAccountMastKey.TOTALDEBT, string2Double(jsonData.getString(ATDAccountMastKey.TOTALDEBT))); return Optional.of(result); } catch (DecodeException e) { LOGGER.error("Cannot decode message to json: ", e); } return Optional.empty(); }
public JsonObject toJson() { JsonObject crit = new JsonObject(); findBy .getStrictRestrictions() .forEach( (name, value) -> { crit.put(name, value); }); findBy .getInRestrictions() .forEach( (name, values) -> { crit.put(name, new JsonObject().put("$in", new JsonArray(values))); }); return crit; }
public JsonObject toJson() { JsonObject ret = new JsonObject(); if (value != null) { ret.put("value", value); } return ret; }
@Override public JsonObject checkValidation(JsonObject params) { JsonObject res = new JsonObject(); if (!params.containsKey("token") || params.getString("token").isEmpty() || params.getString("token").equals("")) { res.put("result_code", -1); res.put("result_msg", "로그인 후 이용해주세요."); return res; } if (!params.containsKey("app_id") || params.getString("app_id").isEmpty() || params.getString("app_id").equals("")) { res.put("result_code", -1); res.put("result_msg", "앱을 선택하여 주세요."); return res; } if (!params.containsKey("user_nick") || params.getString("user_nick").isEmpty() || params.getString("user_nick").equals("")) { res.put("result_code", -1); res.put("result_msg", "유저 닉네임을 입력해주세요."); return res; } res.put("result_code", 0); return res; }
public static void toJson(Place obj, JsonObject json) { if (obj.getAddress() != null) { json.put("address", obj.getAddress()); } if (obj.getCategory() != null) { json.put("category", obj.getCategory()); } if (obj.getDescription() != null) { json.put("description", obj.getDescription()); } json.put("latitude", obj.getLatitude()); json.put("longitude", obj.getLongitude()); if (obj.getName() != null) { json.put("name", obj.getName()); } if (obj.getTags() != null) { json.put( "tags", new JsonArray( obj.getTags() .stream() .map(item -> item) .collect(java.util.stream.Collectors.toList()))); } }
@Override public JsonObject generateIdIfAbsentFromDocument(JsonObject json) { // TODO: Is this faster/better then Java UUID ? if (!documentHasId(json)) { ObjectId id = new ObjectId(); json.put(ID_FIELD, id.toHexString()); } return json; }
@Override protected Object readDateTime(BsonReader reader, DecoderContext ctx) { final JsonObject result = new JsonObject(); result.put( DATE_FIELD, OffsetDateTime.ofInstant(Instant.ofEpochMilli(reader.readDateTime()), ZoneOffset.UTC) .format(ISO_OFFSET_DATE_TIME)); return result; }
@Test public void testPublishJsonObject() { JsonObject obj = new JsonObject(); obj.put(TestUtils.randomUnicodeString(100), TestUtils.randomUnicodeString(100)) .put(TestUtils.randomUnicodeString(100), TestUtils.randomInt()); testPublish( obj, (received) -> { assertEquals(obj, received); assertFalse(obj == received); // Make sure it's copied }); }
@Override public JsonObject transform(JsonObject json) { if (json == null) { return null; } converters.forEach( (k, v) -> { Object value = json.getValue(k); if (value != null) { json.put(k, v.apply(value)); } }); return json; }
public void findAll(Router router) { router .get(MyUris.DISTRIBUTION_HOUSES.value) .handler( ctx -> { final JsonObject entries = new JsonObject(); long areaId = Converters.toLong(ctx.request().getParam(gv.areaId)); if (areaId > 0) entries.put(gv.areaId, areaId); Util.<JsonObject>send( vertx.eventBus(), MyEvents.FIND_ALL_DISTRIBUTION_HOUSES, entries.put("baseUrl", ctx.session().get("baseUrl").toString())) .map(m -> m.body()) .then( v -> ctx.response() .putHeader(HttpHeaders.CONTENT_TYPE, Controllers.APPLICATION_JSON)) .then(js -> ctx.response().end(js.encodePrettily())) .error(ctx::fail); }); }
private JsonObject buildLangTextJson(Map<String, String> langMap) { JsonObject jsonObj = new JsonObject(); if (langMap != null) { langMap.forEach( (key, value) -> { jsonObj.put(key, value); }); } return jsonObj; }
public HAManager( VertxInternal vertx, DeploymentManager deploymentManager, ClusterManager clusterManager, int quorumSize, String group, boolean enabled) { this.vertx = vertx; this.deploymentManager = deploymentManager; this.clusterManager = clusterManager; this.quorumSize = enabled ? quorumSize : 0; this.group = enabled ? group : "__DISABLED__"; this.enabled = enabled; this.haInfo = new JsonObject(); haInfo.put("verticles", new JsonArray()); haInfo.put("group", this.group); this.clusterMap = clusterManager.getSyncMap(CLUSTER_MAP_NAME); this.nodeID = clusterManager.getNodeID(); clusterManager.nodeListener( new NodeListener() { @Override public void nodeAdded(String nodeID) { HAManager.this.nodeAdded(nodeID); } @Override public void nodeLeft(String leftNodeID) { HAManager.this.nodeLeft(leftNodeID); } }); clusterMap.put(nodeID, haInfo.encode()); quorumTimerID = vertx.setPeriodic(QUORUM_CHECK_PERIOD, tid -> checkHADeployments()); // Call check quorum to compute whether we have an initial quorum synchronized (this) { checkQuorum(); } }
@RouteMapping(value = "/:id", method = RouteMethod.GET) public Handler<RoutingContext> fetch() { return ctx -> { String id = ctx.request().getParam("id"); if (StringUtils.isBlank(id)) { LOGGER.error("ID is blank"); JsonObject error = new JsonObject(); error.put("error", "ID should not be blank"); ctx.response().setStatusCode(205).end(error.encode()); } JDBCClient client = AppUtil.getJdbcClient(Vertx.vertx()); client.getConnection( conn -> { if (conn.failed()) { LOGGER.error(conn.cause().getMessage(), conn.cause()); ctx.fail(400); } SQLUtil.query( conn.result(), "select id, title, description from item where id = ?", new JsonArray().add(Integer.valueOf(id)), rs -> { SQLUtil.close(conn.result()); if (rs.getRows().size() == 1) { ctx.response().end(rs.getRows().get(0).encode()); } else { JsonObject error = new JsonObject(); error.put("error", "Record not found"); ctx.response().setStatusCode(205).end(error.encode()); } }); }); }; }
@Before public void setUp() { MockitoAnnotations.initMocks(this); configObj = new JsonObject(); configObj.put(EVENT_BUS_ADDRESS_PREFIX_KEY, "address"); JsonObject clusterObj = new JsonObject(); clusterObj.put(SERVERS_KEY, new JsonArray().add("server1")); clusterObj.put(NAMESPACE_KEY, "namespace"); clusterObj.put(POINTS_PER_SERVER, 10); clusterObj.put(ALGORITHM_KEY, HashAlgorithm.CRC_HASH.name()); JsonObject clustersObj = new JsonObject(); clustersObj.put("clusterA", clusterObj); configObj.put(CLUSTERS_KEY, clustersObj); config = new MemcacheClusterConfig(configObj); }
@Override public void getService( String serviceItf, JsonObject filter, Handler<AsyncResult<JsonObject>> resultHandler) { Objects.requireNonNull(resultHandler); JsonObject query; if (filter == null) { query = new JsonObject(); } else { query = filter.copy(); } if (serviceItf != null) { query.put("service.interface", serviceItf); } acquireLock( resultHandler, lock -> getRegistry( lock, resultHandler, map -> vertx.<JsonObject>executeBlocking( future -> { Optional<JsonObject> found = map.values().stream().filter(reg -> match(reg, query)).findAny(); if (found.isPresent()) { future.complete(found.get()); } else { future.fail("No matching service found"); } }, result -> { resultHandler.handle(result); lock.release(); }))); }
@Override public void getServices( String serviceItf, JsonObject filter, Handler<AsyncResult<List<JsonObject>>> resultHandler) { Objects.requireNonNull(resultHandler); JsonObject query; if (filter == null) { query = new JsonObject(); } else { query = filter.copy(); } if (serviceItf != null) { query.put("service.interface", serviceItf); } acquireLock( resultHandler, lock -> getRegistry( lock, resultHandler, map -> vertx.<List<JsonObject>>executeBlocking( future -> { List<JsonObject> matches = map.values() .stream() .filter(reg -> match(reg, query)) .collect(Collectors.toList()); future.complete(matches); }, result -> { resultHandler.handle(result); lock.release(); }))); }
protected void deployRandomVerticles(Runnable runner) { int toDeploy = 0; AtomicInteger deployCount = new AtomicInteger(); List<Integer> numbersToDeploy = new ArrayList<>(); for (int i = 0; i < aliveNodes.size(); i++) { int numToDeploy = random.nextInt(maxVerticlesPerNode + 1); numbersToDeploy.add(numToDeploy); toDeploy += numToDeploy; } int index = 0; for (int pos : aliveNodes) { Vertx v = vertices[pos]; int numToDeploy = numbersToDeploy.get(index); index++; for (int j = 0; j < numToDeploy; j++) { JsonObject config = new JsonObject(); config.put("foo", TestUtils.randomAlphaString(100)); DeploymentOptions options = new DeploymentOptions().setHa(true).setConfig(config); String verticleName = "java:io.vertx.test.core.HAVerticle" + (random.nextInt(3) + 1); v.deployVerticle( verticleName, options, ar -> { assertTrue(ar.succeeded()); deployCount.incrementAndGet(); }); } } int ttoDeploy = toDeploy; eventLoopWaitUntil( () -> ttoDeploy == deployCount.get(), () -> { totDeployed += ttoDeploy; runner.run(); }); }
@CodeTranslate public void putArrayFromIdentifier() throws Exception { JsonObject obj = new JsonObject(); obj.put("nested", new JsonArray().add("foo")); JsonTest.o = JsonConverter.toJsonObject(obj); }
public void saveGraph(Graph graph, boolean isFilterGraph) { int Counter = 0; JsonObject attrJson; // clear existing graph if (!isFilterGraph) { nodesMap.clear(); edgesMap.clear(); } else { nodesMapFilter.clear(); edgesMapFilter.clear(); } /* * Nodes Iteration */ for (Node node : graph.getNodes()) { attrJson = new JsonObject(); for (String attrKey : node.getAttributeKeys()) { attrJson.put(attrKey, node.getAttribute(attrKey)); } attrJson.put("x", node.x()); attrJson.put("y", node.y()); attrJson.put("cR", node.r()); attrJson.put("cG", node.g()); attrJson.put("cB", node.b()); attrJson.put("size", node.size()); if (!isFilterGraph) { nodesMap.put(Counter++, attrJson); } else { nodesMapFilter.put(Counter++, attrJson); } } Counter = 0; /* * Edges Iteration */ for (Edge edge : graph.getEdges()) { attrJson = new JsonObject(); for (String attrKey : edge.getAttributeKeys()) { attrJson.put(attrKey, edge.getAttribute(attrKey)); } attrJson.put("source", edge.getSource().getId()); attrJson.put("target", edge.getTarget().getId()); attrJson.put("cR", edge.r()); attrJson.put("cG", edge.g()); attrJson.put("cB", edge.b()); attrJson.put("size", edge.getWeight()); if (!isFilterGraph) { edgesMap.put(Counter++, attrJson); } else { edgesMapFilter.put(Counter++, attrJson); } } }
@CodeTranslate public void putStringFromIdentifier() throws Exception { JsonObject obj = new JsonObject(); obj.put("foo", "foo_value"); JsonTest.o = JsonConverter.toJsonObject(obj); }
@CodeTranslate public void putNumberFromIdentifier() throws Exception { JsonObject obj = new JsonObject(); obj.put("port", 8080); JsonTest.o = JsonConverter.toJsonObject(obj); }
@Override public void onExecute(int what, JsonObject resultJO) { if (resultJO.containsKey("result_code") && resultJO.getInteger("result_code") == -1) { request.response().end(resultJO.toString()); return; } JsonObject rs = new JsonObject(); switch (what) { case Config.getSession: if (!resultJO.containsKey("result") || resultJO.getString("result") == null) { rs.put("result_code", -1); rs.put("result_msg", "로그인이 필요합니다."); request.response().end(rs.toString()); break; } String user_info[] = resultJO.getString("result").split(","); String user_id = user_info[0]; params.put("user_id", user_id); String query = String.format( "UPDATE app_user_list SET user_nick='%s' WHERE user_id='%s' and app_id='%s'", params.getString("user_nick"), params.getString("user_id"), params.getString("app_id")); insertCustomQuery(this, Config.setNickApp, query); break; case Config.setNickApp: String query2 = String.format( "UPDATE channel_user_list SET user_nick='%s' WHERE user_id='%s' and app_id='%s'", params.getString("user_nick"), params.getString("user_id"), params.getString("app_id")); insertCustomQuery(this, 100, query2); rs.put("result_code", 0); rs.put("result_msg", "닉네임을 변경하였습니다."); request.response().end(rs.toString()); getRedis(this, Config.getRedis, "app:" + params.getString("user_id")); break; case Config.getRedis: JsonArray ja = new JsonArray(resultJO.getString("result")); for (int i = 0; i < ja.size(); i++) { if (params.getString("app_id").equals(ja.getJsonObject(i).getString("app_id"))) { JsonObject jo = ja.getJsonObject(i); jo.put("user_nick", params.getString("user_nick")); ja.remove(i); ja.add(jo); } } JsonObject table = new JsonObject(); table.put("key", "app:" + Util.getUserId(params.getString("token"))); table.put("value", ja.toString()); setRedis(this, Config.setRedis, table); break; } }