diff options
author | arpitsingh <as00745003@techmahindra.com> | 2023-01-09 19:53:10 +0530 |
---|---|---|
committer | Arpit Singh <as00745003@techmahindra.com> | 2023-02-17 11:20:35 +0000 |
commit | 0bd192ca12ac2f768e44d0d3482785c79a881904 (patch) | |
tree | a91a96325ecaa38adaa4b9420e4655b6cbea85a3 /cps-rest/src/main | |
parent | 9575b84ab4e2db885d8761a98eaae9ff3a06aa81 (diff) |
CPS-1401 Implement V2 of GET Data Node API
- Modified the GET Data Node API so it returns all the data nodes when
xpath set to root "/"
- Fragment Repository now returns a collection of Fragment Entities
- Instead of returning only the first Fragment Entity now all fragment
entities are returned when xpath is set to root
- The Fragemnt Entities are further processed to a Collection of Data
Nodes. As opposed to singular Data Node in current implementation.
- Finally the DataRestController also returns a Collection of Data
Nodes when xpath is set to root and valid data is present
- Response body changed from JSON object to JSON Array.
- Exception handling for invalid xpath and non-existing xpath is now
done separately at persistence layer.
- Refactored code against CPS-1422
- Deprecated getDataNode method from Service and Persistence layer
- Modified V1 of Get Data Node API to use the getDataNodes method and
get the first data node from the collection returned.
- Modified NCMP to use getDataNodes method
- NCMP still does not support multiple data nodes. It retrieves the
first data node from the collection returned by getDataNodes
Signed-off-by: arpitsingh <as00745003@techmahindra.com>
Change-Id: I494a5740a53f65376d135fcb9f1e2e8900a2803e
Diffstat (limited to 'cps-rest/src/main')
-rwxr-xr-x | cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java | 31 |
1 files changed, 20 insertions, 11 deletions
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 3a9c764bc6..80cfb8ce0b 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) 2023 TechMahindra Ltd. + * Modifications Copyright (C) 2022-2023 TechMahindra Ltd. * Modifications Copyright (C) 2022 Deutsche Telekom AG * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,6 +26,10 @@ package org.onap.cps.rest.controller; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; import javax.validation.ValidationException; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; @@ -97,21 +101,27 @@ public class DataRestController implements CpsDataApi { 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, - fetchDescendantsOption); - final String prefix = prefixResolver.getPrefix(dataspaceName, anchorName, xpath); + final DataNode dataNode = cpsDataService.getDataNodes(dataspaceName, anchorName, xpath, + fetchDescendantsOption).iterator().next(); + final String prefix = prefixResolver.getPrefix(dataspaceName, anchorName, dataNode.getXpath()); return new ResponseEntity<>(DataMapUtils.toDataMapWithIdentifier(dataNode, prefix), HttpStatus.OK); } @Override public ResponseEntity<Object> getNodeByDataspaceAndAnchorV2(final String dataspaceName, final String anchorName, - final String xpath, final String fetchDescendantsOptionAsString) { + 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); + FetchDescendantsOption.getFetchDescendantsOption(fetchDescendantsOptionAsString); + final Collection<DataNode> dataNodes = cpsDataService.getDataNodes(dataspaceName, anchorName, xpath, + fetchDescendantsOption); + final List<Map<String, Object>> dataMaps = new ArrayList<>(dataNodes.size()); + for (final DataNode dataNode: dataNodes) { + final String 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); } @Override @@ -162,5 +172,4 @@ public class DataRestController implements CpsDataApi { String.format("observed-timestamp must be in '%s' format", ISO_TIMESTAMP_FORMAT)); } } - } |