X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fpolicy%2Fcontroller%2FDecisionPolicyController.java;h=ef43135c2b81b005996052213a5bb927ad8c863c;hb=eb654437ee2815028602daa943d0a939a5bee3cd;hp=57e8821f468d1a97acb75e5da24dcaaba7be10c4;hpb=dda032f8bb161d54eb1f59de2b4a3efb774fc4d1;p=policy%2Fengine.git 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 57e8821f4..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,15 +66,19 @@ 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"; @SuppressWarnings("unchecked") public void prePopulateDecisionPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) { - attributeList = new ArrayList(); - decisionList = new ArrayList(); - ruleAlgorithmList = new ArrayList(); + 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()); @@ -115,13 +122,13 @@ public class DecisionPolicyController extends RestrictedBaseController { AttributeDesignatorType designator = match.getAttributeDesignator(); String attributeId = designator.getAttributeId(); // First match in the target is EcompName, so set that value. - if (index == 0) { + if (attributeId.equals("ECOMPName")) { policyAdapter.setEcompName(value); } // Component attributes are saved under Target here we are fetching them back. - // One row is default so we are not adding dynamic componet at index 0. + // One row is default so we are not adding dynamic component at index 0. if (index >= 1) { - Map attribute = new HashMap(); + Map attribute = new HashMap<>(); attribute.put("key", attributeId); attribute.put("value", value); attributeList.add(attribute); @@ -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(); @@ -157,6 +182,8 @@ public class DecisionPolicyController extends RestrictedBaseController { break; }else if(((RuleType) object).getAdviceExpressions().getAdviceExpression().get(0).getAdviceId().toString().equalsIgnoreCase("GUARD_YAML")){ policyAdapter.setRuleProvider("GUARD_YAML"); + }else if(((RuleType) object).getAdviceExpressions().getAdviceExpression().get(0).getAdviceId().toString().equalsIgnoreCase("GUARD_BL_YAML")){ + policyAdapter.setRuleProvider("GUARD_BL_YAML"); } }else{ policyAdapter.setRuleProvider("Custom"); @@ -165,8 +192,8 @@ public class DecisionPolicyController extends RestrictedBaseController { if (condition != null) { ApplyType decisionApply = (ApplyType) condition.getExpression().getValue(); decisionApply = (ApplyType) decisionApply.getExpression().get(0).getValue(); - ruleAlgoirthmTracker = new LinkedList(); - if(policyAdapter.getRuleProvider()!=null && policyAdapter.getRuleProvider().equals("GUARD_YAML")){ + ruleAlgoirthmTracker = new LinkedList<>(); + if(policyAdapter.getRuleProvider()!=null && (policyAdapter.getRuleProvider().equals("GUARD_YAML")||(policyAdapter.getRuleProvider().equals("GUARD_BL_YAML")))){ YAMLParams yamlParams = new YAMLParams(); for(int i=0; i map = (Map)attributeList.get(i); @@ -179,9 +206,19 @@ public class DecisionPolicyController extends RestrictedBaseController { ApplyType apply = ((ApplyType)((ApplyType)decisionApply.getExpression().get(0).getValue()).getExpression().get(0).getValue()); yamlParams.setGuardActiveStart(((AttributeValueType)apply.getExpression().get(1).getValue()).getContent().get(0).toString()); yamlParams.setGuardActiveEnd(((AttributeValueType)apply.getExpression().get(2).getValue()).getContent().get(0).toString()); - yamlParams.setLimit(((AttributeValueType)((ApplyType)decisionApply.getExpression().get(1).getValue()).getExpression().get(1).getValue()).getContent().get(0).toString()); - String timeWindow = ((AttributeDesignatorType)((ApplyType)((ApplyType)decisionApply.getExpression().get(1).getValue()).getExpression().get(0).getValue()).getExpression().get(0).getValue()).getIssuer(); - yamlParams.setTimeWindow(timeWindow.substring(timeWindow.lastIndexOf(":")+1)); + if(policyAdapter.getRuleProvider().equals("GUARD_BL_YAML")){ + apply = (ApplyType)((ApplyType)((ApplyType)decisionApply.getExpression().get(0).getValue()).getExpression().get(1).getValue()).getExpression().get(2).getValue(); + Iterator> attributes = apply.getExpression().iterator(); + List blackList = new ArrayList<>(); + while(attributes.hasNext()){ + blackList.add(((AttributeValueType)attributes.next().getValue()).getContent().get(0).toString()); + } + yamlParams.setBlackList(blackList); + }else{ + yamlParams.setLimit(((AttributeValueType)((ApplyType)decisionApply.getExpression().get(1).getValue()).getExpression().get(1).getValue()).getContent().get(0).toString()); + String timeWindow = ((AttributeDesignatorType)((ApplyType)((ApplyType)decisionApply.getExpression().get(1).getValue()).getExpression().get(0).getValue()).getExpression().get(0).getValue()).getIssuer(); + yamlParams.setTimeWindow(timeWindow.substring(timeWindow.lastIndexOf(":")+1)); + } policyAdapter.setYamlparams(yamlParams); policyAdapter.setAttributes(new ArrayList()); policyAdapter.setRuleAlgorithmschoices(new ArrayList()); @@ -191,17 +228,42 @@ 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(); + Map ruleMap = new HashMap<>(); ruleMap.put("id", "A" + (index +1)); Map dropDownMap = PolicyController.getDropDownMap(); for (String key : dropDownMap.keySet()) { @@ -262,7 +324,7 @@ public class DecisionPolicyController extends RestrictedBaseController { if (logger.isDebugEnabled()) { logger.debug("Prepopulating Compound rule algorithm: " + index); } - Map rule = new HashMap(); + Map rule = new HashMap<>(); for (String key : PolicyController.getDropDownMap().keySet()) { String keyValue = PolicyController.getDropDownMap().get(key); if (keyValue.equals(decisionApply.getFunctionId())) { @@ -281,6 +343,7 @@ public class DecisionPolicyController extends RestrictedBaseController { ruleAlgorithmList.add(rule); index++; } + return index; } }