public void testAcceptRejectGet() {
    TestHttpApiClient client =
        newHttpApiClient(UA_EMPTY, ServerTeam.jcsTicket(), TestApp.APP2_ID, TestApp.APP2_SECRET);
    client.get(
        PUB_API + "/suggest/recommend",
        new Object[][] {
          {"touser", ServerTeam.CG_ID},
          {"suggestedusers", String.valueOf(ServerTeam.WP_ID)}
        });
    client =
        newHttpApiClient(UA_EMPTY, ServerTeam.grxTicket(), TestApp.APP1_ID, TestApp.APP1_SECRET);
    client.get(
        PUB_API + "/psuggest/create",
        new Object[][] {
          {"to", ServerTeam.CG_ID},
          {
            "suggested",
            StringHelper.join(
                new long[] {ServerTeam.WP_ID, ServerTeam.GRX_ID, ServerTeam.JCS_ID}, ",")
          }
        });

    client =
        newHttpApiClient(UA_EMPTY, ServerTeam.cgTicket(), TestApp.APP2_ID, TestApp.APP2_SECRET);
    client.get(
        PUB_API + "/psuggest/accept",
        new Object[][] {
          {"suggested", ServerTeam.GRX_ID},
          {
            "circles",
            StringHelper.join(new int[] {Circle.CIRCLE_DEFAULT, Circle.CIRCLE_FAMILY}, ",")
          }
        });
    client.get(PUB_API + "/psuggest/reject", new Object[][] {{"suggested", ServerTeam.WP_ID}});

    AbstractHttpClient.Response resp =
        client.get(PUB_API + "/psuggest/get", new Object[][] {{"status", Status.ACCEPTED}});
    ArrayNode arrNode = (ArrayNode) resp.getJsonNode();
    assertEquals(arrNode.size(), 1);
    assertTrue(
        JsonCompare.compare(
                arrNode.get(0).get("suggested"),
                JsonHelper.parse(JsonHelper.toJson(PeopleId.fromId(ServerTeam.GRX_ID), false)))
            .isEquals());
    resp = client.get(PUB_API + "/psuggest/get", new Object[][] {{"status", Status.REJECTED}});
    arrNode = (ArrayNode) resp.getJsonNode();
    assertEquals(arrNode.size(), 1);
    assertTrue(
        JsonCompare.compare(
                arrNode.get(0).get("suggested"),
                JsonHelper.parse(JsonHelper.toJson(PeopleId.fromId(ServerTeam.WP_ID), false)))
            .isEquals());
  }
  public void testCreateGet() {
    TestHttpApiClient client =
        newHttpApiClient(UA_EMPTY, ServerTeam.jcsTicket(), TestApp.APP2_ID, TestApp.APP2_SECRET);
    AbstractHttpClient.Response resp =
        client.get(
            PUB_API + "/suggest/recommend",
            new Object[][] {
              {"touser", ServerTeam.CG_ID},
              {"suggestedusers", String.valueOf(ServerTeam.WP_ID)}
            });
    assertTrue(resp.getJsonNode().get("result").getBooleanValue());
    resp = client.get(PUB_API + "/suggest/get", new Object[][] {{"user_id", ServerTeam.CG_ID}});
    ArrayNode arrNode = (ArrayNode) resp.getJsonNode();
    assertEquals(arrNode.size(), 1);
    assertTrue(
        JsonCompare.compare(
                arrNode.get(0).get("suggested"),
                JsonHelper.parse(JsonHelper.toJson(PeopleId.fromId(ServerTeam.WP_ID), false)))
            .isEquals());

    client =
        newHttpApiClient(UA_EMPTY, ServerTeam.grxTicket(), TestApp.APP1_ID, TestApp.APP1_SECRET);
    resp =
        client.get(
            PUB_API + "/psuggest/create",
            new Object[][] {
              {"to", ServerTeam.CG_ID},
              {
                "suggested",
                StringHelper.join(
                    new long[] {ServerTeam.WP_ID, ServerTeam.GRX_ID, ServerTeam.JCS_ID}, ",")
              }
            });
    assertTrue(resp.getJsonNode().get("result").getBooleanValue());
    resp = client.get(PUB_API + "/psuggest/get", new Object[][] {{"user_id", ServerTeam.CG_ID}});
    arrNode = (ArrayNode) resp.getJsonNode();
    assertEquals(arrNode.size(), 2);
    for (JsonNode node : arrNode) {
      if (JsonCompare.compare(
              node.get("suggested"),
              JsonHelper.parse(JsonHelper.toJson(PeopleId.fromId(ServerTeam.WP_ID), false)))
          .isEquals()) {
        assertEquals(
            node.get("source").getTextValue(),
            StringHelper.join(new long[] {ServerTeam.JCS_ID, ServerTeam.GRX_ID}, ","));
      }
    }
  }
  private static String expandText(String s) {
    return StringHelper.replaceRegex(
        s,
        REF_PATT,
        new StringHelper.ReplaceHandler() {
          @Override
          public String replace(String replaced) {
            String constName = StringHelper.removeStartAndEnd(replaced, "${", "}");
            Object o = ClassHelper.getConstant(constName, null);
            if (o == null) return "";

            Class vt = o.getClass();
            if (vt.isArray()) {
              StringBuilder buff = new StringBuilder();
              int len = Array.getLength(o);
              for (int i = 0; i < len; i++) {
                Object elem = Array.get(o, i);
                if (elem == null) continue;

                if (buff.length() > 0) buff.append(", ");

                buff.append(elem.toString());
              }
              return buff.toString();
            } else {
              return ObjectUtils.toString(o);
            }
          }
        });
  }
