summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorniamhcore <niamh.core@est.tech>2021-09-21 16:08:29 +0100
committerNiamh Core <niamh.core@est.tech>2021-09-22 15:47:16 +0000
commit4f431887d66854589354c7361f2614f76420d738 (patch)
tree73d3e3ac956c84cc024ecc5f8b76c6c60aca5c50 /src/main
parentfa11e9cb799b9738d2295abd4690c142639b9250 (diff)
Add get modules response type to openapi
Issue-ID: CPS-657 Signed-off-by: niamhcore <niamh.core@est.tech> Change-Id: Ifcd22b6e82aaf4993f9071ad56b524fe620afaf7
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java8
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java5
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java24
-rw-r--r--src/main/resources/spotbugs-exclude.xml54
4 files changed, 72 insertions, 19 deletions
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 37381fb1..9f192841 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
@@ -32,6 +32,7 @@ import org.onap.cps.ncmp.dmi.model.DataAccessWriteRequest;
import org.onap.cps.ncmp.dmi.model.DmiReadRequestBody;
import org.onap.cps.ncmp.dmi.model.ModuleReference;
import org.onap.cps.ncmp.dmi.model.ModuleSet;
+import org.onap.cps.ncmp.dmi.model.YangResources;
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;
@@ -62,17 +63,14 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
}
@Override
- public ResponseEntity<Object> retrieveModuleResources(@Valid final DmiReadRequestBody dmiReadRequestBody,
+ public ResponseEntity<YangResources> retrieveModuleResources(@Valid final DmiReadRequestBody dmiReadRequestBody,
final String cmHandle) {
if (dmiReadRequestBody.getOperation().toString().equals("read")) {
final var moduleReferenceList = convertRestObjectToJavaApiObject(dmiReadRequestBody);
final var response = dmiService.getModuleResources(cmHandle, moduleReferenceList);
- if (response.isEmpty()) {
- return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
- }
return new ResponseEntity<>(response, HttpStatus.OK);
}
- return new ResponseEntity<>("Unsupported operation", HttpStatus.CONFLICT);
+ return new ResponseEntity<>(HttpStatus.CONFLICT);
}
/**
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 7f79a04c..bd0dc600 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
@@ -26,6 +26,7 @@ import javax.validation.constraints.NotNull;
import org.onap.cps.ncmp.dmi.exception.DmiException;
import org.onap.cps.ncmp.dmi.model.ModuleReference;
import org.onap.cps.ncmp.dmi.model.ModuleSet;
+import org.onap.cps.ncmp.dmi.model.YangResources;
/**
* Interface for handling Dmi plugin Data.
@@ -54,9 +55,9 @@ public interface DmiService {
*
* @param cmHandle cmHandle
* @param modules a list of module data
- * @return returns all module resources
+ * @return returns all yang resources
*/
- String getModuleResources(String cmHandle, List<ModuleReference> modules);
+ YangResources getModuleResources(String cmHandle, List<ModuleReference> modules);
/**
* This method use to fetch the resource data from cm handle for datastore pass-through operational and resource
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 11668904..182bdd84 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
@@ -30,8 +30,6 @@ import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
-import net.minidev.json.JSONArray;
-import net.minidev.json.JSONObject;
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;
@@ -46,6 +44,8 @@ import org.onap.cps.ncmp.dmi.model.ModuleSchemaProperties;
import org.onap.cps.ncmp.dmi.model.ModuleSchemas;
import org.onap.cps.ncmp.dmi.model.ModuleSet;
import org.onap.cps.ncmp.dmi.model.ModuleSetSchemas;
+import org.onap.cps.ncmp.dmi.model.YangResource;
+import org.onap.cps.ncmp.dmi.model.YangResources;
import org.onap.cps.ncmp.dmi.service.client.NcmpRestClient;
import org.onap.cps.ncmp.dmi.service.operation.SdncOperations;
import org.springframework.http.HttpStatus;
@@ -100,13 +100,13 @@ public class DmiServiceImpl implements DmiService {
}
@Override
- public String getModuleResources(final String cmHandle, final List<ModuleReference> moduleReferences) {
- final var getModuleResponses = new JSONArray();
+ public YangResources getModuleResources(final String cmHandle, final List<ModuleReference> moduleReferences) {
+ final YangResources yangResources = new YangResources();
for (final var moduleReference : moduleReferences) {
final var moduleRequest = createModuleRequest(moduleReference);
final ResponseEntity<String> responseEntity = sdncOperations.getModuleResource(cmHandle, moduleRequest);
if (responseEntity.getStatusCode() == HttpStatus.OK) {
- getModuleResponses.add(toJsonObject(moduleReference, responseEntity));
+ yangResources.add(toYangResource(moduleReference, responseEntity));
} else if (responseEntity.getStatusCode() == HttpStatus.NOT_FOUND) {
log.error("SDNC did not return a module resource for the given cmHandle {}", cmHandle);
throw new ModuleResourceNotFoundException(cmHandle,
@@ -117,7 +117,7 @@ public class DmiServiceImpl implements DmiService {
RESPONSE_CODE + responseEntity.getStatusCode() + MESSAGE + responseEntity.getBody());
}
}
- return getModuleResponses.toJSONString();
+ return yangResources;
}
@Override
@@ -248,13 +248,13 @@ public class DmiServiceImpl implements DmiService {
return moduleRequest;
}
- private JSONObject toJsonObject(final ModuleReference moduleReference,
+ private YangResource toYangResource(final ModuleReference moduleReference,
final ResponseEntity<String> response) {
- final var jsonObject = new JSONObject();
- jsonObject.put("moduleName", moduleReference.getName());
- jsonObject.put("revision", moduleReference.getRevision());
- jsonObject.put("yangSource", extractYangSourceFromBody(response));
- return jsonObject;
+ final YangResource yangResource = new YangResource();
+ yangResource.setModuleName(moduleReference.getName());
+ yangResource.setRevision(moduleReference.getRevision());
+ yangResource.setYangSource(extractYangSourceFromBody(response));
+ return yangResource;
}
private String extractYangSourceFromBody(final ResponseEntity<String> responseEntity) {
diff --git a/src/main/resources/spotbugs-exclude.xml b/src/main/resources/spotbugs-exclude.xml
new file mode 100644
index 00000000..e8a1f6e2
--- /dev/null
+++ b/src/main/resources/spotbugs-exclude.xml
@@ -0,0 +1,54 @@
+<!--
+ ============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.
+ ============LICENSE_END=========================================================
+-->
+
+<FindBugsFilter>
+ <Match>
+ <!-- Ignore generated code -->
+ <Source name="~.*generated-sources.*.java"/>
+ </Match>
+ <Match>
+ <Or>
+ <!-- Anonymous inner classes are very common. -->
+ <Bug pattern="SIC_INNER_SHOULD_BE_STATIC_ANON" />
+
+ <!-- We use static slf4j Logger (this rule is from KengoTODA/findbugs-slf4j jp.skypencil.findbugs.slf4:bug-pattern) -->
+ <Bug pattern="SLF4J_LOGGER_SHOULD_BE_NON_STATIC" />
+
+ <!-- Guava 25.1+ uses the Checker Framework's @Nullable which SpotBugs doesn't handle correctly, even though it's
+ supposed to; see https://github.com/spotbugs/spotbugs/issues/743 -->
+ <Bug pattern="NP_NONNULL_PARAM_VIOLATION" />
+ <Bug pattern="NP_NULL_PARAM_DEREF" />
+ <Bug pattern="NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE" />
+ <Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" />
+
+ <!-- https://stackoverflow.com/a/34674776. Doesn't detect Lombok All Args Constructor variables being used with map get key and value, which can lead to spotbugs being detected
+ on used fields -->
+ <Bug pattern="URF_UNREAD_FIELD"/>
+
+ <!-- https://github.com/spotbugs/spotbugs/issues/511. Strict reading of Object.equals() contract means that
+ evenever equals() behaviour is defined, all implementations need to adhere to it. The only reason
+ to override the method (assuming correct API design, of course) is to provide a more efficient
+ implementation. This rule would be forcing a @SuppressFBWarnings on perfectly compliant classes. -->
+ <Bug pattern="EQ_DOESNT_OVERRIDE_EQUALS"/>
+
+ <!-- https://github.com/spotbugs/spotbugs/issues/756. spotbugs does not grok Java 11's try-with-resources -->
+ <Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/>
+ </Or>
+ </Match>
+
+</FindBugsFilter>