List of usage examples for com.fasterxml.jackson.databind.node ArrayNode add
public ArrayNode add(JsonNode paramJsonNode)
From source file:org.activiti.rest.service.api.history.HistoricProcessInstanceQueryResourceTest.java
/** * Test querying historic process instance based on variables. POST query/historic-process-instances *//*from w ww .j a va2 s . c o m*/ @Deployment public void testQueryProcessInstancesWithVariables() throws Exception { HashMap<String, Object> processVariables = new HashMap<String, Object>(); processVariables.put("stringVar", "Azerty"); processVariables.put("intVar", 67890); processVariables.put("booleanVar", false); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); taskService.complete(task.getId()); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables); String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_QUERY); // Process variables ObjectNode requestNode = objectMapper.createObjectNode(); ArrayNode variableArray = objectMapper.createArrayNode(); ObjectNode variableNode = objectMapper.createObjectNode(); variableArray.add(variableNode); requestNode.put("variables", variableArray); // String equals variableNode.put("name", "stringVar"); variableNode.put("value", "Azerty"); variableNode.put("operation", "equals"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // Integer equals variableNode.removeAll(); variableNode.put("name", "intVar"); variableNode.put("value", 67890); variableNode.put("operation", "equals"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // Boolean equals variableNode.removeAll(); variableNode.put("name", "booleanVar"); variableNode.put("value", false); variableNode.put("operation", "equals"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // String not equals variableNode.removeAll(); variableNode.put("name", "stringVar"); variableNode.put("value", "ghijkl"); variableNode.put("operation", "notEquals"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // Integer not equals variableNode.removeAll(); variableNode.put("name", "intVar"); variableNode.put("value", 45678); variableNode.put("operation", "notEquals"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // Boolean not equals variableNode.removeAll(); variableNode.put("name", "booleanVar"); variableNode.put("value", true); variableNode.put("operation", "notEquals"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // String equals ignore case variableNode.removeAll(); variableNode.put("name", "stringVar"); variableNode.put("value", "azeRTY"); variableNode.put("operation", "equalsIgnoreCase"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // String not equals ignore case (not supported) variableNode.removeAll(); variableNode.put("name", "stringVar"); variableNode.put("value", "HIJKLm"); variableNode.put("operation", "notEqualsIgnoreCase"); assertErrorResult(url, requestNode, HttpStatus.SC_BAD_REQUEST); // String equals without value variableNode.removeAll(); variableNode.put("value", "Azerty"); variableNode.put("operation", "equals"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // String equals with non existing value variableNode.removeAll(); variableNode.put("value", "Azerty2"); variableNode.put("operation", "equals"); assertResultsPresentInPostDataResponse(url, requestNode); // String like ignore case variableNode.removeAll(); variableNode.put("name", "stringVar"); variableNode.put("value", "azerty"); variableNode.put("operation", "likeIgnoreCase"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); variableNode.removeAll(); variableNode.put("name", "stringVar"); variableNode.put("value", "azerty2"); variableNode.put("operation", "likeIgnoreCase"); assertResultsPresentInPostDataResponse(url, requestNode); requestNode = objectMapper.createObjectNode(); requestNode.put("finished", true); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("finished", false); assertResultsPresentInPostDataResponse(url, requestNode, processInstance2.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("processDefinitionId", processInstance.getProcessDefinitionId()); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("processDefinitionKey", "oneTaskProcess"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("processDefinitionKey", "oneTaskProcess"); HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url + "?sort=startTime"); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK); // Check status and size JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data"); closeResponse(response); assertEquals(2, dataNode.size()); assertEquals(processInstance.getId(), dataNode.get(0).get("id").asText()); assertEquals(processInstance2.getId(), dataNode.get(1).get("id").asText()); }
From source file:org.flowable.rest.service.api.history.HistoricProcessInstanceQueryResourceTest.java
/** * Test querying historic process instance based on variables. POST query/historic-process-instances *///from w w w .j ava 2 s . c o m @Deployment public void testQueryProcessInstancesWithVariables() throws Exception { HashMap<String, Object> processVariables = new HashMap<String, Object>(); processVariables.put("stringVar", "Azerty"); processVariables.put("intVar", 67890); processVariables.put("booleanVar", false); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); taskService.complete(task.getId()); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables); String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_QUERY); // Process variables ObjectNode requestNode = objectMapper.createObjectNode(); ArrayNode variableArray = objectMapper.createArrayNode(); ObjectNode variableNode = objectMapper.createObjectNode(); variableArray.add(variableNode); requestNode.set("variables", variableArray); // String equals variableNode.put("name", "stringVar"); variableNode.put("value", "Azerty"); variableNode.put("operation", "equals"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // Integer equals variableNode.removeAll(); variableNode.put("name", "intVar"); variableNode.put("value", 67890); variableNode.put("operation", "equals"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // Boolean equals variableNode.removeAll(); variableNode.put("name", "booleanVar"); variableNode.put("value", false); variableNode.put("operation", "equals"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // String not equals variableNode.removeAll(); variableNode.put("name", "stringVar"); variableNode.put("value", "ghijkl"); variableNode.put("operation", "notEquals"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // Integer not equals variableNode.removeAll(); variableNode.put("name", "intVar"); variableNode.put("value", 45678); variableNode.put("operation", "notEquals"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // Boolean not equals variableNode.removeAll(); variableNode.put("name", "booleanVar"); variableNode.put("value", true); variableNode.put("operation", "notEquals"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // String equals ignore case variableNode.removeAll(); variableNode.put("name", "stringVar"); variableNode.put("value", "azeRTY"); variableNode.put("operation", "equalsIgnoreCase"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // String not equals ignore case (not supported) variableNode.removeAll(); variableNode.put("name", "stringVar"); variableNode.put("value", "HIJKLm"); variableNode.put("operation", "notEqualsIgnoreCase"); assertErrorResult(url, requestNode, HttpStatus.SC_BAD_REQUEST); // String equals without value variableNode.removeAll(); variableNode.put("value", "Azerty"); variableNode.put("operation", "equals"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); // String equals with non existing value variableNode.removeAll(); variableNode.put("value", "Azerty2"); variableNode.put("operation", "equals"); assertResultsPresentInPostDataResponse(url, requestNode); // String like ignore case variableNode.removeAll(); variableNode.put("name", "stringVar"); variableNode.put("value", "azerty"); variableNode.put("operation", "likeIgnoreCase"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); variableNode.removeAll(); variableNode.put("name", "stringVar"); variableNode.put("value", "azerty2"); variableNode.put("operation", "likeIgnoreCase"); assertResultsPresentInPostDataResponse(url, requestNode); requestNode = objectMapper.createObjectNode(); requestNode.put("finished", true); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("finished", false); assertResultsPresentInPostDataResponse(url, requestNode, processInstance2.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("processDefinitionId", processInstance.getProcessDefinitionId()); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("processDefinitionKey", "oneTaskProcess"); assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("processDefinitionKey", "oneTaskProcess"); HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url + "?sort=startTime"); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK); // Check status and size JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data"); closeResponse(response); assertEquals(2, dataNode.size()); assertEquals(processInstance.getId(), dataNode.get(0).get("id").asText()); assertEquals(processInstance2.getId(), dataNode.get(1).get("id").asText()); }
From source file:org.apache.taverna.tavlang.tools.convert.ToJson.java
public ObjectNode toJson(WorkflowBundle wfBundle) { ObjectNode root = mapper.createObjectNode(); ArrayNode contextList = root.arrayNode(); root.put("@context", contextList); ObjectNode context = root.objectNode(); contextList.add("https://w3id.org/scufl2/context"); contextList.add(context);/*w w w . jav a 2s.com*/ URI base = wfBundle.getGlobalBaseURI(); context.put("@base", base.toASCIIString()); root.put("id", base.toASCIIString()); // root.put("name", wfBundle.getName()); // root.put("revisions", toJson(wfBundle.getCurrentRevision())); root.put("workflow", toJson(wfBundle.getMainWorkflow())); root.put("profile", toJson(wfBundle.getMainProfile())); return root; }
From source file:net.pterodactylus.sone.web.ajax.GetStatusAjaxPage.java
/** * {@inheritDoc}//from ww w . j a v a2 s . c o m */ @Override protected JsonReturnObject createJsonObject(FreenetRequest request) { final Sone currentSone = getCurrentSone(request.getToadletContext(), false); /* load Sones. always return the status of the current Sone. */ Set<Sone> sones = new HashSet<Sone>( Collections.singleton(getCurrentSone(request.getToadletContext(), false))); String loadSoneIds = request.getHttpRequest().getParam("soneIds"); if (loadSoneIds.length() > 0) { String[] soneIds = loadSoneIds.split(","); for (String soneId : soneIds) { /* just add it, we skip null further down. */ sones.add(webInterface.getCore().getSone(soneId).orNull()); } } ArrayNode jsonSones = new ArrayNode(instance); for (Sone sone : sones) { if (sone == null) { continue; } jsonSones.add(createJsonSone(sone)); } /* load notifications. */ List<Notification> notifications = ListNotificationFilters .filterNotifications(webInterface.getNotifications().getNotifications(), currentSone); Collections.sort(notifications, Notification.CREATED_TIME_SORTER); /* load new posts. */ Collection<Post> newPosts = webInterface.getNewPosts(); if (currentSone != null) { newPosts = Collections2.filter(newPosts, new Predicate<Post>() { @Override public boolean apply(Post post) { return ListNotificationFilters.isPostVisible(currentSone, post); } }); } ArrayNode jsonPosts = new ArrayNode(instance); for (Post post : newPosts) { ObjectNode jsonPost = new ObjectNode(instance); jsonPost.put("id", post.getId()); jsonPost.put("sone", post.getSone().getId()); jsonPost.put("recipient", post.getRecipientId().orNull()); jsonPost.put("time", post.getTime()); jsonPosts.add(jsonPost); } /* load new replies. */ Collection<PostReply> newReplies = webInterface.getNewReplies(); if (currentSone != null) { newReplies = Collections2.filter(newReplies, new Predicate<PostReply>() { @Override public boolean apply(PostReply reply) { return ListNotificationFilters.isReplyVisible(currentSone, reply); } }); } /* remove replies to unknown posts. */ newReplies = Collections2.filter(newReplies, PostReply.HAS_POST_FILTER); ArrayNode jsonReplies = new ArrayNode(instance); for (PostReply reply : newReplies) { ObjectNode jsonReply = new ObjectNode(instance); jsonReply.put("id", reply.getId()); jsonReply.put("sone", reply.getSone().getId()); jsonReply.put("post", reply.getPostId()); jsonReply.put("postSone", reply.getPost().get().getSone().getId()); jsonReplies.add(jsonReply); } return createSuccessJsonObject().put("loggedIn", currentSone != null) .put("options", createJsonOptions(currentSone)).put("sones", jsonSones) .put("notificationHash", notifications.hashCode()).put("newPosts", jsonPosts) .put("newReplies", jsonReplies); }
From source file:com.attribyte.essem.DefaultResponseGenerator.java
@Override public boolean generateGraph(GraphQuery graphQuery, Response esResponse, EnumSet<Option> options, RateUnit rateUnit, HttpServletResponse response) throws IOException { ObjectNode jsonObject = mapper.readTree(parserFactory.createParser(esResponse.getBody().toByteArray())); ObjectNode responseObject = JsonNodeFactory.instance.objectNode(); List<String> fields = ImmutableList.copyOf(graphQuery.searchRequest.fields); ObjectNode targetMeta = JsonNodeFactory.instance.objectNode(); ArrayNode targetGraphs = responseObject.putArray("graphs"); if (graphQuery.range.expression != null) { targetMeta.put("range", graphQuery.range.expression); }/*from w w w . j a v a 2 s . c om*/ if (graphQuery.range.startTimestamp > 0L) { targetMeta.put("rangeStartTimestamp", graphQuery.range.startTimestamp); } if (graphQuery.range.endTimestamp > 0L) { targetMeta.put("rangeEndTimestamp", graphQuery.range.endTimestamp); } JsonNode aggregations = jsonObject.get("aggregations"); if (aggregations != null && aggregations.isObject()) { ArrayNode metaFields = targetMeta.putArray("fields"); metaFields.add("timestamp"); metaFields.add("samples"); for (String field : fields) { metaFields.add(field); } if (graphQuery.downsampleInterval != null) { targetMeta.put("downsampledTo", graphQuery.downsampleInterval); } if (graphQuery.downsampleFunction != null) { targetMeta.put("downsampledWith", graphQuery.downsampleFunction); } String error = parseGraphAggregation(aggregations, fields, rateUnit, targetMeta, targetGraphs); if (error == null) { generateGraph(responseObject, response); return true; } else { response.sendError(500, error); return false; } } else { ArrayNode metaFields = targetMeta.putArray("fields"); metaFields.add("timestamp"); metaFields.add("samples"); for (String field : fields) { if (!graphIgnoreProperties.contains(field)) { metaFields.add(field); } } parseGraph(jsonObject, fields, rateUnit, targetMeta, targetGraphs); generateGraph(responseObject, response); return true; } }
From source file:net.logstash.logback.LogstashFormatter.java
private ArrayNode createTags(ILoggingEvent event) { ArrayNode node = null; final Marker marker = event.getMarker(); if (marker != null) { node = MAPPER.createArrayNode(); if (!marker.getName().equals("JSON")) { node.add(marker.getName()); }/*from w ww . j a v a2s . c o m*/ if (marker.hasReferences()) { final Iterator<?> i = event.getMarker().iterator(); while (i.hasNext()) { Marker next = (Marker) i.next(); // attached markers will never be null as provided by the MarkerFactory. if (!marker.getName().equals("JSON")) { node.add(next.getName()); } } } } return node; }
From source file:com.redhat.smonkey.Monkey.java
private JsonNode generateArrayNode(ArrayNode templateNode) { ArrayNode node = nodeFactory.arrayNode(); for (Iterator<JsonNode> elements = templateNode.elements(); elements.hasNext();) { JsonNode element = elements.next(); JsonNode value = generateNode(element); if (value != FIELD_DOES_NOT_EXIST) node.add(value); }// ww w .j av a2 s .co m return node; }
From source file:io.macgyver.neorx.rest.NeoRxClient.java
protected ObjectNode createParameters(Object... args) { checkNotNull(args);//w w w . ja v a2s . c o m checkArgument(args.length % 2 == 0, "must be an even number of arguments (key/value pairs)"); ObjectNode n = mapper.createObjectNode(); for (int i = 0; i < args.length; i += 2) { String key = args[i].toString(); Object val = args[i + 1]; if (val == null) { n.set(key, NullNode.getInstance()); } else if (val instanceof String) { n.put(key, val.toString()); } else if (val instanceof Integer) { n.put(key, (Integer) val); } else if (val instanceof Long) { n.put(key, (Long) val); } else if (val instanceof Double) { n.put(key, (Double) val); } else if (val instanceof Boolean) { n.put(key, (Boolean) val); } else if (val instanceof List) { ArrayNode an = mapper.createArrayNode(); for (Object item : (List) val) { an.add(item.toString()); } n.set(key, an); } else if (val instanceof Map) { n.set(key, mapToObjectNode((Map) val)); } else if (val instanceof ObjectNode) { n.set(key, (ObjectNode) val); } else if (val instanceof ArrayNode) { n.set(key, (ArrayNode) val); } else if (val instanceof JsonNode) { JsonNode x = (JsonNode) val; if (x.isValueNode()) { n.set(key, x); } else { throw new IllegalArgumentException( "parameter '" + key + "' type not supported: " + val.getClass().getName()); } } else { throw new IllegalArgumentException( "parameter '" + key + "' type not supported: " + val.getClass().getName()); } } return n; }
From source file:com.github.fge.jsonschema.keyword.digest.draftv3.DraftV3PropertiesDigester.java
@Override public JsonNode digest(final JsonNode schema) { // TODO: return an array directly (same for "required" in v4) final ObjectNode ret = FACTORY.objectNode(); final ArrayNode required = FACTORY.arrayNode(); ret.put("required", required); final JsonNode node = schema.get(keyword); final List<String> list = Lists.newArrayList(node.fieldNames()); Collections.sort(list);/*ww w. j a v a 2s . co m*/ for (final String field : list) if (node.get(field).path("required").asBoolean(false)) required.add(field); return ret; }
From source file:org.onosproject.sse.SseTopologyResource.java
private void addGeoData(ArrayNode array, String idField, String id, ObjectNode memento) { ObjectNode node = mapper.createObjectNode().put(idField, id); ObjectNode annot = mapper.createObjectNode(); node.set("annotations", annot); try {//from www.j a v a 2 s .c om annot.put("latitude", memento.get("lat").asDouble()).put("longitude", memento.get("lng").asDouble()); array.add(node); } catch (Exception e) { log.debug("Skipping geo entry"); } }