aboutsummaryrefslogtreecommitdiffstats
path: root/cps-tbdmt-service/src/main
diff options
context:
space:
mode:
authorkrishnaa96 <krishna.moorthy6@wipro.com>2021-07-20 17:44:16 +0530
committerkrishnaa96 <krishna.moorthy6@wipro.com>2021-07-22 18:06:56 +0530
commite1216505db39f033c8460ca835eb352e27737b9f (patch)
tree9f0e46a17e0eee1c8d2c75d154536a1802f6e39e /cps-tbdmt-service/src/main
parent9c4054fc42ded465b52f6a3577df983aa407b118 (diff)
Fix issues in CPS integration
- Add include descendants to the template - Add authentication for CPS rest client - Update the CPS url - Add configuration for CPS core and NCMP Issue-ID: CPS-512 Signed-off-by: krishnaa96 <krishna.moorthy6@wipro.com> Change-Id: I071e96d9d3c09b2a90f455f8056dea8ced0060d8
Diffstat (limited to 'cps-tbdmt-service/src/main')
-rw-r--r--cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/client/CpsRestClient.java23
-rw-r--r--cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/AppConfiguration.java7
-rw-r--r--cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/CpsConfiguration.java36
-rw-r--r--cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/Template.java2
-rw-r--r--cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateRequest.java1
-rw-r--r--cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java2
-rw-r--r--cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/TemplateBusinessLogic.java4
7 files changed, 62 insertions, 13 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 879efb5..0d356d8 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
@@ -23,6 +23,7 @@ package org.onap.cps.tbdmt.client;
import java.util.Arrays;
import org.onap.cps.tbdmt.exception.CpsClientException;
import org.onap.cps.tbdmt.model.AppConfiguration;
+import org.onap.cps.tbdmt.model.CpsConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
@@ -38,7 +39,7 @@ import org.springframework.web.util.UriComponentsBuilder;
@Component
public class CpsRestClient {
- private static final String NODES_API_PATH = "/anchors/{anchor}/nodes";
+ private static final String NODES_API_PATH = "/anchors/{anchor}/node";
private static final String QUERY_API_PATH = "/anchors/{anchor}/nodes/query";
@@ -56,16 +57,21 @@ public class CpsRestClient {
* @return result Response string from CPS
*/
public String fetchNode(final String anchor, final String xpath,
- final String requestType) throws CpsClientException {
+ final String requestType, final Boolean includeDescendants) throws CpsClientException {
final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
- queryParams.add("cpsPath", xpath);
- String uri = buildCpsUrl(NODES_API_PATH, anchor, queryParams);
- if ("query".equals(requestType)) {
- uri = buildCpsUrl(QUERY_API_PATH, anchor, queryParams);
- }
+ 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;
+ final String uri = buildCpsUrl(cpsConfiguration.getUrl(), path, anchor, queryParams);
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
+
+ headers.setBasicAuth(cpsConfiguration.getUsername(), cpsConfiguration.getPassword());
final HttpEntity<String> entity = new HttpEntity<>(headers);
ResponseEntity<String> responseEntity = null;
@@ -85,9 +91,8 @@ public class CpsRestClient {
}
}
- private String buildCpsUrl(final String path, final String anchor,
+ private String buildCpsUrl(final String baseUrl, final String path, final String anchor,
final MultiValueMap<String, String> queryParams) {
- final String baseUrl = appConfiguration.getXnfProxyUrl();
return UriComponentsBuilder
.fromHttpUrl(baseUrl)
diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/AppConfiguration.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/AppConfiguration.java
index 90666cd..e9fd290 100644
--- a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/AppConfiguration.java
+++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/AppConfiguration.java
@@ -36,7 +36,12 @@ import org.springframework.web.client.RestTemplate;
@ConfigurationProperties(prefix = "app")
public class AppConfiguration {
- private String xnfProxyUrl;
+ private CpsConfiguration cpsCoreConfiguration;
+
+ private CpsConfiguration ncmpConfiguration;
+
+ private String cpsClient;
+
private Map<String, String> schemaToAnchor;
@Bean
diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/CpsConfiguration.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/CpsConfiguration.java
new file mode 100644
index 0000000..bcaf161
--- /dev/null
+++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/CpsConfiguration.java
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.tbdmt.model;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class CpsConfiguration {
+
+ private String url;
+
+ private String username;
+
+ private String password;
+
+}
diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/Template.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/Template.java
index 97353f2..00ad134 100644
--- a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/Template.java
+++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/Template.java
@@ -51,4 +51,6 @@ public class Template implements Serializable {
private String requestType;
+ private Boolean includeDescendants;
+
}
diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateRequest.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateRequest.java
index c8daf0f..6b08ad8 100644
--- a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateRequest.java
+++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateRequest.java
@@ -47,4 +47,5 @@ public class TemplateRequest implements Serializable {
@NotEmpty(message = "request type missing")
private String requestType;
+ private Boolean includeDescendants;
}
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 b83a1f8..b7dd42a 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
@@ -72,7 +72,7 @@ public class ExecutionBusinessLogic {
final String xpath = generateXpath(template.getXpathTemplate(), inputParameters);
try {
- return cpsRestClient.fetchNode(anchor, xpath, template.getRequestType());
+ return cpsRestClient.fetchNode(anchor, xpath, template.getRequestType(), template.getIncludeDescendants());
} catch (final CpsClientException e) {
throw new ExecuteException(e.getLocalizedMessage());
}
diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/TemplateBusinessLogic.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/TemplateBusinessLogic.java
index 06c48fa..ae179d3 100644
--- a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/TemplateBusinessLogic.java
+++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/TemplateBusinessLogic.java
@@ -47,8 +47,8 @@ public class TemplateBusinessLogic {
*/
public Template createTemplate(final TemplateRequest templateRequest) {
final Template template = new Template(templateRequest.getTemplateId(),
- templateRequest.getModel(),
- templateRequest.getXpathTemplate(), templateRequest.getRequestType());
+ templateRequest.getModel(), templateRequest.getXpathTemplate(),
+ templateRequest.getRequestType(), templateRequest.getIncludeDescendants());
return templateRepository.save(template);
}