List of usage examples for com.fasterxml.jackson.databind.node ArrayNode toString
public String toString()
From source file:org.kiji.rest.TestRowsResource.java
protected final String createJsonArray(String... components) throws IOException { final JsonNodeFactory factory = new JsonNodeFactory(true); ArrayNode arrayNode = factory.arrayNode(); for (String component : components) { JsonNode node;/*from w w w. ja v a 2 s .c o m*/ if (component.startsWith(KijiRestEntityId.HBASE_ROW_KEY_PREFIX) || component.startsWith(KijiRestEntityId.HBASE_HEX_ROW_KEY_PREFIX)) { node = factory.textNode(component); } else { node = stringToJsonNode(component); } arrayNode.add(node); } return arrayNode.toString(); }
From source file:com.delphix.delphix.DelphixEngine.java
/** * Update the pre and post hooks for a specific type of operation on a container *//* w w w.j ava2 s. com*/ public void updateHooks(ContainerOperationType targetOperation, String containerRef, ArrayList<HookOperation> preOperations, ArrayList<HookOperation> postOperations) throws IOException, DelphixEngineException { // Figure out the operation type to set on JSON payload DelphixSource source = listSources().get(containerRef); String operationType = ""; if (source.getType().contains("VirtualSource")) { operationType = "VirtualSourceOperations"; } else if (source.getType().contains("LinkedSource")) { operationType = "LinkedSourceOperations"; } // Read the operation content for pre hooks and set it on payload ArrayNode preHooks = MAPPER.createArrayNode(); for (HookOperation operation : preOperations) { ObjectNode node = MAPPER.createObjectNode(); String operationContent = FileUtils.readFileToString(new File(operation.getPath())); node.put("command", operationContent); node.put("type", "RunCommandOnSourceOperation"); preHooks.add(node); } // Read the operation content for post hooks and set it on payload ArrayNode postHooks = MAPPER.createArrayNode(); for (HookOperation operation : postOperations) { ObjectNode node = MAPPER.createObjectNode(); String operationContent = FileUtils.readFileToString(new File(operation.getPath())); node.put("command", operationContent); node.put("type", "RunCommandOnSourceOperation"); postHooks.add(node); } // Choose the appropriate payload based on target operation type to update String postData = ""; if (targetOperation.equals(ContainerOperationType.REFRESH)) { postData = String.format(CONTENT_REFRESH_HOOK, preHooks.toString(), postHooks.toString(), operationType, source.getType()); } else if (targetOperation.equals(ContainerOperationType.ROLLBACK)) { postData = String.format(CONTENT_ROLLBACK_HOOK, preHooks.toString(), postHooks.toString(), operationType, source.getType()); } else if (targetOperation.equals(ContainerOperationType.SYNC)) { postData = String.format(CONTENT_SYNC_HOOK, preHooks.toString(), postHooks.toString(), operationType, source.getType()); } enginePOST(String.format(PATH_HOOK_OPERATION, source.getReference()), postData); }
From source file:org.jetbrains.webdemo.sessions.MyHttpSession.java
private void sendExamplesList() { try {/*from w w w . j a va 2s. c o m*/ ArrayNode responseBody = new ArrayNode(JsonNodeFactory.instance); Map<String, Boolean> taskStatuses = MySqlConnector.getInstance() .getUserTaskStatuses(sessionInfo.getUserInfo()); for (ExamplesFolder folder : ExamplesFolder.ROOT_FOLDER.getChildFolders()) { addFolderContent(responseBody, folder, taskStatuses); } ObjectNode adventOfCodeContent = responseBody.addObject(); adventOfCodeContent.put("name", "Advent of Code"); adventOfCodeContent.put("id", "advent%20of%20code"); adventOfCodeContent.putArray("childFolders"); if (sessionInfo.getUserInfo().isLogin()) { adventOfCodeContent.put("projects", MySqlConnector.getInstance() .getProjectHeaders(sessionInfo.getUserInfo(), "ADVENT_OF_CODE_PROJECT")); } else { adventOfCodeContent.putArray("projects"); } ObjectNode myProgramsContent = responseBody.addObject(); myProgramsContent.put("name", "My programs"); myProgramsContent.put("id", "My%20programs"); myProgramsContent.putArray("childFolders"); if (sessionInfo.getUserInfo().isLogin()) { myProgramsContent.put("projects", MySqlConnector.getInstance().getProjectHeaders(sessionInfo.getUserInfo(), "USER_PROJECT")); } else { myProgramsContent.putArray("projects"); } writeResponse(responseBody.toString(), HttpServletResponse.SC_OK); } catch (DatabaseOperationException e) { writeResponse(e.getMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.glaf.base.modules.sys.springmvc.SysDepartmentController.java
@ResponseBody @RequestMapping(params = "method=treegridJson") public byte[] treegridJson(HttpServletRequest request) { Map<String, Object> params = RequestUtils.getParameterMap(request); logger.debug(params);/*from w ww . j av a 2 s .c om*/ long parentId = RequestUtils.getLong(request, "parentId", -1); List<SysTree> trees = sysTreeService.getSysTreeListForDept(parentId, 0); List<SysDepartment> depts = sysDepartmentService.getSysDepartmentList(parentId); ArrayNode responseJSON = new ObjectMapper().createArrayNode(); List<TreeModel> treeModels = new java.util.ArrayList<TreeModel>(); if (trees != null && !trees.isEmpty() && depts != null && !depts.isEmpty()) { Map<Long, SysDepartment> deptMap = new java.util.HashMap<Long, SysDepartment>(); for (SysDepartment dept : depts) { deptMap.put(dept.getNodeId(), dept); } for (SysTree tree : trees) { SysDepartment dept = deptMap.get(tree.getId()); if (dept != null) { Map<String, Object> dataMap = tree.getDataMap(); if (dataMap == null) { dataMap = new java.util.HashMap<String, Object>(); } dataMap.put("deptId", dept.getId()); dataMap.put("deptName", dept.getName()); dataMap.put("deptCode", dept.getCode()); dataMap.put("deptCode2", dept.getCode2()); dataMap.put("deptNo", dept.getNo()); dataMap.put("deptDesc", dept.getDesc()); dataMap.put("deptFincode", dept.getFincode()); dataMap.put("deptLevel", dept.getLevel()); tree.setDataMap(dataMap); } treeModels.add(tree); } } JacksonTreeHelper treeHelper = new JacksonTreeHelper(); responseJSON = treeHelper.getTreeArrayNode(treeModels); logger.debug(responseJSON.toString()); try { return responseJSON.toString().getBytes("UTF-8"); } catch (IOException e) { return responseJSON.toString().getBytes(); } }
From source file:org.activiti.rest.service.api.runtime.ProcessInstanceVariablesCollectionResourceTest.java
/** * Test creating multiple process variables in a single call. POST runtime/process-instance/{processInstanceId}/variables *///from w ww.j av a 2 s.c o m @Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" }) public void testCreateMultipleProcessVariables() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); ArrayNode requestNode = objectMapper.createArrayNode(); // String variable ObjectNode stringVarNode = requestNode.addObject(); stringVarNode.put("name", "stringVariable"); stringVarNode.put("value", "simple string value"); stringVarNode.put("type", "string"); // Integer ObjectNode integerVarNode = requestNode.addObject(); integerVarNode.put("name", "integerVariable"); integerVarNode.put("value", 1234); integerVarNode.put("type", "integer"); // Short ObjectNode shortVarNode = requestNode.addObject(); shortVarNode.put("name", "shortVariable"); shortVarNode.put("value", 123); shortVarNode.put("type", "short"); // Long ObjectNode longVarNode = requestNode.addObject(); longVarNode.put("name", "longVariable"); longVarNode.put("value", 4567890L); longVarNode.put("type", "long"); // Double ObjectNode doubleVarNode = requestNode.addObject(); doubleVarNode.put("name", "doubleVariable"); doubleVarNode.put("value", 123.456); doubleVarNode.put("type", "double"); // Boolean ObjectNode booleanVarNode = requestNode.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 = requestNode.addObject(); dateVarNode.put("name", "dateVariable"); dateVarNode.put("value", isoString); dateVarNode.put("type", "date"); // Create local variables with a single request HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertTrue(responseNode.isArray()); assertEquals(7, responseNode.size()); // Check if engine has correct variables set Map<String, Object> variables = runtimeService.getVariablesLocal(processInstance.getId()); assertEquals(7, variables.size()); assertEquals("simple string value", variables.get("stringVariable")); assertEquals(1234, variables.get("integerVariable")); assertEquals((short) 123, variables.get("shortVariable")); assertEquals(4567890L, variables.get("longVariable")); assertEquals(123.456, variables.get("doubleVariable")); assertEquals(Boolean.TRUE, variables.get("booleanVariable")); assertEquals(dateFormat.parse(isoString), variables.get("dateVariable")); }
From source file:org.flowable.rest.service.api.runtime.ProcessInstanceVariablesCollectionResourceTest.java
/** * Test creating multiple process variables in a single call. POST runtime/process-instance/{processInstanceId}/variables *//* w ww . j a v a 2 s. c om*/ @Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" }) public void testCreateMultipleProcessVariables() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); ArrayNode requestNode = objectMapper.createArrayNode(); // String variable ObjectNode stringVarNode = requestNode.addObject(); stringVarNode.put("name", "stringVariable"); stringVarNode.put("value", "simple string value"); stringVarNode.put("type", "string"); // Integer ObjectNode integerVarNode = requestNode.addObject(); integerVarNode.put("name", "integerVariable"); integerVarNode.put("value", 1234); integerVarNode.put("type", "integer"); // Short ObjectNode shortVarNode = requestNode.addObject(); shortVarNode.put("name", "shortVariable"); shortVarNode.put("value", 123); shortVarNode.put("type", "short"); // Long ObjectNode longVarNode = requestNode.addObject(); longVarNode.put("name", "longVariable"); longVarNode.put("value", 4567890L); longVarNode.put("type", "long"); // Double ObjectNode doubleVarNode = requestNode.addObject(); doubleVarNode.put("name", "doubleVariable"); doubleVarNode.put("value", 123.456); doubleVarNode.put("type", "double"); // Boolean ObjectNode booleanVarNode = requestNode.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 = requestNode.addObject(); dateVarNode.put("name", "dateVariable"); dateVarNode.put("value", isoString); dateVarNode.put("type", "date"); // Create local variables with a single request HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertTrue(responseNode.isArray()); assertEquals(7, responseNode.size()); // Check if engine has correct variables set Map<String, Object> variables = runtimeService.getVariablesLocal(processInstance.getId()); assertEquals(7, variables.size()); assertEquals("simple string value", variables.get("stringVariable")); assertEquals(1234, variables.get("integerVariable")); assertEquals((short) 123, variables.get("shortVariable")); assertEquals(4567890L, variables.get("longVariable")); assertEquals(123.456, variables.get("doubleVariable")); assertEquals(Boolean.TRUE, variables.get("booleanVariable")); assertEquals(dateFormat.parse(isoString), variables.get("dateVariable")); }
From source file:com.glaf.activiti.web.springmvc.ActivitiTreeController.java
@ResponseBody @RequestMapping("/json") public byte[] json(HttpServletRequest request) { ArrayNode responseJSON = new ObjectMapper().createArrayNode(); List<ProcessDefinition> processDefinitions = activitiProcessQueryService.getAllLatestProcessDefinitions(); if (processDefinitions != null && !processDefinitions.isEmpty()) { for (ProcessDefinition processDefinition : processDefinitions) { ObjectNode row = new ObjectMapper().createObjectNode(); row.put("category", processDefinition.getCategory()); row.put("deploymentId", processDefinition.getDeploymentId()); row.put("description", processDefinition.getDescription()); row.put("id", processDefinition.getId()); row.put("key", processDefinition.getKey()); row.put("name", processDefinition.getName()); row.put("text", processDefinition.getName()); row.put("version", processDefinition.getVersion()); row.put("leaf", Boolean.valueOf(false)); row.put("iconSkin", "process_folder"); row.put("nlevel", 0); responseJSON.add(row);/*www . j a v a 2 s. c o m*/ List<ProcessDefinition> list = activitiProcessQueryService .getProcessDefinitions(processDefinition.getKey()); if (list != null && !list.isEmpty()) { ArrayNode arrayJSON = new ObjectMapper().createArrayNode(); for (ProcessDefinition pd : list) { ObjectNode o = new ObjectMapper().createObjectNode(); o.put("category", pd.getCategory()); o.put("deploymentId", pd.getDeploymentId()); o.put("description", pd.getDescription()); o.put("id", pd.getId()); o.put("key", pd.getKey()); o.put("name", pd.getName() + " V" + pd.getVersion()); o.put("text", pd.getName() + " V" + pd.getVersion()); o.put("version", pd.getVersion()); o.put("leaf", Boolean.valueOf(true)); o.put("iconSkin", "process_leaf"); o.put("nlevel", 1); arrayJSON.add(o); } row.set("children", arrayJSON); } } } try { // logger.debug(responseJSON.toString()); return responseJSON.toString().getBytes("UTF-8"); } catch (IOException e) { return responseJSON.toString().getBytes(); } }
From source file:org.activiti.rest.service.api.runtime.TaskVariablesCollectionResourceTest.java
/** * Test creating a multipe task variable in a single call. POST runtime/tasks/{taskId}/variables *///from w w w . j a va 2s .co m public void testCreateMultipleTaskVariables() throws Exception { try { Task task = taskService.newTask(); taskService.saveTask(task); ArrayNode requestNode = objectMapper.createArrayNode(); // String variable ObjectNode stringVarNode = requestNode.addObject(); stringVarNode.put("name", "stringVariable"); stringVarNode.put("value", "simple string value"); stringVarNode.put("scope", "local"); stringVarNode.put("type", "string"); // Integer ObjectNode integerVarNode = requestNode.addObject(); integerVarNode.put("name", "integerVariable"); integerVarNode.put("value", 1234); integerVarNode.put("scope", "local"); integerVarNode.put("type", "integer"); // Short ObjectNode shortVarNode = requestNode.addObject(); shortVarNode.put("name", "shortVariable"); shortVarNode.put("value", 123); shortVarNode.put("scope", "local"); shortVarNode.put("type", "short"); // Long ObjectNode longVarNode = requestNode.addObject(); longVarNode.put("name", "longVariable"); longVarNode.put("value", 4567890L); longVarNode.put("scope", "local"); longVarNode.put("type", "long"); // Double ObjectNode doubleVarNode = requestNode.addObject(); doubleVarNode.put("name", "doubleVariable"); doubleVarNode.put("value", 123.456); doubleVarNode.put("scope", "local"); doubleVarNode.put("type", "double"); // Boolean ObjectNode booleanVarNode = requestNode.addObject(); booleanVarNode.put("name", "booleanVariable"); booleanVarNode.put("value", Boolean.TRUE); booleanVarNode.put("scope", "local"); booleanVarNode.put("type", "boolean"); // Date Calendar varCal = Calendar.getInstance(); String isoString = getISODateString(varCal.getTime()); ObjectNode dateVarNode = requestNode.addObject(); dateVarNode.put("name", "dateVariable"); dateVarNode.put("value", isoString); dateVarNode.put("scope", "local"); dateVarNode.put("type", "date"); // Create local variables with a single request HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertTrue(responseNode.isArray()); assertEquals(7, responseNode.size()); // Check if engine has correct variables set Map<String, Object> taskVariables = taskService.getVariablesLocal(task.getId()); assertEquals(7, taskVariables.size()); assertEquals("simple string value", taskVariables.get("stringVariable")); assertEquals(1234, taskVariables.get("integerVariable")); assertEquals((short) 123, taskVariables.get("shortVariable")); assertEquals(4567890L, taskVariables.get("longVariable")); assertEquals(123.456, taskVariables.get("doubleVariable")); assertEquals(Boolean.TRUE, taskVariables.get("booleanVariable")); assertEquals(dateFormat.parse(isoString), taskVariables.get("dateVariable")); } finally { // Clean adhoc-tasks even if test fails List<Task> tasks = taskService.createTaskQuery().list(); for (Task task : tasks) { taskService.deleteTask(task.getId(), true); } } }