diff options
author | Michael Mokry <mm117s@att.com> | 2017-07-07 16:00:59 -0500 |
---|---|---|
committer | Michael Mokry <mm117s@att.com> | 2017-07-10 18:58:00 +0000 |
commit | eb654437ee2815028602daa943d0a939a5bee3cd (patch) | |
tree | 77ad3b26bcf60a80cbbf87dbd1b06f60de976c39 /POLICY-SDK-APP/src/main/java | |
parent | bb927b5325d7b82cdc65bf25aa217ad7c56a46b3 (diff) |
[POLICY-67] Add new Rainy Day Decision Policy
Change-Id: I8fb730e4363c885ccbe3a05ae971c5de5608d70c
Signed-off-by: Michael Mokry <mm117s@att.com>
Diffstat (limited to 'POLICY-SDK-APP/src/main/java')
2 files changed, 80 insertions, 0 deletions
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<Object> attributeList; private ArrayList<Object> decisionList; private ArrayList<Object> ruleAlgorithmList; + private ArrayList<Object> treatmentList = null; protected LinkedList<Integer> 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<attributeList.size() ; i++){ + Map<String, String> map = (Map<String,String>)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<Object> 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<AttributeValueType> tempTreatmentObj = (JAXBElement<AttributeValueType>) 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<String, String> ruleMap = new HashMap<>(); + + ruleMap.put("errorcode", errorcode); + ruleMap.put("treatment", treatment); + treatmentList.add(ruleMap); + + } + private void prePopulateDecisionRuleAlgorithms(int index, ApplyType decisionApply, List<JAXBElement<?>> jaxbDecisionTypes) { Map<String, String> 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" + "<br>"); valid = false; } + + if("Rainy_Day".equals(policyData.getRuleProvider())){ + if(policyData.getRainyday()==null){ + responseString.append("<b> Rainy Day Parameters are Required </b><br>"); + valid = false; + }else{ + if(policyData.getRainyday().getServiceType()==null){ + responseString.append("Rainy Day <b>Service Type</b> is Required<br>"); + valid = false; + } + if(policyData.getRainyday().getVnfType()==null){ + responseString.append("Rainy Day <b>VNF Type</b> is Required<br>"); + valid = false; + } + if(policyData.getRainyday().getBbid()==null){ + responseString.append("Rainy Day <b>Building Block ID</b> is Required<br>"); + valid = false; + } + if(policyData.getRainyday().getWorkstep()==null){ + responseString.append("Rainy Day <b>Work Step</b> is Required<br>"); + valid = false; + } + if(policyData.getRainyday().getServiceType()==null){ + responseString.append("Rainy Day <b>Error Code</b> is Required<br>"); + valid = false; + } + } + } + if("GUARD_YAML".equals(policyData.getRuleProvider()) || "GUARD_BL_YAML".equals(policyData.getRuleProvider())){ if(policyData.getYamlparams()==null){ responseString.append("<b> Guard Params are Required </b>" + "<br>"); |