From 87c95be02a8a4d77e165dede90777e811b59dcae Mon Sep 17 00:00:00 2001 From: Ravindra Bakkamanthala Date: Tue, 23 May 2017 14:56:12 -0400 Subject: Commit includes ControlLoopPolicy API and bugfixes Change-Id: I3e18bb8b4c31a0d908bb0cff4c85e2a3fb450a63 Signed-off-by: Ravindra Bakkamanthala --- .../pap/xacml/rest/components/DecisionPolicy.java | 39 +++++++++++----------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java') diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java index e5a114ba8..8d2617ce2 100644 --- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java @@ -88,13 +88,13 @@ public class DecisionPolicy extends Policy { private static final String XACMLTEMPLATE = "Decision_GuardPolicyTemplate.xml"; - List dynamicLabelRuleAlgorithms = new LinkedList(); - List dynamicFieldComboRuleAlgorithms = new LinkedList(); - List dynamicFieldOneRuleAlgorithms = new LinkedList(); - List dynamicFieldTwoRuleAlgorithms = new LinkedList(); - List dataTypeList = new LinkedList(); + List dynamicLabelRuleAlgorithms = new LinkedList<>(); + List dynamicFieldComboRuleAlgorithms = new LinkedList<>(); + List dynamicFieldOneRuleAlgorithms = new LinkedList<>(); + List dynamicFieldTwoRuleAlgorithms = new LinkedList<>(); + List dataTypeList = new LinkedList<>(); - protected Map dropDownMap = new HashMap(); + protected Map dropDownMap = new HashMap<>(); public DecisionPolicy() { @@ -108,7 +108,7 @@ public class DecisionPolicy extends Policy { @Override public Map savePolicies() throws Exception { - Map successMap = new HashMap(); + Map successMap = new HashMap<>(); if(isPolicyExists()){ successMap.put("EXISTS", "This Policy already exist on the PAP"); return successMap; @@ -153,7 +153,7 @@ public class DecisionPolicy extends Policy { policyName = policyAdapter.getNewFileName(); if(policyAdapter.getRuleProvider().equals(GUARD_YAML)){ - Map yamlParams = new HashMap(); + Map yamlParams = new HashMap<>(); yamlParams.put("description", (policyAdapter.getPolicyDescription()!=null)? policyAdapter.getPolicyDescription(): "YAML Guard Policy"); String fileName = policyAdapter.getNewFileName(); String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length()); @@ -191,7 +191,7 @@ public class DecisionPolicy extends Policy { Map dynamicFieldComponentAttributes = policyAdapter.getDynamicFieldConfigAttributes(); if(policyAdapter.getRuleProvider()!=null && policyAdapter.getRuleProvider().equals(AAFProvider)){ - dynamicFieldComponentAttributes = new HashMap(); + dynamicFieldComponentAttributes = new HashMap<>(); } // If there is any dynamic field attributes create the matches here @@ -214,7 +214,7 @@ public class DecisionPolicy extends Policy { //dynamicVariableList = policyAdapter.getDynamicVariableList(); if(policyAdapter.getRuleProvider()!=null && policyAdapter.getRuleProvider().equals(AAFProvider)){ - dynamicFieldDecisionSettings = new HashMap(); + dynamicFieldDecisionSettings = new HashMap<>(); } // settings are dynamic so check how many rows are added and add all @@ -240,11 +240,12 @@ public class DecisionPolicy extends Policy { ControlLoopGuardBuilder builder = ControlLoopGuardBuilder.Factory.buildControlLoopGuard(new Guard()); GuardPolicy policy1 = new GuardPolicy((policyAdapter.getUuid()!=null? policyAdapter.getUuid(): UUID.randomUUID().toString()) ,yamlParams.get("PolicyName"), yamlParams.get("description"), yamlParams.get("actor"), yamlParams.get("recipe")); builder = builder.addGuardPolicy(policy1); - Map time_in_range = new HashMap(); + Map time_in_range = new HashMap<>(); time_in_range.put("arg2", yamlParams.get("guardActiveStart")); time_in_range.put("arg3", yamlParams.get("guardActiveEnd")); - Constraint cons = new Constraint(Integer.parseInt(yamlParams.get("limit")), yamlParams.get("timeWindow"), time_in_range); - builder = builder.addLimitConstraint(policy1.id, cons); + Constraint cons = new Constraint(Integer.parseInt(yamlParams.get("limit")), yamlParams.get("timeWindow")); + cons.setTime_in_range(time_in_range); + builder = builder.addLimitConstraint(policy1.getId(), cons); // Build the specification Results results = builder.buildSpecification(); // YAML TO XACML @@ -257,12 +258,12 @@ public class DecisionPolicy extends Policy { yamlSpecs.put("PolicyName", yamlParams.get("PolicyName")); yamlSpecs.put("description", yamlParams.get("description")); yamlSpecs.put("ECOMPName", yamlParams.get("ECOMPName")); - yamlSpecs.put("actor", yamlGuardObject.guards.getFirst().actor); - yamlSpecs.put("recipe", yamlGuardObject.guards.getFirst().recipe); - yamlSpecs.put("limit", yamlGuardObject.guards.getFirst().limit_constraints.getFirst().num.toString()); - yamlSpecs.put("timeWindow", yamlGuardObject.guards.getFirst().limit_constraints.getFirst().duration); - yamlSpecs.put("guardActiveStart", yamlGuardObject.guards.getFirst().limit_constraints.getFirst().time_in_range.get("arg2")); - yamlSpecs.put("guardActiveEnd", yamlGuardObject.guards.getFirst().limit_constraints.getFirst().time_in_range.get("arg3")); + yamlSpecs.put("actor", ((LinkedList)yamlGuardObject.getGuards()).getFirst().getActor()); + yamlSpecs.put("recipe", ((LinkedList)yamlGuardObject.getGuards()).getFirst().getRecipe()); + yamlSpecs.put("limit", ((LinkedList)((LinkedList)yamlGuardObject.getGuards()).getFirst().getLimit_constraints()).getFirst().getNum().toString()); + yamlSpecs.put("timeWindow", ((LinkedList)((LinkedList)yamlGuardObject.getGuards()).getFirst().getLimit_constraints()).getFirst().getDuration()); + yamlSpecs.put("guardActiveStart", ((LinkedList)((LinkedList)yamlGuardObject.getGuards()).getFirst().getLimit_constraints()).getFirst().getTime_in_range().get("arg2")); + yamlSpecs.put("guardActiveEnd", ((LinkedList)((LinkedList)yamlGuardObject.getGuards()).getFirst().getLimit_constraints()).getFirst().getTime_in_range().get("arg3")); String xacmlPolicyContent = SafePolicyBuilder.generateXacmlGuard(xacmlTemplateContent,yamlSpecs); // Convert the Policy into Stream input to Policy Adapter. Object policy = XACMLPolicyScanner.readPolicy(new ByteArrayInputStream(xacmlPolicyContent.getBytes(StandardCharsets.UTF_8))); -- cgit 1.2.3-korg