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