X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontroller%2FDecisionPolicyController.java;h=8ecf3692dc5a4111bc3aba253f1e2090aa2565b5;hp=fdbee2a99834ffad7439ca80b14403f7d00e3c45;hb=0950d79047d3404c15b4dd30cffeb81346565f64;hpb=7fd58e9a2427a215daa6b543e901534e83d3c246 diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java index fdbee2a99..8ecf3692d 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,19 +30,9 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; + import javax.xml.bind.JAXBElement; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.policy.common.logging.flexlogger.FlexLogger; -import org.onap.policy.common.logging.flexlogger.Logger; -import org.onap.policy.rest.adapter.PolicyRestAdapter; -import org.onap.policy.rest.adapter.RainyDayParams; -import org.onap.policy.rest.adapter.YAMLParams; -import org.onap.policy.rest.jpa.PolicyEntity; -import org.onap.policy.xacml.util.XACMLPolicyWriter; -import org.onap.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.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; @@ -59,274 +49,296 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableDefinitionType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableReferenceType; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; +import org.onap.policy.rest.adapter.PolicyRestAdapter; +import org.onap.policy.rest.adapter.RainyDayParams; +import org.onap.policy.rest.adapter.YAMLParams; +import org.onap.policy.rest.jpa.PolicyEntity; +import org.onap.policy.xacml.util.XACMLPolicyWriter; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + @Controller @RequestMapping("/") public class DecisionPolicyController extends RestrictedBaseController { private static final Logger policyLogger = FlexLogger.getLogger(DecisionPolicyController.class); - public DecisionPolicyController() { - // This constructor is empty - } + public static final String FUNCTION_NOT = "urn:oasis:names:tc:xacml:1.0:function:not"; + private static final String BLENTRY = "@blEntry@"; + private static final String DECISIONRAWTYPE = "@#RuleProvider@#Decision_Raw@#RuleProvider@#"; + private static final String GUARD_YAML = "GUARD_YAML"; + private static final String GUARD_BL_YAML = "GUARD_BL_YAML"; + private static final String GUARD_MIN_MAX = "GUARD_MIN_MAX"; protected PolicyRestAdapter policyAdapter = null; - 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"; - private static final String blEntry = "@blEntry@"; - private static final String decisionRawType = "@#RuleProvider@#Decision_Raw@#RuleProvider@#"; - public void rawXACMLPolicy(PolicyRestAdapter policyAdapter, PolicyEntity entity) { + public DecisionPolicyController() { + // This constructor is empty + } + + /** + * rawXacmlPolicy. Should this method be private? + * + * @param policyAdapter PolicyRestAdapter + * @param entity PolicyEntity + */ + public void rawXacmlPolicy(PolicyRestAdapter policyAdapter, PolicyEntity entity) { try (InputStream policyXmlStream = XACMLPolicyWriter.getXmlAsInputStream(policyAdapter.getPolicyData())) { String name = StringUtils.substringAfter(entity.getPolicyName(), "Decision_"); policyAdapter.setPolicyName(name.substring(0, name.indexOf('.'))); policyAdapter.setRuleProvider("Raw"); - policyAdapter.setRawXacmlPolicy(IOUtils.toString(policyXmlStream).replaceAll(decisionRawType, "")); + policyAdapter.setRawXacmlPolicy(IOUtils.toString(policyXmlStream).replaceAll(DECISIONRAWTYPE, "")); } catch (IOException e) { policyLogger.error("Exception Occured while setting XACML Raw Object" + e); } } + /** + * prePopulateDecisionPolicyData. + * + * @param policyAdapter PolicyRestAdapter + * @param entity PolicyEntity + */ @SuppressWarnings("unchecked") public void prePopulateDecisionPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) { - attributeList = new ArrayList<>(); - decisionList = new ArrayList<>(); + List attributeList = new ArrayList<>(); + List decisionList = new ArrayList<>(); ruleAlgorithmList = new ArrayList<>(); treatmentList = new ArrayList<>(); boolean rawPolicyCheck = false; if (policyAdapter.getPolicyData() instanceof PolicySetType) { - rawPolicyCheck = ((PolicySetType) policyAdapter.getPolicyData()).getDescription().contains(decisionRawType); + rawPolicyCheck = ((PolicySetType) policyAdapter.getPolicyData()).getDescription().contains(DECISIONRAWTYPE); } else { - rawPolicyCheck = ((PolicyType) policyAdapter.getPolicyData()).getDescription().contains(decisionRawType); + rawPolicyCheck = ((PolicyType) policyAdapter.getPolicyData()).getDescription().contains(DECISIONRAWTYPE); } if (rawPolicyCheck) { - rawXACMLPolicy(policyAdapter, entity); - } else { - RainyDayParams rainydayParams = new RainyDayParams(); - Object policyData = policyAdapter.getPolicyData(); - PolicyType policy = (PolicyType) policyData; - policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); - - policyAdapter.setPolicyName(StringUtils.substringAfter(policyAdapter.getPolicyName(), "Decision_")); - String description = ""; - String blackListEntryType = "Use Manual Entry"; - try { - if (policy.getDescription().contains(blEntry)) { - blackListEntryType = policy.getDescription().substring(policy.getDescription().indexOf(blEntry) + 9, - policy.getDescription().lastIndexOf(blEntry)); - } - policyAdapter.setBlackListEntryType(blackListEntryType); - description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); + rawXacmlPolicy(policyAdapter, entity); + return; + } + RainyDayParams rainydayParams = new RainyDayParams(); + Object policyData = policyAdapter.getPolicyData(); + PolicyType policy = (PolicyType) policyData; + policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); - } catch (Exception e) { - policyLogger.info("General error", e); - description = policy.getDescription(); + policyAdapter.setPolicyName(StringUtils.substringAfter(policyAdapter.getPolicyName(), "Decision_")); + String description = ""; + String blackListEntryType = "Use Manual Entry"; + try { + if (policy.getDescription().contains(BLENTRY)) { + blackListEntryType = policy.getDescription().substring(policy.getDescription().indexOf(BLENTRY) + 9, + policy.getDescription().lastIndexOf(BLENTRY)); } - policyAdapter.setPolicyDescription(description); - // Get the target data under policy for Action. - TargetType target = policy.getTarget(); - if (target != null) { - // under target we have AnyOFType - List anyOfList = target.getAnyOf(); - if (anyOfList != null) { - Iterator iterAnyOf = anyOfList.iterator(); - while (iterAnyOf.hasNext()) { - AnyOfType anyOf = iterAnyOf.next(); - // Under AntOfType we have AllOfType - List allOfList = anyOf.getAllOf(); - if (allOfList != null) { - Iterator iterAllOf = allOfList.iterator(); - while (iterAllOf.hasNext()) { - AllOfType allOf = iterAllOf.next(); - // Under AllOfType we have Mathch. - List matchList = allOf.getMatch(); - int index = 0; - if (matchList != null) { - Iterator iterMatch = matchList.iterator(); - while (iterMatch.hasNext()) { - MatchType match = iterMatch.next(); - // - // Under the match we have attributevalue and - // attributeDesignator. So,finally down to the actual attribute. - // - AttributeValueType attributeValue = match.getAttributeValue(); - String value = (String) attributeValue.getContent().get(0); - if (value != null) { - value = value.replaceAll("\\(\\?i\\)", ""); - } - AttributeDesignatorType designator = match.getAttributeDesignator(); - String attributeId = designator.getAttributeId(); - // First match in the target is OnapName, so set that value. - if ("ONAPName".equals(attributeId)) { - policyAdapter.setOnapName(value); - } - // 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 attribute = new HashMap<>(); - attribute.put("key", attributeId); - attribute.put("value", value); - attributeList.add(attribute); - } - index++; - } - } - policyAdapter.setAttributes(attributeList); - } - } + policyAdapter.setBlackListEntryType(blackListEntryType); + description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); + + } catch (Exception e) { + policyLogger.info("General error", e); + description = policy.getDescription(); + } + policyAdapter.setPolicyDescription(description); + // Get the target data under policy for Action. + TargetType target = policy.getTarget(); + if (target == null) { + rainydayParams.setTreatmentTableChoices(treatmentList); + policyAdapter.setRainyday(rainydayParams); + policyAdapter.setSettings(decisionList); + return; + } + // under target we have AnyOFType + for (AnyOfType anyOf : target.getAnyOf()) { + for (AllOfType allOf : anyOf.getAllOf()) { + int index = 0; + for (MatchType match : allOf.getMatch()) { + // + // Under the match we have attributevalue and + // attributeDesignator. So,finally down to the actual attribute. + // + AttributeValueType attributeValue = match.getAttributeValue(); + String value = (String) attributeValue.getContent().get(0); + if (value != null) { + value = value.replaceAll("\\(\\?i\\)", ""); } - // Setting rainy day attributes to the parameters object if they exist - boolean rainy = false; - if (!attributeList.isEmpty()) { - for (int i = 0; i < attributeList.size(); i++) { - Map map = (Map) attributeList.get(i); - if ("WorkStep".equals(map.get("key"))) { - rainydayParams.setWorkstep(map.get("value")); - rainy = true; - } else if ("BB_ID".equals(map.get("key"))) { - rainydayParams.setBbid(map.get("value")); - rainy = true; - } else if ("ServiceType".equals(map.get("key"))) { - rainydayParams.setServiceType(map.get("value")); - rainy = true; - } else if ("VNFType".equals(map.get("key"))) { - rainydayParams.setVnfType(map.get("value")); - rainy = true; - } - } + AttributeDesignatorType designator = match.getAttributeDesignator(); + String attributeId = designator.getAttributeId(); + // First match in the target is OnapName, so set that value. + if ("ONAPName".equals(attributeId)) { + policyAdapter.setOnapName(value); } - if (rainy) { - policyAdapter.setRuleProvider("Rainy_Day"); + // 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 attribute = new HashMap<>(); + attribute.put("key", attributeId); + attribute.put("value", value); + attributeList.add(attribute); } + index++; } + policyAdapter.setAttributes(attributeList); + } + } + // Setting rainy day attributes to the parameters object if they exist + boolean rainy = false; + if (!attributeList.isEmpty()) { + for (int i = 0; i < attributeList.size(); i++) { + Map map = (Map) attributeList.get(i); + String key = map.get("key"); + if ("WorkStep".equals(key)) { + rainydayParams.setWorkstep(map.get("value")); + rainy = true; + } else if ("BB_ID".equals(key)) { + rainydayParams.setBbid(map.get("value")); + rainy = true; + } else if ("ServiceType".equals(key)) { + rainydayParams.setServiceType(map.get("value")); + rainy = true; + } else if ("VNFType".equals(key)) { + rainydayParams.setVnfType(map.get("value")); + rainy = true; + } + } + } + if (rainy) { + policyAdapter.setRuleProvider("Rainy_Day"); + } - List ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); - int index = 0; - for (Object object : ruleList) { - if (object instanceof VariableDefinitionType) { - VariableDefinitionType variableDefinitionType = (VariableDefinitionType) object; - Map settings = new HashMap<>(); - settings.put("key", variableDefinitionType.getVariableId()); - JAXBElement attributeValueTypeElement = - (JAXBElement) variableDefinitionType.getExpression(); - if (attributeValueTypeElement != null) { - AttributeValueType attributeValueType = attributeValueTypeElement.getValue(); - settings.put("value", attributeValueType.getContent().get(0).toString()); + List ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); + int index = 0; + for (Object object : ruleList) { + if (object instanceof VariableDefinitionType) { + VariableDefinitionType variableDefinitionType = (VariableDefinitionType) object; + Map settings = new HashMap<>(); + settings.put("key", variableDefinitionType.getVariableId()); + JAXBElement attributeValueTypeElement = + (JAXBElement) 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 ("AAF".equalsIgnoreCase(((RuleType) object).getAdviceExpressions() + .getAdviceExpression().get(0).getAdviceId())) { + policyAdapter.setRuleProvider("AAF"); + break; + } else if (GUARD_YAML.equalsIgnoreCase(((RuleType) object).getAdviceExpressions() + .getAdviceExpression().get(0).getAdviceId())) { + policyAdapter.setRuleProvider(GUARD_YAML); + } else if (GUARD_BL_YAML.equalsIgnoreCase(((RuleType) object).getAdviceExpressions() + .getAdviceExpression().get(0).getAdviceId())) { + policyAdapter.setRuleProvider(GUARD_BL_YAML); + } else if (GUARD_MIN_MAX.equalsIgnoreCase(((RuleType) object).getAdviceExpressions() + .getAdviceExpression().get(0).getAdviceId())) { + policyAdapter.setRuleProvider(GUARD_MIN_MAX); } - 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 ("AAF".equalsIgnoreCase(((RuleType) object).getAdviceExpressions() - .getAdviceExpression().get(0).getAdviceId())) { - policyAdapter.setRuleProvider("AAF"); - break; - } else if ("GUARD_YAML".equalsIgnoreCase(((RuleType) object).getAdviceExpressions() - .getAdviceExpression().get(0).getAdviceId())) { - policyAdapter.setRuleProvider("GUARD_YAML"); - } else if ("GUARD_BL_YAML".equalsIgnoreCase(((RuleType) object).getAdviceExpressions() - .getAdviceExpression().get(0).getAdviceId())) { - 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 + && (GUARD_YAML.equals(policyAdapter.getRuleProvider()) + || (GUARD_BL_YAML.equals(policyAdapter.getRuleProvider())) + || (GUARD_MIN_MAX.equals(policyAdapter.getRuleProvider())))) { + YAMLParams yamlParams = new YAMLParams(); + for (int i = 0; i < attributeList.size(); i++) { + Map map = (Map) attributeList.get(i); + String key = map.get("key"); + if ("actor".equals(key)) { + yamlParams.setActor(map.get("value")); + } else if ("recipe".equals(key)) { + yamlParams.setRecipe(map.get("value")); + } else if ("target".equals(key)) { + yamlParams.setTargets(Arrays.asList(map.get("value").split("\\|"))); + } else if ("clname".equals(key)) { + yamlParams.setClname(map.get("value")); + } else if ("min".equals(key)) { + yamlParams.setMin(map.get("value")); + } else if ("max".equals(key)) { + yamlParams.setMax(map.get("value")); } - } 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 - && ("GUARD_YAML".equals(policyAdapter.getRuleProvider()) - || ("GUARD_BL_YAML".equals(policyAdapter.getRuleProvider())))) { - YAMLParams yamlParams = new YAMLParams(); - for (int i = 0; i < attributeList.size(); i++) { - Map map = (Map) 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 ("GUARD_BL_YAML".equals(policyAdapter.getRuleProvider())) { - 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); - if ("Use File Upload".equals(policyAdapter.getBlackListEntryType())) { - policyAdapter.setBlackListEntries(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()); - policyAdapter.setRuleAlgorithmschoices(new ArrayList()); - break; + 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 (GUARD_BL_YAML.equals(policyAdapter.getRuleProvider())) { + apply = (ApplyType) ((ApplyType) ((ApplyType) decisionApply.getExpression() + .get(0).getValue()).getExpression().get(1).getValue()).getExpression() + .get(2).getValue(); + List blackList = new ArrayList<>(); + for (JAXBElement attr : apply.getExpression()) { + blackList.add(((AttributeValueType) attr.getValue()) + .getContent().get(0).toString()); + } + yamlParams.setBlackList(blackList); + if ("Use File Upload".equals(policyAdapter.getBlackListEntryType())) { + policyAdapter.setBlackListEntries(blackList); } - // Populating Rule Algorithms starting from compound. - prePopulateDecisionCompoundRuleAlgorithm(index, decisionApply); - policyAdapter.setRuleAlgorithmschoices(ruleAlgorithmList); + } 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(':'))); } - } else if (policyAdapter.getRuleProvider() != null - && "Rainy_Day".equals(policyAdapter.getRuleProvider()) - && ((RuleType) object).getEffect().equals(EffectType.PERMIT)) { + policyAdapter.setYamlparams(yamlParams); + policyAdapter.setAttributes(new ArrayList()); + policyAdapter.setRuleAlgorithmschoices(new ArrayList()); + break; + } + // Populating Rule Algorithms starting from compound. + prePopulateDecisionCompoundRuleAlgorithm(index, decisionApply); + policyAdapter.setRuleAlgorithmschoices(ruleAlgorithmList); + } + } else if (policyAdapter.getRuleProvider() != null + && "Rainy_Day".equals(policyAdapter.getRuleProvider()) + && ((RuleType) object).getEffect().equals(EffectType.PERMIT)) { - TargetType ruleTarget = ((RuleType) object).getTarget(); - AdviceExpressionsType adviceExpression = ((RuleType) object).getAdviceExpressions(); + 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(); + 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); + prePopulateRainyDayTreatments(errorcode, treatment); - } - } } } - - rainydayParams.setTreatmentTableChoices(treatmentList); - policyAdapter.setRainyday(rainydayParams); - policyAdapter.setSettings(decisionList); } + rainydayParams.setTreatmentTableChoices(treatmentList); + policyAdapter.setRainyday(rainydayParams); + policyAdapter.setSettings(decisionList); } private void prePopulateRainyDayTreatments(String errorcode, String treatment) { @@ -367,7 +379,6 @@ public class DecisionPolicyController extends RestrictedBaseController { VariableReferenceType variableReference = (VariableReferenceType) jaxbDecisionTypes.get(0).getValue(); ruleMap.put("dynamicRuleAlgorithmField1", "S_" + variableReference.getVariableId()); - // Get from Attribute Value AttributeValueType actionConditionAttributeValue = (AttributeValueType) jaxbDecisionTypes.get(1).getValue(); String attributeValue = (String) actionConditionAttributeValue.getContent().get(0); @@ -392,36 +403,36 @@ public class DecisionPolicyController extends RestrictedBaseController { index++; } } - if (isCompoundRule) { - // As it's compound rule, Get the Apply types - for (JAXBElement jaxbElement : jaxbDecisionTypes) { - ApplyType innerDecisionApply = (ApplyType) jaxbElement.getValue(); - index = prePopulateDecisionCompoundRuleAlgorithm(index, innerDecisionApply); - } - // Populate combo box - if (policyLogger.isDebugEnabled()) { - policyLogger.debug("Prepopulating Compound rule algorithm: " + index); - } - Map rule = new HashMap<>(); - for (String key : PolicyController.getDropDownMap().keySet()) { - String keyValue = PolicyController.getDropDownMap().get(key); - if (keyValue.equals(decisionApply.getFunctionId())) { - rule.put("dynamicRuleAlgorithmCombo", key); - break; - } + if (! isCompoundRule) { + return index; + } + // As it's compound rule, Get the Apply types + for (JAXBElement jaxbElement : jaxbDecisionTypes) { + ApplyType innerDecisionApply = (ApplyType) jaxbElement.getValue(); + index = prePopulateDecisionCompoundRuleAlgorithm(index, innerDecisionApply); + } + // Populate combo box + if (policyLogger.isDebugEnabled()) { + policyLogger.debug("Prepopulating Compound rule algorithm: " + index); + } + Map rule = new HashMap<>(); + for (String key : PolicyController.getDropDownMap().keySet()) { + String keyValue = PolicyController.getDropDownMap().get(key); + if (keyValue.equals(decisionApply.getFunctionId())) { + rule.put("dynamicRuleAlgorithmCombo", key); + break; } - - rule.put("id", "A" + (index + 1)); - // Populate Key and values for Compound Rule - rule.put("dynamicRuleAlgorithmField1", "A" + (ruleAlgoirthmTracker.getLast() + 1)); - ruleAlgoirthmTracker.removeLast(); - rule.put("dynamicRuleAlgorithmField2", "A" + (ruleAlgoirthmTracker.getLast() + 1)); - ruleAlgoirthmTracker.removeLast(); - ruleAlgoirthmTracker.addLast(index); - ruleAlgorithmList.add(rule); - index++; } - return index; + rule.put("id", "A" + (index + 1)); + // Populate Key and values for Compound Rule + rule.put("dynamicRuleAlgorithmField1", "A" + (ruleAlgoirthmTracker.getLast() + 1)); + ruleAlgoirthmTracker.removeLast(); + rule.put("dynamicRuleAlgorithmField2", "A" + (ruleAlgoirthmTracker.getLast() + 1)); + ruleAlgoirthmTracker.removeLast(); + ruleAlgoirthmTracker.addLast(index); + ruleAlgorithmList.add(rule); + + return ++index; } }