List of usage examples for com.fasterxml.jackson.databind.node ArrayNode add
public ArrayNode add(JsonNode paramJsonNode)
From source file:org.apache.streams.lucene.LuceneSimpleTaggingProcessor.java
@Override public List<StreamsDatum> process(StreamsDatum entry) { LOGGER.debug("{} processing {}", STREAMS_ID, entry.getDocument().getClass()); List<StreamsDatum> result = Lists.newArrayList(); List<String> jsons = Lists.newLinkedList(); ObjectNode node;/* ww w. jav a 2 s . c om*/ // first check for valid json if (this.metaDataKey == null) jsons.add(getJson(entry.getDocument())); else getMetaDataJsons(entry, jsons); for (String json : jsons) { try { node = (ObjectNode) mapper.readTree(json); } catch (IOException e) { e.printStackTrace(); return result; } List<SimpleVerbatim> verbatimList = convertEntryToWorkUnit(json); Map<SimpleVerbatim, List<LanguageTag>> objectTags = taggingEngine.findMatches(verbatimList); Set<String> tagSet = Sets.newHashSet(); for (List<LanguageTag> fieldtags : objectTags.values()) { for (LanguageTag tag : fieldtags) { tagSet.add(tag.getTag()); } } ArrayNode tagArray = JsonNodeFactory.instance.arrayNode(); Set<String> tags = Sets.newHashSet(); for (String tag : tagSet) { if (tags.add(tag)) { tagArray.add(tag); } } // need utility methods for get / create specific node ObjectNode extensions = (ObjectNode) node.get("extensions"); if (extensions == null) { extensions = JsonNodeFactory.instance.objectNode(); node.put("extensions", extensions); } ObjectNode w2o = (ObjectNode) extensions.get("w2o"); if (w2o == null) { w2o = JsonNodeFactory.instance.objectNode(); extensions.put("w2o", w2o); } w2o.put("tags", tagArray); w2o.put("contentTags", tagArray); if (entry.getDocument() instanceof W2OActivity) { entry.setDocument(mapper.convertValue(node, W2OActivity.class)); } else if (entry.getDocument() instanceof Activity) { entry.setDocument(mapper.convertValue(node, Activity.class)); } else if (entry.getDocument() instanceof String) { try { entry.setDocument(mapper.writeValueAsString(node)); } catch (JsonProcessingException jpe) { LOGGER.error("Exception while converting ObjectNode to string. Outputing as ObjectNode. {}", jpe); entry.setDocument(node); } } else { entry.setDocument(node); } result.add(entry); } return result; }
From source file:fr.gouv.vitam.query.construct.request.InRequest.java
/** * In Request constructor/*from w ww . j a v a 2 s . c o m*/ * * @param inRequest * in, nin * @param variableName * @param value * @throws InvalidCreateOperationException */ public InRequest(final REQUEST inRequest, final String variableName, final long value) throws InvalidCreateOperationException { super(); switch (inRequest) { case in: case nin: { if (variableName == null || variableName.trim().isEmpty()) { throw new InvalidCreateOperationException( "Request " + inRequest + " cannot be created with empty variable name"); } final ObjectNode sub = ((ObjectNode) currentObject).putObject(inRequest.exactToken()); final ArrayNode array = sub.putArray(variableName.trim()); array.add(value); longVals = new HashSet<Long>(); longVals.add(value); currentObject = array; currentREQUEST = inRequest; setReady(true); break; } default: throw new InvalidCreateOperationException("Request " + inRequest + " is not an In Request"); } }
From source file:fr.gouv.vitam.query.construct.request.InRequest.java
/** * In Request constructor//from www . j a v a 2 s. c om * * @param inRequest * in, nin * @param variableName * @param value * @throws InvalidCreateOperationException */ public InRequest(final REQUEST inRequest, final String variableName, final double value) throws InvalidCreateOperationException { super(); switch (inRequest) { case in: case nin: { if (variableName == null || variableName.trim().isEmpty()) { throw new InvalidCreateOperationException( "Request " + inRequest + " cannot be created with empty variable name"); } final ObjectNode sub = ((ObjectNode) currentObject).putObject(inRequest.exactToken()); final ArrayNode array = sub.putArray(variableName.trim()); array.add(value); doubleVals = new HashSet<Double>(); doubleVals.add(value); currentObject = array; currentREQUEST = inRequest; setReady(true); break; } default: throw new InvalidCreateOperationException("Request " + inRequest + " is not an In Request"); } }
From source file:fr.gouv.vitam.query.construct.request.InRequest.java
/** * In Request constructor/* ww w. j a v a2 s .c o m*/ * * @param inRequest * in, nin * @param variableName * @param value * @throws InvalidCreateOperationException */ public InRequest(final REQUEST inRequest, final String variableName, final String value) throws InvalidCreateOperationException { super(); switch (inRequest) { case in: case nin: { if (variableName == null || variableName.trim().isEmpty()) { throw new InvalidCreateOperationException( "Request " + inRequest + " cannot be created with empty variable name"); } final ObjectNode sub = ((ObjectNode) currentObject).putObject(inRequest.exactToken()); final ArrayNode array = sub.putArray(variableName.trim()); array.add(value); stringVals = new HashSet<String>(); stringVals.add(value); currentObject = array; currentREQUEST = inRequest; setReady(true); break; } default: throw new InvalidCreateOperationException("Request " + inRequest + " is not an In or Search Request"); } }
From source file:fr.gouv.vitam.query.construct.request.InRequest.java
/** * In Request constructor// ww w.j a v a 2 s . co m * * @param inRequest * in, nin * @param variableName * @param value * @throws InvalidCreateOperationException */ public InRequest(final REQUEST inRequest, final String variableName, final boolean value) throws InvalidCreateOperationException { super(); switch (inRequest) { case in: case nin: { if (variableName == null || variableName.trim().isEmpty()) { throw new InvalidCreateOperationException( "Request " + inRequest + " cannot be created with empty variable name"); } final ObjectNode sub = ((ObjectNode) currentObject).putObject(inRequest.exactToken()); final ArrayNode array = sub.putArray(variableName.trim()); array.add(value); booleanVals = new HashSet<Boolean>(); booleanVals.add(value); currentObject = array; currentREQUEST = inRequest; setReady(true); break; } default: throw new InvalidCreateOperationException("Request " + inRequest + " is not an In Request"); } }
From source file:org.wisdom.wamp.WampControllerPubSubTest.java
@Test public void testSubscriptionAndUnsubscriptionUsingURI() throws RegistryException { clear();/*w w w . java 2 s . co m*/ Json json = new JsonService(); WampController controller = createWampControllerAndConnectClient(json); final WampClient client = controller.getClientById(CLIENT_ID).getValue(); assertThat(client.isSubscribed("http://example.com:9001/wamp/topic")).isFalse(); clear(); ArrayNode msg = json.newArray(); msg.add(MessageType.SUBSCRIBE.code()); msg.add("http://example.com:9001/wamp/topic"); controller.onMessage(CLIENT_ID, msg); assertThat(client.isSubscribed("http://example.com:9001/wamp/topic")).isTrue(); msg = json.newArray(); msg.add(MessageType.UNSUBSCRIBE.code()); msg.add("http://example.com:9001/wamp/topic"); controller.onMessage(CLIENT_ID, msg); assertThat(client.isSubscribed("http://example.com:9001/wamp/topic")).isFalse(); }
From source file:org.wisdom.wamp.WampControllerPubSubTest.java
@Test public void testSubscriptionAndUnsubscriptionOfUnknownClients() throws RegistryException { clear();/*from w ww . j a v a 2 s. com*/ Json json = new JsonService(); WampController controller = createWampControllerAndConnectClient(json); final WampClient client = controller.getClientById(CLIENT_ID).getValue(); assertThat(client.isSubscribed("http://example.com:9001/wamp/topic")).isFalse(); clear(); assertThat(last()).isNull(); ArrayNode msg = json.newArray(); msg.add(MessageType.SUBSCRIBE.code()); msg.add("http://example.com:9001/wamp/topic"); controller.onMessage("unknown", msg); assertThat(last()).isNull(); msg = json.newArray(); msg.add(MessageType.UNSUBSCRIBE.code()); msg.add("http://example.com:9001/wamp/topic"); controller.onMessage("unknown", msg); assertThat(last()).isNull(); }
From source file:org.wisdom.wamp.WampControllerPubSubTest.java
@Test public void testSubscriptionAndUnsubscriptionUsingCURI() throws RegistryException { clear();//from w w w . j a v a 2s . c o m Json json = new JsonService(); WampController controller = createWampControllerAndConnectClient(json); final WampClient client = controller.getClientById(CLIENT_ID).getValue(); assertThat(client.isSubscribed("http://example.com:9001/wamp/topic")).isFalse(); client.registerPrefix("event", "http://example.com:9001/wamp/"); clear(); ArrayNode msg = json.newArray(); msg.add(MessageType.SUBSCRIBE.code()); msg.add("event:topic"); controller.onMessage(CLIENT_ID, msg); assertThat(client.isSubscribed("http://example.com:9001/wamp/topic")).isTrue(); msg = json.newArray(); msg.add(MessageType.UNSUBSCRIBE.code()); msg.add("event:topic"); controller.onMessage(CLIENT_ID, msg); assertThat(client.isSubscribed("http://example.com:9001/wamp/topic")).isFalse(); }
From source file:models.protocol.v2.MetricMessagesProcessor.java
private void processMetricsList(final MetricsList metricsList) { //TODO(barp): Map with a POJO mapper [MAI-184] final ObjectNode dataNode = JsonNodeFactory.instance.objectNode(); final ArrayNode services = JsonNodeFactory.instance.arrayNode(); for (final Map.Entry<String, Map<String, Set<String>>> service : metricsList.getMetrics().entrySet()) { final ObjectNode serviceObject = JsonNodeFactory.instance.objectNode(); serviceObject.put("name", service.getKey()); final ArrayNode metrics = JsonNodeFactory.instance.arrayNode(); for (final Map.Entry<String, Set<String>> metric : service.getValue().entrySet()) { final ObjectNode metricObject = JsonNodeFactory.instance.objectNode(); metricObject.put("name", metric.getKey()); final ArrayNode stats = JsonNodeFactory.instance.arrayNode(); for (final String statistic : metric.getValue()) { final ObjectNode statsObject = JsonNodeFactory.instance.objectNode(); statsObject.put("name", statistic); statsObject.set("children", JsonNodeFactory.instance.arrayNode()); stats.add(statsObject); }//www . j a va2 s .c o m metricObject.set("children", stats); metrics.add(metricObject); } serviceObject.set("children", metrics); services.add(serviceObject); } dataNode.set("metrics", services); _connectionContext.sendCommand(COMMAND_METRICS_LIST, dataNode); }
From source file:org.apache.drill.optiq.DrillJoinRel.java
@Override public int implement(DrillImplementor implementor) { final List<String> fields = getRowType().getFieldNames(); assert isUnique(fields); final int leftCount = left.getRowType().getFieldCount(); final List<String> leftFields = fields.subList(0, leftCount); final List<String> rightFields = fields.subList(leftCount, fields.size()); final int leftId = implementInput(implementor, 0, 0, left); final int rightId = implementInput(implementor, 1, leftCount, right); /*/* w w w. j a v a2s. co m*/ * E.g. { op: "join", left: 2, right: 4, conditions: [ {relationship: "==", left: "deptId", right: "deptId"} ] } */ final ObjectNode join = implementor.mapper.createObjectNode(); join.put("op", "join"); join.put("left", leftId); join.put("right", rightId); join.put("type", toDrill(joinType)); final ArrayNode conditions = implementor.mapper.createArrayNode(); join.put("conditions", conditions); for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) { final ObjectNode condition = implementor.mapper.createObjectNode(); condition.put("relationship", "=="); condition.put("left", leftFields.get(pair.left)); condition.put("right", rightFields.get(pair.right)); conditions.add(condition); } return implementor.add(join); }