aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main
diff options
context:
space:
mode:
authorMichael Mokry <mm117s@att.com>2017-09-08 11:25:20 -0500
committerMichael Mokry <mm117s@att.com>2017-09-08 11:38:24 -0500
commitd9eb582ec7c95aaa4ebae06bb8e97140cc195697 (patch)
treeff16238fc99b08427d9ba4dc4f751cbd13b24d67 /ONAP-PAP-REST/src/main
parent24c6b1682bb59691f8d5e631b1074355b7d82a54 (diff)
New commit to add Junits to PAP-REST
Updated the previous commit to resolve merge conflicts from another pull request being merged before this one. Change-Id: I488246061e9b29c75ac8fe45c167ed7afa8db3b8 Issue-ID: POLICY-32 Signed-off-by: Michael Mokry <mm117s@att.com>
Diffstat (limited to 'ONAP-PAP-REST/src/main')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java43
1 files changed, 11 insertions, 32 deletions
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 ae17ebf67..1efe82794 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
@@ -31,9 +31,6 @@ import java.util.LinkedList;
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;
@@ -53,7 +50,6 @@ 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.ActionPolicyDict;
import org.onap.policy.rest.jpa.Datatype;
import org.onap.policy.rest.jpa.FunctionDefinition;
import org.onap.policy.xacml.api.XACMLErrorConstants;
@@ -101,9 +97,6 @@ public class ActionPolicy extends Policy {
return isAttribute;
}
- private static synchronized void setAttribute (boolean att) {
- isAttribute = att;
- }
public ActionPolicy() {
super();
@@ -168,9 +161,13 @@ public class ActionPolicy extends Policy {
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.");
@@ -302,7 +299,7 @@ public class ActionPolicy extends Policy {
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));
@@ -315,7 +312,7 @@ public class ActionPolicy extends Policy {
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));
@@ -328,14 +325,14 @@ public class ActionPolicy extends Policy {
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);
@@ -349,8 +346,8 @@ public class ActionPolicy extends Policy {
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(":");
@@ -510,24 +507,6 @@ public class ActionPolicy extends Policy {
}
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() {