Example usage for com.fasterxml.jackson.databind.node ArrayNode add

List of usage examples for com.fasterxml.jackson.databind.node ArrayNode add

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ArrayNode add.

Prototype

public ArrayNode add(JsonNode paramJsonNode) 

Source Link

Usage

From source file:org.activiti.rest.service.api.runtime.ExecutionCollectionResourceTest.java

/**
 * Test signalling all executions with variables
 */// w ww .  ja v a  2 s  . co m
@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" })
public void testSignalEventExecutionsWithvariables() throws Exception {
    Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne");
    assertNotNull(signalExecution);

    ArrayNode variables = objectMapper.createArrayNode();
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "signalEventReceived");
    requestNode.put("signalName", "alert");
    requestNode.put("variables", variables);

    ObjectNode varNode = objectMapper.createObjectNode();
    variables.add(varNode);
    varNode.put("name", "myVar");
    varNode.put("value", "Variable set when signal event is receieved");

    Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
    assertNotNull(waitingExecution);

    // Sending signal event causes the execution to end (scope-execution for
    // the catching event)
    HttpPut httpPut = new HttpPut(
            SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_NO_CONTENT));

    // Check if process is moved on to the other wait-state
    waitingExecution = runtimeService.createExecutionQuery().activityId("anotherWaitState").singleResult();
    assertNotNull(waitingExecution);

    Map<String, Object> vars = runtimeService.getVariables(waitingExecution.getId());
    assertEquals(1, vars.size());

    assertEquals("Variable set when signal event is receieved", vars.get("myVar"));
}

From source file:org.flowable.rest.service.api.runtime.ExecutionCollectionResourceTest.java

/**
 * Test signalling all executions with variables
 *///from w ww. j a  v  a2  s . co  m
@Deployment(resources = {
        "org/flowable/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" })
public void testSignalEventExecutionsWithvariables() throws Exception {
    Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne");
    assertNotNull(signalExecution);

    ArrayNode variables = objectMapper.createArrayNode();
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "signalEventReceived");
    requestNode.put("signalName", "alert");
    requestNode.set("variables", variables);

    ObjectNode varNode = objectMapper.createObjectNode();
    variables.add(varNode);
    varNode.put("name", "myVar");
    varNode.put("value", "Variable set when signal event is received");

    Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
    assertNotNull(waitingExecution);

    // Sending signal event causes the execution to end (scope-execution for
    // the catching event)
    HttpPut httpPut = new HttpPut(
            SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_NO_CONTENT));

    // Check if process is moved on to the other wait-state
    waitingExecution = runtimeService.createExecutionQuery().activityId("anotherWaitState").singleResult();
    assertNotNull(waitingExecution);

    Map<String, Object> vars = runtimeService.getVariables(waitingExecution.getId());
    assertEquals(1, vars.size());

    assertEquals("Variable set when signal event is received", vars.get("myVar"));
}

From source file:neo4play.Neo4jTest.java

@Test
public void buildStatementsTest() {
    // JSON node containing statements (to execute inside of a
    // transaction) should look like this:

    // {//from  w w  w.j  a v a2 s.c o  m
    //     "statements": [
    //         {
    //             "statement": "CREATE (n {props}) RETURN n",
    //             "parameters": {
    //                 "props": {
    //                     "prop1": "val1",
    //                     "prop2": "val2",
    //                 }
    //             }
    //         }
    //     ]
    // }

    ObjectNode statements = Json.newObject();
    ArrayNode statementList = JsonNodeFactory.instance.arrayNode();
    ObjectNode statement = Json.newObject();
    String query = "CREATE (n {props}) RETURN n";
    ObjectNode parameters = Json.newObject();
    ObjectNode props = Json.newObject();
    props.put("prop1", "val1");
    props.put("prop2", "val2");
    parameters.put("props", props);
    statement.put("statement", query);
    statement.put("parameters", parameters);
    statementList.add(statement);
    statements.put("statements", statementList);

    assert (Neo4j.buildStatements(query, props).equals(statements));
}

From source file:org.opendaylight.sfc.sbrest.json.SffExporterFactory.java

