Some minor improvements

Minor improvements of condition, sonar reporting

Issue-ID: CLAMP-252
Change-Id: I216a0896f15e92a0b72e85d0c1ebc114a7302036
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
diff --git a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java
index 8729993..5a983b7 100644
--- a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java
@@ -60,15 +60,19 @@
         Policy policy = prop.getType(Policy.class);
         prop.setCurrentModelElementId(policy.getId());
         String eventAction = (String) camelExchange.getProperty("eventAction");
-        String responseMessage = "";
-        if (!eventAction.equalsIgnoreCase(CldsEvent.ACTION_CREATE) && policy.isFound()) {
-            for (PolicyChain policyChain : policy.getPolicyChains()) {
-                prop.setPolicyUniqueId(policyChain.getPolicyId());
-                responseMessage = policyClient.deleteBrms(prop);
-            }
-            if (responseMessage != null) {
-                camelExchange.setProperty("operationalPolicyDeleteResponseMessage", responseMessage.getBytes());
+        if(policy.getPolicyChains() != null && policy.getPolicyChains().size() > 0) {
+        	String responseMessage = "";
+            
+            if (!eventAction.equalsIgnoreCase(CldsEvent.ACTION_CREATE) && policy.isFound()) {
+                for (PolicyChain policyChain : policy.getPolicyChains()) {
+                    prop.setPolicyUniqueId(policyChain.getPolicyId());
+                    responseMessage = policyClient.deleteBrms(prop);
+                }
+                if (responseMessage != null) {
+                    camelExchange.setProperty("operationalPolicyDeleteResponseMessage", responseMessage.getBytes());
+                }
             }
         }
+        
     }
 }
diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java b/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java
index de86faa..0b4cbea 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java
@@ -44,7 +44,8 @@
     private GuardPolicyAttributesConstructor() {
     }
 
