DataRestController.java | @Override public ResponseEntity<Object> getNodeByDataspaceAndAnchorgetNodeByDataspaceAndAnchorV2(final String dataspaceName, final String anchorName, final String xpath, final String descendants) { final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants) ? new FetchDescendantsOption(depth) : FetchDescendantsOption.OMIT_DESCENDANTSgetFetchDescendantOption(descendants); final DataNode dataNode = cpsDataService.getDataNode(dataspaceName, anchorName, xpath, fetchDescendantsOption, depth); final String prefix = prefixResolver.getPrefix(dataspaceName, anchorName, xpath); return new ResponseEntity<>(DataMapUtils.toDataMapWithIdentifier(dataNode, prefix), HttpStatus.OK); } private FetchDescendantsOption getFetchDescendantsOptiongetFetchDescendantOption(final String descendants) { if (null == descendants || descendants.trim().isEmpty() || "-1".equals(descendants) || "all".equals(descendants)) { return FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS; } else if ("0".equals(descendants) || "none".equals(descendants)) { return FetchDescendantsOption.OMIT_DESCENDANTS; } else { final Integer depth = Integer.valueOf(descendants); return new FetchDescendantsOption(depth); } } |
QueryRestController.java | @Override public ResponseEntity<Object> getNodesByDataspaceAndAnchorAndCpsPath(final String dataspaceName, final String anchorName, final String cpsPath, final Boolean includeDescendants) { final FetchDescendantsOption(Integer.valueOf(descendants) fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants) ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS; final Collection<DataNode> dataNodes = cpsQueryService.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption); final List<Map<String, Object>> dataMaps = new ArrayList<>(dataNodes.size()); String prefix = null; for (final DataNode dataNode : dataNodes) { if (prefix == null) { prefix = prefixResolver.getPrefix(dataspaceName, anchorName, dataNode.getXpath()); } final Map<String, Object> dataMap = DataMapUtils.toDataMapWithIdentifier(dataNode, prefix); dataMaps.add(dataMap); }
return new ResponseEntity<>(jsonObjectMapper.asJsonString(dataMaps), HttpStatus.OK); }
|