8478c73c7283844c2bb3a8d388a43d9862e9ee85
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalsdk.analytics.system.fusion.web;
39
40 import java.io.IOException;
41 import java.io.OutputStreamWriter;
42 import java.io.PrintWriter;
43 import java.io.StringWriter;
44 import java.io.Writer;
45 import java.lang.reflect.InvocationTargetException;
46 import java.lang.reflect.Method;
47 import java.util.ArrayList;
48 import java.util.Enumeration;
49 import java.util.HashMap;
50 import java.util.HashSet;
51 import java.util.Iterator;
52 import java.util.List;
53 import java.util.Map;
54 import java.util.Vector;
55
56 import javax.servlet.ServletContext;
57 import javax.servlet.http.HttpServletRequest;
58 import javax.servlet.http.HttpServletResponse;
59 import javax.servlet.http.HttpSession;
60
61 import org.onap.portalsdk.analytics.controller.Action;
62 import org.onap.portalsdk.analytics.controller.ErrorHandler;
63 import org.onap.portalsdk.analytics.controller.WizardSequence;
64 import org.onap.portalsdk.analytics.error.RaptorException;
65 import org.onap.portalsdk.analytics.error.RaptorRuntimeException;
66 import org.onap.portalsdk.analytics.error.ReportSQLException;
67 import org.onap.portalsdk.analytics.model.DataCache;
68 import org.onap.portalsdk.analytics.model.ReportHandler;
69 import org.onap.portalsdk.analytics.model.base.IdNameValue;
70 import org.onap.portalsdk.analytics.model.base.ReportUserRole;
71 import org.onap.portalsdk.analytics.model.definition.ReportDefinition;
72 import org.onap.portalsdk.analytics.model.definition.SecurityEntry;
73 import org.onap.portalsdk.analytics.model.definition.wizard.ColumnEditJSON;
74 import org.onap.portalsdk.analytics.model.definition.wizard.ColumnJSON;
75 import org.onap.portalsdk.analytics.model.definition.wizard.DefinitionJSON;
76 import org.onap.portalsdk.analytics.model.definition.wizard.FormEditJSON;
77 import org.onap.portalsdk.analytics.model.definition.wizard.IdNameBooleanJSON;
78 import org.onap.portalsdk.analytics.model.definition.wizard.ImportJSON;
79 import org.onap.portalsdk.analytics.model.definition.wizard.MessageJSON;
80 import org.onap.portalsdk.analytics.model.definition.wizard.NameBooleanJSON;
81 import org.onap.portalsdk.analytics.model.definition.wizard.QueryJSON;
82 import org.onap.portalsdk.analytics.model.definition.wizard.QueryResultJSON;
83 import org.onap.portalsdk.analytics.model.definition.wizard.RaptorResponse;
84 import org.onap.portalsdk.analytics.model.definition.wizard.SearchFieldJSON;
85 import org.onap.portalsdk.analytics.model.pdf.PdfReportHandler;
86 import org.onap.portalsdk.analytics.model.runtime.CategoryAxisJSON;
87 import org.onap.portalsdk.analytics.model.runtime.ChartJSON;
88 import org.onap.portalsdk.analytics.model.runtime.ErrorJSONRuntime;
89 import org.onap.portalsdk.analytics.model.runtime.FormField;
90 import org.onap.portalsdk.analytics.model.runtime.RangeAxisJSON;
91 import org.onap.portalsdk.analytics.model.runtime.ReportFormFields;
92 import org.onap.portalsdk.analytics.model.runtime.ReportRuntime;
93 import org.onap.portalsdk.analytics.system.AppUtils;
94 import org.onap.portalsdk.analytics.system.ConnectionUtils;
95 import org.onap.portalsdk.analytics.system.Globals;
96 import org.onap.portalsdk.analytics.util.AppConstants;
97 import org.onap.portalsdk.analytics.util.DataSet;
98 import org.onap.portalsdk.analytics.util.Utils;
99 import org.onap.portalsdk.analytics.util.XSSFilter;
100 import org.onap.portalsdk.analytics.view.ReportData;
101 import org.onap.portalsdk.analytics.xmlobj.DataColumnType;
102 import org.onap.portalsdk.analytics.xmlobj.FormFieldType;
103 import org.onap.portalsdk.analytics.xmlobj.ObjectFactory;
104 import org.onap.portalsdk.analytics.xmlobj.PredefinedValueList;
105 import org.onap.portalsdk.core.controller.RestrictedBaseController;
106 import org.onap.portalsdk.core.domain.User;
107 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
108 import org.onap.portalsdk.core.util.SecurityCodecUtil;
109 import org.onap.portalsdk.core.web.support.UserUtils;
110 import org.owasp.esapi.ESAPI;
111 import org.springframework.stereotype.Controller;
112 import org.springframework.web.bind.annotation.PathVariable;
113 import org.springframework.web.bind.annotation.RequestBody;
114 import org.springframework.web.bind.annotation.RequestMapping;
115 import org.springframework.web.bind.annotation.RequestMethod;
116 import org.springframework.web.bind.annotation.ResponseBody;
117
118 import com.fasterxml.jackson.databind.DeserializationFeature;
119 import com.fasterxml.jackson.databind.ObjectMapper;
120 import com.fasterxml.jackson.databind.SerializationFeature;
121
122 @Controller
123 @RequestMapping("/")
124 public class RaptorControllerAsync extends RestrictedBaseController {
125
126         private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RaptorControllerAsync.class);
127
128         private String viewName;
129
130         @RequestMapping(value = { "/raptor.htm" }, method = RequestMethod.GET)
131         public void RaptorSearch(HttpServletRequest request, HttpServletResponse response)
132                         throws IOException, RaptorException {
133
134                 viewName = "";
135                 String actionKey = nvl(request.getParameter(AppConstants.RI_ACTION), request.getParameter("action"));
136                 actionKey = nvl(actionKey, "report.run");
137
138                 HttpSession session = request.getSession();
139                 User user = UserUtils.getUserSession(request);
140
141                 if (actionKey.equals("report.download.excel2007.session") || actionKey.equals("report.download.csv.session")
142                                 || actionKey.equals("report.download.excel.session")
143                                 || actionKey.equals("report.download.pdf.session")) {
144                         if (session != null && user != null) {
145                                 ServletContext servletContext = request.getSession().getServletContext();
146                                 if (!Globals.isSystemInitialized()) {
147                                         Globals.initializeSystem(servletContext);
148                                 }
149                                 ReportRuntime rr = null;
150                                 ReportData rd = null;
151                                 String parent = "";
152                                 int parentFlag = 0;
153                                 if (!nvl(request.getParameter("parent"), "").equals("N"))
154                                         parent = nvl(request.getParameter("parent"), "");
155                                 if (parent.startsWith("parent_"))
156                                         parentFlag = 1;
157                                 if (parentFlag == 1) {
158                                         rr = (ReportRuntime) request.getSession().getAttribute(parent + "_rr");
159                                         rd = (ReportData) request.getSession().getAttribute(parent + "_rd");
160                                 }
161
162                                 boolean isEmbedded = false;
163                                 Object temp = request.getSession().getAttribute("isEmbedded");
164                                 if (temp != null) {
165                                         isEmbedded = (boolean) temp;
166                                 }
167                                 if (isEmbedded) {
168                                         String reportID = AppUtils.getRequestValue(request, AppConstants.RI_REPORT_ID);
169                                         if (rr == null)
170                                                 rr = (ReportRuntime) ((HashMap) request.getSession()
171                                                                 .getAttribute(AppConstants.EMBEDDED_REPORTRUNTIME_MAP)).get(reportID);
172                                         if (rd == null)
173                                                 rd = (ReportData) ((HashMap) request.getSession()
174                                                                 .getAttribute(AppConstants.EMBEDDED_REPORTDATA_MAP)).get(reportID);
175                                 } else {
176                                         if (rr == null)
177                                                 rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
178                                         if (rd == null)
179                                                 rd = (ReportData) request.getSession().getAttribute(AppConstants.RI_REPORT_DATA);
180                                 }
181                                 String user_id = AppUtils.getUserID(request);
182                                 int downloadLimit = 0;
183                                 if (rr != null)
184                                         downloadLimit = (rr.getMaxRowsInExcelDownload() > 0) ? rr.getMaxRowsInExcelDownload()
185                                                         : Globals.getDownloadLimit();
186                                 if (actionKey.equals("report.csv.download"))
187                                         downloadLimit = Globals.getCSVDownloadLimit();
188                                 String sql_whole = rr.getReportDataSQL(user_id, downloadLimit, request);
189                                 request.setAttribute(AppConstants.RI_REPORT_SQL_WHOLE, sql_whole);
190                                 try {
191                                         OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream());
192
193                                         if (actionKey.equals("report.download.pdf.session")) {
194                                                 new PdfReportHandler().createPdfFileContent(request, response, 3);
195                                         } else if (actionKey.equals("report.download.csv.session")) {
196                                                 (new ReportHandler()).createCSVFileContent(out, rd, rr, request, response);
197                                         } else if (actionKey.equals("report.download.excel.session")) {
198                                                 new ReportHandler().createExcelFileContent(out, rd, rr, request, response, user_id, 3); // 3
199                                                                                                                                                                                                                                 // whole
200                                         } else {
201
202                                                 new ReportHandler().createExcel2007FileContent(out, rd, rr, request, response, user_id, 3); // 3
203                                                                                                                                                                                                                                         // whole
204                                         }
205                                 } catch (Exception e) {
206                                         logger.error(EELFLoggerDelegate.errorLogger,
207                                                         "[Controller.processRequest]Invalid raptor action [" + actionKey + "].", e);
208                                 }
209                         } else {
210                                 response.sendRedirect("login.htm");
211                         }
212                 } else {
213                         if (session != null && user != null) {
214                                 Action action = null;
215                                 ServletContext servletContext = request.getSession().getServletContext();
216                                 if (!Globals.isSystemInitialized()) {
217                                         Globals.initializeSystem(servletContext);
218                                 }
219                                 try {
220                                         action = Globals.getRaptorActionMapping().getAction(actionKey);
221                                         if (action == null)
222                                                 throw new RaptorRuntimeException("Action not found");
223                                 } catch (RaptorException e) {
224                                         logger.error(EELFLoggerDelegate.errorLogger,
225                                                         "[Controller.processRequest]Invalid raptor action [" + actionKey + "].", e);
226
227                                         viewName = (new ErrorHandler()).processFatalErrorJSON(request,
228                                                         new RaptorRuntimeException("[Controller.processRequest]Invalid raptor action [" + actionKey
229                                                                         + "]. Exception: " + e.getMessage()));
230                                 }
231
232                                 try {
233                                         Class[] paramTypes = new Class[2];
234                                         paramTypes[0] = Class.forName("javax.servlet.http.HttpServletRequest");
235                                         paramTypes[1] = Class.forName("java.lang.String");
236
237                                         Class handlerClass = Class.forName(action.getControllerClass());
238                                         Object handler = handlerClass.newInstance();
239                                         Method handlerMethod = handlerClass.getMethod(action.getControllerMethod(), paramTypes);
240
241                                         Object[] paramValues = new Object[2];
242                                         paramValues[0] = request;
243                                         paramValues[1] = action.getJspName();
244                                         ;
245
246                                         viewName = (String) handlerMethod.invoke(handler, paramValues);
247                                         if (!actionKey.equals("chart.run"))
248                                                 response.setContentType("application/json");
249                                         else
250                                                 response.setContentType("text/html");
251
252                                 } catch (ClassNotFoundException e) {
253                                         logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action ["
254                                                         + actionKey + "]. ClassNotFoundException: " + e.getMessage()));
255                                         viewName = (new ErrorHandler()).processFatalErrorJSON(request,
256                                                         new RaptorRuntimeException(
257                                                                         "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
258                                                                                         + e.getMessage()));
259                                 } catch (IllegalAccessException e) {
260                                         logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action ["
261                                                         + actionKey + "]. IllegalAccessException: " + e.getMessage()));
262                                         viewName = (new ErrorHandler()).processFatalErrorJSON(request,
263                                                         new RaptorRuntimeException(
264                                                                         "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
265                                                                                         + e.getMessage()));
266                                 } catch (InstantiationException e) {
267                                         logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action ["
268                                                         + actionKey + "]. InstantiationException: " + e.getMessage()));
269                                         viewName = (new ErrorHandler()).processFatalErrorJSON(request,
270                                                         new RaptorRuntimeException(
271                                                                         "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
272                                                                                         + e.getMessage()));
273                                 } catch (NoSuchMethodException e) {
274                                         logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action ["
275                                                         + actionKey + "]. NoSuchMethodException: " + e.getMessage()));
276                                         viewName = (new ErrorHandler()).processFatalErrorJSON(request,
277                                                         new RaptorRuntimeException(
278                                                                         "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
279                                                                                         + e.getMessage()));
280                                 } catch (InvocationTargetException e) {
281                                         logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action ["
282                                                         + actionKey + "]. InvocationTargetException: " + e.getMessage()));
283                                         viewName = (new ErrorHandler()).processFatalErrorJSON(request,
284                                                         new RaptorRuntimeException(
285                                                                         "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
286                                                                                         + e.getMessage()));
287                                 } finally {
288                                         PrintWriter out = response.getWriter();
289                                         out.write(viewName);
290                                 }
291                         } else {
292                                 PrintWriter out = response.getWriter();
293                                 out.write("session has timed out for user");
294                         }
295
296                 }
297         }
298
299         @RequestMapping(value = "/report/wizard/list_columns", method = RequestMethod.GET, produces = "application/json")
300         public @ResponseBody ArrayList<ColumnJSON> listColumns(HttpServletRequest request, HttpServletResponse response)
301                         throws IOException, RaptorException {
302                 ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
303                 List<DataColumnType> reportColumnList = rdef.getAllColumns();
304                 ArrayList<ColumnJSON> listJSON = new ArrayList<ColumnJSON>();
305                 ColumnJSON columnJSON = new ColumnJSON();
306
307                 for (DataColumnType reportColumnType : reportColumnList) {
308                         columnJSON = new ColumnJSON();
309                         columnJSON.setId(reportColumnType.getColId());
310                         columnJSON.setName(reportColumnType.getColName());
311                         listJSON.add(columnJSON);
312                 }
313                 return listJSON;
314         }
315
316         @RequestMapping(value = "/report/wizard/list_drilldown_reports", method = RequestMethod.GET, produces = "application/json")
317         public @ResponseBody ArrayList<ColumnJSON> list_drilldown_reports(HttpServletRequest request,
318                         HttpServletResponse response) throws IOException, RaptorException {
319                 ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
320                 Vector<IdNameValue> publicReportIdNames = DataCache.getPublicReportIdNames();
321                 Vector groupReportIdNames = DataCache.getGroupAccessibleReportIdNames(AppUtils.getUserID(request),
322                                 AppUtils.getUserRoles(request));
323                 Vector privateReportIdNames = DataCache.getPrivateAccessibleReportIdNames(AppUtils.getUserID(request),
324                                 AppUtils.getUserRoles(request));
325
326                 ArrayList<ColumnJSON> listJSON = new ArrayList<ColumnJSON>();
327                 ColumnJSON columnJSON = new ColumnJSON();
328
329                 ServletContext servletContext = request.getSession().getServletContext();
330                 if (!Globals.isSystemInitialized()) {
331                         Globals.initializeSystem(servletContext);
332                 }
333
334                 for (int i = 0; i < publicReportIdNames.size(); i++) {
335                         IdNameValue reportIdName = (IdNameValue) publicReportIdNames.get(i);
336                         columnJSON = new ColumnJSON();
337                         columnJSON.setId(reportIdName.getId());
338                         columnJSON.setName("Public Report: " + reportIdName.getName());
339                         if (!rdef.getReportID().equals(reportIdName.getId()))
340                                 listJSON.add(columnJSON);
341                 }
342
343                 for (int i = 0; i < groupReportIdNames.size(); i++) {
344                         IdNameValue reportIdName = (IdNameValue) groupReportIdNames.get(i);
345                         columnJSON = new ColumnJSON();
346                         columnJSON.setId(reportIdName.getId());
347                         columnJSON.setName("Group Report: " + reportIdName.getName());
348                         if (!rdef.getReportID().equals(reportIdName.getId()))
349                                 listJSON.add(columnJSON);
350                 }
351
352                 for (int i = 0; i < privateReportIdNames.size(); i++) {
353                         IdNameValue reportIdName = (IdNameValue) privateReportIdNames.get(i);
354                         columnJSON = new ColumnJSON();
355                         columnJSON.setId(reportIdName.getId());
356                         columnJSON.setName("Private Report: " + reportIdName.getName());
357                         if (!rdef.getReportID().equals(reportIdName.getId()))
358                                 listJSON.add(columnJSON);
359                 }
360
361                 return listJSON;
362         }
363
364         @RequestMapping(value = "/report/wizard/list_formfields", method = RequestMethod.GET, produces = "application/json")
365         public @ResponseBody ArrayList<SearchFieldJSON> listFormFields(HttpServletRequest request,
366                         HttpServletResponse response) throws IOException, RaptorException {
367                 ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
368                 ArrayList<SearchFieldJSON> listJSON = new ArrayList<SearchFieldJSON>();
369                 SearchFieldJSON fieldJSON = new SearchFieldJSON();
370                 if (rdef.getFormFieldList() != null) {
371                         for (Iterator iter = rdef.getFormFieldList().getFormField().iterator(); iter.hasNext();) {
372                                 fieldJSON = new SearchFieldJSON();
373                                 FormFieldType fft = (FormFieldType) iter.next();
374                                 String fieldId = fft.getFieldId();
375                                 String fieldDisplay = fft.getFieldName();
376                                 fieldJSON.setId(fieldId);
377                                 fieldJSON.setName(fieldDisplay);
378                                 listJSON.add(fieldJSON);
379                         }
380                 }
381
382                 return listJSON;
383         }
384
385         @RequestMapping(value = "/report/wizard/list_child_report_col/{reportID}", method = RequestMethod.GET, produces = "application/json")
386         public @ResponseBody ArrayList<ColumnJSON> listChildReportCols(@PathVariable("reportID") String reportID,
387                         HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException {
388                 ReportRuntime ddRr = (new ReportHandler()).loadReportRuntime(request, reportID, false);
389
390                 List<DataColumnType> reportColumnList = ddRr.getAllColumns();
391                 ArrayList<ColumnJSON> listJSON = new ArrayList<ColumnJSON>();
392                 ColumnJSON columnJSON = new ColumnJSON();
393
394                 for (DataColumnType reportColumnType : reportColumnList) {
395                         columnJSON = new ColumnJSON();
396                         columnJSON.setId(reportColumnType.getColId());
397                         columnJSON.setName(reportColumnType.getColName());
398                         listJSON.add(columnJSON);
399                 }
400                 return listJSON;
401         }
402
403         @RequestMapping(value = "/report/wizard/list_child_report_ff/{reportID}", method = RequestMethod.GET, produces = "application/json")
404         public @ResponseBody ArrayList<SearchFieldJSON> listChildReportFormFields(@PathVariable("reportID") String reportID,
405                         HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException {
406                 ReportRuntime ddRr = (new ReportHandler()).loadReportRuntime(request, reportID, false);
407                 ArrayList<SearchFieldJSON> listJSON = new ArrayList<SearchFieldJSON>();
408                 SearchFieldJSON fieldJSON = new SearchFieldJSON();
409
410                 ReportFormFields ddReportFormFields = ddRr.getReportFormFields();
411                 if (ddReportFormFields != null) {
412                         for (ddReportFormFields.resetNext(); ddReportFormFields.hasNext();) {
413                                 FormField ff = ddReportFormFields.getNext();
414                                 if (!ff.getFieldType().equals(FormField.FFT_BLANK)) {
415                                         fieldJSON = new SearchFieldJSON();
416                                         fieldJSON.setId(ff.getFieldName());
417                                         fieldJSON.setName(ff.getFieldDisplayName());
418                                         listJSON.add(fieldJSON);
419                                 }
420                         }
421                 }
422                 return listJSON;
423         }
424
425         @RequestMapping(value = "report/wizard/copy_report/{reportID}", method = RequestMethod.GET, produces = "application/json")
426         public @ResponseBody MessageJSON copyReport(@PathVariable("reportID") String reportID, HttpServletRequest request,
427                         HttpServletResponse response) throws IOException, RaptorException {
428                 MessageJSON messageJSON = new MessageJSON();
429                 try {
430
431                         ReportHandler rh = new ReportHandler();
432                         ReportDefinition rdef = rh.loadReportDefinition(request, reportID);
433                         rdef.setAsCopy(request);
434                         request.getSession().setAttribute(AppConstants.SI_REPORT_DEFINITION, rdef);
435                         messageJSON.setMessage("Success- Report Copied.");
436                         messageJSON.setAnyStacktrace(rdef.getReportID() + " is Modified and added to session and DB.");
437
438                 } catch (RaptorException e) {
439                         request.setAttribute("error_extra_msg", "While copying report " + reportID);
440                         messageJSON.setMessage("Failed - While copying report " + reportID);
441                         messageJSON.setAnyStacktrace(getStackTrace(e));
442                         logger.debug(EELFLoggerDelegate.debugLogger,
443                                         ("[Controller.processRequest]Invalid raptor action [copyReport]. RaptorException: "
444                                                         + e.getMessage()));
445                         return messageJSON;
446                 }
447
448                 return messageJSON;
449         }
450
451         @RequestMapping(value = "report/wizard/import_report", method = RequestMethod.POST, consumes = "application/json")
452         public @ResponseBody MessageJSON importReport(@RequestBody ImportJSON importJSON, HttpServletRequest request,
453                         HttpServletResponse response) throws IOException, RaptorException {
454                 MessageJSON messageJSON = new MessageJSON();
455                 try {
456                         String reportXML = importJSON.getReportXML();
457
458                         ReportHandler rh = new ReportHandler();
459                         ReportDefinition rdef = rh.createReportDefinition(request, "-1", reportXML);
460                         rdef.updateReportDefType();
461                         rdef.generateWizardSequence(request);
462                         rdef.setReportName("Import: " + rdef.getReportName());
463                         rdef.clearAllDrillDowns();
464
465                         request.getSession().setAttribute(AppConstants.SI_REPORT_DEFINITION, rdef);
466
467                         messageJSON.setMessage("Success- Report imported.");
468                         messageJSON.setAnyStacktrace(rdef.getReportID() + " is Modified and added to session and DB.");
469
470                 } catch (RaptorException e) {
471                         request.setAttribute("error_extra_msg", "Unable to parse XML. Nested error: ");
472                         messageJSON.setMessage("Unable to parse XML. Nested error: ");
473                         messageJSON.setAnyStacktrace(getStackTrace(e));
474
475                         return messageJSON;
476                 }
477
478                 return messageJSON;
479
480         }
481
482         @RequestMapping(value = "report/wizard/save_formfield_tab_data", method = RequestMethod.POST)
483         public @ResponseBody MessageJSON saveFFTabWiseData(@RequestBody FormEditJSON formEditJSON,
484                         HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException {
485                 ReportDefinition rdef = null;
486                 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
487
488                 MessageJSON messageJSON = new MessageJSON();
489                 try {
490                         if (rdef != null) {
491
492                                 String fieldId = formEditJSON.getFieldId();
493
494                                 if (rdef.getFormFieldList() != null) {
495                                         for (FormFieldType fft : rdef.getFormFieldList().getFormField()) {
496                                                 if (fft.getFieldId().equals(fieldId)) {
497                                                         fft.setFieldName(formEditJSON.getFieldName());
498                                                         fft.setFieldType(formEditJSON.getFieldType());
499                                                         fft.setVisible(formEditJSON.isVisible() ? "Y" : "N");
500                                                         fft.setDefaultValue(formEditJSON.getDefaultValue());
501                                                         fft.setFieldDefaultSQL(formEditJSON.getFieldDefaultSQL());
502                                                         fft.setFieldSQL(formEditJSON.getFieldSQL());
503                                                         fft.setValidationType(formEditJSON.getValidationType());
504
505                                                         // clear predefined value
506                                                         if (fft.getPredefinedValueList() != null) {
507                                                                 for (Iterator<String> iter = fft.getPredefinedValueList().getPredefinedValue()
508                                                                                 .iterator(); iter.hasNext();)
509                                                                         iter.remove();
510                                                         }
511
512                                                         List<IdNameBooleanJSON> predefList = formEditJSON.getPredefinedValueList();
513                                                         if (predefList != null && predefList.size() > 0) {
514                                                                 for (IdNameBooleanJSON item : predefList) {
515                                                                         PredefinedValueList predefinedValueList = new ObjectFactory()
516                                                                                         .createPredefinedValueList();
517                                                                         fft.setPredefinedValueList(predefinedValueList);
518                                                                         fft.getPredefinedValueList().getPredefinedValue().add(item.getId());
519                                                                 }
520                                                         }
521
522                                                 }
523                                         }
524                                 }
525
526                                 persistReportDefinition(request, rdef);
527                                 messageJSON.setMessage("Success formfield Details of given report is saved in session.");
528                                 messageJSON.setAnyStacktrace(rdef.getReportID() + " is Modified and added to session and DB.");
529
530                         } else {
531                                 messageJSON.setMessage("Report Definition is not in session");
532                                 messageJSON.setAnyStacktrace("Report Definition is not in session");
533
534                         }
535                 } catch (Exception ex) {
536                         messageJSON.setMessage("Error occured while formfield details Tab");
537                         messageJSON.setAnyStacktrace(getStackTrace(ex));
538                         return messageJSON;
539                 }
540
541                 return messageJSON;
542         }
543
544         @RequestMapping(value = "report/wizard/save_col_tab_data", method = RequestMethod.POST)
545         public @ResponseBody MessageJSON saveColTabWiseData(@RequestBody ColumnEditJSON columnEditJSON,
546                         HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException {
547                 ReportDefinition rdef = null;
548                 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
549
550                 MessageJSON messageJSON = new MessageJSON();
551
552                 try {
553                         if (rdef != null) {
554                                 String colId = columnEditJSON.getColId();
555                                 List<DataColumnType> reportColumnList = rdef.getAllColumns();
556
557                                 for (DataColumnType reportColumnType : reportColumnList) {
558                                         // columnJSON = new ColumnJSON();
559                                         if (reportColumnType.getColId().equals(colId)) {
560                                                 reportColumnType.setColName(columnEditJSON.getColName());
561                                                 reportColumnType.setDisplayAlignment(columnEditJSON.getDisplayAlignment());
562                                                 reportColumnType.setDisplayHeaderAlignment(columnEditJSON.getDisplayHeaderAlignment());
563                                                 reportColumnType.setIsSortable(columnEditJSON.isSortable());
564                                                 reportColumnType.setVisible(columnEditJSON.isVisible());
565                                                 reportColumnType.setDrillDownURL(columnEditJSON.getDrilldownURL());
566                                                 reportColumnType.setDrillDownParams(columnEditJSON.getDrilldownParams());
567                                                 reportColumnType.setDrillDownType(columnEditJSON.getDrilldownType());
568
569                                         }
570
571                                 }
572                                 persistReportDefinition(request, rdef);
573                                 messageJSON.setMessage("Success Column Details of given report is saved in session.");
574                                 messageJSON.setAnyStacktrace(rdef.getReportID() + " is Modified and added to session and DB.");
575
576                         } else {
577                                 messageJSON.setMessage("Report Definition is not in session");
578                                 messageJSON.setAnyStacktrace("");
579
580                         }
581                 } catch (Exception ex) {
582                         messageJSON.setMessage("Error occured while saving column details Tab");
583                         messageJSON.setAnyStacktrace(getStackTrace(ex));
584
585                         return messageJSON;
586                 }
587
588                 return messageJSON;
589         }
590
591         @RequestMapping(value = "report/wizard/save_def_tab_data/{id}", method = RequestMethod.POST)
592         public @ResponseBody MessageJSON saveDefTabWiseData(@PathVariable("id") String id,
593                         @RequestBody DefinitionJSON definitionJSON, HttpServletRequest request, HttpServletResponse response)
594                         throws IOException, RaptorException {
595                 ReportDefinition rdef = null;
596                 ReportRuntime rr = null;
597                 boolean newReport = false;
598                 MessageJSON messageJSON = new MessageJSON();
599
600                 try {
601                         if (id.equals("InSession")) {
602                                 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
603                                 newReport = false;
604
605                         } else if (id.equals("Create")) {
606                                 removeVariablesFromSession(request);
607                                 rdef = (new ReportHandler()).loadReportDefinition(request, "-1");
608                                 newReport = true;
609                                 System.out.println("&&&&&&&&&&&&&&&&&&&&&& CHECK Report Type "
610                                                 + (AppUtils.nvl(rdef.getReportType()).length() <= 0));
611                                 if (AppUtils.nvl(rdef.getReportType()).length() <= 0) {
612                                         rdef.setReportType(AppConstants.RT_LINEAR);
613                                         System.out.println("&&&&&&&&&&&&&&&&&&&&&& ADDED Report Type in session ");
614                                 }
615
616                         } else if (AppUtils.nvl(id).length() > 0) {
617                                 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
618                                 rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
619
620                                 if (rdef != null && !rdef.getReportID().equals(id)) {
621                                         request.getSession().removeAttribute(AppConstants.SI_REPORT_DEFINITION);
622                                         removeVariablesFromSession(request);
623                                         rdef = (new ReportHandler()).loadReportDefinition(request, id);
624                                 } else if (rr != null && !rr.getReportID().equals(id)) {
625                                         request.getSession().removeAttribute(AppConstants.SI_REPORT_RUNTIME);
626                                         removeVariablesFromSession(request);
627                                         rdef = (new ReportHandler()).loadReportDefinition(request, id);
628                                 } else if (rdef == null) {
629                                         rdef = (new ReportHandler()).loadReportDefinition(request, id);
630                                 }
631                                 newReport = false;
632
633                         } else {
634                                 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
635                                 newReport = true;
636                         }
637                         // }
638
639                         if (rdef != null) {
640                                 String reportName = definitionJSON.getReportName();
641                                 String errorString = "";
642                                 if (AppUtils.nvl(reportName).length() <= 0)
643                                         errorString = "ReportName cannot be null;";
644                                 rdef.setReportName(reportName);
645
646                                 String reportDescr = definitionJSON.getReportDescr();
647                                 rdef.setReportDescr(reportDescr);
648
649                                 String formHelpText = definitionJSON.getFormHelpText();
650                                 rdef.setFormHelpText(formHelpText);
651
652                                 Integer pageSize = definitionJSON.getPageSize();
653                                 rdef.setPageSize(pageSize);
654
655                                 List<IdNameBooleanJSON> menuIds = definitionJSON.getDisplayArea();
656                                 for (IdNameBooleanJSON menuId : menuIds) {
657                                         if (menuId.isSelected()) {
658                                                 rdef.setMenuID(menuId.getName());
659                                         }
660
661                                 }
662
663                                 Boolean hideFormFieldsAfterRun = definitionJSON.getHideFormFieldsAfterRun();
664                                 rdef.setHideFormFieldAfterRun(hideFormFieldsAfterRun);
665                                 Integer maxRowsInExcelCSVDownload = definitionJSON.getMaxRowsInExcelCSVDownload();
666                                 rdef.setMaxRowsInExcelDownload(maxRowsInExcelCSVDownload);
667                                 Integer frozenColumns = definitionJSON.getFrozenColumns();
668                                 rdef.setFrozenColumns(frozenColumns);
669                                 String dataGridAlign = definitionJSON.getDataGridAlign();
670                                 rdef.setDataGridAlign(dataGridAlign);
671                                 String emptyMessage = definitionJSON.getEmptyMessage();
672                                 rdef.setEmptyMessage(emptyMessage);
673                                 String dataContainerHeight = definitionJSON.getDataContainerHeight();
674                                 rdef.setDataContainerHeight(dataContainerHeight);
675                                 String dataContainerWidth = definitionJSON.getDataContainerWidth();
676                                 rdef.setDataContainerWidth(dataContainerWidth);
677                                 boolean runtimeColSortDisabled = definitionJSON.getRuntimeColSortDisabled();
678                                 rdef.setRuntimeColSortDisabled(runtimeColSortDisabled);
679                                 Integer numFormCols = definitionJSON.getNumFormCols();
680                                 rdef.setNumFormCols(Integer.toString(numFormCols));
681                                 String reportTitle = definitionJSON.getReportTitle();
682                                 rdef.setReportTitle(reportTitle);
683                                 String reportSubTitle = definitionJSON.getReportSubTitle();
684                                 rdef.setReportSubTitle(reportSubTitle);
685
686                                 List<NameBooleanJSON> displayOptions = definitionJSON.getDisplayOptions();
687                                 StringBuffer displayOptionStr = new StringBuffer("NNNNNNN");
688                                 for (NameBooleanJSON displayOption : displayOptions) {
689                                         if (displayOption.isSelected()) {
690                                                 if (displayOption.getName().equals("HideFormFields")) {
691                                                         displayOptionStr.setCharAt(0, 'Y');
692                                                 } else if (displayOption.getName().equals("HideChart")) {
693                                                         displayOptionStr.setCharAt(1, 'Y');
694                                                 } else if (displayOption.getName().equals("HideReportData")) {
695                                                         displayOptionStr.setCharAt(2, 'Y');
696                                                 } else if (displayOption.getName().equals("HideExcel")) {
697                                                         displayOptionStr.setCharAt(5, 'Y');
698                                                 } else if (displayOption.getName().equals("HidePdf")) {
699                                                         displayOptionStr.setCharAt(6, 'Y');
700                                                 }
701                                         }
702
703                                 }
704
705                                 rdef.setDisplayOptions(displayOptionStr.toString());
706                         }
707                         if (id.equals("Create")) {
708                                 rdef.persistReport(request);
709                         } else
710                                 persistReportDefinition(request, rdef);
711                         messageJSON.setMessage("Success Definition of given report is saved in session.");
712                         messageJSON.setAnyStacktrace((newReport ? " New Report info is added to Session "
713                                         : rdef.getReportID() + " is Modified and added to session and DB."));
714
715                 } catch (Exception ex) {
716                         messageJSON.setMessage("Error occured while saving definition Tab");
717                         messageJSON.setAnyStacktrace(getStackTrace(ex));
718                         logger.error(EELFLoggerDelegate.errorLogger,
719                                         "[Controller.processRequest]Invalid raptor action [retrieveTabWiseData].", ex);
720                         return messageJSON;
721                 }
722
723                 return messageJSON;
724         }
725
726         @RequestMapping(value = { "/report/wizard/retrieve_form_tab_wise_data/{id}",
727                         "/report/wizard/retrieve_form_tab_wise_data/{id}/{action}" }, method = RequestMethod.GET)
728         public @ResponseBody FormEditJSON retrieveFormTabWiseData(@PathVariable Map<String, String> pathVariables,
729                         HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException {
730                 ReportDefinition rdef = null;
731                 String id = "";
732                 String action = "";
733                 String detailId = "";
734                 FormEditJSON wizardJSON = new FormEditJSON();
735                 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
736
737                 if (pathVariables.containsKey("id")) {
738                         id = pathVariables.get("id");
739                 }
740                 if (pathVariables.containsKey("action")) {
741                         action = pathVariables.get("action");
742                 }
743
744                 ServletContext servletContext = request.getSession().getServletContext();
745                 if (!Globals.isSystemInitialized()) {
746                         Globals.initializeSystem(servletContext);
747                 }
748                 wizardJSON.setTabId("FormEdit");
749                 wizardJSON.setTabName("Form Edit");
750                 FormFieldType currField = null;
751                 try {
752                         if (id.equals("add")) {
753
754                                 currField = rdef.addFormFieldType(new ObjectFactory(), "", "", "", "", "", "", "", "", null, null, "",
755                                                 "");
756                                 wizardJSON.setFieldId(currField.getFieldId());
757                                 wizardJSON.setFieldName(currField.getFieldName());
758                                 wizardJSON.setFieldType(currField.getFieldType());
759                                 wizardJSON.setVisible(AppUtils.nvls(currField.getVisible(), "Y").toUpperCase().startsWith("Y"));
760                                 wizardJSON.setDefaultValue(currField.getDefaultValue());
761                                 wizardJSON.setFieldDefaultSQL(currField.getFieldDefaultSQL());
762                                 wizardJSON.setFieldSQL(currField.getFieldSQL());
763                                 wizardJSON.setValidationType(currField.getValidationType());
764                                 persistReportDefinition(request, rdef);
765
766                         } else if (action.equals("delete")) {
767                                 rdef.deleteFormField(id);
768                                 persistReportDefinition(request, rdef);
769                                 wizardJSON.setMessage("Formfield " + detailId + " Deleted");
770                         }
771                         if (rdef.getFormFieldList() != null) {
772                                 for (FormFieldType fft : rdef.getFormFieldList().getFormField()) {
773                                         if (fft.getFieldId().equals(id)) {
774                                                 wizardJSON.setFieldId(fft.getFieldId());
775                                                 wizardJSON.setFieldName(fft.getFieldName());
776                                                 wizardJSON.setFieldType(fft.getFieldType());
777                                                 wizardJSON.setVisible(fft.getVisible().toUpperCase().startsWith("Y"));
778                                                 wizardJSON.setDefaultValue(fft.getDefaultValue());
779                                                 wizardJSON.setFieldDefaultSQL(fft.getFieldDefaultSQL());
780                                                 wizardJSON.setFieldSQL(fft.getFieldSQL());
781                                                 wizardJSON.setValidationType(fft.getValidationType());
782
783                                                 PredefinedValueList preDefined = fft.getPredefinedValueList();
784
785                                                 if (preDefined != null) {
786                                                         List<IdNameBooleanJSON> preDefinedList = new ArrayList<IdNameBooleanJSON>();
787                                                         IdNameBooleanJSON idNameBooleanJSON = new IdNameBooleanJSON();
788
789                                                         for (String v : preDefined.getPredefinedValue()) {
790                                                                 idNameBooleanJSON = new IdNameBooleanJSON();
791                                                                 idNameBooleanJSON.setId(v);
792                                                                 idNameBooleanJSON.setName(v);
793                                                                 preDefinedList.add(idNameBooleanJSON);
794                                                         }
795                                                         wizardJSON.setPredefinedValueList(preDefinedList);
796                                                 }
797                                         }
798                                 }
799                         }
800                 } catch (Exception ex) {
801                         logger.error(EELFLoggerDelegate.errorLogger,
802                                         "[Controller.processRequest]Invalid raptor action [retrieveFormTabWiseData].", ex);
803                         ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
804                         errorJSONRuntime.setErrormessage("Error occured while retreiving formedit definition Tab");
805                         errorJSONRuntime.setStacktrace(getStackTrace(ex));
806                         wizardJSON.setErrorMessage("Error occured while retreiving formedit definition Tab");
807                         wizardJSON.setErrorStackTrace(getStackTrace(ex));
808
809                 }
810
811                 return wizardJSON;
812         }
813
814         @RequestMapping(value = { "/report/wizard/retrieve_col_tab_wise_data/{id}" }, method = RequestMethod.GET)
815         public @ResponseBody ColumnEditJSON retrieveColTabWiseData(@PathVariable Map<String, String> pathVariables,
816                         HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException {
817                 ReportDefinition rdef = null;
818                 String id = "";
819                 ColumnEditJSON wizardJSON = new ColumnEditJSON();
820                 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
821
822                 if (pathVariables.containsKey("id")) {
823                         id = pathVariables.get("id");
824                 }
825                 ServletContext servletContext = request.getSession().getServletContext();
826                 if (!Globals.isSystemInitialized()) {
827                         Globals.initializeSystem(servletContext);
828                 }
829                 if (rdef != null) {
830                         wizardJSON.setTabId("ColEdit");
831                         wizardJSON.setTabName("Column Edit");
832
833                         List<DataColumnType> reportColumnList = rdef.getAllColumns();
834
835                         for (DataColumnType reportColumnType : reportColumnList) {
836                                 if (reportColumnType.getColId().equals(id)) {
837                                         wizardJSON.setColId(reportColumnType.getColId());
838                                         wizardJSON.setColName(reportColumnType.getColName());
839                                         wizardJSON.setDisplayAlignment(reportColumnType.getDisplayAlignment());
840                                         wizardJSON.setDisplayHeaderAlignment(reportColumnType.getDisplayHeaderAlignment());
841                                         wizardJSON.setSortable(
842                                                         reportColumnType.isIsSortable() == null ? false : reportColumnType.isIsSortable());
843                                         wizardJSON.setVisible(reportColumnType.isVisible());
844                                         wizardJSON.setDrilldownURL(
845                                                         reportColumnType.getDrillDownURL() == null ? "" : reportColumnType.getDrillDownURL());
846                                         wizardJSON.setDrilldownParams(
847                                                         reportColumnType.getDrillDownParams() == null ? "" : reportColumnType.getDrillDownParams());
848                                         wizardJSON.setDrilldownType(
849                                                         reportColumnType.getDrillDownType() == null ? "" : reportColumnType.getDrillDownType());
850
851                                 }
852                         }
853                 } else {
854                         wizardJSON.setErrorMessage("Report is not in session");
855                 }
856
857                 return wizardJSON;
858         }
859
860         @RequestMapping(value = { "/report/wizard/retrieve_sql_tab_wise_data/{id}",
861                         "/report/wizard/retrieve_sql_tab_wise_data/" }, method = RequestMethod.GET)
862         public @ResponseBody QueryJSON retrieveSqlTabWiseData(@PathVariable Map<String, String> pathVariables,
863                         HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException {
864                 ReportDefinition rdef = null;
865                 ReportRuntime rr = null;
866                 String id = "";
867                 String detailId = "";
868                 QueryJSON wizardJSON = new QueryJSON();
869
870                 if (pathVariables.containsKey("id")) {
871                         id = pathVariables.get("id");
872                 }
873                 if (pathVariables.containsKey("detailId")) {
874                         detailId = pathVariables.get("detailId");
875                 }
876                 ServletContext servletContext = request.getSession().getServletContext();
877                 if (!Globals.isSystemInitialized()) {
878                         Globals.initializeSystem(servletContext);
879                 }
880                 if (id.equals("InSession") || AppUtils.nvl(id).length() <= 0) {
881                         rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
882                 } else if (AppUtils.nvl(id).length() > 0) {
883                         rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
884                         rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
885
886                         if (rdef != null && !rdef.getReportID().equals(id)) {
887                                 request.getSession().removeAttribute(AppConstants.SI_REPORT_DEFINITION);
888                                 removeVariablesFromSession(request);
889                                 rdef = (new ReportHandler()).loadReportDefinition(request, id);
890                         } else if (rr != null && !rr.getReportID().equals(id)) {
891                                 request.getSession().removeAttribute(AppConstants.SI_REPORT_RUNTIME);
892                                 removeVariablesFromSession(request);
893                                 rdef = (new ReportHandler()).loadReportDefinition(request, id);
894                         } else if (rdef == null) {
895                                 rdef = (new ReportHandler()).loadReportDefinition(request, id);
896                         }
897                 }
898
899                 if (rdef != null) {
900
901                         wizardJSON.setTabId("Sql");
902                         wizardJSON.setTabName("Sql");
903                         wizardJSON.setQuery(rdef.getReportSQL());
904                 }
905                 return wizardJSON;
906         }
907
908         @RequestMapping(value = { "/report/wizard/security/retrieveReportUserList" }, method = RequestMethod.GET)
909         public @ResponseBody List<SecurityEntry> getReportUserList(HttpServletRequest request)
910                         throws IOException, RaptorException {
911                         List<SecurityEntry> reportUserList = new ArrayList<SecurityEntry>();
912                         ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
913                         Vector reportUsers = rdef.getReportUsers(request);
914                         for(Iterator iter=reportUsers.iterator(); iter.hasNext();) { 
915                                 SecurityEntry rUser = (SecurityEntry) iter.next(); 
916                                 reportUserList.add(rUser);
917                         }
918                         return reportUserList;
919         };
920         
921         @RequestMapping(value = { "/report/wizard/security/retrieveReportRoleList" }, method = RequestMethod.GET)
922         public @ResponseBody List<IdNameValue> getReportRoleList(HttpServletRequest request)
923                         throws IOException, RaptorException {
924                         List<IdNameValue> reportRoleList = new ArrayList<IdNameValue>();
925                         ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
926                         Vector reportRoles = rdef.getReportRoles(request);
927                         Vector remainingRoles = Utils.getRolesNotInList(reportRoles,request); 
928                         for(int i=0; i<remainingRoles.size(); i++) {
929                                 IdNameValue role = (IdNameValue) remainingRoles.get(i);
930                                 reportRoleList.add(role);
931                         }
932                         return reportRoleList;
933                 };
934                 
935                 @RequestMapping(value = { "/report/wizard/security/retrieveReportUserList_query" }, method = RequestMethod.GET)
936                 public @ResponseBody List<Map<String, String>> getReportUserListQuery(HttpServletRequest request)
937                                 throws IOException, RaptorException {                           
938                                 List<Map<String, String>> reportUserList = new ArrayList();
939                                 ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
940                                 String reportId = rdef.getReportID();
941                                 Map<String, Object> params = new HashMap<String, Object>();
942                         params.put("report_id", new Long(reportId));    
943                         List<ReportUserRole> queriedUserList = getDataAccessService().executeNamedQuery("getReportSecurityUsers", params, null);
944                         for (int i=0; i<queriedUserList.size();i++){
945                                 Map<String, String> reportUser = new HashMap<String, String>();
946                                 Object tmp = queriedUserList.get(i);
947                                 reportUser.put("rep_id", queriedUserList.get(i).toString());
948                                 reportUser.put("order_no", queriedUserList.get(i).getOrderNo().toString());
949                                 reportUser.put("user_id", queriedUserList.get(i).getUserId().toString());                               
950                                 reportUser.put("role_id", queriedUserList.get(i).getRoleId().toString());                                                               
951                                 reportUser.put("read_only_yn", queriedUserList.get(i).getReadOnlyYn());                                                         
952                                 reportUserList.add(reportUser);
953                         }                       
954                                 return reportUserList;
955                         };
956
957
958
959                         @RequestMapping(value = "/report/security/addReportUser", method = RequestMethod.POST)
960                         public @ResponseBody Map<String,String> addSelectedReportUser(
961                                         @RequestBody String userIdToAdd, HttpServletRequest request, HttpServletResponse response)
962                                         throws IOException, RaptorException {
963                                         Map<String, String> JsonResponse = new HashMap<String, String>();
964                                         ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
965                                         try {
966                                                 JsonResponse.put("status","success");
967                                                 JsonResponse.put("userId",userIdToAdd);
968                                                 String action = "Add User";
969                                                 rdef.getReportSecurity().addUserAccess(userIdToAdd, "Y");
970                                                 WizardSequence ws = rdef.getWizardSequence();
971                                                 ws.performAction(action,rdef);
972                                                 return JsonResponse;
973                                         } catch (Exception ex) {
974                                                 logger.error(EELFLoggerDelegate.errorLogger,
975                                                                 "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex);
976                                                 return null;
977                                         }                               
978                                 }
979
980                         @RequestMapping(value = "/report/security/removeReportUser", method = RequestMethod.POST)
981                         public @ResponseBody Map<String,String> removeSelectedReportUser(
982                                         @RequestBody String userIdToRemove, HttpServletRequest request, HttpServletResponse response)
983                                         throws IOException, RaptorException {
984                                                 Map<String, String> JsonResponse = new HashMap<String, String>();
985                                                 ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
986                                                 try {
987                                                         JsonResponse.put("status","success");
988                                                         JsonResponse.put("userId",userIdToRemove);
989                                                         String action = "Delete User";                          
990                                                         rdef.getReportSecurity().removeUserAccess(userIdToRemove);
991                                                         rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
992                                                         WizardSequence ws = rdef.getWizardSequence();
993                                                         ws.performAction(action,rdef);
994                                                         return JsonResponse;                                                    
995                                                 } catch (Exception ex) {
996                                                         logger.error(EELFLoggerDelegate.errorLogger,
997                                                                         "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex);
998                                                         return null;
999                                                 }                               
1000                                         }
1001                         
1002                         @RequestMapping(value = "/report/security/addReportRole", method = RequestMethod.POST)
1003                         public @ResponseBody Map<String,String> addSelectedReportRole(
1004                                         @RequestBody String roleIdToAdd, HttpServletRequest request, HttpServletResponse response)
1005                                         throws IOException, RaptorException {
1006                                         Map<String, String> JsonResponse = new HashMap<String, String>();
1007                                         ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1008                                         try {
1009                                                 JsonResponse.put("status","success");
1010                                                 JsonResponse.put("roleId",roleIdToAdd);
1011                                                 String action = "Add Role";
1012                                                 rdef.getReportSecurity().addRoleAccess(roleIdToAdd, "Y");
1013                                                 WizardSequence ws = rdef.getWizardSequence();
1014                                                 ws.performAction(action,rdef);
1015                                                 return JsonResponse;
1016                                         } catch (Exception ex) {
1017                                                 logger.error(EELFLoggerDelegate.errorLogger,
1018                                                                 "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex);
1019                                                 return null;
1020                                         }                               
1021                                 }
1022
1023                         @RequestMapping(value = "/report/security/removeReportRole", method = RequestMethod.POST)
1024                         public @ResponseBody Map<String,String> removeSelectedReportRole(
1025                                         @RequestBody String roleIdToRemove, HttpServletRequest request, HttpServletResponse response)
1026                                         throws IOException, RaptorException {
1027                                         Map<String, String> JsonResponse = new HashMap<String, String>();
1028                                         ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1029                                         try {
1030                                                 JsonResponse.put("status","success");
1031                                                 JsonResponse.put("roleId",roleIdToRemove);
1032                                                 String action = "Delete Role";
1033                                                 rdef.getReportSecurity().removeRoleAccess(roleIdToRemove);
1034                                                 WizardSequence ws = rdef.getWizardSequence();
1035                                                 ws.performAction(action,rdef);
1036                                                 return JsonResponse;
1037                                         } catch (Exception ex) {
1038                                                 logger.error(EELFLoggerDelegate.errorLogger,
1039                                                                 "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex);
1040                                                 return null;
1041                                         }                               
1042                                 }                       
1043
1044                         @RequestMapping(value = "/report/security/updateReportSecurityInfo", method = RequestMethod.POST)
1045                         public @ResponseBody Map<String,String> updateReportSecurityInfo(
1046                                         @RequestBody Map<String,String> securityInfo, HttpServletRequest request, HttpServletResponse response)
1047                                         throws IOException, RaptorException {
1048
1049                                         Map<String, String> JsonResponse = new HashMap<String, String>();
1050                                         ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1051                                         try {
1052                                                 JsonResponse.put("status","success");
1053                                                 String OwnerUserId = securityInfo.get("userId");
1054                                                 String isPublic = securityInfo.get("isPublic");
1055                                                 boolean rPublic = isPublic.equals("true"); 
1056                                                 rdef.getReportSecurity().setOwnerID(OwnerUserId);
1057                                                 rdef.setPublic(rPublic);
1058                                                 persistReportDefinition(request, rdef);
1059                                                 return JsonResponse;
1060                                                 
1061                                         } catch (Exception ex) {
1062                                                 logger.error(EELFLoggerDelegate.errorLogger,
1063                                                                 "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex);
1064                                                 return null;
1065                                         }                               
1066                                 }
1067
1068                         @RequestMapping(value = "/report/security/toggleUserEditAccess/{userID}", method = RequestMethod.POST)
1069                         public @ResponseBody Map<String,String> toggleUserEditAccess(
1070                                         @PathVariable("userID") String userId,
1071                                         @RequestBody String readOnly, HttpServletRequest request, HttpServletResponse response)
1072                                         throws IOException, RaptorException {
1073                                         Map<String, String> JsonResponse = new HashMap<String, String>();
1074                                         ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1075                                         try {
1076                                                 String action ="";
1077                                                 JsonResponse.put("status","success");
1078                                                 if (readOnly.equals("N")) {
1079                                                         action = "Grant User Access";
1080                                                 }  else {
1081                                                         action = "Revoke User Access";                                                  
1082                                                 }                                               
1083                                                 rdef.getReportSecurity().updateUserAccess(userId, readOnly);
1084                                                 WizardSequence ws = rdef.getWizardSequence();
1085                                                 ws.performAction(action,rdef);
1086                                                 
1087                                                 return JsonResponse;
1088                                         } catch (Exception ex) {
1089                                                 logger.error(EELFLoggerDelegate.errorLogger,
1090                                                                 "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex);
1091                                                 return null;
1092                                         }                               
1093                                 };                      
1094
1095                                 @RequestMapping(value = "/report/security/toggleRoleEditAccess/{roleID}", method = RequestMethod.POST)
1096                                 public @ResponseBody Map<String,String> toggleRoleEditAccess(
1097                                                 @PathVariable("roleID") String roleId,
1098                                                 @RequestBody String readOnly, HttpServletRequest request, HttpServletResponse response)
1099                                                 throws IOException, RaptorException {
1100                                                 Map<String, String> JsonResponse = new HashMap<String, String>();
1101                                                 ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1102                                                 try {
1103                                                         String action ="";
1104                                                         JsonResponse.put("status","success");
1105                                                         if (readOnly.equals("N")) {
1106                                                                 action = "Grant Role Access";
1107                                                         }  else {
1108                                                                 action = "Revoke Role Access";                                                  
1109                                                         }                                               
1110                                                         rdef.getReportSecurity().updateRoleAccess(roleId, readOnly);
1111                                                         WizardSequence ws = rdef.getWizardSequence();
1112                                                         ws.performAction(action,rdef);
1113                                                         
1114                                                         return JsonResponse;
1115                                                 } catch (Exception ex) {
1116                                                         logger.error(EELFLoggerDelegate.errorLogger,
1117                                                                         "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex);
1118                                                         return null;
1119                                                 }                               
1120                                         };                      
1121                                 
1122         @RequestMapping(value = { "/report/wizard/security/retrieveReportOwner" }, method = RequestMethod.GET)
1123         public @ResponseBody List<IdNameValue> getReportOwnerInList(HttpServletRequest request)
1124                         throws IOException, RaptorException {
1125                 ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1126
1127                 List<IdNameValue> UserList = new ArrayList<IdNameValue>();
1128                 List excludeValues = new java.util.ArrayList();
1129                 HttpSession session = request.getSession();
1130                 String query = Globals.getCustomizedScheduleQueryForUsers();
1131                 session.setAttribute("login_id", AppUtils.getUserBackdoorLoginId(request));
1132                 String userId = AppUtils.getUserID(request);
1133                 session.setAttribute("LOGGED_USERID", userId);
1134                 String[] sessionParameters = Globals.getSessionParams().split(",");
1135                 String param = "";
1136                 for (int i = 0; i < sessionParameters.length; i++) {
1137                         param = (String) session.getAttribute(sessionParameters[0]);
1138                         query = Utils.replaceInString(query, "[" + sessionParameters[i].toUpperCase() + "]",
1139                                         (String) session.getAttribute(sessionParameters[i]));
1140                 }
1141                 boolean isAdmin = AppUtils.isAdminUser(request);
1142                 Vector allUsers = AppUtils.getAllUsers(query, param, isAdmin);
1143                 Vector result = new Vector(allUsers.size());
1144
1145                 for (Iterator iter = allUsers.iterator(); iter.hasNext();) {
1146                         IdNameValue value = (IdNameValue) iter.next();
1147
1148                         boolean exclude = false;
1149                         for (Iterator iterE = excludeValues.iterator(); iterE.hasNext();)
1150                                 if (((IdNameValue) iterE.next()).getId().equals(value.getId())) {
1151                                         exclude = true;
1152                                         break;
1153                                 } // if
1154
1155                         if (!exclude)
1156                                 UserList.add(value);
1157                 } // for
1158                 return UserList;
1159         }
1160
1161         
1162         @RequestMapping(value = { "/report/wizard/security/getReportSecurityInfo" }, method = RequestMethod.GET)
1163         public @ResponseBody Map<String,String> getReportSecurityInfo(HttpServletRequest request)
1164                         throws IOException, RaptorException {
1165                 Map<String, String> securityInfoMap = new HashMap<String,String>();
1166                 ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1167                 String isPublic = Boolean.toString(rdef.isPublic()); 
1168                 String createUser = AppUtils.getUserName(rdef.getCreateID());
1169                 String createDate = rdef.getCreateDate();
1170                 String updateUser = AppUtils.getUserName(rdef.getUpdateID());
1171                 String updateDate = rdef.getUpdateDate();
1172                 String ownerId = rdef.getOwnerID();
1173                 
1174                 securityInfoMap.put("isPublic",isPublic);
1175                 securityInfoMap.put("createdUser",createUser);          
1176                 securityInfoMap.put("createdDate",createDate);          
1177                 securityInfoMap.put("updateUser",updateUser);
1178                 securityInfoMap.put("updatedDate",updateDate);
1179                 securityInfoMap.put("ownerId",ownerId);
1180                 
1181                 return securityInfoMap;
1182         }       
1183         
1184         @RequestMapping(value = { "/report/wizard/security/getReportSecurityUsers" }, method = RequestMethod.GET)
1185         public @ResponseBody List<SecurityEntry> getReportSecurityUsers(HttpServletRequest request)
1186                         throws IOException, RaptorException {
1187                 
1188                 List<SecurityEntry> reportUserMapList = new ArrayList<SecurityEntry>();
1189                 ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1190                 Vector reportUsers = rdef.getReportUsers(request);
1191                 int iCount = 0;
1192                 
1193                 for(Iterator iter=reportUsers.iterator(); iter.hasNext(); iCount++) { 
1194                         Map<String, String> reportUserMap = new HashMap<String,String>();
1195                         SecurityEntry rUser = (SecurityEntry) iter.next();
1196                         reportUserMapList.add(rUser);
1197                 }
1198                 
1199                 return reportUserMapList;
1200         }               
1201         
1202         
1203         @RequestMapping(value = { "/report/wizard/security/getReportSecurityRoles" }, method = RequestMethod.GET)
1204         public @ResponseBody List<SecurityEntry> getReportSecurityRoles(HttpServletRequest request)
1205                         throws IOException, RaptorException {
1206                 
1207                 List<SecurityEntry> reportRoleList = new ArrayList<SecurityEntry>();
1208                 ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1209                 Vector reportRoles = rdef.getReportRoles(request);
1210                 int iCount = 0;
1211                 
1212                 for(Iterator iter=reportRoles.iterator(); iter.hasNext(); iCount++) { 
1213                         SecurityEntry rRole = (SecurityEntry) iter.next(); 
1214                         reportRoleList.add(rRole);
1215                 }
1216                 
1217                 return reportRoleList;
1218         }               
1219         
1220         
1221         @RequestMapping(value = { "/report/wizard/retrieve_def_tab_wise_data/{id}",
1222                         "/report/wizard/retrieve_def_tab_wise_data/{id}/{detailId}" }, method = RequestMethod.GET)
1223         public @ResponseBody DefinitionJSON retrieveDefTabWiseData(@PathVariable Map<String, String> pathVariables,
1224                         HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException {
1225                 ReportDefinition rdef = null;
1226                 ReportRuntime rr = null;
1227                 boolean newReport = false;
1228                 String tabId = "Def";
1229                 String id = "";
1230
1231                 if (pathVariables.containsKey("id")) {
1232                         id = pathVariables.get("id");
1233                 }
1234                 String detailId = "";
1235                 if (pathVariables.containsKey("detailId")) {
1236                         detailId = pathVariables.get("detailId");
1237                 }
1238
1239                 ServletContext servletContext = request.getSession().getServletContext();
1240                 if (!Globals.isSystemInitialized()) {
1241                         Globals.initializeSystem(servletContext);
1242                 }
1243
1244                 if (tabId.equals("Def") && id.equals("InSession")) {
1245                         rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1246                         newReport = false;
1247
1248                 } else if (tabId.equals("Def") && id.equals("Create")) {
1249                         removeVariablesFromSession(request);
1250                         rdef = (new ReportHandler()).loadReportDefinition(request, "-1");
1251                         rdef.setReportType(AppConstants.RT_LINEAR);
1252                         newReport = true;
1253
1254                 } else if (tabId.equals("Def") && AppUtils.nvl(id).length() > 0) {
1255                         rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1256                         rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
1257
1258                         if (rdef != null && !rdef.getReportID().equals(id)) {
1259                                 request.getSession().removeAttribute(AppConstants.SI_REPORT_DEFINITION);
1260                                 removeVariablesFromSession(request);
1261                                 rdef = (new ReportHandler()).loadReportDefinition(request, id);
1262                                 request.getSession().setAttribute(AppConstants.SI_REPORT_DEFINITION, rdef);
1263                         } else if (rr != null && !rr.getReportID().equals(id)) {
1264                                 request.getSession().removeAttribute(AppConstants.SI_REPORT_RUNTIME);
1265                                 removeVariablesFromSession(request);
1266                                 rdef = (new ReportHandler()).loadReportDefinition(request, id);
1267                                 request.getSession().setAttribute(AppConstants.SI_REPORT_DEFINITION, rdef);
1268                         } else if (rdef == null) {
1269                                 rdef = (new ReportHandler()).loadReportDefinition(request, id);
1270                                 request.getSession().setAttribute(AppConstants.SI_REPORT_DEFINITION, rdef);
1271                         }
1272                         newReport = false;
1273
1274                 } else {
1275                         rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1276                 }
1277                 DefinitionJSON wizardJSON = new DefinitionJSON();
1278                 if (tabId.equals("Def")) {
1279                         wizardJSON.setTabId("Def");
1280                         wizardJSON.setTabName("Definition");
1281
1282                         wizardJSON.setReportId((rdef != null) ? rdef.getReportID() + "" : "");
1283                         wizardJSON.setReportName((rdef != null) ? rdef.getReportName() : "");
1284                         wizardJSON.setReportDescr((rdef != null) ? rdef.getReportDescr() : "");
1285                         wizardJSON.setReportType((rdef != null) ? rdef.getReportType() : AppConstants.RT_LINEAR);
1286                         wizardJSON.setDbInfo((rdef != null) ? rdef.getDBInfo() : "");
1287                         wizardJSON.setFormHelpText((rdef != null) ? rdef.getFormHelpText() : "");
1288                         wizardJSON.setPageSize((rdef != null) ? rdef.getPageSize() : 50);
1289                         List<IdNameBooleanJSON> displayArea = new ArrayList<IdNameBooleanJSON>();
1290                         IdNameBooleanJSON idNameJSON = new IdNameBooleanJSON();
1291                         String qMenu = "";
1292                         for (int i = 0; i < AppUtils.getQuickLinksMenuIDs().size(); i++) {
1293                                 idNameJSON = new IdNameBooleanJSON();
1294                                 qMenu = (String) AppUtils.getQuickLinksMenuIDs().get(i);
1295                                 idNameJSON.setId(qMenu);
1296                                 idNameJSON.setName(qMenu);
1297                                 if (rdef != null && (rdef.getMenuID().equals(qMenu))) {
1298                                         idNameJSON.setSelected(true);
1299                                 }
1300                                 displayArea.add(idNameJSON);
1301                         }
1302                         wizardJSON.setDisplayArea(displayArea);
1303                         wizardJSON.setHideFormFieldsAfterRun((rdef != null) ? rdef.isHideFormFieldAfterRun() : false);
1304                         wizardJSON.setMaxRowsInExcelCSVDownload((rdef != null) ? rdef.getMaxRowsInExcelDownload() : 500);
1305                         wizardJSON.setFrozenColumns((rdef != null) ? rdef.getFrozenColumns() : 0);
1306                         wizardJSON.setDataGridAlign((rdef != null) ? rdef.getDataGridAlign() : "left");
1307                         wizardJSON.setEmptyMessage((rdef != null) ? rdef.getEmptyMessage() : "No records found");
1308                         wizardJSON.setDataContainerHeight((rdef != null) ? rdef.getDataContainerHeight() : "600");
1309                         wizardJSON.setDataContainerWidth((rdef != null) ? rdef.getDataContainerWidth() : "900");
1310                         List<NameBooleanJSON> displayOptions = new ArrayList<NameBooleanJSON>();
1311                         NameBooleanJSON nameBooleanJSON = new NameBooleanJSON();
1312                         nameBooleanJSON.setName("HideFormFields");
1313                         nameBooleanJSON.setSelected((rdef != null) ? rdef.isDisplayOptionHideForm() : false);
1314                         displayOptions.add(nameBooleanJSON);
1315
1316                         nameBooleanJSON = new NameBooleanJSON();
1317                         nameBooleanJSON.setName("HideChart");
1318                         nameBooleanJSON.setSelected((rdef != null) ? rdef.isDisplayOptionHideChart() : false);
1319                         displayOptions.add(nameBooleanJSON);
1320
1321                         nameBooleanJSON = new NameBooleanJSON();
1322                         nameBooleanJSON.setName("HideReportData");
1323                         nameBooleanJSON.setSelected((rdef != null) ? rdef.isDisplayOptionHideData() : false);
1324                         displayOptions.add(nameBooleanJSON);
1325
1326                         nameBooleanJSON = new NameBooleanJSON();
1327                         nameBooleanJSON.setName("HideExcel");
1328                         nameBooleanJSON.setSelected((rdef != null) ? rdef.isDisplayOptionHideExcelIcons() : false);
1329                         displayOptions.add(nameBooleanJSON);
1330
1331                         nameBooleanJSON = new NameBooleanJSON();
1332                         nameBooleanJSON.setName("HidePdf");
1333                         nameBooleanJSON.setSelected((rdef != null) ? rdef.isDisplayOptionHidePDFIcons() : false);
1334                         displayOptions.add(nameBooleanJSON);
1335
1336                         wizardJSON.setDisplayOptions(displayOptions);
1337
1338                         wizardJSON.setRuntimeColSortDisabled((rdef != null) ? rdef.isRuntimeColSortDisabled() : false);
1339                         wizardJSON.setNumFormCols((rdef != null) ? rdef.getNumFormColsAsInt() : 1);
1340                         wizardJSON.setReportTitle((rdef != null) ? rdef.getReportTitle() : "");
1341                         wizardJSON.setReportSubTitle((rdef != null) ? rdef.getReportSubTitle() : "");
1342
1343                 }
1344
1345                 ObjectMapper mapper = new ObjectMapper();
1346                 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
1347                 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1348
1349                 return wizardJSON;
1350
1351         }
1352
1353         @RequestMapping(value = "/report/wizard/retrieve_data/{validate}", method = RequestMethod.POST)
1354         public @ResponseBody RaptorResponse retrieveDataForGivenQuery(@PathVariable("validate") boolean validate,
1355                         @RequestBody QueryJSON queryJSON, HttpServletRequest request, HttpServletResponse response)
1356                         throws IOException, RaptorException {
1357                 RaptorResponse raptorResponse = new RaptorResponse();
1358                 String sql = queryJSON.getQuery();
1359                 String jsonInString = "";
1360
1361                 ServletContext servletContext = request.getSession().getServletContext();
1362                 if (!Globals.isSystemInitialized()) {
1363                         Globals.initializeSystem(servletContext);
1364                 }
1365
1366                 ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1367                 if (rdef == null) {
1368                         ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
1369                         errorJSONRuntime.setErrormessage("Report Definition is not in session;");
1370                         errorJSONRuntime.setStacktrace("");
1371
1372                         ObjectMapper mapper = new ObjectMapper();
1373                         mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
1374                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1375
1376                         try {
1377                                 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
1378                                 raptorResponse.data().put("elements", jsonInString);
1379                                 return raptorResponse;
1380                         } catch (Exception ex1) {
1381                                 logger.error(EELFLoggerDelegate.errorLogger,
1382                                                 "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex1);
1383                         }
1384                 } else {
1385                         if (!sql.trim().toUpperCase().startsWith("SELECT")) {
1386                                 ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
1387                                 errorJSONRuntime.setErrormessage("Invalid statement - the SQL must start with the keyword SELECT");
1388                                 errorJSONRuntime.setStacktrace("SQL Error");
1389                                 ObjectMapper mapper = new ObjectMapper();
1390                                 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
1391                                 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1392
1393                                 try {
1394                                         jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
1395                                         raptorResponse.data().put("elements", jsonInString);
1396                                         return raptorResponse;
1397
1398                                 } catch (Exception ex) {
1399                                         logger.error(EELFLoggerDelegate.errorLogger,
1400                                                         "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex);
1401                                 }
1402                         } else {
1403                                 DataSet ds = null;
1404                                 String remoteDb = request.getParameter("remoteDbPrefix");
1405                                 // comment below two lines to test
1406                                 String remoteDbPrefix = (remoteDb != null && !remoteDb.equalsIgnoreCase("null")) ? remoteDb
1407                                                 : rdef.getDBInfo();
1408                                 String userId = AppUtils.getUserID(request);
1409                                 // String userId = "1";
1410                                 sql = Utils.replaceInString(sql, "[LOGGED_USERID]", userId);
1411                                 sql = Utils.replaceInString(sql, "[USERID]", userId);
1412                                 String[] reqParameters = Globals.getRequestParams().split(",");
1413                                 String[] sessionParameters = Globals.getSessionParams().split(",");
1414                                 javax.servlet.http.HttpSession session = request.getSession();
1415                                 logger.debug(EELFLoggerDelegate.debugLogger, ("B4 testRunSQL " + sql));
1416                                 if (request != null) {
1417                                         for (int i = 0; i < reqParameters.length; i++) {
1418                                                 if (!reqParameters[i].startsWith("ff"))
1419                                                         sql = Utils.replaceInString(sql, "[" + reqParameters[i].toUpperCase() + "]",
1420                                                                         ESAPI.encoder().encodeForSQL( SecurityCodecUtil.getCodec(),request.getParameter(reqParameters[i].toUpperCase())));
1421                                                 else
1422                                                                                                                 sql = Utils.replaceInString(sql, "[" + reqParameters[i].toUpperCase() + "]",
1423                                                                         ESAPI.encoder().encodeForSQL( SecurityCodecUtil.getCodec(),request.getParameter(reqParameters[i])));
1424                                         }
1425                                 }
1426                                 if (session != null) {
1427                                         for (int i = 0; i < sessionParameters.length; i++) {
1428                                                 logger.debug(EELFLoggerDelegate.debugLogger, (" Session " + " sessionParameters[i] "
1429                                                                 + sessionParameters[i] + " " + (String) session.getAttribute(sessionParameters[i])));
1430                                                 sql = Utils.replaceInString(sql, "[" + sessionParameters[i].toUpperCase() + "]",
1431                                                                 (String) session.getAttribute(sessionParameters[i]));
1432                                         }
1433                                 }
1434                                 logger.debug(EELFLoggerDelegate.debugLogger, ("After testRunSQL " + sql));
1435                                 try {
1436
1437                                         response.setContentType("application/json");
1438                                         ds = ConnectionUtils.getDataSet(sql, "local", true);
1439
1440                                         QueryResultJSON queryResultJSON = new QueryResultJSON();
1441                                         queryResultJSON.setQuery(queryJSON.getQuery());
1442                                         String query = XSSFilter.filterRequestOnlyScript(queryJSON.getQuery());
1443                                         rdef.parseReportSQL(query);
1444                                         queryResultJSON.setQuery(query);
1445
1446                                         int numColumns = ds.getColumnCount();
1447                                         queryResultJSON.setTotalRows(ds.getRowCount());
1448
1449                                         int count = 0;
1450                                         Map<String, String> dvJSON = null;
1451                                         ArrayList<String> colList = new ArrayList<String>();
1452                                         ArrayList<Map<String, String>> reportDataRows = new ArrayList<Map<String, String>>();
1453                                         if (!ds.isEmpty()) {
1454                                                 count = 0;
1455
1456                                                 for (int i = 0; i < ds.getColumnCount(); i++) {
1457                                                         colList.add(ds.getColumnName(i));
1458                                                 }
1459                                                 queryResultJSON.setReportDataColumns(colList);
1460                                                 if (queryResultJSON.getTotalRows() > 0) {
1461                                                         count = 0;
1462                                                         dvJSON = new HashMap<String, String>();
1463                                                         for (int r = 0; r < Math.min(ds.getRowCount(), 100); r++) {
1464                                                                 dvJSON = new HashMap<String, String>();
1465                                                                 for (int c = 0; c < ds.getColumnCount(); c++) {
1466                                                                         try {
1467                                                                                 dvJSON.put(ds.getColumnName(c), ds.getString(r, c));
1468                                                                         } catch (Exception ex) {
1469                                                                                 logger.error(EELFLoggerDelegate.errorLogger,
1470                                                                                                 "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].",
1471                                                                                                 ex);
1472                                                                         }
1473                                                                 }
1474                                                                 reportDataRows.add(dvJSON);
1475
1476                                                         }
1477                                                 }
1478
1479                                         }
1480                                         queryResultJSON.setReportDataRows(reportDataRows);
1481                                         ObjectMapper mapper = new ObjectMapper();
1482                                         mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
1483                                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1484                                         if (validate) {
1485                                                 query = XSSFilter.filterRequestOnlyScript(queryJSON.getQuery());
1486                                                 request.setAttribute("sqlValidated", "N");
1487                                                 rdef.parseReportSQL(query);
1488                                                 request.setAttribute("sqlValidated", "Y");
1489                                                 persistReportDefinition(request, rdef);
1490
1491                                         }
1492                                         try {
1493                                                 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(queryResultJSON);
1494                                                 raptorResponse.data().put("elements", jsonInString);
1495                                                 return raptorResponse;
1496
1497                                         } catch (Exception ex) {
1498                                                 logger.error(EELFLoggerDelegate.errorLogger,
1499                                                                 "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery]. RaptorException: ",
1500                                                                 ex);
1501                                         }
1502                                 } catch (ReportSQLException ex) {
1503                                         ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
1504                                         if (sql.contains("[")) {
1505                                                 errorJSONRuntime.setErrormessage(
1506                                                                 "Formfield information is present in the query, hence couldn't execute");
1507                                                 errorJSONRuntime
1508                                                                 .setStacktrace("Formfield information is present in the query, hence couldn't execute");
1509                                                 if (validate) {
1510                                                         String query = XSSFilter.filterRequestOnlyScript(queryJSON.getQuery());
1511                                                         request.setAttribute("sqlValidated", "N");
1512                                                         rdef.parseReportSQL(query);
1513                                                         request.setAttribute("sqlValidated", "Y");
1514                                                         persistReportDefinition(request, rdef);
1515
1516                                                 }
1517
1518                                         } else {
1519                                                 errorJSONRuntime.setErrormessage(ex.getMessage());
1520                                                 errorJSONRuntime.setStacktrace(getStackTrace(ex));
1521                                         }
1522                                         ObjectMapper mapper = new ObjectMapper();
1523                                         mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
1524                                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1525
1526                                         try {
1527                                                 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
1528                                                 raptorResponse.data().put("elements", jsonInString);
1529                                                 return raptorResponse;
1530
1531                                         } catch (Exception ex1) {
1532                                                 logger.error(EELFLoggerDelegate.errorLogger,
1533                                                                 "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex1);
1534                                         }
1535                                 }
1536                                 if (validate) {
1537                                         String query = XSSFilter.filterRequestOnlyScript(queryJSON.getQuery());
1538                                         request.setAttribute("sqlValidated", "N");
1539                                         rdef.parseReportSQL(query);
1540                                         request.setAttribute("sqlValidated", "Y");
1541                                         persistReportDefinition(request, rdef);
1542
1543                                 }
1544
1545                         }
1546                 }
1547                 raptorResponse.data().put("elements", jsonInString);
1548                 return raptorResponse;
1549
1550         }
1551
1552         @RequestMapping(value = "save_chart", method = RequestMethod.POST)
1553         public void reportChartReceive(@RequestBody ChartJSON chartJSON, HttpServletRequest request,
1554                         HttpServletResponse response) throws IOException {
1555                 ReportRuntime reportRuntime;
1556                 reportRuntime = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME); // changing
1557                                                                                                                                                                                                                         // session
1558                                                                                                                                                                                                                         // to
1559                                                                                                                                                                                                                         // request
1560                 String reportID = request.getParameter("c_master");
1561                 if (reportRuntime == null && AppUtils.nvl(reportID).length() > 0) {
1562                         try {
1563                                 ReportHandler rh = new ReportHandler();
1564                                 reportRuntime = rh.loadReportRuntime(request, reportID);
1565                         } catch (RaptorException ex) {
1566                                 logger.error(EELFLoggerDelegate.errorLogger,
1567                                                 "[Controller.processRequest]Invalid raptor action [reportChartReceive].", ex);
1568                         }
1569                 }
1570
1571                 if (reportRuntime != null) {
1572                         String chartType = chartJSON.getChartType();
1573                         reportRuntime.setChartType(chartJSON.getChartType());
1574                         reportRuntime.setChartAnimate(chartJSON.isAnimation());
1575                         reportRuntime.setChartWidth(chartJSON.getWidth());
1576                         reportRuntime.setChartHeight(chartJSON.getHeight());
1577                         reportRuntime.setShowChartTitle(chartJSON.isShowTitle());
1578
1579                         String domainAxis = null;
1580                         domainAxis = chartJSON.getDomainAxis();
1581
1582                         List<DataColumnType> reportCols = reportRuntime.getAllColumns();
1583
1584                         for (Iterator<DataColumnType> iter = reportCols.iterator(); iter.hasNext();) {
1585                                 DataColumnType dct = (DataColumnType) iter.next();
1586                                 if (dct.getColId().equals(domainAxis)) {
1587                                         dct.setColOnChart(AppConstants.GC_LEGEND);
1588                                 } else {
1589                                         dct.setColOnChart(null);
1590                                 }
1591                         }
1592
1593                         CategoryAxisJSON categoryAxisJSON = chartJSON.getCategoryAxisJSON();
1594                         String categoryAxis = null;
1595
1596                         categoryAxis = (categoryAxisJSON != null ? categoryAxisJSON.getValue() : "");
1597
1598                         reportCols = reportRuntime.getAllColumns();
1599
1600                         for (Iterator<DataColumnType> iter = reportCols.iterator(); iter.hasNext();) {
1601                                 DataColumnType dct = (DataColumnType) iter.next();
1602                                 if (dct.getColId().equals(categoryAxis)) {
1603                                         dct.setChartSeries(true);
1604                                 } else {
1605                                         dct.setChartSeries(false);
1606                                 }
1607                         }
1608
1609                         ArrayList<RangeAxisJSON> rangeAxisList = chartJSON.getRangeAxisList();
1610                         int r = 0;
1611                         HashSet<String> removeRangeAxisMap = new HashSet<>();
1612                         for(RangeAxisJSON rangeAxis:chartJSON.getRangeAxisRemoveList()){                                
1613                                 removeRangeAxisMap.add(rangeAxis.getRangeAxis());
1614                         }
1615                         for (int i = 0; i < rangeAxisList.size(); i++) {
1616                                 RangeAxisJSON rangeAxisJSON = rangeAxisList.get(i);
1617                                 String rangeAxis = rangeAxisJSON.getRangeAxis();
1618                                 String rangeYAxis = AppUtils.nvl(rangeAxisJSON.getRangeYAxis());
1619                                 String rangeChartGroup = AppUtils.nvl(rangeAxisJSON.getRangeChartGroup());
1620                                 String rangeColor = AppUtils.nvl(rangeAxisJSON.getRangeColor());
1621                                 String rangeLineType = AppUtils.nvl(rangeAxisJSON.getRangeLineType());
1622
1623                                 rangefor: for (Iterator<DataColumnType> iterator = reportCols.iterator(); iterator.hasNext();) {
1624                                         DataColumnType dct = (DataColumnType) iterator.next();
1625                                         if (dct.getColId().equals(rangeAxis)) {
1626                                                 if(removeRangeAxisMap.contains(rangeAxis))
1627                                                         dct.setChartSeq(-1); // if we set it to -1, means this range axis will not be included
1628                                                 else
1629                                                         dct.setChartSeq(++r);
1630                                                 dct.setColOnChart("0");
1631                                                 dct.setYAxis(rangeYAxis); // +"|"+dct.getColId());
1632                                                 dct.setChartGroup(rangeChartGroup); // +"|"+dct.getColId());
1633                                                 dct.setChartColor(rangeColor);
1634                                                 dct.setChartLineType(rangeLineType);
1635
1636                                                 if (chartType.equals(AppConstants.GT_ANNOTATION_CHART)
1637                                                                 || chartType.equals(AppConstants.GT_FLEX_TIME_CHARTS)) {
1638                                                         if (rangeAxisJSON.isShowAsArea()) {
1639                                                                 dct.setIsRangeAxisFilled(true);
1640                                                         } else {
1641                                                                 dct.setIsRangeAxisFilled(false);
1642                                                         }
1643                                                 }
1644                                                 break rangefor;
1645                                         }
1646                                 }
1647
1648                         }
1649
1650                         reportRuntime.setChartLeftAxisLabel(chartJSON.getPrimaryAxisLabel());
1651                         reportRuntime.setChartRightAxisLabel(chartJSON.getSecondaryAxisLabel());
1652
1653                         reportRuntime.setRangeAxisLowerLimit(chartJSON.getMinRange());
1654                         reportRuntime.setRangeAxisUpperLimit(chartJSON.getMaxRange());
1655
1656                         if (chartType.equals(AppConstants.GT_ANNOTATION_CHART)
1657                                         || chartType.equals(AppConstants.GT_FLEX_TIME_CHARTS)) {
1658                                 if (chartJSON.getFlexTimeSeriesChartOptions() != null) {
1659                                         reportRuntime.setZoomIn(chartJSON.getFlexTimeSeriesChartOptions().getZoomIn());
1660                                         reportRuntime.setTimeAxisType(chartJSON.getFlexTimeSeriesChartOptions().getTimeAxisType());
1661                                 }
1662
1663                         }
1664
1665                         if (chartType.equals(AppConstants.GT_TIME_SERIES)) {
1666                                 if (chartJSON.getTimeSeriesChartOptions() != null) {
1667                                         reportRuntime.setTimeSeriesRender(chartJSON.getTimeSeriesChartOptions().getLineChartRenderer());
1668                                         reportRuntime.setShowXAxisLabel(chartJSON.getTimeSeriesChartOptions().isShowXAxisLabel());
1669                                         reportRuntime.setAddXAxisTickers(chartJSON.getTimeSeriesChartOptions().isAddXAxisTicker());
1670                                         reportRuntime.setTimeAxis(chartJSON.getTimeSeriesChartOptions().isNonTimeAxis());
1671                                         reportRuntime.setMultiSeries(chartJSON.getTimeSeriesChartOptions().isMultiSeries());
1672                                 }
1673
1674                         }
1675
1676                         if (chartType.equals(AppConstants.GT_BAR_3D)) {
1677                                 if (chartJSON.getBarChartOptions() != null) {
1678                                         reportRuntime.setChartOrientation(
1679                                                         chartJSON.getBarChartOptions().isVerticalOrientation() ? "vertical" : "horizontal");
1680                                         reportRuntime.setChartStacked(chartJSON.getBarChartOptions().isStackedChart());
1681                                         reportRuntime.setBarControls(chartJSON.getBarChartOptions().isDisplayBarControls());
1682                                         reportRuntime.setXAxisDateType(chartJSON.getBarChartOptions().isxAxisDateType());
1683                                         reportRuntime.setLessXaxisTickers(chartJSON.getBarChartOptions().isMinimizeXAxisTickers());
1684                                         reportRuntime.setTimeAxis(chartJSON.getBarChartOptions().isTimeAxis());
1685                                         reportRuntime.setLogScale(chartJSON.getBarChartOptions().isyAxisLogScale());
1686                                 }
1687                         }
1688
1689                         reportRuntime.setLegendLabelAngle(chartJSON.getCommonChartOptions().getLegendLabelAngle());
1690                         reportRuntime.setLegendPosition(chartJSON.getCommonChartOptions().getLegendPosition());
1691                         reportRuntime.setChartLegendDisplay(chartJSON.getCommonChartOptions().isHideLegend() ? "Y" : "N");
1692                         reportRuntime.setAnimateAnimatedChart(chartJSON.getCommonChartOptions().isAnimateAnimatedChart());
1693
1694                         reportRuntime.setTopMargin(chartJSON.getCommonChartOptions().getTopMargin());
1695                         reportRuntime.setBottomMargin(chartJSON.getCommonChartOptions().getBottomMargin());
1696                         reportRuntime.setLeftMargin(chartJSON.getCommonChartOptions().getLeftMargin());
1697                         reportRuntime.setRightMargin(chartJSON.getCommonChartOptions().getRightMargin());
1698
1699                         for (Iterator<DataColumnType> iterator = reportCols.iterator(); iterator.hasNext();) {
1700                                 DataColumnType dct = (DataColumnType) iterator.next();
1701                                 if (!(AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)
1702                                                 || (dct.getChartSeq() != null && dct.getChartSeq() > 0) || dct.isChartSeries())) {
1703                                         dct.setChartSeq(-1);
1704                                         dct.setChartColor(null);
1705                                         dct.setColOnChart(null);
1706                                         dct.setCreateInNewChart(false);
1707                                         dct.setChartGroup(null);
1708                                         dct.setYAxis(null);
1709                                 }
1710                         }
1711
1712                         try {
1713                                 reportRuntime.persistLinearReport(request);
1714                         } catch (Exception ex) {
1715                                 logger.error(EELFLoggerDelegate.errorLogger,
1716                                                 "[Controller.processRequest]Invalid raptor action [reportChartReceive].", ex);
1717                         }
1718                 }
1719
1720         }
1721
1722         public String getViewName() {
1723                 return viewName;
1724         }
1725
1726         public void setViewName(String viewName) {
1727                 this.viewName = viewName;
1728         }
1729
1730         public String nvl(String s) {
1731                 return (s == null) ? "" : s;
1732         }
1733
1734         public String nvl(String s, String sDefault) {
1735                 return nvl(s).equals("") ? sDefault : s;
1736         }
1737
1738         public static String getStackTrace(Throwable aThrowable) {
1739                 Writer result = new StringWriter();
1740                 PrintWriter printWriter = new PrintWriter(result);
1741                 aThrowable.printStackTrace(printWriter);
1742                 return result.toString();
1743         }
1744
1745         public void persistReportDefinition(HttpServletRequest request, ReportDefinition rdef) throws RaptorException {
1746                 ReportRuntime rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
1747                 if (rr != null && rr.getReportID().equals(rdef.getReportID()))
1748                         request.getSession().removeAttribute(AppConstants.SI_REPORT_RUNTIME);
1749                 rdef.persistReport(request);
1750         } // persistReportDefinition
1751
1752         // Remove from session
1753         private void removeVariablesFromSession(HttpServletRequest request) {
1754                 HttpSession session = request.getSession();
1755                 session.removeAttribute(AppConstants.DRILLDOWN_REPORTS_LIST);
1756                 session.removeAttribute(AppConstants.DRILLDOWN_INDEX);
1757                 session.removeAttribute(AppConstants.FORM_DRILLDOWN_INDEX);
1758                 session.removeAttribute(AppConstants.SI_BACKUP_FOR_REP_ID);
1759                 session.removeAttribute(AppConstants.SI_COLUMN_LOOKUP);
1760                 session.removeAttribute(AppConstants.SI_DASHBOARD_REP_ID);
1761                 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP);
1762                 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME);
1763                 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP);
1764                 session.removeAttribute(AppConstants.SI_DASHBOARD_CHARTDATA_MAP);
1765                 session.removeAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP);
1766                 session.removeAttribute(AppConstants.SI_DATA_SIZE_FOR_TEXTFIELD_POPUP);
1767                 session.removeAttribute(AppConstants.SI_MAP);
1768                 session.removeAttribute(AppConstants.SI_MAP_OBJECT);
1769                 session.removeAttribute(AppConstants.SI_REPORT_DEFINITION);
1770                 session.removeAttribute(AppConstants.SI_REPORT_RUNTIME);
1771                 session.removeAttribute(AppConstants.SI_REPORT_RUN_BACKUP);
1772                 session.removeAttribute(AppConstants.SI_REPORT_SCHEDULE);
1773                 session.removeAttribute(AppConstants.RI_REPORT_DATA);
1774                 session.removeAttribute(AppConstants.RI_CHART_DATA);
1775                 session.removeAttribute(AppConstants.SI_FORMFIELD_INFO);
1776                 session.removeAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO);
1777                 session.removeAttribute(AppConstants.EMBEDDED_REPORTRUNTIME_MAP);
1778                 session.removeAttribute(AppConstants.EMBEDDED_REPORTDATA_MAP);
1779                 Enumeration<String> enum1 = session.getAttributeNames();
1780                 String attributeName = "";
1781                 while (enum1.hasMoreElements()) {
1782                         attributeName = enum1.nextElement();
1783                         if (attributeName.startsWith("parent_")) {
1784                                 session.removeAttribute(attributeName);
1785                         }
1786                 }
1787         }
1788
1789 }