public FetchNotificationsResult a(
     FetchNotificationsParams paramFetchNotificationsParams, ApiResponse paramApiResponse) {
   paramApiResponse.g();
   FqlResultHelper localFqlResultHelper = new FqlResultHelper(paramApiResponse.c());
   JsonNode localJsonNode1 = localFqlResultHelper.a("notifications");
   JsonNode localJsonNode2 = localFqlResultHelper.a("profiles");
   ImmutableList.Builder localBuilder = ImmutableList.e();
   Iterator localIterator1 = localJsonNode1.iterator();
   while (localIterator1.hasNext()) {
     JsonNode localJsonNode4 = (JsonNode) localIterator1.next();
     localBuilder.b(
         FacebookNotification.a(FBJsonFactory.a.createJsonParser(localJsonNode4.toString())));
   }
   ImmutableMap.Builder localBuilder1 = ImmutableMap.k();
   Iterator localIterator2 = localJsonNode2.iterator();
   while (localIterator2.hasNext()) {
     JsonNode localJsonNode3 = (JsonNode) localIterator2.next();
     FacebookProfile localFacebookProfile =
         FacebookProfile.a(FBJsonFactory.a.createJsonParser(localJsonNode3.toString()));
     localBuilder1.b(Long.valueOf(localFacebookProfile.mId), localFacebookProfile);
   }
   return new FetchNotificationsResult(
       DataFreshnessResult.FROM_SERVER,
       localBuilder.b(),
       localBuilder1.b(),
       System.currentTimeMillis());
 }
Esempio n. 2
0
  /**
   * Map path segments to tree nodes, each segment to a set of nodes of a same level from the root
   *
   * @param pathSegments
   * @param treeRoot
   * @return
   * @throws PathException
   */
  public static Map<String, List<JsonNode>> mapPath2Tree(
      List<String> pathSegments, JsonNode treeRoot) throws PathException {

    if (treeRoot == null || !treeRoot.has(pathSegments.get(0))) {
      // Failed from root
      return null;
    }
    Map<String, List<JsonNode>> queryMap = new HashMap<String, List<JsonNode>>();
    for (String s : pathSegments) {
      queryMap.put(s, new ArrayList<JsonNode>());
    }

    for (int i = 0; i < pathSegments.size(); i++) {
      String nodeName = pathSegments.get(i);
      List<JsonNode> ret = new ArrayList<JsonNode>();
      if (i == 0) {
        JsonNode childs = treeRoot.get(nodeName);
        if (childs != null) {
          if (childs.isArray()) {
            Iterator<JsonNode> iter = childs.iterator();
            while (iter.hasNext()) {
              ret.add(iter.next());
            }
          } else {
            ret.add(childs);
          }
        }
      } else {
        // parent node
        List<JsonNode> parents = queryMap.get(pathSegments.get(i - 1));
        for (JsonNode parent : parents) {
          JsonNode childs = parent.get(nodeName);
          if (childs != null) {
            if (childs.isArray()) {
              Iterator<JsonNode> iter = childs.iterator();
              while (iter.hasNext()) {
                ret.add(iter.next());
              }
            } else {
              ret.add(childs);
            }
          }
        }
      }
      if (ret.size() > 0) {
        queryMap.get(nodeName).addAll(ret);
      } else if (i < pathSegments.size() - 1) {
        // not found in the middle of the path
        return null;
      }
    }

    return queryMap;
  }
    @Override
    public AckArgs deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
      List<Object> args = new ArrayList<Object>();
      AckArgs result = new AckArgs(args);

      ObjectMapper mapper = (ObjectMapper) jp.getCodec();
      JsonNode root = mapper.readTree(jp);
      AckCallback<?> callback = currentAckClass.get();
      Iterator<JsonNode> iter = root.iterator();
      int i = 0;
      while (iter.hasNext()) {
        Object val;

        Class<?> clazz = callback.getResultClass();
        if (callback instanceof MultiTypeAckCallback) {
          MultiTypeAckCallback multiTypeAckCallback = (MultiTypeAckCallback) callback;
          clazz = multiTypeAckCallback.getResultClasses()[i];
        }

        JsonNode arg = iter.next();
        if (arg.isTextual() || arg.isBoolean()) {
          clazz = Object.class;
        }

        val = mapper.treeToValue(arg, clazz);
        args.add(val);
        i++;
      }
      return result;
    }
  protected void assertResultsPresentInPostDataResponseWithStatusCheck(
      String url, ObjectNode body, int expectedStatusCode, String... expectedResourceIds)
      throws JsonProcessingException, IOException {
    int numberOfResultsExpected = 0;
    if (expectedResourceIds != null) {
      numberOfResultsExpected = expectedResourceIds.length;
    }

    // Do the actual call
    HttpPost post = new HttpPost(SERVER_URL_PREFIX + url);
    post.setEntity(new StringEntity(body.toString()));
    HttpResponse response = executeHttpRequest(post, expectedStatusCode);

    if (expectedStatusCode == HttpStatus.SC_OK) {
      // Check status and size
      JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
      JsonNode dataNode = rootNode.get("data");
      assertEquals(numberOfResultsExpected, dataNode.size());

      // Check presence of ID's
      if (expectedResourceIds != null) {
        List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedResourceIds));
        Iterator<JsonNode> it = dataNode.iterator();
        while (it.hasNext()) {
          String id = it.next().get("id").textValue();
          toBeFound.remove(id);
        }
        assertTrue(
            "Not all entries have been found in result, missing: "
                + StringUtils.join(toBeFound, ", "),
            toBeFound.isEmpty());
      }
    }
  }
