List of usage examples for com.fasterxml.jackson.databind.node ArrayNode add
public ArrayNode add(JsonNode paramJsonNode)
From source file:org.activiti.rest.service.api.form.FormDataResourceTest.java
@Deployment public void testSubmitFormData() throws Exception { Map<String, Object> variableMap = new HashMap<String, Object>(); variableMap.put("SpeakerName", "John Doe"); Address address = new Address(); variableMap.put("address", address); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap); String processInstanceId = processInstance.getId(); String processDefinitionId = processInstance.getProcessDefinitionId(); Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("taskId", task.getId()); ArrayNode propertyArray = objectMapper.createArrayNode(); requestNode.put("properties", propertyArray); ObjectNode propNode = objectMapper.createObjectNode(); propNode.put("id", "room"); propNode.put("value", 123l); propertyArray.add(propNode); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA)); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_INTERNAL_SERVER_ERROR)); propNode = objectMapper.createObjectNode(); propNode.put("id", "street"); propNode.put("value", "test"); propertyArray.add(propNode);//from w w w .jav a 2s . co m httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_NO_CONTENT)); task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); assertNull(task); processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId) .singleResult(); assertNull(processInstance); List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstanceId).list(); Map<String, HistoricVariableInstance> historyMap = new HashMap<String, HistoricVariableInstance>(); for (HistoricVariableInstance historicVariableInstance : variables) { historyMap.put(historicVariableInstance.getVariableName(), historicVariableInstance); } assertEquals("123", historyMap.get("room").getValue()); assertEquals(processInstanceId, historyMap.get("room").getProcessInstanceId()); processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap); processInstanceId = processInstance.getId(); task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); requestNode.put("taskId", task.getId()); propNode = objectMapper.createObjectNode(); propNode.put("id", "direction"); propNode.put("value", "nowhere"); propertyArray.add(propNode); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST)); propNode.put("value", "up"); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_NO_CONTENT)); task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); assertNull(task); processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId) .singleResult(); assertNull(processInstance); variables = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId) .list(); historyMap.clear(); for (HistoricVariableInstance historicVariableInstance : variables) { historyMap.put(historicVariableInstance.getVariableName(), historicVariableInstance); } assertEquals("123", historyMap.get("room").getValue()); assertEquals(processInstanceId, historyMap.get("room").getProcessInstanceId()); assertEquals("up", historyMap.get("direction").getValue()); requestNode = objectMapper.createObjectNode(); requestNode.put("processDefinitionId", processDefinitionId); propertyArray = objectMapper.createArrayNode(); requestNode.put("properties", propertyArray); propNode = objectMapper.createObjectNode(); propNode.put("id", "number"); propNode.put("value", 123); propertyArray.add(propNode); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode.get("id").asText()); assertEquals(processDefinitionId, responseNode.get("processDefinitionId").asText()); task = taskService.createTaskQuery().processInstanceId(responseNode.get("id").asText()).singleResult(); assertNotNull(task); }
From source file:org.flowable.rest.service.api.form.FormDataResourceTest.java
@Deployment public void testSubmitFormData() throws Exception { Map<String, Object> variableMap = new HashMap<String, Object>(); variableMap.put("SpeakerName", "John Doe"); Address address = new Address(); variableMap.put("address", address); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap); String processInstanceId = processInstance.getId(); String processDefinitionId = processInstance.getProcessDefinitionId(); Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("taskId", task.getId()); ArrayNode propertyArray = objectMapper.createArrayNode(); requestNode.set("properties", propertyArray); ObjectNode propNode = objectMapper.createObjectNode(); propNode.put("id", "room"); propNode.put("value", 123L); propertyArray.add(propNode); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA)); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_INTERNAL_SERVER_ERROR)); propNode = objectMapper.createObjectNode(); propNode.put("id", "street"); propNode.put("value", "test"); propertyArray.add(propNode);/*from ww w .j a va 2 s . c om*/ httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_NO_CONTENT)); task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); assertNull(task); processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId) .singleResult(); assertNull(processInstance); List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstanceId).list(); Map<String, HistoricVariableInstance> historyMap = new HashMap<String, HistoricVariableInstance>(); for (HistoricVariableInstance historicVariableInstance : variables) { historyMap.put(historicVariableInstance.getVariableName(), historicVariableInstance); } assertEquals("123", historyMap.get("room").getValue()); assertEquals(processInstanceId, historyMap.get("room").getProcessInstanceId()); processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap); processInstanceId = processInstance.getId(); task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); requestNode.put("taskId", task.getId()); propNode = objectMapper.createObjectNode(); propNode.put("id", "direction"); propNode.put("value", "nowhere"); propertyArray.add(propNode); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST)); propNode.put("value", "up"); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_NO_CONTENT)); task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); assertNull(task); processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId) .singleResult(); assertNull(processInstance); variables = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId) .list(); historyMap.clear(); for (HistoricVariableInstance historicVariableInstance : variables) { historyMap.put(historicVariableInstance.getVariableName(), historicVariableInstance); } assertEquals("123", historyMap.get("room").getValue()); assertEquals(processInstanceId, historyMap.get("room").getProcessInstanceId()); assertEquals("up", historyMap.get("direction").getValue()); requestNode = objectMapper.createObjectNode(); requestNode.put("processDefinitionId", processDefinitionId); propertyArray = objectMapper.createArrayNode(); requestNode.set("properties", propertyArray); propNode = objectMapper.createObjectNode(); propNode.put("id", "number"); propNode.put("value", 123); propertyArray.add(propNode); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode.get("id").asText()); assertEquals(processDefinitionId, responseNode.get("processDefinitionId").asText()); task = taskService.createTaskQuery().processInstanceId(responseNode.get("id").asText()).singleResult(); assertNotNull(task); }
From source file:fr.gouv.vitam.query.construct.request.MltRequest.java
/** * Add a variable into the Mlt Request/* w ww .j a v a2 s .c o m*/ * * @param variableName * @return the MltRequest * @throws InvalidCreateOperationException */ public final MltRequest addMltVariable(final String... variableName) throws InvalidCreateOperationException { if (currentREQUEST != REQUEST.flt && currentREQUEST != REQUEST.mlt) { throw new InvalidCreateOperationException( "Cannot add a variableName since this is not an Mlt Request: " + currentREQUEST); } final ArrayNode array = (ArrayNode) currentObject; if (stringVals == null) { stringVals = new HashSet<String>(); } for (String val : variableName) { if (val == null || val.trim().isEmpty()) { throw new InvalidCreateOperationException( "Request " + currentREQUEST + " cannot be updated with empty variable name"); } val = val.trim(); if (!stringVals.contains(val)) { array.add(val); stringVals.add(val); } } return this; }
From source file:models.protocol.v1.MetricMessagesProcessor.java
private void processMetricsList(final MetricsList metricsList) { //TODO(barp): Map with a POJO mapper [MAI-184] final ObjectNode dataNode = JsonNodeFactory.instance.objectNode(); final ArrayNode services = JsonNodeFactory.instance.arrayNode(); for (final Map.Entry<String, Map<String, Set<String>>> service : metricsList.getMetrics().entrySet()) { final ObjectNode serviceObject = JsonNodeFactory.instance.objectNode(); serviceObject.put("name", service.getKey()); final ArrayNode metrics = JsonNodeFactory.instance.arrayNode(); for (final Map.Entry<String, Set<String>> metric : service.getValue().entrySet()) { final ObjectNode metricObject = JsonNodeFactory.instance.objectNode(); metricObject.put("name", metric.getKey()); final ArrayNode stats = JsonNodeFactory.instance.arrayNode(); for (final String statistic : metric.getValue()) { final ObjectNode statsObject = JsonNodeFactory.instance.objectNode(); statsObject.put("name", statistic); statsObject.set("children", JsonNodeFactory.instance.arrayNode()); stats.add(statsObject); }//from w w w.java 2 s . co m metricObject.set("children", stats); metrics.add(metricObject); } serviceObject.set("children", metrics); services.add(serviceObject); } dataNode.set("metrics", services); _connectionContext.sendCommand(COMMAND_METRICS_LIST, dataNode); }
From source file:org.opendaylight.sfc.sbrest.json.SfstateExporterFactory.java
@Override public String exportJson(DataObject dataObject) { String ret = null;/* ww w . jav a 2s. c o m*/ if (dataObject instanceof ServiceFunctionState) { ServiceFunctionState sfstate = (ServiceFunctionState) dataObject; ArrayNode sfstateArray = mapper.createArrayNode(); ObjectNode sfstateNode = mapper.createObjectNode(); if (sfstate.getName() != null && sfstate.getName().getValue() != null) { sfstateNode.put(_NAME, sfstate.getName().getValue()); } if (sfstate.getServiceStatistics() != null) { sfstateNode.put(_SERVICE_STATISTICS, getServiceStatisticsObjectNode(sfstate.getServiceStatistics())); } if (sfstate.getSfServicePath() != null) { ArrayNode servicePathArray = mapper.createArrayNode(); for (SfServicePath sfServicePath : sfstate.getSfServicePath()) { ObjectNode servicePathNode = this.getSfServicePathObjectNode(sfServicePath); servicePathArray.add(servicePathNode); } sfstateNode.putArray(_SF_SERVICE_PATH).addAll(servicePathArray); } sfstateNode.put(SERVICE_FUNCTION_DESCRIPTION_MONITOR_PREFIX + _SFC_SF_DESC_MON, getSfDescriptionMonitorObjectNode(sfstate)); sfstateArray.add(sfstateNode); try { Object sfstateObject = mapper.treeToValue(sfstateArray, Object.class); ret = mapper.writeValueAsString(sfstateObject); ret = "{\"" + _SERVICE_FUNCTION_STATE + "\":" + ret + "}"; LOG.debug("Created Service Function State JSON: {}", ret); } catch (JsonProcessingException e) { LOG.error("Error during creation of JSON for Service Function State {}", sfstate.getName()); } } else { throw new IllegalArgumentException("Argument is not an instance of ServiceFunctionState"); } return ret; }
From source file:com.irccloud.android.test.IgnoreTests.java
public void testNoNickWithDot() { ArrayNode ignores = new ObjectMapper().createArrayNode(); ignores.add("*!users.1@host.local"); ServersDataSource.Server s = ServersDataSource.getInstance().createServer(0, "", "", 0, "", "", 0, 0, "", "", "", "", null, "", ignores, 0); Ignore ignore = new Ignore(); ignore.setIgnores(s.ignores);//from w w w . jav a 2 s.c o m assertEquals(true, ignore.match("sam!users.1@host.local")); assertEquals(true, ignore.match("SAM!userS.1@host.LOCAL")); assertEquals(true, ignore.match("harry!users.1@host.local")); assertEquals(false, ignore.match("sam!~username@host.local")); assertEquals(false, ignore.match("harry!~username@host.local")); assertEquals(false, ignore.match("sam!users.1@work.local")); assertEquals(false, ignore.match("harry!users.1@work.local")); assertEquals(false, ignore.match("sam!~username@work.local")); assertEquals(false, ignore.match("harry!~username@work.local")); }
From source file:com.irccloud.android.test.IgnoreTests.java
public void testNoNick() { ArrayNode ignores = new ObjectMapper().createArrayNode(); ignores.add("*!username@host.local"); ServersDataSource.Server s = ServersDataSource.getInstance().createServer(0, "", "", 0, "", "", 0, 0, "", "", "", "", null, "", ignores, 0); Ignore ignore = new Ignore(); ignore.setIgnores(s.ignores);/*w w w .ja va2s.c om*/ assertEquals(false, ignore.match("sam!users.1@host.local")); assertEquals(false, ignore.match("SAM!userS.1@host.LOCAL")); assertEquals(false, ignore.match("harry!users.1@host.local")); assertEquals(true, ignore.match("sam!~username@host.local")); assertEquals(true, ignore.match("harry!~username@host.local")); assertEquals(false, ignore.match("sam!users.1@work.local")); assertEquals(false, ignore.match("harry!users.1@work.local")); assertEquals(false, ignore.match("sam!~username@work.local")); assertEquals(false, ignore.match("harry!~username@work.local")); }
From source file:com.irccloud.android.test.IgnoreTests.java
public void testNoNickIdentUsername() { ArrayNode ignores = new ObjectMapper().createArrayNode(); ignores.add("*!~username@host.local"); ServersDataSource.Server s = ServersDataSource.getInstance().createServer(0, "", "", 0, "", "", 0, 0, "", "", "", "", null, "", ignores, 0); Ignore ignore = new Ignore(); ignore.setIgnores(s.ignores);/*from ww w. ja v a 2 s . c o m*/ assertEquals(false, ignore.match("sam!users.1@host.local")); assertEquals(false, ignore.match("SAM!userS.1@host.LOCAL")); assertEquals(false, ignore.match("harry!users.1@host.local")); assertEquals(true, ignore.match("sam!~username@host.local")); assertEquals(true, ignore.match("harry!~username@host.local")); assertEquals(false, ignore.match("sam!users.1@work.local")); assertEquals(false, ignore.match("harry!users.1@work.local")); assertEquals(false, ignore.match("sam!~username@work.local")); assertEquals(false, ignore.match("harry!~username@work.local")); }
From source file:com.irccloud.android.test.IgnoreTests.java
public void testNoHost() { ArrayNode ignores = new ObjectMapper().createArrayNode(); ignores.add("sam!users.1@*"); ServersDataSource.Server s = ServersDataSource.getInstance().createServer(0, "", "", 0, "", "", 0, 0, "", "", "", "", null, "", ignores, 0); Ignore ignore = new Ignore(); ignore.setIgnores(s.ignores);//from ww w .j a v a 2s . co m assertEquals(true, ignore.match("sam!users.1@host.local")); assertEquals(true, ignore.match("SAM!userS.1@host.LOCAL")); assertEquals(false, ignore.match("harry!users.1@host.local")); assertEquals(false, ignore.match("sam!~username@host.local")); assertEquals(false, ignore.match("harry!~username@host.local")); assertEquals(true, ignore.match("sam!users.1@work.local")); assertEquals(false, ignore.match("harry!users.1@work.local")); assertEquals(false, ignore.match("sam!~username@work.local")); assertEquals(false, ignore.match("harry!~username@work.local")); }
From source file:com.irccloud.android.test.IgnoreTests.java
public void testJustHost() { ArrayNode ignores = new ObjectMapper().createArrayNode(); ignores.add("host.local"); ServersDataSource.Server s = ServersDataSource.getInstance().createServer(0, "", "", 0, "", "", 0, 0, "", "", "", "", null, "", ignores, 0); Ignore ignore = new Ignore(); ignore.setIgnores(s.ignores);// w ww . j a v a2 s . c o m assertEquals(false, ignore.match("sam!users.1@host.local")); assertEquals(false, ignore.match("SAM!userS.1@host.LOCAL")); assertEquals(false, ignore.match("harry!users.1@host.local")); assertEquals(false, ignore.match("sam!~username@host.local")); assertEquals(false, ignore.match("harry!~username@host.local")); assertEquals(false, ignore.match("sam!users.1@work.local")); assertEquals(false, ignore.match("harry!users.1@work.local")); assertEquals(false, ignore.match("sam!~username@work.local")); assertEquals(false, ignore.match("harry!~username@work.local")); }