summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/Application.java (renamed from src/main/java/org/onap/cps/ncmp/Application.java)2
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/config/CpsConfiguration.java55
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java (renamed from src/main/java/org/onap/cps/ncmp/config/DmiPluginConfig.java)2
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/config/WebSecurityConfig.java (renamed from src/main/java/org/onap/cps/ncmp/config/WebSecurityConfig.java)2
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java (renamed from src/main/java/org/onap/cps/ncmp/rest/controller/DmiRestController.java)4
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java (renamed from src/main/java/org/onap/cps/ncmp/service/DmiService.java)2
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java (renamed from src/main/java/org/onap/cps/ncmp/service/DmiServiceImpl.java)2
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java63
8 files changed, 125 insertions, 7 deletions
diff --git a/src/main/java/org/onap/cps/ncmp/Application.java b/src/main/java/org/onap/cps/ncmp/dmi/Application.java
index 44acde4c..69d21ba1 100644
--- a/src/main/java/org/onap/cps/ncmp/Application.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/Application.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp;
+package org.onap.cps.ncmp.dmi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/config/CpsConfiguration.java b/src/main/java/org/onap/cps/ncmp/dmi/config/CpsConfiguration.java
new file mode 100644
index 00000000..a9970da8
--- /dev/null
+++ b/src/main/java/org/onap/cps/ncmp/dmi/config/CpsConfiguration.java
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.dmi.config;
+
+import lombok.Getter;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.web.client.RestTemplateBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * Provides access to cps base url and cps authentication.
+ */
+@Configuration
+public class CpsConfiguration {
+
+ @Getter
+ @Component
+ public static class CpsProperties {
+
+ @Value("${cps-core.baseUrl}")
+ private String baseUrl;
+ @Value("${cps-core.dmiRegistrationUrl}")
+ private String dmiRegistrationUrl;
+ @Value("${cps-core.auth.username}")
+ private String authUsername;
+ @Value("${cps-core.auth.password}")
+ private String authPassword;
+ }
+
+ @Bean
+ public RestTemplate restTemplate(final RestTemplateBuilder restTemplateBuilder) {
+ return restTemplateBuilder.build();
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/cps/ncmp/config/DmiPluginConfig.java b/src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java
index 06b28691..33d6ae89 100644
--- a/src/main/java/org/onap/cps/ncmp/config/DmiPluginConfig.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.config;
+package org.onap.cps.ncmp.dmi.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
diff --git a/src/main/java/org/onap/cps/ncmp/config/WebSecurityConfig.java b/src/main/java/org/onap/cps/ncmp/dmi/config/WebSecurityConfig.java
index a911ef82..a51d4862 100644
--- a/src/main/java/org/onap/cps/ncmp/config/WebSecurityConfig.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/config/WebSecurityConfig.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.config;
+package org.onap.cps.ncmp.dmi.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
diff --git a/src/main/java/org/onap/cps/ncmp/rest/controller/DmiRestController.java b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
index 16fb73a8..c4cbaece 100644
--- a/src/main/java/org/onap/cps/ncmp/rest/controller/DmiRestController.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
@@ -18,10 +18,10 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.rest.controller;
+package org.onap.cps.ncmp.dmi.rest.controller;
+import org.onap.cps.ncmp.dmi.service.DmiService;
import org.onap.cps.ncmp.rest.api.DmiPluginApi;
-import org.onap.cps.ncmp.service.DmiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
diff --git a/src/main/java/org/onap/cps/ncmp/service/DmiService.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
index 48509d98..84c60d55 100644
--- a/src/main/java/org/onap/cps/ncmp/service/DmiService.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.service;
+package org.onap.cps.ncmp.dmi.service;
/**
* Interface for handling Dmi plugin Data.
diff --git a/src/main/java/org/onap/cps/ncmp/service/DmiServiceImpl.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
index f84039bb..5051b1ad 100644
--- a/src/main/java/org/onap/cps/ncmp/service/DmiServiceImpl.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.service;
+package org.onap.cps.ncmp.dmi.service;
import org.springframework.stereotype.Service;
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java b/src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java
new file mode 100644
index 00000000..2158e836
--- /dev/null
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java
@@ -0,0 +1,63 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.dmi.service.client;
+
+import org.onap.cps.ncmp.dmi.config.CpsConfiguration.CpsProperties;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.util.UriComponentsBuilder;
+
+@Component
+public class NcmpRestClient {
+
+ private CpsProperties cpsProperties;
+ private RestTemplate restTemplate;
+
+ public NcmpRestClient(final CpsProperties cpsProperties, final RestTemplate restTemplate) {
+ this.cpsProperties = cpsProperties;
+ this.restTemplate = restTemplate;
+ }
+
+ /**
+ * Register a cmHandle with NCMP using a HTTP call.
+ * @param jsonData json data
+ * @return the response entity
+ */
+ public ResponseEntity<String> registerCmHandlesWithNcmp(final String jsonData) {
+ final var ncmpRegistrationUrl = buildNcmpRegistrationUrl();
+ final var httpHeaders = new HttpHeaders();
+ httpHeaders.setBasicAuth(cpsProperties.getAuthUsername(), cpsProperties.getAuthPassword());
+ httpHeaders.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
+ final var httpEntity = new HttpEntity<>(jsonData, httpHeaders);
+ return restTemplate.postForEntity(ncmpRegistrationUrl, httpEntity, String.class);
+ }
+
+ private String buildNcmpRegistrationUrl() {
+ return UriComponentsBuilder
+ .fromHttpUrl(cpsProperties.getBaseUrl())
+ .path(cpsProperties.getDmiRegistrationUrl())
+ .toUriString();
+ }
+} \ No newline at end of file