List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString
public String toString()
From source file:com.netflix.metacat.usermetadata.mysql.MysqlUserMetadataService.java
@Override public void saveDefinitionMetadata(@Nonnull final QualifiedName name, @Nonnull final String userId, @Nonnull final Optional<ObjectNode> metadata, final boolean merge) { final Optional<ObjectNode> existingData = getDefinitionMetadata(name); final int count; if (existingData.isPresent() && metadata.isPresent()) { final ObjectNode merged = existingData.get(); if (merge) { metacatJson.mergeIntoPrimary(merged, metadata.get()); }//from w w w . j a v a 2 s . c o m count = executeUpdateForKey(SQL.UPDATE_DEFINITION_METADATA, merged.toString(), userId, name.toString()); } else if (metadata.isPresent()) { count = executeUpdateForKey(SQL.INSERT_DEFINITION_METADATA, metadata.get().toString(), userId, userId, name.toString()); } else { // Nothing to insert in this case count = 1; } if (count != 1) { throw new IllegalStateException("Expected one row to be insert or update for " + name); } }
From source file:com.syncedsynapse.kore2.jsonrpc.HostConnection.java
private Thread newListenerThread(final Socket socket) { // Launch a new thread to read from the socket return new Thread(new Runnable() { @Override/*from ww w. j a va 2 s. c o m*/ public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); try { LogUtils.LOGD(TAG, "Starting socket listener thread..."); // We're going to read from the socket. This will be a blocking call and // it will keep on going until disconnect() is called on this object. // Note: Mind the objects used here: we use createParser because it doesn't // close the socket after ObjectMapper.readTree. JsonParser jsonParser = objectMapper.getFactory().createParser(socket.getInputStream()); ObjectNode jsonResponse; while ((jsonResponse = objectMapper.readTree(jsonParser)) != null) { LogUtils.LOGD(TAG, "Read from socket: " + jsonResponse.toString()); // LogUtils.LOGD_FULL(TAG, "Read from socket: " + jsonResponse.toString()); handleTcpResponse(jsonResponse); } } catch (JsonProcessingException e) { LogUtils.LOGW(TAG, "Got an exception while parsing JSON response.", e); callErrorCallback(null, new ApiException(ApiException.INVALID_JSON_RESPONSE_FROM_HOST, e)); } catch (IOException e) { LogUtils.LOGW(TAG, "Error reading from socket.", e); disconnect(); callErrorCallback(null, new ApiException(ApiException.IO_EXCEPTION_WHILE_READING_RESPONSE, e)); } } }); }
From source file:org.activiti.rest.service.api.runtime.TaskResourceTest.java
/** * Test actions on an unexisting task. POST runtime/tasks/{taskId} *//*from w w w . java 2s .co m*/ public void testActionsUnexistingTask() throws Exception { ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("action", "complete"); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, "unexisting")); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_NOT_FOUND)); requestNode.put("action", "claim"); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_NOT_FOUND)); requestNode.put("action", "delegate"); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_NOT_FOUND)); requestNode.put("action", "resolve"); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_NOT_FOUND)); }
From source file:com.msopentech.odatajclient.testservice.utils.JSONUtilities.java
@Override protected InputStream replaceLink(final InputStream toBeChanged, final String linkName, final InputStream replacement) throws Exception { final ObjectMapper mapper = new ObjectMapper(); final ObjectNode toBeChangedNode = (ObjectNode) mapper.readTree(toBeChanged); final ObjectNode replacementNode = (ObjectNode) mapper.readTree(replacement); if (toBeChangedNode.get(linkName + JSON_NAVIGATION_SUFFIX) == null) { throw new NotFoundException(); }/*from w ww .j a v a 2 s. co m*/ toBeChangedNode.set(linkName, replacementNode.get(JSON_VALUE_NAME)); final JsonNode next = replacementNode.get(linkName + JSON_NEXTLINK_NAME); if (next != null) { toBeChangedNode.set(linkName + JSON_NEXTLINK_SUFFIX, next); } return IOUtils.toInputStream(toBeChangedNode.toString()); }
From source file:com.stratio.ingestion.sink.druid.DruidSinkIT.java
private Event getTrackerEvent() { Random random = new Random(); String[] users = new String[] { "user1@santander.com", "user2@santander.com", "user3@santander.com", "user4@santander.com" }; String[] isoCode = new String[] { "DE", "ES", "US", "FR" }; TimeUnit[] offset = new TimeUnit[] { TimeUnit.DAYS, TimeUnit.HOURS, TimeUnit.SECONDS }; ObjectNode jsonBody = new ObjectNode(JsonNodeFactory.instance); Map<String, String> headers; ObjectMapper mapper = new ObjectMapper(); JsonNode jsonNode = null;/*from w ww . java 2 s . co m*/ final String fileName = "/trackerSample" + random.nextInt(4) + ".json"; try { jsonNode = mapper.readTree(getClass().getResourceAsStream(fileName)); } catch (IOException e) { e.printStackTrace(); } headers = mapper.convertValue(jsonNode, Map.class); headers.put("timestamp", String.valueOf(new Date().getTime() + getOffset(offset[random.nextInt(3)]) * random.nextInt(100))); headers.put("santanderID", users[random.nextInt(4)]); headers.put("isoCode", isoCode[random.nextInt(4)]); return EventBuilder.withBody(jsonBody.toString().getBytes(Charsets.UTF_8), headers); }
From source file:org.activiti.rest.service.api.runtime.TaskResourceTest.java
/** * Test updating an unexisting task. PUT runtime/tasks/{taskId} *//*from w w w . j ava 2 s . c o m*/ public void testUpdateUnexistingTask() throws Exception { ObjectNode requestNode = objectMapper.createObjectNode(); // Execute the request with an empty request JSON-object HttpPut httpPut = new HttpPut( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, "unexistingtask")); httpPut.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND)); }
From source file:org.activiti.app.rest.editor.AbstractModelsResource.java
public ModelRepresentation importProcessModel(HttpServletRequest request, MultipartFile file) { String fileName = file.getOriginalFilename(); if (fileName != null && (fileName.endsWith(".bpmn") || fileName.endsWith(".bpmn20.xml"))) { try {/*from w w w . j av a 2 s. co m*/ XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory(); InputStreamReader xmlIn = new InputStreamReader(file.getInputStream(), "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(xmlIn); BpmnModel bpmnModel = bpmnXmlConverter.convertToBpmnModel(xtr); if (CollectionUtils.isEmpty(bpmnModel.getProcesses())) { throw new BadRequestException("No process found in definition " + fileName); } if (bpmnModel.getLocationMap().size() == 0) { BpmnAutoLayout bpmnLayout = new BpmnAutoLayout(bpmnModel); bpmnLayout.execute(); } ObjectNode modelNode = bpmnJsonConverter.convertToJson(bpmnModel); org.activiti.bpmn.model.Process process = bpmnModel.getMainProcess(); String name = process.getId(); if (StringUtils.isNotEmpty(process.getName())) { name = process.getName(); } String description = process.getDocumentation(); ModelRepresentation model = new ModelRepresentation(); model.setKey(process.getId()); model.setName(name); model.setDescription(description); model.setModelType(AbstractModel.MODEL_TYPE_BPMN); Model newModel = modelService.createModel(model, modelNode.toString(), SecurityUtils.getCurrentUserObject()); return new ModelRepresentation(newModel); } catch (BadRequestException e) { throw e; } catch (Exception e) { logger.error("Import failed for " + fileName, e); throw new BadRequestException( "Import failed for " + fileName + ", error message " + e.getMessage()); } } else { throw new BadRequestException( "Invalid file name, only .bpmn and .bpmn20.xml files are supported not " + fileName); } }
From source file:org.activiti.rest.service.api.repository.ModelResourceTest.java
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" }) public void testUpdateModel() throws Exception { Model model = null;/*from w w w. j av a 2 s . co m*/ try { Calendar createTime = Calendar.getInstance(); createTime.set(Calendar.MILLISECOND, 0); processEngineConfiguration.getClock().setCurrentTime(createTime.getTime()); model = repositoryService.newModel(); model.setCategory("Model category"); model.setKey("Model key"); model.setMetaInfo("Model metainfo"); model.setName("Model name"); model.setVersion(2); repositoryService.saveModel(model); Calendar updateTime = Calendar.getInstance(); updateTime.set(Calendar.MILLISECOND, 0); updateTime.add(Calendar.HOUR, 1); processEngineConfiguration.getClock().setCurrentTime(updateTime.getTime()); // Create update request ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("name", "Updated name"); requestNode.put("category", "Updated category"); requestNode.put("key", "Updated key"); requestNode.put("metaInfo", "Updated metainfo"); requestNode.put("deploymentId", deploymentId); requestNode.put("version", 3); requestNode.put("tenantId", "myTenant"); HttpPut httpPut = new HttpPut( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId())); 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("Updated name", responseNode.get("name").textValue()); assertEquals("Updated key", responseNode.get("key").textValue()); assertEquals("Updated category", responseNode.get("category").textValue()); assertEquals(3, responseNode.get("version").intValue()); assertEquals("Updated metainfo", responseNode.get("metaInfo").textValue()); assertEquals(deploymentId, responseNode.get("deploymentId").textValue()); assertEquals(model.getId(), responseNode.get("id").textValue()); assertEquals("myTenant", responseNode.get("tenantId").textValue()); assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime()); assertEquals(updateTime.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime()); assertTrue(responseNode.get("url").textValue() .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()))); assertTrue(responseNode.get("deploymentUrl").textValue() .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId))); } finally { try { repositoryService.deleteModel(model.getId()); } catch (Throwable ignore) { // Ignore, model might not be created } } }
From source file:org.flowable.rest.service.api.repository.ModelResourceTest.java
@Deployment(resources = { "org/flowable/rest/service/api/repository/oneTaskProcess.bpmn20.xml" }) public void testUpdateModel() throws Exception { Model model = null;/*from w w w . j a v a 2 s . c o m*/ try { Calendar createTime = Calendar.getInstance(); createTime.set(Calendar.MILLISECOND, 0); processEngineConfiguration.getClock().setCurrentTime(createTime.getTime()); model = repositoryService.newModel(); model.setCategory("Model category"); model.setKey("Model key"); model.setMetaInfo("Model metainfo"); model.setName("Model name"); model.setVersion(2); repositoryService.saveModel(model); Calendar updateTime = Calendar.getInstance(); updateTime.set(Calendar.MILLISECOND, 0); updateTime.add(Calendar.HOUR, 1); processEngineConfiguration.getClock().setCurrentTime(updateTime.getTime()); // Create update request ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("name", "Updated name"); requestNode.put("category", "Updated category"); requestNode.put("key", "Updated key"); requestNode.put("metaInfo", "Updated metainfo"); requestNode.put("deploymentId", deploymentId); requestNode.put("version", 3); requestNode.put("tenantId", "myTenant"); HttpPut httpPut = new HttpPut( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId())); 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("Updated name", responseNode.get("name").textValue()); assertEquals("Updated key", responseNode.get("key").textValue()); assertEquals("Updated category", responseNode.get("category").textValue()); assertEquals(3, responseNode.get("version").intValue()); assertEquals("Updated metainfo", responseNode.get("metaInfo").textValue()); assertEquals(deploymentId, responseNode.get("deploymentId").textValue()); assertEquals(model.getId(), responseNode.get("id").textValue()); assertEquals("myTenant", responseNode.get("tenantId").textValue()); assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime()); assertEquals(updateTime.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime()); assertTrue(responseNode.get("url").textValue() .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()))); assertTrue(responseNode.get("deploymentUrl").textValue() .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId))); } finally { try { repositoryService.deleteModel(model.getId()); } catch (Throwable ignore) { // Ignore, model might not be created } } }
From source file:org.activiti.rest.service.api.runtime.TaskResourceTest.java
/** * Test executing an invalid action on a single task. POST runtime/tasks/{taskId} *//*from w w w . j ava 2s. co m*/ public void testInvalidTaskAction() throws Exception { try { Task task = taskService.newTask(); taskService.saveTask(task); String taskId = task.getId(); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("action", "unexistingaction"); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId)); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST)); } 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()); } } }