From d1779040e9f6aeaff20a8c0f4da64f4ac7774ae0 Mon Sep 17 00:00:00 2001 From: sebdet Date: Sat, 1 Dec 2018 15:06:42 +0100 Subject: Some minor improvements Minor improvements of condition, sonar reporting Issue-ID: CLAMP-252 Change-Id: I216a0896f15e92a0b72e85d0c1ebc114a7302036 Signed-off-by: sebdet --- .../client/OperationalPolicyDeleteDelegate.java | 20 ++++++++++------- .../policy/GuardPolicyAttributesConstructor.java | 25 +++++++++++----------- .../onap/clamp/clds/config/ClampProperties.java | 19 ++++++++++++++++ .../onap/clamp/clds/model/properties/Global.java | 7 ++++++ .../clds/model/properties/ModelProperties.java | 17 +++++++++++++++ 5 files changed, 68 insertions(+), 20 deletions(-) (limited to 'src/main/java') 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 872999356..5a983b782 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 @@ 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()); + } } } + } } 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 de86faa21..0b4cbeab7 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 @@ public class GuardPolicyAttributesConstructor { private GuardPolicyAttributesConstructor() { } - public static Map> formatAttributes(ModelProperties modelProperties, PolicyItem policyItem) { + public static Map> formatAttributes(ModelProperties modelProperties, + PolicyItem policyItem) { Map matchingAttributes = prepareMatchingAttributes(policyItem, modelProperties); return createAttributesMap(matchingAttributes); } @@ -62,20 +63,20 @@ public class GuardPolicyAttributesConstructor { private static Map prepareMatchingAttributes(PolicyItem policyItem, ModelProperties modelProp) { logger.info("Preparing matching attributes for guard..."); Map 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 bdb4dda5b..7c6c6ff60 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 @@ 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 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 6fabc7a51..e86740726 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 @@ public class Global { private List resourceVfc; private JsonNode deployParameters; private List 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; + } + } 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 f38e8c1c4..b56794005 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 @@ -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. * -- cgit 1.2.3-korg