List of usage examples for com.fasterxml.jackson.databind.node ArrayNode ArrayNode
public ArrayNode(JsonNodeFactory paramJsonNodeFactory)
From source file:io.syndesis.maven.ExtractConnectorDescriptorsMojo.java
@Override @SuppressWarnings("PMD.EmptyCatchBlock") public void execute() throws MojoExecutionException, MojoFailureException { ArrayNode root = new ArrayNode(JsonNodeFactory.instance); URLClassLoader classLoader = null; try {//from w w w .j a v a 2 s .c o m PluginDescriptor desc = (PluginDescriptor) getPluginContext().get("pluginDescriptor"); List<Artifact> artifacts = desc.getArtifacts(); ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest()); buildingRequest.setRemoteRepositories(remoteRepositories); for (Artifact artifact : artifacts) { ArtifactResult result = artifactResolver.resolveArtifact(buildingRequest, artifact); File jar = result.getArtifact().getFile(); classLoader = createClassLoader(jar); if (classLoader == null) { throw new IOException("Can not create classloader for " + jar); } ObjectNode entry = new ObjectNode(JsonNodeFactory.instance); addConnectorMeta(entry, classLoader); addComponentMeta(entry, classLoader); if (entry.size() > 0) { addGav(entry, artifact); root.add(entry); } } if (root.size() > 0) { saveCamelMetaData(root); } } catch (ArtifactResolverException | IOException e) { throw new MojoExecutionException(e.getMessage(), e); } finally { if (classLoader != null) { try { classLoader.close(); } catch (IOException ignored) { } } } }
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 ww w. j a v a2 s .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); 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:com.turn.shapeshifter.AutoSerializer.java
/** * Serializes a repeated field.//from ww w .jav a 2 s .co m * * @param message the message being serialized * @param registry a registry of schemas, for enclosed object types * @param field the descriptor of the repeated field to serialize * @param count the count of repeated items in the field * @return the JSON representation of the serialized * @throws SerializationException */ private ArrayNode serializeRepeatedField(Message message, FieldDescriptor field, ReadableSchemaRegistry registry) throws SerializationException { ArrayNode array = new ArrayNode(JsonNodeFactory.instance); int count = message.getRepeatedFieldCount(field); for (int i = 0; i < count; i++) { Object value = message.getRepeatedField(field, i); JsonNode valueNode = serializeValue(value, field, registry); if (!valueNode.isNull()) { array.add(valueNode); } } return array; }
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 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); 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:org.walkmod.conf.providers.yml.RemoveIncludesOrExcludesYMLAction.java
private void removesIncludesOrExcludesList(ObjectNode node) { ArrayNode wildcardArray = null;//from w w w. j av a 2s . co m ArrayNode result = new ArrayNode(provider.getObjectMapper().getNodeFactory()); String label = "includes"; if (isExcludes) { label = "excludes"; } 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.jetbrains.webdemo.help.HelpLoader.java
private void generateHelpForWords() { resultWords = new ArrayNode(JsonNodeFactory.instance); try {/*from w ww . jav a2 s . c o m*/ File file = new File( CommonSettings.HELP_DIRECTORY + File.separator + ApplicationSettings.HELP_FOR_WORDS); Document doc = ResponseUtils.getXmlDocument(file); if (doc == null) { return; } NodeList nodeList = doc.getElementsByTagName("keyword"); for (int temp = 0; temp < nodeList.getLength(); temp++) { Node node = nodeList.item(temp); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; ObjectNode jsonObject = resultWords.addObject(); jsonObject.put("word", getTagValue("name", element)); jsonObject.put("help", getTagValueWithInnerTags("text", element)); } } } catch (Exception e) { ErrorWriter.ERROR_WRITER.writeExceptionToExceptionAnalyzer(e, SessionInfo.TypeOfRequest.LOAD_EXAMPLE.name(), "unknown", ""); } response.append("\nHelp for keywords was loaded."); }
From source file:org.apache.solr.kelvin.testcases.DateRangeCondition.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); }// www. ja v a 2s.c om 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, fieldToCheck)) { ret.add(new MissingFieldTestEvent(testCase, queryParams, "missing field from result - " + fieldToCheck, i)); } else { String fieldValue = getField(row, fieldToCheck).asText(); Date dateReturned = null; try { dateReturned = parseDate(fieldValue); } catch (Exception e) { ret.add(new ConditionsNotMetTestEvent(testCase, queryParams, String.format("date parsing error %s", fieldValue), i)); continue; } boolean error = false; if (leftInclusive && leftDate.compareTo(dateReturned) > 0) error = true; if (!leftInclusive && leftDate.compareTo(dateReturned) >= 0) error = true; if (rightInclusive && rightDate.compareTo(dateReturned) < 0) error = true; if (!rightInclusive && rightDate.compareTo(dateReturned) <= 0) error = true; if (error && !this.reverseConditions) ret.add(new ConditionsNotMetTestEvent(testCase, queryParams, String.format("date range error %s not in %s", fieldValue, this.dateRangeString), i)); if (!error && this.reverseConditions) ret.add(new ConditionsNotMetTestEvent(testCase, queryParams, String.format( "reverse date range error %s not in %s", fieldValue, this.dateRangeString), i)); } } } return ret; }
From source file:org.walkmod.conf.providers.yml.AbstractYMLConfigurationAction.java
public void populateWriterReader(ObjectNode root, String path, String type, String[] includes, String[] excludes, Map<String, Object> params) { if (path != null && !"".equals(path)) { root.set("path", new TextNode(path)); }//from ww w . j a va 2s.c o m if (type != null) { root.set("type", new TextNode(type)); } if (includes != null && includes.length > 0) { ArrayNode includesNode = new ArrayNode(provider.getObjectMapper().getNodeFactory()); for (int i = 0; i < includes.length; i++) { includesNode.add(new TextNode(includes[i])); } root.set("includes", includesNode); } if (excludes != null && excludes.length > 0) { ArrayNode excludesNode = new ArrayNode(provider.getObjectMapper().getNodeFactory()); for (int i = 0; i < excludes.length; i++) { excludesNode.add(new TextNode(excludes[i])); } root.set("excludes", excludesNode); } if (params != null && !params.isEmpty()) { populateParams(root, params); } }
From source file:org.bonitasoft.web.designer.model.contract.databind.ContractDeserializer.java
private ArrayNode childInput(JsonNode treeNode) { return (ArrayNode) (treeNode.has("input") ? treeNode.get("input") : new ArrayNode(JsonNodeFactory.instance)); }
From source file:fr.paris.lutece.plugins.libraryelastic.business.search.BoolQuery.java
/** * {@inheritDoc}//from w w w . ja v a2 s. c o m */ @Override protected ObjectNode getNodeContent(JsonNodeFactory factory) { ObjectNode content = new ObjectNode(factory); if (CollectionUtils.isNotEmpty(_listMust)) { JsonNode must; if (_listMust.size() == 1) { must = _listMust.get(0).mapToNode(factory); } else { must = new ArrayNode(factory); for (AbstractSearchLeaf searchLeaf : _listMust) { ((ArrayNode) must).add(searchLeaf.mapToNode(factory)); } } content.set("must", must); } if (CollectionUtils.isNotEmpty(_listFilter)) { JsonNode filter; if (_listFilter.size() == 1) { filter = _listFilter.get(0).mapToNode(factory); } else { filter = new ArrayNode(factory); for (AbstractSearchLeaf searchLeaf : _listFilter) { ((ArrayNode) filter).add(searchLeaf.mapToNode(factory)); } } content.set("filter", filter); } if (CollectionUtils.isNotEmpty(_listShould)) { JsonNode should; if (_listShould.size() == 1) { should = _listShould.get(0).mapToNode(factory); } else { should = new ArrayNode(factory); for (AbstractSearchLeaf searchLeaf : _listShould) { ((ArrayNode) should).add(searchLeaf.mapToNode(factory)); } } content.set("should", should); } if (CollectionUtils.isNotEmpty(_listMustNot)) { JsonNode mustNot; if (_listMustNot.size() == 1) { mustNot = _listMustNot.get(0).mapToNode(factory); } else { mustNot = new ArrayNode(factory); for (AbstractSearchLeaf searchLeaf : _listMustNot) { ((ArrayNode) mustNot).add(searchLeaf.mapToNode(factory)); } } content.set("must_not", mustNot); } return content; }