private ObjectNode getOvsBridgeObjectNode(OvsBridge ovsBridge) {
    if (ovsBridge == null) {
        return null;
    }/*  www . j a  va  2  s  . c om*/

    ObjectNode ovsBridgeNode = mapper.createObjectNode();
    ovsBridgeNode.put(_BRIDGE_NAME, ovsBridge.getBridgeName());

    try {
        if (ovsBridge.getUuid() != null && !ovsBridge.getUuid().getValue().isEmpty()) {
            ovsBridgeNode.put(_UUID, ovsBridge.getUuid().getValue());
        }
    } catch (IllegalArgumentException e) {
        LOG.error("Supplied value does not match any of the permitted UUID patterns");
    }

    if (ovsBridge.getExternalIds() != null) {
        ArrayNode externalIdsArray = mapper.createArrayNode();
        for (ExternalIds externalId : ovsBridge.getExternalIds()) {
            ObjectNode externalIdNode = mapper.createObjectNode();
            externalIdNode.put(_NAME, externalId.getName());
            externalIdNode.put(_VALUE, externalId.getValue());
            externalIdsArray.add(externalIdNode);
        }
        ovsBridgeNode.putArray(_EXTERNAL_IDS).addAll(externalIdsArray);
    }

    return ovsBridgeNode;
}

From source file:com.github.reinert.jjschema.v1.PropertyWrapper.java

protected void processAttributes(ObjectNode node, AccessibleObject accessibleObject) {
    final Attributes attributes = accessibleObject.getAnnotation(Attributes.class);
    if (attributes != null) {
        //node.put("$schema", SchemaVersion.DRAFTV4.getLocation().toString());
        node.remove("$schema");
        if (!attributes.id().isEmpty()) {
            node.put("id", attributes.id());
        }//from  w  w  w  . j a v a2s  .com
        if (!attributes.description().isEmpty()) {
            node.put("description", attributes.description());
        }
        if (!attributes.pattern().isEmpty()) {
            node.put("pattern", attributes.pattern());
        }
        if (!attributes.title().isEmpty()) {
            node.put("title", attributes.title());
        }
        if (attributes.maximum() > -1) {
            node.put("maximum", attributes.maximum());
        }
        if (attributes.exclusiveMaximum()) {
            node.put("exclusiveMaximum", true);
        }
        if (attributes.minimum() > -1) {
            node.put("minimum", attributes.minimum());
        }
        if (attributes.exclusiveMinimum()) {
            node.put("exclusiveMinimum", true);
        }
        if (attributes.enums().length > 0) {
            ArrayNode enumArray = node.putArray("enum");
            String[] enums = attributes.enums();
            for (String v : enums) {
                enumArray.add(v);
            }
        }
        if (attributes.uniqueItems()) {
            node.put("uniqueItems", true);
        }
        if (attributes.minItems() > 0) {
            node.put("minItems", attributes.minItems());
        }
        if (attributes.maxItems() > -1) {
            node.put("maxItems", attributes.maxItems());
        }
        if (attributes.multipleOf() > 0) {
            node.put("multipleOf", attributes.multipleOf());
        }
        if (attributes.minLength() > 0) {
            node.put("minLength", attributes.minLength());
        }
        if (attributes.maxLength() > -1) {
            node.put("maxLength", attributes.maxLength());
        }
        if (attributes.required()) {
            setRequired(true);
        }
        if (attributes.readonly()) {
            node.put("readonly", true);
        }
    }
}

From source file:org.unl.cse.netgroup.rest.OpenSecMonitorWebResource.java

/**
 * List TCP Transmission Statistics for all Devices.
 *
 * @return 200 OK with tcp transmission statistics
 *//*from w w  w .j  a v  a2  s .c o m*/
