コード例 #1
0
 public void handle(Message<JsonObject> msg) {
   try {
     JsonObject json = msg.body();
     String action = msg.headers().get("action");
     if (action == null) {
       throw new IllegalStateException("action not specified");
     }
     accessed();
     switch (action) {
       case "checkin":
         {
           service.checkin(
               (java.lang.String) json.getValue("name"),
               json.getValue("lat") == null ? null : (json.getDouble("lat").doubleValue()),
               json.getValue("lon") == null ? null : (json.getDouble("lon").doubleValue()),
               createHandler(msg));
           break;
         }
       case "getCheckins":
         {
           service.getCheckins(
               res -> {
                 if (res.failed()) {
                   msg.fail(-1, res.cause().getMessage());
                 } else {
                   msg.reply(
                       new JsonArray(
                           res.result()
                               .stream()
                               .map(Checkin::toJson)
                               .collect(Collectors.toList())));
                 }
               });
           break;
         }
       default:
         {
           throw new IllegalStateException("Invalid action: " + action);
         }
     }
   } catch (Throwable t) {
     msg.fail(-1, t.getMessage());
     throw t;
   }
 }
コード例 #2
0
 public static boolean match(JsonObject registration, JsonObject query) {
   // A service registration match <=> all values from the query matches.
   // If the query as a value set to "*" any value are accepted
   for (Map.Entry<String, Object> entry : query) {
     Object value = registration.getValue(entry.getKey());
     if (value != null) {
       if (!entry.getValue().equals("*") && !value.equals(entry.getValue())) {
         return false;
       }
     }
   }
   return true;
 }
コード例 #3
0
 @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;
 }
コード例 #4
0
  @Override
  public BsonValue getDocumentId(JsonObject json) {
    if (!documentHasId(json)) {
      throw new IllegalStateException("The document does not contain an _id");
    }

    Object id = json.getValue(ID_FIELD);
    if (id instanceof String) {
      return new BsonString((String) id);
    }

    BsonDocument idHoldingDocument = new BsonDocument();
    BsonWriter writer = new BsonDocumentWriter(idHoldingDocument);
    writer.writeStartDocument();
    writer.writeName(ID_FIELD);
    writeValue(writer, null, id, EncoderContext.builder().build());
    writer.writeEndDocument();
    return idHoldingDocument.get(ID_FIELD);
  }
コード例 #5
0
 public static void fromJson(JsonObject json, Place obj) {
   if (json.getValue("address") instanceof String) {
     obj.setAddress((String) json.getValue("address"));
   }
   if (json.getValue("category") instanceof String) {
     obj.setCategory((String) json.getValue("category"));
   }
   if (json.getValue("description") instanceof String) {
     obj.setDescription((String) json.getValue("description"));
   }
   if (json.getValue("latitude") instanceof Number) {
     obj.setLatitude(((Number) json.getValue("latitude")).doubleValue());
   }
   if (json.getValue("longitude") instanceof Number) {
     obj.setLongitude(((Number) json.getValue("longitude")).doubleValue());
   }
   if (json.getValue("name") instanceof String) {
     obj.setName((String) json.getValue("name"));
   }
   if (json.getValue("tags") instanceof JsonArray) {
     java.util.List<java.lang.String> list = new java.util.ArrayList<>();
     json.getJsonArray("tags")
         .forEach(
             item -> {
               if (item instanceof String) list.add((String) item);
             });
     obj.setTags(list);
   }
 }
コード例 #6
0
ファイル: JsObject.java プロジェクト: eformat/vertx-codetrans
 @CodeTranslate
 public void getValueFromIdentifier() throws Exception {
   JsonObject obj = new JsonObject().put("foo", "foo_value");
   JsonTest.o = obj.getValue("foo");
 }
コード例 #7
0
 @Override
 protected void beforeFields(JsonObject object, BiConsumer<String, Object> objectConsumer) {
   if (object.containsKey(ID_FIELD)) {
     objectConsumer.accept(ID_FIELD, object.getValue(ID_FIELD));
   }
 }
コード例 #8
0
 public static void fromJson(JsonObject json, VertxApiRequest obj) {
   if (json.getValue("apiKey") instanceof String) {
     obj.setApiKey((String) json.getValue("apiKey"));
   }
   if (json.getValue("destination") instanceof String) {
     obj.setDestination((String) json.getValue("destination"));
   }
   if (json.getValue("headers") instanceof JsonObject) {
     HeaderMap map = new HeaderMap();
     json.getJsonObject("headers")
         .forEach(
             entry -> {
               if (entry.getValue() instanceof String)
                 map.put(entry.getKey(), (String) entry.getValue());
             });
     obj.setHeaders(map);
   }
   if (json.getValue("queryParams") instanceof JsonObject) {
     QueryMap map = new QueryMap();
     json.getJsonObject("queryParams")
         .forEach(
             entry -> {
               if (entry.getValue() instanceof String)
                 map.put(entry.getKey(), (String) entry.getValue());
             });
     obj.setQueryParams(map);
   }
   if (json.getValue("rawRequest") instanceof Object) {
     obj.setRawRequest(json.getValue("rawRequest"));
   }
   if (json.getValue("remoteAddr") instanceof String) {
     obj.setRemoteAddr((String) json.getValue("remoteAddr"));
   }
   if (json.getValue("serviceId") instanceof String) {
     obj.setApiId((String) json.getValue("serviceId"));
   }
   if (json.getValue("serviceOrgId") instanceof String) {
     obj.setApiOrgId((String) json.getValue("serviceOrgId"));
   }
   if (json.getValue("serviceVersion") instanceof String) {
     obj.setApiVersion((String) json.getValue("serviceVersion"));
   }
   if (json.getValue("transportSecure") instanceof Boolean) {
     obj.setTransportSecure((Boolean) json.getValue("transportSecure"));
   }
   if (json.getValue("type") instanceof String) {
     obj.setType((String) json.getValue("type"));
   }
 }