summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest/src
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-rest/src')
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java52
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy29
-rw-r--r--cps-ncmp-rest/src/test/resources/cmhandle-search.json15
-rw-r--r--cps-ncmp-rest/src/test/resources/invalid-cmhandle-search.json7
4 files changed, 102 insertions, 1 deletions
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
index 14f33d1e24..ca661b817e 100755
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
@@ -24,13 +24,23 @@ package org.onap.cps.ncmp.rest.controller;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
+import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
+import org.onap.cps.ncmp.rest.model.CmHandleProperties;
+import org.onap.cps.ncmp.rest.model.CmHandleProperty;
import org.onap.cps.ncmp.rest.model.CmHandles;
+import org.onap.cps.ncmp.rest.model.ConditionProperties;
import org.onap.cps.ncmp.rest.model.Conditions;
+import org.onap.cps.ncmp.rest.model.ModuleNameAsJsonObject;
+import org.onap.cps.ncmp.rest.model.ModuleNamesAsJsonArray;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
import org.onap.cps.spi.model.ModuleReference;
@@ -40,6 +50,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
+@Slf4j
@RestController
@RequestMapping("${rest.api.ncmp-base-path}")
public class NetworkCmProxyController implements NetworkCmProxyApi {
@@ -197,7 +208,12 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
@Override
public ResponseEntity<CmHandles> executeCmHandleSearch(final Conditions conditions) {
- return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ final List<ConditionProperties> conditionProperties =
+ conditions.getConditions().stream().collect(Collectors.toList());
+ final CmHandles cmHandles = new CmHandles();
+ final Collection<String> cmHandleIdentifiers = processConditions(conditionProperties);
+ cmHandleIdentifiers.forEach(cmHandle -> cmHandles.setCmHandles(toCmHandleProperties(cmHandle)));
+ return ResponseEntity.ok(cmHandles);
}
@Override
@@ -207,4 +223,38 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
return new ResponseEntity<>(new Gson().toJson(moduleReferences), HttpStatus.OK);
}
+ private Collection<String> processConditions(final List<ConditionProperties> conditionProperties) {
+ for (final ConditionProperties conditionProperty : conditionProperties) {
+ if (conditionProperty.getName().equals("hasAllModules")) {
+ return executeCmHandleSearchesForModuleNames(conditionProperty);
+ } else {
+ log.warn("Unrecognized condition name {}.", conditionProperty.getName());
+ }
+ }
+ log.warn("No valid conditions found {}.", conditionProperties);
+ return Collections.emptyList();
+ }
+
+ private Collection<String> executeCmHandleSearchesForModuleNames(final ConditionProperties conditionProperties) {
+ return networkCmProxyDataService
+ .executeCmHandleHasAllModulesSearch(getModuleNames(conditionProperties.getConditionParameters()));
+ }
+
+ private Collection<String> getModuleNames(final ModuleNamesAsJsonArray moduleNamesAsJsonArray) {
+ final Collection<String> moduleNames = new ArrayList<>(moduleNamesAsJsonArray.size());
+ for (final ModuleNameAsJsonObject moduleNameAsJsonObject : moduleNamesAsJsonArray) {
+ moduleNames.add(moduleNameAsJsonObject.getModuleName());
+ }
+ return moduleNames;
+ }
+
+ private CmHandleProperties toCmHandleProperties(final String cmHandleId) {
+ final CmHandleProperties cmHandleProperties = new CmHandleProperties();
+ final CmHandleProperty cmHandleProperty = new CmHandleProperty();
+ cmHandleProperty.setCmHandleId(cmHandleId);
+ cmHandleProperties.add(cmHandleProperty);
+ return cmHandleProperties;
+ }
+
+
}
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
index 342f41b26f..a609cfacb8 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
@@ -22,6 +22,7 @@
package org.onap.cps.ncmp.rest.controller
+import org.onap.cps.TestUtils
import org.onap.cps.spi.model.ModuleReference
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
@@ -252,5 +253,33 @@ class NetworkCmProxyControllerSpec extends Specification {
and: 'response returns an OK http code'
response.status == HttpStatus.OK.value()
}
+
+ def 'Retrieve cm handles.'() {
+ given: 'an endpoint and json data'
+ def searchesEndpoint = "$ncmpBasePathV1/ch/searches"
+ String jsonData = TestUtils.getResourceFileContent('cmhandle-search.json')
+ and: 'the service method is invoked with module names and returns a cm handle id'
+ mockNetworkCmProxyDataService.executeCmHandleHasAllModulesSearch(['module1', 'module2']) >> ['some-cmhandle-id']
+ when: 'the searches api is invoked'
+ def response = mvc.perform(post(searchesEndpoint)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(jsonData)).andReturn().response
+ then: 'response status returns OK'
+ response.status == HttpStatus.OK.value()
+ and: 'the expected response content is returned'
+ response.contentAsString == '{"cmHandles":[{"cmHandleId":"some-cmhandle-id"}]}'
+ }
+
+ def 'Call execute cm handle searches with unrecognized condition name.'() {
+ given: 'an endpoint and json data'
+ def searchesEndpoint = "$ncmpBasePathV1/ch/searches"
+ String jsonData = TestUtils.getResourceFileContent('invalid-cmhandle-search.json')
+ when: 'the searches api is invoked'
+ def response = mvc.perform(post(searchesEndpoint)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(jsonData)).andReturn().response
+ then: 'an empty cm handle identifier is returned'
+ response.contentAsString == '{"cmHandles":null}'
+ }
}
diff --git a/cps-ncmp-rest/src/test/resources/cmhandle-search.json b/cps-ncmp-rest/src/test/resources/cmhandle-search.json
new file mode 100644
index 0000000000..e3c721bfdf
--- /dev/null
+++ b/cps-ncmp-rest/src/test/resources/cmhandle-search.json
@@ -0,0 +1,15 @@
+{
+ "conditions": [
+ {
+ "name": "hasAllModules",
+ "conditionParameters": [
+ {
+ "moduleName": "module1"
+ },
+ {
+ "moduleName": "module2"
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/cps-ncmp-rest/src/test/resources/invalid-cmhandle-search.json b/cps-ncmp-rest/src/test/resources/invalid-cmhandle-search.json
new file mode 100644
index 0000000000..838c9481b9
--- /dev/null
+++ b/cps-ncmp-rest/src/test/resources/invalid-cmhandle-search.json
@@ -0,0 +1,7 @@
+{
+ "conditions": [
+ {
+ "name": "does-not-exist"
+ }
+ ]
+} \ No newline at end of file