List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString
public String toString()
From source file:dao.SearchDAO.java
public static JsonNode elasticSearchDatasetByKeyword(String category, String keywords, String source, int page, int size) { ObjectNode queryNode = Json.newObject(); queryNode.put("from", (page - 1) * size); queryNode.put("size", size); JsonNode responseNode = null;//from ww w . j a v a 2s . c om ObjectNode keywordNode = null; try { keywordNode = utils.Search.generateElasticSearchQueryString(category, source, keywords); } catch (Exception e) { Logger.error("Elastic search dataset input query is not JSON format. Error message :" + e.getMessage()); } if (keywordNode != null) { ObjectNode funcScoreNodes = Json.newObject(); ObjectNode fieldValueFactorNode = Json.newObject(); fieldValueFactorNode.put("field", "static_boosting_score"); fieldValueFactorNode.put("factor", 1); fieldValueFactorNode.put("modifier", "square"); fieldValueFactorNode.put("missing", 1); funcScoreNodes.put("query", keywordNode); funcScoreNodes.put("field_value_factor", fieldValueFactorNode); ObjectNode funcScoreNodesWrapper = Json.newObject(); funcScoreNodesWrapper.put("function_score", funcScoreNodes); queryNode.put("query", funcScoreNodesWrapper); Logger.debug("The query sent to Elastic Search is: " + queryNode.toString()); Promise<WSResponse> responsePromise = WS .url(Play.application().configuration().getString(SearchDAO.ELASTICSEARCH_DATASET_URL_KEY)) .post(queryNode); responseNode = responsePromise.get(1000).asJson(); Logger.debug("The responseNode from Elastic Search is: " + responseNode.toString()); } ObjectNode resultNode = Json.newObject(); Long count = 0L; List<Dataset> pagedDatasets = new ArrayList<>(); resultNode.put("page", page); resultNode.put("category", category); resultNode.put("source", source); resultNode.put("itemsPerPage", size); resultNode.put("keywords", keywords); if (responseNode != null && responseNode.isContainerNode() && responseNode.has("hits")) { JsonNode hitsNode = responseNode.get("hits"); if (hitsNode != null) { if (hitsNode.has("total")) { count = hitsNode.get("total").asLong(); } if (hitsNode.has("hits")) { JsonNode dataNode = hitsNode.get("hits"); if (dataNode != null && dataNode.isArray()) { Iterator<JsonNode> arrayIterator = dataNode.elements(); if (arrayIterator != null) { while (arrayIterator.hasNext()) { JsonNode node = arrayIterator.next(); if (node.isContainerNode() && node.has("_id")) { Dataset dataset = new Dataset(); dataset.id = node.get("_id").asLong(); if (node.has("_source")) { JsonNode sourceNode = node.get("_source"); if (sourceNode != null) { if (sourceNode.has("name")) { dataset.name = sourceNode.get("name").asText(); } if (sourceNode.has("source")) { dataset.source = sourceNode.get("source").asText(); } if (sourceNode.has("urn")) { dataset.urn = sourceNode.get("urn").asText(); } if (sourceNode.has("schema")) { dataset.schema = sourceNode.get("schema").asText(); } } } pagedDatasets.add(dataset); } } } } } } } resultNode.put("count", count); resultNode.put("totalPages", (int) Math.ceil(count / ((double) size))); resultNode.set("data", Json.toJson(pagedDatasets)); return resultNode; }
From source file:org.activiti.rest.service.api.runtime.TaskResourceTest.java
/** * Test completing a single task. POST runtime/tasks/{taskId} *//*w ww . j a v a 2 s .co m*/ @Deployment public void testCompleteTask() throws Exception { try { Task task = taskService.newTask(); taskService.saveTask(task); String taskId = task.getId(); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("action", "complete"); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_OK)); // Task shouldn't exist anymore task = taskService.createTaskQuery().taskId(taskId).singleResult(); assertNull(task); // Test completing with variables ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); taskId = task.getId(); requestNode = objectMapper.createObjectNode(); ArrayNode variablesNode = objectMapper.createArrayNode(); requestNode.put("action", "complete"); requestNode.put("variables", variablesNode); ObjectNode var1 = objectMapper.createObjectNode(); variablesNode.add(var1); var1.put("name", "var1"); var1.put("value", "First value"); ObjectNode var2 = objectMapper.createObjectNode(); variablesNode.add(var2); var2.put("name", "var2"); var2.put("value", "Second value"); httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId)); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_OK)); task = taskService.createTaskQuery().taskId(taskId).singleResult(); assertNull(task); if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) { HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery() .taskId(taskId).singleResult(); assertNotNull(historicTaskInstance); List<HistoricVariableInstance> updates = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).list(); assertNotNull(updates); assertEquals(2, updates.size()); boolean foundFirst = false; boolean foundSecond = false; for (HistoricVariableInstance var : updates) { if (var.getVariableName().equals("var1")) { assertEquals("First value", var.getValue()); foundFirst = true; } else if (var.getVariableName().equals("var2")) { assertEquals("Second value", var.getValue()); foundSecond = true; } } assertTrue(foundFirst); assertTrue(foundSecond); } } finally { // Clean adhoc-tasks even if test fails List<Task> tasks = taskService.createTaskQuery().list(); for (Task task : tasks) { taskService.deleteTask(task.getId(), true); } // Clean historic tasks with no runtime-counterpart List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery().list(); for (HistoricTaskInstance task : historicTasks) { historyService.deleteHistoricTaskInstance(task.getId()); } } }
From source file:org.flowable.rest.service.api.runtime.TaskResourceTest.java
/** * Test completing a single task. POST runtime/tasks/{taskId} *//*from w ww.j a v a 2s .co m*/ @Deployment public void testCompleteTask() throws Exception { try { Task task = taskService.newTask(); taskService.saveTask(task); String taskId = task.getId(); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("action", "complete"); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_OK)); // Task shouldn't exist anymore task = taskService.createTaskQuery().taskId(taskId).singleResult(); assertNull(task); // Test completing with variables ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); taskId = task.getId(); requestNode = objectMapper.createObjectNode(); ArrayNode variablesNode = objectMapper.createArrayNode(); requestNode.put("action", "complete"); requestNode.set("variables", variablesNode); ObjectNode var1 = objectMapper.createObjectNode(); variablesNode.add(var1); var1.put("name", "var1"); var1.put("value", "First value"); ObjectNode var2 = objectMapper.createObjectNode(); variablesNode.add(var2); var2.put("name", "var2"); var2.put("value", "Second value"); httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId)); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_OK)); task = taskService.createTaskQuery().taskId(taskId).singleResult(); assertNull(task); if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) { HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery() .taskId(taskId).singleResult(); assertNotNull(historicTaskInstance); List<HistoricVariableInstance> updates = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).list(); assertNotNull(updates); assertEquals(2, updates.size()); boolean foundFirst = false; boolean foundSecond = false; for (HistoricVariableInstance var : updates) { if (var.getVariableName().equals("var1")) { assertEquals("First value", var.getValue()); foundFirst = true; } else if (var.getVariableName().equals("var2")) { assertEquals("Second value", var.getValue()); foundSecond = true; } } assertTrue(foundFirst); assertTrue(foundSecond); } } finally { // Clean adhoc-tasks even if test fails List<Task> tasks = taskService.createTaskQuery().list(); for (Task task : tasks) { taskService.deleteTask(task.getId(), true); } // Clean historic tasks with no runtime-counterpart List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery().list(); for (HistoricTaskInstance task : historicTasks) { historyService.deleteHistoricTaskInstance(task.getId()); } } }
From source file:org.activiti.rest.service.api.runtime.ProcessInstanceCollectionResourceTest.java
/** * Test starting a process instance passing in variables to set. *///from www .j a v a 2s . com @Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" }) public void testStartProcessWithVariables() throws Exception { ArrayNode variablesNode = objectMapper.createArrayNode(); // String variable ObjectNode stringVarNode = variablesNode.addObject(); stringVarNode.put("name", "stringVariable"); stringVarNode.put("value", "simple string value"); stringVarNode.put("type", "string"); ObjectNode integerVarNode = variablesNode.addObject(); integerVarNode.put("name", "integerVariable"); integerVarNode.put("value", 1234); integerVarNode.put("type", "integer"); ObjectNode shortVarNode = variablesNode.addObject(); shortVarNode.put("name", "shortVariable"); shortVarNode.put("value", 123); shortVarNode.put("type", "short"); ObjectNode longVarNode = variablesNode.addObject(); longVarNode.put("name", "longVariable"); longVarNode.put("value", 4567890L); longVarNode.put("type", "long"); ObjectNode doubleVarNode = variablesNode.addObject(); doubleVarNode.put("name", "doubleVariable"); doubleVarNode.put("value", 123.456); doubleVarNode.put("type", "double"); ObjectNode booleanVarNode = variablesNode.addObject(); booleanVarNode.put("name", "booleanVariable"); booleanVarNode.put("value", Boolean.TRUE); booleanVarNode.put("type", "boolean"); // Date Calendar varCal = Calendar.getInstance(); String isoString = getISODateString(varCal.getTime()); ObjectNode dateVarNode = variablesNode.addObject(); dateVarNode.put("name", "dateVariable"); dateVarNode.put("value", isoString); dateVarNode.put("type", "date"); ObjectNode requestNode = objectMapper.createObjectNode(); // Start using process definition key, passing in variables requestNode.put("processDefinitionKey", "processOne"); requestNode.put("variables", variablesNode); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION)); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertEquals(false, responseNode.get("ended").asBoolean()); JsonNode variablesArrayNode = responseNode.get("variables"); assertEquals(0, variablesArrayNode.size()); ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult(); assertNotNull(processInstance); // Check if engine has correct variables set Map<String, Object> processVariables = runtimeService.getVariables(processInstance.getId()); assertEquals(7, processVariables.size()); assertEquals("simple string value", processVariables.get("stringVariable")); assertEquals(1234, processVariables.get("integerVariable")); assertEquals((short) 123, processVariables.get("shortVariable")); assertEquals(4567890L, processVariables.get("longVariable")); assertEquals(123.456, processVariables.get("doubleVariable")); assertEquals(Boolean.TRUE, processVariables.get("booleanVariable")); assertEquals(dateFormat.parse(isoString), processVariables.get("dateVariable")); }
From source file:org.flowable.rest.service.api.runtime.ProcessInstanceCollectionResourceTest.java
/** * Test starting a process instance passing in variables to set. *//* www . j a va 2 s . c o m*/ @Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" }) public void testStartProcessWithVariables() throws Exception { ArrayNode variablesNode = objectMapper.createArrayNode(); // String variable ObjectNode stringVarNode = variablesNode.addObject(); stringVarNode.put("name", "stringVariable"); stringVarNode.put("value", "simple string value"); stringVarNode.put("type", "string"); ObjectNode integerVarNode = variablesNode.addObject(); integerVarNode.put("name", "integerVariable"); integerVarNode.put("value", 1234); integerVarNode.put("type", "integer"); ObjectNode shortVarNode = variablesNode.addObject(); shortVarNode.put("name", "shortVariable"); shortVarNode.put("value", 123); shortVarNode.put("type", "short"); ObjectNode longVarNode = variablesNode.addObject(); longVarNode.put("name", "longVariable"); longVarNode.put("value", 4567890L); longVarNode.put("type", "long"); ObjectNode doubleVarNode = variablesNode.addObject(); doubleVarNode.put("name", "doubleVariable"); doubleVarNode.put("value", 123.456); doubleVarNode.put("type", "double"); ObjectNode booleanVarNode = variablesNode.addObject(); booleanVarNode.put("name", "booleanVariable"); booleanVarNode.put("value", Boolean.TRUE); booleanVarNode.put("type", "boolean"); // Date Calendar varCal = Calendar.getInstance(); String isoString = getISODateString(varCal.getTime()); ObjectNode dateVarNode = variablesNode.addObject(); dateVarNode.put("name", "dateVariable"); dateVarNode.put("value", isoString); dateVarNode.put("type", "date"); ObjectNode requestNode = objectMapper.createObjectNode(); // Start using process definition key, passing in variables requestNode.put("processDefinitionKey", "processOne"); requestNode.set("variables", variablesNode); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION)); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertFalse(responseNode.get("ended").asBoolean()); JsonNode variablesArrayNode = responseNode.get("variables"); assertEquals(0, variablesArrayNode.size()); ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult(); assertNotNull(processInstance); // Check if engine has correct variables set Map<String, Object> processVariables = runtimeService.getVariables(processInstance.getId()); assertEquals(7, processVariables.size()); assertEquals("simple string value", processVariables.get("stringVariable")); assertEquals(1234, processVariables.get("integerVariable")); assertEquals((short) 123, processVariables.get("shortVariable")); assertEquals(4567890L, processVariables.get("longVariable")); assertEquals(123.456, processVariables.get("doubleVariable")); assertEquals(Boolean.TRUE, processVariables.get("booleanVariable")); assertEquals(dateFormat.parse(isoString), processVariables.get("dateVariable")); }
From source file:org.flowable.rest.service.api.runtime.ExecutionCollectionResourceTest.java
/** * Test signalling all executions with variables *//*from w ww. j av a 2 s. c o 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:org.activiti.rest.service.api.runtime.ExecutionCollectionResourceTest.java
/** * Test signalling all executions with variables *//*from ww w . 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:com.glaf.dts.web.rest.MxTableResource.java
@GET @POST//from w w w . j av a 2 s . c o m @Path("/view") @ResponseBody @Produces({ MediaType.APPLICATION_OCTET_STREAM }) public byte[] view(@Context HttpServletRequest request, @Context UriInfo uriInfo) { Map<String, Object> params = RequestUtils.getParameterMap(request); TableDefinitionQuery query = new TableDefinitionQuery(); Tools.populate(query, params); String tableName = request.getParameter("tableName"); String tableName_enc = request.getParameter("tableName_enc"); if (StringUtils.isNotEmpty(tableName_enc)) { tableName = RequestUtils.decodeString(tableName_enc); } TableDefinition tableDefinition = tableDefinitionService.getTableDefinition(tableName); ObjectNode responseJSON = tableDefinition.toObjectNode(); ArrayNode columnsJSON = new ObjectMapper().createArrayNode(); responseJSON.set("columns", columnsJSON); for (ColumnDefinition column : tableDefinition.getColumns()) { ObjectNode columnJSON = column.toObjectNode(); columnsJSON.add(columnJSON); } try { return responseJSON.toString().getBytes("UTF-8"); } catch (IOException e) { return responseJSON.toString().getBytes(); } }
From source file:org.flowable.rest.dmn.service.api.decision.DmnRuleServiceResourceTest.java
@DmnDeploymentAnnotation(resources = { "org/flowable/rest/dmn/service/api/decision/single-hit.dmn" }) public void testExecutionDecisionSingleResult() throws Exception { // Add decision key ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("decisionKey", "decision"); // add input variable ArrayNode variablesNode = objectMapper.createArrayNode(); ObjectNode variableNode1 = objectMapper.createObjectNode(); variableNode1.put("name", "inputVariable1"); variableNode1.put("type", "integer"); variableNode1.put("value", 5); variablesNode.add(variableNode1);//from ww w . j a va 2 s . c om ObjectNode variableNode2 = objectMapper.createObjectNode(); variableNode2.put("name", "inputVariable2"); variableNode2.put("type", "string"); variableNode2.put("value", "test2"); variablesNode.add(variableNode2); requestNode.set("inputVariables", variablesNode); HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_RULE_SERVICE_EXECUTE_SINGLE_RESULT)); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); // Check response JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); ArrayNode resultVariables = (ArrayNode) responseNode.get("resultVariables"); assertEquals(1, resultVariables.size()); }