List of usage examples for com.fasterxml.jackson.databind JsonNode size
public int size()
From source file:org.activiti.rest.service.api.runtime.ProcessInstanceVariablesCollectionResourceTest.java
/** * Test creating multiple process variables in a single call. POST runtime/process-instance/{processInstanceId}/variables?override=true */// w ww . j a va 2 s . c o m @Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" }) public void testCreateMultipleProcessVariablesWithOverride() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); runtimeService.setVariable(processInstance.getId(), "stringVariable", "initialValue"); ArrayNode requestNode = objectMapper.createArrayNode(); // String variable ObjectNode stringVarNode = requestNode.addObject(); stringVarNode.put("name", "stringVariable"); stringVarNode.put("value", "simple string value"); stringVarNode.put("type", "string"); ObjectNode anotherVariable = requestNode.addObject(); anotherVariable.put("name", "stringVariable2"); anotherVariable.put("value", "another string value"); anotherVariable.put("type", "string"); // Create local variables with a single request HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId())); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertTrue(responseNode.isArray()); assertEquals(2, responseNode.size()); // Check if engine has correct variables set Map<String, Object> variables = runtimeService.getVariablesLocal(processInstance.getId()); assertEquals(2, variables.size()); assertEquals("simple string value", variables.get("stringVariable")); assertEquals("another string value", variables.get("stringVariable2")); }
From source file:org.flowable.rest.service.api.runtime.ProcessInstanceVariablesCollectionResourceTest.java
/** * Test creating multiple process variables in a single call. POST runtime/process-instance/{processInstanceId}/variables?override=true *///from w ww.j a v a2s .c om @Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" }) public void testCreateMultipleProcessVariablesWithOverride() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); runtimeService.setVariable(processInstance.getId(), "stringVariable", "initialValue"); ArrayNode requestNode = objectMapper.createArrayNode(); // String variable ObjectNode stringVarNode = requestNode.addObject(); stringVarNode.put("name", "stringVariable"); stringVarNode.put("value", "simple string value"); stringVarNode.put("type", "string"); ObjectNode anotherVariable = requestNode.addObject(); anotherVariable.put("name", "stringVariable2"); anotherVariable.put("value", "another string value"); anotherVariable.put("type", "string"); // Create local variables with a single request HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId())); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertTrue(responseNode.isArray()); assertEquals(2, responseNode.size()); // Check if engine has correct variables set Map<String, Object> variables = runtimeService.getVariablesLocal(processInstance.getId()); assertEquals(2, variables.size()); assertEquals("simple string value", variables.get("stringVariable")); assertEquals("another string value", variables.get("stringVariable2")); }
From source file:org.opendaylight.nemo.renderer.cli.physicalnetwork.PhysicalResourceLoaderTest.java
@Test public void testBuildHosts() throws Exception { Class<PhysicalResourceLoader> class1 = PhysicalResourceLoader.class; Method method = class1.getDeclaredMethod("buildHosts", new Class[] { JsonNode.class }); method.setAccessible(true);// w w w . j a va 2 s. co m JsonNode hostsNode = mock(JsonNode.class); JsonNode hosts = mock(JsonNode.class); JsonNode host = mock(JsonNode.class); JsonNode host_temp = mock(JsonNode.class); JsonNode host_temp1 = mock(JsonNode.class); JsonNode ipaddrs = mock(JsonNode.class); JsonNode ipaddr = mock(JsonNode.class); List<PhysicalHost> list; when(hostsNode.path(any(String.class))).thenReturn(hosts); when(hosts.size()).thenReturn(1); when(hosts.get(any(Integer.class))).thenReturn(host); //get into method "buildhost" when(host.get(any(String.class))).thenReturn(host_temp); when(host_temp.asText()).thenReturn(new String("00001111-0000-0000-0000-000011112222")) //HOST_ID .thenReturn(new String("hostName")) //HOST_NAME .thenReturn(new String("00:11:22:33:44:55")) //MAC_ADDRESS .thenReturn(new String("nodeId")) //NODE_ID .thenReturn(new String("connetionId"));//PhysicalPortId when(host.path(any(String.class))).thenReturn(ipaddrs); when(ipaddrs.size()).thenReturn(1); when(ipaddrs.get(any(Integer.class))).thenReturn(ipaddr); when(ipaddr.get(any(String.class))).thenReturn(host_temp1); when(host_temp1.asText()).thenReturn(new String("192.168.1.1"));//ipv4_address list = (List<PhysicalHost>) method.invoke(physicalResourceLoader, hostsNode); Assert.assertTrue(list.size() == 1); }
From source file:com.vaushell.superpipes.tools.scribe.fb.FacebookClient.java
private FB_Post convertJsonToPost(final JsonNode node) { final JsonNode nodeFrom = node.get("from"); int count = 0; final JsonNode nodeActions = node.get("actions"); if (nodeActions != null && nodeActions.size() >= 2) { for (final JsonNode nodeAction : nodeActions) { final String name = nodeAction.get("name").asText(); if ("Comment".equalsIgnoreCase(name) || "Like".equalsIgnoreCase(name)) { ++count;//from www . j a v a 2 s. c om } } } return new FB_Post(node.get("id").asText(), convertNodeToString(node.get("message")), convertNodeToString(node.get("link")), convertNodeToString(node.get("name")), convertNodeToString(node.get("caption")), convertNodeToString(node.get("description")), new FB_User(nodeFrom.get("id").asText(), nodeFrom.get("name").asText()), fmtPSTread.parseDateTime(node.get("created_time").asText()), count == 2); }
From source file:org.apache.logging.log4j.core.config.EDNConfiguration.java
private Node constructNode(final String name, final Node parent, final JsonNode jsonNode) { final PluginType<?> type = pluginManager.getPluginType(name); final Node node = new Node(parent, name, type); processAttributes(node, jsonNode);//from ww w.ja v a2 s .com final Iterator<Map.Entry<String, JsonNode>> iter = jsonNode.fields(); final List<Node> children = node.getChildren(); while (iter.hasNext()) { final Map.Entry<String, JsonNode> entry = iter.next(); final JsonNode n = entry.getValue(); if (n.isArray() || n.isObject()) { if (type == null) { status.add(new Status(name, n, ErrorType.CLASS_NOT_FOUND)); } if (n.isArray()) { LOGGER.debug("Processing node for array {}", entry.getKey()); for (int i = 0; i < n.size(); ++i) { final String pluginType = getType(n.get(i), entry.getKey()); final PluginType<?> entryType = pluginManager.getPluginType(pluginType); final Node item = new Node(node, entry.getKey(), entryType); processAttributes(item, n.get(i)); if (pluginType.equals(entry.getKey())) { LOGGER.debug("Processing {}[{}]", entry.getKey(), i); } else { LOGGER.debug("Processing {} {}[{}]", pluginType, entry.getKey(), i); } final Iterator<Map.Entry<String, JsonNode>> itemIter = n.get(i).fields(); final List<Node> itemChildren = item.getChildren(); while (itemIter.hasNext()) { final Map.Entry<String, JsonNode> itemEntry = itemIter.next(); if (itemEntry.getValue().isObject()) { LOGGER.debug("Processing node for object {}", itemEntry.getKey()); itemChildren.add(constructNode(itemEntry.getKey(), item, itemEntry.getValue())); } else if (itemEntry.getValue().isArray()) { final JsonNode array = itemEntry.getValue(); final String entryName = itemEntry.getKey(); LOGGER.debug("Processing array for object {}", entryName); for (int j = 0; j < array.size(); ++j) { itemChildren.add(constructNode(entryName, item, array.get(j))); } } } children.add(item); } } else { LOGGER.debug("Processing node for object {}", entry.getKey()); children.add(constructNode(entry.getKey(), node, n)); } } else { LOGGER.debug("Node {} is of type {}", entry.getKey(), n.getNodeType()); } } String t; if (type == null) { t = "null"; } else { t = type.getElementName() + ':' + type.getPluginClass(); } final String p = node.getParent() == null ? "null" : node.getParent().getName() == null ? LoggerConfig.ROOT : node.getParent().getName(); LOGGER.debug("Returning {} with parent {} of type {}", node.getName(), p, t); return node; }
From source file:com.marklogic.client.test.SPARQLManagerTest.java
@Test public void testConstrainingQueries() throws Exception { // insert two triples for the tests below String localGraphUri = "SPARQLManagerTest.testConstrainingQueries"; // the first triple is a managed triple so GraphManager can write it String triple1 = "<http://example.org/s1> <http://example.org/p1> 'test1'."; gmgr.writeAs(localGraphUri, triple1); // the second triple is an embeded triple so we need a DocumentManager to write it // we're using an embeded triple so we can have other fields on which to query String embededTriple = "<xml>" + "<test2>testValue</test2>" + "<sem:triples xmlns:sem='http://marklogic.com/semantics'>" + "<sem:triple>" + "<sem:subject>http://example.org/s2</sem:subject>" + "<sem:predicate>http://example.org/p2</sem:predicate>" + "<sem:object datatype='http://www.w3.org/2001/XMLSchema#string'>" + "test2</sem:object>" + "</sem:triple>" + "</sem:triples>" + "</xml>"; XMLDocumentManager docMgr = Common.client.newXMLDocumentManager(); QueryManager queryMgr = Common.client.newQueryManager(); docMgr.writeAs(localGraphUri + "/embededTriple.xml", new DocumentMetadataHandle().withCollections(localGraphUri), embededTriple); // test StringQueryDefinition SPARQLQueryDefinition qdef = smgr.newQueryDefinition("select ?s ?p ?o { ?s ?p ?o } limit 100"); qdef.setIncludeDefaultRulesets(false); qdef.setCollections(localGraphUri);/*from w w w .j a va 2 s . c o m*/ qdef.setConstrainingQueryDefinition(queryMgr.newStringDefinition().withCriteria("test1")); JsonNode jsonResults = smgr.executeSelect(qdef, new JacksonHandle()).get(); JsonNode tuples = jsonResults.path("results").path("bindings"); assertEquals(1, tuples.size()); String value = tuples.path(0).path("o").path("value").asText(); assertEquals("test1", value); // test StructuredQueryDefinition StructuredQueryBuilder sqb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition sqdef = sqb.and(sqb.term("test2"), sqb.value(sqb.element("test2"), "testValue")); qdef.setConstrainingQueryDefinition(sqdef); jsonResults = smgr.executeSelect(qdef, new JacksonHandle()).get(); tuples = jsonResults.path("results").path("bindings"); assertEquals(1, tuples.size()); value = tuples.path(0).path("o").path("value").asText(); assertEquals("test2", value); // test XML RawStructuredQueryDefinition String rawXMLStructuredQuery = "<query>" + "<term-query><text>test1</text></term-query>" + "</query>"; StringHandle handle = new StringHandle(rawXMLStructuredQuery).withFormat(Format.XML); RawStructuredQueryDefinition rawStructuredQDef = queryMgr.newRawStructuredQueryDefinition(handle); qdef.setConstrainingQueryDefinition(rawStructuredQDef); jsonResults = smgr.executeSelect(qdef, new JacksonHandle()).get(); tuples = jsonResults.path("results").path("bindings"); assertEquals(1, tuples.size()); value = tuples.path(0).path("o").path("value").asText(); assertEquals("test1", value); // test JSON RawStructuredQueryDefinition String rawJSONStructuredQuery = "{ query:{" + "term-query:{text:'test2'}" + "}}"; handle = new StringHandle(rawJSONStructuredQuery).withFormat(Format.JSON); rawStructuredQDef = queryMgr.newRawStructuredQueryDefinition(handle); qdef.setConstrainingQueryDefinition(rawStructuredQDef); jsonResults = smgr.executeSelect(qdef, new JacksonHandle()).get(); tuples = jsonResults.path("results").path("bindings"); assertEquals(1, tuples.size()); value = tuples.path(0).path("o").path("value").asText(); assertEquals("test2", value); // test RawCombinedQueryDefinition String rawCombinedQuery = "<search xmlns='http://marklogic.com/appservices/search'>" + "<sparql>select ?s ?p ?o { ?s ?p ?o } limit 50</sparql>" + "<options>" + "<constraint name='test2'>" + "<value type='string'><element ns='' name='test2'/></value>" + "</constraint>" + "</options>" + "<query>" + "<and-query>" + "<term-query><text>test2</text></term-query>" + "<value-constraint-query>" + "<constraint-name>test2</constraint-name>" + "<text>testValue</text>" + "</value-constraint-query>" + "</and-query>" + "</query>" + "</search>"; handle = new StringHandle(rawCombinedQuery).withFormat(Format.XML); RawCombinedQueryDefinition rawCombinedQDef = queryMgr.newRawCombinedQueryDefinition(handle); qdef.setConstrainingQueryDefinition(rawCombinedQDef); jsonResults = smgr.executeSelect(qdef, new JacksonHandle()).get(); tuples = jsonResults.path("results").path("bindings"); assertEquals(1, tuples.size()); value = tuples.path(0).path("o").path("value").asText(); assertEquals("test2", value); // this one has no <sparql>, so we'll insert it. String rawCombinedQuery2 = "<search xmlns='http://marklogic.com/appservices/search'>" + "<options>" + "<constraint name='test2'>" + "<value type='string'><element ns='' name='test2'/></value>" + "</constraint>" + "</options>" + "<query>" + "<and-query>" + "<term-query><text>test2</text></term-query>" + "<value-constraint-query>" + "<constraint-name>test2</constraint-name>" + "<text>testValue</text>" + "</value-constraint-query>" + "</and-query>" + "</query>" + "</search>"; handle = new StringHandle(rawCombinedQuery2).withFormat(Format.XML); RawCombinedQueryDefinition rawCombinedQDef2 = queryMgr.newRawCombinedQueryDefinition(handle); qdef.setConstrainingQueryDefinition(rawCombinedQDef2); jsonResults = smgr.executeSelect(qdef, new JacksonHandle()).get(); tuples = jsonResults.path("results").path("bindings"); assertEquals(1, tuples.size()); value = tuples.path(0).path("o").path("value").asText(); assertEquals("test2", value); String rawCombinedJson = "{\"search\" : " + "{\"sparql\":\"select ?s ?p ?o { ?s ?p ?o } limit 100\"," + "\"qtext\":\"testValue\"}}"; handle = new StringHandle(rawCombinedJson).withFormat(Format.JSON); RawCombinedQueryDefinition rawCombinedJsonDef = queryMgr.newRawCombinedQueryDefinition(handle); qdef.setConstrainingQueryDefinition(rawCombinedJsonDef); jsonResults = smgr.executeSelect(qdef, new JacksonHandle()).get(); tuples = jsonResults.path("results").path("bindings"); assertEquals(1, tuples.size()); value = tuples.path(0).path("o").path("value").asText(); assertEquals("test2", value); rawCombinedJson = "{\"search\" : " + "{\"options\" : " + "{\"constraint\": " + "{\"name\":\"test2\", " + " \"value\": " + " { \"type\":\"string\", " + " \"element\" : { \"ns\":\"\", \"name\":\"test2\" } } } } " + "," + "\"query\" : " + "{\"and-query\" : " + "[{\"term-query\": {\"text\": \"test2\"}}," + " {\"value-constraint-query\" : " + "{\"constraint-name\": \"test2\"," + "\"text\":\"testValue\"}" + "}]" + "}" + "}" + "}"; handle = new StringHandle(rawCombinedJson).withFormat(Format.JSON); rawCombinedJsonDef = queryMgr.newRawCombinedQueryDefinition(handle); qdef.setConstrainingQueryDefinition(rawCombinedJsonDef); jsonResults = smgr.executeSelect(qdef, new JacksonHandle()).get(); tuples = jsonResults.path("results").path("bindings"); assertEquals(1, tuples.size()); value = tuples.path(0).path("o").path("value").asText(); assertEquals("test2", value); // clean up the data for this method docMgr.delete(localGraphUri + "/embededTriple.xml"); gmgr.delete(localGraphUri); }
From source file:net.sf.jasperreports.engine.json.expression.member.evaluation.ArraySliceExpressionEvaluator.java
private List<JRJsonNode> goAnywhereDown(JRJsonNode jrJsonNode) { List<JRJsonNode> result = new ArrayList<>(); Deque<JRJsonNode> stack = new ArrayDeque<>(); if (log.isDebugEnabled()) { log.debug("initial stack population with: " + jrJsonNode.getDataNode()); }//w w w .j ava 2s .co 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(); Integer start = getSliceStart(stackDataNode.size()); if (start >= stackDataNode.size()) { continue; } Integer end = getSliceEnd(stackDataNode.size()); if (end < 0) { continue; } for (int i = start; i < end; i++) { JRJsonNode nodeAtIndex = stackNode.createChild(stackDataNode.get(i)); if (applyFilter(nodeAtIndex)) { newNode.add(nodeAtIndex.getDataNode()); } } if (newNode.size() > 0) { result.add(stackNode.createChild(newNode)); } } } return result; }
From source file:com.arantius.tivocommander.MyShows.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getIntent().getExtras(); if (MindRpc.init(this, bundle)) { return;/*from w w w .j a va2s. c om*/ } if (bundle != null) { mFolderId = bundle.getString("folderId"); setTitle(bundle.getString("folderName")); } else { mFolderId = null; setTitle("My Shows"); } Utils.log(String.format("MyShows: folderId:%s", mFolderId)); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.list_my_shows); if (mFolderId != null) { findViewById(R.id.sort_button).setVisibility(View.GONE); } mListAdapter = new ShowsAdapter(this); final ListView lv = getListView(); lv.setAdapter(mListAdapter); lv.setOnItemClickListener(mOnClickListener); lv.setLongClickable(true); lv.setOnItemLongClickListener(this); mDetailCallback = new MindRpcResponseListener() { public void onResponse(MindRpcResponse response) { setProgressIndicator(-1); String itemId = "recordingFolderItem"; if ("deleted".equals(mFolderId)) { itemId = "recording"; } final JsonNode items = response.getBody().path(itemId); ArrayList<Integer> slotMap = mRequestSlotMap.get(response.getRpcId()); MindRpc.saveBodyId(items.path(0).path("bodyId").asText(), MyShows.this); for (int i = 0; i < items.size(); i++) { int pos = slotMap.get(i); JsonNode item = items.get(i); mShowData.set(pos, item); mShowStatus.set(pos, ShowStatus.LOADED); } mRequestSlotMap.remove(response.getRpcId()); mListAdapter.notifyDataSetChanged(); } }; mIdSequenceCallback = new MindRpcResponseListener() { public void onResponse(MindRpcResponse response) { JsonNode body = response.getBody(); if ("error".equals(body.path("status").asText())) { Utils.log("Handling mIdSequenceCallback error response by " + "finishWithRefresh()"); finishWithRefresh(); return; } if (!body.has("objectIdAndType")) { Utils.log("Handling mIdSequenceCallback empty response by " + "finishWithRefresh()"); finishWithRefresh(); return; } setProgressIndicator(-1); mShowIds = (ArrayNode) body.findValue("objectIdAndType"); if (mFolderId == null) { mShowIds.add("deleted"); } if (mShowIds != null) { // e.g. "Suggestions" can be present, but empty! for (int i = 0; i < mShowIds.size(); i++) { mShowData.add(null); mShowStatus.add(ShowStatus.MISSING); } } mListAdapter.notifyDataSetChanged(); } }; startRequest(); }
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); }/* w w w . j a v a 2 s . 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; }