2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
38 package org.onap.portalsdk.analytics.model.runtime;
40 import java.io.UnsupportedEncodingException;
41 import java.text.ParsePosition;
42 import java.text.SimpleDateFormat;
43 import java.util.ArrayList;
44 import java.util.Arrays;
45 import java.util.Collections;
46 import java.util.Enumeration;
47 import java.util.HashMap;
48 import java.util.Iterator;
49 import java.util.List;
51 import java.util.Map.Entry;
53 import java.util.regex.Matcher;
54 import java.util.regex.Pattern;
56 import javax.servlet.http.HttpServletRequest;
57 import javax.servlet.http.HttpSession;
59 import org.onap.portalsdk.analytics.error.RaptorException;
60 import org.onap.portalsdk.analytics.model.ReportHandler;
61 import org.onap.portalsdk.analytics.model.base.ChartSeqComparator;
62 import org.onap.portalsdk.analytics.system.AppUtils;
63 import org.onap.portalsdk.analytics.system.ConnectionUtils;
64 import org.onap.portalsdk.analytics.util.AppConstants;
65 import org.onap.portalsdk.analytics.util.DataSet;
66 import org.onap.portalsdk.analytics.util.Utils;
67 import org.onap.portalsdk.analytics.xmlobj.DataColumnType;
68 import org.onap.portalsdk.analytics.xmlobj.FormFieldType;
69 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
70 import org.onap.portalsdk.core.web.support.UserUtils;
72 import com.fasterxml.jackson.databind.DeserializationFeature;
73 import com.fasterxml.jackson.databind.ObjectMapper;
74 import com.fasterxml.jackson.databind.SerializationFeature;
76 public class ChartJSONHelper {
78 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ChartJSONHelper.class);
80 private ReportRuntime reportRuntime;
81 private String chartType;
83 public static final long HOUR = 3600L * 1000L;
84 public static final long DAY = 3600L * 1000L * 24L;
85 public static final long MONTH = 3600L * 1000L * 24L * 31L;
86 public static final long YEAR = 3600L * 1000L * 24L * 365L;
89 public ChartJSONHelper() {
94 * @return the chartType
96 public String getChartType() {
101 * @param chartType the chartType to set
103 public void setChartType(String chartType) {
104 this.chartType = chartType;
107 public ChartJSONHelper(ReportRuntime rr) {
108 this.reportRuntime = rr;
111 public String generateJSON(String reportID, HttpServletRequest request, boolean showData)
112 throws RaptorException {
113 // From annotations chart
114 clearReportRuntimeBackup(request);
116 ReportHandler rh = new ReportHandler();
118 HashMap<String, String> chartOptionsMap = new HashMap<>();
121 if (reportID != null) {
122 reportRuntime = rh.loadReportRuntime(request, reportID, true, 1);
123 setChartType(reportRuntime.getChartType());
126 String rotateLabelsStr = "";
127 rotateLabelsStr = AppUtils.nvl(reportRuntime.getLegendLabelAngle());
128 if (rotateLabelsStr.equalsIgnoreCase("standard")) {
129 rotateLabelsStr = "0";
130 } else if (rotateLabelsStr.equalsIgnoreCase("up45")) {
131 rotateLabelsStr = "45";
132 } else if (rotateLabelsStr.equalsIgnoreCase("down45")) {
133 rotateLabelsStr = "-45";
134 } else if (rotateLabelsStr.equalsIgnoreCase("up90")) {
135 rotateLabelsStr = "90";
136 } else if (rotateLabelsStr.equalsIgnoreCase("down90")) {
137 rotateLabelsStr = "-90";
139 rotateLabelsStr = "0";
141 String width = (AppUtils.getRequestNvlValue(request, "width").length() > 0
142 ? AppUtils.getRequestNvlValue(request, "width")
143 : (AppUtils.nvl(reportRuntime.getChartWidth()).length() > 0
144 ? reportRuntime.getChartWidth()
146 String height = (AppUtils.getRequestNvlValue(request, "height").length() > 0
147 ? AppUtils.getRequestNvlValue(request, "height")
148 : (AppUtils.nvl(reportRuntime.getChartHeight()).length() > 0
149 ? reportRuntime.getChartHeight()
151 String animationStr = (AppUtils.getRequestNvlValue(request, "animation").length() > 0
152 ? AppUtils.getRequestNvlValue(request, "animation")
153 : new Boolean(reportRuntime.isAnimateAnimatedChart()).toString());
155 String rotateLabels = (AppUtils.getRequestNvlValue(request, "rotateLabels").length() > 0
156 ? AppUtils.getRequestNvlValue(request, "rotateLabels")
157 : (rotateLabelsStr.length() > 0 ? rotateLabelsStr : "0"));
158 String staggerLabelsStr =
159 (AppUtils.getRequestNvlValue(request, "staggerLabels").length() > 0
160 ? AppUtils.getRequestNvlValue(request, "staggerLabels")
162 String showMaxMinStr = (AppUtils.getRequestNvlValue(request, "showMaxMin").length() > 0
163 ? AppUtils.getRequestNvlValue(request, "showMaxMin")
165 String showControlsStr =
166 (AppUtils.getRequestNvlValue(request, "showControls").length() > 0
167 ? AppUtils.getRequestNvlValue(request, "showControls")
168 : new Boolean(reportRuntime.displayBarControls()).toString());
169 String showLegendStr = (AppUtils.getRequestNvlValue(request, "showLegend").length() > 0
170 ? AppUtils.getRequestNvlValue(request, "showLegend")
171 : new Boolean(!new Boolean(reportRuntime.hideChartLegend())).toString());
172 String topMarginStr = AppUtils.getRequestNvlValue(request, "topMargin");
173 String topMargin = (AppUtils.nvl(topMarginStr).length() <= 0)
174 ? (reportRuntime.getTopMargin() != null
175 ? reportRuntime.getTopMargin().toString()
178 String bottomMarginStr = AppUtils.getRequestNvlValue(request, "bottomMargin");
179 String bottomMargin = (AppUtils.nvl(bottomMarginStr).length() <= 0)
180 ? (reportRuntime.getBottomMargin() != null
181 ? reportRuntime.getBottomMargin().toString()
184 String leftMarginStr = AppUtils.getRequestNvlValue(request, "leftMargin");
185 String leftMargin = (AppUtils.nvl(leftMarginStr).length() <= 0)
186 ? (reportRuntime.getLeftMargin() != null
187 ? reportRuntime.getLeftMargin().toString()
190 String rightMarginStr = AppUtils.getRequestNvlValue(request, "rightMargin");
191 String rightMargin = (AppUtils.nvl(rightMarginStr).length() <= 0)
192 ? (reportRuntime.getRightMargin() != null
193 ? reportRuntime.getRightMargin().toString()
196 String showTitleStr = (AppUtils.getRequestNvlValue(request, "showTitle").length() > 0
197 ? AppUtils.getRequestNvlValue(request, "showTitle")
198 : new Boolean(reportRuntime.displayChartTitle()).toString());
199 String subType = AppUtils.getRequestNvlValue(request, "subType").length() > 0
200 ? AppUtils.getRequestNvlValue(request, "subType")
201 : (AppUtils.nvl(reportRuntime.getTimeSeriesRender()).equals("area")
202 ? reportRuntime.getTimeSeriesRender()
204 String stackedStr = AppUtils.getRequestNvlValue(request, "stacked").length() > 0
205 ? AppUtils.getRequestNvlValue(request, "stacked")
206 : new Boolean(reportRuntime.isChartStacked()).toString();
207 String horizontalBar =
208 AppUtils.getRequestNvlValue(request, "horizontalBar").length() > 0
209 ? AppUtils.getRequestNvlValue(request, "horizontalBar")
210 : new Boolean(reportRuntime.isHorizontalOrientation()).toString();
211 String barRealTimeAxis = AppUtils.getRequestNvlValue(request, "barRealTimeAxis");
212 String barReduceXAxisLabels =
213 AppUtils.getRequestNvlValue(request, "barReduceXAxisLabels").length() > 0
214 ? AppUtils.getRequestNvlValue(request, "barReduceXAxisLabels")
215 : new Boolean(reportRuntime.isLessXaxisTickers()).toString();;
216 String timeAxis = AppUtils.getRequestNvlValue(request, "timeAxis").length() > 0
217 ? AppUtils.getRequestNvlValue(request, "timeAxis")
218 : new Boolean(reportRuntime.isTimeAxis()).toString();
219 String logScale = AppUtils.getRequestNvlValue(request, "logScale").length() > 0
220 ? AppUtils.getRequestNvlValue(request, "logScale")
221 : new Boolean(reportRuntime.isLogScale()).toString();
222 String precision = AppUtils.getRequestNvlValue(request, "precision").length() > 0
223 ? AppUtils.getRequestNvlValue(request, "precision")
227 chartOptionsMap.put("width", width);
228 chartOptionsMap.put("height", height);
229 chartOptionsMap.put("animation", animationStr);
230 chartOptionsMap.put("rotateLabels", rotateLabels);
231 chartOptionsMap.put("staggerLabels", staggerLabelsStr);
232 chartOptionsMap.put("showMaxMin", showMaxMinStr);
233 chartOptionsMap.put("showControls", showControlsStr);
234 chartOptionsMap.put("showLegend", showLegendStr);
235 chartOptionsMap.put("topMargin", topMargin);
236 chartOptionsMap.put("bottomMargin", bottomMargin);
237 chartOptionsMap.put("leftMargin", leftMargin);
238 chartOptionsMap.put("rightMargin", rightMargin);
239 chartOptionsMap.put("showTitle", showTitleStr);
240 chartOptionsMap.put("subType", subType);
241 chartOptionsMap.put("stacked", stackedStr);
242 chartOptionsMap.put("horizontalBar", horizontalBar);
243 chartOptionsMap.put("timeAxis", timeAxis);
244 chartOptionsMap.put("barRealTimeAxis", barRealTimeAxis);
245 chartOptionsMap.put("barReduceXAxisLabels", barReduceXAxisLabels);
247 chartOptionsMap.put("logScale", logScale);
248 chartOptionsMap.put("precision", precision);
251 } catch (RaptorException ex) {
252 logger.error("Exception in generateJSON", ex);
254 return generateJSON(reportRuntime, chartOptionsMap, request, showData);
257 public String generateJSON(ReportRuntime reportRuntime, HttpServletRequest request, boolean showData) throws RaptorException {
259 String rotateLabelsStr = "";
260 rotateLabelsStr = AppUtils.nvl(reportRuntime.getLegendLabelAngle());
261 if (rotateLabelsStr.equalsIgnoreCase("standard")) {
262 rotateLabelsStr = "0";
263 } else if (rotateLabelsStr.equalsIgnoreCase("up45")) {
264 rotateLabelsStr = "45";
265 } else if (rotateLabelsStr.equalsIgnoreCase("down45")) {
266 rotateLabelsStr = "-45";
267 } else if (rotateLabelsStr.equalsIgnoreCase("up90")) {
268 rotateLabelsStr = "90";
269 } else if (rotateLabelsStr.equalsIgnoreCase("down90")) {
270 rotateLabelsStr = "-90";
272 rotateLabelsStr = "0";
275 HashMap<String,String> chartOptionsMap = new HashMap<>();
276 chartOptionsMap.put("width", reportRuntime.getChartWidth());
277 chartOptionsMap.put("height", reportRuntime.getChartHeight());
278 chartOptionsMap.put("animation", Boolean.toString(reportRuntime.isAnimateAnimatedChart()));
279 chartOptionsMap.put("rotateLabels", rotateLabelsStr);
280 chartOptionsMap.put("staggerLabels", "false");
281 chartOptionsMap.put("showMaxMin", "false");
282 chartOptionsMap.put("showControls", Boolean.toString(reportRuntime.displayBarControls()));
283 chartOptionsMap.put("showLegend", Boolean.toString(!reportRuntime.hideChartLegend()));
284 chartOptionsMap.put("topMargin", reportRuntime.getTopMargin()!=null?reportRuntime.getTopMargin().toString():"30");
285 chartOptionsMap.put("bottomMargin", reportRuntime.getBottomMargin()!=null?reportRuntime.getBottomMargin().toString():"50");
286 chartOptionsMap.put("leftMargin", reportRuntime.getLeftMargin()!=null?reportRuntime.getLeftMargin().toString():"100");
287 chartOptionsMap.put("rightMargin", reportRuntime.getRightMargin()!=null?reportRuntime.getRightMargin().toString():"160");
288 chartOptionsMap.put("showTitle", Boolean.toString(reportRuntime.displayChartTitle()));
289 chartOptionsMap.put("subType", (AppUtils.nvl(reportRuntime.getTimeSeriesRender()).equals("area")?reportRuntime.getTimeSeriesRender():""));
290 chartOptionsMap.put("stacked", Boolean.toString(reportRuntime.isChartStacked()));
291 chartOptionsMap.put("horizontalBar", Boolean.toString(reportRuntime.isHorizontalOrientation()));
292 chartOptionsMap.put("timeAxis", Boolean.toString(reportRuntime.isTimeAxis()));
293 chartOptionsMap.put("barReduceXAxisLabels", Boolean.toString(reportRuntime.isLessXaxisTickers()));
295 chartOptionsMap.put("logScale", Boolean.toString(reportRuntime.isLogScale()));
296 chartOptionsMap.put("precision", "2");
300 return generateJSON(reportRuntime, chartOptionsMap, request, showData);
303 public String generateJSON(ReportRuntime reportRuntime,Map<String, String> chartOptionsMap, HttpServletRequest request, boolean showData) throws RaptorException {
305 String userId = AppUtils.getUserID(request);
306 String width = chartOptionsMap.get("width");
307 String height = chartOptionsMap.get("height");
308 boolean animation = getBooleanValue(chartOptionsMap.get("animation"), true);
309 String rotateLabels = chartOptionsMap.get("rotateLabels");
310 boolean staggerLabels = getBooleanValue(chartOptionsMap.get("staggerLabels"));
311 boolean showMaxMin = getBooleanValue(chartOptionsMap.get("showMaxMin"), false);
312 boolean showLegend = getBooleanValue(chartOptionsMap.get("showLegend"), true);
313 boolean showControls = getBooleanValue(chartOptionsMap.get("showControls"), true);
314 String topMargin = chartOptionsMap.get("topMargin");
315 String bottomMargin = chartOptionsMap.get("bottomMargin");
316 String leftMargin = chartOptionsMap.get("leftMargin");
317 String rightMargin = chartOptionsMap.get("rightMargin");
318 boolean showTitle = getBooleanValue(chartOptionsMap.get("showTitle"), true);
319 String subType = chartOptionsMap.get("subType");
320 boolean stacked = getBooleanValue(chartOptionsMap.get("stacked"), false);
321 boolean horizontalBar = getBooleanValue(chartOptionsMap.get("horizontalBar"), false);
322 boolean barRealTimeAxis = getBooleanValue(chartOptionsMap.get("barRealTimeAxis"), true);
323 boolean barReduceXAxisLabels= getBooleanValue(chartOptionsMap.get("barReduceXAxisLabels"), false);
324 boolean timeAxis = getBooleanValue(chartOptionsMap.get("timeAxis"), true);
327 boolean logScale = getBooleanValue(chartOptionsMap.get("logScale"), false);
332 precision = Integer.parseInt(chartOptionsMap.get("precision"));
333 } catch (NumberFormatException ex) {
337 final Long user_id = new Long((long) UserUtils.getUserId(request));
339 HttpSession session = null;
340 session = request.getSession();
341 String chartType = reportRuntime.getChartType();
342 List l = reportRuntime.getAllColumns();
343 List lGroups = reportRuntime.getAllChartGroups();
344 HashMap mapYAxis = reportRuntime.getAllChartYAxis(reportRuntime.getReportParamValues());
345 String chartLeftAxisLabel = reportRuntime.getFormFieldFilled(nvl(reportRuntime.getChartLeftAxisLabel()));
346 String chartRightAxisLabel = reportRuntime.getFormFieldFilled(nvl(reportRuntime.getChartRightAxisLabel()));
348 boolean multipleSeries = reportRuntime.isMultiSeries();
350 java.util.HashMap formValues = null;
351 formValues = getRequestParametersMap(reportRuntime, request);
354 String legendColumnName = (reportRuntime.getChartLegendColumn()!=null)?reportRuntime.getChartLegendColumn().getDisplayName():"Legend Column";
355 boolean displayChart = reportRuntime.getDisplayChart();
356 HashMap additionalChartOptionsMap = new HashMap();
358 StringBuffer wholeScript = new StringBuffer("");
360 String title = reportRuntime.getReportTitle();
362 title = parseTitle(title, formValues);
363 ObjectMapper mapper = new ObjectMapper();
364 ChartJSON chartJSON = new ChartJSON();
371 if (!(chartType.equals(AppConstants.GT_HIERARCHICAL) || chartType.equals(AppConstants.GT_HIERARCHICAL_SUNBURST) || chartType.equals(AppConstants.GT_ANNOTATION_CHART))) {
372 sql = generateChartSQL(userId, request );
373 ds = (DataSet) loadChartData(new Long(user_id).toString(), request);
374 } else if(chartType.equals(AppConstants.GT_ANNOTATION_CHART)) {
375 sql = reportRuntime.getWholeSQL();
376 String reportSQL = reportRuntime.getWholeSQL();
377 String dbInfo = reportRuntime.getDBInfo();
378 ds = ConnectionUtils.getDataSet(reportSQL, dbInfo);
379 if(ds.getRowCount()<=0) {
380 logger.debug(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
381 logger.info(EELFLoggerDelegate.debugLogger, (chartType.toUpperCase()+" - " + "Report ID : " + reportRuntime.getReportID() + " DATA IS EMPTY" ));
382 logger.info(EELFLoggerDelegate.debugLogger, ("QUERY - " + reportSQL));
383 logger.info(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
385 } else if(chartType.equals(AppConstants.GT_HIERARCHICAL)||chartType.equals(AppConstants.GT_HIERARCHICAL_SUNBURST)) {
386 sql = reportRuntime.getWholeSQL();
387 String reportSQL = reportRuntime.getWholeSQL();
388 String dbInfo = reportRuntime.getDBInfo();
389 ds = ConnectionUtils.getDataSet(reportSQL, dbInfo);
391 } catch (RaptorException ex) {
392 logger.error(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
393 logger.error(EELFLoggerDelegate.debugLogger, (chartType.toUpperCase()+" - " + "Report ID : " + reportRuntime.getReportID() + " ERROR THROWN FOR GIVEN QUERY "));
394 logger.error(EELFLoggerDelegate.debugLogger, ("QUERY - " + reportRuntime.getWholeSQL()));
395 logger.error(EELFLoggerDelegate.debugLogger, ("ERROR STACK TRACE" + ex.getMessage()));
396 logger.error(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
400 if(chartType.equals(AppConstants.GT_ANNOTATION_CHART))
403 displayChart = false;
408 chartJSON.setReportID(reportRuntime.getReportID());
409 chartJSON.setReportName(reportRuntime.getReportName());
410 chartJSON.setReportDescr(reportRuntime.getReportDescr());
411 chartJSON.setReportTitle(reportRuntime.getReportTitle());
412 chartJSON.setReportSubTitle(reportRuntime.getReportSubTitle());
414 List<DataColumnType> dcList = reportRuntime.getOnlyVisibleColumns();
416 ArrayList<ChartColumnJSON> chartColumnJSONList = new ArrayList<>();
417 for(Iterator iter = dcList.iterator(); iter.hasNext(); ) {
418 ChartColumnJSON ccJSON = new ChartColumnJSON();
419 DataColumnType dc = (DataColumnType) iter.next();
420 ccJSON.setIndex(countIndex);
421 ccJSON.setValue(dc.getColId());
422 ccJSON.setTitle(dc.getDisplayName());
424 chartColumnJSONList.add(ccJSON);
426 chartJSON.setChartColumnJSONList(chartColumnJSONList);
427 chartJSON.setChartAvailable(displayChart);
429 ChartTypeJSON chartTypeJSON = new ChartTypeJSON();
430 chartTypeJSON.setIndex(0);
431 chartTypeJSON.setTitle("");
432 chartTypeJSON.setValue(chartType);
433 chartJSON.setChartTypeJSON(chartTypeJSON);
434 chartJSON.setWidth(width);
435 chartJSON.setHeight(height);
436 chartJSON.setAnimation(animation);
437 chartJSON.setRotateLabels(rotateLabels);
438 chartJSON.setStaggerLabels(staggerLabels);
439 chartJSON.setShowTitle(showTitle);
440 DomainAxisJSON domainAxisJSON = new DomainAxisJSON();
441 domainAxisJSON.setIndex(0);
442 if(reportRuntime.getChartLegendColumn()!=null)
443 domainAxisJSON.setTitle(reportRuntime.getChartLegendColumn().getDisplayName());
445 domainAxisJSON.setTitle("");
446 if(reportRuntime.getChartLegendColumn()!=null)
447 domainAxisJSON.setValue(reportRuntime.getChartLegendColumn().getColId());
449 domainAxisJSON.setValue("");
450 chartJSON.setDomainAxisJSON(domainAxisJSON);
453 List<DataColumnType> reportCols = reportRuntime.getAllColumns();
454 boolean hasSeriesColumn = false;
456 for (Iterator<DataColumnType> iter = reportCols.iterator(); iter
458 DataColumnType dct = (DataColumnType) iter.next();
459 if(dct.isChartSeries()!=null && dct.isChartSeries().booleanValue()) {
460 chartJSON.setHasCategoryAxis(true);
461 CategoryAxisJSON categoryAxisJSON = new CategoryAxisJSON();
462 categoryAxisJSON.setIndex(0);
463 categoryAxisJSON.setTitle(dct.getDisplayName());
464 categoryAxisJSON.setValue(dct.getColId());
465 chartJSON.setCategoryAxisJSON(categoryAxisJSON);
469 List<DataColumnType> chartValueCols = reportRuntime.getChartValueColumnsList(AppConstants.CHART_ALL_COLUMNS, null);
470 DataColumnType dct_RangeAxis = null;
472 if(chartValueCols.size() <= 0) {
473 chartValueCols = reportCols;
475 ArrayList<RangeAxisJSON> rangeAxisJSONList = new ArrayList<>();
476 for (int k = 0; k < chartValueCols.size(); k++) {
477 dct_RangeAxis = chartValueCols.get(k);
478 RangeAxisJSON rangeAxisJSON = new RangeAxisJSON();
480 RangeAxisLabelJSON rangeAxisLabelJSON = new RangeAxisLabelJSON();
481 rangeAxisLabelJSON.setIndex(0);
482 rangeAxisLabelJSON.setTitle(dct_RangeAxis.getDisplayName());
483 rangeAxisLabelJSON.setValue(dct_RangeAxis.getColId());
484 rangeAxisJSON.setRangeAxisLabelJSON(rangeAxisLabelJSON);
485 RangeLineTypeJSON rangeLineTypeJSON = new RangeLineTypeJSON();
486 rangeLineTypeJSON.setIndex(0);
487 rangeLineTypeJSON.setTitle("");
488 rangeLineTypeJSON.setValue(dct_RangeAxis.getChartLineType());
489 rangeAxisJSON.setRangeLineTypeJSON(rangeLineTypeJSON);
491 RangeColorJSON rangeColorJSON = new RangeColorJSON();
492 rangeColorJSON.setIndex(0);
493 rangeColorJSON.setTitle("");
494 rangeColorJSON.setValue(dct_RangeAxis.getChartColor());
495 rangeAxisJSON.setRangeColorJSON(rangeColorJSON);
496 String chartGroup = "";
497 chartGroup = AppUtils.nvl(dct_RangeAxis.getChartGroup());
498 if(chartGroup.indexOf("|")!=-1)
499 chartGroup = chartGroup.substring(0, chartGroup.indexOf("|"));
502 rangeAxisJSON.setRangeChartGroup(chartGroup);
504 yAxis = AppUtils.nvl(dct_RangeAxis.getYAxis());
505 if(yAxis.indexOf("|")!=-1)
506 yAxis = yAxis.substring(0, yAxis.indexOf("|"));
508 rangeAxisJSON.setRangeYAxis(yAxis);
509 rangeAxisJSON.setShowAsArea((dct_RangeAxis.isIsRangeAxisFilled()!=null && dct_RangeAxis.isIsRangeAxisFilled().booleanValue())?true:false);
510 rangeAxisJSONList.add(rangeAxisJSON);
512 CommonChartOptions commonChartOptions = new CommonChartOptions();
513 commonChartOptions.setLegendPosition(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>0?reportRuntime.getLegendPosition().toLowerCase():"top");
514 String legendLabelAngle = "";
515 legendLabelAngle = reportRuntime.getLegendLabelAngle().toLowerCase();
516 commonChartOptions.setLegendLabelAngle(AppUtils.nvl(legendLabelAngle).length()>0?legendLabelAngle:"up45");
517 commonChartOptions.setHideLegend(reportRuntime.hideChartLegend());
518 commonChartOptions.setAnimateAnimatedChart(reportRuntime.isAnimateAnimatedChart());
519 commonChartOptions.setTopMargin(reportRuntime.getTopMargin()!=null?reportRuntime.getTopMargin():new Integer("30"));
520 commonChartOptions.setBottomMargin(reportRuntime.getBottomMargin()!=null?reportRuntime.getBottomMargin():new Integer("50"));
521 commonChartOptions.setLeftMargin(reportRuntime.getLeftMargin()!=null?reportRuntime.getLeftMargin():new Integer("100"));
522 commonChartOptions.setRightMargin(reportRuntime.getRightMargin()!=null?reportRuntime.getRightMargin():new Integer("60"));
523 chartJSON.setCommonChartOptions(commonChartOptions);
525 if(chartType.equals(AppConstants.GT_BAR_3D)) {
526 BarChartOptions barChartOptions = new BarChartOptions();
527 barChartOptions.setDisplayBarControls(reportRuntime.displayBarControls()?true:false);
528 barChartOptions.setMinimizeXAxisTickers(reportRuntime.isLessXaxisTickers()?true:false);
529 barChartOptions.setStackedChart(reportRuntime.isChartStacked()?true:false);
530 barChartOptions.setTimeAxis(reportRuntime.isTimeAxis()?true:false);
531 barChartOptions.setVerticalOrientation(reportRuntime.isVerticalOrientation()?true:false);
532 barChartOptions.setxAxisDateType(reportRuntime.isXAxisDateType()?true:false);
533 barChartOptions.setyAxisLogScale(reportRuntime.isLogScale()?true:false);
534 chartJSON.setBarChartOptions(barChartOptions);
535 chartJSON.setTimeSeriesChartOptions(null);
536 chartJSON.setPieChartOptions(null);
537 chartJSON.setFlexTimeSeriesChartOptions(null);
539 } else if(chartType.equals(AppConstants.GT_TIME_SERIES)) {
540 TimeSeriesChartOptions timeSeriesChartOptions = new TimeSeriesChartOptions();
541 timeSeriesChartOptions.setAddXAxisTicker(reportRuntime.isAddXAxisTickers());
542 timeSeriesChartOptions.setLineChartRenderer(AppUtils.nvl(reportRuntime.getTimeSeriesRender()).length()>0?reportRuntime.getTimeSeriesRender():"line");
543 timeSeriesChartOptions.setMultiSeries(reportRuntime.isMultiSeries());
544 timeSeriesChartOptions.setNonTimeAxis(reportRuntime.isTimeAxis());
545 timeSeriesChartOptions.setShowXAxisLabel(reportRuntime.isShowXaxisLabel());
546 chartJSON.setBarChartOptions(null);
547 chartJSON.setTimeSeriesChartOptions(timeSeriesChartOptions);
548 chartJSON.setPieChartOptions(null);
549 chartJSON.setFlexTimeSeriesChartOptions(null);
550 } else if(chartType.equals(AppConstants.GT_ANNOTATION_CHART) || chartType.equals(AppConstants.GT_FLEX_TIME_CHARTS)) {
551 FlexTimeSeriesChartOptions flexTimeSeriesChartOptions = new FlexTimeSeriesChartOptions();
552 flexTimeSeriesChartOptions.setZoomIn(reportRuntime.getZoomIn()!=null?reportRuntime.getZoomIn():new Integer("25"));
553 String timeAxisTypeStr = "";
554 timeAxisTypeStr = reportRuntime.getTimeAxisType().toLowerCase();
555 flexTimeSeriesChartOptions.setTimeAxisType(timeAxisTypeStr);
556 chartJSON.setBarChartOptions(null);
557 chartJSON.setTimeSeriesChartOptions(null);
558 chartJSON.setPieChartOptions(null);
559 chartJSON.setFlexTimeSeriesChartOptions(flexTimeSeriesChartOptions);
561 chartJSON.setRangeAxisList(rangeAxisJSONList);
562 chartJSON.setPrimaryAxisLabel(reportRuntime.getChartLeftAxisLabel());
563 chartJSON.setSecondaryAxisLabel(reportRuntime.getChartRightAxisLabel());
564 chartJSON.setMinRange(reportRuntime.getRangeAxisLowerLimit());
565 chartJSON.setMaxRange(reportRuntime.getRangeAxisUpperLimit());
568 ArrayList<ArrayList<Row>> wholeList = new ArrayList<>();
570 ArrayList<Row> rowList = new ArrayList<>();
572 for (int i = 0; i < ds.getRowCount(); i++) {
573 rowList = new ArrayList<>();
574 for (int j = 0; j<ds.getColumnCount(); j++) {
576 row.setColId(ds.getColumnName(j));
577 row.setDisplayValue(ds.getString(i, j));
578 row.setDataType(ds.getColumnType(j));
581 wholeList.add(rowList);
585 chartJSON.setWholeList(wholeList);
595 // chart is not visible
596 chartJSON.setReportID(reportRuntime.getReportID());
597 chartJSON.setReportName(reportRuntime.getReportName());
598 chartJSON.setReportDescr(reportRuntime.getReportDescr());
599 chartJSON.setReportTitle(reportRuntime.getReportTitle());
600 chartJSON.setReportSubTitle(reportRuntime.getReportSubTitle());
601 chartJSON.setChartAvailable(displayChart);
602 ChartTypeJSON chartTypeJSON = new ChartTypeJSON();
603 chartTypeJSON.setIndex(0);
604 chartTypeJSON.setTitle("");
605 chartTypeJSON.setValue(chartType);
606 chartJSON.setChartTypeJSON(chartTypeJSON);
608 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
609 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
610 String jsonInString = "";
612 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(chartJSON);
613 } catch (Exception ex) {
614 ex.printStackTrace();
621 public String nvl(String s) {
622 return (s == null) ? "" : s;
625 public String nvl(String s, String sDefault) {
626 return nvl(s).equals("") ? sDefault : s;
629 public static String nvls(String s) {
630 return (s == null) ? "" : s;
633 public static String nvls(String s, String sDefault) {
634 return nvls(s).equals("") ? sDefault : s;
637 public boolean getFlagInBoolean(String s) {
638 return nvl(s).toUpperCase().startsWith("Y") || nvl(s).equalsIgnoreCase("true");
641 public DataSet loadChartData(String userId, HttpServletRequest request) throws RaptorException {
642 if (nvl(getChartType()).length() == 0)
644 //TODO: display chart function to be added.
647 sql = generateChartSQL(userId, request);
648 logger.debug(EELFLoggerDelegate.debugLogger, ("SQL generated " + sql));
649 String dbInfo = reportRuntime.getDBInfo();
650 DataSet ds = ConnectionUtils.getDataSet(sql, dbInfo);
651 if(ds.getRowCount()<=0) {
652 logger.info(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
653 logger.info(EELFLoggerDelegate.debugLogger, (getChartType().toUpperCase()+" - " + "Report ID : " + reportRuntime.getReportID() + " DATA IS EMPTY"));
654 logger.info(EELFLoggerDelegate.debugLogger, ("QUERY - " + sql));
655 logger.info(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
661 public String generateChartSQL(String userId, HttpServletRequest request ) throws RaptorException {
662 List reportCols = reportRuntime.getAllColumns();
663 List chartValueCols = getChartValueColumnsList(AppConstants.CHART_ALL_COLUMNS, null); // parameter is 0 has this requires all columns.
664 String reportSQL = reportRuntime.getWholeSQL();
666 //Add order by clause
667 Pattern re1 = Pattern.compile("(^[\r\n]*|([\\s]))[Oo][Rr][Dd][Ee][Rr](.*?[^\r\n]*)[Bb][Yy]",Pattern.DOTALL);
668 Matcher matcher = re1.matcher(reportSQL);
670 reportSQL = reportSQL + " ";
671 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ss][Ee][Ll][Ee][Cc][Tt]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" SELECT ");
672 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ww][Hh][Ee][Rr][Ee]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" WHERE ");
673 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ww][Hh][Ee][Nn]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" WHEN ");
674 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Aa][Nn][Dd]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" AND ");
676 if(!reportRuntime.getReportType().equals(AppConstants.RT_HIVE)) {
677 int startPoint = reportSQL.lastIndexOf(" FROM ");
678 if(startPoint <= 0) {
679 startPoint = reportSQL.lastIndexOf(" from ");
681 if(startPoint <= 0) {
682 startPoint = reportSQL.lastIndexOf("from ");
684 if(startPoint <= 0) {
685 startPoint = reportSQL.lastIndexOf("FROM ");
688 if (!matcher.find(startPoint)) {
689 reportSQL = reportSQL + " ORDER BY 1" ;
692 reportRuntime.setWholeSQL(reportSQL);
694 logger.debug(EELFLoggerDelegate.debugLogger, (" *************************************************************************************** "));
695 logger.debug(EELFLoggerDelegate.debugLogger, ("WHOLE_SQL" + reportSQL));
696 logger.debug(EELFLoggerDelegate.debugLogger, (" *************************************************************************************** "));
698 if (reportRuntime.getFormFieldList() != null) {
699 for (Iterator iter = reportRuntime.getFormFieldList().getFormField().iterator(); iter.hasNext();) {
700 FormFieldType fft = (FormFieldType) iter.next();
701 String fieldId = fft.getFieldId();
702 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
703 String formfield_value = "";
704 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
705 String paramValue = nvl(formfield_value);
706 if(paramValue.length()>0) {
707 reportSQL = Utils.replaceInString(reportSQL, fieldDisplay, nvl(
708 paramValue, "NULL"));
710 reportSQL = Utils.replaceInString(reportSQL, "'" + fieldDisplay + "'", nvl(
711 paramValue, "NULL"));
712 reportSQL = Utils.replaceInString(reportSQL, fieldDisplay , nvl(
713 paramValue, "NULL"));
716 logger.debug(EELFLoggerDelegate.debugLogger, ("SQL " + reportSQL));
717 String legendCol = "1 a";
718 StringBuffer groupCol = new StringBuffer();
719 StringBuffer seriesCol = new StringBuffer();
720 StringBuffer valueCols = new StringBuffer();
722 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
723 DataColumnType dc = (DataColumnType) iter.next();
724 String colName = getColumnSelectStr(dc, request);
725 if (nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
726 legendCol = getSelectExpr(dc, colName)+" " + dc.getColId();
727 if ((!nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
728 && (dc.getChartSeq()!=null && dc.getChartSeq().intValue() <= 0) && dc.isGroupBreak()) {
729 groupCol.append(", ");
730 groupCol.append(colName + " " + dc.getColId());
733 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
734 DataColumnType dc = (DataColumnType) iter.next();
735 if(dc.isChartSeries()!=null && dc.isChartSeries().booleanValue()) {
736 seriesCol.append(", "+ getSelectExpr(dc,getColumnSelectStr(dc, request))+ " " + dc.getColId());
740 for (Iterator iter = chartValueCols.iterator(); iter.hasNext();) {
741 DataColumnType dc = (DataColumnType) iter.next();
742 String colName = getColumnSelectStr(dc, request);
743 String paramValue = "";
744 if(AppUtils.nvl(colName).startsWith("[")) {
745 if (reportRuntime.getFormFieldList() != null) {
746 for (Iterator iterC = reportRuntime.getFormFieldList().getFormField().iterator(); iterC.hasNext();) {
747 FormFieldType fft = (FormFieldType) iterC.next();
748 String fieldId = fft.getFieldId();
749 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
750 String formfield_value = "";
751 if(AppUtils.nvl(fieldDisplay).equals(colName)) {
752 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
753 paramValue = nvl(formfield_value);
759 seriesCol.append("," + (AppUtils.nvl(paramValue).length()>0? paramValue:"null") + " " + dc.getColId());
761 seriesCol.append("," + (AppUtils.nvl(paramValue).length()>0? paramValue:formatChartColumn(colName)) + " " + dc.getColId());
765 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
766 DataColumnType dc = (DataColumnType) iter.next();
767 String colName = dc.getDisplayName();
768 String colValue = getColumnSelectStr(dc, request);
769 if(colName.equals(AppConstants.RI_CHART_TOTAL_COL))
770 seriesCol.append(", " + AppConstants.RI_CHART_TOTAL_COL + " " + AppConstants.RI_CHART_TOTAL_COL );
771 if (colName.equals(AppConstants.RI_CHART_COLOR))
772 seriesCol.append(", " + colValue + " " + AppConstants.RI_CHART_COLOR );
773 if(colName.equals(AppConstants.RI_CHART_MARKER_START))
774 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_START + " " + AppConstants.RI_CHART_MARKER_START );
775 if(colName.equals(AppConstants.RI_CHART_MARKER_END))
776 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_END + " " + AppConstants.RI_CHART_MARKER_END );
777 if(colName.equals(AppConstants.RI_CHART_MARKER_TEXT_LEFT))
778 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_TEXT_LEFT + " " + AppConstants.RI_CHART_MARKER_TEXT_LEFT );
779 if(colName.equals(AppConstants.RI_CHART_MARKER_TEXT_RIGHT))
780 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_TEXT_RIGHT + " " + AppConstants.RI_CHART_MARKER_TEXT_RIGHT );
783 String final_sql = "";
784 reportSQL = Utils.replaceInString(reportSQL, " from ", " FROM ");
785 reportSQL = Utils.replaceInString(reportSQL, " From ", " FROM ");
786 reportSQL = Utils.replaceInString(reportSQL, " select ", " SELECT ");
787 reportSQL = Utils.replaceInString(reportSQL, " union ", " UNION ");
790 int pos_first_select = 0;
791 int pos_dup_select = 0;
792 int pos_prev_select = 0;
793 int pos_last_select = 0;
794 if (reportSQL.indexOf("FROM", pos)!=-1) {
795 pos = reportSQL.indexOf("FROM", pos);
796 pos_dup_select = reportSQL.lastIndexOf("SELECT",pos);
797 pos_first_select = reportSQL.indexOf("SELECT");
798 logger.debug(EELFLoggerDelegate.debugLogger, ("pos_select " + pos_first_select + " " + pos_dup_select));
799 if(pos_dup_select > pos_first_select) {
800 logger.debug(EELFLoggerDelegate.debugLogger, ("********pos_dup_select ********" + pos_dup_select));
801 pos_prev_select = pos_first_select;
802 pos_last_select = pos_dup_select;
803 while (pos_last_select > pos_prev_select) {
804 logger.debug(EELFLoggerDelegate.debugLogger, ("pos_last , pos_prev " + pos_last_select + " " + pos_prev_select));
805 pos = reportSQL.indexOf("FROM", pos+2);
806 pos_prev_select = pos_last_select;
807 pos_last_select = reportSQL.lastIndexOf("SELECT",pos);
808 logger.debug(EELFLoggerDelegate.debugLogger, ("in WHILE LOOP LAST " + pos_last_select));
813 final_sql += " "+reportSQL.substring(pos);
814 logger.debug(EELFLoggerDelegate.debugLogger, ("Final SQL " + final_sql));
815 String sql = "SELECT " + legendCol + ", " + legendCol+"_1" + seriesCol.toString()+ nvl(valueCols.toString(), ", 1")
816 + groupCol.toString()
818 logger.debug(EELFLoggerDelegate.debugLogger, ("Final sql in generateChartSQL " +sql));
821 } // generateChartSQL
823 private String getColumnSelectStr(DataColumnType dc, HttpServletRequest request) {
824 String colName = dc.getColName();
825 String paramValue = null;
826 if (reportRuntime.getFormFieldList() != null) {
827 for (Iterator iter = reportRuntime.getFormFieldList().getFormField().iterator(); iter.hasNext();) {
828 FormFieldType fft = (FormFieldType) iter.next();
829 String fieldId = fft.getFieldId();
830 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
831 String formfield_value = "";
832 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
833 paramValue = nvl(formfield_value);
834 if(paramValue.length()>0) {
835 colName = Utils.replaceInString(colName, "'" + fieldDisplay + "'", "'"+nvl(
836 paramValue, "NULL")+"'");
837 colName = Utils.replaceInString(colName, fieldDisplay, nvl(
838 paramValue, "NULL"));
844 } // getColumnSelectStr
848 public String getSelectExpr(DataColumnType dct) {
849 return getSelectExpr(dct, dct.getColName() /* colName */);
852 private String getSelectExpr(DataColumnType dct, String colName) {
853 String colType = dct.getColType();
854 if (colType.equals(AppConstants.CT_CHAR)
855 || ((nvl(dct.getColFormat()).length() == 0) && (!colType
856 .equals(AppConstants.CT_DATE))))
859 return "TO_CHAR(" + colName + ", '"
860 + nvl(dct.getColFormat(), AppConstants.DEFAULT_DATE_FORMAT) + "')";
863 private String formatChartColumn(String colName) {
864 logger.debug(EELFLoggerDelegate.debugLogger, ("Format Chart Column Input colName " + colName));
865 colName = colName.trim();
866 colName = Utils.replaceInString(colName, "TO_CHAR", "to_char");
867 colName = Utils.replaceInString(colName, "to_number", "TO_NUMBER");
868 colName = colName.replaceAll(",[\\s]*\\(", ",(");
869 StringBuffer colNameBuf = new StringBuffer(colName);
870 int pos = 0, posFormatStart = 0, posFormatEnd = 0;
873 if(colNameBuf.indexOf("999")==-1 && colNameBuf.indexOf("990")==-1) {
874 logger.debug(EELFLoggerDelegate.debugLogger, (" return colName " + colNameBuf.toString()));
875 return colNameBuf.toString();
878 while (colNameBuf.indexOf("to_char")!=-1) {
879 if(colNameBuf.indexOf("999")!=-1 || colNameBuf.indexOf("990")!=-1) {
880 pos = colNameBuf.indexOf("to_char");
881 colNameBuf.insert(pos, " TO_NUMBER ( CR_RAPTOR.SAFE_TO_NUMBER (");
882 pos = colNameBuf.indexOf("to_char");
883 colNameBuf.replace(pos, pos+7, "TO_CHAR");
884 logger.debug(EELFLoggerDelegate.debugLogger, ("After adding to_number " + colNameBuf.toString()));
885 posFormatStart = colNameBuf.indexOf(",'", pos)+1;
886 posFormatEnd = colNameBuf.indexOf(")",posFormatStart);
887 logger.debug(EELFLoggerDelegate.debugLogger, (posFormatStart + " " + posFormatEnd + " "+ pos));
888 format = colNameBuf.substring(posFormatStart, posFormatEnd);
889 colNameBuf.insert(posFormatEnd+1, " ," + format + ") , "+ format + ")");
890 logger.debug(EELFLoggerDelegate.debugLogger, ("colNameBuf " + colNameBuf.toString()));
893 logger.debug(EELFLoggerDelegate.debugLogger, (" return colName " + colNameBuf.toString()));
894 return colNameBuf.toString();
897 public List getChartValueColumnsList( int filter, HashMap formValues) { /*filter; all=0;create without new chart =1; createNewChart=2 */
898 List reportCols = reportRuntime.getAllColumns();
900 ArrayList chartValueCols = new ArrayList();
902 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
904 DataColumnType dc = (DataColumnType) iter.next();
905 flag = reportRuntime.getDependsOnFormFieldFlag(dc, formValues);
907 if( (dc.getChartSeq()!=null && dc.getChartSeq()> 0) && flag == 0 && !(nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
908 if(nvl(dc.getChartGroup()).length()<=0) {
909 if( filter == 2 && (dc.isCreateInNewChart()!=null && dc.isCreateInNewChart().booleanValue())) {
910 chartValueCols.add(dc);
911 } else if (filter == 1 && (dc.isCreateInNewChart()==null || !dc.isCreateInNewChart().booleanValue())) {
912 chartValueCols.add(dc);
915 chartValueCols.add(dc);
916 } else chartValueCols.add(dc);
919 Collections.sort(chartValueCols, new ChartSeqComparator());
920 return chartValueCols;
921 } // getChartValueColumnsList
923 public String parseTitle(String title, HashMap formValues) {
924 Set set = formValues.entrySet();
925 for(Iterator iter = set.iterator(); iter.hasNext(); ) {
926 Map.Entry entry = (Entry<String,String>) iter.next();
927 if(title.indexOf("["+ entry.getKey() + "]")!= -1) {
928 title = Utils.replaceInString(title, "["+entry.getKey()+"]", nvl(
929 (String) entry.getValue(), ""));
935 public java.util.Date getDateFromDateStr(String dateStr) {
936 SimpleDateFormat MMDDYYYYFormat = new SimpleDateFormat("MM/dd/yyyy");
937 SimpleDateFormat EEEMMDDYYYYFormat = new SimpleDateFormat("EEE, MM/dd/yyyy"); //2012-11-01 00:00:00
938 SimpleDateFormat YYYYMMDDFormat = new SimpleDateFormat("yyyy/MM/dd");
939 SimpleDateFormat MONYYYYFormat = new SimpleDateFormat("MMM yyyy");
940 SimpleDateFormat MMYYYYFormat = new SimpleDateFormat("MM/yyyy");
941 SimpleDateFormat MMMMMDDYYYYFormat = new SimpleDateFormat("MMMMM dd, yyyy");
942 SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
943 SimpleDateFormat timestampHrFormat = new SimpleDateFormat("yyyy-MM-dd HH");
944 SimpleDateFormat timestampDayFormat = new SimpleDateFormat("yyyy-MM-dd");
945 SimpleDateFormat DDMONYYYYFormat = new SimpleDateFormat("dd-MMM-yyyy");
946 SimpleDateFormat MONTHYYYYFormat = new SimpleDateFormat("MMMMM, yyyy");
947 SimpleDateFormat MMDDYYYYHHFormat = new SimpleDateFormat("MM/dd/yyyy HH");
948 SimpleDateFormat MMDDYYYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
949 SimpleDateFormat MMDDYYYYHHMMFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
950 SimpleDateFormat YYYYMMDDHHMMSSFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
951 SimpleDateFormat YYYYMMDDHHMMFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
952 SimpleDateFormat DDMONYYYYHHMMSSFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
953 SimpleDateFormat DDMONYYYYHHMMFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
954 SimpleDateFormat MMDDYYFormat = new SimpleDateFormat("MM/dd/yy");
955 SimpleDateFormat MMDDYYHHMMFormat = new SimpleDateFormat("MM/dd/yy HH:mm");
956 SimpleDateFormat MMDDYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
957 SimpleDateFormat timestampFormat1 = new SimpleDateFormat("yyyy-M-d.HH.mm. s. S");
958 SimpleDateFormat MMDDYYYYHHMMZFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm z");
959 SimpleDateFormat YYYYFormat = new SimpleDateFormat("yyyy");
960 java.util.Date date = null;
964 final int YEARFLAG = 1;
965 final int MONTHFLAG = 2;
966 final int DAYFLAG = 3;
967 final int HOURFLAG = 4;
968 final int MINFLAG = 5;
969 final int SECFLAG = 6;
970 final int MILLISECFLAG = 7;
971 final int DAYOFTHEWEEKFLAG = 8;
972 final int FLAGDATE = 9;
974 date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
976 formatFlag = SECFLAG;
978 date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
980 formatFlag = DAYOFTHEWEEKFLAG;
983 date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
985 formatFlag = MINFLAG;
988 date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0));
990 formatFlag = HOURFLAG;
993 date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
995 formatFlag = DAYFLAG;
998 date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0));
1000 formatFlag = DAYFLAG;
1003 date = timestampFormat.parse(dateStr, new ParsePosition(0));
1005 formatFlag = SECFLAG;
1008 date = timestampHrFormat.parse(dateStr, new ParsePosition(0));
1010 formatFlag = HOURFLAG;
1013 date = timestampDayFormat.parse(dateStr, new ParsePosition(0));
1015 formatFlag = DAYFLAG;
1019 date = MONYYYYFormat.parse(dateStr, new ParsePosition(0));
1021 formatFlag = MONTHFLAG;
1024 date = MMYYYYFormat.parse(dateStr, new ParsePosition(0));
1026 formatFlag = MONTHFLAG;
1029 date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1031 formatFlag = DAYFLAG;
1034 date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0));
1036 formatFlag = MONTHFLAG;
1040 date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1042 formatFlag = SECFLAG;
1046 date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0));
1048 formatFlag = MINFLAG;
1052 date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1054 formatFlag = SECFLAG;
1058 date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1060 formatFlag = MINFLAG;
1064 date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0));
1066 formatFlag = DAYFLAG;
1070 date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1072 formatFlag = SECFLAG;
1076 date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1078 formatFlag = MINFLAG;
1082 date = MMDDYYFormat.parse(dateStr, new ParsePosition(0));
1084 formatFlag = DAYFLAG;
1088 date = timestampFormat1.parse(dateStr, new ParsePosition(0));
1090 formatFlag = SECFLAG;
1094 date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0));
1096 formatFlag = MINFLAG;
1100 date = YYYYFormat.parse(dateStr, new ParsePosition(0));
1101 /* Some random numbers should not satisfy this year format. */
1102 if(dateStr.length()>4)
1105 formatFlag = YEARFLAG;
1112 public int getFlagFromDateStr(String dateStr) {
1113 SimpleDateFormat MMDDYYYYFormat = new SimpleDateFormat("MM/dd/yyyy");
1114 SimpleDateFormat EEEMMDDYYYYFormat = new SimpleDateFormat("EEE, MM/dd/yyyy"); //2012-11-01 00:00:00
1115 SimpleDateFormat YYYYMMDDFormat = new SimpleDateFormat("yyyy/MM/dd");
1116 SimpleDateFormat MONYYYYFormat = new SimpleDateFormat("MMM yyyy");
1117 SimpleDateFormat MMYYYYFormat = new SimpleDateFormat("MM/yyyy");
1118 SimpleDateFormat MMMMMDDYYYYFormat = new SimpleDateFormat("MMMMM dd, yyyy");
1119 SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1120 SimpleDateFormat timestampHrFormat = new SimpleDateFormat("yyyy-MM-dd HH");
1121 SimpleDateFormat timestampDayFormat = new SimpleDateFormat("yyyy-MM-dd");
1122 SimpleDateFormat DDMONYYYYFormat = new SimpleDateFormat("dd-MMM-yyyy");
1123 SimpleDateFormat MONTHYYYYFormat = new SimpleDateFormat("MMMMM, yyyy");
1124 SimpleDateFormat MMDDYYYYHHFormat = new SimpleDateFormat("MM/dd/yyyy HH");
1125 SimpleDateFormat MMDDYYYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
1126 SimpleDateFormat MMDDYYYYHHMMFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
1127 SimpleDateFormat YYYYMMDDHHMMSSFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
1128 SimpleDateFormat YYYYMMDDHHMMFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
1129 SimpleDateFormat DDMONYYYYHHMMSSFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
1130 SimpleDateFormat DDMONYYYYHHMMFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
1131 SimpleDateFormat MMDDYYFormat = new SimpleDateFormat("MM/dd/yy");
1132 SimpleDateFormat MMDDYYHHMMFormat = new SimpleDateFormat("MM/dd/yy HH:mm");
1133 SimpleDateFormat MMDDYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
1134 SimpleDateFormat timestampFormat1 = new SimpleDateFormat("yyyy-M-d.HH.mm. s. S");
1135 SimpleDateFormat MMDDYYYYHHMMZFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm z");
1136 SimpleDateFormat YYYYFormat = new SimpleDateFormat("yyyy");
1137 java.util.Date date = null;
1141 final int YEARFLAG = 1;
1142 final int MONTHFLAG = 2;
1143 final int DAYFLAG = 3;
1144 final int HOURFLAG = 4;
1145 final int MINFLAG = 5;
1146 final int SECFLAG = 6;
1147 final int MILLISECFLAG = 7;
1148 final int DAYOFTHEWEEKFLAG = 8;
1149 final int FLAGDATE = 9;
1151 date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1153 formatFlag = SECFLAG;
1155 date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1157 formatFlag = DAYOFTHEWEEKFLAG;
1160 date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1162 formatFlag = MINFLAG;
1165 date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0));
1167 formatFlag = HOURFLAG;
1170 date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1172 formatFlag = DAYFLAG;
1175 date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0));
1177 formatFlag = DAYFLAG;
1180 date = timestampFormat.parse(dateStr, new ParsePosition(0));
1182 formatFlag = SECFLAG;
1185 date = timestampHrFormat.parse(dateStr, new ParsePosition(0));
1187 formatFlag = HOURFLAG;
1190 date = timestampDayFormat.parse(dateStr, new ParsePosition(0));
1192 formatFlag = DAYFLAG;
1195 date = MONYYYYFormat.parse(dateStr, new ParsePosition(0));
1197 formatFlag = MONTHFLAG;
1200 date = MMYYYYFormat.parse(dateStr, new ParsePosition(0));
1202 formatFlag = MONTHFLAG;
1205 date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1207 formatFlag = DAYFLAG;
1210 date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0));
1212 formatFlag = MONTHFLAG;
1216 date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1218 formatFlag = SECFLAG;
1222 date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0));
1224 formatFlag = MINFLAG;
1228 date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1230 formatFlag = SECFLAG;
1234 date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1236 formatFlag = MINFLAG;
1240 date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0));
1242 formatFlag = DAYFLAG;
1246 date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1248 formatFlag = SECFLAG;
1252 date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1254 formatFlag = MINFLAG;
1258 date = MMDDYYFormat.parse(dateStr, new ParsePosition(0));
1260 formatFlag = DAYFLAG;
1264 date = timestampFormat1.parse(dateStr, new ParsePosition(0));
1266 formatFlag = SECFLAG;
1270 date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0));
1272 formatFlag = MINFLAG;
1276 date = YYYYFormat.parse(dateStr, new ParsePosition(0));
1277 /* Some random numbers should not satisfy this year format. */
1278 if(dateStr.length()>4)
1281 formatFlag = YEARFLAG;
1288 public static String[] reverse(String[] arr) {
1289 List<String> list = Arrays.asList(arr);
1290 Collections.reverse(list);
1291 return (String[])list.toArray();
1294 public int getNumberOfDecimalPlaces(double num) {
1296 String[] splitter = d.toString().split("\\.");
1297 splitter[0].length(); // Before Decimal Count
1298 splitter[1].length(); // After Decimal Count
1299 return splitter[1].length();
1302 public boolean getBooleanValue(String s) {
1303 return getBooleanValue(s,null);
1306 public boolean getBooleanValue(String s, Boolean defaultValue) {
1308 if(s.length()<=0 && defaultValue!=null)
1309 return defaultValue.booleanValue();
1310 else if(s.length()<=0)
1313 if(s.toUpperCase().startsWith("Y") || s.toLowerCase().equals("true"))
1321 public String IntToLetter(int Int) {
1323 return Character.toString((char)(Int+96));
1326 return IntToLetter((Int/26)-1)+IntToLetter((Int%26)+1);
1328 return IntToLetter(Int/26)+IntToLetter(Int%26);
1336 private void clearReportRuntimeBackup(HttpServletRequest request) {
1337 HttpSession session = request.getSession();
1338 session.removeAttribute(AppConstants.DRILLDOWN_REPORTS_LIST);
1339 request.removeAttribute(AppConstants.DRILLDOWN_INDEX);
1340 session.removeAttribute(AppConstants.DRILLDOWN_INDEX);
1341 request.removeAttribute(AppConstants.FORM_DRILLDOWN_INDEX);
1342 session.removeAttribute(AppConstants.FORM_DRILLDOWN_INDEX);
1343 Enumeration<String> enum1 = session.getAttributeNames();
1344 String attributeName = "";
1345 while(enum1.hasMoreElements()) {
1346 attributeName = enum1.nextElement();
1347 if(attributeName.startsWith("parent_")) {
1348 session.removeAttribute(attributeName);
1351 session.removeAttribute(AppConstants.DRILLDOWN_REPORTS_LIST);
1352 session.removeAttribute(AppConstants.SI_BACKUP_FOR_REP_ID);
1353 session.removeAttribute(AppConstants.SI_COLUMN_LOOKUP);
1354 session.removeAttribute(AppConstants.SI_DASHBOARD_REP_ID);
1355 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP);
1356 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME);
1357 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP);
1358 session.removeAttribute(AppConstants.SI_DASHBOARD_CHARTDATA_MAP);
1359 session.removeAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP);
1360 session.removeAttribute(AppConstants.SI_DATA_SIZE_FOR_TEXTFIELD_POPUP);
1361 session.removeAttribute(AppConstants.SI_MAP);
1362 session.removeAttribute(AppConstants.SI_MAP_OBJECT);
1363 session.removeAttribute(AppConstants.SI_REPORT_DEFINITION);
1364 session.removeAttribute(AppConstants.SI_REPORT_RUNTIME);
1365 session.removeAttribute(AppConstants.SI_REPORT_RUN_BACKUP);
1366 session.removeAttribute(AppConstants.SI_REPORT_SCHEDULE);
1367 session.removeAttribute(AppConstants.RI_REPORT_DATA);
1368 session.removeAttribute(AppConstants.RI_CHART_DATA);
1369 session.removeAttribute(AppConstants.SI_FORMFIELD_INFO);
1370 session.removeAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO);
1372 } // clearReportRuntimeBackup
1375 public static synchronized java.util.HashMap getRequestParametersMap(ReportRuntime rr, HttpServletRequest request)
1377 HashMap valuesMap = new HashMap();
1379 ReportFormFields rff = rr.getReportFormFields();
1382 FormField ff = null;
1384 Map fieldNameMap = new HashMap();
1385 int countOfFields = 0 ;
1388 for(rff.resetNext(); rff.hasNext(); idx++) {
1390 fieldNameMap.put(ff.getFieldName(), ff.getFieldDisplayName());
1394 List formParameter = new ArrayList();
1395 String formField = "";
1396 for(int i = 0 ; i < rff.size(); i++) {
1397 ff = ((FormField)rff.getFormField(i));
1398 formField = ff.getFieldName();
1399 boolean isMultiValue = false;
1400 isMultiValue = ff.getFieldType().equals(FormField.FFT_CHECK_BOX)
1401 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI);
1402 boolean isTextArea = (ff.getFieldType().equals(FormField.FFT_TEXTAREA) && rr.getReportDefType()
1403 .equals(AppConstants.RD_SQL_BASED));
1405 if(request.getParameterValues(formField) != null && isMultiValue ) {
1406 String[] vals = request.getParameterValues(formField);
1407 StringBuffer value = new StringBuffer("");
1408 if(!AppUtils.getRequestFlag(request, AppConstants.RI_RESET_ACTION)) {
1410 if ( isMultiValue ) {
1413 for(int j = 0 ; j < vals.length; j++) {
1417 if(vals[j] !=null && vals[j].length() > 0) {
1418 vals[j] = Utils.oracleSafe(vals[j]);
1419 value.append(java.net.URLDecoder.decode(vals[j], "UTF-8"));
1422 value.append(vals[j]);
1423 } catch (UnsupportedEncodingException ex) {value.append(vals[j]);}
1424 catch (IllegalArgumentException ex1){value.append(vals[j]);}
1425 catch (Exception ex2){
1426 value.append(vals[j]);
1433 if(j != vals.length -1) {
1437 if(vals.length > 0) {
1442 valuesMap.put(fieldNameMap.get(formField), value.toString());
1443 value = new StringBuffer("");
1444 } else if(request.getParameter(formField) != null) {
1447 value = request.getParameter(formField);
1449 value = Utils.oracleSafe(value);
1450 value = "('" + Utils.replaceInString(value, ",", "'|'") + "')";
1451 value = Utils.replaceInString(value, "|", ",");
1452 valuesMap.put(fieldNameMap.get(formField), value);
1456 if(!AppUtils.getRequestFlag(request, AppConstants.RI_RESET_ACTION))
1457 value = request.getParameter(formField);
1458 valuesMap.put(fieldNameMap.get(formField), Utils.oracleSafe(value));
1462 valuesMap.put(fieldNameMap.get(formField), "" );