Fixed the Policy API issues and Bugfixes
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / openecomp / policy / controller / DecisionPolicyController.java
index 82fc24b..2827806 100644 (file)
@@ -68,9 +68,9 @@ public class DecisionPolicyController extends RestrictedBaseController {
 
        @SuppressWarnings("unchecked")
        public void prePopulateDecisionPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
-               attributeList = new ArrayList<Object>();
-               decisionList = new ArrayList<Object>();
-               ruleAlgorithmList = new ArrayList<Object>();
+               attributeList = new ArrayList<>();
+               decisionList = new ArrayList<>();
+               ruleAlgorithmList = new ArrayList<>();
                if (policyAdapter.getPolicyData() instanceof PolicyType) {
                        Object policyData = policyAdapter.getPolicyData();
                        PolicyType policy = (PolicyType) policyData;
@@ -121,7 +121,7 @@ public class DecisionPolicyController extends RestrictedBaseController {
                                                                                // Component attributes are saved under Target here we are fetching  them back.
                                                                                // One row is default so we are not adding dynamic component at index 0.
                                                                                if (index >= 1) {       
-                                                                                       Map<String, String> attribute = new HashMap<String, String>();
+                                                                                       Map<String, String> attribute = new HashMap<>();
                                                                                        attribute.put("key", attributeId);
                                                                                        attribute.put("value", value);
                                                                                        attributeList.add(attribute);   
@@ -157,6 +157,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 +167,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<Integer>();
-                                                               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<attributeList.size() ; i++){
                                                                                Map<String, String> map = (Map<String,String>)attributeList.get(i);
@@ -179,9 +181,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<JAXBElement<?>> attributes = apply.getExpression().iterator();
+                                                                               List<String> 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<Object>());
                                                                        policyAdapter.setRuleAlgorithmschoices(new ArrayList<Object>());
@@ -201,7 +213,7 @@ public class DecisionPolicyController extends RestrictedBaseController {
        }
 
        private void prePopulateDecisionRuleAlgorithms(int index, ApplyType decisionApply, List<JAXBElement<?>> jaxbDecisionTypes) {
-               Map<String, String> ruleMap = new HashMap<String, String>();
+               Map<String, String> ruleMap = new HashMap<>();
                ruleMap.put("id", "A" + (index +1));
                Map<String, String> dropDownMap = PolicyController.getDropDownMap();
                for (String key : dropDownMap.keySet()) {
@@ -262,7 +274,7 @@ public class DecisionPolicyController extends RestrictedBaseController {
                        if (logger.isDebugEnabled()) {
                                logger.debug("Prepopulating Compound rule algorithm: " + index);
                        }
-                       Map<String, String> rule = new HashMap<String, String>();
+                       Map<String, String> rule = new HashMap<>();
                        for (String key : PolicyController.getDropDownMap().keySet()) {
                                String keyValue = PolicyController.getDropDownMap().get(key);
                                if (keyValue.equals(decisionApply.getFunctionId())) {