Merge "Fixing SonarQube violations"
authorToine Siebelink <toine.siebelink@est.tech>
Tue, 13 Dec 2022 11:08:25 +0000 (11:08 +0000)
committerGerrit Code Review <gerrit@onap.org>
Tue, 13 Dec 2022 11:08:25 +0000 (11:08 +0000)
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java
cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java
cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
cps-service/src/test/groovy/org/onap/cps/spi/model/DataNodeBuilderSpec.groovy

index 1a54a82..bda0a72 100644 (file)
@@ -47,6 +47,7 @@ public class CmHandleQueriesImpl implements CmHandleQueries {
 
     private static final String NCMP_DATASPACE_NAME = "NCMP-Admin";
     private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry";
+    private static final String DESCENDANT_PATH = "//";
 
     private final CpsDataPersistenceService cpsDataPersistenceService;
     private static final Map<String, NcmpServiceCmHandle> NO_QUERY_TO_EXECUTE = null;
@@ -72,7 +73,7 @@ public class CmHandleQueriesImpl implements CmHandleQueries {
         }
         Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandles = null;
         for (final Map.Entry<String, String> publicPropertyQueryPair : propertyQueryPairs.entrySet()) {
-            final String cpsPath = "//" + propertyType.getYangContainerName() + "[@name=\""
+            final String cpsPath = DESCENDANT_PATH + propertyType.getYangContainerName() + "[@name=\""
                     + publicPropertyQueryPair.getKey()
                     + "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]";
 
index b22f171..c725b42 100644 (file)
@@ -24,6 +24,7 @@ package org.onap.cps.spi.impl;
 
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSet.Builder;
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -346,7 +347,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
     private DataNode toDataNode(final FragmentEntity fragmentEntity,
                                 final FetchDescendantsOption fetchDescendantsOption) {
         final List<DataNode> childDataNodes = getChildDataNodes(fragmentEntity, fetchDescendantsOption);
-        Map<String, Object> leaves = new HashMap<>();
+        Map<String, Serializable> leaves = new HashMap<>();
         if (fragmentEntity.getAttributes() != null) {
             leaves = jsonObjectMapper.convertJsonString(fragmentEntity.getAttributes(), Map.class);
         }
@@ -368,7 +369,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
 
     @Override
     public void updateDataLeaves(final String dataspaceName, final String anchorName, final String xpath,
-                                 final Map<String, Object> leaves) {
+                                 final Map<String, Serializable> leaves) {
         final FragmentEntity fragmentEntity = getFragmentWithoutDescendantsByXpath(dataspaceName, anchorName, xpath);
         fragmentEntity.setAttributes(jsonObjectMapper.asJsonString(leaves));
         fragmentRepository.save(fragmentEntity);
index 03f021e..c9f9a78 100755 (executable)
@@ -337,12 +337,14 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
      */
     private String getNameForChecksum(
             final String checksum, final Collection<YangResourceEntity> yangResourceEntities) {
-        return
-                yangResourceEntities.stream()
+        final Optional<String> optionalFileName = yangResourceEntities.stream()
                         .filter(entity -> StringUtils.equals(checksum, (entity.getChecksum())))
                         .findFirst()
-                        .map(YangResourceEntity::getFileName)
-                        .orElse(null);
+                        .map(YangResourceEntity::getFileName);
+        if (optionalFileName.isPresent()) {
+            return optionalFileName.get();
+        }
+        return null;
     }
 
     /**
index 8d4df20..28b18b3 100644 (file)
@@ -22,6 +22,7 @@
 
 package org.onap.cps.spi;
 
+import java.io.Serializable;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -97,7 +98,7 @@ public interface CpsDataPersistenceService {
      * @param xpath         xpath
      * @param leaves        the leaves as a map where key is a leaf name and a value is a leaf value
      */
-    void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Object> leaves);
+    void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Serializable> leaves);
 
     /**
      * Replaces an existing data node's content including descendants.
index 8170db3..76f33bb 100644 (file)
@@ -46,7 +46,7 @@ public class DataNode implements Serializable {
     private ModuleReference moduleReference;
     private String xpath;
     private String moduleNamePrefix;
-    private Map<String, Object> leaves = Collections.emptyMap();
+    private Map<String, Serializable> leaves = Collections.emptyMap();
     private Collection<String> xpathsChildren;
     private Collection<DataNode> childDataNodes = Collections.emptySet();
 }
index af820de..1d8bac0 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.cps.spi.model;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
+import java.io.Serializable;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -49,7 +50,7 @@ public class DataNodeBuilder {
     private String xpath;
     private String moduleNamePrefix;
     private String parentNodeXpath = "";
-    private Map<String, Object> leaves = Collections.emptyMap();
+    private Map<String, Serializable> leaves = Collections.emptyMap();
     private Collection<DataNode> childDataNodes = Collections.emptySet();
 
     /**
@@ -103,7 +104,7 @@ public class DataNodeBuilder {
      * @param leaves for the data node
      * @return DataNodeBuilder
      */
-    public DataNodeBuilder withLeaves(final Map<String, Object> leaves) {
+    public DataNodeBuilder withLeaves(final Map<String, Serializable> leaves) {
         this.leaves = leaves;
         return this;
     }
@@ -183,7 +184,7 @@ public class DataNodeBuilder {
         } else if (normalizedNode instanceof ValueNode) {
             final ValueNode<NormalizedNode> valuesNode = (ValueNode) normalizedNode;
             addYangLeaf(currentDataNode, valuesNode.getIdentifier().getNodeType().getLocalName(),
-                    valuesNode.body());
+                    (Serializable) valuesNode.body());
         } else if (normalizedNode instanceof LeafSetNode) {
             addYangLeafList(currentDataNode, (LeafSetNode<?>) normalizedNode);
         } else {
@@ -202,8 +203,9 @@ public class DataNodeBuilder {
         }
     }
 
-    private static void addYangLeaf(final DataNode currentDataNode, final String leafName, final Object leafValue) {
-        final Map<String, Object> leaves = new ImmutableMap.Builder<String, Object>()
+    private static void addYangLeaf(final DataNode currentDataNode, final String leafName,
+                                    final Serializable leafValue) {
+        final Map<String, Serializable> leaves = new ImmutableMap.Builder<String, Serializable>()
             .putAll(currentDataNode.getLeaves())
             .put(leafName, leafValue)
             .build();
@@ -216,7 +218,7 @@ public class DataNodeBuilder {
                 .stream()
                 .map(normalizedNode -> (normalizedNode).body())
                 .collect(Collectors.toUnmodifiableList());
-        addYangLeaf(currentDataNode, leafListName, leafListValues);
+        addYangLeaf(currentDataNode, leafListName, (Serializable) leafListValues);
     }
 
     private static void addDataNodeForEachListElement(final DataNode currentDataNode, final MapNode mapNode) {
index a58504f..e46147c 100644 (file)
@@ -32,7 +32,7 @@ import spock.lang.Specification
 
 class DataNodeBuilderSpec extends Specification {
 
-    Map<String, Map<String, Object>> expectedLeavesByXpathMap = [
+    Map<String, Map<String, Serializable>> expectedLeavesByXpathMap = [
             '/test-tree'                                            : [],
             '/test-tree/branch[@name=\'Left\']'                     : [name: 'Left'],
             '/test-tree/branch[@name=\'Left\']/nest'                : [name: 'Small', birds: ['Sparrow', 'Robin', 'Finch']],