Ejemplo n.º 1
0
 @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;
 }
  @Override
  public void start(final Future<Void> startFuture) throws Exception {
    LOGGER.info("starting {0}..", identifier());

    // start the HELLO slacker protocol
    final JsonObject helloMessage =
        new JsonObject().put("i", identifier()).put("d", description()).put("v", version());
    vertx
        .eventBus()
        .send(
            "reg.slacker-server",
            helloMessage,
            result -> {
              if (result.succeeded() && JsonObject.class.isInstance(result.result().body())) {
                final JsonObject response = (JsonObject) result.result().body();
                if (response.containsKey("a")) {
                  // everything went smoothly - register the listener and complete the startup
                  registerListener(response.getString("a"));
                  LOGGER.info("successfully registered {0} executor", identifier());
                  startFuture.complete();
                } else {
                  failStart(startFuture, "no address to bind was received");
                }
              } else {
                // something unexpected happened
                failStart(
                    startFuture,
                    Optional.ofNullable(result.cause())
                        .map(Throwable::getMessage)
                        .orElse("invalid response"));
              }
            });
  }
Ejemplo n.º 3
0
  @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());
    }
  }
 @Override
 protected BsonType getBsonType(Object value) {
   BsonType type = super.getBsonType(value);
   if (type == BsonType.DOCUMENT) {
     JsonObject obj = (JsonObject) value;
     if (obj.containsKey(DATE_FIELD)) {
       return BsonType.DATE_TIME;
     }
     // not supported yet
     /*else if (obj.containsKey("$binary")) {
       return BsonType.BINARY;
     } else if (obj.containsKey("$maxKey")) {
       return BsonType.MAX_KEY;
     } else if (obj.containsKey("$minKey")) {
       return BsonType.MIN_KEY;
     } else if (obj.containsKey("$oid")) {
       return BsonType.OBJECT_ID;
     } else if (obj.containsKey("$regex")) {
       return BsonType.REGULAR_EXPRESSION;
     } else if (obj.containsKey("$symbol")) {
       return BsonType.SYMBOL;
     } else if (obj.containsKey("$timestamp")) {
       return BsonType.TIMESTAMP;
     } else if (obj.containsKey("$undefined")) {
       return BsonType.UNDEFINED;
     } else if (obj.containsKey("$numberLong")) {
       return BsonType.INT64;
     } else if (obj.containsKey("$code")) {
       return JAVASCRIPT or JAVASCRIPT_WITH_SCOPE;
     } */
   }
   return type;
 }
Ejemplo n.º 5
0
  @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;
    }
  }
 @Override
 protected void beforeFields(JsonObject object, BiConsumer<String, Object> objectConsumer) {
   if (object.containsKey(ID_FIELD)) {
     objectConsumer.accept(ID_FIELD, object.getValue(ID_FIELD));
   }
 }
 @Override
 public boolean documentHasId(JsonObject json) {
   return json.containsKey(ID_FIELD);
 }