예제 #4
0
  public static String disableComments(Context ctx, String table, long now, long... comment) {
    Sql sql = new Sql().update(table).setValues(value("destroyed_time", now));

    if (comment.length == 1) sql.where("`comment_id`=:comment_id", "comment_id", comment[0]);
    else sql.where("`comment_id` IN ($comment_id)", "comment_id", StringHelper.join(comment, ","));

    return sql.toString();
  }
 private static ParamDoc parseParamDoc(String s) {
   String param = StringUtils.substringBefore(s, " ").trim();
   ParamDoc paramDoc = new ParamDoc();
   paramDoc.description = expandText(StringUtils.substringAfter(s, " "));
   paramDoc.names = StringHelper.splitArray(StringUtils.substringBefore(param, ":"), "|", true);
   boolean hasDefault = StringUtils.contains(param, ":");
   paramDoc.must = !hasDefault;
   paramDoc.def = expandText(hasDefault ? StringUtils.substringAfter(param, ":") : "");
   return paramDoc;
 }
예제 #6
0
 public static String saveComment(String table, Comment comment) {
   return new Sql()
       .insertInto(table)
       .values(
           value("comment_id", comment.getCommentId()),
           value("can_like", comment.getCanLike()),
           value("commenter", comment.getCommenterId()),
           value("created_time", comment.getCreatedTime()),
           value("destroyed_time", 0),
           value("device", comment.getDevice()),
           value("message", comment.getMessage()),
           value("target_id", comment.getTarget().id),
           value("target_type", comment.getTarget().type),
           value(
               "add_to",
               comment.getAddTo() != null
                   ? StringHelper.join(comment.getAddTo().getIds(PeopleId.USER), ",")
                   : ""))
       .toString();
 }
예제 #7
0
 public static String getComments(String table, long... commentIds) {
   if (commentIds.length == 1) {
     return new Sql()
         .select("* ")
         .from(table)
         .where("comment_id =:comment_ids and destroyed_time = 0 ", "comment_ids", commentIds[0])
         .orderBy("created_time", "DESC")
         .toString();
   } else {
     return new Sql()
         .select("* ")
         .from(table)
         .where(
             "comment_id IN ($comment_ids)  and destroyed_time = 0 ",
             "comment_ids",
             StringHelper.join(commentIds, ","))
         .orderBy("created_time", "DESC")
         .toString();
   }
 }