-    public static Map<AttributeType, Map<String, String>> formatAttributes(ModelProperties modelProperties, PolicyItem policyItem) {
+    public static Map<AttributeType, Map<String, String>> formatAttributes(ModelProperties modelProperties,
+        PolicyItem policyItem) {
         Map<String, String> matchingAttributes = prepareMatchingAttributes(policyItem, modelProperties);
         return createAttributesMap(matchingAttributes);
     }
@@ -62,20 +63,20 @@
     private static Map<String, String> prepareMatchingAttributes(PolicyItem policyItem, ModelProperties modelProp) {
         logger.info("Preparing matching attributes for guard...");
         Map<String, String> matchingAttributes = new HashMap<>();
-        matchingAttributes.put("actor",policyItem.getActor());
-        matchingAttributes.put("recipe",policyItem.getRecipe());
-        matchingAttributes.put("targets",policyItem.getGuardTargets());
-        matchingAttributes.put("clname",modelProp.getControlNameAndPolicyUniqueId());
+        matchingAttributes.put("actor", policyItem.getActor());
+        matchingAttributes.put("recipe", policyItem.getRecipe());
+        matchingAttributes.put("targets", policyItem.getGuardTargets());
+        matchingAttributes.put("clname", modelProp.getControlNameAndPolicyUniqueId());
         if (RuleProvider.GUARD_MIN_MAX.equals(RuleProvider.valueOf(policyItem.getGuardPolicyType()))) {
-            matchingAttributes.put("min",policyItem.getMinGuard());
-            matchingAttributes.put("max",policyItem.getMaxGuard());
+            matchingAttributes.put("min", policyItem.getMinGuard());
+            matchingAttributes.put("max", policyItem.getMaxGuard());
         } else if (RuleProvider.GUARD_YAML.equals(RuleProvider.valueOf(policyItem.getGuardPolicyType()))) {
-            matchingAttributes.put("limit",policyItem.getLimitGuard());
-            matchingAttributes.put("timeWindow",policyItem.getTimeWindowGuard());
-            matchingAttributes.put("timeUnits",policyItem.getTimeUnitsGuard());
+            matchingAttributes.put("limit", policyItem.getLimitGuard());
+            matchingAttributes.put("timeWindow", policyItem.getTimeWindowGuard());
+            matchingAttributes.put("timeUnits", policyItem.getTimeUnitsGuard());
         }
-        matchingAttributes.put("guardActiveStart",policyItem.getGuardActiveStart());
-        matchingAttributes.put("guardActiveEnd",policyItem.getGuardActiveEnd());
+        matchingAttributes.put("guardActiveStart", policyItem.getGuardActiveStart());
+        matchingAttributes.put("guardActiveEnd", policyItem.getGuardActiveEnd());
 
         logger.info("Prepared: " + matchingAttributes);
         return matchingAttributes;
diff --git a/src/main/java/org/onap/clamp/clds/config/ClampProperties.java b/src/main/java/org/onap/clamp/clds/config/ClampProperties.java
index bdb4dda..7c6c6ff 100644
--- a/src/main/java/org/onap/clamp/clds/config/ClampProperties.java
+++ b/src/main/java/org/onap/clamp/clds/config/ClampProperties.java
@@ -24,10 +24,12 @@
 package org.onap.clamp.clds.config;
 
 import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.base.Splitter;
 
 import java.io.IOException;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
+import java.util.List;
 
 import org.apache.commons.io.IOUtils;
 import org.onap.clamp.clds.util.JacksonUtils;
@@ -47,6 +49,8 @@
     @Autowired
     private Environment env;
     public static final String CONFIG_PREFIX = "clamp.config.";
+    public static final String TOSCA_POLICY_TYPES_CONFIG= "tosca.policyTypes";
+    public static final String IMPORT_TOSCA_POLICY= "import.tosca.model";
 
     /**
      * get property value.
@@ -153,4 +157,19 @@
         URL url = appContext.getResource(filepath).getURL();
         return IOUtils.toString(url, StandardCharsets.UTF_8);
     }
+    
+	/**
+	 * 
+	 * 
+	 * @param key
+	 *       property key
+	 * @param separator
+	 *       property value separator
+	 * @return
+	 *       List of Strings split with a separator
+	 */
+	public List<String> getStringList(String key, String separator) {
+		return Splitter.on(separator).trimResults().omitEmptyStrings()
+				.splitToList(env.getProperty(CONFIG_PREFIX + key));
+	}
 }
diff --git a/src/main/java/org/onap/clamp/clds/model/properties/Global.java b/src/main/java/org/onap/clamp/clds/model/properties/Global.java
index 6fabc7a..e867407 100644
--- a/src/main/java/org/onap/clamp/clds/model/properties/Global.java
+++ b/src/main/java/org/onap/clamp/clds/model/properties/Global.java
@@ -47,6 +47,7 @@
     private List<String> resourceVfc;
     private JsonNode deployParameters;
     private List<String> location;
+    private String vnfScope;
 
     /**
      * Parse global given json node.
@@ -61,6 +62,7 @@
         resourceVfc = AbstractModelElement.getValuesByName(globalNode, "vfc");
         deployParameters = AbstractModelElement.getJsonNodeByName(globalNode, "deployParameters");
         location = AbstractModelElement.getValuesByName(globalNode, "location");
+        vnfScope = AbstractModelElement.getValueByName(globalNode, "vnf");
     }
 
     /**
@@ -141,4 +143,9 @@
     public void setDeployParameters(JsonNode deployParameters) {
         this.deployParameters = deployParameters;
     }
+
+    public String getVnfScope() {
+        return vnfScope;
+    }
+
 }
diff --git a/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java b/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java
index f38e8c1..b567940 100644
--- a/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java
+++ b/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java
@@ -264,6 +264,23 @@
     }
 
     /**
+     * @return the PolicyNameWithScopeContext
+     */
+    public String getPolicyNameWithScopeContext(String policyScope, String policyType, String vnfScope, String context, String userDefinedName) {
+        return normalizePolicyScopeName(
+                policyScope + createScopeSeparator(policyScope) + policyType + "_" + vnfScope + "_" + context + "_" + modelName + "_" + userDefinedName);
+    }
+
+    /**
+     * @return the PolicyNameWithPrefixScopeContext
+     */
+    public String getPolicyNameWithPrefixScopeContext(String policyScope, String policyType, String vnfScope,  String context,
+    		String userDefinedName, String policyPrefix) {
+        return normalizePolicyScopeName(policyScope + createScopeSeparator(policyScope) + policyPrefix + policyType + "_" + vnfScope + "_"
+                + context + "_" + modelName + "_" + userDefinedName);
+    }
+
+    /**
      * Replace all '-' with '_' within policy scope and name.
      *
      * @param inName
diff --git a/src/test/resources/example/dao/bpmn-prop.json b/src/test/resources/example/dao/bpmn-prop.json
index f1b87a0..a38d58c 100644
--- a/src/test/resources/example/dao/bpmn-prop.json
+++ b/src/test/resources/example/dao/bpmn-prop.json
@@ -5,6 +5,80 @@
       "value": "uktukk"
     }
   ],
+  "TCA_11n5nl9": {
+		"group1": [
+			{
+				"name": "tname",
+				"value": "group1"
+			},
+			{
+				"name": "tuuid",
+				"value": "f734f031-10aa-t8fb-330f-04dde2886325"
+			},
+			{
+				"name": "tcaPolId",
+				"value": "policy1"
+			},
+			{
+				"name": "eventName",
+				"value": "vFirewallBroadcastPackets"
+			},
+			{
+				"name": "controlLoopSchemaType",
+				"value": "VNF"
+			},
+			{
+				"serviceConfigurations": [
+					[
+						"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value",
+						"LESS_OR_EQUAL",
+						"123",
+						"ABATED"
+					],
+					[
+						"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value",
+						"GREATER_OR_EQUAL",
+						"123",
+						"ONSET"
+					]
+				]
+			}
+		]
+	},
+	"global":
+    [
+        {
+            "name": "service",
+            "value":
+            [
+                "0f983e18-4603-4bb4-a98c-e29691fb16a1"
+            ]
+        },
+
+        {
+            "name": "vf",
+            "value":
+            [
+                "6c7aaec2-59eb-41d9-8681-b7f976ab668d"
+            ]
+        },
+
+        {
+            "name": "actionSet",
+            "value":
+            [
+                "vnfRecipe"
+            ]
+        },
+
+        {
+            "name": "location",
+            "value":
+            [
+                "SNDGCA64"
+            ]
+        }
+    ],
   "Policy_19c1hms": {
     "policy1": [
       {