X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontroller%2FCreatePolicyController.java;h=a2cf2083463ecb17630722e211e891df0e8ce1e7;hb=1e61676b77dd09659027b8984f050df7e8538526;hp=af4f8cfc3a90ddf699ea40597186d7f9613733a2;hpb=f36e53a3637e1204a42491ec0eeed7b3c763f681;p=policy%2Fengine.git diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java index af4f8cfc3..a2cf20834 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java @@ -22,14 +22,11 @@ package org.onap.policy.controller; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; 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.AttributeDesignatorType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; @@ -80,58 +77,30 @@ public class CreatePolicyController extends RestrictedBaseController { policyAdapter.setPolicyDescription(description); // Get the target data under policy. TargetType target = policy.getTarget(); - if (target != null && target.getAnyOf() != null) { + // + // NOTE: target.getAnyOf() will NEVER return null + // + if (target != null) { // Under target we have AnyOFType - List anyOfList = target.getAnyOf(); - Iterator iterAnyOf = anyOfList.iterator(); - while (iterAnyOf.hasNext()) { - AnyOfType anyOf = iterAnyOf.next(); + for (AnyOfType anyOf : target.getAnyOf()) { // Under AnyOFType we have AllOFType - List allOfList = anyOf.getAllOf(); - if (allOfList == null) { - continue; - } - Iterator iterAllOf = allOfList.iterator(); + // + // NOTE: anyOf.getAllOf() will NEVER return null + // int index = 0; - while (iterAllOf.hasNext()) { - AllOfType allOf = iterAllOf.next(); + for (AllOfType allOf : anyOf.getAllOf()) { // Under AllOFType we have Match - List matchList = allOf.getMatch(); - if (matchList == null) { - continue; - } - Iterator iterMatch = matchList.iterator(); - while (iterMatch.hasNext()) { - MatchType match = iterMatch.next(); + // NOTE: allOf.getMatch() will NEVER be NULL + // + for (MatchType match : allOf.getMatch()) { // // Under the match we have attribute value and // attributeDesignator. So,finally down to the actual attribute. // - AttributeValueType attributeValue = match.getAttributeValue(); - String value = (String) attributeValue.getContent().get(0); - AttributeDesignatorType designator = match.getAttributeDesignator(); - String attributeId = designator.getAttributeId(); + String value = (String) match.getAttributeValue().getContent().get(0); + String attributeId = match.getAttributeDesignator().getAttributeId(); // First match in the target is OnapName, so set that value. - if ("ONAPName".equals(attributeId)) { - policyAdapter.setOnapName(value); - } - if ("RiskType".equals(attributeId)) { - policyAdapter.setRiskType(value); - } - if ("RiskLevel".equals(attributeId)) { - policyAdapter.setRiskLevel(value); - } - if ("guard".equals(attributeId)) { - policyAdapter.setGuard(value); - } - if ("TTLDate".equals(attributeId) && !value.contains("NA")) { - PolicyController controller = new PolicyController(); - String newDate = controller.convertDate(value); - policyAdapter.setTtlDate(newDate); - } - if ("ConfigName".equals(attributeId)) { - policyAdapter.setConfigName(value); - } + policyAdapter.setupUsingAttribute(attributeId, value); // After Onap and Config it is optional to have attributes, so // check weather dynamic values or there or not. if (index >= 7) { @@ -147,10 +116,10 @@ public class CreatePolicyController extends RestrictedBaseController { policyAdapter.setAttributes(attributeList); } List ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); - for (Object o : ruleList) { - if (o instanceof RuleType) { + for (Object object : ruleList) { + if (object instanceof RuleType) { // get the condition data under the rule for rule Algorithms. - policyAdapter.setRuleID(((RuleType) o).getRuleId()); + policyAdapter.setRuleID(((RuleType) object).getRuleId()); } } }