@GET
@Path("tcpinfo")
public Response getTcpTwo() {
    ObjectNode root = mapper().createObjectNode();
    root.put("measurement", "gridftp-transfers");

    ObjectNode tagContents = mapper().createObjectNode();
    tagContents.put("host", "server01");
    tagContents.put("region", "us-midwest");

    root.set("tags", tagContents);
    ObjectNode fieldContents = mapper().createObjectNode();

    TcpProcessorService processor = get(TcpProcessorService.class);
    HashMultimap<DeviceId, TcpRecord> map = processor.getTcpHashMultimap();

    for (DeviceId id : map.keys()) {
        ObjectNode switchesContents = mapper().createObjectNode();
        ObjectNode deviceContents = mapper().createObjectNode();

        for (Map.Entry<DeviceId, Collection<TcpRecord>> entry : map.asMap().entrySet()) {
            DeviceId d = entry.getKey();
            Collection<TcpRecord> v = entry.getValue();
            ArrayNode deviceContentArray = deviceContents.putArray("Devices");
            for (TcpRecord t : v) {
                deviceContentArray.add(String.valueOf(t.getSrc()));
                deviceContentArray.add(String.valueOf(t.getDst()));
                deviceContentArray.add(String.valueOf(t.getPktCount()));
                deviceContentArray.add(String.valueOf(t.getByteCount()));
            }

        }
        switchesContents.set(String.valueOf(id), deviceContents);
        fieldContents.set("Devices", switchesContents);
    }

    fieldContents.put("field1", 9);
    fieldContents.put("field2", 0.64);
    root.set("fields", fieldContents);

    return ok(root).build();
}

From source file:org.apache.streams.elasticsearch.processor.PercolateTagProcessor.java

