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:com.unboundid.scim2.common.GenericScimResource.java

/**
 * Gets a list of Long from a generic SCIM resource.  If the path exists,
 * the JSON node at the path must be a list of Long.  If the path
 * does not exist, an empty list will be returned.
 *   <p>// ww w .jav a 2  s.  c o m
 *
 * For example:
 *   In a GenericScimResource (gsr) representing the following resource:
 * <pre><code>
 *   {
 *     "path1":[11, 13]
 *   }
 * </code></pre>
 *   <p>
 *
 *   getLongValueList(Path.fromString("path1"))
 *   returns a list containing 11, 13
 *   <p>
 *
 *   getLongValueList(Path.fromString("bogusPath"))
 *   returns an empty list
 *
 * @param path the path to get the value from.
 * @return the value at the path, or an empty list.
 * @throws ScimException thrown if an error occurs.
 */
public List<Long> getLongValueList(final Path path) throws ScimException {
    JsonNode valueNode = getValue(path);
    List<Long> values = new ArrayList<Long>();

    Iterator<JsonNode> iterator = valueNode.iterator();
    while (iterator.hasNext()) {
        values.add(iterator.next().longValue());
    }
    return values;
}

From source file:com.unboundid.scim2.common.GenericScimResource.java

/**
 * Gets a list of Date from a generic SCIM resource.  If the path exists,
 * the JSON node at the path must be a list of Date.  If the path
 * does not exist, an empty list will be returned.
 *   <p>//w  w  w  .  j a va  2 s  .  com
 *
 * For example:
 *   In a GenericScimResource (gsr) representing the following resource:
 * <pre><code>
 *   {
 *     "path1":["1970-04-20T17:54:47.542Z", "2000-04-20T17:54:47.542Z"]
 *   }
 * </code></pre>
 *   <p>
 *
 *   getDateValueList(Path.fromString("path1"))
 *   returns a list containing dates representing
 *       "1970-04-20T17:54:47.542Z", "2000-04-20T17:54:47.542Z"
 *   <p>
 *
 *   getDateValueList(Path.fromString("bogusPath"))
 *   returns an empty list
 *
 * @param path the path to get the value from.
 * @return the value at the path, or an empty list.
 * @throws ScimException thrown if an error occurs.
 */
public List<Date> getDateValueList(final Path path) throws ScimException {
    JsonNode valueNode = getValue(path);
    List<Date> values = new ArrayList<Date>();

    Iterator<JsonNode> iterator = valueNode.iterator();
    while (iterator.hasNext()) {
        values.add(GenericScimResource.getDateFromJsonNode(iterator.next()));
    }
    return values;
}

From source file:com.unboundid.scim2.common.GenericScimResource.java

/**
 * Gets a list of String from a generic SCIM resource.  If the path exists,
 * the JSON node at the path must be a list of String.  If the path
 * does not exist, an empty list will be returned.
 *   <p>/*from w  w  w .j ava2s .c o m*/
 *
 * For example:
 *   In a GenericScimResource (gsr) representing the following resource:
 * <pre><code>
 *   {
 *     "path1":["stringValue1", "stringValue2"]
 *   }
 * </code></pre>
 *   <p>
 *
 *   getStringValueList(Path.fromString("path1"))
 *   returns a list containing "stringValue1", "stringValue2"
 *   <p>
 *
 *   getStringValueList(Path.fromString("bogusPath"))
 *   returns an empty list
 *
 * @param path the path to get the value from.
 * @return the value at the path, or an empty list.
 * @throws ScimException thrown if an error occurs.
 */
public List<String> getStringValueList(final Path path) throws ScimException {
    JsonNode valueNode = getValue(path);
    List<String> values = new ArrayList<String>();

    Iterator<JsonNode> iterator = valueNode.iterator();
    while (iterator.hasNext()) {
        values.add(iterator.next().textValue());
    }
    return values;
}

From source file:com.unboundid.scim2.common.GenericScimResource.java

