X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcomponents%2FDecisionPolicy.java;h=56c23ac2c6b354df0f0c5f949ed414e094df6ee4;hb=9bf8e18042746f52b96155bb2654dfb472f09e14;hp=22d2da311215422ba7bfd025981ee83fa57e6772;hpb=b2c2186295866511b3c989279599388aaacd0ba2;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java index 22d2da311..56c23ac2c 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -53,9 +53,8 @@ import org.onap.policy.controlloop.policy.guard.GuardPolicy; import org.onap.policy.controlloop.policy.guard.MatchParameters; import org.onap.policy.controlloop.policy.guard.builder.ControlLoopGuardBuilder; import org.onap.policy.pap.xacml.rest.XACMLPapServlet; -import org.onap.policy.pap.xacml.rest.util.JPAUtils; import org.onap.policy.rest.adapter.PolicyRestAdapter; -import org.onap.policy.rest.jpa.Datatype; +import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.DecisionSettings; import org.onap.policy.rest.jpa.FunctionDefinition; import org.onap.policy.utils.PolicyUtils; @@ -108,15 +107,15 @@ public class DecisionPolicy extends Policy { List dynamicFieldTwoRuleAlgorithms = new LinkedList<>(); List dataTypeList = new LinkedList<>(); - protected Map dropDownMap = new HashMap<>(); + private CommonClassDao commonClassDao; - public DecisionPolicy() { super(); } - public DecisionPolicy(PolicyRestAdapter policyAdapter){ + public DecisionPolicy(PolicyRestAdapter policyAdapter, CommonClassDao commonClassDao){ this.policyAdapter = policyAdapter; + this.commonClassDao = commonClassDao; } @Override @@ -419,7 +418,6 @@ public class DecisionPolicy extends Policy { dynamicFieldComboRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmCombo(); dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1(); dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2(); - dropDownMap = createDropDownMap(); if(policyAdapter.getRuleProvider()!=null && policyAdapter.getRuleProvider().equals(AAFPROVIDER)){ // Values for AAF Provider are here for XML Creation. @@ -494,7 +492,7 @@ public class DecisionPolicy extends Policy { String selectedFunction = dynamicFieldComboRuleAlgorithms.get(index); String value1 = dynamicFieldOneRuleAlgorithms.get(index); String value2 = dynamicFieldTwoRuleAlgorithms.get(index); - decisionApply.setFunctionId(dropDownMap.get(selectedFunction)); + decisionApply.setFunctionId(getFunctionDefinitionId(selectedFunction)); decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value1))); decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value2))); condition.setExpression(new ObjectFactory().createApply(decisionApply)); @@ -633,7 +631,7 @@ public class DecisionPolicy extends Policy { // Getting the values from the form. String functionKey = dynamicFieldComboRuleAlgorithms.get(index); String value2 = dynamicFieldTwoRuleAlgorithms.get(index); - decisionApply.setFunctionId(dropDownMap.get(functionKey)); + decisionApply.setFunctionId(getFunctionDefinitionId(functionKey)); // if two text field are rule attributes. if ((value1.contains(RULE_VARIABLE)) && (value2.contains(RULE_VARIABLE))) { ApplyType innerDecisionApply1 = new ApplyType(); @@ -721,7 +719,7 @@ public class DecisionPolicy extends Policy { String selectedFunction = dynamicFieldComboRuleAlgorithms.get(index); String value1 = dynamicFieldOneRuleAlgorithms.get(index); String value2 = dynamicFieldTwoRuleAlgorithms.get(index); - decisionApply.setFunctionId(dropDownMap.get(selectedFunction)); + decisionApply.setFunctionId(getFunctionDefinitionId(selectedFunction)); decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value1))); decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value2))); return decisionApply; @@ -760,24 +758,6 @@ public class DecisionPolicy extends Policy { dataTypeList.add(dataType); } - private Map createDropDownMap(){ - JPAUtils jpaUtils = null; - try { - jpaUtils = JPAUtils.getJPAUtilsInstance(XACMLPapServlet.getEmf()); - } catch (Exception e) { - LOGGER.error("Exception Occured"+e); - } - Map dropDownOptions = new HashMap<>(); - if(jpaUtils!=null){ - Map> functionMap = jpaUtils.getFunctionDatatypeMap(); - for (Map.Entry> map: functionMap.entrySet()) { - for (FunctionDefinition functionDef : map.getValue()) { - dropDownOptions.put(functionDef.getShortname(),functionDef.getXacmlid()); - } - } - } - return dropDownOptions; - } private String getDataType(String key) { @@ -800,4 +780,12 @@ public class DecisionPolicy extends Policy { return policyAdapter.getData(); } + public String getFunctionDefinitionId(String key){ + FunctionDefinition object = (FunctionDefinition) commonClassDao.getDataById(FunctionDefinition.class, "short_name", key); + if(object != null){ + return object.getXacmlid(); + } + return null; + } + }