From cc21a025308153e8f187cd3e82cf828191d7b387 Mon Sep 17 00:00:00 2001 From: "rajesh.kumar" Date: Tue, 6 Dec 2022 11:47:24 +0000 Subject: Added depth parameter in query nodes API. Issue-ID: CPS-1381 Change-ID: I73f97f986a817d423f93a8d922dcd9647b1206bb Signed-off-by: rajesh.kumar --- .../cps/rest/controller/DataRestController.java | 18 +++++++++++--- .../cps/rest/controller/QueryRestController.java | 28 ++++++++++++++++------ 2 files changed, 36 insertions(+), 10 deletions(-) (limited to 'cps-rest/src/main/java/org') diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java index 30bed12775..3a9c764bc6 100755 --- a/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java @@ -3,7 +3,7 @@ * Copyright (C) 2020-2022 Bell Canada. * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2021-2022 Nordix Foundation - * Modifications Copyright (C) 2022 TechMahindra Ltd. + * Modifications Copyright (C) 2023 TechMahindra Ltd. * Modifications Copyright (C) 2022 Deutsche Telekom AG * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -93,8 +93,8 @@ public class DataRestController implements CpsDataApi { } @Override - public ResponseEntity getNodeByDataspaceAndAnchor(final String apiVersion, - final String dataspaceName, final String anchorName, final String xpath, final Boolean includeDescendants) { + public ResponseEntity getNodeByDataspaceAndAnchor(final String dataspaceName, + final String anchorName, final String xpath, final Boolean includeDescendants) { final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants) ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS; final DataNode dataNode = cpsDataService.getDataNode(dataspaceName, anchorName, xpath, @@ -103,6 +103,17 @@ public class DataRestController implements CpsDataApi { return new ResponseEntity<>(DataMapUtils.toDataMapWithIdentifier(dataNode, prefix), HttpStatus.OK); } + @Override + public ResponseEntity getNodeByDataspaceAndAnchorV2(final String dataspaceName, final String anchorName, + final String xpath, final String fetchDescendantsOptionAsString) { + final FetchDescendantsOption fetchDescendantsOption = + FetchDescendantsOption.getFetchDescendantsOption(fetchDescendantsOptionAsString); + final DataNode dataNode = cpsDataService.getDataNode(dataspaceName, anchorName, xpath, + fetchDescendantsOption); + final String prefix = prefixResolver.getPrefix(dataspaceName, anchorName, xpath); + return new ResponseEntity<>(DataMapUtils.toDataMapWithIdentifier(dataNode, prefix), HttpStatus.OK); + } + @Override public ResponseEntity updateNodeLeaves(final String apiVersion, final String dataspaceName, final String anchorName, final Object jsonData, final String parentNodeXpath, final String observedTimestamp) { @@ -151,4 +162,5 @@ public class DataRestController implements CpsDataApi { String.format("observed-timestamp must be in '%s' format", ISO_TIMESTAMP_FORMAT)); } } + } diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java index 3e162ae683..81938dcd95 100644 --- a/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2021-2022 Nordix Foundation * Modifications Copyright (C) 2022 Bell Canada. - * Modifications Copyright (C) 2022 TechMahindra Ltd. + * Modifications Copyright (C) 2022-2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,22 +49,36 @@ public class QueryRestController implements CpsQueryApi { private final PrefixResolver prefixResolver; @Override - public ResponseEntity getNodesByDataspaceAndAnchorAndCpsPath(final String apiVersion, - final String dataspaceName, final String anchorName, final String cpsPath, final Boolean includeDescendants) { + public ResponseEntity getNodesByDataspaceAndAnchorAndCpsPath(final String dataspaceName, + final String anchorName, final String cpsPath, final Boolean includeDescendants) { final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants) ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS; + return executeNodesByDataspaceQueryAndCreateResponse(dataspaceName, anchorName, cpsPath, + fetchDescendantsOption); + } + + @Override + public ResponseEntity getNodesByDataspaceAndAnchorAndCpsPathV2(final String dataspaceName, + final String anchorName, final String cpsPath, final String fetchDescendantsOptionAsString) { + final FetchDescendantsOption fetchDescendantsOption = + FetchDescendantsOption.getFetchDescendantsOption(fetchDescendantsOptionAsString); + return executeNodesByDataspaceQueryAndCreateResponse(dataspaceName, anchorName, cpsPath, + fetchDescendantsOption); + } + + private ResponseEntity executeNodesByDataspaceQueryAndCreateResponse(final String dataspaceName, + final String anchorName, final String cpsPath, final FetchDescendantsOption fetchDescendantsOption) { final Collection dataNodes = cpsQueryService.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption); - final List> dataMaps = new ArrayList<>(dataNodes.size()); + final List> dataNodesAsListOfMaps = new ArrayList<>(dataNodes.size()); String prefix = null; for (final DataNode dataNode : dataNodes) { if (prefix == null) { prefix = prefixResolver.getPrefix(dataspaceName, anchorName, dataNode.getXpath()); } final Map dataMap = DataMapUtils.toDataMapWithIdentifier(dataNode, prefix); - dataMaps.add(dataMap); + dataNodesAsListOfMaps.add(dataMap); } - - return new ResponseEntity<>(jsonObjectMapper.asJsonString(dataMaps), HttpStatus.OK); + return new ResponseEntity<>(jsonObjectMapper.asJsonString(dataNodesAsListOfMaps), HttpStatus.OK); } } -- cgit 1.2.3-korg