@Override
public List<StreamsDatum> process(StreamsDatum entry) {

    List<StreamsDatum> result = Lists.newArrayList();

    String json;/* w  w w . j a v  a2s  . c  o  m*/
    ObjectNode node;
    // first check for valid json
    if (entry.getDocument() instanceof String) {
        json = (String) entry.getDocument();
        try {
            node = (ObjectNode) mapper.readTree(json);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    } else if (entry.getDocument() instanceof ObjectNode) {
        node = (ObjectNode) entry.getDocument();
        try {
            json = mapper.writeValueAsString(node);
        } catch (JsonProcessingException e) {
            LOGGER.warn("Invalid datum: ", node);
            return null;
        }
    } else {
        LOGGER.warn("Incompatible document type: ", entry.getDocument().getClass());
        return null;
    }

    StringBuilder percolateRequestJson = new StringBuilder();
    percolateRequestJson.append("{ \"doc\": ");
    percolateRequestJson.append(json);
    //percolateRequestJson.append("{ \"content\" : \"crazy good shit\" }");
    percolateRequestJson.append("}");

    PercolateRequestBuilder request;
    PercolateResponse response;

    try {
        LOGGER.trace("Percolate request json: {}", percolateRequestJson.toString());
        request = manager.getClient().preparePercolate().setIndices(config.getIndex())
                .setDocumentType(config.getType()).setSource(percolateRequestJson.toString());
        LOGGER.trace("Percolate request: {}", mapper.writeValueAsString(request.request()));
        response = request.execute().actionGet();
        LOGGER.trace("Percolate response: {} matches", response.getMatches().length);
    } catch (Exception e) {
        LOGGER.warn("Percolate exception: {}", e.getMessage());
        return null;
    }

    ArrayNode tagArray = JsonNodeFactory.instance.arrayNode();

    Iterator<PercolateResponse.Match> matchIterator = response.iterator();
    while (matchIterator.hasNext()) {
        tagArray.add(matchIterator.next().getId().string());
    }

    LOGGER.trace("Percolate matches: {}", tagArray);

    Activity activity = mapper.convertValue(node, Activity.class);

    appendMatches(tagArray, activity);

    entry.setDocument(activity);

    result.add(entry);

    return result;

}

From source file:org.activiti.rest.service.api.runtime.process.ProcessDefinitionPropertiesResource.java

@Get
public ObjectNode getStartFormProperties() {
    if (authenticate() == false)
        return null;

    String processDefinitionId = (String) getRequest().getAttributes().get("processDefinitionId");
    StartFormData startFormData = ActivitiUtil.getFormService().getStartFormData(processDefinitionId);

    ObjectNode responseJSON = new ObjectMapper().createObjectNode();

    ArrayNode propertiesJSON = new ObjectMapper().createArrayNode();

    if (startFormData != null) {

        List<FormProperty> properties = startFormData.getFormProperties();

        for (FormProperty property : properties) {
            ObjectNode propertyJSON = new ObjectMapper().createObjectNode();
            propertyJSON.put("id", property.getId());
            propertyJSON.put("name", property.getName());

            if (property.getValue() != null) {
                propertyJSON.put("value", property.getValue());
            } else {
                propertyJSON.putNull("value");
            }/*from  w  ww .j  av a 2  s  .co  m*/

            if (property.getType() != null) {
                propertyJSON.put("type", property.getType().getName());

                if (property.getType() instanceof EnumFormType) {
                    @SuppressWarnings("unchecked")
                    Map<String, String> valuesMap = (Map<String, String>) property.getType()
                            .getInformation("values");
                    if (valuesMap != null) {
                        ArrayNode valuesArray = new ObjectMapper().createArrayNode();
                        propertyJSON.put("enumValues", valuesArray);

                        for (String key : valuesMap.keySet()) {
                            ObjectNode valueJSON = new ObjectMapper().createObjectNode();
                            valueJSON.put("id", key);
                            valueJSON.put("name", valuesMap.get(key));
                            valuesArray.add(valueJSON);
                        }
                    }
                }

            } else {
                propertyJSON.put("type", "String");
            }

            propertyJSON.put("required", property.isRequired());
            propertyJSON.put("readable", property.isReadable());
            propertyJSON.put("writable", property.isWritable());

            propertiesJSON.add(propertyJSON);
        }
    }

    responseJSON.put("data", propertiesJSON);
    return responseJSON;
}

From source file:org.activiti.rest.service.api.legacy.TaskPropertiesResource.java

@Get
public ObjectNode getTaskProperties() {
    if (authenticate() == false)
        return null;
    String taskId = (String) getRequest().getAttributes().get("taskId");
    TaskFormData taskFormData = ActivitiUtil.getFormService().getTaskFormData(taskId);

    ObjectNode responseJSON = new ObjectMapper().createObjectNode();

    ArrayNode propertiesJSON = new ObjectMapper().createArrayNode();

    if (taskFormData != null) {

        List<FormProperty> properties = taskFormData.getFormProperties();

        for (FormProperty property : properties) {
            ObjectNode propertyJSON = new ObjectMapper().createObjectNode();
            propertyJSON.put("id", property.getId());
            propertyJSON.put("name", property.getName());

            if (property.getValue() != null) {
                propertyJSON.put("value", property.getValue());
            } else {
                propertyJSON.putNull("value");
            }/*from www .  ja  va  2s.  com*/

            if (property.getType() != null) {
                propertyJSON.put("type", property.getType().getName());

                if (property.getType() instanceof EnumFormType) {
                    @SuppressWarnings("unchecked")
                    Map<String, String> valuesMap = (Map<String, String>) property.getType()
                            .getInformation("values");
                    if (valuesMap != null) {
                        ArrayNode valuesArray = new ObjectMapper().createArrayNode();
                        propertyJSON.put("enumValues", valuesArray);

                        for (String key : valuesMap.keySet()) {
                            ObjectNode valueJSON = new ObjectMapper().createObjectNode();
                            valueJSON.put("id", key);
                            valueJSON.put("name", valuesMap.get(key));
                            valuesArray.add(valueJSON);
                        }
                    }
                }

            } else {
                propertyJSON.put("type", "String");
            }

            propertyJSON.put("required", property.isRequired());
            propertyJSON.put("readable", property.isReadable());
            propertyJSON.put("writable", property.isWritable());

            propertiesJSON.add(propertyJSON);
        }
    }

    responseJSON.put("data", propertiesJSON);

    return responseJSON;
}

From source file:org.wrml.runtime.format.application.schema.json.JsonSchemaLoader.java

private void initStringArrayNode(final ObjectNode node, final String arrayNodeName,
        Collection<?> arrayNodeElements) {

    if (arrayNodeElements == null || arrayNodeElements.isEmpty() || arrayNodeName == null) {
        return;/*w  w w  . j  a va2 s.  c o m*/
    }

    final ArrayNode arrayNode = node.putArray(arrayNodeName);

    final SyntaxLoader syntaxLoader = getSyntaxLoader();
    for (Object element : arrayNodeElements) {
        final String stringValue = syntaxLoader.formatSyntaxValue(element);
        arrayNode.add(stringValue);
    }

}