List of usage examples for com.fasterxml.jackson.databind JsonNode size
public int size()
From source file:org.activiti.rest.dmn.service.api.repository.DmnDeploymentCollectionResourceTest.java
/** * Test getting deployments. GET dmn-repository/deployments *//*from w ww. j av a 2 s . c o m*/ public void testGetDeployments() throws Exception { try { // Alter time to ensure different deployTimes Calendar yesterday = Calendar.getInstance(); yesterday.add(Calendar.DAY_OF_MONTH, -1); dmnEngineConfiguration.getClock().setCurrentTime(yesterday.getTime()); DmnDeployment firstDeployment = dmnRepositoryService.createDeployment().name("Deployment 1") .category("DEF").addClasspathResource("org/activiti/rest/dmn/service/api/repository/simple.dmn") .deploy(); dmnEngineConfiguration.getClock().setCurrentTime(Calendar.getInstance().getTime()); DmnDeployment secondDeployment = dmnRepositoryService.createDeployment().name("Deployment 2") .category("ABC").addClasspathResource("org/activiti/rest/dmn/service/api/repository/simple.dmn") .tenantId("myTenant").deploy(); String baseUrl = DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_DEPLOYMENT_COLLECTION); assertResultsPresentInDataResponse(baseUrl, firstDeployment.getId(), secondDeployment.getId()); // Check name filtering String url = baseUrl + "?name=" + encode("Deployment 1"); assertResultsPresentInDataResponse(url, firstDeployment.getId()); // Check name-like filtering url = baseUrl + "?nameLike=" + encode("%ment 2"); assertResultsPresentInDataResponse(url, secondDeployment.getId()); // Check category filtering url = baseUrl + "?category=DEF"; assertResultsPresentInDataResponse(url, firstDeployment.getId()); // Check category-not-equals filtering url = baseUrl + "?categoryNotEquals=DEF"; assertResultsPresentInDataResponse(url, secondDeployment.getId()); // Check tenantId filtering url = baseUrl + "?tenantId=myTenant"; assertResultsPresentInDataResponse(url, secondDeployment.getId()); // Check tenantId filtering url = baseUrl + "?tenantId=unexistingTenant"; assertResultsPresentInDataResponse(url); // Check tenantId like filtering url = baseUrl + "?tenantIdLike=" + encode("%enant"); assertResultsPresentInDataResponse(url, secondDeployment.getId()); // Check without tenantId filtering url = baseUrl + "?withoutTenantId=true"; assertResultsPresentInDataResponse(url, firstDeployment.getId()); // Check ordering by name CloseableHttpResponse response = executeRequest(new HttpGet( SERVER_URL_PREFIX + DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_DEPLOYMENT_COLLECTION) + "?sort=name&order=asc"), HttpStatus.SC_OK); JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data"); closeResponse(response); assertEquals(2L, dataNode.size()); assertEquals(firstDeployment.getId(), dataNode.get(0).get("id").textValue()); assertEquals(secondDeployment.getId(), dataNode.get(1).get("id").textValue()); // Check ordering by deploy time response = executeRequest(new HttpGet( SERVER_URL_PREFIX + DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_DEPLOYMENT_COLLECTION) + "?sort=deployTime&order=asc"), HttpStatus.SC_OK); dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data"); closeResponse(response); assertEquals(2L, dataNode.size()); assertEquals(firstDeployment.getId(), dataNode.get(0).get("id").textValue()); assertEquals(secondDeployment.getId(), dataNode.get(1).get("id").textValue()); // Check ordering by tenantId response = executeRequest(new HttpGet( SERVER_URL_PREFIX + DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_DEPLOYMENT_COLLECTION) + "?sort=tenantId&order=desc"), HttpStatus.SC_OK); dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data"); closeResponse(response); assertEquals(2L, dataNode.size()); assertEquals(secondDeployment.getId(), dataNode.get(0).get("id").textValue()); assertEquals(firstDeployment.getId(), dataNode.get(1).get("id").textValue()); // Check paging response = executeRequest(new HttpGet( SERVER_URL_PREFIX + DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_DEPLOYMENT_COLLECTION) + "?sort=deployTime&order=asc&start=1&size=1"), HttpStatus.SC_OK); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); dataNode = responseNode.get("data"); assertEquals(1L, dataNode.size()); assertEquals(secondDeployment.getId(), dataNode.get(0).get("id").textValue()); assertEquals(2L, responseNode.get("total").longValue()); assertEquals(1L, responseNode.get("start").longValue()); assertEquals(1L, responseNode.get("size").longValue()); } finally { // Always cleanup any created deployments, even if the test failed List<DmnDeployment> deployments = dmnRepositoryService.createDeploymentQuery().list(); for (DmnDeployment deployment : deployments) { dmnRepositoryService.deleteDeployment(deployment.getId()); } } }
From source file:org.flowable.rest.dmn.service.api.repository.DmnDeploymentCollectionResourceTest.java
/** * Test getting deployments. GET dmn-repository/deployments */// w ww . j a va 2 s . c o m public void testGetDeployments() throws Exception { try { // Alter time to ensure different deployTimes Calendar yesterday = Calendar.getInstance(); yesterday.add(Calendar.DAY_OF_MONTH, -1); dmnEngineConfiguration.getClock().setCurrentTime(yesterday.getTime()); DmnDeployment firstDeployment = dmnRepositoryService.createDeployment().name("Deployment 1") .category("DEF").addClasspathResource("org/flowable/rest/dmn/service/api/repository/simple.dmn") .deploy(); dmnEngineConfiguration.getClock().setCurrentTime(Calendar.getInstance().getTime()); DmnDeployment secondDeployment = dmnRepositoryService.createDeployment().name("Deployment 2") .category("ABC").addClasspathResource("org/flowable/rest/dmn/service/api/repository/simple.dmn") .tenantId("myTenant").deploy(); String baseUrl = DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_DEPLOYMENT_COLLECTION); assertResultsPresentInDataResponse(baseUrl, firstDeployment.getId(), secondDeployment.getId()); // Check name filtering String url = baseUrl + "?name=" + encode("Deployment 1"); assertResultsPresentInDataResponse(url, firstDeployment.getId()); // Check name-like filtering url = baseUrl + "?nameLike=" + encode("%ment 2"); assertResultsPresentInDataResponse(url, secondDeployment.getId()); // Check category filtering url = baseUrl + "?category=DEF"; assertResultsPresentInDataResponse(url, firstDeployment.getId()); // Check category-not-equals filtering url = baseUrl + "?categoryNotEquals=DEF"; assertResultsPresentInDataResponse(url, secondDeployment.getId()); // Check tenantId filtering url = baseUrl + "?tenantId=myTenant"; assertResultsPresentInDataResponse(url, secondDeployment.getId()); // Check tenantId filtering url = baseUrl + "?tenantId=unexistingTenant"; assertResultsPresentInDataResponse(url); // Check tenantId like filtering url = baseUrl + "?tenantIdLike=" + encode("%enant"); assertResultsPresentInDataResponse(url, secondDeployment.getId()); // Check without tenantId filtering url = baseUrl + "?withoutTenantId=true"; assertResultsPresentInDataResponse(url, firstDeployment.getId()); // Check ordering by name CloseableHttpResponse response = executeRequest(new HttpGet( SERVER_URL_PREFIX + DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_DEPLOYMENT_COLLECTION) + "?sort=name&order=asc"), HttpStatus.SC_OK); JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data"); closeResponse(response); assertEquals(2L, dataNode.size()); assertEquals(firstDeployment.getId(), dataNode.get(0).get("id").textValue()); assertEquals(secondDeployment.getId(), dataNode.get(1).get("id").textValue()); // Check ordering by deploy time response = executeRequest(new HttpGet( SERVER_URL_PREFIX + DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_DEPLOYMENT_COLLECTION) + "?sort=deployTime&order=asc"), HttpStatus.SC_OK); dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data"); closeResponse(response); assertEquals(2L, dataNode.size()); assertEquals(firstDeployment.getId(), dataNode.get(0).get("id").textValue()); assertEquals(secondDeployment.getId(), dataNode.get(1).get("id").textValue()); // Check ordering by tenantId response = executeRequest(new HttpGet( SERVER_URL_PREFIX + DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_DEPLOYMENT_COLLECTION) + "?sort=tenantId&order=desc"), HttpStatus.SC_OK); dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data"); closeResponse(response); assertEquals(2L, dataNode.size()); assertEquals(secondDeployment.getId(), dataNode.get(0).get("id").textValue()); assertEquals(firstDeployment.getId(), dataNode.get(1).get("id").textValue()); // Check paging response = executeRequest(new HttpGet( SERVER_URL_PREFIX + DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_DEPLOYMENT_COLLECTION) + "?sort=deployTime&order=asc&start=1&size=1"), HttpStatus.SC_OK); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); dataNode = responseNode.get("data"); assertEquals(1L, dataNode.size()); assertEquals(secondDeployment.getId(), dataNode.get(0).get("id").textValue()); assertEquals(2L, responseNode.get("total").longValue()); assertEquals(1L, responseNode.get("start").longValue()); assertEquals(1L, responseNode.get("size").longValue()); } finally { // Always cleanup any created deployments, even if the test failed List<DmnDeployment> deployments = dmnRepositoryService.createDeploymentQuery().list(); for (DmnDeployment deployment : deployments) { dmnRepositoryService.deleteDeployment(deployment.getId()); } } }
From source file:com.epam.catgenome.manager.externaldb.ncbi.NCBIGeneManager.java
private void parseJsonFromBio(final JsonNode biosystemsResultRoot, final JsonNode biosystemsEntries, final NCBIGeneVO ncbiGeneVO) throws JsonProcessingException { if (biosystemsResultRoot.isArray()) { ncbiGeneVO.setPathwaysNumber(biosystemsResultRoot.size()); List<NCBISummaryVO> pathways = new ArrayList<>(biosystemsResultRoot.size()); for (final JsonNode objNode : biosystemsResultRoot) { JsonNode jsonNode = biosystemsEntries.path(RESULT_PATH).get("" + objNode.asText()); NCBISummaryVO biosystemsReference = mapper.treeToValue(jsonNode, NCBISummaryVO.class); biosystemsReference.setLink( String.format(NCBI_BIOSYSTEM_URL, biosystemsReference.getUid(), ncbiGeneVO.getGeneId())); pathways.add(biosystemsReference); }// w w w .j av a2 s . c om ncbiGeneVO.setBiosystemsReferences(pathways.stream() .sorted(Comparator.comparing(summary -> summary.getBiosystem().getBiosystemname())) .collect(Collectors.toList())); } }
From source file:com.github.fge.jsonschema.syntax.checkers.draftv4.DraftV4TypeSyntaxChecker.java
@Override protected void checkValue(final Collection<JsonPointer> pointers, final ProcessingReport report, final SchemaTree tree) throws ProcessingException { final JsonNode node = getNode(tree); if (node.isTextual()) { final String s = node.textValue(); if (NodeType.fromName(s) == null) report.error(newMsg(tree, "incorrectPrimitiveType").put("valid", ALL_TYPES).put("found", s)); return;/* ww w . ja v a 2 s .co m*/ } final int size = node.size(); if (size == 0) { report.error(newMsg(tree, "emptyArray")); return; } final Set<Equivalence.Wrapper<JsonNode>> set = Sets.newHashSet(); JsonNode element; NodeType type; boolean uniqueElements = true; for (int index = 0; index < size; index++) { element = node.get(index); type = NodeType.getNodeType(element); uniqueElements = set.add(EQUIVALENCE.wrap(element)); if (type != NodeType.STRING) { report.error(newMsg(tree, "incorrectElementType").put("index", index) .put("expected", NodeType.STRING).put("found", type)); continue; } if (NodeType.fromName(element.textValue()) == null) report.error(newMsg(tree, "incorrectPrimitiveType").put("index", index).put("valid", ALL_TYPES) .put("found", element)); } if (!uniqueElements) report.error(newMsg(tree, "elementsNotUnique")); }
From source file:org.activiti.rest.content.service.api.BaseSpringContentRestTestCase.java
protected void assertResultsPresentInPostDataResponseWithStatusCheck(String url, ObjectNode body, int expectedStatusCode, String... expectedResourceIds) throws JsonProcessingException, IOException { int numberOfResultsExpected = 0; if (expectedResourceIds != null) { numberOfResultsExpected = expectedResourceIds.length; }/*w ww. java2 s .c o m*/ // Do the actual call HttpPost post = new HttpPost(SERVER_URL_PREFIX + url); post.setEntity(new StringEntity(body.toString())); CloseableHttpResponse response = executeRequest(post, expectedStatusCode); if (expectedStatusCode == HttpStatus.SC_OK) { // Check status and size JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent()); JsonNode dataNode = rootNode.get("data"); assertEquals(numberOfResultsExpected, dataNode.size()); // Check presence of ID's if (expectedResourceIds != null) { List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedResourceIds)); Iterator<JsonNode> it = dataNode.iterator(); while (it.hasNext()) { String id = it.next().get("id").textValue(); toBeFound.remove(id); } assertTrue( "Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "), toBeFound.isEmpty()); } } closeResponse(response); }
From source file:org.n52.tamis.core.json.deserialize.processes.SingleProcessDescriptionDeserializer.java
private void extractAndAddInputFormat(ProcessDescriptionInput input_short, JsonNode format) { String formatAstring = ""; if (format.isArray()) { // format IS AN ARRAY int numberOfFormatEntries = format.size(); for (int i = 0; i < numberOfFormatEntries; i++) { JsonNode formatEntry = format.get(i); if (i == 0) formatAstring = formatAstring + formatEntry.get("_mimeType").asText(); else//from www . j a v a 2s .c o m formatAstring = formatAstring + " | " + formatEntry.get("_mimeType").asText(); } } else { // format is NOT AN ARRAY formatAstring = format.get("_mimeType").asText(); } input_short.setType(formatAstring); }
From source file:org.n52.tamis.core.json.deserialize.processes.SingleProcessDescriptionDeserializer.java
private void extractAndAddOutputFormat(ProcessDescriptionOutput output_short, JsonNode format) { String formatAstring = ""; if (format.isArray()) { // format IS AN ARRAY int numberOfFormatEntries = format.size(); for (int i = 0; i < numberOfFormatEntries; i++) { JsonNode formatEntry = format.get(i); if (i == 0) formatAstring = formatAstring + formatEntry.get("_mimeType").asText(); else/*w w w .ja va 2s . c o m*/ formatAstring = formatAstring + " | " + formatEntry.get("_mimeType").asText(); } } else { // format is NOT AN ARRAY formatAstring = format.get("_mimeType").asText(); } output_short.setType(formatAstring); }
From source file:org.activiti.rest.service.api.runtime.ProcessInstanceIdentityLinkResourceTest.java
/** * Test getting all identity links./*from w w w. j a va2 s. com*/ */ @Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceIdentityLinkResourceTest.process.bpmn20.xml" }) public void testGetIdentityLinks() throws Exception { // Test candidate user/groups links + manual added identityLink ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); runtimeService.addUserIdentityLink(processInstance.getId(), "john", "customType"); runtimeService.addUserIdentityLink(processInstance.getId(), "paul", "candidate"); // Execute the request CloseableHttpResponse response = executeRequest( new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINKS_COLLECTION, processInstance.getId())), HttpStatus.SC_OK); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertTrue(responseNode.isArray()); assertEquals(2, responseNode.size()); boolean johnFound = false; boolean paulFound = false; for (int i = 0; i < responseNode.size(); i++) { ObjectNode link = (ObjectNode) responseNode.get(i); assertNotNull(link); if (!link.get("user").isNull()) { if (link.get("user").textValue().equals("john")) { assertEquals("customType", link.get("type").textValue()); assertTrue(link.get("group").isNull()); assertTrue(link.get("url").textValue() .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINK, processInstance.getId(), "john", "customType"))); johnFound = true; } else { assertEquals("paul", link.get("user").textValue()); assertEquals("candidate", link.get("type").textValue()); assertTrue(link.get("group").isNull()); assertTrue(link.get("url").textValue() .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINK, processInstance.getId(), "paul", "candidate"))); paulFound = true; } } } assertTrue(johnFound); assertTrue(paulFound); }
From source file:org.flowable.rest.service.api.runtime.ProcessInstanceIdentityLinkResourceTest.java
/** * Test getting all identity links.//from w w w. java 2 s. com */ @Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceIdentityLinkResourceTest.process.bpmn20.xml" }) public void testGetIdentityLinks() throws Exception { // Test candidate user/groups links + manual added identityLink ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); runtimeService.addUserIdentityLink(processInstance.getId(), "john", "customType"); runtimeService.addUserIdentityLink(processInstance.getId(), "paul", "candidate"); // Execute the request CloseableHttpResponse response = executeRequest( new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINKS_COLLECTION, processInstance.getId())), HttpStatus.SC_OK); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertTrue(responseNode.isArray()); assertEquals(2, responseNode.size()); boolean johnFound = false; boolean paulFound = false; for (int i = 0; i < responseNode.size(); i++) { ObjectNode link = (ObjectNode) responseNode.get(i); assertNotNull(link); if (!link.get("user").isNull()) { if (link.get("user").textValue().equals("john")) { assertEquals("customType", link.get("type").textValue()); assertTrue(link.get("group").isNull()); assertTrue(link.get("url").textValue() .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINK, processInstance.getId(), "john", "customType"))); johnFound = true; } else { assertEquals("paul", link.get("user").textValue()); assertEquals("candidate", link.get("type").textValue()); assertTrue(link.get("group").isNull()); assertTrue(link.get("url").textValue() .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINK, processInstance.getId(), "paul", "candidate"))); paulFound = true; } } } assertTrue(johnFound); assertTrue(paulFound); }
From source file:com.unboundid.scim2.common.utils.JsonDiff.java
/** * Removes any fields with the {@code null} value or an empty array. * * @param node The node with {@code null} and empty array values removed. *//*from w ww . j av a2 s . c o m*/ private void removeNullAndEmptyValues(final JsonNode node) { Iterator<JsonNode> si = node.elements(); while (si.hasNext()) { JsonNode field = si.next(); if (field.isNull() || field.isArray() && field.size() == 0) { si.remove(); } else if (field.isContainerNode()) { removeNullAndEmptyValues(field); } } }