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=d12cbb2d4b577275cd4a0fb99e6cd5f6850e344d;hp=d6a4e8285fbc780bdd0431dcee587159f8e21137;hb=f36e53a3637e1204a42491ec0eeed7b3c763f681;hpb=b86c95c99240e8ed0ef91932a70ebed313dbd60c 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 d6a4e8285..d12cbb2d4 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 @@ -7,9 +7,9 @@ * 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. @@ -83,7 +83,13 @@ public class DecisionPolicyController extends RestrictedBaseController { // This constructor is empty } - public void rawXACMLPolicy(PolicyRestAdapter policyAdapter, PolicyEntity entity) { + /** + * 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('.'))); @@ -94,6 +100,12 @@ public class DecisionPolicyController extends RestrictedBaseController { } } + /** + * prePopulateDecisionPolicyData. + * + * @param policyAdapter PolicyRestAdapter + * @param entity PolicyEntity + */ @SuppressWarnings("unchecked") public void prePopulateDecisionPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) { List attributeList = new ArrayList<>(); @@ -109,7 +121,7 @@ public class DecisionPolicyController extends RestrictedBaseController { } if (rawPolicyCheck) { - rawXACMLPolicy(policyAdapter, entity); + rawXacmlPolicy(policyAdapter, entity); } else { RainyDayParams rainydayParams = new RainyDayParams(); Object policyData = policyAdapter.getPolicyData(); @@ -143,45 +155,46 @@ public class DecisionPolicyController extends RestrictedBaseController { 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++; + if (allOfList == null) { + continue; + } + 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.setAttributes(attributeList); } } // Setting rainy day attributes to the parameters object if they exist