2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalsdk.analytics.system.fusion.web;
22 import java.io.IOException;
23 import java.io.OutputStreamWriter;
24 import java.io.PrintWriter;
25 import java.io.StringWriter;
26 import java.io.Writer;
27 import java.lang.reflect.InvocationTargetException;
28 import java.lang.reflect.Method;
29 import java.util.ArrayList;
30 import java.util.Enumeration;
31 import java.util.HashMap;
32 import java.util.Iterator;
33 import java.util.List;
36 import javax.servlet.ServletContext;
37 import javax.servlet.http.HttpServletRequest;
38 import javax.servlet.http.HttpServletResponse;
39 import javax.servlet.http.HttpSession;
41 import org.openecomp.portalsdk.analytics.controller.Action;
42 import org.openecomp.portalsdk.analytics.controller.ErrorHandler;
43 import org.openecomp.portalsdk.analytics.error.RaptorException;
44 import org.openecomp.portalsdk.analytics.error.RaptorRuntimeException;
45 import org.openecomp.portalsdk.analytics.error.ReportSQLException;
46 import org.openecomp.portalsdk.analytics.error.UserDefinedException;
47 import org.openecomp.portalsdk.analytics.model.ReportHandler;
48 import org.openecomp.portalsdk.analytics.model.definition.ReportDefinition;
49 import org.openecomp.portalsdk.analytics.model.definition.wizard.ColumnEditJSON;
50 import org.openecomp.portalsdk.analytics.model.definition.wizard.ColumnJSON;
51 import org.openecomp.portalsdk.analytics.model.definition.wizard.DefinitionJSON;
52 import org.openecomp.portalsdk.analytics.model.definition.wizard.FormEditJSON;
53 import org.openecomp.portalsdk.analytics.model.definition.wizard.IdNameBooleanJSON;
54 import org.openecomp.portalsdk.analytics.model.definition.wizard.ImportJSON;
55 import org.openecomp.portalsdk.analytics.model.definition.wizard.MessageJSON;
56 import org.openecomp.portalsdk.analytics.model.definition.wizard.NameBooleanJSON;
57 import org.openecomp.portalsdk.analytics.model.definition.wizard.QueryJSON;
58 import org.openecomp.portalsdk.analytics.model.definition.wizard.QueryResultJSON;
59 import org.openecomp.portalsdk.analytics.model.definition.wizard.SearchFieldJSON;
60 import org.openecomp.portalsdk.analytics.model.definition.wizard.WizardJSON;
61 import org.openecomp.portalsdk.analytics.model.pdf.PdfReportHandler;
62 import org.openecomp.portalsdk.analytics.model.runtime.CategoryAxisJSON;
63 import org.openecomp.portalsdk.analytics.model.runtime.ChartJSON;
65 import org.openecomp.portalsdk.analytics.model.runtime.ErrorJSONRuntime;
66 import org.openecomp.portalsdk.analytics.model.runtime.FormField;
67 import org.openecomp.portalsdk.analytics.model.runtime.RangeAxisJSON;
68 import org.openecomp.portalsdk.analytics.model.runtime.ReportFormFields;
69 import org.openecomp.portalsdk.analytics.model.runtime.ReportRuntime;
71 import org.openecomp.portalsdk.analytics.system.AppUtils;
72 import org.openecomp.portalsdk.analytics.system.ConnectionUtils;
73 import org.openecomp.portalsdk.analytics.system.Globals;
74 import org.openecomp.portalsdk.analytics.util.AppConstants;
75 import org.openecomp.portalsdk.analytics.util.DataSet;
76 import org.openecomp.portalsdk.analytics.util.Utils;
77 import org.openecomp.portalsdk.analytics.util.XSSFilter;
78 import org.openecomp.portalsdk.analytics.view.ReportData;
79 import org.openecomp.portalsdk.analytics.xmlobj.DataColumnType;
80 import org.openecomp.portalsdk.analytics.xmlobj.FormFieldList;
81 import org.openecomp.portalsdk.analytics.xmlobj.FormFieldType;
82 import org.openecomp.portalsdk.analytics.xmlobj.ObjectFactory;
83 import org.openecomp.portalsdk.analytics.xmlobj.PredefinedValueList;
84 import org.openecomp.portalsdk.core.controller.UnRestrictedBaseController;
85 import org.openecomp.portalsdk.core.domain.User;
86 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
87 import org.openecomp.portalsdk.core.web.support.UserUtils;
88 import org.springframework.stereotype.Controller;
89 import org.springframework.web.bind.annotation.PathVariable;
90 import org.springframework.web.bind.annotation.RequestBody;
91 import org.springframework.web.bind.annotation.RequestMapping;
92 import org.springframework.web.bind.annotation.RequestMethod;
93 import org.springframework.web.bind.annotation.ResponseBody;
95 import com.fasterxml.jackson.databind.DeserializationFeature;
96 import com.fasterxml.jackson.databind.ObjectMapper;
97 import com.fasterxml.jackson.databind.SerializationFeature;
98 import com.fasterxml.jackson.databind.module.SimpleModule;
99 import com.fasterxml.jackson.databind.node.ObjectNode;
103 public class RaptorControllerAsync extends UnRestrictedBaseController {
106 @RequestMapping(value = { "/raptor.htm" }, method = RequestMethod.GET)
107 public void RaptorSearch(HttpServletRequest request, HttpServletResponse response)
108 throws IOException, RaptorException {
109 // System.out.println("Inside RAPTOR run ");
111 * List items = null; int reportId =
112 * ServletRequestUtils.getIntParameter(request, "report_id", 0);
113 * //String task = ServletRequestUtils.getStringParameter(request,
116 * HashMap additionalParams = new HashMap();
117 * additionalParams.put(Parameters.PARAM_HTTP_REQUEST, request);
119 * return new ModelAndView(getViewName(), "model", null);
121 * //return new ModelAndView(getViewName(), "model", null);
122 * //System.out.println("Fill with proper code"); //return null;
125 String actionKey = nvl(request.getParameter(AppConstants.RI_ACTION), request.getParameter("action"));
126 actionKey = nvl(actionKey, "report.run");
128 HttpSession session = request.getSession();
129 User user = UserUtils.getUserSession(request);
131 if (actionKey.equals("report.download.excel2007.session") || actionKey.equals("report.download.csv.session")
132 || actionKey.equals("report.download.excel.session")
133 || actionKey.equals("report.download.pdf.session")) {
134 if (session != null && user != null) {
135 ServletContext servletContext = request.getSession().getServletContext();
136 if (!Globals.isSystemInitialized()) {
137 Globals.initializeSystem(servletContext);
139 ReportRuntime rr = null;
140 ReportData rd = null;
143 if (!nvl(request.getParameter("parent"), "").equals("N"))
144 parent = nvl(request.getParameter("parent"), "");
145 if (parent.startsWith("parent_"))
147 if (parentFlag == 1) {
148 rr = (ReportRuntime) request.getSession().getAttribute(parent + "_rr");
149 rd = (ReportData) request.getSession().getAttribute(parent + "_rd");
152 boolean isEmbedded = false;
153 Object temp = request.getSession().getAttribute("isEmbedded");
155 isEmbedded = (boolean) temp;
158 String reportID = AppUtils.getRequestValue(request, AppConstants.RI_REPORT_ID);
160 rr = (ReportRuntime) ((HashMap) request.getSession()
161 .getAttribute(AppConstants.EMBEDDED_REPORTRUNTIME_MAP)).get(reportID);
163 rd = (ReportData) ((HashMap) request.getSession()
164 .getAttribute(AppConstants.EMBEDDED_REPORTDATA_MAP)).get(reportID);
167 rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
169 rd = (ReportData) request.getSession().getAttribute(AppConstants.RI_REPORT_DATA);
171 String user_id = AppUtils.getUserID(request);
172 int downloadLimit = 0;
174 downloadLimit = (rr.getMaxRowsInExcelDownload() > 0) ? rr.getMaxRowsInExcelDownload()
175 : Globals.getDownloadLimit();
176 if (actionKey.equals("report.csv.download"))
177 downloadLimit = Globals.getCSVDownloadLimit();
178 String sql_whole = rr.getReportDataSQL(user_id, downloadLimit, request);
179 request.setAttribute(AppConstants.RI_REPORT_SQL_WHOLE, sql_whole);
181 OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream());
183 if (actionKey.equals("report.download.pdf.session")) {
184 new PdfReportHandler().createPdfFileContent(request, response, 3);
185 } else if (actionKey.equals("report.download.csv.session")) {
186 (new ReportHandler()).createCSVFileContent(out, rd, rr, request, response);
187 } else if (actionKey.equals("report.download.excel.session")) {
188 new ReportHandler().createExcelFileContent(out, rd, rr, request, response, user_id, 3); // 3
192 new ReportHandler().createExcel2007FileContent(out, rd, rr, request, response, user_id, 3); // 3
195 } catch (Exception e) {
197 // Log.write("Fatal error [report_download_xlsx.jsp]:
198 // "+e.getMessage());
201 response.sendRedirect("login.htm");
204 if (session != null && user != null) {
205 Action action = null;
206 ServletContext servletContext = request.getSession().getServletContext();
207 if (!Globals.isSystemInitialized()) {
208 Globals.initializeSystem(servletContext);
211 action = Globals.getRaptorActionMapping().getAction(actionKey);
213 throw new RaptorRuntimeException("Action not found");
214 } catch (RaptorException e) {
215 logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action ["
216 + actionKey + "]. RaptorException: " + e.getMessage()));
217 // if (actionKey.equals("system_upgrade")) // System
220 // att.raptor.util.upgrade.SystemUpgrade.upgradeDB(request);
222 viewName = (new ErrorHandler()).processFatalErrorJSON(request,
223 new RaptorRuntimeException("[Controller.processRequest]Invalid raptor action [" + actionKey
224 + "]. Exception: " + e.getMessage()));
228 Class[] paramTypes = new Class[2];
229 paramTypes[0] = Class.forName("javax.servlet.http.HttpServletRequest");
230 paramTypes[1] = Class.forName("java.lang.String");
232 Class handlerClass = Class.forName(action.getControllerClass());
233 Object handler = handlerClass.newInstance();
234 Method handlerMethod = handlerClass.getMethod(action.getControllerMethod(), paramTypes);
236 Object[] paramValues = new Object[2];
237 paramValues[0] = request;
238 paramValues[1] = action.getJspName();
241 viewName = (String) handlerMethod.invoke(handler, paramValues);
242 // ObjectMapper mapper = new ObjectMapper();
243 if (!actionKey.equals("chart.run"))
244 response.setContentType("application/json");
246 response.setContentType("text/html");
248 } catch (ClassNotFoundException e) {
249 logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action ["
250 + actionKey + "]. ClassNotFoundException: " + e.getMessage()));
251 viewName = (new ErrorHandler()).processFatalErrorJSON(request,
252 new RaptorRuntimeException(
253 "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
255 } catch (IllegalAccessException e) {
256 logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action ["
257 + actionKey + "]. IllegalAccessException: " + e.getMessage()));
258 viewName = (new ErrorHandler()).processFatalErrorJSON(request,
259 new RaptorRuntimeException(
260 "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
262 } catch (InstantiationException e) {
263 logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action ["
264 + actionKey + "]. InstantiationException: " + e.getMessage()));
265 viewName = (new ErrorHandler()).processFatalErrorJSON(request,
266 new RaptorRuntimeException(
267 "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
269 } catch (NoSuchMethodException e) {
270 logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action ["
271 + actionKey + "]. NoSuchMethodException: " + e.getMessage()));
272 viewName = (new ErrorHandler()).processFatalErrorJSON(request,
273 new RaptorRuntimeException(
274 "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
276 } catch (InvocationTargetException e) {
278 logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action ["
279 + actionKey + "]. InvocationTargetException: " + e.getMessage()));
280 viewName = (new ErrorHandler()).processFatalErrorJSON(request,
281 new RaptorRuntimeException(
282 "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
285 PrintWriter out = response.getWriter();
287 // System.out.println("******Viewname******"+viewName);
289 // return new ModelAndView(getViewName(), "model", null);
291 PrintWriter out = response.getWriter();
292 out.write("session has timed out for user");
298 @RequestMapping(value = "/report/wizard/list_columns", method = RequestMethod.GET, produces="application/json")
299 public @ResponseBody ArrayList<ColumnJSON> listColumns(HttpServletRequest request, HttpServletResponse response)
300 throws IOException, RaptorException {
301 //PrintWriter out = response.getWriter();
302 ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
303 List<DataColumnType> reportColumnList = rdef.getAllColumns();
304 ArrayList<ColumnJSON> listJSON = new ArrayList<ColumnJSON>();
305 ColumnJSON columnJSON = new ColumnJSON();
307 for (DataColumnType reportColumnType : reportColumnList) {
308 columnJSON = new ColumnJSON();
309 columnJSON.setId(reportColumnType.getColId());
310 columnJSON.setName(reportColumnType.getColName());
311 listJSON.add(columnJSON);
313 /* String jsonInString = "";
314 ObjectMapper mapper = new ObjectMapper();
315 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
316 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
317 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
318 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
321 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(listJSON);
322 } catch (Exception ex) {
323 ex.printStackTrace();
329 @RequestMapping(value = "/report/wizard/list_formfields", method = RequestMethod.GET, produces="application/json")
330 public @ResponseBody ArrayList<SearchFieldJSON> listFormFields(HttpServletRequest request, HttpServletResponse response)
331 throws IOException, RaptorException {
332 //PrintWriter out = response.getWriter();
333 ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
334 ArrayList<SearchFieldJSON> listJSON = new ArrayList<SearchFieldJSON>();
335 SearchFieldJSON fieldJSON = new SearchFieldJSON();
336 if (rdef.getFormFieldList() != null) {
337 for (Iterator iter = rdef.getFormFieldList().getFormField().iterator(); iter.hasNext();) {
338 fieldJSON = new SearchFieldJSON();
339 FormFieldType fft = (FormFieldType) iter.next();
340 String fieldId = fft.getFieldId();
341 String fieldDisplay = fft.getFieldName();
342 fieldJSON.setId(fieldId);
343 fieldJSON.setName(fieldDisplay);
344 listJSON.add(fieldJSON);
348 /* String jsonInString = "";
349 ObjectMapper mapper = new ObjectMapper();
350 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
351 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
352 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
353 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
356 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(listJSON);
357 } catch (Exception ex) {
358 ex.printStackTrace();
361 out.write(jsonInString);
366 @RequestMapping(value = "/report/wizard/list_child_report_ff/{reportID}", method = RequestMethod.GET, produces="application/json")
367 public @ResponseBody ArrayList<SearchFieldJSON> listChildReportFormFields(@PathVariable("reportID") String reportID, HttpServletRequest request,
368 HttpServletResponse response) throws IOException, RaptorException {
369 //PrintWriter out = response.getWriter();
370 ReportRuntime ddRr = (new ReportHandler()).loadReportRuntime(request, reportID, false);
371 ArrayList<SearchFieldJSON> listJSON = new ArrayList<SearchFieldJSON>();
372 SearchFieldJSON fieldJSON = new SearchFieldJSON();
374 ReportFormFields ddReportFormFields = ddRr.getReportFormFields();
375 if (ddReportFormFields != null) {
376 for (ddReportFormFields.resetNext(); ddReportFormFields.hasNext();) {
377 FormField ff = ddReportFormFields.getNext();
378 if (!ff.getFieldType().equals(FormField.FFT_BLANK)) {
379 fieldJSON = new SearchFieldJSON();
380 fieldJSON.setId(ff.getFieldName());
381 fieldJSON.setName(ff.getFieldDisplayName());
382 listJSON.add(fieldJSON);
386 /* String jsonInString = "";
387 ObjectMapper mapper = new ObjectMapper();
388 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
389 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
390 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
391 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
394 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(listJSON);
395 } catch (Exception ex) {
396 ex.printStackTrace();
399 out.write(jsonInString);
404 @RequestMapping(value = "report/wizard/copy_report/{reportID}", method = RequestMethod.GET, produces="application/json")
405 public @ResponseBody MessageJSON copyReport(@PathVariable("reportID") String reportID, HttpServletRequest request,
406 HttpServletResponse response) throws IOException, RaptorException {
407 //PrintWriter out = response.getWriter();
408 //String jsonInString = "";
409 MessageJSON messageJSON = new MessageJSON();
412 ReportHandler rh = new ReportHandler();
413 ReportDefinition rdef = rh.loadReportDefinition(request, reportID);
414 rdef.setAsCopy(request);
415 request.getSession().setAttribute(AppConstants.SI_REPORT_DEFINITION, rdef);
416 messageJSON.setMessage("Success- Report Copied.");
417 messageJSON.setAnyStacktrace(rdef.getReportID() + " is Modified and added to session and DB.");
419 /* ObjectMapper mapper = new ObjectMapper();
420 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
421 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
422 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
423 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
426 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(messageJSON);
427 } catch (Exception ex1) {
428 ex1.printStackTrace();
431 } catch (RaptorException e) {
432 request.setAttribute("error_extra_msg", "While copying report " + reportID);
433 messageJSON.setMessage("Failed - While copying report " + reportID);
434 messageJSON.setAnyStacktrace(getStackTrace(e));
435 // ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
436 // errorJSONRuntime.setErrormessage("While copying report " + reportID);
437 // errorJSONRuntime.setStacktrace(getStackTrace(e));
439 /* ObjectMapper mapper = new ObjectMapper();
440 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
441 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
442 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
443 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
446 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
447 } catch (Exception ex1) {
448 ex1.printStackTrace();
458 @RequestMapping(value = "report/wizard/import_report", method = RequestMethod.POST, consumes="application/json")
459 public MessageJSON importReport(@RequestBody ImportJSON importJSON, HttpServletRequest request,
460 HttpServletResponse response) throws IOException, RaptorException {
461 //PrintWriter out = response.getWriter();
462 //String jsonInString = "";
463 MessageJSON messageJSON = new MessageJSON();
465 String reportXML = importJSON.getReportXML();
467 ReportHandler rh = new ReportHandler();
468 ReportDefinition rdef = rh.createReportDefinition(request, "-1", reportXML);
469 rdef.updateReportDefType();
470 rdef.generateWizardSequence(request);
471 rdef.setReportName("Import: " + rdef.getReportName());
472 rdef.clearAllDrillDowns();
474 request.getSession().setAttribute(AppConstants.SI_REPORT_DEFINITION, rdef);
476 messageJSON.setMessage("Success- Report imported.");
477 messageJSON.setAnyStacktrace(rdef.getReportID() + " is Modified and added to session and DB.");
479 /* ObjectMapper mapper = new ObjectMapper();
480 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
481 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
482 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
483 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
486 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(messageJSON);
487 } catch (Exception ex1) {
488 ex1.printStackTrace();
492 } catch (RaptorException e) {
493 request.setAttribute("error_extra_msg", "Unable to parse XML. Nested error: ");
494 messageJSON.setMessage("Unable to parse XML. Nested error: ");
495 messageJSON.setAnyStacktrace(getStackTrace(e));
496 /* ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
497 errorJSONRuntime.setErrormessage("Unable to parse XML. Nested error: ");
498 errorJSONRuntime.setStacktrace(getStackTrace(e));
500 /* ObjectMapper mapper = new ObjectMapper();
501 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
502 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
503 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
504 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
507 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
508 } catch (Exception ex1) {
509 ex1.printStackTrace();
519 @RequestMapping(value = "report/wizard/save_formfield_tab_data", method = RequestMethod.POST)
520 public MessageJSON saveFFTabWiseData(@RequestBody FormEditJSON formEditJSON, HttpServletRequest request,
521 HttpServletResponse response) throws IOException, RaptorException {
522 ReportDefinition rdef = null;
523 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
525 String tabId = formEditJSON.getTabId();
526 //String errorString = "";
527 MessageJSON messageJSON = new MessageJSON();
529 //PrintWriter out = response.getWriter();
530 //String jsonInString = "";
534 String fieldId = formEditJSON.getFieldId();
536 if (rdef.getFormFieldList() != null) {
537 for (FormFieldType fft : rdef.getFormFieldList().getFormField()) {
538 if (fft.getFieldId().equals(fieldId)) {
539 fft.setFieldName(formEditJSON.getFieldName());
540 fft.setFieldType(formEditJSON.getFieldType());
541 fft.setVisible(formEditJSON.isVisible() ? "Y" : "N");
542 fft.setDefaultValue(formEditJSON.getDefaultValue());
543 fft.setFieldDefaultSQL(formEditJSON.getFieldDefaultSQL());
544 fft.setFieldSQL(formEditJSON.getFieldSQL());
545 fft.setValidationType(formEditJSON.getValidationType());
547 // clear predefined value
548 if (fft.getPredefinedValueList() != null) {
549 for (Iterator iter = fft.getPredefinedValueList().getPredefinedValue()
550 .iterator(); iter.hasNext();)
554 List<IdNameBooleanJSON> predefList = formEditJSON.getPredefinedValueList();
555 for (IdNameBooleanJSON item : predefList) {
556 PredefinedValueList predefinedValueList = new ObjectFactory()
557 .createPredefinedValueList();
558 fft.setPredefinedValueList(predefinedValueList);
559 fft.getPredefinedValueList().getPredefinedValue().add(item.getId());
567 persistReportDefinition(request, rdef);
568 messageJSON.setMessage("Success formfield Details of given report is saved in session.");
569 messageJSON.setAnyStacktrace(rdef.getReportID() + " is Modified and added to session and DB.");
571 /* ObjectMapper mapper = new ObjectMapper();
572 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
573 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
574 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
575 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
578 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(messageJSON);
579 } catch (Exception ex1) {
580 ex1.printStackTrace();
583 messageJSON.setMessage("Report Definition is not in session");
584 messageJSON.setAnyStacktrace("Report Definition is not in session");
586 /* ObjectMapper mapper = new ObjectMapper();
587 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
588 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
589 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
590 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
593 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
594 } catch (Exception ex1) {
595 ex1.printStackTrace();
598 } catch (Exception ex) {
600 messageJSON.setMessage("Error occured while formfield details Tab");
601 messageJSON.setAnyStacktrace(getStackTrace(ex));
603 /* ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
604 errorJSONRuntime.setErrormessage("Error occured while formfield column details Tab");
605 errorJSONRuntime.setStacktrace(getStackTrace(ex));
607 ObjectMapper mapper = new ObjectMapper();
608 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
609 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
610 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
611 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
614 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
615 } catch (Exception ex1) {
616 ex1.printStackTrace();
625 @RequestMapping(value = "report/wizard/save_col_tab_data", method = RequestMethod.POST)
626 public MessageJSON saveColTabWiseData(@RequestBody ColumnEditJSON columnEditJSON, HttpServletRequest request,
627 HttpServletResponse response) throws IOException, RaptorException {
628 ReportDefinition rdef = null;
629 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
631 //String errorString = "";
632 //String jsonInString = "";
633 //PrintWriter out = response.getWriter();
634 MessageJSON messageJSON = new MessageJSON();
638 String colId = columnEditJSON.getColId();
639 List<DataColumnType> reportColumnList = rdef.getAllColumns();
641 for (DataColumnType reportColumnType : reportColumnList) {
642 // columnJSON = new ColumnJSON();
643 if (reportColumnType.getColId().equals(colId)) {
644 reportColumnType.setColName(columnEditJSON.getColName());
645 reportColumnType.setDisplayAlignment(columnEditJSON.getDisplayAlignment());
646 reportColumnType.setDisplayHeaderAlignment(columnEditJSON.getDisplayHeaderAlignment());
647 reportColumnType.setIsSortable(columnEditJSON.isSortable());
648 reportColumnType.setVisible(columnEditJSON.isVisible());
649 reportColumnType.setDrillDownURL(columnEditJSON.getDrilldownURL());
650 reportColumnType.setDrillDownParams(columnEditJSON.getDrilldownParams());
651 reportColumnType.setDrillDownType(columnEditJSON.getDrilldownType());
656 persistReportDefinition(request, rdef);
657 messageJSON.setMessage("Success Column Details of given report is saved in session.");
658 messageJSON.setAnyStacktrace(rdef.getReportID() + " is Modified and added to session and DB.");
660 /* ObjectMapper mapper = new ObjectMapper();
661 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
662 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
663 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
664 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
667 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(messageJSON);
668 } catch (Exception ex1) {
669 ex1.printStackTrace();
673 messageJSON.setMessage("Report Definition is not in session");
674 messageJSON.setAnyStacktrace("");
676 /* ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
677 errorJSONRuntime.setErrormessage("Report Definition is not in session;");
678 errorJSONRuntime.setStacktrace("");
680 ObjectMapper mapper = new ObjectMapper();
681 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
682 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
683 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
684 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
687 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
688 } catch (Exception ex1) {
689 ex1.printStackTrace();
692 } catch (Exception ex) {
693 messageJSON.setMessage("Error occured while saving column details Tab");
694 messageJSON.setAnyStacktrace(getStackTrace(ex));
696 /* ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
697 errorJSONRuntime.setErrormessage("Error occured while saving column details Tab");
698 errorJSONRuntime.setStacktrace(getStackTrace(ex));
700 ObjectMapper mapper = new ObjectMapper();
701 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
702 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
703 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
704 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
707 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
708 } catch (Exception ex1) {
709 ex1.printStackTrace();
718 @RequestMapping(value = "report/wizard/save_def_tab_data/{id}", method = RequestMethod.POST)
719 public MessageJSON saveDefTabWiseData(@PathVariable("id") String id, @RequestBody DefinitionJSON definitionJSON,
720 HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException {
721 ReportDefinition rdef = null;
722 ReportRuntime rr = null;
723 String tabId = definitionJSON.getTabId();
724 String errorString = "";
725 boolean newReport = false;
726 //String jsonInString = "";
727 //PrintWriter out = response.getWriter();
728 MessageJSON messageJSON = new MessageJSON();
733 * rdef = (ReportDefinition) request.getSession().getAttribute(
734 * AppConstants.SI_REPORT_DEFINITION); if(rdef!=null) { rdef = (new
735 * ReportHandler()).loadReportDefinition(request, id); } else {
738 if (id.equals("InSession")) {
739 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
742 } else if (id.equals("Create")) {
743 removeVariablesFromSession(request);
744 rdef = (new ReportHandler()).loadReportDefinition(request, "-1");
746 System.out.println("&&&&&&&&&&&&&&&&&&&&&& CHECK Report Type " + (AppUtils.nvl(rdef.getReportType()).length()<=0));
747 if(AppUtils.nvl(rdef.getReportType()).length()<=0) {
748 rdef.setReportType(AppConstants.RT_LINEAR);
749 System.out.println("&&&&&&&&&&&&&&&&&&&&&& ADDED Report Type in session ");
753 } else if (AppUtils.nvl(id).length() > 0) {
754 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
755 rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
757 if (rdef != null && !rdef.getReportID().equals(id)) {
758 request.getSession().removeAttribute(AppConstants.SI_REPORT_DEFINITION);
759 removeVariablesFromSession(request);
760 rdef = (new ReportHandler()).loadReportDefinition(request, id);
761 } else if (rr != null && !rr.getReportID().equals(id)) {
762 request.getSession().removeAttribute(AppConstants.SI_REPORT_RUNTIME);
763 removeVariablesFromSession(request);
764 rdef = (new ReportHandler()).loadReportDefinition(request, id);
765 } else if (rdef == null) {
766 rdef = (new ReportHandler()).loadReportDefinition(request, id);
771 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
777 String reportName = definitionJSON.getReportName();
778 if (AppUtils.nvl(reportName).length() <= 0)
779 errorString = "ReportName cannot be null;";
780 rdef.setReportName(reportName);
782 String reportDescr = definitionJSON.getReportDescr();
783 rdef.setReportDescr(reportDescr);
785 String formHelpText = definitionJSON.getFormHelpText();
786 rdef.setFormHelpText(formHelpText);
788 Integer pageSize = definitionJSON.getPageSize();
789 rdef.setPageSize(pageSize);
791 List<IdNameBooleanJSON> menuIds = definitionJSON.getDisplayArea();
792 for (IdNameBooleanJSON menuId : menuIds) {
793 if (menuId.isSelected()) {
794 rdef.setMenuID(menuId.getName());
799 Boolean hideFormFieldsAfterRun = definitionJSON.getHideFormFieldsAfterRun();
800 rdef.setHideFormFieldAfterRun(hideFormFieldsAfterRun);
801 Integer maxRowsInExcelCSVDownload = definitionJSON.getMaxRowsInExcelCSVDownload();
802 rdef.setMaxRowsInExcelDownload(maxRowsInExcelCSVDownload);
803 Integer frozenColumns = definitionJSON.getFrozenColumns();
804 rdef.setFrozenColumns(frozenColumns);
805 String dataGridAlign = definitionJSON.getDataGridAlign();
806 rdef.setDataGridAlign(dataGridAlign);
807 String emptyMessage = definitionJSON.getEmptyMessage();
808 rdef.setEmptyMessage(emptyMessage);
809 String dataContainerHeight = definitionJSON.getDataContainerHeight();
810 rdef.setDataContainerHeight(dataContainerHeight);
811 String dataContainerWidth = definitionJSON.getDataContainerWidth();
812 rdef.setDataContainerWidth(dataContainerWidth);
813 boolean runtimeColSortDisabled = definitionJSON.getRuntimeColSortDisabled();
814 rdef.setRuntimeColSortDisabled(runtimeColSortDisabled);
815 Integer numFormCols = definitionJSON.getNumFormCols();
816 rdef.setNumFormCols(Integer.toString(numFormCols));
817 String reportTitle = definitionJSON.getReportTitle();
818 rdef.setReportTitle(reportTitle);
819 String reportSubTitle = definitionJSON.getReportSubTitle();
820 rdef.setReportSubTitle(reportSubTitle);
822 List<NameBooleanJSON> displayOptions = definitionJSON.getDisplayOptions();
823 StringBuffer displayOptionStr = new StringBuffer("NNNNNNN");
824 for (NameBooleanJSON displayOption : displayOptions) {
825 if (displayOption.isSelected()) {
826 if (displayOption.getName().equals("HideFormFields")) {
827 displayOptionStr.setCharAt(0, 'Y');
828 } else if (displayOption.getName().equals("HideChart")) {
829 displayOptionStr.setCharAt(1, 'Y');
830 } else if (displayOption.getName().equals("HideReportData")) {
831 displayOptionStr.setCharAt(2, 'Y');
832 } else if (displayOption.getName().equals("HideExcel")) {
833 displayOptionStr.setCharAt(5, 'Y');
834 } else if (displayOption.getName().equals("HidePdf")) {
835 displayOptionStr.setCharAt(6, 'Y');
841 rdef.setDisplayOptions(displayOptionStr.toString());
843 persistReportDefinition(request, rdef);
844 messageJSON.setMessage("Success Definition of given report is saved in session.");
845 messageJSON.setAnyStacktrace((newReport ? " New Report info is added to Session "
846 : rdef.getReportID() + " is Modified and added to session and DB."));
848 /* ObjectMapper mapper = new ObjectMapper();
849 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
850 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
851 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
852 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
855 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(messageJSON);
856 } catch (Exception ex1) {
857 ex1.printStackTrace();
859 */ } catch (Exception ex) {
860 messageJSON.setMessage("Error occured while saving definition Tab");
861 messageJSON.setAnyStacktrace(getStackTrace(ex));
863 /* ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
864 errorJSONRuntime.setErrormessage("Error occured while saving definition Tab");
865 errorJSONRuntime.setStacktrace(getStackTrace(ex));
867 ObjectMapper mapper = new ObjectMapper();
868 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
869 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
870 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
871 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
874 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
875 } catch (Exception ex1) {
876 ex1.printStackTrace();
885 /* @RequestMapping(value = "report/wizard/save_tab_wise_data/{reportID}", method = RequestMethod.POST)
886 public void saveTabWiseData(@PathVariable("reportID") String reportID, @RequestBody WizardJSON wizardJSON,
887 HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException {
888 ReportDefinition rdef = null;
889 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
891 rdef = (new ReportHandler()).loadReportDefinition(request, reportID);
893 System.out.println("&&&&&&&&&&&&&&&&&&&&&& CHECK Report Type " + (AppUtils.nvl(rdef.getReportType()).length()<=0));
894 if(AppUtils.nvl(rdef.getReportType()).length()<=0) {
895 rdef.setReportType(AppConstants.RT_LINEAR);
896 System.out.println("&&&&&&&&&&&&&&&&&&&&&& ADDED Report Type in session ");
898 // ReportDefinition rdef = (ReportDefinition)
899 // request.getSession().getAttribute(
900 // AppConstants.SI_REPORT_DEFINITION);
901 String tabId = wizardJSON.getTabId();
902 String errorString = "";
904 if (tabId.equals("Def")) {
905 String reportName = ((DefinitionJSON) wizardJSON).getReportName();
906 if (AppUtils.nvl(reportName).length() <= 0)
907 errorString = "ReportName cannot be null;";
908 rdef.setReportName(reportName);
910 String reportDescr = ((DefinitionJSON) wizardJSON).getReportDescr();
911 rdef.setReportDescr(reportDescr);
913 String formHelpText = ((DefinitionJSON) wizardJSON).getFormHelpText();
914 rdef.setFormHelpText(formHelpText);
916 Integer pageSize = ((DefinitionJSON) wizardJSON).getPageSize();
917 rdef.setPageSize(pageSize);
919 List<IdNameBooleanJSON> menuIds = ((DefinitionJSON) wizardJSON).getDisplayArea();
920 for (IdNameBooleanJSON menuId : menuIds) {
921 if (menuId.isSelected()) {
922 rdef.setMenuID(menuId.getName());
927 Boolean hideFormFieldsAfterRun = ((DefinitionJSON) wizardJSON).getHideFormFieldsAfterRun();
928 rdef.setHideFormFieldAfterRun(hideFormFieldsAfterRun);
929 Integer maxRowsInExcelCSVDownload = ((DefinitionJSON) wizardJSON).getMaxRowsInExcelCSVDownload();
930 rdef.setMaxRowsInExcelDownload(maxRowsInExcelCSVDownload);
931 Integer frozenColumns = ((DefinitionJSON) wizardJSON).getFrozenColumns();
932 rdef.setFrozenColumns(frozenColumns);
933 String dataGridAlign = ((DefinitionJSON) wizardJSON).getDataGridAlign();
934 rdef.setDataGridAlign(dataGridAlign);
935 String emptyMessage = ((DefinitionJSON) wizardJSON).getEmptyMessage();
936 rdef.setEmptyMessage(emptyMessage);
937 String dataContainerHeight = ((DefinitionJSON) wizardJSON).getDataContainerHeight();
938 rdef.setDataContainerHeight(dataContainerHeight);
939 String dataContainerWidth = ((DefinitionJSON) wizardJSON).getDataContainerWidth();
940 rdef.setDataContainerWidth(dataContainerWidth);
941 boolean runtimeColSortDisabled = ((DefinitionJSON) wizardJSON).getRuntimeColSortDisabled();
942 rdef.setRuntimeColSortDisabled(runtimeColSortDisabled);
943 Integer numFormCols = ((DefinitionJSON) wizardJSON).getNumFormCols();
944 rdef.setNumFormCols(Integer.toString(numFormCols));
945 String reportTitle = ((DefinitionJSON) wizardJSON).getReportTitle();
946 rdef.setReportTitle(reportTitle);
947 String reportSubTitle = ((DefinitionJSON) wizardJSON).getReportSubTitle();
948 rdef.setReportSubTitle(reportSubTitle);
950 List<NameBooleanJSON> displayOptions = ((DefinitionJSON) wizardJSON).getDisplayOptions();
951 StringBuffer displayOptionStr = new StringBuffer("NNNNNNN");
952 for (NameBooleanJSON displayOption : displayOptions) {
953 if (displayOption.isSelected()) {
954 if (displayOption.getName().equals("HideFormFields")) {
955 displayOptionStr.setCharAt(0, 'Y');
956 } else if (displayOption.getName().equals("HideChart")) {
957 displayOptionStr.setCharAt(1, 'Y');
958 } else if (displayOption.getName().equals("HideReportData")) {
959 displayOptionStr.setCharAt(2, 'Y');
960 } else if (displayOption.getName().equals("HideExcel")) {
961 displayOptionStr.setCharAt(5, 'Y');
962 } else if (displayOption.getName().equals("HidePdf")) {
963 displayOptionStr.setCharAt(6, 'Y');
969 rdef.setDisplayOptions(displayOptionStr.toString());
971 } else if (tabId.equals("ColEdit")) {
972 String colId = ((ColumnEditJSON) wizardJSON).getColId();
973 List<DataColumnType> reportColumnList = rdef.getAllColumns();
975 for (DataColumnType reportColumnType : reportColumnList) {
976 // columnJSON = new ColumnJSON();
977 if (reportColumnType.getColId().equals(colId)) {
978 reportColumnType.setColName(((ColumnEditJSON) wizardJSON).getColName());
979 reportColumnType.setDisplayAlignment(((ColumnEditJSON) wizardJSON).getDisplayAlignment());
981 .setDisplayHeaderAlignment(((ColumnEditJSON) wizardJSON).getDisplayHeaderAlignment());
982 reportColumnType.setIsSortable(((ColumnEditJSON) wizardJSON).isSortable());
983 reportColumnType.setVisible(((ColumnEditJSON) wizardJSON).isVisible());
984 reportColumnType.setDrillDownURL(((ColumnEditJSON) wizardJSON).getDrilldownURL());
985 reportColumnType.setDrillDownParams(((ColumnEditJSON) wizardJSON).getDrilldownParams());
986 reportColumnType.setDrillDownType(((ColumnEditJSON) wizardJSON).getDrilldownType());
991 } else if (tabId.equals("FormEdit")) {
992 String fieldId = ((FormEditJSON) wizardJSON).getFieldId();
994 if (rdef.getFormFieldList() != null) {
995 for (FormFieldType fft : rdef.getFormFieldList().getFormField()) {
996 if (fft.getFieldId().equals(fieldId)) {
997 fft.setFieldName(((FormEditJSON) wizardJSON).getFieldName());
998 fft.setFieldType(((FormEditJSON) wizardJSON).getFieldType());
999 fft.setVisible(((FormEditJSON) wizardJSON).isVisible() ? "Y" : "N");
1000 fft.setDefaultValue(((FormEditJSON) wizardJSON).getDefaultValue());
1001 fft.setFieldDefaultSQL(((FormEditJSON) wizardJSON).getFieldDefaultSQL());
1002 fft.setValidationType(((FormEditJSON) wizardJSON).getValidationType());
1004 // clear predefined value
1005 if (fft.getPredefinedValueList() != null) {
1006 for (Iterator iter = fft.getPredefinedValueList().getPredefinedValue().iterator(); iter
1011 List<IdNameBooleanJSON> predefList = ((FormEditJSON) wizardJSON).getPredefinedValueList();
1012 for (IdNameBooleanJSON item : predefList) {
1013 PredefinedValueList predefinedValueList = new ObjectFactory()
1014 .createPredefinedValueList();
1015 fft.setPredefinedValueList(predefinedValueList);
1016 fft.getPredefinedValueList().getPredefinedValue().add(item.getId());
1023 persistReportDefinition(request, rdef);
1025 String jsonInString = "";
1027 ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
1028 errorJSONRuntime.setErrormessage("Success");
1029 errorJSONRuntime.setStacktrace("Report changed");
1030 PrintWriter out = response.getWriter();
1031 ObjectMapper mapper = new ObjectMapper();
1032 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
1033 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
1034 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
1035 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1038 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
1039 } catch (Exception ex) {
1040 ex.printStackTrace();
1043 out.write(jsonInString);
1048 @RequestMapping(value = {"/report/wizard/retrieve_tab_wise_data/{tabId}/{id}", "/report/wizard/retrieve_tab_wise_data/{tabId}/{id}/{detailId}"}, method = RequestMethod.GET)
1049 public @ResponseBody String retrieveTabWiseData( @PathVariable Map<String, String> pathVariables, /*@PathVariable("tabId") String tabId, @PathVariable("id") String id, @PathVariable("detailId") String detailId,*/
1050 HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException {
1051 ReportDefinition rdef = null;
1052 ReportRuntime rr = null;
1053 boolean newReport = false;
1054 String jsonInString = "";
1057 String detailId = "";
1059 if (pathVariables.containsKey("tabId")) {
1060 tabId = pathVariables.get("tabId");
1062 if (pathVariables.containsKey("id")) {
1063 id = pathVariables.get("id");
1065 if (pathVariables.containsKey("detailId")) {
1066 detailId = pathVariables.get("detailId");
1070 ServletContext servletContext = request.getSession().getServletContext();
1071 if (!Globals.isSystemInitialized()) {
1072 Globals.initializeSystem(servletContext);
1075 if (tabId.equals("Def") && id.equals("InSession")) {
1076 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1079 } else if (tabId.equals("Def") && id.equals("Create")) {
1080 removeVariablesFromSession(request);
1081 rdef = (new ReportHandler()).loadReportDefinition(request, "-1");
1082 rdef.setReportType(AppConstants.RT_LINEAR);
1085 } else if (tabId.equals("Def") && AppUtils.nvl(id).length() > 0) {
1086 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1087 rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
1089 if (rdef != null && !rdef.getReportID().equals(id)) {
1090 request.getSession().removeAttribute(AppConstants.SI_REPORT_DEFINITION);
1091 removeVariablesFromSession(request);
1092 rdef = (new ReportHandler()).loadReportDefinition(request, id);
1093 } else if (rr != null && !rr.getReportID().equals(id)) {
1094 request.getSession().removeAttribute(AppConstants.SI_REPORT_RUNTIME);
1095 removeVariablesFromSession(request);
1096 rdef = (new ReportHandler()).loadReportDefinition(request, id);
1097 } else if (rdef == null) {
1098 rdef = (new ReportHandler()).loadReportDefinition(request, id);
1103 rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1105 WizardJSON wizardJSON = null;
1106 if (tabId.equals("Def")) {
1107 wizardJSON = new DefinitionJSON();
1108 ((DefinitionJSON) wizardJSON).setTabId("Def");
1109 ((DefinitionJSON) wizardJSON).setTabName("Definition");
1111 ((DefinitionJSON) wizardJSON).setReportId((rdef != null) ? rdef.getReportID() + "" : "");
1112 ((DefinitionJSON) wizardJSON).setReportName((rdef != null) ? rdef.getReportName() : "");
1113 ((DefinitionJSON) wizardJSON).setReportDescr((rdef != null) ? rdef.getReportDescr() : "");
1114 ((DefinitionJSON) wizardJSON).setReportType((rdef != null) ? rdef.getReportType() : AppConstants.RT_LINEAR);
1115 ((DefinitionJSON) wizardJSON).setDbInfo((rdef != null) ? rdef.getDBInfo() : "");
1116 ((DefinitionJSON) wizardJSON).setFormHelpText((rdef != null) ? rdef.getFormHelpText() : "");
1117 ((DefinitionJSON) wizardJSON).setPageSize((rdef != null) ? rdef.getPageSize() : 50);
1118 List<IdNameBooleanJSON> displayArea = new ArrayList<IdNameBooleanJSON>();
1119 IdNameBooleanJSON idNameJSON = new IdNameBooleanJSON();
1121 for (int i = 0; i < AppUtils.getQuickLinksMenuIDs().size(); i++) {
1122 idNameJSON = new IdNameBooleanJSON();
1123 qMenu = (String) AppUtils.getQuickLinksMenuIDs().get(i);
1124 idNameJSON.setId(qMenu);
1125 idNameJSON.setName(qMenu);
1126 if (rdef != null && (rdef.getMenuID().equals(qMenu))) {
1127 idNameJSON.setSelected(true);
1129 displayArea.add(idNameJSON);
1131 ((DefinitionJSON) wizardJSON).setDisplayArea(displayArea);
1132 ((DefinitionJSON) wizardJSON)
1133 .setHideFormFieldsAfterRun((rdef != null) ? rdef.isHideFormFieldAfterRun() : false);
1134 ((DefinitionJSON) wizardJSON)
1135 .setMaxRowsInExcelCSVDownload((rdef != null) ? rdef.getMaxRowsInExcelDownload() : 500);
1136 ((DefinitionJSON) wizardJSON).setFrozenColumns((rdef != null) ? rdef.getFrozenColumns() : 0);
1137 ((DefinitionJSON) wizardJSON).setDataGridAlign((rdef != null) ? rdef.getDataGridAlign() : "left");
1138 ((DefinitionJSON) wizardJSON).setEmptyMessage((rdef != null) ? rdef.getEmptyMessage() : "No records found");
1139 ((DefinitionJSON) wizardJSON)
1140 .setDataContainerHeight((rdef != null) ? rdef.getDataContainerHeight() : "600");
1141 ((DefinitionJSON) wizardJSON).setDataContainerWidth((rdef != null) ? rdef.getDataContainerWidth() : "900");
1142 List<NameBooleanJSON> displayOptions = new ArrayList<NameBooleanJSON>();
1143 NameBooleanJSON nameBooleanJSON = new NameBooleanJSON();
1144 nameBooleanJSON.setName("HideFormFields");
1145 nameBooleanJSON.setSelected((rdef != null) ? rdef.isDisplayOptionHideForm() : false);
1146 displayOptions.add(nameBooleanJSON);
1148 nameBooleanJSON = new NameBooleanJSON();
1149 nameBooleanJSON.setName("HideChart");
1150 nameBooleanJSON.setSelected((rdef != null) ? rdef.isDisplayOptionHideChart() : false);
1151 displayOptions.add(nameBooleanJSON);
1153 nameBooleanJSON = new NameBooleanJSON();
1154 nameBooleanJSON.setName("HideReportData");
1155 nameBooleanJSON.setSelected((rdef != null) ? rdef.isDisplayOptionHideData() : false);
1156 displayOptions.add(nameBooleanJSON);
1158 nameBooleanJSON = new NameBooleanJSON();
1159 nameBooleanJSON.setName("HideExcel");
1160 nameBooleanJSON.setSelected((rdef != null) ? rdef.isDisplayOptionHideExcelIcons() : false);
1161 displayOptions.add(nameBooleanJSON);
1163 nameBooleanJSON = new NameBooleanJSON();
1164 nameBooleanJSON.setName("HidePdf");
1165 nameBooleanJSON.setSelected((rdef != null) ? rdef.isDisplayOptionHidePDFIcons() : false);
1166 displayOptions.add(nameBooleanJSON);
1168 ((DefinitionJSON) wizardJSON).setDisplayOptions(displayOptions);
1170 ((DefinitionJSON) wizardJSON)
1171 .setRuntimeColSortDisabled((rdef != null) ? rdef.isRuntimeColSortDisabled() : false);
1172 ((DefinitionJSON) wizardJSON).setNumFormCols((rdef != null) ? rdef.getNumFormColsAsInt() : 1);
1173 ((DefinitionJSON) wizardJSON).setReportTitle((rdef != null) ? rdef.getReportTitle() : "");
1174 ((DefinitionJSON) wizardJSON).setReportSubTitle((rdef != null) ? rdef.getReportSubTitle() : "");
1176 } else if (tabId.equals("Sql")) {
1177 wizardJSON = new QueryJSON();
1178 ((QueryJSON) wizardJSON).setTabId("Sql");
1179 ((QueryJSON) wizardJSON).setTabName("Sql");
1180 ((QueryJSON) wizardJSON).setQuery(rdef.getReportSQL());
1182 } else if (tabId.equals("ColEdit") && rdef != null) {
1183 // wizardJSON = new QueryJSON();
1185 // wizardJSON).setQuery((rdef!=null)?rdef.getReportSQL():"");
1186 wizardJSON = new ColumnEditJSON();
1187 ((ColumnEditJSON) wizardJSON).setTabId("ColEdit");
1188 ((ColumnEditJSON) wizardJSON).setTabName("Column Edit");
1190 List<DataColumnType> reportColumnList = rdef.getAllColumns();
1192 for (DataColumnType reportColumnType : reportColumnList) {
1193 // columnJSON = new ColumnJSON();
1194 if (reportColumnType.getColId().equals(id)) {
1195 ((ColumnEditJSON) wizardJSON).setColId(reportColumnType.getColId());
1196 ((ColumnEditJSON) wizardJSON).setColName(reportColumnType.getColName());
1197 ((ColumnEditJSON) wizardJSON).setDisplayAlignment(reportColumnType.getDisplayAlignment());
1198 ((ColumnEditJSON) wizardJSON)
1199 .setDisplayHeaderAlignment(reportColumnType.getDisplayHeaderAlignment());
1200 ((ColumnEditJSON) wizardJSON).setSortable(
1201 reportColumnType.isIsSortable() == null ? false : reportColumnType.isIsSortable());
1202 ((ColumnEditJSON) wizardJSON).setVisible(reportColumnType.isVisible());
1203 ((ColumnEditJSON) wizardJSON).setDrilldownURL(
1204 reportColumnType.getDrillDownURL() == null ? "" : reportColumnType.getDrillDownURL());
1205 ((ColumnEditJSON) wizardJSON).setDrilldownParams(
1206 reportColumnType.getDrillDownParams() == null ? "" : reportColumnType.getDrillDownParams());
1207 ((ColumnEditJSON) wizardJSON).setDrilldownType(
1208 reportColumnType.getDrillDownType() == null ? "" : reportColumnType.getDrillDownType());
1213 } else if (tabId.equals("FormEdit") && rdef != null) {
1214 wizardJSON = new FormEditJSON();
1215 ((FormEditJSON) wizardJSON).setTabId("FormEdit");
1216 ((FormEditJSON) wizardJSON).setTabName("Form Edit");
1217 FormFieldType currField = null;
1219 if (id.equals("add")) {
1221 currField = rdef.addFormFieldType(new ObjectFactory(), "", "", "", "", "", "", "", "", null, null, "",
1223 ((FormEditJSON) wizardJSON).setFieldId(currField.getFieldId());
1224 ((FormEditJSON) wizardJSON).setFieldName(currField.getFieldName());
1225 ((FormEditJSON) wizardJSON).setFieldType(currField.getFieldType());
1226 ((FormEditJSON) wizardJSON).setVisible(currField.getVisible().toUpperCase().startsWith("Y"));
1227 ((FormEditJSON) wizardJSON).setDefaultValue(currField.getDefaultValue());
1228 ((FormEditJSON) wizardJSON).setFieldDefaultSQL(currField.getFieldDefaultSQL());
1229 ((FormEditJSON) wizardJSON).setFieldSQL(currField.getFieldSQL());
1230 ((FormEditJSON) wizardJSON).setValidationType(currField.getValidationType());
1232 } else if (id.equals("delete")) {
1233 rdef.deleteFormField(detailId);
1234 persistReportDefinition(request, rdef);
1235 MessageJSON messageJSON = new MessageJSON();
1236 messageJSON.setMessage("Formfield " + detailId+ " Deleted");
1237 messageJSON.setAnyStacktrace("Given formfield deleted");
1239 ObjectMapper mapper = new ObjectMapper();
1240 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
1241 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
1242 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
1243 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1246 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(messageJSON);
1247 } catch (Exception ex1) {
1248 ex1.printStackTrace();
1253 if (rdef.getFormFieldList() != null) {
1254 for (FormFieldType fft : rdef.getFormFieldList().getFormField()) {
1255 if (fft.getFieldId().equals(id)) {
1256 ((FormEditJSON) wizardJSON).setFieldId(fft.getFieldId());
1257 ((FormEditJSON) wizardJSON).setFieldName(fft.getFieldName());
1258 ((FormEditJSON) wizardJSON).setFieldType(fft.getFieldType());
1259 ((FormEditJSON) wizardJSON).setVisible(fft.getVisible().toUpperCase().startsWith("Y"));
1260 ((FormEditJSON) wizardJSON).setDefaultValue(fft.getDefaultValue());
1261 ((FormEditJSON) wizardJSON).setFieldDefaultSQL(fft.getFieldDefaultSQL());
1262 ((FormEditJSON) wizardJSON).setFieldSQL(fft.getFieldSQL());
1263 ((FormEditJSON) wizardJSON).setValidationType(fft.getValidationType());
1265 PredefinedValueList preDefined = fft.getPredefinedValueList();
1267 if (preDefined != null) {
1268 List<IdNameBooleanJSON> preDefinedList = new ArrayList<IdNameBooleanJSON>();
1269 IdNameBooleanJSON idNameBooleanJSON = new IdNameBooleanJSON();
1271 for (String v : preDefined.getPredefinedValue()) {
1272 idNameBooleanJSON = new IdNameBooleanJSON();
1273 idNameBooleanJSON.setId(v);
1274 idNameBooleanJSON.setName(v);
1275 preDefinedList.add(idNameBooleanJSON);
1277 ((FormEditJSON) wizardJSON).setPredefinedValueList(preDefinedList);
1282 } catch (Exception ex) {
1283 ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
1284 errorJSONRuntime.setErrormessage("Error occured while retreiving formedit definition Tab");
1285 errorJSONRuntime.setStacktrace(getStackTrace(ex));
1287 ObjectMapper mapper = new ObjectMapper();
1288 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
1289 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
1290 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
1291 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1294 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
1295 } catch (Exception ex1) {
1296 ex1.printStackTrace();
1304 //PrintWriter out = response.getWriter();
1305 ObjectMapper mapper = new ObjectMapper();
1306 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
1307 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
1308 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
1309 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1312 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(wizardJSON);
1313 } catch (Exception ex) {
1314 ex.printStackTrace();
1316 return jsonInString;
1319 @RequestMapping(value = "/report/wizard/retrieve_data/{validate}", method = RequestMethod.POST)
1320 public String retrieveDataForGivenQuery(@PathVariable("validate") boolean validate, @RequestBody QueryJSON queryJSON, HttpServletRequest request,
1321 HttpServletResponse response) throws IOException, RaptorException {
1322 String sql = queryJSON.getQuery();
1323 String jsonInString = "";
1324 //PrintWriter out = response.getWriter();
1326 ServletContext servletContext = request.getSession().getServletContext();
1327 if (!Globals.isSystemInitialized()) {
1328 Globals.initializeSystem(servletContext);
1331 ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION);
1333 ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
1334 errorJSONRuntime.setErrormessage("Report Definition is not in session;");
1335 errorJSONRuntime.setStacktrace("");
1337 ObjectMapper mapper = new ObjectMapper();
1338 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
1339 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
1340 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
1341 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1344 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
1345 } catch (Exception ex1) {
1346 ex1.printStackTrace();
1349 if (!sql.trim().toUpperCase().startsWith("SELECT")) {
1350 ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
1351 errorJSONRuntime.setErrormessage("Invalid statement - the SQL must start with the keyword SELECT");
1352 errorJSONRuntime.setStacktrace("SQL Error");
1353 ObjectMapper mapper = new ObjectMapper();
1354 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
1355 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
1356 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
1357 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1360 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
1361 } catch (Exception ex) {
1362 ex.printStackTrace();
1367 String remoteDb = request.getParameter("remoteDbPrefix");
1368 // comment below two lines to test
1369 String remoteDbPrefix = (remoteDb != null && !remoteDb.equalsIgnoreCase("null")) ? remoteDb
1371 String userId = AppUtils.getUserID(request);
1372 // String userId = "1";
1373 sql = Utils.replaceInString(sql, "[LOGGED_USERID]", userId);
1374 sql = Utils.replaceInString(sql, "[USERID]", userId);
1375 String[] reqParameters = Globals.getRequestParams().split(",");
1376 String[] sessionParameters = Globals.getSessionParams().split(",");
1377 javax.servlet.http.HttpSession session = request.getSession();
1378 logger.debug(EELFLoggerDelegate.debugLogger, ("B4 testRunSQL " + sql));
1379 if (request != null) {
1380 for (int i = 0; i < reqParameters.length; i++) {
1381 if (!reqParameters[i].startsWith("ff"))
1382 sql = Utils.replaceInString(sql, "[" + reqParameters[i].toUpperCase() + "]",
1383 request.getParameter(reqParameters[i].toUpperCase()));
1385 sql = Utils.replaceInString(sql, "[" + reqParameters[i].toUpperCase() + "]",
1386 request.getParameter(reqParameters[i]));
1389 if (session != null) {
1390 for (int i = 0; i < sessionParameters.length; i++) {
1391 // if(!sessionParameters[i].startsWith("ff"))
1392 // sql = Utils.replaceInString(sql, "[" +
1393 // sessionParameters[i].toUpperCase()+"]",
1394 // (String)session.getAttribute(sessionParameters[i].toUpperCase())
1397 logger.debug(EELFLoggerDelegate.debugLogger, (" Session " + " sessionParameters[i] "
1398 + sessionParameters[i] + " " + (String) session.getAttribute(sessionParameters[i])));
1399 sql = Utils.replaceInString(sql, "[" + sessionParameters[i].toUpperCase() + "]",
1400 (String) session.getAttribute(sessionParameters[i]));
1404 logger.debug(EELFLoggerDelegate.debugLogger, ("After testRunSQL " + sql));
1407 response.setContentType("application/json");
1408 ds = ConnectionUtils.getDataSet(sql, "local", true);
1410 * SimpleModule module = new SimpleModule();
1411 * module.addSerializer(new ResultSetSerializer());
1413 * ObjectMapper objectMapper = new ObjectMapper();
1414 * objectMapper.registerModule(module);
1416 * ObjectNode objectNode = objectMapper.createObjectNode();
1417 * objectNode.putPOJO("results", ds);
1419 * objectMapper.writeValue(writer, objectNode);
1422 QueryResultJSON queryResultJSON = new QueryResultJSON();
1423 queryResultJSON.setQuery(queryJSON.getQuery());
1425 int numColumns = ds.getColumnCount();
1426 queryResultJSON.setTotalRows(ds.getRowCount());
1429 Map<String, String> dvJSON = null;
1430 ArrayList<String> colList = new ArrayList<String>();
1431 ArrayList<Map<String, String>> reportDataRows = new ArrayList<Map<String, String>>();
1432 if (!ds.isEmpty()) {
1435 for (int i = 0; i < ds.getColumnCount(); i++) {
1436 colList.add(ds.getColumnName(i));
1438 queryResultJSON.setReportDataColumns(colList);
1439 if (queryResultJSON.getTotalRows() > 0) {
1441 dvJSON = new HashMap<String, String>();
1442 // for(rd.reportDataRows.resetNext();
1443 // rd.reportDataRows.hasNext(); count++) {
1444 for (int r = 0; r < Math.min(ds.getRowCount(), 100); r++) {
1445 dvJSON = new HashMap<String, String>();
1446 for (int c = 0; c < ds.getColumnCount(); c++) {
1447 // jgen.writeFieldName(columnNames[c]);
1448 // jgen.writeString(ds.getString(r, c));
1450 dvJSON.put(ds.getColumnName(c), ds.getString(r, c));
1451 } catch (Exception ex) {
1452 ex.printStackTrace();
1456 reportDataRows.add(dvJSON);
1462 queryResultJSON.setReportDataRows(reportDataRows);
1463 ObjectMapper mapper = new ObjectMapper();
1464 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
1465 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
1466 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
1467 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1468 // String jsonInString = "";
1470 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(queryResultJSON);
1471 } catch (Exception ex) {
1472 ex.printStackTrace();
1476 // return queryResultJSON;
1478 } catch (ReportSQLException ex) {
1479 ex.printStackTrace();
1480 ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
1481 if(sql.contains("[")) {
1482 errorJSONRuntime.setErrormessage("Formfield information is present in the query, hence couldn't execute");
1483 errorJSONRuntime.setStacktrace("Formfield information is present in the query, hence couldn't execute");
1485 errorJSONRuntime.setErrormessage(ex.getMessage());
1486 errorJSONRuntime.setStacktrace(getStackTrace(ex));
1488 ObjectMapper mapper = new ObjectMapper();
1489 // mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
1490 // mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
1491 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
1492 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1495 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
1496 } catch (Exception ex1) {
1497 ex1.printStackTrace();
1502 String query = XSSFilter.filterRequestOnlyScript(queryJSON.getQuery());
1503 request.setAttribute("sqlValidated", "N");
1504 rdef.parseReportSQL(query);
1505 request.setAttribute("sqlValidated", "Y");
1506 persistReportDefinition(request, rdef);
1512 return jsonInString;
1516 @RequestMapping(value = "save_chart", method = RequestMethod.POST)
1517 public void reportChartReceive(@RequestBody ChartJSON chartJSON, HttpServletRequest request,
1518 HttpServletResponse response) throws IOException {
1519 ReportRuntime reportRuntime;
1520 // System.out.println("*****Hit RaptorChart******");
1522 // System.out.println("chartJSON"+chartJSON.getRangeAxisList());
1523 // System.out.println("chartJSON"+chartJSON.getCommonChartOptions().getLegendPosition());
1524 reportRuntime = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME); // changing
1528 String reportID = request.getParameter("c_master");
1529 if (reportRuntime == null && AppUtils.nvl(reportID).length() > 0) {
1531 ReportHandler rh = new ReportHandler();
1532 reportRuntime = rh.loadReportRuntime(request, reportID);
1533 } catch (RaptorException ex) {
1534 ex.printStackTrace();
1539 if (reportRuntime != null) {
1540 String chartType = chartJSON.getChartType();
1541 reportRuntime.setChartType(chartJSON.getChartType());
1542 reportRuntime.setChartAnimate(chartJSON.isAnimation());
1543 reportRuntime.setChartWidth(chartJSON.getWidth());
1544 reportRuntime.setChartHeight(chartJSON.getHeight());
1545 reportRuntime.setShowChartTitle(chartJSON.isShowTitle());
1547 String domainAxis = null;
1548 domainAxis = chartJSON.getDomainAxis();
1550 List<DataColumnType> reportCols = reportRuntime.getAllColumns();
1552 for (Iterator<DataColumnType> iter = reportCols.iterator(); iter.hasNext();) {
1553 DataColumnType dct = (DataColumnType) iter.next();
1554 if (dct.getColId().equals(domainAxis)) {
1555 dct.setColOnChart(AppConstants.GC_LEGEND);
1557 dct.setColOnChart(null);
1561 CategoryAxisJSON categoryAxisJSON = chartJSON.getCategoryAxisJSON();
1562 String categoryAxis = null;
1564 categoryAxis = (categoryAxisJSON != null ? categoryAxisJSON.getValue() : "");
1566 reportCols = reportRuntime.getAllColumns();
1568 for (Iterator<DataColumnType> iter = reportCols.iterator(); iter.hasNext();) {
1569 DataColumnType dct = (DataColumnType) iter.next();
1570 if (dct.getColId().equals(categoryAxis)) {
1571 dct.setChartSeries(true);
1573 dct.setChartSeries(false);
1577 ArrayList<RangeAxisJSON> rangeAxisList = chartJSON.getRangeAxisList();
1579 for (int i = 0; i < rangeAxisList.size(); i++) {
1580 RangeAxisJSON rangeAxisJSON = rangeAxisList.get(i);
1581 String rangeAxis = rangeAxisJSON.getRangeAxis();
1582 String rangeYAxis = AppUtils.nvl(rangeAxisJSON.getRangeYAxis());
1583 String rangeChartGroup = AppUtils.nvl(rangeAxisJSON.getRangeChartGroup());
1584 String rangeColor = AppUtils.nvl(rangeAxisJSON.getRangeColor());
1585 String rangeLineType = AppUtils.nvl(rangeAxisJSON.getRangeLineType());
1587 rangefor: for (Iterator<DataColumnType> iterator = reportCols.iterator(); iterator.hasNext();) {
1588 DataColumnType dct = (DataColumnType) iterator.next();
1589 if (dct.getColId().equals(rangeAxis)) {
1590 dct.setChartSeq(++r);
1591 dct.setColOnChart("0");
1592 dct.setYAxis(rangeYAxis); // +"|"+dct.getColId());
1593 dct.setChartGroup(rangeChartGroup); // +"|"+dct.getColId());
1594 dct.setChartColor(rangeColor);
1595 dct.setChartLineType(rangeLineType);
1597 if (chartType.equals(AppConstants.GT_ANNOTATION_CHART)
1598 || chartType.equals(AppConstants.GT_FLEX_TIME_CHARTS)) {
1599 if (rangeAxisJSON.isShowAsArea()) {
1600 dct.setIsRangeAxisFilled(true);
1602 dct.setIsRangeAxisFilled(false);
1611 reportRuntime.setChartLeftAxisLabel(chartJSON.getPrimaryAxisLabel());
1612 reportRuntime.setChartRightAxisLabel(chartJSON.getSecondaryAxisLabel());
1614 reportRuntime.setRangeAxisLowerLimit(chartJSON.getMinRange());
1615 reportRuntime.setRangeAxisUpperLimit(chartJSON.getMaxRange());
1617 if (chartType.equals(AppConstants.GT_ANNOTATION_CHART)
1618 || chartType.equals(AppConstants.GT_FLEX_TIME_CHARTS)) {
1619 if (chartJSON.getFlexTimeSeriesChartOptions() != null) {
1620 reportRuntime.setZoomIn(chartJSON.getFlexTimeSeriesChartOptions().getZoomIn());
1621 reportRuntime.setTimeAxisType(chartJSON.getFlexTimeSeriesChartOptions().getTimeAxisType());
1626 if (chartType.equals(AppConstants.GT_TIME_SERIES)) {
1627 if (chartJSON.getTimeSeriesChartOptions() != null) {
1628 reportRuntime.setTimeSeriesRender(chartJSON.getTimeSeriesChartOptions().getLineChartRenderer());
1629 reportRuntime.setShowXAxisLabel(chartJSON.getTimeSeriesChartOptions().isShowXAxisLabel());
1630 reportRuntime.setAddXAxisTickers(chartJSON.getTimeSeriesChartOptions().isAddXAxisTicker());
1631 reportRuntime.setTimeAxis(chartJSON.getTimeSeriesChartOptions().isNonTimeAxis());
1632 reportRuntime.setMultiSeries(chartJSON.getTimeSeriesChartOptions().isMultiSeries());
1637 if (chartType.equals(AppConstants.GT_BAR_3D)) {
1638 if (chartJSON.getBarChartOptions() != null) {
1639 reportRuntime.setChartOrientation(
1640 chartJSON.getBarChartOptions().isVerticalOrientation() ? "vertical" : "horizontal");
1641 reportRuntime.setChartStacked(chartJSON.getBarChartOptions().isStackedChart());
1642 reportRuntime.setBarControls(chartJSON.getBarChartOptions().isDisplayBarControls());
1643 reportRuntime.setXAxisDateType(chartJSON.getBarChartOptions().isxAxisDateType());
1644 reportRuntime.setLessXaxisTickers(chartJSON.getBarChartOptions().isMinimizeXAxisTickers());
1645 reportRuntime.setTimeAxis(chartJSON.getBarChartOptions().isTimeAxis());
1646 reportRuntime.setLogScale(chartJSON.getBarChartOptions().isyAxisLogScale());
1650 reportRuntime.setLegendLabelAngle(chartJSON.getCommonChartOptions().getLegendLabelAngle());
1651 reportRuntime.setLegendPosition(chartJSON.getCommonChartOptions().getLegendPosition());
1652 reportRuntime.setChartLegendDisplay(chartJSON.getCommonChartOptions().isHideLegend() ? "Y" : "N");
1653 reportRuntime.setAnimateAnimatedChart(chartJSON.getCommonChartOptions().isAnimateAnimatedChart());
1655 reportRuntime.setTopMargin(chartJSON.getCommonChartOptions().getTopMargin());
1656 reportRuntime.setBottomMargin(chartJSON.getCommonChartOptions().getBottomMargin());
1657 reportRuntime.setLeftMargin(chartJSON.getCommonChartOptions().getLeftMargin());
1658 reportRuntime.setRightMargin(chartJSON.getCommonChartOptions().getRightMargin());
1660 for (Iterator<DataColumnType> iterator = reportCols.iterator(); iterator.hasNext();) {
1661 DataColumnType dct = (DataColumnType) iterator.next();
1662 if (!(AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)
1663 || (dct.getChartSeq() != null && dct.getChartSeq() > 0) || dct.isChartSeries())) {
1664 dct.setChartSeq(-1);
1665 dct.setChartColor(null);
1666 dct.setColOnChart(null);
1667 dct.setCreateInNewChart(false);
1668 dct.setChartGroup(null);
1674 reportRuntime.persistLinearReport(request);
1675 } catch (Exception ex) {
1676 ex.printStackTrace();
1677 logger.error("While SAVING CHART", ex);
1683 public String getViewName() {
1687 public void setViewName(String viewName) {
1688 this.viewName = viewName;
1691 public String nvl(String s) {
1692 return (s == null) ? "" : s;
1695 public String nvl(String s, String sDefault) {
1696 return nvl(s).equals("") ? sDefault : s;
1699 public static String getStackTrace(Throwable aThrowable) {
1700 Writer result = new StringWriter();
1701 PrintWriter printWriter = new PrintWriter(result);
1702 aThrowable.printStackTrace(printWriter);
1703 return result.toString();
1706 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RaptorControllerAsync.class);
1708 public void persistReportDefinition(HttpServletRequest request, ReportDefinition rdef) throws RaptorException {
1709 ReportRuntime rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
1710 if (rr != null && rr.getReportID().equals(rdef.getReportID()))
1711 request.getSession().removeAttribute(AppConstants.SI_REPORT_RUNTIME);
1712 rdef.persistReport(request);
1713 } // persistReportDefinition
1715 // Remove from session
1716 private void removeVariablesFromSession(HttpServletRequest request) {
1717 HttpSession session = request.getSession();
1718 session.removeAttribute(AppConstants.DRILLDOWN_REPORTS_LIST);
1719 session.removeAttribute(AppConstants.DRILLDOWN_INDEX);
1720 session.removeAttribute(AppConstants.FORM_DRILLDOWN_INDEX);
1721 session.removeAttribute(AppConstants.SI_BACKUP_FOR_REP_ID);
1722 session.removeAttribute(AppConstants.SI_COLUMN_LOOKUP);
1723 session.removeAttribute(AppConstants.SI_DASHBOARD_REP_ID);
1724 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP);
1725 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME);
1726 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP);
1727 session.removeAttribute(AppConstants.SI_DASHBOARD_CHARTDATA_MAP);
1728 session.removeAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP);
1729 session.removeAttribute(AppConstants.SI_DATA_SIZE_FOR_TEXTFIELD_POPUP);
1730 session.removeAttribute(AppConstants.SI_MAP);
1731 session.removeAttribute(AppConstants.SI_MAP_OBJECT);
1732 session.removeAttribute(AppConstants.SI_REPORT_DEFINITION);
1733 session.removeAttribute(AppConstants.SI_REPORT_RUNTIME);
1734 session.removeAttribute(AppConstants.SI_REPORT_RUN_BACKUP);
1735 session.removeAttribute(AppConstants.SI_REPORT_SCHEDULE);
1736 session.removeAttribute(AppConstants.RI_REPORT_DATA);
1737 session.removeAttribute(AppConstants.RI_CHART_DATA);
1738 session.removeAttribute(AppConstants.SI_FORMFIELD_INFO);
1739 session.removeAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO);
1740 session.removeAttribute(AppConstants.EMBEDDED_REPORTRUNTIME_MAP);
1741 session.removeAttribute(AppConstants.EMBEDDED_REPORTDATA_MAP);
1742 Enumeration<String> enum1 = session.getAttributeNames();
1743 String attributeName = "";
1744 while (enum1.hasMoreElements()) {
1745 attributeName = enum1.nextElement();
1746 if (attributeName.startsWith("parent_")) {
1747 session.removeAttribute(attributeName);