/**
 * Gets a list of Double from a generic SCIM resource.  If the path exists,
 * the JSON node at the path must be a list of Double.  If the path
 * does not exist, an empty list will be returned.
 *   <p>/* w w  w  .  ja v  a 2 s  . co  m*/
 *
 * For example:
 *   In a GenericScimResource (gsr) representing the following resource:
 * <pre><code>
 *   {
 *     "path1":[2.1, 2.2]
 *   }
 * </code></pre>
 *   <p>
 *
 *   getDoubleValueList(Path.fromString("path1"))
 *   returns a list containing 2.1, 2.2
 *   <p>
 *
 *   getDoubleValueList(Path.fromString("bogusPath"))
 *   returns an empty list
 *
 * @param path the path to get the value from.
 * @return the value at the path, or an empty list.
 * @throws ScimException thrown if an error occurs.
 */
public List<Double> getDoubleValueList(final Path path) throws ScimException {
    JsonNode valueNode = getValue(path);
    List<Double> values = new ArrayList<Double>();

    Iterator<JsonNode> iterator = valueNode.iterator();
    while (iterator.hasNext()) {
        values.add(iterator.next().doubleValue());
    }
    return values;
}

From source file:com.unboundid.scim2.common.GenericScimResource.java

/**
 * Gets a list of byte[] from a generic SCIM resource.  If the path exists,
 * the JSON node at the path must be a list of binary values.  If the path
 * does not exist, an empty list will be returned.
 *   <p>/* ww w. ja  v a 2 s .c o  m*/
 *
 * For example:
 *   In a GenericScimResource (gsr) representing the following resource:
 * <pre><code>
 *   {
 *     "path1":["AjIzLg==", "AjNjLp=="]
 *   }
 * </code></pre>
 *   <p>
 *
 *   getBinaryValueList(Path.fromString("path1"))
 *   returns a list containing the byte arrays decoded from
 *       "AjIzLg==", "AjNjLp=="
 *   <p>
 *
 *   getBinaryValueList(Path.fromString("bogusPath"))
 *   returns an empty list
 *
 * @param path the path to get the value from.
 * @return the value at the path, or an empty list.
 * @throws ScimException thrown if an error occurs.
 */
public List<byte[]> getBinaryValueList(final Path path) throws ScimException {
    JsonNode valueNode = getValue(path);
    List<byte[]> values = new ArrayList<byte[]>();

    Iterator<JsonNode> iterator = valueNode.iterator();
    while (iterator.hasNext()) {
        values.add(getBinaryForString(iterator.next().textValue()));
    }
    return values;
}

From source file:com.unboundid.scim2.common.GenericScimResource.java

/**
 * Gets a list of Boolean from a generic SCIM resource.  If the path exists,
 * the JSON node at the path must be a list of Boolean.  If the path
 * does not exist, an empty list will be returned.
 *   <p>/*from  w w  w  .j  ava  2s.co m*/
 *
 * For example:
 * <pre><code>
 *   In a GenericScimResource (gsr) representing the following resource:
 *   {
 *     "path1":[true, false]
 *   }
 * </code></pre>
 *   <p>
 *
 *   getBooleanValueList(Path.fromString("path1"))
 *   returns a list containing true, false
 *   <p>
 *
 *   getBooleanValueList(Path.fromString("bogusPath"))
 *   returns an empty list
 *
 * @param path the path to get the value from.
 * @return the value at the path, or an empty list.
 * @throws ScimException thrown if an error occurs.
 */
public List<Boolean> getBooleanValueList(final Path path) throws ScimException {
    JsonNode valueNode = getValue(path);
    List<Boolean> values = new ArrayList<Boolean>();

    Iterator<JsonNode> iterator = valueNode.iterator();
    while (iterator.hasNext()) {
        values.add(iterator.next().booleanValue());
    }
    return values;
}

From source file:com.unboundid.scim2.common.GenericScimResource.java

/**
 * Gets a list of Integer from a generic SCIM resource.  If the path exists,
 * the JSON node at the path must be a list of Integer.  If the path
 * does not exist, an empty list will be returned.
 *   <p>/*  ww  w . java2s .  c om*/
 *
 * For example:
 *   In a GenericScimResource (gsr) representing the following resource:
 * <pre><code>
 *   {
 *     "path1":[11, 13]
 *   }
 * </code></pre>
 *   <p>
 *
 *   getIntegerValueList(Path.fromString("path1"))
 *   returns a list containing 11, 13
 *   <p>
 *
 *   getIntegerValueList(Path.fromString("bogusPath"))
 *   returns an empty list
 *
 * @param path the path to get the value from.
 * @return the value at the path, or an empty list.
 * @throws ScimException thrown if an error occurs.
 */
