aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiranjana <niranjana.y60@wipro.com>2021-08-18 12:59:18 +0000
committerNiranjana <niranjana.y60@wipro.com>2021-08-20 06:31:43 +0000
commite101edabb28f7c31de9102d8111be51cd7d88f83 (patch)
tree779922da6366d116433931025c8520f70f572357
parent433ba106cf99762039b7bd6a430eaf24b45d2271 (diff)
Support cps-path query and list-node api
Issue-ID: CPS-570 Signed-off-by: Niranjana <niranjana.y60@wipro.com> Change-Id: Ie8a7d08257d51a022d00e3431e68f4a633d4e322
-rw-r--r--cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/client/CpsRestClient.java48
-rw-r--r--cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java5
2 files changed, 35 insertions, 18 deletions
diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/client/CpsRestClient.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/client/CpsRestClient.java
index e1301fb..8bf0bed 100644
--- a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/client/CpsRestClient.java
+++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/client/CpsRestClient.java
@@ -47,6 +47,8 @@ public class CpsRestClient {
private static final String POST_API_PATH = "/anchors/{anchor}/nodes";
+ private static final String LIST_NODE_API_PATH = "/anchors/{anchor}/list-node";
+
@Autowired
private RestTemplate restTemplate;
@@ -63,13 +65,23 @@ public class CpsRestClient {
public String fetchNode(final String anchor, final String xpath,
final String requestType, final Boolean includeDescendants) throws CpsClientException {
final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
- queryParams.add("xpath", xpath);
- queryParams.add("include-descendants", includeDescendants.toString());
final CpsConfiguration cpsConfiguration = "cpsCore".equals(appConfiguration.getCpsClient())
? appConfiguration.getCpsCoreConfiguration() : appConfiguration.getNcmpConfiguration();
-
- final String path = "query".equals(requestType) ? QUERY_API_PATH : NODES_API_PATH;
+ String path = NODES_API_PATH;
+ switch (requestType) {
+ case "query-cps-path":
+ queryParams.add("cps-path", xpath);
+ path = QUERY_API_PATH;
+ break;
+ case "query":
+ queryParams.add("xpath", xpath);
+ path = QUERY_API_PATH;
+ break;
+ default:
+ queryParams.add("xpath", xpath);
+ }
+ queryParams.add("include-descendants", includeDescendants.toString());
final String uri = buildCpsUrl(cpsConfiguration.getUrl(), path, anchor, queryParams);
final HttpHeaders headers = new HttpHeaders();
@@ -120,18 +132,22 @@ public class CpsRestClient {
String uri = buildCpsUrl(cpsConfiguration.getUrl(), POST_API_PATH, anchor, queryParams);
try {
- if (requestType.equalsIgnoreCase("post")) {
- uri = buildCpsUrl(cpsConfiguration.getUrl(), POST_API_PATH, anchor, new LinkedMultiValueMap<>());
- return restTemplate.postForEntity(uri, entity, String.class).getBody();
- } else if (requestType.equalsIgnoreCase("patch")) {
- final HttpComponentsClientHttpRequestFactory requestFactory
- = new HttpComponentsClientHttpRequestFactory();
- requestFactory.setConnectTimeout(10000);
- requestFactory.setReadTimeout(10000);
- restTemplate.setRequestFactory(requestFactory);
- return restTemplate.patchForObject(uri, entity, String.class);
- } else {
- return restTemplate.exchange(uri, HttpMethod.PUT, entity, String.class).getBody();
+ switch (requestType) {
+ case "post":
+ uri = buildCpsUrl(cpsConfiguration.getUrl(), POST_API_PATH, anchor, new LinkedMultiValueMap<>());
+ return restTemplate.postForEntity(uri, entity, String.class).getBody();
+ case "patch":
+ final HttpComponentsClientHttpRequestFactory requestFactory =
+ new HttpComponentsClientHttpRequestFactory();
+ requestFactory.setConnectTimeout(10000);
+ requestFactory.setReadTimeout(10000);
+ restTemplate.setRequestFactory(requestFactory);
+ return restTemplate.patchForObject(uri, entity, String.class);
+ case "post-list-node":
+ uri = buildCpsUrl(cpsConfiguration.getUrl(), LIST_NODE_API_PATH, anchor, queryParams);
+ return restTemplate.postForEntity(uri, entity, String.class).getBody();
+ default:
+ return restTemplate.exchange(uri, HttpMethod.PUT, entity, String.class).getBody();
}
} catch (final Exception e) {
throw new CpsClientException(e.getLocalizedMessage());
diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java
index 6032b05..a8004be 100644
--- a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java
+++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java
@@ -134,8 +134,9 @@ public class ExecutionBusinessLogic {
}
final String xpath = generateXpath(template.getXpathTemplate(), inputParameters);
try {
- if (template.getRequestType().equalsIgnoreCase("put") || template.getRequestType().equalsIgnoreCase("patch")
- || template.getRequestType().equalsIgnoreCase("post")) {
+ if ("put".equalsIgnoreCase(template.getRequestType()) || "patch".equalsIgnoreCase(template.getRequestType())
+ || "post".equalsIgnoreCase(template.getRequestType())
+ || "post-list-node".equalsIgnoreCase(template.getRequestType())) {
return cpsRestClient.addData(anchor, xpath, template.getRequestType(), payload);
} else {
final String result = cpsRestClient.fetchNode(anchor, xpath, template.getRequestType(),