Esempio n. 5
0
  private static void testJson() {
    String json1 = "[\"hello\"]";
    JsonNode jsonNode = Json.parse(json1);
    Json.stringify(jsonNode);
    System.out.println(jsonNode.toString());
    System.out.println(Json.stringify(jsonNode));
    ObjectNode jsonObject = Json.newObject();
    jsonObject.put("hello", jsonNode);
    jsonObject.put("hello", 56);
    System.out.println(jsonObject.toString());
    List<Object> strings = new ArrayList<Object>();
    strings.add("hello");
    strings.add("world");
    jsonObject.put("test", Json.toJson(strings));
    System.out.println(jsonObject.toString());
    jsonObject.put("test2", Json.toJson("string"));
    jsonObject.put("test2", Json.toJson("sshshhs"));
    List<String> list = new ArrayList<String>();
    list.add("hello me");
    // ObjectNode objectNode = Json.newObject();

    jsonObject.put("me", Json.toJson(list));
    System.out.println(jsonObject.toString());
    System.out.println(jsonObject.size());
    System.out.println(jsonObject.get("test").isArray());
    JsonNode jsonNode1 = jsonObject.get("test");
    Iterator iterator = jsonNode1.iterator();
    while ((iterator.hasNext())) {
      System.out.println(iterator.next());
    }
    Iterator<JsonNode> iterator1 = jsonObject.iterator();
    while (iterator1.hasNext()) {
      System.out.println("----------------------");
      JsonNode jsonNode2 = iterator1.next();
      if (jsonNode2.isArray()) {
        Iterator iterator2 = jsonNode2.iterator();
        while ((iterator2.hasNext())) {
          System.out.println(iterator2.next());
        }
      } else {
        if (jsonNode2.isTextual()) {
          System.out.println("String:" + jsonNode2);
        }
      }
    }
  }
  private BasicDBList processGeneList(String genes) {

    BasicDBList list = new BasicDBList();

    Client wsRestClient = Client.create();
    WebResource webResource =
        wsRestClient.resource("http://ws.bioinfo.cipf.es/cellbase/rest/latest/hsa/feature/gene/");

    ObjectMapper mapper = new ObjectMapper();

    String response =
        webResource.path(genes).path("info").queryParam("of", "json").get(String.class);

    try {
      JsonNode actualObj = mapper.readTree(response);
      Iterator<JsonNode> it = actualObj.iterator();
      Iterator<JsonNode> aux;

      while (it.hasNext()) {
        JsonNode node = it.next();
        if (node.isArray()) {

          aux = node.iterator();
          while (aux.hasNext()) {
            JsonNode auxNode = aux.next();

            DBObject regionClause = new BasicDBObject("chr", auxNode.get("chromosome").asText());
            regionClause.put(
                "pos",
                new BasicDBObject("$gte", auxNode.get("start").asInt())
                    .append("$lte", auxNode.get("end").asInt()));
            list.add(regionClause);
          }
        }
      }

    } catch (IOException e) {
      e.printStackTrace();
    }

    return list;
  }
 private JsonNode createProduct(JsonNode node, String userName) throws Exception {
   ObjectMapper om = new ObjectMapper();
   ArrayNode anode = om.createArrayNode();
   if (node.isArray()) {
     Iterator<JsonNode> nodeiterator = node.iterator();
     while (nodeiterator.hasNext()) {
       ProductBack cbase = om.convertValue(nodeiterator.next(), ProductBack.class);
       anode.add(createProductToDb(om, cbase, userName));
     }
   } else {
     ProductBack cbase = JSON.parseObject(node.asText(), ProductBack.class);
     anode.add(createProductToDb(om, cbase, userName));
   }
   return anode;
 }
  protected void assertResultsPresentInDataResponse(
      String url, int numberOfResultsExpected, String... expectedActivityIds)
      throws JsonProcessingException, IOException {
    // Do the actual call
    CloseableHttpResponse response =
        executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK);
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);
    Assert.assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (expectedActivityIds != null) {
      List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedActivityIds));
      Iterator<JsonNode> it = dataNode.iterator();
      while (it.hasNext()) {
        String activityId = it.next().get("activityId").textValue();
        toBeFound.remove(activityId);
      }
      Assert.assertTrue(
          "Not all entries have been found in result, missing: "
              + StringUtils.join(toBeFound, ", "),
          toBeFound.isEmpty());
    }
  }
  /**
   * Checks if the returned "data" array (child-node of root-json node returned by invoking a GET on
   * the given url) contains entries with the given ID's.
   */
  protected void assertResultsPresentInDataResponse(String url, String... expectedResourceIds)
      throws JsonProcessingException, IOException {
    int numberOfResultsExpected = expectedResourceIds.length;

    // Do the actual call
    HttpResponse response =
        executeHttpRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK);

    // Check status and size
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedResourceIds));
    Iterator<JsonNode> it = dataNode.iterator();
    while (it.hasNext()) {
      String id = it.next().get("id").textValue();
      toBeFound.remove(id);
    }
    assertTrue(
        "Not all process-definitions have been found in result, missing: "
            + StringUtils.join(toBeFound, ", "),
        toBeFound.isEmpty());
  }
  public SolverSimpleQuery(String query) {

    try {
      season = numberOfSeasons = teamID = numberOfSeasons = leagueID = -1;
      superEff = false;
      solver = selectedMethod = leagueName = teamName = null;
      selectedInputs = new ArrayList<>();
      selectedInputsNames = new ArrayList<>();
      selectedOutputs = new ArrayList<>();
      selectedOutputsNames = new ArrayList<>();

      ObjectMapper mapper = new ObjectMapper();

      JsonNode rootNode = mapper.readTree(query);
      if (rootNode.has("superEff")) superEff = rootNode.path("superEff").asBoolean(true);
      if (rootNode.has("inputOriented")) inputOriented = rootNode.path("inputOriented").asBoolean();
      if (rootNode.has("season")) season = rootNode.path("season").asInt();
      if (rootNode.has("numberOfTeams")) numberOfTeams = rootNode.path("numberOfTeams").asInt();
      if (rootNode.has("numberOfSeasons"))
        numberOfSeasons = rootNode.path("numberOfSeasons").asInt(1);
      if (rootNode.has("teamID")) teamID = rootNode.path("teamID").asInt();
      if (rootNode.has("leagueID")) leagueID = rootNode.path("leagueID").asInt();
      if (rootNode.has("solver")) solver = rootNode.path("solver").asText();
      if (rootNode.has("selectedMethod")) selectedMethod = rootNode.path("selectedMethod").asText();
      if (rootNode.has("leagueName")) leagueName = rootNode.path("leagueName").asText();
      if (rootNode.has("teamName")) teamName = rootNode.path("teamName").asText();
      if (rootNode.has("selectedInputs")) {
        JsonNode selectedInputs = rootNode.path("selectedInputs");
        Iterator<JsonNode> iterator = selectedInputs.iterator();
        while (iterator.hasNext()) {
          JsonNode input = iterator.next();
          this.selectedInputs.add(input.asInt());
        }
      }
      if (rootNode.has("selectedInputsNames")) {
        JsonNode selectedInputsNames = rootNode.path("selectedInputsNames");
        Iterator<JsonNode> iterator = selectedInputsNames.iterator();
        while (iterator.hasNext()) {
          JsonNode input = iterator.next();
          this.selectedInputsNames.add(input.asText());
        }
      }
      if (rootNode.has("selectedOutputs")) {
        JsonNode selectedOutputs = rootNode.path("selectedOutputs");
        Iterator<JsonNode> iterator = selectedOutputs.iterator();
        while (iterator.hasNext()) {
          JsonNode input = iterator.next();
          this.selectedOutputs.add(input.asInt());
        }
      }
      if (rootNode.has("selectedOutputsNames")) {
        JsonNode selectedOutputsNames = rootNode.path("selectedOutputsNames");
        Iterator<JsonNode> iterator = selectedOutputsNames.iterator();
        while (iterator.hasNext()) {
          JsonNode input = iterator.next();
          this.selectedOutputsNames.add(input.asText());
        }
      }
      // System.out.println("]");
    } catch (JsonParseException e) {
      e.printStackTrace();
    } catch (JsonMappingException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Esempio n. 11
0
 private Map<String, Integer> extractSectionsList(JsonNode sections) {
   JsonNode parseNode = sections.get(PARSE);
   JsonNode sectionsNode = parseNode.get(SECTIONS);
   return collectSections(sectionsNode.iterator());
 }