List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get
public JsonNode get(String paramString)
From source file:com.almende.eve.agent.google.GoogleDirectionsAgent.java
/** * Retrieve the distance between origin to destination in readable text, * for example "74.2 km"/*from w ww. j a va2 s . co m*/ * * @param origin * the origin * @param destination * the destination * @return duration Distance in meters * @throws IOException * Signals that an I/O exception has occurred. * @throws InvalidKeyException * the invalid key exception * @throws NoSuchAlgorithmException * the no such algorithm exception * @throws URISyntaxException * the uRI syntax exception */ public String getDistanceHuman(@Name("origin") final String origin, @Name("destination") final String destination) throws IOException, InvalidKeyException, NoSuchAlgorithmException, URISyntaxException { final ObjectNode directions = getDirections(origin, destination); // TODO: check fields for being null final JsonNode routes = directions.get("routes"); final JsonNode route = routes.get(0); final JsonNode legs = route.get("legs"); final JsonNode leg = legs.get(0); final JsonNode jsonDistance = leg.get("distance"); final String distance = jsonDistance.get("text").asText(); return distance; }
From source file:org.lendingclub.mercator.aws.S3BucketScanner.java
private void scanBucket(Bucket b) { ObjectNode props = mapper.createObjectNode(); props.put("name", b.getName()); props.put("aws_arn", computeArn(props).orElse(null)); props.put("aws_account", getAccountId()); String cypher = "merge (b:AwsS3Bucket { aws_arn:{aws_arn} }) set b+={props}, b.updateTs=timestamp()"; getNeoRxClient().execCypher(cypher, "aws_arn", props.get("aws_arn"), "props", props).forEach(r -> { getShadowAttributeRemover().removeTagAttributes("AwsS3Bucket", props, r); });//from w w w.ja v a 2 s .c om incrementEntityCount(); cypher = "match (a:AwsAccount {aws_account:{account}}), (b:AwsS3Bucket {aws_account:{account}}) MERGE (a)-[r:OWNS]->(b) set r.updateTs=timestamp()"; getNeoRxClient().execCypher(cypher, "account", getAccountId()); }
From source file:com.ethlo.geodata.restdocs.AbstractJacksonFieldSnippet.java
protected void handleSchema(final Class<?> type, final ObjectNode root, final ObjectNode definitions, FieldDescriptor desc, final Iterator<String> path) { ObjectNode lastNode = (ObjectNode) root.get("properties"); Class<?> lastField = type; while (path.hasNext() && lastNode != null && lastField != null) { final String p = StringUtils.replace(path.next(), "[]", ""); final Field f = FieldUtils.getField(lastField, p, true); final Class<?> field = f != null ? (Collection.class.isAssignableFrom(f.getType()) ? (Class<?>) ((ParameterizedType) f.getGenericType()).getActualTypeArguments()[0] : f.getType()) : null;//from w w w.ja va 2 s. c o m final JsonNode currentNode = lastNode.get(p); if (currentNode instanceof ObjectNode && field != null) { if (!path.hasNext()) { // Leaf of path definition, set description final String description = desc.getDescription().toString(); ((ObjectNode) currentNode).put("description", description); } final String typeDef = currentNode.path("type").asText(); if (!StringUtils.isNotEmpty(typeDef)) { handleRef(field, root, definitions, (ObjectNode) currentNode, desc, path); } } lastNode = currentNode instanceof ObjectNode ? (ObjectNode) currentNode : null; lastField = field; } }
From source file:com.vz.onosproject.zeromqprovider.AppWebResource.java
/** * Installs flows to downstream ZMQ device * @param stream blob flowrule/* www . jav a2 s . c o m*/ * @return 200 OK */ @POST @Path("flows") @Consumes(MediaType.APPLICATION_JSON) public Response persisFlow(InputStream stream) { log.info("#### Pushing a flow"); ObjectNode jsonTree = null; List<String> devices = controller.getAvailableDevices(); try { jsonTree = (ObjectNode) mapper().readTree(stream); JsonNode devId = jsonTree.get("DeviceId"); JsonNode payload = jsonTree.get("Payload"); String sPayload = payload.toString(); log.info("Device Id" + devId.asText()); log.info("Payload Text value " + payload.textValue() + " toString " + payload.toString() + "Type " + payload.getNodeType().toString()); if (devId == null || devId.asText().isEmpty() || devices.contains(devId.asText()) == false) { throw new IllegalArgumentException(INVALID_DEVICEID); } if (payload == null || sPayload.isEmpty()) { throw new IllegalArgumentException(INVALID_FLOW); } DeviceId deviceId = DeviceId.deviceId(devId.asText()); Blob blob = new Blob(sPayload.getBytes()); store.InsertBlob(deviceId, blob); controller.writeToDevice(deviceId, blob); incrPostCount(); log.info("#### Total num of posts : " + getNumPostRecieved()); return Response.ok().build(); } catch (/*IO*/Exception e) { e.printStackTrace(); log.info("###### ERROR " + e.getMessage()); } return Response.noContent().build(); }
From source file:com.palominolabs.crm.sf.rest.HttpApiClientTest.java
@Test public void testCreateThenDelete() throws IOException { String createStr = createTask(); ObjectNode actual = MAPPER.readValue(createStr, ObjectNode.class); ObjectNode expected = MAPPER.readValue(ResourceUtil.readResource("/apiResponses/create.json"), ObjectNode.class); String id = actual.get("id").textValue(); // id changes every time expected.put("id", id); assertEquals(expected, actual);//w ww . ja v a2s . c o m client.delete("Task", new Id(id)); }
From source file:org.walkmod.conf.providers.yml.RemoveIncludesOrExcludesYMLAction.java
private void removesIncludesOrExcludesList(ObjectNode node) { ArrayNode wildcardArray = null;// w ww . j a va 2 s . c o m ArrayNode result = new ArrayNode(provider.getObjectMapper().getNodeFactory()); String label = "includes"; if (isExcludes) { label = "excludes"; } if (node.has(label)) { JsonNode wildcard = node.get(label); if (wildcard.isArray()) { wildcardArray = (ArrayNode) wildcard; } } if (wildcardArray != null) { int limit = wildcardArray.size(); for (int i = 0; i < limit; i++) { String aux = wildcardArray.get(i).asText(); if (!includes.contains(aux)) { result.add(wildcardArray.get(i)); } } } if (result.size() > 0) { node.set(label, result); } else { node.remove(label); } }
From source file:com.almende.eve.rpc.jsonrpc.JSONRequest.java
/** * Gets the param./*from w w w .ja v a 2 s .c o m*/ * * @param name the name * @return the param */ public Object getParam(final String name) { final ObjectMapper mapper = JOM.getInstance(); final ObjectNode params = req.with(PARAMS); if (params.has(name)) { return mapper.convertValue(params.get(name), Object.class); } return null; }
From source file:com.marklogic.samplestack.integration.service.QnAServiceIT.java
@Test public void testDefaultSearchService() throws JsonProcessingException { testComments(); // get a document in there. JsonNode structuredQuery = getTestJson("queries/blank.json"); // test view-all ObjectNode jsonResults = service.rawSearch(ClientRole.SAMPLESTACK_CONTRIBUTOR, structuredQuery, 1); logger.info(mapper.writeValueAsString(jsonResults)); assertTrue("Blank query got back results", jsonResults.get("results").size() > 0); assertEquals("Blank query got back facets", 2, jsonResults.get("facets").size()); assertNotNull("Blank query got back date facet", jsonResults.get("facets").get("date")); assertNotNull("Blank query got back tag facet", jsonResults.get("facets").get("tag")); }
From source file:com.yahoo.elide.extensions.JsonApiPatch.java
/** * Turn an exception into a proper error response from patch extension. *///from www. j av a 2 s .com private Pair<Integer, JsonNode> buildErrorResponse(HttpStatusException e, SecurityMode securityMode) { if (e.getStatus() == HttpStatus.SC_FORBIDDEN) { return securityMode == SecurityMode.SECURITY_ACTIVE_VERBOSE ? e.getVerboseErrorResponse() : e.getErrorResponse(); } ObjectNode errorContainer = getErrorContainer(); ArrayNode errorList = (ArrayNode) errorContainer.get("errors"); boolean failed = false; for (PatchAction action : actions) { failed = processAction(errorList, failed, action); } return Pair.of(HttpStatus.SC_BAD_REQUEST, errorContainer); }
From source file:de.thingweb.servient.ServientTestHttp.java
@Test public void readTD() throws Exception { String fromSrv = TestTools.fromUrl("http://localhost:8080/things/SimpleThing/.td"); String orig = readResource("simplething.jsonld"); orig = orig.replace("localhost", InetAddress.getLocalHost().getHostName()); ObjectNode srvJson = (ObjectNode) ContentHelper.readJSON(fromSrv); JsonNode origJson = ContentHelper.readJSON(orig); Thing td = ThingDescriptionParser.fromBytes(fromSrv.getBytes()); Thing reference = ThingDescriptionParser.fromBytes(orig.getBytes()); assertThat("jsonld context should match", srvJson.get("@context"), equalTo(origJson.get("@context"))); // assertThat("metadata content should match",srvJson.get("metadata"),equalTo(origJson.get("metadata"))); // assertThat("interactions should match",srvJson.get("interactions"),equalTo(origJson.get("interactions"))); // assertThat(ContentHelper.getJsonMapper().valueToTree(td),equalTo(ContentHelper.getJsonMapper().valueToTree(reference))); // TODO !//w w w.j a va 2 s .c o m }