import java.util.List;
import java.util.Map;
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
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;
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.ActionPolicyDict;
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;
protected Map<String, String> dropDownMap = new HashMap<>();
private static boolean isAttribute = false;
- private static synchronized boolean getAttribute () {
+ private synchronized static boolean getAttribute () {
return isAttribute;
}
- private static synchronized void setAttribute (boolean att) {
- isAttribute = att;
- }
public ActionPolicy() {
super();
}
@Override
- public Map<String, String> savePolicies() throws Exception {
+ public Map<String, String> savePolicies() throws PAPException {
Map<String, String> successMap = new HashMap<>();
if(isPolicyExists()){
//This is the method for preparing the policy for saving. We have broken it out
//separately because the fully configured policy is used for multiple things
@Override
- public boolean prepareToSave() throws Exception{
+ public boolean prepareToSave() throws PAPException{
if(isPreparedToSave()){
//we have already done this
if (policyAdapter.getData() != null) {
// Action body is optional so checking value provided or not
String comboDictValue = policyAdapter.getActionAttribute();
- String actionBody = getActionPolicyDict(comboDictValue).getBody();
+ String actionBody = policyAdapter.getActionBody();
+ isAttribute = false;
+
+ //if actionBody is null or empty then we know the ActionAttribute in the request does not exist in the dictionary
if(!(actionBody==null || "".equals(actionBody))){
saveActionBody(policyName, actionBody);
+ isAttribute = true;
} else {
if(!getAttribute()){
LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not find " + comboDictValue + " in the ActionPolicyDict table.");
AttributeValueType typeAttributeValue = new AttributeValueType();
typeAttributeValue.setDataType(STRING_DATATYPE);
- String actionDictType = getActionPolicyDict(comboDictValue).getType();
+ String actionDictType = policyAdapter.getActionDictType();
typeAttributeValue.getContent().add(actionDictType);
assignmentType.setExpression(new ObjectFactory().createAttributeValue(typeAttributeValue));
AttributeValueType actionURLAttributeValue = new AttributeValueType();
actionURLAttributeValue.setDataType(URI_DATATYPE);
- String actionDictUrl = getActionPolicyDict(comboDictValue).getUrl();
+ String actionDictUrl = policyAdapter.getActionDictUrl();
actionURLAttributeValue.getContent().add(actionDictUrl);
assignmentURL.setExpression(new ObjectFactory().createAttributeValue(actionURLAttributeValue));
AttributeValueType methodAttributeValue = new AttributeValueType();
methodAttributeValue.setDataType(STRING_DATATYPE);
- String actionDictMethod = getActionPolicyDict(comboDictValue).getMethod();
+ String actionDictMethod = policyAdapter.getActionDictMethod();
methodAttributeValue.getContent().add(actionDictMethod);
assignmentMethod.setExpression(new ObjectFactory().createAttributeValue(methodAttributeValue));
obligation.getAttributeAssignmentExpression().add(assignmentMethod);
// Add JSON_URL Assignment:
- String actionBody = getActionPolicyDict(comboDictValue).getBody();
+ String actionBody = policyAdapter.getActionBody();
if (actionBody != null) {
AttributeAssignmentExpressionType assignmentJsonURL = new AttributeAssignmentExpressionType();
assignmentJsonURL.setAttributeId(BODY_ATTRIBUTEID);
obligation.getAttributeAssignmentExpression().add(assignmentJsonURL);
}
- if(getActionPolicyDict(comboDictValue).getHeader() != null){
- String headerVal = getActionPolicyDict(comboDictValue).getHeader();
+ String headerVal = policyAdapter.getActionDictHeader();
+ if(headerVal != null){
if(headerVal != null && !headerVal.equals("")){
// parse it on : to get number of headers
String[] result = headerVal.split(":");
}
return dropDownMap;
}
-
- private ActionPolicyDict getActionPolicyDict(String attributeName){
- ActionPolicyDict retObj = new ActionPolicyDict();
- EntityManager em = XACMLPapServlet.getEmf().createEntityManager();
- Query getActionPolicyDicts = em.createNamedQuery("ActionPolicyDict.findAll");
- List<?> actionPolicyDicts = getActionPolicyDicts.getResultList();
-
- for (Object id : actionPolicyDicts) {
- ActionPolicyDict actionPolicy = (ActionPolicyDict) id;
- if(attributeName.equals(actionPolicy.getAttributeName())){
- setAttribute(true);
- retObj = actionPolicy;
- break;
- }
- }
- em.close();
- return retObj;
- }
@Override
public Object getCorrectPolicyDataObject() {