Sonar Fixes
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / components / ActionPolicy.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.pap.xacml.rest.components;
22
23 import java.io.BufferedWriter;
24 import java.io.File;
25 import java.io.FileWriter;
26 import java.io.IOException;
27 import java.nio.file.Path;
28 import java.nio.file.Paths;
29 import java.util.HashMap;
30 import java.util.LinkedList;
31 import java.util.List;
32 import java.util.Map;
33
34 import javax.persistence.EntityManager;
35 import javax.persistence.Query;
36
37 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
38 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
39 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType;
40 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType;
41 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
42 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
43 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType;
44 import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType;
45 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
46 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
47 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionType;
48 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionsType;
49 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
50 import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
51 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
52
53 import org.onap.policy.pap.xacml.rest.XACMLPapServlet;
54 import org.onap.policy.pap.xacml.rest.util.JPAUtils;
55 import org.onap.policy.rest.adapter.PolicyRestAdapter;
56 import org.onap.policy.rest.jpa.ActionPolicyDict;
57 import org.onap.policy.rest.jpa.Datatype;
58 import org.onap.policy.rest.jpa.FunctionDefinition;
59 import org.onap.policy.xacml.api.XACMLErrorConstants;
60
61 import com.att.research.xacml.api.pap.PAPException;
62
63 import org.onap.policy.common.logging.eelf.MessageCodes;
64 import org.onap.policy.common.logging.eelf.PolicyLogger;
65 import org.onap.policy.common.logging.flexlogger.FlexLogger; 
66 import org.onap.policy.common.logging.flexlogger.Logger; 
67
68 public class ActionPolicy extends Policy {
69         
70         /**
71          * ActionPolicy Fields
72          */
73         private static final Logger LOGGER = FlexLogger.getLogger(ActionPolicy.class);
74         
75         public static final String JSON_CONFIG = "JSON";
76         
77         public static final String PDP_ACTION = "PDP";
78         public static final String PEP_ACTION = "PEP";
79         public static final String TYPE_ACTION = "REST";
80
81         public static final String GET_METHOD = "GET";
82         public static final String PUT_METHOD = "PUT";
83         public static final String POST_METHOD = "POST";
84
85         public static final String PERFORMER_ATTRIBUTEID = "performer";
86         public static final String TYPE_ATTRIBUTEID = "type";
87         public static final String METHOD_ATTRIBUTEID = "method";
88         public static final String HEADERS_ATTRIBUTEID = "headers";
89         public static final String URL_ATTRIBUTEID = "url";
90         public static final String BODY_ATTRIBUTEID = "body";
91         
92         List<String> dynamicLabelRuleAlgorithms = new LinkedList<>();
93         List<String> dynamicFieldFunctionRuleAlgorithms = new LinkedList<>();
94         List<String> dynamicFieldOneRuleAlgorithms = new LinkedList<>();
95         List<String> dynamicFieldTwoRuleAlgorithms = new LinkedList<>();
96         
97         protected Map<String, String> dropDownMap = new HashMap<>();
98         
99         private static boolean isAttribute = false;
100         private synchronized static boolean getAttribute () {
101                 return isAttribute;
102
103         }
104         private static synchronized void setAttribute (boolean att) {
105                 isAttribute = att;
106         }
107         
108         public ActionPolicy() {
109                 super();
110         }
111         
112         public ActionPolicy(PolicyRestAdapter policyAdapter){
113                 this.policyAdapter = policyAdapter;
114         }
115         
116         @Override
117         public Map<String, String> savePolicies() throws PAPException {
118                 
119                 Map<String, String> successMap = new HashMap<>();
120                 if(isPolicyExists()){
121                         successMap.put("EXISTS", "This Policy already exist on the PAP");
122                         return successMap;
123                 }
124                 
125                 if(!ActionPolicy.getAttribute()) {
126                         successMap.put("invalidAttribute", "Action Attrbute was not in the database.");
127                         return successMap;
128                 }
129                 
130                 if(!isPreparedToSave()){
131                         //Prep and configure the policy for saving
132                         prepareToSave();
133                 }
134
135                 // Until here we prepared the data and here calling the method to create xml.
136                 Path newPolicyPath = null;
137                 newPolicyPath = Paths.get(policyAdapter.getNewFileName());
138                 successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject() );         
139                 return successMap;              
140         }
141         
142         //This is the method for preparing the policy for saving.  We have broken it out
143         //separately because the fully configured policy is used for multiple things
144         @Override
145         public boolean prepareToSave() throws PAPException{
146
147                 if(isPreparedToSave()){
148                         //we have already done this
149                         return true;
150                 }
151                 
152                 int version = 0;
153                 String policyID = policyAdapter.getPolicyID();
154                 version = policyAdapter.getHighestVersion();
155                 
156                 // Create the Instance for pojo, PolicyType object is used in marshalling.
157                 if (policyAdapter.getPolicyType().equals("Action")) {
158                         PolicyType policyConfig = new PolicyType();
159
160                         policyConfig.setVersion(Integer.toString(version));
161                         policyConfig.setPolicyId(policyID);
162                         policyConfig.setTarget(new TargetType());
163                         policyAdapter.setData(policyConfig);
164                 }
165                 
166                 policyName = policyAdapter.getNewFileName();
167                 
168                 if (policyAdapter.getData() != null) {
169                         // Action body is optional so checking value provided or not
170                         String comboDictValue = policyAdapter.getActionAttribute();
171                 String actionBody = getActionPolicyDict(comboDictValue).getBody();
172                         if(!(actionBody==null || "".equals(actionBody))){       
173                                 saveActionBody(policyName, actionBody);
174                         } else {
175                                 if(!getAttribute()){
176                                         LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not find " + comboDictValue + " in the ActionPolicyDict table.");
177                                         return false;
178                                 }
179                         }
180                         
181                         PolicyType actionPolicy = (PolicyType) policyAdapter.getData();
182                         actionPolicy.setDescription(policyAdapter.getPolicyDescription());
183                         actionPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
184
185                         AllOfType allOf = new AllOfType();
186                         
187                         Map<String, String> dynamicFieldComponentAttributes = policyAdapter.getDynamicFieldConfigAttributes();
188                         
189                         // If there is any dynamic field attributes create the matches here
190                         for (String keyField : dynamicFieldComponentAttributes.keySet()) {
191                                 String key = keyField;
192                                 String value = dynamicFieldComponentAttributes.get(key);
193                                 MatchType dynamicMatch = createDynamicMatch(key, value);
194                                 allOf.getMatch().add(dynamicMatch);
195                         }
196
197                         AnyOfType anyOf = new AnyOfType();
198                         anyOf.getAllOf().add(allOf);
199
200                         TargetType target = new TargetType();
201                         target.getAnyOf().add(anyOf);
202                         
203                         // Adding the target to the policy element
204                         actionPolicy.setTarget(target);
205                         
206                         RuleType rule = new RuleType();
207                         rule.setRuleId(policyAdapter.getRuleID());
208
209                         rule.setEffect(EffectType.PERMIT);
210                         rule.setTarget(new TargetType());
211                         
212                         dynamicLabelRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmLabels();
213                         dynamicFieldFunctionRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmCombo();
214                         dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1();
215                         dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2();
216                         //dropDownMap = policyAdapter.getDropDownMap();
217                         dropDownMap = createDropDownMap();
218                                                 
219                         // Rule attributes are optional and dynamic so check and add them to condition.
220                         if (dynamicLabelRuleAlgorithms != null && dynamicLabelRuleAlgorithms.size() > 0) {
221                                 boolean isCompound = false;
222                                 ConditionType condition = new ConditionType();
223                                 int index = dynamicFieldOneRuleAlgorithms.size() - 1;
224
225                                 for (String labelAttr : dynamicLabelRuleAlgorithms) {
226                                         // if the rule algorithm as a label means it is a compound
227                                         if (dynamicFieldOneRuleAlgorithms.get(index).toString().equals(labelAttr)) {
228                                                 ApplyType actionApply = new ApplyType();
229
230                                                 String selectedFunction = (String) dynamicFieldFunctionRuleAlgorithms.get(index).toString();
231                                                 String value1 = (String) dynamicFieldOneRuleAlgorithms.get(index).toString();
232                                                 String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString();
233                                                 actionApply.setFunctionId(dropDownMap.get(selectedFunction));
234                                                 actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1)));
235                                                 actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2)));
236                                                 condition.setExpression(new ObjectFactory().createApply(actionApply));
237                                                 isCompound = true;
238                                         }
239                                 }
240                                 // if rule algorithm not a compound
241                                 if (!isCompound) {
242                                         condition.setExpression(new ObjectFactory().createApply(getInnerActionApply(dynamicLabelRuleAlgorithms.get(index).toString())));
243                                 }
244                                 rule.setCondition(condition);
245                         }
246                         // set the obligations to rule
247                         rule.setObligationExpressions(getObligationExpressions());
248                         actionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
249                         policyAdapter.setPolicyData(actionPolicy);
250                 }  else {
251                         PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
252                 }       
253
254                 setPreparedToSave(true);
255                 return true;
256         }
257         
258         // Saving the json Configurations file if exists at server location for action policy.
259         private void saveActionBody(String policyName, String actionBodyData) {
260                 try {
261                         if(policyName.endsWith(".xml")){
262                                 policyName = policyName.replace(".xml", "");
263                         }
264                         File file = new File(ACTION_HOME+ File.separator + policyName + ".json");
265                         FileWriter fw = new FileWriter(file.getAbsoluteFile());
266                         BufferedWriter bw = new BufferedWriter(fw);
267                         bw.write(actionBodyData);
268                         bw.close();
269                         if (LOGGER.isInfoEnabled()) {
270                                 LOGGER.info("Action Body is succesfully saved at " + file.getAbsolutePath());
271                         }
272                 } catch (IOException e) {
273                         LOGGER.error("Exception Occured"+e);
274                 }
275         }
276         
277         // Data required for obligation part is setting here.
278         private ObligationExpressionsType getObligationExpressions() {
279                 ObligationExpressionsType obligations = new ObligationExpressionsType();
280
281                 ObligationExpressionType obligation = new ObligationExpressionType();
282         String comboDictValue = policyAdapter.getActionAttribute();
283                 obligation.setObligationId(comboDictValue);
284                 obligation.setFulfillOn(EffectType.PERMIT);
285
286                 // Add Action Assignment:
287                 AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
288                 assignment1.setAttributeId(PERFORMER_ATTRIBUTEID);
289                 assignment1.setCategory(CATEGORY_RECIPIENT_SUBJECT);
290
291                 AttributeValueType actionNameAttributeValue = new AttributeValueType();
292                 actionNameAttributeValue.setDataType(STRING_DATATYPE);
293                 actionNameAttributeValue.getContent().add(performer.get(policyAdapter.getActionPerformer()));
294
295                 assignment1.setExpression(new ObjectFactory().createAttributeValue(actionNameAttributeValue));
296                 obligation.getAttributeAssignmentExpression().add(assignment1);
297
298                 // Add Type Assignment:
299                 AttributeAssignmentExpressionType assignmentType = new AttributeAssignmentExpressionType();
300                 assignmentType.setAttributeId(TYPE_ATTRIBUTEID);
301                 assignmentType.setCategory(CATEGORY_RESOURCE);
302
303                 AttributeValueType typeAttributeValue = new AttributeValueType();
304                 typeAttributeValue.setDataType(STRING_DATATYPE);
305                 String actionDictType = getActionPolicyDict(comboDictValue).getType();
306                 typeAttributeValue.getContent().add(actionDictType);
307
308                 assignmentType.setExpression(new ObjectFactory().createAttributeValue(typeAttributeValue));
309                 obligation.getAttributeAssignmentExpression().add(assignmentType);
310
311                 // Add Rest_URL Assignment:
312                 AttributeAssignmentExpressionType assignmentURL = new AttributeAssignmentExpressionType();
313                 assignmentURL.setAttributeId(URL_ATTRIBUTEID);
314                 assignmentURL.setCategory(CATEGORY_RESOURCE);
315
316                 AttributeValueType actionURLAttributeValue = new AttributeValueType();
317                 actionURLAttributeValue.setDataType(URI_DATATYPE);
318                 String actionDictUrl = getActionPolicyDict(comboDictValue).getUrl();
319                 actionURLAttributeValue.getContent().add(actionDictUrl);
320
321                 assignmentURL.setExpression(new ObjectFactory().createAttributeValue(actionURLAttributeValue));
322                 obligation.getAttributeAssignmentExpression().add(assignmentURL);
323
324                 // Add Method Assignment:
325                 AttributeAssignmentExpressionType assignmentMethod = new AttributeAssignmentExpressionType();
326                 assignmentMethod.setAttributeId(METHOD_ATTRIBUTEID);
327                 assignmentMethod.setCategory(CATEGORY_RESOURCE);
328
329                 AttributeValueType methodAttributeValue = new AttributeValueType();
330                 methodAttributeValue.setDataType(STRING_DATATYPE);
331                 String actionDictMethod = getActionPolicyDict(comboDictValue).getMethod();
332                 methodAttributeValue.getContent().add(actionDictMethod);
333
334                 assignmentMethod.setExpression(new ObjectFactory().createAttributeValue(methodAttributeValue));
335                 obligation.getAttributeAssignmentExpression().add(assignmentMethod);
336
337                 // Add JSON_URL Assignment:
338                 String actionBody = getActionPolicyDict(comboDictValue).getBody();
339                 if (actionBody != null) {
340                         AttributeAssignmentExpressionType assignmentJsonURL = new AttributeAssignmentExpressionType();
341                         assignmentJsonURL.setAttributeId(BODY_ATTRIBUTEID);
342                         assignmentJsonURL.setCategory(CATEGORY_RESOURCE);
343
344                         AttributeValueType jsonURLAttributeValue = new AttributeValueType();
345                         jsonURLAttributeValue.setDataType(URI_DATATYPE);
346                         jsonURLAttributeValue.getContent().add(CONFIG_URL + "/Action/"  + policyName + ".json");
347
348                         assignmentJsonURL.setExpression(new ObjectFactory().createAttributeValue(jsonURLAttributeValue));
349                         obligation.getAttributeAssignmentExpression().add(assignmentJsonURL);
350                 }
351
352                 if(getActionPolicyDict(comboDictValue).getHeader() != null){
353                         String headerVal = getActionPolicyDict(comboDictValue).getHeader();
354                         if(headerVal != null && !headerVal.equals("")){
355                                 // parse it on : to get number of headers
356                                 String[] result = headerVal.split(":");
357                                 for (String eachString : result){
358                                         // parse each value on =
359                                         String[] textFieldVals = eachString.split("=");
360                                         obligation.getAttributeAssignmentExpression().add(addDynamicHeaders(textFieldVals[0], textFieldVals[1]));
361                                 }
362                         }
363
364                 }
365                         
366                 obligations.getObligationExpression().add(obligation);
367                 return obligations;
368         }
369
370         
371         // if compound setting the inner apply here
372         protected ApplyType getInnerActionApply(String value1Label) {
373                 ApplyType actionApply = new ApplyType();
374                 int index = 0;
375                 // check the index for the label.
376                 for (String labelAttr : dynamicLabelRuleAlgorithms) {
377                         if (labelAttr.equals(value1Label)) {
378                                 String value1 = dynamicFieldOneRuleAlgorithms.get(index).toString();
379                                 // check if the row contains label again
380                                 for (String labelValue : dynamicLabelRuleAlgorithms) {
381                                         if (labelValue.equals(value1)) {
382                                                 return getCompoundApply(index);
383                                         }
384                                 }
385
386                                 // Getting the values from the form.
387                                 String functionKey = dynamicFieldFunctionRuleAlgorithms.get(index).toString();
388                                 String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString();
389                                 actionApply.setFunctionId(dropDownMap.get(functionKey));
390                                 // if two text field are rule attributes.
391                                 if ((value1.contains(RULE_VARIABLE)) && (value2.contains(RULE_VARIABLE))) {
392                                         ApplyType innerActionApply1 = new ApplyType();
393                                         ApplyType innerActionApply2 = new ApplyType();
394                                         AttributeDesignatorType attributeDesignator1 = new AttributeDesignatorType();
395                                         AttributeDesignatorType attributeDesignator2 = new AttributeDesignatorType();
396                                         // If selected function is Integer function set integer functionID
397                                         if (functionKey.toLowerCase().contains("integer")) {
398                                                 innerActionApply1.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
399                                                 innerActionApply2.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
400                                                 attributeDesignator1.setDataType(INTEGER_DATATYPE);
401                                                 attributeDesignator2.setDataType(INTEGER_DATATYPE);
402                                         } else {
403                                                 // If selected function is not a Integer function
404                                                 // set String functionID
405                                                 innerActionApply1.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
406                                                 innerActionApply2.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
407                                                 attributeDesignator1.setDataType(STRING_DATATYPE);
408                                                 attributeDesignator2.setDataType(STRING_DATATYPE);
409                                         }
410                                         attributeDesignator1.setCategory(CATEGORY_RESOURCE);
411                                         attributeDesignator2.setCategory(CATEGORY_RESOURCE);
412
413                                         // Here set actual field values
414                                         attributeDesignator1.setAttributeId(value1.contains("resource:") ? value1.substring(9): value1.substring(8));
415                                         attributeDesignator2.setAttributeId(value1.contains("resource:") ? value1.substring(9): value1.substring(8));
416
417                                         innerActionApply1.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator1));
418                                         innerActionApply2.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator2));
419
420                                         actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply1));
421                                         actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply2));
422
423                                 } else {// if either of one text field is rule attribute.
424                                         ApplyType innerActionApply = new ApplyType();
425                                         AttributeDesignatorType attributeDesignator = new AttributeDesignatorType();
426                                         AttributeValueType actionConditionAttributeValue = new AttributeValueType();
427
428                                         if (functionKey.toLowerCase().contains("integer")) {
429                                                 innerActionApply.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
430                                                 actionConditionAttributeValue.setDataType(INTEGER_DATATYPE);
431                                                 attributeDesignator.setDataType(INTEGER_DATATYPE);
432                                         } else {
433                                                 innerActionApply.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
434                                                 actionConditionAttributeValue.setDataType(STRING_DATATYPE);
435                                                 attributeDesignator.setDataType(STRING_DATATYPE);
436                                         }
437
438                                         String attributeId = null;
439                                         String attributeValue = null;
440
441                                         // Find which textField has rule attribute and set it as
442                                         attributeId = value1;
443                                         attributeValue = value2;
444
445                                         if (attributeId != null) {
446                                                 attributeDesignator.setCategory(CATEGORY_RESOURCE);
447                                                 attributeDesignator.setAttributeId(attributeId);
448                                         }
449                                         actionConditionAttributeValue.getContent().add(attributeValue);
450                                         innerActionApply.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator));
451                                         // Decide the order of element based the values.
452                                         if (attributeId.equals(value1)) {
453                                                 actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply));
454                                                 actionApply.getExpression().add(new ObjectFactory().createAttributeValue(actionConditionAttributeValue));
455                                         } else {
456                                                 actionApply.getExpression().add(new ObjectFactory().createAttributeValue(actionConditionAttributeValue));
457                                                 actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply));
458                                         }
459                                 }
460                         }
461                         index++;
462                 }
463                 return actionApply;
464         }
465
466         // if the rule algorithm is multiple compound one setting the apply
467         protected ApplyType getCompoundApply(int index) {
468                 ApplyType actionApply = new ApplyType();
469                 String selectedFunction = dynamicFieldFunctionRuleAlgorithms.get(index).toString();
470                 String value1 = dynamicFieldOneRuleAlgorithms.get(index).toString();
471                 String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString();
472                 actionApply.setFunctionId(dropDownMap.get(selectedFunction));
473                 actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1)));
474                 actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2)));
475                 return actionApply;
476         }
477                 
478         // Adding the dynamic headers if any
479         private AttributeAssignmentExpressionType addDynamicHeaders(String header, String value) {
480                 AttributeAssignmentExpressionType assignmentHeaders = new AttributeAssignmentExpressionType();
481                 assignmentHeaders.setAttributeId("headers:" + header);
482                 assignmentHeaders.setCategory(CATEGORY_RESOURCE);
483
484                 AttributeValueType headersAttributeValue = new AttributeValueType();
485                 headersAttributeValue.setDataType(STRING_DATATYPE);
486                 headersAttributeValue.getContent().add(value);
487
488                 assignmentHeaders.setExpression(new ObjectFactory().createAttributeValue(headersAttributeValue));
489                 return assignmentHeaders;
490         }
491         
492         private Map<String,String> createDropDownMap(){
493                 JPAUtils jpaUtils = null;
494                 Map<String, String> dropDownMap = new HashMap<>();
495                 try {
496                         jpaUtils = JPAUtils.getJPAUtilsInstance(XACMLPapServlet.getEmf());
497                 } catch (Exception e) {
498                         LOGGER.error("Exception Occured"+e);
499                 }
500                 if(jpaUtils != null){
501                         Map<Datatype, List<FunctionDefinition>> functionMap = jpaUtils.getFunctionDatatypeMap();
502                         
503                         for (Datatype id : functionMap.keySet()) {
504                                 List<FunctionDefinition> functionDefinitions = (List<FunctionDefinition>) functionMap
505                                                 .get(id);
506                                 for (FunctionDefinition functionDef : functionDefinitions) {
507                                         dropDownMap.put(functionDef.getShortname(),functionDef.getXacmlid());
508                                 }
509                         }
510                 }
511                 return dropDownMap;
512         }
513         
514         private ActionPolicyDict getActionPolicyDict(String attributeName){
515                 ActionPolicyDict retObj = new ActionPolicyDict();
516                 EntityManager em = XACMLPapServlet.getEmf().createEntityManager();
517                 Query getActionPolicyDicts = em.createNamedQuery("ActionPolicyDict.findAll");   
518                 List<?> actionPolicyDicts = getActionPolicyDicts.getResultList();       
519                 
520                 for (Object id : actionPolicyDicts) {
521                         ActionPolicyDict actionPolicy = (ActionPolicyDict) id;
522                         if(attributeName.equals(actionPolicy.getAttributeName())){
523                                 setAttribute(true);
524                                 retObj = actionPolicy;
525                                 break;
526                         }
527                 }
528                 em.close();
529                 return retObj;
530         }
531
532         @Override
533         public Object getCorrectPolicyDataObject() {
534                 return policyAdapter.getPolicyData();
535         }
536
537 }