List of usage examples for com.fasterxml.jackson.databind.node ArrayNode size
public int size()
From source file:org.apache.solr.kelvin.testcases.ValueListCondition.java
public List<ConditionFailureTestEvent> verifyConditions(ITestCase testCase, Properties queryParams, Map<String, Object> decodedResponses, Object testSpecificArgument) { List<ConditionFailureTestEvent> ret = new ArrayList<ConditionFailureTestEvent>(); ArrayNode results = new ArrayNode(null); if (decodedResponses.containsKey(XmlDoclistExtractorResponseAnalyzer.DOC_LIST)) { results = (ArrayNode) decodedResponses.get(XmlDoclistExtractorResponseAnalyzer.DOC_LIST); }/*from w ww . j a v a2 s .c o m*/ int lengthToCheck = getLengthToCheck(results); for (int i = 0; i < lengthToCheck; i++) { if (results.size() <= i) { ret.add(new MissingResultTestEvent(testCase, queryParams, "result set too short", i)); } else { JsonNode row = results.get(i); if (!hasField(row, field)) { ret.add(new MissingFieldTestEvent(testCase, queryParams, "missing field " + field + " from result", i)); } else { JsonNode fieldValue = getField(row, field); fieldValue = ConfigurableLoader.assureArray(fieldValue); boolean found = false; ArrayList<String> allTextValues = new ArrayList<String>(); for (int j = 0; j < fieldValue.size(); j++) { String fieldText = fieldValue.get(j).asText(); allTextValues.add(fieldText); if (checkContains(fieldText)) { found = true; break; } else if (legacy) { for (String cond : correctValuesList) { if (cond.endsWith("*")) { if (fieldText.startsWith(cond.substring(0, cond.length() - 1))) { found = true; break; } } } } } if (!found && !reverseConditions) ret.add(new ConditionsNotMetTestEvent(testCase, queryParams, "unexpected vaule [" + StringUtils.join(allTextValues, ',') + "] not in " + correctValuesList.toString(), i)); else if (found && reverseConditions) { ret.add(new ConditionsNotMetTestEvent(testCase, queryParams, "[" + StringUtils.join(allTextValues, ',') + "] matches " + correctValuesList.toString(), i)); } } } } return ret; }
From source file:org.apache.solr.kelvin.testcases.SimpleCondition.java
public List<ConditionFailureTestEvent> verifyConditions(ITestCase testCase, Properties queryParams, Map<String, Object> decodedResponses, Object testSpecificArgument) { List<ConditionFailureTestEvent> ret = new ArrayList<ConditionFailureTestEvent>(); ArrayNode results = new ArrayNode(null); if (decodedResponses.containsKey(XmlDoclistExtractorResponseAnalyzer.DOC_LIST)) { results = (ArrayNode) decodedResponses.get(XmlDoclistExtractorResponseAnalyzer.DOC_LIST); }/*from w w w .j a va2s. co m*/ int lengthToCheck = getLengthToCheck(results); for (int i = 0; i < lengthToCheck; i++) { if (results.size() <= i) { ret.add(new MissingResultTestEvent(testCase, queryParams, "result set too short", i)); } else { JsonNode row = results.get(i); boolean allFields = true; for (String field : this.fields) { if (!hasField(row, field)) { ret.add(new MissingFieldTestEvent(testCase, queryParams, "missing field from result - " + field, i)); allFields = false; } } if (allFields) { String allText = ""; for (String field : fields) { JsonNode fieldValue = getField(row, field); if (fieldValue.isArray()) { for (int j = 0; j < fieldValue.size(); j++) { allText = allText + " " + fieldValue.get(j); } //checkAllWords(testCase, queryParams, ret, i, // allText); } else { String stringFieldValue = fieldValue.asText(); allText = allText + " " + stringFieldValue; } } checkAllWords(testCase, queryParams, ret, i, allText); } } } return ret; }
From source file:eu.vital.orchestrator.rest.EvaluationRESTService.java
@POST @Path("/latest") public Response executeLatestScenario(JsonNode input) throws Exception { String dmsUrl = "https://local.vital-iot.eu:8443/vital-core-dms"; // 1. Get List of sensors from DMS observing AvailableBikes Client dmsClient = ClientBuilder.newClient(); WebTarget dmsTarget = dmsClient.target(dmsUrl).path("querySensor").queryParam("encodeKeys", "false"); ObjectNode sensorQuery = objectMapper.createObjectNode(); sensorQuery.put("http://purl\\u002eoclc\\u002eorg/NET/ssnx/ssn#observes.@type", "http://vital-iot.eu/ontology/ns/Speed"); ArrayNode sensorList = dmsTarget.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(sensorQuery), ArrayNode.class); // 2. Find the nearest sensor double minDistance = Double.MAX_VALUE; JsonNode nearestSensor = null;/*w ww. j a v a 2 s .c o m*/ for (int i = 0; i < sensorList.size(); i++) { JsonNode sensor = sensorList.get(i); // Calculate Distance: double tmp = distance(input.get("lat").asDouble(), input.get("lng").asDouble(), sensor.get("hasLastKnownLocation").get("geo:lat").asDouble(), sensor.get("hasLastKnownLocation").has("geo:long") ? sensor.get("hasLastKnownLocation").get("geo:long").asDouble() : sensor.get("hasLastKnownLocation").get("geo:lon").asDouble()); if (tmp < minDistance) { minDistance = tmp; nearestSensor = sensor; } } // 3. Find the System of the Sensor dmsTarget = dmsClient.target(dmsUrl).path("querySystem").queryParam("encodeKeys", "false"); ObjectNode systemQuery = objectMapper.createObjectNode(); systemQuery.put("http://vital-iot\\u002eeu/ontology/ns/managesSensor.@id", nearestSensor.get("id").asText()); ArrayNode systemList = dmsTarget.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(systemQuery), ArrayNode.class); JsonNode system = systemList.get(0); // 4. Find the Observation Service of the System dmsTarget = dmsClient.target(dmsUrl).path("queryService").queryParam("encodeKeys", "false"); ObjectNode serviceAndQuery = objectMapper.createObjectNode(); ArrayNode serviceAndParameters = objectMapper.createArrayNode(); serviceAndQuery.put("$and", serviceAndParameters); ObjectNode serviceIdQuery = objectMapper.createObjectNode(); ObjectNode serviceInQuery = objectMapper.createObjectNode(); serviceInQuery.put("$in", system.get("services")); serviceIdQuery.put("@id", serviceInQuery); serviceAndParameters.add(serviceIdQuery); ObjectNode serviceTypeQuery = objectMapper.createObjectNode(); serviceTypeQuery.put("@type", "http://vital-iot.eu/ontology/ns/ObservationService"); serviceAndParameters.add(serviceTypeQuery); ArrayNode serviceList = dmsTarget.request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.json(serviceAndQuery), ArrayNode.class); JsonNode observationService = serviceList.get(0); // 5. Call GetObservation operation of the service String operationUrl = observationService.get("operations").get("hrest:hasAddress").asText(); Client systemClient = ClientBuilder.newClient(); WebTarget systemTarget = systemClient.target(operationUrl); ObjectNode operationInput = objectMapper.createObjectNode(); ArrayNode sensorsArray = objectMapper.createArrayNode(); sensorsArray.add(nearestSensor.get("id").asText()); operationInput.put("sensor", sensorsArray); operationInput.put("property", "http://vital-iot.eu/ontology/ns/Speed"); ArrayNode observationList = systemTarget.request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.json(operationInput), ArrayNode.class); JsonNode latestObservation = observationList.get(0); // 6. Parse Result and return response ObjectNode result = objectMapper.createObjectNode(); result.put("measurementValue", latestObservation.get("ssn:observationResult").get("ssn:hasValue").get("value")); result.put("measurementDate", latestObservation.get("ssn:observationResultTime").get("time:inXSDDateTime")); return Response.ok(result).build(); }
From source file:org.walkmod.conf.providers.yml.RemoveModulesYMLAction.java
@Override public void doAction(JsonNode node) throws Exception { if (node.has("modules")) { JsonNode aux = node.get("modules"); ObjectMapper mapper = provider.getObjectMapper(); if (aux.isArray()) { ArrayNode modulesList = (ArrayNode) node.get("modules"); Iterator<JsonNode> it = modulesList.iterator(); ArrayNode newModulesList = new ArrayNode(mapper.getNodeFactory()); while (it.hasNext()) { JsonNode next = it.next(); if (next.isTextual()) { String text = next.asText(); if (!modules.contains(text)) { newModulesList.add(text); }//from w w w .j a v a 2 s . c om } } ObjectNode oNode = (ObjectNode) node; if (newModulesList.size() > 0) { oNode.set("modules", newModulesList); } else { oNode.remove("modules"); } provider.write(node); } } }
From source file:org.walkmod.conf.providers.yml.RemoveChainsYMLAction.java
@Override public void doAction(JsonNode node) throws Exception { HashSet<String> chainsSet = new HashSet<String>(chains); ArrayNode chainsList = null;/* ww w. j ava2s .c om*/ ObjectMapper mapper = provider.getObjectMapper(); if (node.has("chains")) { JsonNode aux = node.get("chains"); if (aux.isArray()) { chainsList = (ArrayNode) node.get("chains"); Iterator<JsonNode> it = chainsList.iterator(); ArrayNode newChainsList = new ArrayNode(mapper.getNodeFactory()); while (it.hasNext()) { JsonNode next = it.next(); if (next.isObject()) { String type = next.get("name").asText(); if (!chainsSet.contains(type)) { newChainsList.add(next); } } } ObjectNode oNode = (ObjectNode) node; if (newChainsList.size() > 0) { oNode.set("chains", newChainsList); } else { oNode.remove("chains"); } provider.write(node); } } else if (node.has("transformations") && chainsSet.contains("default")) { ObjectNode oNode = (ObjectNode) node; oNode.remove("transformations"); provider.write(node); } }
From source file:org.walkmod.conf.providers.yml.RemoveIncludesOrExcludesYMLAction.java
private void removesIncludesOrExcludesList(ObjectNode node) { ArrayNode wildcardArray = null; ArrayNode result = new ArrayNode(provider.getObjectMapper().getNodeFactory()); String label = "includes"; if (isExcludes) { label = "excludes"; }/*from ww w.ja v a 2 s.c o m*/ 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:org.apache.syncope.fit.core.SCIMITCase.java
@Test public void schemas() { assumeTrue(SCIMDetector.isSCIMAvailable(webClient())); Response response = webClient().path("Schemas").get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";")); ArrayNode schemas = response.readEntity(ArrayNode.class); assertNotNull(schemas);/* w w w . j a v a2s. c o m*/ assertEquals(3, schemas.size()); response = webClient().path("Schemas").path("none").get(); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); response = webClient().path("Schemas").path(Resource.EnterpriseUser.schema()).get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); ObjectNode enterpriseUser = response.readEntity(ObjectNode.class); assertNotNull(enterpriseUser); assertEquals(Resource.EnterpriseUser.schema(), enterpriseUser.get("id").textValue()); }
From source file:org.apache.taverna.scufl2.translator.t2flow.defaultactivities.SpreadsheetActivityParser.java
@Override public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean, ParserState parserState) throws ReaderException { SpreadsheetImportConfig config = unmarshallConfig(t2FlowParser, configBean, "xstream", SpreadsheetImportConfig.class); Configuration configuration = new Configuration(); configuration.setParent(parserState.getCurrentProfile()); ObjectNode json = (ObjectNode) configuration.getJson(); configuration.setType(ACTIVITY_URI.resolve("#Config")); ObjectNode columnRange = json.objectNode(); json.put("columnRange", columnRange); makeRange(config.getColumnRange(), columnRange); ObjectNode rowRange = json.objectNode(); json.put("rowRange", rowRange); makeRange(config.getRowRange(), rowRange); if (config.getEmptyCellValue() != null) json.put("emptyCellValue", config.getEmptyCellValue()); ArrayNode columnNames = json.arrayNode(); if (config.getColumnNames() != null && config.getColumnNames().getEntry() != null) { for (SpreadsheetColumnNameEntry entry : config.getColumnNames().getEntry()) { ObjectNode mapping = json.objectNode(); columnNames.add(mapping);/*from w ww . j ava 2 s . co m*/ mapping.put("column", entry.getString().get(0)); mapping.put("port", entry.getString().get(1)); } if (columnNames.size() > 0) json.put("columnNames", columnNames); } json.put("allRows", config.isAllRows()); json.put("excludeFirstRow", config.isExcludeFirstRow()); json.put("ignoreBlankRows", config.isIgnoreBlankRows()); if (config.getEmptyCellPolicy() != null) json.put("emptyCellPolicy", config.getEmptyCellPolicy().value()); if (config.getOutputFormat() != null) json.put("outputFormat", config.getOutputFormat().value()); if (config.getCsvDelimiter() != null) json.put("csvDelimiter", config.getCsvDelimiter()); return configuration; }
From source file:org.walkmod.conf.providers.YAMLConfigurationProvider.java
@Override public void addPluginConfig(final PluginConfig pluginConfig, boolean recursive) throws TransformerException { File cfg = new File(fileName); ArrayNode pluginList = null;// w w w . ja v a 2 s . c o m JsonNode node = null; try { node = mapper.readTree(cfg); } catch (Exception e) { } if (node == null) { node = new ObjectNode(mapper.getNodeFactory()); } if (recursive && node.has("modules")) { JsonNode aux = node.get("modules"); if (aux.isArray()) { ArrayNode modules = (ArrayNode) aux; int max = modules.size(); for (int i = 0; i < max; i++) { JsonNode module = modules.get(i); if (module.isTextual()) { String moduleDir = module.asText(); try { File auxFile = new File(fileName).getCanonicalFile().getParentFile(); YAMLConfigurationProvider child = new YAMLConfigurationProvider( auxFile.getAbsolutePath() + File.separator + moduleDir + File.separator + "walkmod.yml"); child.createConfig(); child.addPluginConfig(pluginConfig, recursive); } catch (IOException e) { throw new TransformerException(e); } } } } } else { if (!node.has("plugins")) { pluginList = new ArrayNode(mapper.getNodeFactory()); if (node.isObject()) { ObjectNode aux = (ObjectNode) node; aux.set("plugins", pluginList); } else { throw new TransformerException("The root element is not a JSON node"); } } else { JsonNode aux = node.get("plugins"); if (aux.isArray()) { pluginList = (ArrayNode) node.get("plugins"); } else { throw new TransformerException("The plugins element is not a valid array"); } } pluginList.add(new TextNode(pluginConfig.getGroupId() + ":" + pluginConfig.getArtifactId() + ":" + pluginConfig.getVersion())); write(node); } }
From source file:org.modeshape.web.jcr.rest.handler.ItemHandlerImpl.java
private Object convertToJcrValues(Node node, Object value, boolean encoded) throws RepositoryException { if (value == NullNode.getInstance() || (value instanceof ArrayNode && ((ArrayNode) value).size() == 0)) { // for any null value of empty json array, return an empty array which will mean the property will be removed return null; }/*from w ww . j av a 2 s . co m*/ org.modeshape.jcr.api.ValueFactory valueFactory = (org.modeshape.jcr.api.ValueFactory) node.getSession() .getValueFactory(); if (value instanceof ArrayNode) { ArrayNode jsonValues = (ArrayNode) value; Value[] values = new Value[jsonValues.size()]; for (int i = 0; i < jsonValues.size(); i++) { if (encoded) { values[i] = createBinaryValue(jsonValues.get(i).asText(), valueFactory); } else { values[i] = RestHelper.jsonValueToJCRValue(jsonValues.get(i), valueFactory); } } return values; } return encoded ? createBinaryValue(value.toString(), valueFactory) : RestHelper.jsonValueToJCRValue(value, valueFactory); }