From eb654437ee2815028602daa943d0a939a5bee3cd Mon Sep 17 00:00:00 2001 From: Michael Mokry Date: Fri, 7 Jul 2017 16:00:59 -0500 Subject: [POLICY-67] Add new Rainy Day Decision Policy Change-Id: I8fb730e4363c885ccbe3a05ae971c5de5608d70c Signed-off-by: Michael Mokry --- .../controller/DecisionPolicyController.java | 51 ++++++++++++++++++++++ .../controller/PolicyValidationController.java | 29 ++++++++++++ 2 files changed, 80 insertions(+) (limited to 'POLICY-SDK-APP/src/main/java') diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/DecisionPolicyController.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/DecisionPolicyController.java index 28278062d..ef43135c2 100644 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/DecisionPolicyController.java +++ b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/DecisionPolicyController.java @@ -32,12 +32,15 @@ import javax.xml.bind.JAXBElement; import org.openecomp.policy.common.logging.flexlogger.FlexLogger; import org.openecomp.policy.common.logging.flexlogger.Logger; import org.openecomp.policy.rest.adapter.PolicyRestAdapter; +import org.openecomp.policy.rest.adapter.RainyDayParams; import org.openecomp.policy.rest.adapter.YAMLParams; import org.openecomp.policy.rest.jpa.PolicyEntity; import org.openecomp.portalsdk.core.controller.RestrictedBaseController; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType; @@ -63,6 +66,7 @@ public class DecisionPolicyController extends RestrictedBaseController { private ArrayList attributeList; private ArrayList decisionList; private ArrayList ruleAlgorithmList; + private ArrayList treatmentList = null; protected LinkedList ruleAlgoirthmTracker; public static final String FUNCTION_NOT = "urn:oasis:names:tc:xacml:1.0:function:not"; @@ -71,7 +75,10 @@ public class DecisionPolicyController extends RestrictedBaseController { attributeList = new ArrayList<>(); decisionList = new ArrayList<>(); ruleAlgorithmList = new ArrayList<>(); + treatmentList = new ArrayList<>(); + if (policyAdapter.getPolicyData() instanceof PolicyType) { + RainyDayParams rainydayParams = new RainyDayParams(); Object policyData = policyAdapter.getPolicyData(); PolicyType policy = (PolicyType) policyData; policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); @@ -133,6 +140,24 @@ public class DecisionPolicyController extends RestrictedBaseController { } } } + // Setting rainy day attributes to the parameters object if they exist + if(!attributeList.isEmpty()) { + for(int i=0; i map = (Map)attributeList.get(i); + if(map.get("key").equals("WorkStep")){ + rainydayParams.setWorkstep(map.get("value")); + }else if(map.get("key").equals("BB_ID")){ + rainydayParams.setBbid(map.get("value")); + }else if(map.get("key").equals("ServiceType")){ + rainydayParams.setServiceType(map.get("value")); + }else if(map.get("key").equals("VNFType")){ + rainydayParams.setVnfType(map.get("value")); + } + } + } + + policyAdapter.setRuleProvider("Rainy_Day"); + } List ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); @@ -203,15 +228,40 @@ public class DecisionPolicyController extends RestrictedBaseController { prePopulateDecisionCompoundRuleAlgorithm(index, decisionApply); policyAdapter.setRuleAlgorithmschoices(ruleAlgorithmList); } + } else if (((RuleType) object).getEffect().equals(EffectType.PERMIT)) { + + TargetType ruleTarget = ((RuleType) object).getTarget(); + AdviceExpressionsType adviceExpression = ((RuleType) object).getAdviceExpressions(); + + String errorcode = ruleTarget.getAnyOf().get(0).getAllOf().get(0).getMatch(). + get(1).getAttributeValue().getContent().get(0).toString(); + JAXBElement tempTreatmentObj = (JAXBElement) adviceExpression.getAdviceExpression(). + get(0).getAttributeAssignmentExpression().get(0).getExpression(); + String treatment = tempTreatmentObj.getValue().getContent().get(0).toString(); + + prePopulateRainyDayTreatments(errorcode, treatment); + } } } } + + rainydayParams.setTreatmentTableChoices(treatmentList); + policyAdapter.setRainyday(rainydayParams); policyAdapter.setSettings(decisionList); } } + private void prePopulateRainyDayTreatments(String errorcode, String treatment) { + Map ruleMap = new HashMap<>(); + + ruleMap.put("errorcode", errorcode); + ruleMap.put("treatment", treatment); + treatmentList.add(ruleMap); + + } + private void prePopulateDecisionRuleAlgorithms(int index, ApplyType decisionApply, List> jaxbDecisionTypes) { Map ruleMap = new HashMap<>(); ruleMap.put("id", "A" + (index +1)); @@ -293,6 +343,7 @@ public class DecisionPolicyController extends RestrictedBaseController { ruleAlgorithmList.add(rule); index++; } + return index; } } diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java index ed47fd949..cc6903b91 100644 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java +++ b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java @@ -438,6 +438,35 @@ public class PolicyValidationController extends RestrictedBaseController { responseString.append("Ecomp Name: Ecomp Name Should not be empty" + "
"); valid = false; } + + if("Rainy_Day".equals(policyData.getRuleProvider())){ + if(policyData.getRainyday()==null){ + responseString.append(" Rainy Day Parameters are Required
"); + valid = false; + }else{ + if(policyData.getRainyday().getServiceType()==null){ + responseString.append("Rainy Day Service Type is Required
"); + valid = false; + } + if(policyData.getRainyday().getVnfType()==null){ + responseString.append("Rainy Day VNF Type is Required
"); + valid = false; + } + if(policyData.getRainyday().getBbid()==null){ + responseString.append("Rainy Day Building Block ID is Required
"); + valid = false; + } + if(policyData.getRainyday().getWorkstep()==null){ + responseString.append("Rainy Day Work Step is Required
"); + valid = false; + } + if(policyData.getRainyday().getServiceType()==null){ + responseString.append("Rainy Day Error Code is Required
"); + valid = false; + } + } + } + if("GUARD_YAML".equals(policyData.getRuleProvider()) || "GUARD_BL_YAML".equals(policyData.getRuleProvider())){ if(policyData.getYamlparams()==null){ responseString.append(" Guard Params are Required " + "
"); -- cgit 1.2.3-korg