List of usage examples for com.fasterxml.jackson.databind.node ArrayNode get
public JsonNode get(String paramString)
From source file:org.apache.solr.kelvin.testcases.SimpleCondition.java
public void configure(JsonNode condition) throws Exception { parseLen(condition);//w w w . j a v a 2s .c o m parseReverseConditions(condition); List<String> values = new LinkedList<String>(); mandatory(condition, "field"); ArrayList<String> realFiels = new ArrayList<String>(); ArrayNode fieldsArray = ConfigurableLoader.assureArray(condition.get("field")); for (int i = 0; i < fieldsArray.size(); i++) { if (fieldsArray.get(i).asText().contains("+")) { //legacy for (String f : fieldsArray.get(i).asText().split("[+]")) realFiels.add(f); } else { realFiels.add(fieldsArray.get(i).asText()); } } if (condition.has("args")) readStringArrayOpt(condition.get("args"), values); //legacy if (condition.has("values")) readStringArrayOpt(condition.get("values"), values); if (values.size() == 0) throw new Exception("missing condition values"); init(this.length, realFiels, values); }
From source file:br.com.ingenieux.mojo.simpledb.cmd.PutAttributesCommand.java
public void execute(PutAttributesContext ctx) throws Exception { if (ctx.isCreateDomainIfNeeded()) createIfNeeded(ctx);// ww w . jav a2 s . c om ArrayNode attributesArray = (ArrayNode) new ObjectMapper().readTree(ctx.getSource()); for (int i = 0; i < attributesArray.size(); i++) { ObjectNode putAttributeNode = (ObjectNode) attributesArray.get(i); putAttribute(ctx, putAttributeNode); } }
From source file:io.sidecar.event.EventJsonValidationTest.java
@Test(description = "Assert that an event can have duplicate tags") public void tagsCanBeDuplicated() throws Exception { Set<String> originalTagSet = tagsJsonArrayToSet(); ArrayNode tagsNode = (ArrayNode) eventAsObjectNode.path("tags"); tagsNode.add(tagsNode.get(0)); Event e = mapper.readValue(eventAsObjectNode.traverse(), Event.class); assertEquals(e.getTags(), originalTagSet); }
From source file:org.gitana.platform.client.FileFolderTest.java
@Test public void testCRUD() { Gitana gitana = new Gitana(); // authenticate Platform platform = gitana.authenticate("admin", "admin"); // create a repository Repository repository = platform.createRepository(); // get the master branch Branch master = repository.readBranch("master"); // create a tree structure from ROOT Node root = master.rootNode(); // tree structure /**/*from w ww . ja v a 2 s . c om*/ * * / * /a1 * /a1/b1 * /a1/b1/c1 * /a1/b1/c1/d1 * /a1/b1/c1/d2 * /a1/b1/c1/d3 * /a1/b1/c2 * /a1/b1/c2/d4 * /a1/b1/c2/d5 * /a1/b2 * /a2 * /a2/b3 */ Node a1 = createFolder(master, root, "a1"); Node a2 = createFolder(master, root, "a2"); Node b1 = createFolder(master, a1, "b1"); Node b2 = createFolder(master, a1, "b2"); Node b3 = createFolder(master, a2, "b2"); Node c1 = createFolder(master, b1, "c1"); Node c2 = createFolder(master, b1, "c2"); Node d1 = createFile(master, c1, "d1"); Node d2 = createFile(master, c1, "d2"); Node d3 = createFile(master, c1, "d3"); Node d4 = createFile(master, c2, "d4"); Node d5 = createFile(master, c2, "d5"); // read the WHOLE tree ObjectNode tree1 = root.fileFolderTree(); System.out.println(JsonUtil.stringify(tree1, true)); // a few tests to ensure this is good ArrayNode children = (ArrayNode) tree1.get("children"); assertNotNull(children); assertEquals(2, children.size()); assertTrue(children.get(0).get("container").booleanValue()); assertNotNull(children.get(0).get("filename").textValue()); assertNotNull(children.get(0).get("label").textValue()); assertNotNull(children.get(0).get("path").textValue()); assertNotNull(children.get(0).get("typeQName").textValue()); assertNotNull(children.get(0).get("qname").textValue()); // read the tree from root with the "/a1/b1/c1" path already expanded ObjectNode tree2 = root.fileFolderTree("/", "/a1/b1/c1"); System.out.println(JsonUtil.stringify(tree2, true)); // read the tree segment starting at "/a1/b1" ObjectNode tree3 = root.fileFolderTree("/a1/b1"); System.out.println(JsonUtil.stringify(tree3, true)); }
From source file:com.basho.riak.client.api.commands.itest.ITestBucketKeyMapReduce.java
private void JsBucketKeyMR(String bucketType) throws InterruptedException, ExecutionException, IOException { initValues(bucketType);//from ww w .ja v a 2 s . c o m Namespace ns = new Namespace(bucketType, mrBucket); MapReduce mr = new BucketKeyMapReduce.Builder().withLocation(new Location(ns, "p1")) .withLocation(new Location(ns, "p2")).withLocation(new Location(ns, "p3")) .withMapPhase(Function.newAnonymousJsFunction("function(v, key_data) {" + " var m = v.values[0].data.toLowerCase().match(/\\w*/g);" + " var r = [];" + " for(var i in m) {" + " if(m[i] != '') {" + " var o = {};" + " o[m[i]] = 1;" + " r.push(o);" + " }" + " }" + " return r;" + "}")) .withReducePhase(Function.newAnonymousJsFunction("function(v, key_data) {" + " var r = {};" + " for(var i in v) {" + " for(var w in v[i]) {" + " if(w in r)" + " r[w] += v[i][w];" + " else" + " r[w] = v[i][w];" + " }" + " }" + " return [r];" + "}"), true) .build(); MapReduce.Response response = client.execute(mr); // The query should return one phase result which is a JSON array containing a // single JSON object that is a set of word counts. ArrayNode resultList = response.getResultForPhase(1); assertEquals(1, response.getResultsFromAllPhases().size()); String json = resultList.get(0).toString(); ObjectMapper oMapper = new ObjectMapper(); TypeReference<Map<String, Integer>> type = new TypeReference<Map<String, Integer>>() { }; Map<String, Integer> resultMap = oMapper.readValue(json, type); assertNotNull(resultMap.containsKey("the")); assertEquals(Integer.valueOf(8), resultMap.get("the")); }
From source file:org.walkmod.conf.providers.yml.AbstractYMLConfigurationAction.java
@Override public void execute() throws Exception { JsonNode node = provider.getRootNode(); boolean isMultiModule = node.has("modules"); if (recursive && isMultiModule) { 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(provider.getFileName()).getCanonicalFile().getParentFile(); YAMLConfigurationProvider child = new YAMLConfigurationProvider( auxFile.getAbsolutePath() + File.separator + moduleDir + File.separator + "walkmod.yml"); child.createConfig(); AbstractYMLConfigurationAction childAction = clone(child, recursive); childAction.execute(); } catch (IOException e) { throw new TransformerException(e); }/*from w w w. j a v a 2 s. co m*/ } } } } else { doAction(node); } }
From source file:de.jlo.talendcomp.json.JsonComparator.java
/** * Collects the differences between the both arrays * @param array1//from w w w .ja va 2 s.com * @param array2 * @return an array which contains the difference between both arrays */ public ArrayNode difference(ArrayNode array1, ArrayNode array2) { ArrayNode result = objectMapper.createArrayNode(); for (int i1 = 0, n1 = array1.size(); i1 < n1; i1++) { JsonNode node1 = array1.get(i1); boolean found = false; for (int i2 = 0, n2 = array2.size(); i2 < n2; i2++) { JsonNode node2 = array2.get(i2); if (node1.equals(node2)) { found = true; break; } } if (found == false) { result.add(node1); } } // exchange the arrays ArrayNode x = array1; array1 = array2; array2 = x; for (int i1 = 0, n1 = array1.size(); i1 < n1; i1++) { JsonNode node1 = array1.get(i1); boolean found = false; for (int i2 = 0, n2 = array2.size(); i2 < n2; i2++) { JsonNode node2 = array2.get(i2); if (node1.equals(node2)) { found = true; break; } } if (found == false) { result.add(node1); } } return result; }
From source file:com.vmware.photon.controller.clustermanager.clients.SwarmClient.java
/** * This method calls into the Swarm API endpoint to retrieve the node ip addresses. * * @param connectionString connectionString of the master Node in the Cluster * @param callback callback that is invoked on completion of the operation. * @param nodeProperty specify the property of the node to return. * @throws IOException/*from ww w.ja va2 s . c o m*/ */ private void getNodeStatusAsync(final String connectionString, final FutureCallback<Set<String>> callback, final NodeProperty nodeProperty) throws IOException { final RestClient restClient = new RestClient(connectionString, this.httpClient); org.apache.http.concurrent.FutureCallback<HttpResponse> futureCallback = new org.apache.http.concurrent.FutureCallback<HttpResponse>() { @Override public void completed(HttpResponse result) { ArrayNode driverStatus; try { restClient.checkResponse(result, HttpStatus.SC_OK); JsonNode response = objectMapper.readTree(result.getEntity().getContent()); driverStatus = (ArrayNode) response.get("DriverStatus"); } catch (Throwable e) { callback.onFailure(e); return; } Set<String> nodes = new HashSet<>(); for (JsonNode entry : driverStatus) { ArrayNode kv = (ArrayNode) entry; if (kv.size() == 2) { try { String key = kv.get(0).asText(); if (key.startsWith(MASTER_VM_NAME_PREFIX) || key.startsWith(WORKER_VM_NAME_PREFIX)) { switch (nodeProperty) { case IP_ADDRESS: String nodeAddress = kv.get(1).asText().split(":")[0]; nodes.add(nodeAddress); break; case HOSTNAME: nodes.add(key); break; default: new UnsupportedOperationException( "NodeProperty is not supported. NodeProperty: " + nodeProperty); } } } catch (Exception ex) { logger.error("malformed node value", ex); } } } callback.onSuccess(nodes); } @Override public void failed(Exception ex) { callback.onFailure(ex); } @Override public void cancelled() { callback.onFailure(new RuntimeException("getNodeStatusAsync was cancelled")); } }; restClient.performAsync(RestClient.Method.GET, SWARM_STATUS_PATH, null, futureCallback); }
From source file:com.marklogic.samplestack.database.DatabaseTransformsIT.java
@Test public void acceptPatchTransform() { // make a user contributorService.store(Utils.joeUser); // make sure there's no question operations.delete(ClientRole.SAMPLESTACK_CONTRIBUTOR, TEST_URI); askAndAnswer();//from ww w . j ava 2 s. co m // now we can accept an answer. JsonNode qnaDoc = operations.getJsonDocument(ClientRole.SAMPLESTACK_CONTRIBUTOR, TEST_URI); ArrayNode answers = (ArrayNode) qnaDoc.get("answers"); String answerId = answers.get(0).get("id").asText(); ServerTransform acceptTransform = new ServerTransform("accept-patch"); acceptTransform.add("answerId", answerId); // dummy uri because this transform does an update on parent doc. contribManager.write(DUMMY_URI, new StringHandle(""), acceptTransform); // check accept qnaDoc = operations.getJsonDocument(ClientRole.SAMPLESTACK_CONTRIBUTOR, TEST_URI); assertEquals("doc has acceptedAnswerId", answerId, qnaDoc.get("acceptedAnswerId").asText()); assertTrue("answerid is accepted", qnaDoc.get("answers").get(0).get("accepted").asBoolean()); }
From source file:org.onosproject.sdxl3.config.SdxParticipantsConfig.java
/** * Removes BGP peer details from configuration. * * @param peerIp BGP peer IP address//w ww . j a v a2 s . c o m */ public void removePeer(IpAddress peerIp) { ArrayNode peersArray = (ArrayNode) object.get(PEERS); for (int i = 0; i < peersArray.size(); i++) { if (peersArray.get(i).get(IP).asText().equals(peerIp.toString())) { peersArray.remove(i); return; } } }