Example usage for com.fasterxml.jackson.databind JsonNode iterator

List of usage examples for com.fasterxml.jackson.databind JsonNode iterator

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode iterator.

Prototype

public final Iterator<JsonNode> iterator() 

Source Link

Usage

From source file:org.flowable.rest.service.api.history.HistoricTaskInstanceCollectionResourceTest.java

protected void assertResultsPresentInDataResponse(String url, int numberOfResultsExpected,
        String... expectedTaskIds) throws JsonProcessingException, IOException {

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

    // Check status and size
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);//from ww w .ja  v a 2  s.co m
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (expectedTaskIds != null) {
        List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedTaskIds));
        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());
    }
}

From source file:org.flowable.rest.service.api.history.HistoricTaskInstanceQueryResourceTest.java

protected void assertResultsPresentInPostDataResponse(String url, ObjectNode body, int numberOfResultsExpected,
        String... expectedTaskIds) throws JsonProcessingException, IOException {
    // Do the actual call
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url);
    httpPost.setEntity(new StringEntity(body.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK);
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);/* ww  w .ja  v a 2  s .  co m*/
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (expectedTaskIds != null) {
        List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedTaskIds));
        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());
    }
}

From source file:org.opencb.opencga.storage.variant.sqlite.VariantSqliteDBAdaptor.java

private String processGeneList(String genes) {
    System.out.println("genes = " + genes);
    List<String> list = new ArrayList<>();

    //        Client client = ClientBuilder.newClient();
    //        WebTarget webTarget = client.target("http://ws.bioinfo.cipf.es/cellbase/rest/latest/hsa/feature/gene/");

    Client client = Client.create();/*from  w w w  .ja v  a  2  s  .c  om*/
    WebResource webResource = client
            .resource("http://ws.bioinfo.cipf.es/cellbase/rest/latest/hsa/feature/gene/");

    ObjectMapper mapper = new ObjectMapper();

    //        Response response = webTarget.path(genes).path("info").queryParam("of", "json").request().get();
    String response = webResource.path(genes).path("info").queryParam("of", "json").get(String.class);
    String data = response.toString();

    System.out.println("response = " + response);

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

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

                aux = node.iterator();
                while (aux.hasNext()) {
                    JsonNode auxNode = aux.next();
                    sb = new StringBuilder("(");

                    System.out.println(
                            "auxNode.get(\"chromosome\").asText() = " + auxNode.get("chromosome").asText());

                    sb.append("variant_stats.chromosome='").append(auxNode.get("chromosome").asText())
                            .append("' AND ");
                    sb.append("variant_stats.position>=").append(auxNode.get("start")).append(" AND ");
                    sb.append("variant_stats.position<=").append(auxNode.get("end")).append(" )");

                    list.add(sb.toString());
                }

            }
        }

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

    String res = "(" + StringUtils.join(list, " OR ") + ")";

    return res;

}

From source file:org.openiot.security.client.AuthorizationManager.java

protected Map<String, Set<Permission>> getAuthorizationInfoInternal(final OAuthorizationCredentials credentials,
        final String targetClientId) throws AccessTokenExpiredException {
    Map<String, Set<Permission>> map = new HashMap<String, Set<Permission>>();

    final String body = sendRequestForPermissions(credentials, targetClientId);
    JsonNode json = JsonHelper.getFirstNode(body);
    if (json != null) {
        JsonNode errorNode = json.get(ERROR);
        if (errorNode != null) {
            String errorMsg = errorNode.asText();
            logger.info("Error returned: {}", errorMsg);
            if (errorMsg.startsWith(EXPIRED_ACCESS_TOKEN)) {
                String token = credentials.getAccessToken();
                if (errorMsg.endsWith("_for_caller"))
                    token = credentials.getCallerCredentials().getAccessToken();
                else if (errorMsg.endsWith("_for_user"))
                    if (credentials.getCallerCredentials().getCallerCredentials() == null)
                        token = credentials.getCallerCredentials().getAccessToken();
                    else
                        token = credentials.getCallerCredentials().getCallerCredentials().getAccessToken();
                throw new AccessTokenExpiredException(token, errorMsg);
            }//  w w w .  j a  v a2  s . co  m
        } else {
            json = json.get(ROLE_PERMISSIONS);
            if (json != null) {
                final Iterator<JsonNode> nodes = json.iterator();
                while (nodes.hasNext()) {
                    for (Iterator<Entry<String, JsonNode>> fields = nodes.next().fields(); fields.hasNext();) {
                        Entry<String, JsonNode> next = fields.next();

                        logger.debug("next role: {}", next.getKey());

                        final HashSet<Permission> permissionsSet = new HashSet<Permission>();
                        map.put(next.getKey(), permissionsSet);
                        Iterator<JsonNode> permIter = next.getValue().iterator();
                        while (permIter.hasNext()) {
                            json = permIter.next();
                            String permission = json.asText();
                            permissionsSet.add(permissionResolver.resolvePermission(permission));
                            logger.debug("next permission: {}", permission);
                        }
                    }
                }
            }
        }
    }

    return map;
}