Fix sonar code smells 04/129604/1
authorkissand <andras.zoltan.kiss@est.tech>
Mon, 13 Jun 2022 08:55:49 +0000 (10:55 +0200)
committerkissand <andras.zoltan.kiss@est.tech>
Mon, 13 Jun 2022 08:55:49 +0000 (10:55 +0200)
- https://sonarcloud.io/project/issues?resolved=false&types=CODE_SMELL&id=onap_cps&open=AYFC3OguDZ5Vb3SQMOU1

Issue-ID: CPS-1016
Change-Id: Ic8fdae78337da1ff2c239ae2dfae67e23e88a4bb
Signed-off-by: kissand <andras.zoltan.kiss@est.tech>
cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DeprecationHelper.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandlerQueryService.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryServiceParameters.java [moved from cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryParameters.java with 97% similarity]
cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java
cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy
cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy

index ccb1e9b..fb234ef 100755 (executable)
@@ -211,6 +211,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
      * @return collection of cm handles
      */
     @Override
+    @SuppressWarnings("deprecation") // mapOldConditionProperties method will be removed in Release 12
     public ResponseEntity<List<RestOutputCmHandle>> searchCmHandles(
             final CmHandleQueryParameters cmHandleQueryParameters) {
         final CmHandleQueryApiParameters cmHandleQueryApiParameters =
index fc992da..573491c 100644 (file)
@@ -40,9 +40,11 @@ public class DeprecationHelper {
      * !!! remove it after the old condition removed !!!
      * it only works for module names
      *
+     * @deprecated this method will be removed in Release 12 (No Name know yet)
+     *
      * @param cmHandleQueryParameters the original input parameter
      */
-    @Deprecated //this method wil be removed in Release 12 (No Name know yet)
+    @Deprecated
     public CmHandleQueryApiParameters mapOldConditionProperties(
                                            final CmHandleQueryParameters cmHandleQueryParameters) {
         final CmHandleQueryApiParameters cmHandleQueryApiParameters =
index f8d51fe..92b1e82 100644 (file)
 package org.onap.cps.ncmp.api;
 
 import java.util.Collection;
-import org.onap.cps.spi.model.CmHandleQueryParameters;
+import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
 import org.onap.cps.spi.model.DataNode;
 
 public interface NetworkCmProxyCmHandlerQueryService {
     /**
      * Query and return cm handles that match the given query parameters.
      *
-     * @param cmHandleQueryParameters the cm handle query parameters
+     * @param cmHandleQueryServiceParameters the cm handle query parameters
      * @return collection of cm handles
      */
-    Collection<DataNode> queryCmHandles(CmHandleQueryParameters cmHandleQueryParameters);
+    Collection<DataNode> queryCmHandles(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
 }
index ef6e953..00cbe69 100644 (file)
@@ -37,7 +37,7 @@ import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService;
 import org.onap.cps.spi.CpsAdminPersistenceService;
 import org.onap.cps.spi.CpsDataPersistenceService;
 import org.onap.cps.spi.model.Anchor;
-import org.onap.cps.spi.model.CmHandleQueryParameters;
+import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
 import org.onap.cps.spi.model.ConditionProperties;
 import org.onap.cps.spi.model.DataNode;
 import org.onap.cps.spi.model.DataNodeIdentifier;
@@ -58,23 +58,23 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
     /**
      * Query and return cm handles that match the given query parameters.
      *
-     * @param cmHandleQueryParameters the cm handle query parameters
+     * @param cmHandleQueryServiceParameters the cm handle query parameters
      * @return collection of cm handles
      */
     @Override
-    public Collection<DataNode> queryCmHandles(final CmHandleQueryParameters cmHandleQueryParameters) {
+    public Collection<DataNode> queryCmHandles(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
 
-        if (cmHandleQueryParameters.getCmHandleQueryParameters().isEmpty()) {
+        if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) {
             return getAllCmHandles();
         }
 
         final Collection<DataNodeIdentifier> amalgamatedQueryResultIdentifiers = new ArrayList<>();
         final Map<DataNodeIdentifier, DataNode> amalgamatedQueryResults = new HashMap<>();
 
-        final boolean firstQuery = moduleNameQuery(cmHandleQueryParameters,
+        final boolean firstQuery = moduleNameQuery(cmHandleQueryServiceParameters,
                 amalgamatedQueryResultIdentifiers, amalgamatedQueryResults);
 
-        publicPropertyQuery(cmHandleQueryParameters, amalgamatedQueryResultIdentifiers,
+        publicPropertyQuery(cmHandleQueryServiceParameters, amalgamatedQueryResultIdentifiers,
                 amalgamatedQueryResults, firstQuery);
 
         final Collection<DataNode> filteredDataNodes = new ArrayList<>();
@@ -85,12 +85,12 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
         return filteredDataNodes;
     }
 
-    private void publicPropertyQuery(final CmHandleQueryParameters cmHandleQueryParameters,
+    private void publicPropertyQuery(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
                                      final Collection<DataNodeIdentifier> amalgamatedQueryResultIdentifiers,
                                      final Map<DataNodeIdentifier, DataNode> amalgamatedQueryResults,
                                      boolean firstQuery) {
         for (final Map.Entry<String, String> entry :
-                getPublicPropertyPairs(cmHandleQueryParameters.getCmHandleQueryParameters()).entrySet()) {
+                getPublicPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters()).entrySet()) {
             final String cmHandlePath = "//public-properties[@name='" + entry.getKey() + "' " + "and @value='"
                     + entry.getValue() + "']" + "/ancestor::cm-handles";
 
@@ -121,13 +121,13 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
         }
     }
 
-    private boolean moduleNameQuery(final CmHandleQueryParameters cmHandleQueryParameters,
+    private boolean moduleNameQuery(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
                                     final Collection<DataNodeIdentifier> amalgamatedQueryResultIdentifiers,
                                     final Map<DataNodeIdentifier, DataNode> amalgamatedQueryResults) {
         boolean firstQuery = true;
-        if (!getModuleNames(cmHandleQueryParameters.getCmHandleQueryParameters()).isEmpty()) {
+        if (!getModuleNames(cmHandleQueryServiceParameters.getCmHandleQueryParameters()).isEmpty()) {
             final Collection<Anchor> anchors = cpsAdminPersistenceService.queryAnchors("NFP-Operational",
-                    getModuleNames(cmHandleQueryParameters.getCmHandleQueryParameters()));
+                    getModuleNames(cmHandleQueryServiceParameters.getCmHandleQueryParameters()));
             anchors.forEach(anchor -> {
                 final List<DataNode> dataNodes = getDataNodes("//cm-handles[@id='" + anchor.getName() + "']");
                 dataNodes.parallelStream().forEach(dataNode -> {
index d1f72a5..f8cab4f 100755 (executable)
@@ -63,7 +63,7 @@ import org.onap.cps.spi.exceptions.AlreadyDefinedException;
 import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
 import org.onap.cps.spi.exceptions.DataValidationException;
 import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
-import org.onap.cps.spi.model.CmHandleQueryParameters;
+import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
 import org.onap.cps.spi.model.ModuleReference;
 import org.onap.cps.utils.CpsValidator;
 import org.onap.cps.utils.JsonObjectMapper;
@@ -167,12 +167,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
     @Override
     public Set<NcmpServiceCmHandle> executeCmHandleSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
 
-        final CmHandleQueryParameters cmHandleQueryParameters = jsonObjectMapper.convertToValueType(
-                cmHandleQueryApiParameters, CmHandleQueryParameters.class);
+        final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
+                cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
 
-        validateCmHandleQueryParameters(cmHandleQueryParameters);
+        validateCmHandleQueryParameters(cmHandleQueryServiceParameters);
 
-        return networkCmProxyCmHandlerQueryService.queryCmHandles(cmHandleQueryParameters).stream()
+        return networkCmProxyCmHandlerQueryService.queryCmHandles(cmHandleQueryServiceParameters).stream()
                 .map(dataNode -> YangDataConverter
                         .convertCmHandleToYangModel(dataNode, dataNode.getLeaves().get("id").toString()))
                 .map(YangDataConverter::convertYangModelCmHandleToNcmpServiceCmHandle).collect(Collectors.toSet());
index a1ad9af..b689097 100644 (file)
@@ -25,7 +25,7 @@ import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService
 import org.onap.cps.spi.CpsAdminPersistenceService
 import org.onap.cps.spi.CpsDataPersistenceService
 import org.onap.cps.spi.model.Anchor
-import org.onap.cps.spi.model.CmHandleQueryParameters
+import org.onap.cps.spi.model.CmHandleQueryServiceParameters
 import org.onap.cps.spi.model.ConditionProperties
 import org.onap.cps.spi.model.DataNode
 import org.onap.cps.utils.JsonObjectMapper
@@ -44,7 +44,7 @@ class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
 
     def 'Retrieve cm handles with public properties when #scenario.'() {
         given: 'a condition property'
-            def cmHandleQueryParameters = new CmHandleQueryParameters()
+            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
             def conditionProperties = new ConditionProperties()
             conditionProperties.conditionName = 'hasAllProperties'
             conditionProperties.conditionParameters = publicProperties
@@ -65,7 +65,7 @@ class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
 
     def 'Retrieve cm handles with module names when #scenario.'() {
         given: 'a condition property'
-            def cmHandleQueryParameters = new CmHandleQueryParameters()
+            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
             def conditionProperties = new ConditionProperties()
             conditionProperties.conditionName = 'hasAllModules'
             conditionProperties.conditionParameters = moduleNames
@@ -86,7 +86,7 @@ class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
 
     def 'Retrieve cm handles with combined queries when #scenario.'() {
         given: 'condition properties'
-            def cmHandleQueryParameters = new CmHandleQueryParameters()
+            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
             def conditionProperties1 = new ConditionProperties()
             conditionProperties1.conditionName = 'hasAllProperties'
             conditionProperties1.conditionParameters = publicProperties
@@ -111,7 +111,7 @@ class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
         given: 'mock services'
             mockResponses()
         when: 'the service is invoked'
-            def cmHandleQueryParameters = new CmHandleQueryParameters()
+            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
             def returnedCmHandles = objectUnderTest.queryCmHandles(cmHandleQueryParameters)
         then: 'the correct expected cm handles are returned'
             returnedCmHandles.stream().map(d -> d.leaves.get('id').toString()).collect(Collectors.toList()) == ['PNFDemo', 'PNFDemo2', 'PNFDemo3', 'PNFDemo4']
index 6ba2a2c..d58fe6a 100644 (file)
@@ -33,7 +33,7 @@ import org.onap.cps.ncmp.api.models.DmiPluginRegistration
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
 import org.onap.cps.spi.exceptions.DataValidationException
 import org.onap.cps.ncmp.api.inventory.sync.ModuleSyncService
-import org.onap.cps.spi.model.CmHandleQueryParameters
+import org.onap.cps.spi.model.CmHandleQueryServiceParameters
 import org.onap.cps.spi.model.ConditionProperties
 import spock.lang.Shared
 
@@ -252,7 +252,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             conditionApiProperties.conditionParameters = [[moduleName: 'module-name-1']]
             cmHandleQueryApiParameters.cmHandleQueryParameters = [conditionApiProperties]
         and: 'valid CmHandleQueryParameters input'
-            def cmHandleQueryParameters = new CmHandleQueryParameters()
+            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
             def conditionProperties = new ConditionProperties()
             conditionProperties.conditionName = 'hasAllModules'
             conditionProperties.conditionParameters = [[moduleName: 'module-name-1']]
@@ -34,7 +34,7 @@ import lombok.Setter;
 @Getter
 @EqualsAndHashCode
 @JsonInclude(Include.NON_EMPTY)
-public class CmHandleQueryParameters {
+public class CmHandleQueryServiceParameters {
     @JsonProperty("cmHandleQueryParameters")
     @Valid
     private List<ConditionProperties> cmHandleQueryParameters = Collections.emptyList();
index c510a73..c3811eb 100644 (file)
@@ -27,7 +27,7 @@ import java.util.Map;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.onap.cps.spi.exceptions.DataValidationException;
-import org.onap.cps.spi.model.CmHandleQueryParameters;
+import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
 
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public class CmHandleQueryRestParametersValidator {
@@ -36,10 +36,11 @@ public class CmHandleQueryRestParametersValidator {
 
     /**
      * Validate cm handle query parameters.
-     * @param cmHandleQueryParameters name of data to be validated
+     * @param cmHandleQueryServiceParameters name of data to be validated
      */
-    public static void validateCmHandleQueryParameters(final CmHandleQueryParameters cmHandleQueryParameters) {
-        cmHandleQueryParameters.getCmHandleQueryParameters().forEach(
+    public static void validateCmHandleQueryParameters(
+            final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+        cmHandleQueryServiceParameters.getCmHandleQueryParameters().forEach(
                 conditionApiProperty -> {
                     if (Strings.isNullOrEmpty(conditionApiProperty.getConditionName())) {
                         throwDataValidationException("Missing 'conditionName' - please supply a valid name.");
@@ -54,27 +55,29 @@ public class CmHandleQueryRestParametersValidator {
                                 "Empty 'conditionsParameters' - please supply a valid condition parameter.");
                     }
                     conditionApiProperty.getConditionParameters().forEach(
-                            conditionParameter -> {
-                                if (conditionParameter.isEmpty()) {
-                                    throwDataValidationException(
-                                            "Empty 'conditionsParameter' - please supply a valid condition parameter.");
-                                }
-                                if (conditionParameter.size() > 1) {
-                                    throwDataValidationException("Too many name in one 'conditionsParameter' -"
-                                            + " please supply one name in one condition parameter.");
-                                }
-                                conditionParameter.forEach((key, value) -> {
-                                    if (Strings.isNullOrEmpty(key)) {
-                                        throwDataValidationException(
-                                                "Missing 'conditionsParameterName' - please supply a valid name.");
-                                    }
-                                });
-                            }
+                            CmHandleQueryRestParametersValidator::validateConditionParameter
                     );
                 }
         );
     }
 
+    private static void validateConditionParameter(final Map<String, String> conditionParameter) {
+        if (conditionParameter.isEmpty()) {
+            throwDataValidationException(
+                    "Empty 'conditionsParameter' - please supply a valid condition parameter.");
+        }
+        if (conditionParameter.size() > 1) {
+            throwDataValidationException("Too many name in one 'conditionsParameter' -"
+                    + " please supply one name in one condition parameter.");
+        }
+        conditionParameter.forEach((key, value) -> {
+            if (Strings.isNullOrEmpty(key)) {
+                throwDataValidationException(
+                        "Missing 'conditionsParameterName' - please supply a valid name.");
+            }
+        });
+    }
+
     /**
      * Validate module name condition properties.
      * @param conditionProperty name of data to be validated
index def99e2..41fcb29 100755 (executable)
@@ -26,7 +26,6 @@ import org.onap.cps.api.CpsDataService
 import org.onap.cps.spi.CpsAdminPersistenceService
 import org.onap.cps.spi.exceptions.DataValidationException
 import org.onap.cps.spi.model.Anchor
-import org.onap.cps.spi.model.CmHandleQueryParameters
 import spock.lang.Specification
 import java.time.OffsetDateTime
 
index 645829b..a9b04c1 100644 (file)
 package org.onap.cps.utils
 
 import org.onap.cps.spi.exceptions.DataValidationException
-import org.onap.cps.spi.model.CmHandleQueryParameters
+import org.onap.cps.spi.model.CmHandleQueryServiceParameters
 import org.onap.cps.spi.model.ConditionProperties
 import spock.lang.Specification
 
 class CmHandleQueryRestParametersValidatorSpec extends Specification {
     def 'CM Handle Query validation: empty query.'() {
         given: 'a cm handle query'
-            def cmHandleQueryParameters = new CmHandleQueryParameters()
+            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
         when: 'validator is invoked'
             CmHandleQueryRestParametersValidator.validateCmHandleQueryParameters(cmHandleQueryParameters)
         then: 'data validation exception is not thrown'
@@ -37,7 +37,7 @@ class CmHandleQueryRestParametersValidatorSpec extends Specification {
 
     def 'CM Handle Query validation: normal query.'() {
         given: 'a cm handle query'
-            def cmHandleQueryParameters = new CmHandleQueryParameters()
+            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
             def condition = new ConditionProperties()
             condition.conditionName = 'hasAllProperties'
             condition.conditionParameters = [[key1:'value1'],[key2:'value2']]
@@ -50,7 +50,7 @@ class CmHandleQueryRestParametersValidatorSpec extends Specification {
 
     def 'CM Handle Query validation: #scenario.'() {
         given: 'a cm handle query'
-            def cmHandleQueryParameters = new CmHandleQueryParameters()
+            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
             def condition = new ConditionProperties()
             condition.conditionName = conditionName
             condition.conditionParameters = conditionParameters