List of usage examples for com.fasterxml.jackson.databind.node ArrayNode get
public JsonNode get(String paramString)
From source file:ru.histone.optimizer.SafeASTEvaluationOptimizerTest.java
@Test public void constant_folding_simplest() throws IOException, HistoneException { String input = input("constant_folding/simplest.tpl"); ArrayNode ast = histone.parseTemplateToAST(new StringReader(input)); ArrayNode finalAst = histone.optimizeAST(ast); assertTrue(finalAst.get(0).asInt() == 7); // Assert that evaluation results are equal String astS = histone.evaluateAST(ast); String finalAstS = histone.evaluateAST(finalAst); assertEquals(astS, finalAstS);//from w w w . j ava2 s . c o m }
From source file:net.idea.opentox.cli.dataset.DatasetClient.java
@Override public List<Dataset> processPayload(InputStream in, String mediaType) throws RestException, IOException { List<Dataset> list = null; if (mime_json.equals(mediaType)) { ObjectMapper m = new ObjectMapper(); JsonNode node = m.readTree(in);//ww w .j a va 2s . c o m if (callback != null) callback.callback(node); ArrayNode data = (ArrayNode) node.get("dataset"); if (data != null) for (int i = 0; i < data.size(); i++) { JsonNode metadata = data.get(i); Dataset dataset = new Dataset(new Identifier(metadata.get("URI").textValue())); if (list == null) list = new ArrayList<Dataset>(); list.add(dataset); try { dataset.getMetadata().setTitle(metadata.get("title").textValue()); } catch (Exception x) { } try { dataset.getMetadata().setSeeAlso(metadata.get("seeAlso").textValue()); } catch (Exception x) { } try { dataset.getMetadata().setStars(metadata.get("stars").intValue()); } catch (Exception x) { } dataset.getMetadata().setRights(new Rights()); try { dataset.getMetadata().getRights().setRightsHolder(metadata.get("rightsHolder").textValue()); } catch (Exception x) { } try { dataset.getMetadata().getRights().setURI(metadata.get("rights").get("URI").textValue()); } catch (Exception x) { } try { dataset.getMetadata().getRights() .setType(_type.rights.valueOf(metadata.get("rights").get("type").textValue())); } catch (Exception x) { } } return list; } else if (mime_rdfxml.equals(mediaType)) { return super.processPayload(in, mediaType); } else if (mime_n3.equals(mediaType)) { return super.processPayload(in, mediaType); } else if (mime_csv.equals(mediaType)) { return super.processPayload(in, mediaType); } else return super.processPayload(in, mediaType); }
From source file:com.discover.cls.processors.cls.JSONToAttributes.java
private void addKeys(final String currentPath, final JsonNode jsonNode, final String separator, final boolean preserveType, final boolean flattenArrays, final Map<String, String> map) { if (jsonNode.isObject()) { ObjectNode objectNode = (ObjectNode) jsonNode; Iterator<Map.Entry<String, JsonNode>> iter = objectNode.fields(); String pathPrefix = currentPath.isEmpty() ? "" : currentPath + separator; while (iter.hasNext()) { Map.Entry<String, JsonNode> entry = iter.next(); addKeys(pathPrefix + entry.getKey(), entry.getValue(), separator, preserveType, flattenArrays, map); }//from w ww .j a v a2 s .c om } else if (jsonNode.isArray()) { if (flattenArrays) { ArrayNode arrayNode = (ArrayNode) jsonNode; for (int i = 0; i < arrayNode.size(); i++) { addKeys(currentPath + "[" + i + "]", arrayNode.get(i), separator, preserveType, flattenArrays, map); } } else { map.put(currentPath, jsonNode.toString()); } } else if (jsonNode.isValueNode()) { ValueNode valueNode = (ValueNode) jsonNode; map.put(currentPath, valueNode.isTextual() && preserveType ? valueNode.toString() : valueNode.textValue()); } }
From source file:com.basho.riak.client.core.operations.itest.ITestMapReduceOperation.java
private void testBasicMR(Namespace namespace) throws InterruptedException, ExecutionException, IOException { RiakObject obj = new RiakObject(); obj.setValue(BinaryValue.create("Alice was beginning to get very tired of sitting by her sister on the " + "bank, and of having nothing to do: once or twice she had peeped into the " + "book her sister was reading, but it had no pictures or conversations in " + "it, 'and what is the use of a book,' thought Alice 'without pictures or " + "conversation?'")); Location location = new Location(namespace, BinaryValue.unsafeCreate("p1".getBytes())); StoreOperation storeOp = new StoreOperation.Builder(location).withContent(obj).build(); cluster.execute(storeOp);/* ww w . ja v a2 s . c o m*/ storeOp.get(); obj.setValue(BinaryValue.create("So she was considering in her own mind (as well as she could, for the " + "hot day made her feel very sleepy and stupid), whether the pleasure " + "of making a daisy-chain would be worth the trouble of getting up and " + "picking the daisies, when suddenly a White Rabbit with pink eyes ran " + "close by her.")); location = new Location(namespace, BinaryValue.unsafeCreate("p2".getBytes())); storeOp = new StoreOperation.Builder(location).withContent(obj).build(); cluster.execute(storeOp); storeOp.get(); obj.setValue(BinaryValue.create("The rabbit-hole went straight on like a tunnel for some way, and then " + "dipped suddenly down, so suddenly that Alice had not a moment to think " + "about stopping herself before she found herself falling down a very deep " + "well.")); location = new Location(namespace, BinaryValue.unsafeCreate("p3".getBytes())); storeOp = new StoreOperation.Builder(location).withContent(obj).build(); cluster.execute(storeOp); storeOp.get(); String bName = namespace.getBucketNameAsString(); String bType = namespace.getBucketTypeAsString(); String query = "{\"inputs\":[[\"" + bName + "\",\"p1\",\"\",\"" + bType + "\"]," + "[\"" + bName + "\",\"p2\",\"\",\"" + bType + "\"]," + "[\"" + bName + "\",\"p3\",\"\",\"" + bType + "\"]]," + "\"query\":[{\"map\":{\"language\":\"javascript\",\"source\":\"" + "function(v) {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;}" + "\"}},{\"reduce\":{\"language\":\"javascript\",\"source\":\"" + "function(v) {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];}\"}}]}"; MapReduceOperation mrOp = new MapReduceOperation.Builder(BinaryValue.unsafeCreate(query.getBytes())) .build(); cluster.execute(mrOp); mrOp.await(); assertTrue(mrOp.isSuccess()); ArrayNode resultList = mrOp.get().getResults().get(1); // The query should return one result which is a JSON array containing a // single JSON object that is a asSet of word counts. assertEquals(resultList.size(), 1); String json = resultList.get(0).toString(); ObjectMapper oMapper = new ObjectMapper(); @SuppressWarnings("unchecked") Map<String, Integer> resultMap = oMapper.readValue(json, Map.class); assertNotNull(resultMap.containsKey("the")); assertEquals(Integer.valueOf(8), resultMap.get("the")); resetAndEmptyBucket(namespace); }
From source file:com.activiti.service.activiti.ProcessInstanceService.java
public List<String> getCompletedActivityInstancesAndProcessDefinitionId(ServerConfig serverConfig, String processInstanceId) { URIBuilder builder = clientUtil.createUriBuilder(HISTORIC_ACTIVITY_INSTANCE_LIST_URL); builder.addParameter("processInstanceId", processInstanceId); //builder.addParameter("finished", "true"); builder.addParameter("sort", "startTime"); builder.addParameter("order", "asc"); builder.addParameter("size", DEFAULT_ACTIVITY_SIZE); HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder)); JsonNode node = clientUtil.executeRequest(get, serverConfig); List<String> result = new ArrayList<String>(); if (node.has("data") && node.get("data").isArray()) { ArrayNode data = (ArrayNode) node.get("data"); ObjectNode activity = null;/*from www .j av a2 s . c om*/ for (int i = 0; i < data.size(); i++) { activity = (ObjectNode) data.get(i); if (activity.has("activityType")) { result.add(activity.get("activityId").asText()); } } } return result; }
From source file:graphene.dao.es.impl.CombinedDAOESImpl.java
@Override public G_SearchResults search(final G_EntityQuery pq) { // TODO: Use a helper class final G_SearchResults results = G_SearchResults.newBuilder().setTotal(0) .setResults(new ArrayList<G_SearchResult>()).build(); final List<G_SearchResult> resultsList = new ArrayList<G_SearchResult>(); JestResult jestResult = new JestResult(null); try {// w w w .ja v a 2 s . co m final io.searchbox.core.Search.Builder action = buildSearchAction(pq); JestClient jestClient = c.getClient(); synchronized (jestClient) { jestResult = jestClient.execute(action.build()); } } catch (final DataAccessException e) { e.printStackTrace(); } catch (final Exception e) { e.printStackTrace(); } // logger.debug(jestResult.getJsonString()); JsonNode rootNode; long totalNumberOfPossibleResults = 0l; try { rootNode = mapper.readValue(jestResult.getJsonString(), JsonNode.class); if ((rootNode != null) && (rootNode.get("hits") != null) && (rootNode.get("hits").get("total") != null)) { totalNumberOfPossibleResults = rootNode.get("hits").get("total").asLong(); logger.debug("Found " + totalNumberOfPossibleResults + " hits in hitparent!"); final ArrayNode actualListOfHits = getListOfHitsFromResult(jestResult); for (int i = 0; i < actualListOfHits.size(); i++) { final JsonNode currentHit = actualListOfHits.get(i); if (ValidationUtils.isValid(currentHit)) { final G_SearchResult result = db.buildSearchResultFromDocument(i, currentHit, pq); if (result == null) { logger.error("could not build search result from hit " + currentHit.toString()); } CollectionUtils.addIgnoreNull(resultsList, result); } else { logger.error("Invalid search result at index " + i + " for query " + pq.toString()); } } } } catch (final IOException e) { e.printStackTrace(); } results.setResults(resultsList); results.setTotal(totalNumberOfPossibleResults); return results; }
From source file:org.flowable.admin.service.engine.ProcessInstanceService.java
public List<String> getCompletedActivityInstancesAndProcessDefinitionId(ServerConfig serverConfig, String processInstanceId) { URIBuilder builder = clientUtil.createUriBuilder(HISTORIC_ACTIVITY_INSTANCE_LIST_URL); builder.addParameter("processInstanceId", processInstanceId); // builder.addParameter("finished", "true"); builder.addParameter("sort", "startTime"); builder.addParameter("order", "asc"); builder.addParameter("size", DEFAULT_ACTIVITY_SIZE); HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder)); JsonNode node = clientUtil.executeRequest(get, serverConfig); List<String> result = new ArrayList<String>(); if (node.has("data") && node.get("data").isArray()) { ArrayNode data = (ArrayNode) node.get("data"); ObjectNode activity = null;/*from w w w. j a v a 2 s.co m*/ for (int i = 0; i < data.size(); i++) { activity = (ObjectNode) data.get(i); if (activity.has("activityType")) { result.add(activity.get("activityId").asText()); } } } return result; }
From source file:org.pentaho.metaverse.impl.model.kettle.json.TransMetaJsonDeserializer.java
protected void deserializeHops(TransMeta transMeta, JsonNode root, ObjectMapper mapper) { ArrayNode hopsArray = (ArrayNode) root.get(TransMetaJsonSerializer.JSON_PROPERTY_HOPS); for (int i = 0; i < hopsArray.size(); i++) { JsonNode hopNode = hopsArray.get(i); try {/*from w w w . j av a2s. co m*/ HopInfo hop = mapper.readValue(hopNode.toString(), HopInfo.class); if (hop != null) { TransHopMeta hopMeta = new TransHopMeta(); hopMeta.setFromStep(transMeta.findStep(hop.getFromStepName())); hopMeta.setToStep(transMeta.findStep(hop.getToStepName())); hopMeta.setEnabled(hop.isEnabled()); transMeta.addTransHop(hopMeta); } } catch (IOException e) { LOGGER.warn(Messages.getString("WARNING.Deserialization.Trans.Hops"), e); } } }
From source file:org.pentaho.metaverse.impl.model.kettle.json.TransMetaJsonDeserializer.java
protected void deserializeVariables(TransMeta transMeta, JsonNode node, ObjectMapper mapper) throws IOException { ArrayNode varsArrayNode = (ArrayNode) node.get(TransMetaJsonSerializer.JSON_PROPERTY_VARIABLES); for (int i = 0; i < varsArrayNode.size(); i++) { JsonNode paramNode = varsArrayNode.get(i); ParamInfo param = mapper.readValue(paramNode.toString(), ParamInfo.class); transMeta.setVariable(param.getName(), param.getValue()); }/*from w w w . j ava 2s.c om*/ }