List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get
public JsonNode get(String paramString)
From source file:com.ikanow.aleph2.graph.titan.utils.TitanGraphBuildingUtils.java
/** Previously our edges were double-grouped by in and out keys - now we can group them by the (in/out) pair * @param key/*w ww . j a va2s.c o m*/ * @param vertex_winner * @param mutable_edges * @return */ protected static Map<ObjectNode, List<ObjectNode>> finalEdgeGrouping(final ObjectNode key, final Vertex vertex_winner, final List<ObjectNode> mutable_edges) { final Map<ObjectNode, List<ObjectNode>> grouped_edges = mutable_edges.stream().filter(mutable_edge -> { final JsonNode in_key = mutable_edge.get(GraphAnnotationBean.inV); final JsonNode out_key = mutable_edge.get(GraphAnnotationBean.outV); final JsonNode matching_key = in_key.equals(key) // (has to be one of the 2 by construction) ? in_key : out_key; final JsonNode off_key = !in_key.equals(key) // (doesn't match this key) ? in_key : (!out_key.equals(key) ? out_key : null); // (a vertex can have an edge be to itself) if (null == off_key) { mutable_edge.put(GraphAnnotationBean.inV, (Long) vertex_winner.id()); mutable_edge.put(GraphAnnotationBean.outV, (Long) vertex_winner.id()); mutable_edge.set(GraphAnnotationBean.inVLabel, key); // (internal, see below) mutable_edge.set(GraphAnnotationBean.outVLabel, key); // (internal, see below) } else { mutable_edge.put((matching_key == in_key) ? GraphAnnotationBean.inV : GraphAnnotationBean.outV, (Long) vertex_winner.id()); mutable_edge.set( (matching_key == in_key) ? GraphAnnotationBean.inVLabel : GraphAnnotationBean.outVLabel, key); // (internal, see below) } return ((null == off_key) || off_key.isIntegralNumber()); }).collect(Collectors.groupingBy((ObjectNode mutable_edge) -> { // These edges are "promoted" - can call the user merge on them final ObjectNode edge_key = Optional.of(_mapper.createObjectNode()).map( o -> (ObjectNode) o.set(GraphAnnotationBean.label, mutable_edge.get(GraphAnnotationBean.label))) .map(o -> Optional.ofNullable(mutable_edge.remove(GraphAnnotationBean.inVLabel)) .map(k -> (ObjectNode) o.set(GraphAnnotationBean.inV, k)).orElse(o)) .map(o -> Optional.ofNullable(mutable_edge.remove(GraphAnnotationBean.outVLabel)) .map(k -> (ObjectNode) o.set(GraphAnnotationBean.outV, k)).orElse(o)) .get(); return edge_key; })); return grouped_edges; }
From source file:org.lendingclub.mercator.newrelic.NewRelicScanner.java
/** * Scans all the APM's in NewRelic and establishes relationship to servers * that are hosting them. In this way we know what all servers are hosting * a particular application./*from w w w .j ava 2 s . c om*/ * */ private void scanApms() { Instant startTime = Instant.now(); ObjectNode apps = getNewRelicClient().getApplications(); Preconditions.checkNotNull(getProjector().getNeoRxClient(), "neorx client must be set"); String cypher = "WITH {json} as data " + "UNWIND data.applications as app " + "MERGE (a:NewRelicApplication { nr_appId: toString(app.id), nr_accountId: {accountId}} ) " + "ON CREATE SET a.appName = app.name, a.lastReportedAt = app.last_reported_at, a.createTs = timestamp(), a.healthStatus = app.health_status, " + "a.reporting = app.reporting, a.language = app.language, a.updateTs = timestamp() " + "ON MATCH SET a.lastReportedAt = app.last_reported_at, a.reporting = app.reporting, a.healthStatus = app.health_status, a.updateTs = timestamp() " + "FOREACH ( sid IN app.links.servers | MERGE (s:NewRelicServer { nr_serverId: toString(sid), nr_accountId:{accountId} }) MERGE (a)-[:HOSTED_ON]->(s))"; getProjector().getNeoRxClient().execCypher(cypher, "json", apps, "accountId", clientSupplier.get().getAccountId()); Instant endTime = Instant.now(); logger.info("Updating neo4j with the latest information about {} NewRelic Applications took {} secs", apps.get("applications").size(), Duration.between(startTime, endTime).getSeconds()); }
From source file:com.appdynamics.analytics.processor.event.ElasticSearchEventService.java
private static void copyField(String fieldName, ObjectNode from, ObjectNode to) { /* 350 */ JsonNode fromNode = from.get(fieldName); /* 351 */ if (fromNode != null) { /* 352 */ to.setAll(ImmutableMap.of(fieldName, fromNode.deepCopy())); /* */ } /* */ }// w w w . j a v a 2 s. c o m
From source file:com.appdynamics.analytics.processor.event.ElasticSearchEventService.java
private static void addTimestampFields(ObjectNode body) /* */ {//from w w w . j ava 2s . co m /* 1464 */ JsonNode propNode = body.get("properties"); /* 1465 */ if (propNode == null) { /* 1466 */ return; /* */ } /* */ /* */ /* 1470 */ ObjectNode eventTimestampNode = Reader.DEFAULT_JSON_MAPPER.createObjectNode(); /* 1471 */ for (Map.Entry<String, String> entry : TIMESTAMP_PROPERTIES.entrySet()) { /* 1472 */ eventTimestampNode.put((String) entry.getKey(), (String) entry.getValue()); /* */ } /* 1474 */ ((ObjectNode) propNode).put("eventTimestamp", eventTimestampNode); /* */ /* 1476 */ ObjectNode pickupTimestampNode = Reader.DEFAULT_JSON_MAPPER.createObjectNode(); /* 1477 */ for (Map.Entry<String, String> entry : TIMESTAMP_PROPERTIES.entrySet()) { /* 1478 */ pickupTimestampNode.put((String) entry.getKey(), (String) entry.getValue()); /* */ } /* 1480 */ ((ObjectNode) propNode).put("pickupTimestamp", pickupTimestampNode); /* */ }
From source file:com.appdynamics.analytics.processor.event.ElasticSearchEventService.java
private static void amendSourceSettingsOnNode(ObjectNode eventTypeDefinition) { /* 1444 */ ObjectNode properties = (ObjectNode) eventTypeDefinition.get("properties"); /* 1445 */ if (properties != null) { /* 1446 */ for (JsonNode property : properties) { /* 1447 */ if (property.isObject()) { /* 1448 */ if ((property.has("type")) && (property.has("store"))) { /* 1449 */ ((ObjectNode) property).remove("store"); /* */ } /* 1451 */ amendSourceSettingsOnNode((ObjectNode) property); /* */ } /* */ } /* */ } /* */ }/*from www . jav a2 s . c o m*/
From source file:org.apache.streams.json.JsonPathFilter.java
@Override public List<StreamsDatum> process(StreamsDatum entry) { List<StreamsDatum> result = Lists.newArrayList(); String json = null;/*from w w w. ja v a2 s . c o m*/ ObjectNode document = null; LOGGER.debug("{} processing {}", STREAMS_ID); if (entry.getDocument() instanceof ObjectNode) { document = (ObjectNode) entry.getDocument(); try { json = mapper.writeValueAsString(document); } catch (JsonProcessingException e) { e.printStackTrace(); } } else if (entry.getDocument() instanceof String) { json = (String) entry.getDocument(); try { document = mapper.readValue(json, ObjectNode.class); } catch (IOException e) { e.printStackTrace(); return null; } } Preconditions.checkNotNull(document); if (StringUtils.isNotEmpty(json)) { Object srcResult = null; try { srcResult = jsonPath.read(json); } catch (Exception e) { e.printStackTrace(); LOGGER.warn(e.getMessage()); } Preconditions.checkNotNull(srcResult); String[] path = StringUtils.split(pathExpression, '.'); ObjectNode node = document; for (int i = 1; i < path.length - 1; i++) { node = (ObjectNode) document.get(path[i]); } Preconditions.checkNotNull(node); if (srcResult instanceof JSONArray) { try { ArrayNode jsonNode = mapper.convertValue(srcResult, ArrayNode.class); if (jsonNode.size() == 1) { JsonNode item = jsonNode.get(0); node.set(destNodeName, item); } else { node.set(destNodeName, jsonNode); } } catch (Exception e) { LOGGER.warn(e.getMessage()); } } else if (srcResult instanceof JSONObject) { try { ObjectNode jsonNode = mapper.convertValue(srcResult, ObjectNode.class); node.set(destNodeName, jsonNode); } catch (Exception e) { LOGGER.warn(e.getMessage()); } } else if (srcResult instanceof String) { try { node.put(destNodeName, (String) srcResult); } catch (Exception e) { LOGGER.warn(e.getMessage()); } } } result.add(new StreamsDatum(document)); return result; }
From source file:io.swagger.parser.util.SwaggerDeserializer.java
public ArrayNode getArray(String key, ObjectNode node, boolean required, String location, ParseResult result) { JsonNode value = node.get(key); ArrayNode an = null;// w w w .ja v a 2 s.c o m if (value == null) { if (required) { result.missing(location, key); result.invalid(); } } else if (!value.getNodeType().equals(JsonNodeType.ARRAY)) { result.invalidType(location, key, "array", value); } else { an = (ArrayNode) value; } return an; }
From source file:com.appdynamics.analytics.processor.event.ElasticSearchEventService.java
public static void performEventServiceMappingTransformation(ObjectNode mapping, boolean shouldApplyChangesForVersion2, boolean shouldDisableAllField) /* */ {/* w w w. j a v a2 s . c om*/ /* 1404 */ if (mapping.get("metaData") != null) { /* 1405 */ mapping.remove("metaData"); /* */ } /* */ /* 1408 */ addTimestampFields(mapping); /* 1409 */ removeSourceSettings(mapping); /* */ /* 1411 */ if (shouldApplyChangesForVersion2) { /* 1412 */ ElasticSearchMappingHelper.ensureStringNotAnalyzedDefault(mapping); /* 1413 */ ElasticSearchMappingHelper.ensureFieldDataOptimized(mapping); /* */ } /* */ /* 1416 */ ElasticSearchMappingHelper.ensureDocValues(mapping); /* */ /* 1418 */ if (shouldDisableAllField) { /* 1419 */ ObjectNode allDisabledNode = Reader.DEFAULT_JSON_MAPPER.createObjectNode(); /* 1420 */ allDisabledNode.put("enabled", false); /* */ /* 1422 */ mapping.put("_all", allDisabledNode); /* */ } /* */ }
From source file:io.swagger.parser.util.SwaggerDeserializer.java
public ObjectNode getObject(String key, ObjectNode node, boolean required, String location, ParseResult result) {// w ww.j av a2 s .co m JsonNode value = node.get(key); ObjectNode on = null; if (value == null) { if (required) { result.missing(location, key); result.invalid(); } } else if (!value.getNodeType().equals(JsonNodeType.OBJECT)) { result.invalidType(location, key, "object", value); if (required) { result.invalid(); } } else { on = (ObjectNode) value; } return on; }
From source file:io.swagger.parser.util.SwaggerDeserializer.java
public Model allOfModel(ObjectNode node, String location, ParseResult result) { JsonNode sub = node.get("$ref"); JsonNode allOf = node.get("allOf"); if (sub != null) { if (sub.getNodeType().equals(JsonNodeType.OBJECT)) { return refModel((ObjectNode) sub, location, result); } else {// w ww . j a va2s. c o m result.invalidType(location, "$ref", "object", sub); return null; } } else if (allOf != null) { ComposedModel model = null; // we only support one parent, no multiple inheritance or composition if (allOf.getNodeType().equals(JsonNodeType.ARRAY)) { model = new ComposedModel(); int pos = 0; for (JsonNode part : allOf) { if (part.getNodeType().equals(JsonNodeType.OBJECT)) { Model segment = definition((ObjectNode) part, location, result); if (segment != null) { model.getAllOf().add(segment); } } else { result.invalidType(location, "allOf[" + pos + "]", "object", part); } pos++; } List<Model> allComponents = model.getAllOf(); if (allComponents.size() >= 1) { model.setParent(allComponents.get(0)); if (allComponents.size() >= 2) { model.setChild(allComponents.get(allComponents.size() - 1)); List<RefModel> interfaces = new ArrayList<RefModel>(); int size = allComponents.size(); for (Model m : allComponents.subList(1, size - 1)) { if (m instanceof RefModel) { RefModel ref = (RefModel) m; interfaces.add(ref); } } model.setInterfaces(interfaces); } else { model.setChild(new ModelImpl()); } } return model; } else { result.invalidType(location, "allOf", "array", allOf); } return model; } return null; }