List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString
public String toString()
From source file:org.activiti.rest.service.api.identity.UserResourceTest.java
/** * Test updating a single user passing in no fields in the json, user should remain unchanged. *///from ww w . java 2s .c om public void testUpdateUserNoFields() throws Exception { User savedUser = null; try { User newUser = identityService.newUser("testuser"); newUser.setFirstName("Fred"); newUser.setLastName("McDonald"); newUser.setEmail("no-reply@activiti.org"); identityService.saveUser(newUser); savedUser = newUser; ObjectNode taskUpdateRequest = objectMapper.createObjectNode(); HttpPut httpPut = new HttpPut( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId())); httpPut.setEntity(new StringEntity(taskUpdateRequest.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertEquals("testuser", responseNode.get("id").textValue()); assertEquals("Fred", responseNode.get("firstName").textValue()); assertEquals("McDonald", responseNode.get("lastName").textValue()); assertEquals("no-reply@activiti.org", responseNode.get("email").textValue()); assertTrue(responseNode.get("url").textValue() .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId()))); // Check user is updated in activiti newUser = identityService.createUserQuery().userId(newUser.getId()).singleResult(); assertEquals("McDonald", newUser.getLastName()); assertEquals("Fred", newUser.getFirstName()); assertEquals("no-reply@activiti.org", newUser.getEmail()); assertNull(newUser.getPassword()); } finally { // Delete user after test fails if (savedUser != null) { identityService.deleteUser(savedUser.getId()); } } }
From source file:org.apache.streams.cassandra.CassandraPersistWriter.java
@Override public void write(StreamsDatum streamsDatum) { ObjectNode node; if (streamsDatum.getDocument() instanceof String) { try {//from ww w . j av a2 s. c o m node = mapper.readValue((String) streamsDatum.getDocument(), ObjectNode.class); byte[] value = node.toString().getBytes(); String key = GuidUtils.generateGuid(node.toString()); if (!Objects.isNull(streamsDatum.getMetadata().get("id"))) { key = streamsDatum.getMetadata().get("id").toString(); } BoundStatement statement = insertStatement.bind(key, ByteBuffer.wrap(value)); insertBatch.add(statement); } catch (IOException ex) { LOGGER.warn("Failure adding object: {}", streamsDatum.getDocument().toString()); return; } } else { try { node = mapper.valueToTree(streamsDatum.getDocument()); byte[] value = node.toString().getBytes(); String key = GuidUtils.generateGuid(node.toString()); if (!Objects.isNull(streamsDatum.getId())) { key = streamsDatum.getId(); } BoundStatement statement = insertStatement.bind(key, ByteBuffer.wrap(value)); insertBatch.add(statement); } catch (Exception ex) { LOGGER.warn("Failure adding object: {}", streamsDatum.getDocument().toString()); return; } } flushIfNecessary(); }
From source file:org.activiti.rest.service.api.identity.GroupCollectionResourceTest.java
public void testCreateGroup() throws Exception { try {//ww w .j av a2 s. c o m ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("id", "testgroup"); requestNode.put("name", "Test group"); requestNode.put("type", "Test type"); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_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("testgroup", responseNode.get("id").textValue()); assertEquals("Test group", responseNode.get("name").textValue()); assertEquals("Test type", responseNode.get("type").textValue()); assertTrue(responseNode.get("url").textValue() .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup"))); assertNotNull(identityService.createGroupQuery().groupId("testgroup").singleResult()); } finally { try { identityService.deleteGroup("testgroup"); } catch (Throwable t) { // Ignore, user might not have been created by test } } }
From source file:com.funtl.framework.smoke.core.modules.act.service.ActModelService.java
/** * // w w w . j a v a 2 s.c om * * @throws UnsupportedEncodingException */ @Transactional(readOnly = false) public Model create(String name, String key, String description, String category) throws UnsupportedEncodingException { ObjectNode editorNode = objectMapper.createObjectNode(); editorNode.put("id", "canvas"); editorNode.put("resourceId", "canvas"); ObjectNode properties = objectMapper.createObjectNode(); properties.put("process_author", "lusifer"); editorNode.set("properties", properties); // editorNode.put("properties", properties); // - 2016-09-03 by Lusifer ObjectNode stencilset = objectMapper.createObjectNode(); stencilset.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#"); editorNode.set("stencilset", stencilset); // editorNode.put("stencilset", stencilset); // - 2016-09-03 by Lusifer Model modelData = repositoryService.newModel(); description = StringUtils.defaultString(description); modelData.setKey(StringUtils.defaultString(key)); modelData.setName(name); modelData.setCategory(category); modelData.setVersion(Integer.parseInt( String.valueOf(repositoryService.createModelQuery().modelKey(modelData.getKey()).count() + 1))); ObjectNode modelObjectNode = objectMapper.createObjectNode(); modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, name); modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, modelData.getVersion()); modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description); modelData.setMetaInfo(modelObjectNode.toString()); repositoryService.saveModel(modelData); repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8")); return modelData; }
From source file:org.activiti.rest.service.api.identity.GroupMembershipResourceTest.java
public void testCreateMembershipAlreadyExisting() throws Exception { try {/*from w w w.j a v a 2 s. co m*/ Group testGroup = identityService.newGroup("testgroup"); testGroup.setName("Test group"); testGroup.setType("Test type"); identityService.saveGroup(testGroup); User testUser = identityService.newUser("testuser"); identityService.saveUser(testUser); identityService.createMembership("testuser", "testgroup"); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("userId", "testuser"); HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_MEMBERSHIP_COLLECTION, "testgroup")); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_CONFLICT)); } finally { try { identityService.deleteGroup("testgroup"); } catch (Throwable ignore) { // Ignore, since the group may not have been created in the test // or already deleted } try { identityService.deleteUser("testuser"); } catch (Throwable ignore) { // Ignore, since the group may not have been created in the test // or already deleted } } }
From source file:com.globocom.grou.report.ts.opentsdb.OpenTSDBClient.java
private ArrayList<HashMap<String, Object>> doRequest(long testCreated, long testLastModified, List<Query> queries) { final ArrayList<HashMap<String, Object>> listOfResult = new ArrayList<>(); queries.forEach(query -> {/* ww w . ja va2 s . c om*/ String aggr = query.aggregator; String ds = query.downsample; ObjectNode jBody = JsonNodeFactory.instance.objectNode(); jBody.set("queries", mapper.valueToTree(Collections.singleton(query))); jBody.put("start", testCreated); jBody.put("end", testLastModified); String bodyRequest = jBody.toString(); Request requestQuery = HTTP_CLIENT.preparePost(OPENTSDB_URL + "/api/query").setBody(bodyRequest) .setHeader(CONTENT_TYPE, APPLICATION_JSON.toString()).build(); try { Response response = HTTP_CLIENT.executeRequest(requestQuery).get(); String body = response.getResponseBody(); ArrayList<HashMap<String, Object>> resultMap = mapper.readValue(body, typeRef); for (HashMap<String, Object> result : resultMap) result.put("aggr", aggr); resultMap.forEach(h -> listOfResult.add(renameMetricKey(h, aggr, ds))); } catch (InterruptedException | ExecutionException | IOException e) { if (LOGGER.isDebugEnabled()) LOGGER.error(e.getMessage(), e); } }); return listOfResult; }
From source file:io.pivio.server.document.SearchApiTest.java
@Test public void sortWithNotExistingFieldShouldGiveEmptyResultSet() throws IOException { ObjectNode searchQuery = objectMapper.createObjectNode(); searchQuery.putObject("match_all"); ResponseEntity<JsonNode> responseEntity = restTemplate .getForEntity(/* w w w.j a va 2s . c o m*/ "http://localhost:" + port + "/document?query=" + URLEncoder.encode(searchQuery.toString(), "UTF-8") + "&sort=notexisting:asc", JsonNode.class); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); }
From source file:com.stratio.ingestion.sink.druid.EventParserTest.java
private Event createEvent(String index) { ObjectNode jsonBody = new ObjectNode(JsonNodeFactory.instance); jsonBody.put("field1" + index, "foo"); jsonBody.put("field2" + index, 32); Map<String, String> headers = new HashMap<String, String>(); headers.put("header1" + index, "bar"); headers.put("header2" + index, "64"); headers.put("header3" + index, "true"); headers.put("header4" + index, "1.0"); headers.put("header5" + index, null); return EventBuilder.withBody(jsonBody.toString().getBytes(Charsets.UTF_8), headers); }
From source file:com.glaf.report.web.rest.MxReportFileResource.java
@GET @POST// ww w. java 2s .c o m @Path("/view") @ResponseBody @Produces({ MediaType.APPLICATION_OCTET_STREAM }) public byte[] view(@Context HttpServletRequest request, @Context UriInfo uriInfo) { String reportFileId = request.getParameter("reportFileId"); ReportFile reportFile = null; if (StringUtils.isNotEmpty(reportFileId)) { reportFile = reportFileService.getReportFile(reportFileId); } ObjectNode responseJSON = new ObjectMapper().createObjectNode(); if (reportFile != null) { // Map<String, UserProfile> userMap = // MxIdentityFactory.getUserProfileMap(); responseJSON = reportFile.toObjectNode(); } try { return responseJSON.toString().getBytes("UTF-8"); } catch (IOException e) { return responseJSON.toString().getBytes(); } }