List of usage examples for com.fasterxml.jackson.databind JsonNode elements
public Iterator<JsonNode> elements()
From source file:de.jlo.talendcomp.json.JsonDocument.java
public static int countNotNullAttributes(JsonNode node) { if (node == null) { throw new IllegalArgumentException("Node is null"); } else if (node.size() == 0) { return 0; } else {//from w ww . j a va2 s. co m int count = 0; Iterator<JsonNode> it = node.elements(); while (it.hasNext()) { JsonNode valueNode = it.next(); if (valueNode.isMissingNode() == false && valueNode.isNull() == false) { count++; } } return count; } }
From source file:com.sitewhere.wso2.identity.scim.Wso2ScimAssetModule.java
/** * Parse email fields./*from ww w . ja v a2 s. c o m*/ * * @param resource * @param asset */ protected void parseEmail(JsonNode resource, PersonAsset asset) { JsonNode emails = resource.get(IScimFields.EMAILS); if (emails != null) { int index = 1; Iterator<JsonNode> it = emails.elements(); while (it.hasNext()) { String email = it.next().textValue(); asset.getProperties().put("emailAddress" + index, email); asset.setEmailAddress(email); } } }
From source file:eu.europa.ec.fisheries.uvms.reporting.service.util.ReportDeserializer.java
private void addArea(JsonNode area, List<FilterDTO> filterDTOList, Long reportId) { if (area != null) { Iterator<JsonNode> elements = area.elements(); while (elements.hasNext()) { JsonNode next = elements.next(); filterDTOList.add(AreaFilterDTO.AreaFilterDTOBuilder().reportId(reportId) .id(next.get(FilterDTO.ID) != null ? next.get(FilterDTO.ID).longValue() : null) .areaId(next.get(AreaFilterDTO.JSON_ATTR_AREA_ID).longValue()) .areaType(next.get(AreaFilterDTO.JSON_ATTR_AREA_TYPE).textValue()).build()); }//from w ww. j av a2s. com } }
From source file:org.talend.dataprep.api.filter.SimpleFilterService.java
private Predicate<DataSetRow> buildFilter(JsonNode currentNode, RowMetadata rowMetadata) { final Iterator<JsonNode> children = currentNode.elements(); final JsonNode operationContent = children.next(); final String columnId = operationContent.has("field") ? operationContent.get("field").asText() : null; final String value = operationContent.has("value") ? operationContent.get("value").asText() : null; final Iterator<String> propertiesIterator = currentNode.fieldNames(); if (!propertiesIterator.hasNext()) { throw new UnsupportedOperationException( "Unsupported query, empty filter definition: " + currentNode.toString()); }/* w w w.j a v a 2 s . c o m*/ final String operation = propertiesIterator.next(); if (columnId == null && allowFullFilter(operation)) { // Full data set filter (no column) final List<ColumnMetadata> columns = rowMetadata.getColumns(); Predicate<DataSetRow> predicate = null; if (!columns.isEmpty()) { predicate = buildOperationFilter(currentNode, rowMetadata, columns.get(0).getId(), operation, value); for (int i = 1; i < columns.size(); i++) { predicate = predicate.or(buildOperationFilter(currentNode, rowMetadata, columns.get(i).getId(), operation, value)); } } return predicate; } else { return buildOperationFilter(currentNode, rowMetadata, columnId, operation, value); } }
From source file:eu.europa.ec.fisheries.uvms.reporting.service.util.ReportDeserializer.java
private void addVmsFilters(JsonNode vms, List<FilterDTO> filterDTOList, Long reportId) { if (vms != null) { Iterator<JsonNode> elements = vms.elements(); while (elements.hasNext()) { JsonNode next = elements.next(); FilterType type = FilterType.valueOf(next.get("type").textValue()); switch (type) { case vmspos: addPositionFilter(filterDTOList, reportId, next); break; case vmstrack: addTrackFilterDTO(filterDTOList, reportId, next); break; case vmsseg: addVmsSegmentFilterDTO(filterDTOList, reportId, next); break; default: throw new InvalidParameterException("Unsupported parameter"); }// w ww . j av a 2s. c o m } } }
From source file:eu.europa.ec.fisheries.uvms.reporting.service.util.ReportDeserializer.java
private void addAssets(JsonNode asset, List<FilterDTO> filterDTOList, Long reportId) { if (asset != null) { Iterator<JsonNode> elements = asset.elements(); while (elements.hasNext()) { JsonNode next = elements.next(); FilterType type = FilterType.valueOf(next.get("type").textValue()); switch (type) { case asset: addAssetFilterDTO(filterDTOList, reportId, next); break; case vgroup: addAssetGroupFilterDTO(filterDTOList, reportId, next); break; default: throw new InvalidParameterException("Unsupported parameter value"); }//from w w w .java 2 s .co m } } }
From source file:com.sitewhere.server.asset.scim.Wso2ScimAssetModule.java
/** * Make remote call to list all user assets, then parse and cache them. * /*www . ja va 2 s .co m*/ * @throws SiteWhereException */ protected ICommandResponse cacheAssetData() throws SiteWhereException { assetCache.clear(); LOGGER.info("Caching search data."); int totalAssets = 0; long startTime = System.currentTimeMillis(); WebClient caller = WebClient.fromClient(client); caller.accept(MediaType.APPLICATION_JSON_TYPE); Response response = caller.get(); Object entity = response.getEntity(); try { JsonNode json = mapper.readTree((InputStream) entity); JsonNode resources = json.get(IScimFields.RESOURCES); if (resources == null) { String message = "SCIM JSON response did not contain a 'resources' section."; LOGGER.info(message); return new CommandResponse(CommandResult.Failed, message); } Iterator<JsonNode> it = resources.elements(); while (it.hasNext()) { JsonNode resource = it.next(); PersonAsset asset = parse(resource); assetCache.put(asset.getId(), asset); totalAssets++; } } catch (JsonParseException e) { throw new SiteWhereException("Unable to parse asset response.", e); } catch (IOException e) { throw new SiteWhereException("Unable to read asset response.", e); } long totalTime = System.currentTimeMillis() - startTime; String message = "Cached " + totalAssets + " assets in " + totalTime + "ms."; LOGGER.info(message); return new CommandResponse(CommandResult.Successful, message); }
From source file:org.talend.dataprep.api.filter.SimpleFilterService.java
@Override public Predicate<DataSetRow> build(String filterAsString, RowMetadata rowMetadata) { if (isEmpty(filterAsString)) { return r -> true; }//from w w w . j av a2 s . c o m try { ObjectMapper mapper = new ObjectMapper(); final JsonNode root = mapper.reader().readTree(filterAsString); final Iterator<JsonNode> elements = root.elements(); if (!elements.hasNext()) { throw new IllegalArgumentException("Malformed filter: " + filterAsString); } else { return buildFilter(root, rowMetadata); } } catch (Exception e) { throw new TalendRuntimeException(BaseErrorCodes.UNABLE_TO_PARSE_FILTER, e); } }
From source file:com.ning.metrics.action.hdfs.data.JsonNodeComparable.java
@Override public int compareTo(Object o) { JsonNode thing = (JsonNode) o; if (isMissingNode() && !thing.isMissingNode()) { return -1; } else if (!isMissingNode() && thing.isMissingNode()) { return 1; }/*ww w . ja va 2s. co m*/ int mySize = 0; Iterator<JsonNode> myIterator = elements(); while (myIterator.hasNext()) { mySize++; } int hisSize = 0; Iterator<JsonNode> hisIterator = thing.elements(); while (hisIterator.hasNext()) { hisSize++; } if (mySize != 0 || hisSize != 0) { if (mySize > hisSize) { return 1; } else if (mySize < hisSize) { return -1; } } // Looks like both nodes don't have children if (isValueNode() && thing.isValueNode()) { return textValue().compareTo(thing.textValue()); } else { if (equals(thing)) { return 0; } else { // Weak. When do we come here? return toString().compareTo(thing.toString()); } } }
From source file:eu.europa.ec.fisheries.uvms.reporting.service.util.ReportDeserializer.java
private void addGroupCriteria(JsonNode groupBy, List<FilterDTO> filterDTOList, Long reportId, JsonParser jp) { if (groupBy != null) { List list = IteratorUtils.toList(groupBy.elements()); for (int i = 0; i < list.size(); i++) { String code = ((JsonNode) list.get(i)).get("code").asText(); JsonNode valueNode = ((JsonNode) list.get(i)).get("values"); List<GroupCriteriaType> groupCriteriaList = null; if (valueNode != null) { List<String> strings = ((ObjectMapper) jp.getCodec()).convertValue(valueNode, List.class); groupCriteriaList = GroupCriteriaFilterMapper.INSTANCE .mapGroupCriteriaTypeListToStringList(strings); }/*from w w w . j a v a2 s.c o m*/ filterDTOList.add(new CriteriaFilterDTO(code, groupCriteriaList, i + 1, reportId)); } } }