List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString
public String toString()
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void updateTemporalCollectionForLSQT(String dbName, String collectionName, boolean enable) throws Exception { ObjectMapper mapper = new ObjectMapper(); ObjectNode rootNode = mapper.createObjectNode(); rootNode.put("lsqt-enabled", enable); // Set system time values ObjectNode automation = mapper.createObjectNode(); automation.put("enabled", true); rootNode.set("automation", automation); System.out.println(rootNode.toString()); DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002), new UsernamePasswordCredentials("admin", "admin")); HttpPut put = new HttpPut("http://localhost:8002/manage/v2/databases/" + dbName + "/temporal/collections/lsqt/properties?collection=" + collectionName); put.addHeader("Content-type", "application/json"); put.addHeader("accept", "application/json"); put.setEntity(new StringEntity(rootNode.toString())); HttpResponse response = client.execute(put); HttpEntity respEntity = response.getEntity(); if (response.getStatusLine().getStatusCode() == 400) { HttpEntity entity = response.getEntity(); String responseString = EntityUtils.toString(entity, "UTF-8"); System.out.println(responseString); } else if (respEntity != null) { // EntityUtils to get the response content String content = EntityUtils.toString(respEntity); System.out.println(content); System.out.println("Temporal collection: " + collectionName + " created"); System.out.println("=============================================================="); } else {/*from w w w.j a v a2s . c o m*/ System.out.println("No Proper Response"); } }
From source file:org.apache.syncope.core.workflow.activiti.ActivitiUserWorkflowAdapter.java
protected void exportProcessModel(final OutputStream os) { Model model = getModel(getProcessDefinition()); ObjectMapper objectMapper = new ObjectMapper(); try {//from w w w . j av a2 s. c om ObjectNode modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo()); modelNode.put(ModelDataJsonConstants.MODEL_ID, model.getId()); modelNode.replace(MODEL_DATA_JSON_MODEL, objectMapper.readTree(engine.getRepositoryService().getModelEditorSource(model.getId()))); os.write(modelNode.toString().getBytes()); } catch (IOException e) { LOG.error("While exporting workflow definition {}", model.getId(), e); } }
From source file:com.ikanow.aleph2.management_db.mongodb.services.TestIkanowV1SyncService_LibraryJars.java
@Test public void test_createDeleteLibraryBean() throws InterruptedException, ExecutionException, JsonProcessingException, IOException, ParseException { final String temp_dir = System.getProperty("java.io.tmpdir") + File.separator; @SuppressWarnings("unchecked") ICrudService<JsonNode> v1_share_db = this._service_context.getCoreManagementDbService() .getUnderlyingPlatformDriver(ICrudService.class, Optional.of("social.share")).get(); final DBCollection dbc = v1_share_db.getUnderlyingPlatformDriver(DBCollection.class, Optional.empty()) .get();//ww w .j ava 2 s .co m v1_share_db.deleteDatastore().get(); IManagementCrudService<SharedLibraryBean> library_db = this._service_context.getCoreManagementDbService() .getSharedLibraryStore(); library_db.deleteDatastore().get(); final ObjectMapper mapper = BeanTemplateUtils.configureMapper(Optional.empty()); final ObjectNode v1_share_1 = (ObjectNode) mapper .readTree(this.getClass().getResourceAsStream("test_v1_sync_sample_share.json")); final DBObject v1_share_1_dbo = (DBObject) JSON.parse(v1_share_1.toString()); v1_share_1_dbo.put("_id", new ObjectId(v1_share_1.get("_id").asText())); final String fileref_share = IOUtils .toString(this.getClass().getResourceAsStream("test_v1_sync_sample_share_fileref.json"), "UTF-8") .replace("XXX_TEMPDIR_XXX", temp_dir.replace("\\", "\\\\")); final ObjectNode v1_share_1b = (ObjectNode) mapper.readTree(fileref_share); final DBObject v1_share_1b_dbo = (DBObject) JSON.parse(v1_share_1b.toString()); v1_share_1b_dbo.put("_id", new ObjectId(v1_share_1b.get("_id").asText())); assertEquals(0L, (long) v1_share_db.countObjects().get()); dbc.save(v1_share_1_dbo); dbc.save(v1_share_1b_dbo); //v1_share_db.storeObjects(Arrays.asList(v1_share_1)).get(); assertEquals(2L, (long) v1_share_db.countObjects().get()); final ObjectNode v1_share_2 = (ObjectNode) mapper .readTree(this.getClass().getResourceAsStream("test_v1_sync_sample_share.json")); v1_share_2.set("_id", new TextNode("655d44e3347d336b3e8c4cbe")); final SharedLibraryBean share2 = IkanowV1SyncService_LibraryJars.getLibraryBeanFromV1Share(v1_share_2); library_db.storeObject(share2).get(); assertEquals(1L, (long) library_db.countObjects().get()); // Create directory FileUtils.forceMkdir(new File(temp_dir + "/library/")); FileUtils.deleteQuietly(new File(temp_dir + "/library/misc")); assertFalse(new File(temp_dir + "/library/misc").exists()); FileUtils.write(new File(temp_dir + "/v1_library.jar"), "test12345"); final GridFS share_fs = Mockito.mock(GridFS.class); final GridFSDBFile share_file = Mockito.mock(GridFSDBFile.class, new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { if (invocation.getMethod().getName().equals("writeTo")) { ByteArrayOutputStream baos = (ByteArrayOutputStream) invocation.getArguments()[0]; if (null != baos) { try { baos.write("test123".getBytes()); } catch (IOException e) { e.printStackTrace(); } } } return null; } }); Mockito.when(share_fs.find(Mockito.<ObjectId>any())).thenReturn(share_file); // Create Date modified_test = null; { final ManagementFuture<Supplier<Object>> res = IkanowV1SyncService_LibraryJars.createLibraryBean( v1_share_1.get("_id").asText(), library_db, _service_context.getStorageService(), true, v1_share_db, share_fs, _service_context); assertEquals("v1_" + v1_share_1.get("_id").asText(), res.get().get().toString()); // Wrote DB entry assertTrue(library_db.getObjectById(res.get().get().toString()).get().isPresent()); modified_test = library_db.getObjectById(res.get().get().toString()).get().get().modified(); // Created file: final File f = new File(temp_dir + "/library/misc/library.jar"); assertTrue(f.exists()); assertEquals("test123", FileUtils.readFileToString(f)); } // Create - use file reference { final ManagementFuture<Supplier<Object>> res = IkanowV1SyncService_LibraryJars.createLibraryBean( v1_share_1b.get("_id").asText(), library_db, _service_context.getStorageService(), true, v1_share_db, share_fs, _service_context); assertEquals("v1_" + v1_share_1b.get("_id").asText(), res.get().get().toString()); // Wrote DB entry assertTrue(library_db.getObjectById(res.get().get().toString()).get().isPresent()); modified_test = library_db.getObjectById(res.get().get().toString()).get().get().modified(); // Created file: final File f = new File(temp_dir + "/library/misc/v1_library.jar"); assertTrue(f.exists()); assertEquals("test12345", FileUtils.readFileToString(f)); } // Create duplicate { final ManagementFuture<Supplier<Object>> res = IkanowV1SyncService_LibraryJars.createLibraryBean( v1_share_1.get("_id").asText(), library_db, _service_context.getStorageService(), true, v1_share_db, share_fs, _service_context); try { res.get(); fail("Should have thrown dup error"); } catch (Exception e) { } // good } // Update { v1_share_1_dbo.put("modified", new Date()); dbc.save(v1_share_1_dbo); final GridFSDBFile share_file2 = Mockito.mock(GridFSDBFile.class, new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { if (invocation.getMethod().getName().equals("writeTo")) { ByteArrayOutputStream baos = (ByteArrayOutputStream) invocation.getArguments()[0]; if (null != baos) { try { baos.write("test1234".getBytes()); } catch (IOException e) { e.printStackTrace(); } } } return null; } }); Mockito.when(share_fs.find(Mockito.<ObjectId>any())).thenReturn(share_file2); final ManagementFuture<Supplier<Object>> res = IkanowV1SyncService_LibraryJars.createLibraryBean( v1_share_1.get("_id").asText(), library_db, _service_context.getStorageService(), false, v1_share_db, share_fs, _service_context); assertEquals("v1_" + v1_share_1.get("_id").asText(), res.get().get().toString()); // Wrote DB entry assertTrue(library_db.getObjectById(res.get().get().toString()).get().isPresent()); // Created file: final File f = new File(temp_dir + "/library/misc/library.jar"); assertTrue(f.exists()); assertEquals("test1234", FileUtils.readFileToString(f)); final Date modified_2 = library_db.getObjectById(res.get().get().toString()).get().get().modified(); assertTrue("Mod time should change " + modified_test + " < " + modified_2, modified_2.getTime() > modified_test.getTime()); } // Delete { IkanowV1SyncService_LibraryJars.deleteLibraryBean(v1_share_1.get("_id").asText(), library_db, _service_context.getStorageService()); assertFalse(library_db.getObjectById("v1_" + v1_share_1.get("_id").asText()).get().isPresent()); final File f = new File(temp_dir + "/library/misc/library.jar"); assertTrue(f.exists()); IkanowV1SyncService_LibraryJars.deleteLibraryBean(v1_share_2.get("_id").asText(), library_db, _service_context.getStorageService()); assertFalse(f.exists()); } }
From source file:org.apache.olingo.fit.utils.AbstractJSONUtilities.java
@Override public InputStream replaceProperty(final InputStream src, final InputStream replacement, final List<String> path, final boolean justValue) throws Exception { final ObjectMapper mapper = new ObjectMapper(); final ObjectNode srcNode = (ObjectNode) mapper.readTree(src); IOUtils.closeQuietly(src);/*from w w w. j ava2 s .c om*/ final JsonNode replacementNode; if (justValue) { replacementNode = new TextNode(IOUtils.toString(replacement)); } else { replacementNode = (ObjectNode) mapper.readTree(replacement); } IOUtils.closeQuietly(replacement); JsonNode node = srcNode; for (int i = 0; i < path.size() - 1; i++) { node = node.get(path.get(i)); if (node == null) { throw new NotFoundException(); } } ((ObjectNode) node).set(path.get(path.size() - 1), replacementNode); return IOUtils.toInputStream(srcNode.toString()); }
From source file:io.gs2.timer.Gs2TimerClient.java
/** * ?????<br>//from w w w .j a va2s . co m * <br> * ? timestamp ???????????<br> * ????1??URL?????<br> * <br> * ?????????????<br> * <br> * ????????<br> * ??????????????????????????<br> * <br> * ??????????????????????<br> * <br> * * @param request * @return ? */ public CreateTimerResult createTimer(CreateTimerRequest request) { ObjectNode body = JsonNodeFactory.instance.objectNode().put("callbackMethod", request.getCallbackMethod()) .put("callbackUrl", request.getCallbackUrl()).put("executeTime", request.getExecuteTime()); if (request.getCallbackBody() != null) body.put("callbackBody", request.getCallbackBody()); if (request.getRetryMax() != null) body.put("retryMax", request.getRetryMax()); HttpPost post = createHttpPost( Gs2Constant.ENDPOINT_HOST + "/timerPool/" + (request.getTimerPoolName() == null || request.getTimerPoolName().equals("") ? "null" : request.getTimerPoolName()) + "/timer", credential, ENDPOINT, CreateTimerRequest.Constant.MODULE, CreateTimerRequest.Constant.FUNCTION, body.toString()); if (request.getRequestId() != null) { post.setHeader("X-GS2-REQUEST-ID", request.getRequestId()); } return doRequest(post, CreateTimerResult.class); }
From source file:org.flowable.rest.service.api.runtime.ExecutionResourceTest.java
/** * Test signalling a single execution, with signal event. */// w ww. j a va2 s . c o m @Deployment(resources = { "org/flowable/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" }) public void testSignalEventExecutionWithvariables() 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, waitingExecution.getId())); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK); closeResponse(response); // 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.ExecutionResourceTest.java
/** * Test signalling a single execution, with signal event. *///from www . java 2 s . c o m @Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" }) public void testSignalEventExecutionWithvariables() 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, waitingExecution.getId())); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK); closeResponse(response); // 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.almende.eve.test.agents.Test2Agent.java
/** * Ping callback.//from w w w . j a v a 2 s . c o m * * @param params * the params */ public void pingCallback(@Name("params") final ObjectNode params) { System.out.println("pingCallback " + getId() + " " + params.toString()); }
From source file:io.gs2.inbox.Gs2InboxClient.java
/** * ????<br>/*from ww w. jav a2 s . co m*/ * <br> * - : 10<br> * <br> * * @param request * @return ? */ public ReadMessageResult readMessage(ReadMessageRequest request) { ObjectNode body = JsonNodeFactory.instance.objectNode(); HttpPost post = createHttpPost( Gs2Constant.ENDPOINT_HOST + "/inbox/" + (request.getInboxName() == null || request.getInboxName().equals("") ? "null" : request.getInboxName()) + "/message/" + (request.getMessageId() == null || request.getMessageId().equals("") ? "null" : request.getMessageId()) + "", credential, ENDPOINT, ReadMessageRequest.Constant.MODULE, ReadMessageRequest.Constant.FUNCTION, body.toString()); if (request.getRequestId() != null) { post.setHeader("X-GS2-REQUEST-ID", request.getRequestId()); } post.setHeader("X-GS2-ACCESS-TOKEN", request.getAccessToken()); return doRequest(post, ReadMessageResult.class); }
From source file:org.flowable.rest.service.api.runtime.ExecutionResourceTest.java
/** * Test messaging a single execution with variables. *//*w ww .ja v a 2 s. c o m*/ @Deployment(resources = { "org/flowable/rest/service/api/runtime/ExecutionResourceTest.process-with-message-event.bpmn20.xml" }) public void testMessageEventExecutionWithvariables() throws Exception { Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne"); assertNotNull(signalExecution); ArrayNode variables = objectMapper.createArrayNode(); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("action", "messageEventReceived"); requestNode.put("messageName", "paymentMessage"); 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, waitingExecution.getId())); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK); closeResponse(response); // 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")); }