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%2FActionPolicy.java;h=91530c7af89a2ad72f0b9edc08b9dca212bf3018;hb=9bf8e18042746f52b96155bb2654dfb472f09e14;hp=2e2fa0dd03f0a24c65985d3d0e6d7adf8dee734c;hpb=b2c2186295866511b3c989279599388aaacd0ba2;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java index 2e2fa0dd0..91530c7af 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.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. @@ -31,6 +31,17 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.onap.policy.common.logging.eelf.MessageCodes; +import org.onap.policy.common.logging.eelf.PolicyLogger; +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.dao.CommonClassDao; +import org.onap.policy.rest.jpa.FunctionDefinition; +import org.onap.policy.xacml.api.XACMLErrorConstants; + +import com.att.research.xacml.api.pap.PAPException; + 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.ApplyType; @@ -45,21 +56,7 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionsType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; - -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.jpa.FunctionDefinition; -import org.onap.policy.xacml.api.XACMLErrorConstants; - -import com.att.research.xacml.api.pap.PAPException; - -import org.onap.policy.common.logging.eelf.MessageCodes; -import org.onap.policy.common.logging.eelf.PolicyLogger; -import org.onap.policy.common.logging.flexlogger.FlexLogger; -import org.onap.policy.common.logging.flexlogger.Logger; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; public class ActionPolicy extends Policy { @@ -90,7 +87,9 @@ public class ActionPolicy extends Policy { List dynamicFieldOneRuleAlgorithms = new LinkedList<>(); List dynamicFieldTwoRuleAlgorithms = new LinkedList<>(); - protected Map dropDownMap = new HashMap<>(); + + + private CommonClassDao commonClassDao; private static boolean isAttribute = false; private synchronized static boolean getAttribute () { @@ -102,11 +101,12 @@ public class ActionPolicy extends Policy { super(); } - public ActionPolicy(PolicyRestAdapter policyAdapter){ + public ActionPolicy(PolicyRestAdapter policyAdapter, CommonClassDao commonClassDao){ this.policyAdapter = policyAdapter; + this.commonClassDao = commonClassDao; } - - @Override + + @Override public Map savePolicies() throws PAPException { Map successMap = new HashMap<>(); @@ -210,23 +210,22 @@ public class ActionPolicy extends Policy { dynamicFieldFunctionRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmCombo(); dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1(); dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2(); - dropDownMap = createDropDownMap(); // Rule attributes are optional and dynamic so check and add them to condition. - if (dynamicLabelRuleAlgorithms != null && dynamicLabelRuleAlgorithms.size() > 0) { + if (dynamicLabelRuleAlgorithms != null && !dynamicLabelRuleAlgorithms.isEmpty()) { boolean isCompound = false; ConditionType condition = new ConditionType(); int index = dynamicFieldOneRuleAlgorithms.size() - 1; for (String labelAttr : dynamicLabelRuleAlgorithms) { // if the rule algorithm as a label means it is a compound - if (dynamicFieldOneRuleAlgorithms.get(index).toString().equals(labelAttr)) { + if (dynamicFieldOneRuleAlgorithms.get(index).equals(labelAttr)) { ApplyType actionApply = new ApplyType(); - String selectedFunction = (String) dynamicFieldFunctionRuleAlgorithms.get(index).toString(); - String value1 = (String) dynamicFieldOneRuleAlgorithms.get(index).toString(); - String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString(); - actionApply.setFunctionId(dropDownMap.get(selectedFunction)); + String selectedFunction = dynamicFieldFunctionRuleAlgorithms.get(index).toString(); + String value1 = dynamicFieldOneRuleAlgorithms.get(index); + String value2 = dynamicFieldTwoRuleAlgorithms.get(index); + actionApply.setFunctionId(getFunctionDefinitionId(selectedFunction)); actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1))); actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2))); condition.setExpression(new ObjectFactory().createApply(actionApply)); @@ -381,9 +380,9 @@ public class ActionPolicy extends Policy { } // Getting the values from the form. - String functionKey = dynamicFieldFunctionRuleAlgorithms.get(index).toString(); - String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString(); - actionApply.setFunctionId(dropDownMap.get(functionKey)); + String functionKey = dynamicFieldFunctionRuleAlgorithms.get(index); + String value2 = dynamicFieldTwoRuleAlgorithms.get(index); + actionApply.setFunctionId(getFunctionDefinitionId(functionKey)); // if two text field are rule attributes. if ((value1.contains(RULE_VARIABLE)) && (value2.contains(RULE_VARIABLE))) { ApplyType innerActionApply1 = new ApplyType(); @@ -463,10 +462,10 @@ public class ActionPolicy extends Policy { // if the rule algorithm is multiple compound one setting the apply protected ApplyType getCompoundApply(int index) { ApplyType actionApply = new ApplyType(); - String selectedFunction = dynamicFieldFunctionRuleAlgorithms.get(index).toString(); - String value1 = dynamicFieldOneRuleAlgorithms.get(index).toString(); - String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString(); - actionApply.setFunctionId(dropDownMap.get(selectedFunction)); + String selectedFunction = dynamicFieldFunctionRuleAlgorithms.get(index); + String value1 = dynamicFieldOneRuleAlgorithms.get(index); + String value2 = dynamicFieldTwoRuleAlgorithms.get(index); + actionApply.setFunctionId(getFunctionDefinitionId(selectedFunction)); actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1))); actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2))); return actionApply; @@ -485,32 +484,18 @@ public class ActionPolicy extends Policy { assignmentHeaders.setExpression(new ObjectFactory().createAttributeValue(headersAttributeValue)); return assignmentHeaders; } - - private Map createDropDownMap(){ - JPAUtils jpaUtils = null; - Map dropDownMap = new HashMap<>(); - try { - jpaUtils = JPAUtils.getJPAUtilsInstance(XACMLPapServlet.getEmf()); - } catch (Exception e) { - LOGGER.error("Exception Occured"+e); - } - if(jpaUtils != null){ - Map> functionMap = jpaUtils.getFunctionDatatypeMap(); - - for (Datatype id : functionMap.keySet()) { - List functionDefinitions = (List) functionMap - .get(id); - for (FunctionDefinition functionDef : functionDefinitions) { - dropDownMap.put(functionDef.getShortname(),functionDef.getXacmlid()); - } - } - } - return dropDownMap; - } @Override public Object getCorrectPolicyDataObject() { return policyAdapter.getPolicyData(); } + + public String getFunctionDefinitionId(String key){ + FunctionDefinition object = (FunctionDefinition) commonClassDao.getDataById(FunctionDefinition.class, "short_name", key); + if(object != null){ + return object.getXacmlid(); + } + return null; + } } \ No newline at end of file