List of usage examples for com.fasterxml.jackson.databind.node ArrayNode add
public ArrayNode add(JsonNode paramJsonNode)
From source file:fr.gouv.vitam.query.construct.request.MltRequest.java
/** * MoreLikeThis Request constructor/*from w w w. ja v a2 s. c om*/ * * @param mltRequest * flt, mlt * @param value * @param variableNames * @throws InvalidCreateOperationException */ public MltRequest(final REQUEST mltRequest, final String value, final String... variableNames) throws InvalidCreateOperationException { super(); if (value == null || value.trim().isEmpty()) { throw new InvalidCreateOperationException( "Request " + mltRequest + " cannot be created with empty variable name"); } switch (mltRequest) { case flt: case mlt: { final ObjectNode sub = ((ObjectNode) currentObject).putObject(mltRequest.exactToken()); final ArrayNode array = sub.putArray(REQUESTARGS.fields.exactToken()); stringVals = new HashSet<String>(); for (final String varName : variableNames) { if (varName == null || varName.trim().isEmpty()) { continue; } final String var = varName.trim(); if (!stringVals.contains(var)) { array.add(var); stringVals.add(var); } } currentObject = array; sub.put(REQUESTARGS.like.exactToken(), value); break; } default: throw new InvalidCreateOperationException( "Request " + mltRequest + " is not an MoreLikeThis or In Request"); } currentREQUEST = mltRequest; setReady(true); }
From source file:org.eel.kitchen.jsonschema.validator.JsonResolverTest.java
@Test public void crossContextRefLoopIsDetected() { final ArrayNode path = factory.arrayNode(); JsonNode node;/*from w ww . ja v a2s.co m*/ final String location1 = "http://foo.bar/helloword"; final String location2 = "zookeeper://127.0.0.1:9000/acrylic#"; final String ref1 = location2 + "/x"; final String ref2 = location1 + "#/a"; path.add(ref1); path.add(ref2); final ObjectNode schema1 = factory.objectNode(); schema1.put("id", location1); node = factory.objectNode().put("$ref", ref1); schema1.put("a", node); final ObjectNode schema2 = factory.objectNode(); schema2.put("id", location2); node = factory.objectNode().put("$ref", ref2); schema2.put("x", node); registry.register(schema2); container = registry.register(schema1); schemaNode = new SchemaNode(container, schema1.get("a")); try { resolver.resolve(schemaNode); } catch (JsonSchemaException e) { msg = e.getValidationMessage(); verifyMessageParams(msg, Domain.REF_RESOLVING, "$ref"); assertEquals(msg.getMessage(), "ref loop detected"); assertEquals(msg.getInfo("path"), path); } }
From source file:io.macgyver.neorx.rest.NeoRxClient.java
protected ObjectNode formatPayload(String cypher, ObjectNode params) { io.macgyver.neorx.rest.impl.GuavaPreconditions.checkNotNull(cypher); ObjectNode payload = mapper.createObjectNode(); if (params == null) { params = mapper.createObjectNode(); }//from w w w . ja v a 2s .c o m ArrayNode statements = mapper.createArrayNode(); ObjectNode statement = mapper.createObjectNode(); statement.put("statement", cypher); statement.set("parameters", params); statement.put("includeStats", includeStats); statements.add(statement); payload.set("statements", statements); return payload; }
From source file:com.github.fge.jsonschema.processors.validation.InstanceValidator.java
private ProcessingMessage collectSyntaxErrors(final ProcessingReport report) { /*/*from ww w . j a v a 2 s .com*/ * OK, that's for issue #99 but that's ugly nevertheless. * * We want syntax error messages to appear in the exception text. */ final String msg = syntaxMessages.getMessage("core.invalidSchema"); final ArrayNode arrayNode = JacksonUtils.nodeFactory().arrayNode(); JsonNode node; for (final ProcessingMessage message : report) { node = message.asJson(); if ("syntax".equals(node.path("domain").asText())) arrayNode.add(node); } final StringBuilder sb = new StringBuilder(msg); sb.append("\nSyntax errors:\n"); sb.append(JacksonUtils.prettyPrint(arrayNode)); return new ProcessingMessage().setMessage(sb.toString()); }
From source file:com.gsma.mobileconnect.utils.JsonUtilsTest.java
@Test public void extractUrl_withNoRelField_shouldReturnUrl() { // GIVEN//from www . j a v a 2 s . c o m ObjectMapper mapper = new ObjectMapper(); ObjectNode root = mapper.createObjectNode(); ArrayNode links = mapper.createArrayNode(); root.set("links", links); ObjectNode link = mapper.createObjectNode(); link.put("href", "href"); links.add(link); // WHEN String url = JsonUtils.extractUrl(root, "relToFind"); // THEN assertNull(url); }
From source file:fr.gouv.vitam.query.parser.MdQueryParser.java
/** * $in : { name : [ value1, value2, ... ] } * * @param refCommand// w ww.j av a 2 s.c o m * @param command * @param tr0 * @throws InvalidParseOperationException */ @Override protected void analyzeIn(final String refCommand, final JsonNode command, final TypeRequest tr0, final REQUEST req) throws InvalidParseOperationException { if (command == null) { throw new InvalidParseOperationException("Not correctly parsed: " + refCommand); } final Entry<String, JsonNode> element = JsonHandler.checkUnicity(refCommand, command); tr0.requestModel = JsonHandler.createObjectNode(); final ArrayNode objectMD = tr0.requestModel.putObject(element.getKey()).putArray(refCommand); for (final JsonNode value : element.getValue()) { objectMD.add(value); } }
From source file:net.sf.jasperreports.engine.json.expression.member.evaluation.ArrayConstructionExpressionEvaluator.java
private List<JRJsonNode> goAnywhereDown(JRJsonNode jrJsonNode) { List<JRJsonNode> result = new ArrayList<>(); Deque<JRJsonNode> stack = new ArrayDeque<>(); JsonNode initialDataNode = jrJsonNode.getDataNode(); if (log.isDebugEnabled()) { log.debug("initial stack population with: " + initialDataNode); }/*from w w w .j ava2s.c o m*/ // populate the stack initially stack.push(jrJsonNode); while (!stack.isEmpty()) { JRJsonNode stackNode = stack.pop(); JsonNode stackDataNode = stackNode.getDataNode(); addChildrenToStack(stackNode, stack); // process the current stack item if (stackDataNode.isArray()) { if (log.isDebugEnabled()) { log.debug("processing stack element: " + stackDataNode); } ArrayNode newNode = getEvaluationContext().getObjectMapper().createArrayNode(); for (Integer idx : expression.getIndexes()) { if (idx >= 0 && idx < stackDataNode.size()) { JRJsonNode nodeAtIndex = stackNode.createChild(stackDataNode.get(idx)); if (applyFilter(nodeAtIndex)) { newNode.add(nodeAtIndex.getDataNode()); } } } if (newNode.size() > 0) { result.add(stackNode.createChild(newNode)); } } } return result; }
From source file:org.flowable.rest.service.api.history.HistoricTaskInstanceQueryResourceTest.java
/** * Test querying historic task instance. POST query/historic-task-instances *//*w w w . j a v a2 s . co m*/ @Deployment public void testQueryTaskInstances() 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", "myBusinessKey", processVariables); processEngineConfiguration.getClock().setCurrentTime(new GregorianCalendar(2013, 0, 1).getTime()); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); Task finishedTaskProcess1 = task; taskService.complete(task.getId()); processEngineConfiguration.getClock().setCurrentTime(null); task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); taskService.setVariableLocal(task.getId(), "local", "test"); taskService.setOwner(task.getId(), "test"); taskService.setDueDate(task.getId(), new GregorianCalendar(2013, 0, 1).getTime()); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables); Task task2 = taskService.createTaskQuery().processInstanceId(processInstance2.getId()).singleResult(); String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_TASK_INSTANCE_QUERY); // Process variables ObjectNode requestNode = objectMapper.createObjectNode(); ArrayNode variableArray = objectMapper.createArrayNode(); ObjectNode variableNode = objectMapper.createObjectNode(); variableArray.add(variableNode); requestNode.set("processVariables", variableArray); variableNode.put("name", "stringVar"); variableNode.put("value", "Azerty"); variableNode.put("operation", "equals"); assertResultsPresentInPostDataResponse(url, requestNode, 3, task.getId(), task2.getId()); variableNode.put("name", "intVar"); variableNode.put("value", 67890); variableNode.put("operation", "equals"); assertResultsPresentInPostDataResponse(url, requestNode, 3, task.getId(), task2.getId()); variableNode.put("name", "intVar"); variableNode.put("value", 67891); variableNode.put("operation", "lessThan"); assertResultsPresentInPostDataResponse(url, requestNode, 3, task.getId(), task2.getId()); variableNode.put("name", "intVar"); variableNode.put("value", 67890); variableNode.put("operation", "lessThan"); assertResultsPresentInPostDataResponse(url, requestNode); variableNode.put("name", "intVar"); variableNode.put("value", 67890); variableNode.put("operation", "lessThanOrEquals"); assertResultsPresentInPostDataResponse(url, requestNode, 3, task.getId(), task2.getId()); variableNode.put("name", "intVar"); variableNode.put("value", 67889); variableNode.put("operation", "greaterThan"); assertResultsPresentInPostDataResponse(url, requestNode, 3, task.getId(), task2.getId()); variableNode.put("name", "intVar"); variableNode.put("value", 67890); variableNode.put("operation", "greaterThan"); assertResultsPresentInPostDataResponse(url, requestNode); variableNode.put("name", "intVar"); variableNode.put("value", 67890); variableNode.put("operation", "greaterThanOrEquals"); assertResultsPresentInPostDataResponse(url, requestNode, 3, task.getId(), task2.getId()); variableNode.put("name", "stringVar"); variableNode.put("value", "Azer%"); variableNode.put("operation", "like"); assertResultsPresentInPostDataResponse(url, requestNode, 3, task.getId(), task2.getId()); variableNode.put("name", "local"); variableNode.put("value", "test"); variableNode.put("operation", "equals"); assertResultsPresentInPostDataResponse(url, requestNode, 0); requestNode = objectMapper.createObjectNode(); variableArray = objectMapper.createArrayNode(); variableNode = objectMapper.createObjectNode(); variableArray.add(variableNode); requestNode.set("taskVariables", variableArray); variableNode.put("name", "local"); variableNode.put("value", "test"); variableNode.put("operation", "equals"); assertResultsPresentInPostDataResponse(url, requestNode, 1, task.getId()); requestNode = objectMapper.createObjectNode(); assertResultsPresentInPostDataResponse(url, requestNode, 3, task.getId(), task2.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("processInstanceId", processInstance.getId()); assertResultsPresentInPostDataResponse(url, requestNode, 2, task.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("processInstanceId", processInstance2.getId()); assertResultsPresentInPostDataResponse(url, requestNode, 1, task2.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("taskAssignee", "kermit"); assertResultsPresentInPostDataResponse(url, requestNode, 2, task2.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("taskAssigneeLike", "%mit"); assertResultsPresentInPostDataResponse(url, requestNode, 2, task2.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("taskAssignee", "fozzie"); assertResultsPresentInPostDataResponse(url, requestNode, 1, task.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("taskOwner", "test"); assertResultsPresentInPostDataResponse(url, requestNode, 1, task.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("taskOwnerLike", "t%"); assertResultsPresentInPostDataResponse(url, requestNode, 1, task.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("taskInvolvedUser", "test"); assertResultsPresentInPostDataResponse(url, requestNode, 1, task.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("dueDateAfter", dateFormat.format(new GregorianCalendar(2010, 0, 1).getTime())); assertResultsPresentInPostDataResponse(url, requestNode, 1, task.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("dueDateAfter", dateFormat.format(new GregorianCalendar(2013, 4, 1).getTime())); assertResultsPresentInPostDataResponse(url, requestNode, 0); requestNode = objectMapper.createObjectNode(); requestNode.put("dueDateBefore", dateFormat.format(new GregorianCalendar(2010, 0, 1).getTime())); assertResultsPresentInPostDataResponse(url, requestNode, 0); requestNode = objectMapper.createObjectNode(); requestNode.put("dueDateBefore", dateFormat.format(new GregorianCalendar(2013, 4, 1).getTime())); assertResultsPresentInPostDataResponse(url, requestNode, 1, task.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("taskCompletedAfter", dateFormat.format(new GregorianCalendar(2010, 0, 1).getTime())); assertResultsPresentInPostDataResponse(url, requestNode, 1, finishedTaskProcess1.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("taskCompletedAfter", dateFormat.format(new GregorianCalendar(2013, 4, 1).getTime())); assertResultsPresentInPostDataResponse(url, requestNode, 0); requestNode = objectMapper.createObjectNode(); requestNode.put("taskCompletedBefore", dateFormat.format(new GregorianCalendar(2010, 0, 1).getTime())); assertResultsPresentInPostDataResponse(url, requestNode, 0); requestNode = objectMapper.createObjectNode(); requestNode.put("taskCompletedAfter", dateFormat.format(new GregorianCalendar(2010, 3, 1).getTime())); assertResultsPresentInPostDataResponse(url, requestNode, 1, finishedTaskProcess1.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("processBusinessKey", "myBusinessKey"); assertResultsPresentInPostDataResponse(url, requestNode, 2, task.getId(), finishedTaskProcess1.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("processBusinessKeyLike", "myBusiness%"); assertResultsPresentInPostDataResponse(url, requestNode, 2, task.getId(), finishedTaskProcess1.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("processDefinitionKey", "someTaskProcess"); assertResultsPresentInPostDataResponse(url, requestNode, 0); requestNode = objectMapper.createObjectNode(); requestNode.put("processDefinitionKey", "oneTaskProcess"); assertResultsPresentInPostDataResponse(url, requestNode, task.getId(), finishedTaskProcess1.getId(), task2.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("processDefinitionKeyLike", "oneTask%"); assertResultsPresentInPostDataResponse(url, requestNode, task.getId(), finishedTaskProcess1.getId(), task2.getId()); requestNode = objectMapper.createObjectNode(); requestNode.put("processDefinitionKeyLike", "some%"); assertResultsPresentInPostDataResponse(url, requestNode); requestNode = objectMapper.createObjectNode(); requestNode.put("taskDefinitionKey", "processTask"); assertResultsPresentInPostDataResponse(url, requestNode, finishedTaskProcess1.getId(), task2.getId()); }
From source file:org.onosproject.maven.OnosSwaggerMojo.java
private void processConsumesProduces(ObjectNode methodNode, String type, String io) { if (!io.equals("")) { ArrayNode array = mapper.createArrayNode(); methodNode.set(type, array);/*from w ww .ja v a 2 s . com*/ array.add(io); } }