List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString
public String toString()
From source file:org.activiti.rest.service.api.repository.ModelCollectionResourceTest.java
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" }) public void testCreateModel() throws Exception { Model model = null;/* w w w .j a va 2s .c o m*/ try { Calendar createTime = Calendar.getInstance(); createTime.set(Calendar.MILLISECOND, 0); processEngineConfiguration.getClock().setCurrentTime(createTime.getTime()); // Create create request ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("name", "Model name"); requestNode.put("category", "Model category"); requestNode.put("key", "Model key"); requestNode.put("metaInfo", "Model metainfo"); requestNode.put("deploymentId", deploymentId); requestNode.put("version", 2); requestNode.put("tenantId", "myTenant"); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION)); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertEquals("Model name", responseNode.get("name").textValue()); assertEquals("Model key", responseNode.get("key").textValue()); assertEquals("Model category", responseNode.get("category").textValue()); assertEquals(2, responseNode.get("version").intValue()); assertEquals("Model metainfo", responseNode.get("metaInfo").textValue()); assertEquals(deploymentId, responseNode.get("deploymentId").textValue()); assertEquals("myTenant", responseNode.get("tenantId").textValue()); assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime()); assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime()); assertTrue(responseNode.get("url").textValue().endsWith( RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, responseNode.get("id").textValue()))); assertTrue(responseNode.get("deploymentUrl").textValue() .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId))); model = repositoryService.createModelQuery().modelId(responseNode.get("id").textValue()).singleResult(); assertNotNull(model); assertEquals("Model category", model.getCategory()); assertEquals("Model name", model.getName()); assertEquals("Model key", model.getKey()); assertEquals(deploymentId, model.getDeploymentId()); assertEquals("Model metainfo", model.getMetaInfo()); assertEquals("myTenant", model.getTenantId()); assertEquals(2, model.getVersion().intValue()); } finally { if (model != null) { try { repositoryService.deleteModel(model.getId()); } catch (Throwable ignore) { } } } }
From source file:org.flowable.rest.service.api.repository.ModelCollectionResourceTest.java
@Deployment(resources = { "org/flowable/rest/service/api/repository/oneTaskProcess.bpmn20.xml" }) public void testCreateModel() throws Exception { Model model = null;/*from w w w . java 2s . co m*/ try { Calendar createTime = Calendar.getInstance(); createTime.set(Calendar.MILLISECOND, 0); processEngineConfiguration.getClock().setCurrentTime(createTime.getTime()); // Create create request ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("name", "Model name"); requestNode.put("category", "Model category"); requestNode.put("key", "Model key"); requestNode.put("metaInfo", "Model metainfo"); requestNode.put("deploymentId", deploymentId); requestNode.put("version", 2); requestNode.put("tenantId", "myTenant"); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION)); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertEquals("Model name", responseNode.get("name").textValue()); assertEquals("Model key", responseNode.get("key").textValue()); assertEquals("Model category", responseNode.get("category").textValue()); assertEquals(2, responseNode.get("version").intValue()); assertEquals("Model metainfo", responseNode.get("metaInfo").textValue()); assertEquals(deploymentId, responseNode.get("deploymentId").textValue()); assertEquals("myTenant", responseNode.get("tenantId").textValue()); assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime()); assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime()); assertTrue(responseNode.get("url").textValue().endsWith( RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, responseNode.get("id").textValue()))); assertTrue(responseNode.get("deploymentUrl").textValue() .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId))); model = repositoryService.createModelQuery().modelId(responseNode.get("id").textValue()).singleResult(); assertNotNull(model); assertEquals("Model category", model.getCategory()); assertEquals("Model name", model.getName()); assertEquals("Model key", model.getKey()); assertEquals(deploymentId, model.getDeploymentId()); assertEquals("Model metainfo", model.getMetaInfo()); assertEquals("myTenant", model.getTenantId()); assertEquals(2, model.getVersion().intValue()); } finally { if (model != null) { try { repositoryService.deleteModel(model.getId()); } catch (Throwable ignore) { } } } }
From source file:org.activiti.rest.content.service.api.content.ContentItemCollectionResourceTest.java
public void testCreateContentItem() throws Exception { ContentItem urlContentItem = null;// ww w .j a v a2 s. c o m try { ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("name", "Simple content item"); requestNode.put("mimeType", "application/pdf"); requestNode.put("taskId", "12345"); requestNode.put("processInstanceId", "123456"); requestNode.put("contentStoreId", "id"); requestNode.put("contentStoreName", "testStore"); requestNode.put("createdBy", "testa"); requestNode.put("lastModifiedBy", "testb"); HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + ContentRestUrls.createRelativeResourceUrl(ContentRestUrls.URL_CONTENT_ITEM_COLLECTION)); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); // Check if content item is created List<ContentItem> contentItems = contentService.createContentItemQuery().list(); assertEquals(1, contentItems.size()); urlContentItem = contentItems.get(0); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertEquals(urlContentItem.getId(), responseNode.get("id").asText()); assertEquals("Simple content item", responseNode.get("name").asText()); assertEquals("application/pdf", responseNode.get("mimeType").asText()); assertEquals("12345", responseNode.get("taskId").asText()); assertEquals("123456", responseNode.get("processInstanceId").asText()); assertEquals("id", responseNode.get("contentStoreId").asText()); assertEquals("testStore", responseNode.get("contentStoreName").asText()); assertEquals(false, responseNode.get("contentAvailable").asBoolean()); assertEquals("testa", responseNode.get("createdBy").asText()); assertEquals("testb", responseNode.get("lastModifiedBy").asText()); assertEquals(urlContentItem.getCreated(), getDateFromISOString(responseNode.get("created").asText())); assertEquals(urlContentItem.getLastModified(), getDateFromISOString(responseNode.get("lastModified").asText())); assertTrue(responseNode.get("url").textValue().endsWith(ContentRestUrls .createRelativeResourceUrl(ContentRestUrls.URL_CONTENT_ITEM, urlContentItem.getId()))); } finally { if (urlContentItem != null) { contentService.deleteContentItem(urlContentItem.getId()); } } }
From source file:org.activiti.rest.service.api.runtime.TaskVariableResourceTest.java
/** * Test updating a single task variable in all scopes, including "not found" check. * //from www. j ava 2 s . co m * PUT runtime/tasks/{taskId}/variables/{variableName} */ @Deployment public void testUpdateTaskVariable() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", Collections.singletonMap("overlappingVariable", (Object) "processValue")); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); taskService.setVariableLocal(task.getId(), "overlappingVariable", "taskValue"); // Update variable without scope, local should be presumed -> local updated and global should be retained ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("name", "overlappingVariable"); requestNode.put("value", "updatedLocalValue"); requestNode.put("type", "string"); HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls .createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE, task.getId(), "overlappingVariable")); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertEquals("updatedLocalValue", responseNode.get("value").asText()); assertEquals("local", responseNode.get("scope").asText()); // Check local value is changed in engine and global one remains unchanged assertEquals("updatedLocalValue", taskService.getVariableLocal(task.getId(), "overlappingVariable")); assertEquals("processValue", runtimeService.getVariable(task.getExecutionId(), "overlappingVariable")); // Update variable in local scope requestNode = objectMapper.createObjectNode(); requestNode.put("name", "overlappingVariable"); requestNode.put("value", "updatedLocalValueOnceAgain"); requestNode.put("type", "string"); requestNode.put("scope", "local"); httpPut.setEntity(new StringEntity(requestNode.toString())); response = executeRequest(httpPut, HttpStatus.SC_OK); responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertEquals("updatedLocalValueOnceAgain", responseNode.get("value").asText()); assertEquals("local", responseNode.get("scope").asText()); // Check local value is changed in engine and global one remains unchanged assertEquals("updatedLocalValueOnceAgain", taskService.getVariableLocal(task.getId(), "overlappingVariable")); assertEquals("processValue", runtimeService.getVariable(task.getExecutionId(), "overlappingVariable")); // Update variable in global scope requestNode = objectMapper.createObjectNode(); requestNode.put("name", "overlappingVariable"); requestNode.put("value", "updatedInGlobalScope"); requestNode.put("type", "string"); requestNode.put("scope", "global"); httpPut.setEntity(new StringEntity(requestNode.toString())); response = executeRequest(httpPut, HttpStatus.SC_OK); responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertEquals("updatedInGlobalScope", responseNode.get("value").asText()); assertEquals("global", responseNode.get("scope").asText()); // Check global value is changed in engine and local one remains unchanged assertEquals("updatedLocalValueOnceAgain", taskService.getVariableLocal(task.getId(), "overlappingVariable")); assertEquals("updatedInGlobalScope", runtimeService.getVariable(task.getExecutionId(), "overlappingVariable")); // Try updating with mismatch between URL and body variableName unexisting property requestNode.put("name", "unexistingVariable"); httpPut.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST)); // Try updating unexisting property requestNode.put("name", "unexistingVariable"); httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE, task.getId(), "unexistingVariable")); httpPut.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND)); }
From source file:com.almende.eve.algorithms.test.TestGraph.java
/** * Write visGraph./*from www .java 2 s . c om*/ * * @param agents * the agents * @return the string */ private String writeVisGraph(List<NodeAgent> agents) { final ObjectNode result = JOM.createObjectNode(); final ArrayNode nodes = JOM.createArrayNode(); final ArrayNode edges = JOM.createArrayNode(); for (NodeAgent agent : agents) { final ObjectNode node = JOM.createObjectNode(); node.put("id", agent.getId()); node.put("label", agent.getId()); nodes.add(node); for (Edge edge : agent.getGraph().getEdges()) { final ObjectNode edgeNode = JOM.createObjectNode(); edgeNode.put("from", agent.getId()); edgeNode.put("to", edge.getAddress().toASCIIString().replace("local:", "")); edges.add(edgeNode); } } result.set("nodes", nodes); result.set("edges", edges); return result.toString(); }
From source file:io.gs2.realtime.Gs2RealtimeClient.java
/** * ???<br>// ww w . j ava 2s.c o m * <br> * * @param request * @return ? */ public UpdateGatheringPoolResult updateGatheringPool(UpdateGatheringPoolRequest request) { ObjectNode body = JsonNodeFactory.instance.objectNode(); if (request.getDescription() != null) body.put("description", request.getDescription()); HttpPut put = createHttpPut(Gs2Constant.ENDPOINT_HOST + "/gatheringPool/" + (request.getGatheringPoolName() == null || request.getGatheringPoolName().equals("") ? "null" : request.getGatheringPoolName()) + "", credential, ENDPOINT, UpdateGatheringPoolRequest.Constant.MODULE, UpdateGatheringPoolRequest.Constant.FUNCTION, body.toString()); if (request.getRequestId() != null) { put.setHeader("X-GS2-REQUEST-ID", request.getRequestId()); } return doRequest(put, UpdateGatheringPoolResult.class); }
From source file:com.stratio.ingestion.sink.druid.DruidSinkIT.java
private Event getEvent(long offset) { ObjectNode jsonBody = new ObjectNode(JsonNodeFactory.instance); jsonBody.put("field1", "foo"); jsonBody.put("field2", 32); jsonBody.put("timestamp", String.valueOf(new Date().getTime())); Map<String, String> headers = new HashMap<String, String>(); headers.put("field3", "bar"); // Overwrites the value defined in JSON body headers.put("field4", "64"); headers.put("field5", "true"); headers.put("field6", "1.0"); headers.put("field7", "11"); final long l = new Date().getTime(); headers.put("timestamp", String.valueOf(l + offset)); headers.put("myString2", "baz"); return EventBuilder.withBody(jsonBody.toString().getBytes(Charsets.UTF_8), headers); }
From source file:org.activiti.app.service.editor.ActivitiDecisionTableService.java
public ModelRepresentation importDecisionTable(HttpServletRequest request, MultipartFile file) { String fileName = file.getOriginalFilename(); if (fileName != null && (fileName.endsWith(".dmn") || fileName.endsWith(".xml"))) { try {/*from w w w .j a va 2 s. co m*/ XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory(); InputStreamReader xmlIn = new InputStreamReader(file.getInputStream(), "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(xmlIn); DmnDefinition dmnDefinition = dmnXmlConverter.convertToDmnModel(xtr); ObjectNode editorJsonNode = dmnJsonConverter.convertToJson(dmnDefinition); // remove id to avoid InvalidFormatException when deserializing editorJsonNode.remove("id"); ModelRepresentation modelRepresentation = new ModelRepresentation(); modelRepresentation.setName(dmnDefinition.getName()); modelRepresentation.setDescription(dmnDefinition.getDescription()); modelRepresentation.setModelType(AbstractModel.MODEL_TYPE_DECISION_TABLE); Model model = modelService.createModel(modelRepresentation, editorJsonNode.toString(), SecurityUtils.getCurrentUserObject()); return new ModelRepresentation(model); } catch (Exception e) { logger.error("Could not import decision table model", e); throw new InternalServerErrorException("Could not import decision table model"); } } else { throw new BadRequestException( "Invalid file name, only .dmn or .xml files are supported not " + fileName); } }
From source file:com.delphix.delphix.DelphixEngine.java
/** * Get the provision defaults for provisioning from a snapshot *///www . j av a 2 s . c o m private String getProvisionDefaultsSnapshot(String snapshotRef) throws IOException, DelphixEngineException { DelphixSnapshot snapshot = getSnapshot(snapshotRef); JsonNode result = enginePOST(PATH_PROVISION_DEFAULTS, String.format(CONTENT_PROVISION_DEFAULTS_TIMESTAMP, snapshot.getTimeflowRef(), snapshot.getLatestChangePoint())); ObjectNode node = (ObjectNode) result.get(FIELD_RESULT); return node.toString(); }