- List<Object> ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
- int index = 0;
- for (Object object : ruleList) {
- if (object instanceof VariableDefinitionType) {
- VariableDefinitionType variableDefinitionType = (VariableDefinitionType) object;
- Map<String, String> settings = new HashMap<>();
- settings.put("key", variableDefinitionType.getVariableId());
- JAXBElement<AttributeValueType> attributeValueTypeElement = (JAXBElement<AttributeValueType>) variableDefinitionType.getExpression();
- if (attributeValueTypeElement != null) {
- AttributeValueType attributeValueType = attributeValueTypeElement.getValue();
- settings.put("value", attributeValueType.getContent().get(0).toString());
- }
- decisionList.add(settings);
- } else if (object instanceof RuleType) {
- // get the condition data under the rule for rule Algorithms.
- if(((RuleType) object).getEffect().equals(EffectType.DENY)) {
- if(((RuleType) object).getAdviceExpressions()!=null){
- if(((RuleType) object).getAdviceExpressions().getAdviceExpression().get(0).getAdviceId().toString().equalsIgnoreCase("AAF")){
- policyAdapter.setRuleProvider("AAF");
- 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");
- }
- ConditionType condition = ((RuleType) object).getCondition();
- 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")||(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);
- if("actor".equals(map.get("key"))){
- yamlParams.setActor(map.get("value"));
- }else if("recipe".equals(map.get("key"))){
- yamlParams.setRecipe(map.get("value"));
- }else if("target".equals(map.get("key"))){
- yamlParams.setTargets(Arrays.asList(map.get("value").split("\\|")));
- }else if("clname".equals(map.get("key"))){
- yamlParams.setClname(map.get("value"));
- }
- }
- 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());
- 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{
- ApplyType timeWindowSection = (ApplyType)((ApplyType)decisionApply.getExpression().get(0).getValue()).getExpression().get(1).getValue();
- yamlParams.setLimit(((AttributeValueType)timeWindowSection.getExpression().get(1).getValue()).getContent().get(0).toString());
- String timeWindow = ((AttributeDesignatorType)((ApplyType)timeWindowSection.getExpression().get(0).getValue()).getExpression().get(0).getValue()).getIssuer();
- yamlParams.setTimeUnits(timeWindow.substring(timeWindow.lastIndexOf(':')+1));
- yamlParams.setTimeWindow(timeWindow.substring(timeWindow.indexOf(":tw:")+4,timeWindow.lastIndexOf(':')));
- }
- policyAdapter.setYamlparams(yamlParams);
- policyAdapter.setAttributes(new ArrayList<Object>());
- policyAdapter.setRuleAlgorithmschoices(new ArrayList<Object>());
- break;
- }
- // Populating Rule Algorithms starting from compound.
- prePopulateDecisionCompoundRuleAlgorithm(index, decisionApply);
- policyAdapter.setRuleAlgorithmschoices(ruleAlgorithmList);
- }
- } else if(policyAdapter.getRuleProvider()!=null && policyAdapter.getRuleProvider().equals("Rainy_Day")&& ((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);