summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java11
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/exception/CmHandleRegistrationException.java36
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/exception/DmiExceptionHandler.java2
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/model/CmHandleOperation.java35
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/model/CreatedCmHandle.java36
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java23
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java9
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java59
8 files changed, 207 insertions, 4 deletions
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java b/src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java
index 33d6ae89..614435f2 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java
@@ -20,8 +20,11 @@
package org.onap.cps.ncmp.dmi.config;
+import lombok.Getter;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.stereotype.Component;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
@@ -42,5 +45,13 @@ public class DmiPluginConfig {
.paths(PathSelectors.any())
.build();
}
+
+ @Getter
+ @Component
+ public static class DmiPluginProperties {
+
+ @Value("${dmi.service.name}")
+ private String dmiServiceName;
+ }
}
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/exception/CmHandleRegistrationException.java b/src/main/java/org/onap/cps/ncmp/dmi/exception/CmHandleRegistrationException.java
new file mode 100644
index 00000000..1874389e
--- /dev/null
+++ b/src/main/java/org/onap/cps/ncmp/dmi/exception/CmHandleRegistrationException.java
@@ -0,0 +1,36 @@
+/*
+ * ============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.exception;
+
+public class CmHandleRegistrationException extends DmiException {
+
+ private static final long serialVersionUID = 8973438585188332404L;
+
+ /**
+ * Constructor.
+ *
+ * @param details the error details
+ */
+ public CmHandleRegistrationException(final String details) {
+ super("Not able to register the given cm-handles.", details);
+ }
+
+}
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/exception/DmiExceptionHandler.java b/src/main/java/org/onap/cps/ncmp/dmi/exception/DmiExceptionHandler.java
index 9ad561fc..a6ec6dfa 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/exception/DmiExceptionHandler.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/exception/DmiExceptionHandler.java
@@ -51,7 +51,7 @@ public class DmiExceptionHandler {
return buildErrorResponse(HttpStatus.NOT_FOUND, exception);
}
- @ExceptionHandler({DmiException.class})
+ @ExceptionHandler({CmHandleRegistrationException.class, DmiException.class})
public static ResponseEntity<Object> handleAnyOtherDmiExceptions(final DmiException exception) {
return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception);
}
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/model/CmHandleOperation.java b/src/main/java/org/onap/cps/ncmp/dmi/model/CmHandleOperation.java
new file mode 100644
index 00000000..8ddd42f8
--- /dev/null
+++ b/src/main/java/org/onap/cps/ncmp/dmi/model/CmHandleOperation.java
@@ -0,0 +1,35 @@
+/*
+ * ============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.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@Getter
+@Setter
+public class CmHandleOperation {
+
+ private String dmiPlugin;
+ private List<CreatedCmHandle> createdCmHandles;
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/model/CreatedCmHandle.java b/src/main/java/org/onap/cps/ncmp/dmi/model/CreatedCmHandle.java
new file mode 100644
index 00000000..9198d7da
--- /dev/null
+++ b/src/main/java/org/onap/cps/ncmp/dmi/model/CreatedCmHandle.java
@@ -0,0 +1,36 @@
+/*
+ * ============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.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@Getter
+@Setter
+public class CreatedCmHandle {
+
+ private String cmHandle;
+ private Map<String, String> cmHandleProperties;
+
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
index 8081b73d..0e1d3d67 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
@@ -20,7 +20,12 @@
package org.onap.cps.ncmp.dmi.rest.controller;
+import java.util.List;
+import javax.validation.Valid;
+import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.ncmp.dmi.model.CmHandles;
import org.onap.cps.ncmp.dmi.rest.api.DmiPluginApi;
+import org.onap.cps.ncmp.dmi.rest.api.DmiPluginInternalApi;
import org.onap.cps.ncmp.dmi.service.DmiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@@ -30,7 +35,8 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("${rest.api.dmi-base-path}")
@RestController
-public class DmiRestController implements DmiPluginApi {
+@Slf4j
+public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
private DmiService dmiService;
@@ -45,4 +51,19 @@ public class DmiRestController implements DmiPluginApi {
final String modulesListAsJson = dmiService.getModulesForCmHandle(cmHandle);
return new ResponseEntity<>(modulesListAsJson, HttpStatus.OK);
}
+
+ /**
+ * This method register given list of cm-handles to ncmp.
+ *
+ * @param cmHandles list of cm-handles
+ * @return (@code ResponseEntity) response entity
+ */
+ public ResponseEntity<String> registerCmHandles(final @Valid CmHandles cmHandles) {
+ final List<String> cmHandlesList = cmHandles.getCmHandles();
+ if (cmHandlesList.isEmpty()) {
+ return new ResponseEntity<>("Need at least one cmHandle to process.", HttpStatus.BAD_REQUEST);
+ }
+ dmiService.registerCmHandles(cmHandlesList);
+ return new ResponseEntity<>("cm-handle registered successfully.", HttpStatus.CREATED);
+ }
}
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
index e595bd5f..d9196ecb 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
@@ -20,6 +20,7 @@
package org.onap.cps.ncmp.dmi.service;
+import java.util.List;
import org.onap.cps.ncmp.dmi.exception.DmiException;
/**
@@ -36,4 +37,12 @@ public interface DmiService {
*/
String getModulesForCmHandle(String cmHandle) throws DmiException;
+ /**
+ * This method used to register the given {@code CmHandles}
+ * which contains list of {@code CmHandle} to cps repository.
+ *
+ * @param cmHandles list of cm-handles
+ */
+ void registerCmHandles(List<String> cmHandles);
+
}
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
index 4367bf45..990a421e 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
@@ -20,22 +20,51 @@
package org.onap.cps.ncmp.dmi.service;
-import io.micrometer.core.instrument.util.StringUtils;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.ArrayList;
+import java.util.List;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.groovy.parser.antlr4.util.StringUtils;
+import org.onap.cps.ncmp.dmi.config.DmiPluginConfig.DmiPluginProperties;
+import org.onap.cps.ncmp.dmi.exception.CmHandleRegistrationException;
import org.onap.cps.ncmp.dmi.exception.DmiException;
import org.onap.cps.ncmp.dmi.exception.ModulesNotFoundException;
+import org.onap.cps.ncmp.dmi.model.CmHandleOperation;
+import org.onap.cps.ncmp.dmi.model.CreatedCmHandle;
+import org.onap.cps.ncmp.dmi.service.client.NcmpRestClient;
import org.onap.cps.ncmp.dmi.service.operation.SdncOperations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
+
@Service
+@Slf4j
public class DmiServiceImpl implements DmiService {
private SdncOperations sdncOperations;
+ private NcmpRestClient ncmpRestClient;
+ private ObjectMapper objectMapper;
+ private DmiPluginProperties dmiPluginProperties;
+ /**
+ * Constructor.
+ *
+ * @param dmiPluginProperties dmiPluginProperties
+ * @param ncmpRestClient ncmpRestClient
+ * @param objectMapper objectMapper
+ * @param sdncOperations sdncOperations
+ */
@Autowired
- public DmiServiceImpl(final SdncOperations sdncOperations) {
+ public DmiServiceImpl(final DmiPluginProperties dmiPluginProperties,
+ final NcmpRestClient ncmpRestClient,
+ final ObjectMapper objectMapper,
+ final SdncOperations sdncOperations) {
+ this.dmiPluginProperties = dmiPluginProperties;
+ this.ncmpRestClient = ncmpRestClient;
+ this.objectMapper = objectMapper;
this.sdncOperations = sdncOperations;
}
@@ -53,4 +82,30 @@ public class DmiServiceImpl implements DmiService {
"response code : " + responseEntity.getStatusCode() + " message : " + responseEntity.getBody());
}
}
+
+ @Override
+ public void registerCmHandles(final List<String> cmHandles) {
+ final CmHandleOperation cmHandleOperation = new CmHandleOperation();
+ cmHandleOperation.setDmiPlugin(dmiPluginProperties.getDmiServiceName());
+ final List<CreatedCmHandle> createdCmHandleList = new ArrayList<>();
+ for (final String cmHandle: cmHandles) {
+ final CreatedCmHandle createdCmHandle = new CreatedCmHandle();
+ createdCmHandle.setCmHandle(cmHandle);
+ createdCmHandleList.add(createdCmHandle);
+ }
+ cmHandleOperation.setCreatedCmHandles(createdCmHandleList);
+ final String cmHandlesJson;
+ try {
+ cmHandlesJson = objectMapper.writeValueAsString(cmHandleOperation);
+ } catch (final JsonProcessingException e) {
+ log.error("Parsing error occurred while converting cm-handles to JSON {}", cmHandles);
+ throw new DmiException("Internal Server Error.",
+ "Parsing error occurred while converting given cm-handles object list to JSON ");
+ }
+ final ResponseEntity<String> responseEntity = ncmpRestClient.registerCmHandlesWithNcmp(cmHandlesJson);
+ if (!(responseEntity.getStatusCode() == HttpStatus.CREATED)) {
+ throw new CmHandleRegistrationException(responseEntity.getBody());
+ }
+ }
+
}