Some minor improvements 99/74099/1
authorsebdet <sebastien.determe@intl.att.com>
Sat, 1 Dec 2018 14:06:42 +0000 (15:06 +0100)
committersebdet <sebastien.determe@intl.att.com>
Sat, 1 Dec 2018 14:06:42 +0000 (15:06 +0100)
Minor improvements of condition, sonar reporting

Issue-ID: CLAMP-252
Change-Id: I216a0896f15e92a0b72e85d0c1ebc114a7302036
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java
src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java
src/main/java/org/onap/clamp/clds/config/ClampProperties.java
src/main/java/org/onap/clamp/clds/model/properties/Global.java
src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java
src/test/resources/example/dao/bpmn-prop.json

index 8729993..5a983b7 100644 (file)
@@ -60,15 +60,19 @@ public class OperationalPolicyDeleteDelegate {
         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());
+                }
             }
         }
+        
     }
 }
index de86faa..0b4cbea 100644 (file)
@@ -44,7 +44,8 @@ public class GuardPolicyAttributesConstructor {
     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 @@ public class GuardPolicyAttributesConstructor {
     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;
index bdb4dda..7c6c6ff 100644 (file)
 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 @@ public class ClampProperties {
     @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 @@ public class ClampProperties {
         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));
+       }
 }
index 6fabc7a..e867407 100644 (file)
@@ -47,6 +47,7 @@ public class Global {
     private List<String> resourceVfc;
     private JsonNode deployParameters;
     private List<String> location;
+    private String vnfScope;
 
     /**
      * Parse global given json node.
@@ -61,6 +62,7 @@ public class Global {
         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 class Global {
     public void setDeployParameters(JsonNode deployParameters) {
         this.deployParameters = deployParameters;
     }
+
+    public String getVnfScope() {
+        return vnfScope;
+    }
+
 }
index f38e8c1..b567940 100644 (file)
@@ -263,6 +263,23 @@ public class ModelProperties {
             modelName + createScopeSeparator(modelName) + policyNamePrefix + getCurrentPolicyName());
     }
 
+    /**
+     * @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.
      *
index f1b87a0..a38d58c 100644 (file)
@@ -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": [
       {