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