public List<Integer> getIntegerValueList(final Path path) throws ScimException {
    JsonNode valueNode = getValue(path);
    List<Integer> values = new ArrayList<Integer>();

    Iterator<JsonNode> iterator = valueNode.iterator();
    while (iterator.hasNext()) {
        values.add(iterator.next().intValue());
    }
    return values;
}

From source file:com.unboundid.scim2.common.GenericScimResource.java

/**
 * Gets a list of URI from a generic SCIM resource.  If the path exists,
 * the JSON node at the path must be a list of URI.  If the path
 * does not exist, an empty list will be returned.
 *   <p>/*from   ww  w . j  a v a2s  .c o m*/
 *
 * For example:
 *   In a GenericScimResource (gsr) representing the following resource:
 * <pre><code>
 *   {
 *     "path1":
 *     [
 *         "http://localhost:8080/uri/One", "http://localhost:8080/uri/Two"
 *     ]
 *   }
 * </code></pre>
 *   <p>
 *
 *   getURIValueList(Path.fromString("path1"))
 *   returns a list containing
 *       "http://localhost:8080/uri/One", "http://localhost:8080/uri/Two"
 *   <p>
 *
 *   getURIValueList(Path.fromString("bogusPath"))
 *   returns an empty list
 *   <p>
 *
 * @param path the path to get the value from.
 * @return the value at the path, or an empty list.
 * @throws ScimException thrown if an error occurs.
 */
public List<URI> getURIValueList(final Path path) throws ScimException {
    try {
        JsonNode valueNode = getValue(path);
        List<URI> values = new ArrayList<URI>();

        Iterator<JsonNode> iterator = valueNode.iterator();
        while (iterator.hasNext()) {
            String uriString = iterator.next().textValue();
            values.add(new URI(uriString));
        }
        return values;
    } catch (URISyntaxException ex) {
        throw new ServerErrorException(ex.getMessage());
    }
}

From source file:org.activiti.rest.api.history.HistoricDetailCollectionResourceTest.java

/**
 * Test querying historic detail. /*from   w  w  w  .  j a  v a 2 s . c  o  m*/
 * GET history/historic-detail
 */
@Deployment
public void testQueryDetail() throws Exception {
    HashMap<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("stringVar", "Azerty");
    processVariables.put("intVar", 67890);
    processVariables.put("booleanVar", false);
    processVariables.put("byteVar", "test".getBytes());

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess",
            processVariables);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "taskVariable", "test");

    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
            processVariables);

    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_DETAIL);

    assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance.getId(), 5, "stringVar",
            "Azerty");
    assertResultsPresentInDataResponse(url + "?taskId=" + task.getId(), 1, "taskVariable", "test");
    assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance2.getId(), 4, "intVar",
            67890);
    assertResultsPresentInDataResponse(
            url + "?processInstanceId=" + processInstance2.getId() + "&selectOnlyVariableUpdates=true", 4,
            "booleanVar", false);

    ClientResource client = getAuthenticatedClient(url + "?processInstanceId=" + processInstance2.getId());
    Representation response = client.get();

    // Check status and size
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
    JsonNode dataNode = objectMapper.readTree(response.getStream()).get("data");

    boolean byteVarFound = false;
    Iterator<JsonNode> it = dataNode.iterator();
    while (it.hasNext()) {
        JsonNode variableNode = it.next().get("variable");
        String name = variableNode.get("name").textValue();
        if ("byteVar".equals(name)) {
            byteVarFound = true;
            String valueUrl = variableNode.get("valueUrl").textValue();
            client.release();
            client = new ClientResource(valueUrl);
            client.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "kermit", "kermit");
            response = client.get();
            assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
            byte[] varInput = IOUtils.toByteArray(response.getStream());
            assertEquals("test", new String(varInput));
            break;
        }
    }
    assertTrue(byteVarFound);
}