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.
645 //if (!getDisplayChart())
649 sql = generateChartSQL(userId, request);
650 logger.debug(EELFLoggerDelegate.debugLogger, ("SQL generated " + sql));
651 String dbInfo = reportRuntime.getDBInfo();
652 DataSet ds = ConnectionUtils.getDataSet(sql, dbInfo);
653 if(ds.getRowCount()<=0) {
654 logger.info(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
655 logger.info(EELFLoggerDelegate.debugLogger, (getChartType().toUpperCase()+" - " + "Report ID : " + reportRuntime.getReportID() + " DATA IS EMPTY"));
656 logger.info(EELFLoggerDelegate.debugLogger, ("QUERY - " + sql));
657 logger.info(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
663 public String generateChartSQL(String userId, HttpServletRequest request ) throws RaptorException {
664 List reportCols = reportRuntime.getAllColumns();
665 List chartValueCols = getChartValueColumnsList(AppConstants.CHART_ALL_COLUMNS, null); // parameter is 0 has this requires all columns.
666 String reportSQL = reportRuntime.getWholeSQL();
668 //Add order by clause
669 Pattern re1 = Pattern.compile("(^[\r\n]*|([\\s]))[Oo][Rr][Dd][Ee][Rr](.*?[^\r\n]*)[Bb][Yy]",Pattern.DOTALL);
670 Matcher matcher = re1.matcher(reportSQL);
672 reportSQL = reportSQL + " ";
673 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ss][Ee][Ll][Ee][Cc][Tt]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" SELECT ");
674 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ww][Hh][Ee][Rr][Ee]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" WHERE ");
675 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ww][Hh][Ee][Nn]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" WHEN ");
676 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Aa][Nn][Dd]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" AND ");
678 if(!reportRuntime.getReportType().equals(AppConstants.RT_HIVE)) {
679 int startPoint = reportSQL.lastIndexOf(" FROM ");
680 if(startPoint <= 0) {
681 startPoint = reportSQL.lastIndexOf(" from ");
683 if(startPoint <= 0) {
684 startPoint = reportSQL.lastIndexOf("from ");
686 if(startPoint <= 0) {
687 startPoint = reportSQL.lastIndexOf("FROM ");
690 if (!matcher.find(startPoint)) {
691 reportSQL = reportSQL + " ORDER BY 1" ;
694 reportRuntime.setWholeSQL(reportSQL);
696 logger.debug(EELFLoggerDelegate.debugLogger, (" *************************************************************************************** "));
697 logger.debug(EELFLoggerDelegate.debugLogger, ("WHOLE_SQL" + reportSQL));
698 logger.debug(EELFLoggerDelegate.debugLogger, (" *************************************************************************************** "));
700 if (reportRuntime.getFormFieldList() != null) {
701 for (Iterator iter = reportRuntime.getFormFieldList().getFormField().iterator(); iter.hasNext();) {
702 FormFieldType fft = (FormFieldType) iter.next();
703 String fieldId = fft.getFieldId();
704 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
705 String formfield_value = "";
706 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
707 String paramValue = nvl(formfield_value);
708 if(paramValue.length()>0) {
709 reportSQL = Utils.replaceInString(reportSQL, fieldDisplay, nvl(
710 paramValue, "NULL"));
712 reportSQL = Utils.replaceInString(reportSQL, "'" + fieldDisplay + "'", nvl(
713 paramValue, "NULL"));
714 reportSQL = Utils.replaceInString(reportSQL, fieldDisplay , nvl(
715 paramValue, "NULL"));
718 logger.debug(EELFLoggerDelegate.debugLogger, ("SQL " + reportSQL));
719 String legendCol = "1 a";
720 StringBuffer groupCol = new StringBuffer();
721 StringBuffer seriesCol = new StringBuffer();
722 StringBuffer valueCols = new StringBuffer();
724 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
725 DataColumnType dc = (DataColumnType) iter.next();
726 String colName = getColumnSelectStr(dc, request);
727 if (nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
728 legendCol = getSelectExpr(dc, colName)+" " + dc.getColId();
729 if ((!nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
730 && (dc.getChartSeq()!=null && dc.getChartSeq().intValue() <= 0) && dc.isGroupBreak()) {
731 groupCol.append(", ");
732 groupCol.append(colName + " " + dc.getColId());
735 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
736 DataColumnType dc = (DataColumnType) iter.next();
737 if(dc.isChartSeries()!=null && dc.isChartSeries().booleanValue()) {
738 seriesCol.append(", "+ getSelectExpr(dc,getColumnSelectStr(dc, request))+ " " + dc.getColId());
742 for (Iterator iter = chartValueCols.iterator(); iter.hasNext();) {
743 DataColumnType dc = (DataColumnType) iter.next();
744 String colName = getColumnSelectStr(dc, request);
745 String paramValue = "";
746 if(AppUtils.nvl(colName).startsWith("[")) {
747 if (reportRuntime.getFormFieldList() != null) {
748 for (Iterator iterC = reportRuntime.getFormFieldList().getFormField().iterator(); iterC.hasNext();) {
749 FormFieldType fft = (FormFieldType) iterC.next();
750 String fieldId = fft.getFieldId();
751 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
752 String formfield_value = "";
753 if(AppUtils.nvl(fieldDisplay).equals(colName)) {
754 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
755 paramValue = nvl(formfield_value);
761 seriesCol.append("," + (AppUtils.nvl(paramValue).length()>0? paramValue:"null") + " " + dc.getColId());
763 seriesCol.append("," + (AppUtils.nvl(paramValue).length()>0? paramValue:formatChartColumn(colName)) + " " + dc.getColId());
767 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
768 DataColumnType dc = (DataColumnType) iter.next();
769 String colName = dc.getDisplayName();
770 String colValue = getColumnSelectStr(dc, request);
771 if(colName.equals(AppConstants.RI_CHART_TOTAL_COL))
772 seriesCol.append(", " + AppConstants.RI_CHART_TOTAL_COL + " " + AppConstants.RI_CHART_TOTAL_COL );
773 if (colName.equals(AppConstants.RI_CHART_COLOR))
774 seriesCol.append(", " + colValue + " " + AppConstants.RI_CHART_COLOR );
775 if(colName.equals(AppConstants.RI_CHART_MARKER_START))
776 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_START + " " + AppConstants.RI_CHART_MARKER_START );
777 if(colName.equals(AppConstants.RI_CHART_MARKER_END))
778 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_END + " " + AppConstants.RI_CHART_MARKER_END );
779 if(colName.equals(AppConstants.RI_CHART_MARKER_TEXT_LEFT))
780 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_TEXT_LEFT + " " + AppConstants.RI_CHART_MARKER_TEXT_LEFT );
781 if(colName.equals(AppConstants.RI_CHART_MARKER_TEXT_RIGHT))
782 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_TEXT_RIGHT + " " + AppConstants.RI_CHART_MARKER_TEXT_RIGHT );
785 String final_sql = "";
786 reportSQL = Utils.replaceInString(reportSQL, " from ", " FROM ");
787 reportSQL = Utils.replaceInString(reportSQL, " From ", " FROM ");
788 reportSQL = Utils.replaceInString(reportSQL, " select ", " SELECT ");
789 reportSQL = Utils.replaceInString(reportSQL, " union ", " UNION ");
792 int pos_first_select = 0;
793 int pos_dup_select = 0;
794 int pos_prev_select = 0;
795 int pos_last_select = 0;
796 if (reportSQL.indexOf("FROM", pos)!=-1) {
797 pos = reportSQL.indexOf("FROM", pos);
798 pos_dup_select = reportSQL.lastIndexOf("SELECT",pos);
799 pos_first_select = reportSQL.indexOf("SELECT");
800 logger.debug(EELFLoggerDelegate.debugLogger, ("pos_select " + pos_first_select + " " + pos_dup_select));
801 if(pos_dup_select > pos_first_select) {
802 logger.debug(EELFLoggerDelegate.debugLogger, ("********pos_dup_select ********" + pos_dup_select));
803 pos_prev_select = pos_first_select;
804 pos_last_select = pos_dup_select;
805 while (pos_last_select > pos_prev_select) {
806 logger.debug(EELFLoggerDelegate.debugLogger, ("pos_last , pos_prev " + pos_last_select + " " + pos_prev_select));
807 pos = reportSQL.indexOf("FROM", pos+2);
808 pos_prev_select = pos_last_select;
809 pos_last_select = reportSQL.lastIndexOf("SELECT",pos);
810 logger.debug(EELFLoggerDelegate.debugLogger, ("in WHILE LOOP LAST " + pos_last_select));
815 final_sql += " "+reportSQL.substring(pos);
816 logger.debug(EELFLoggerDelegate.debugLogger, ("Final SQL " + final_sql));
817 String sql = "SELECT " + legendCol + ", " + legendCol+"_1" + seriesCol.toString()+ nvl(valueCols.toString(), ", 1")
818 + groupCol.toString()
820 logger.debug(EELFLoggerDelegate.debugLogger, ("Final sql in generateChartSQL " +sql));
823 } // generateChartSQL
825 private String getColumnSelectStr(DataColumnType dc, HttpServletRequest request) {
826 String colName = dc.getColName();
827 String paramValue = null;
828 //if (dc.isCalculated()) {
829 if (reportRuntime.getFormFieldList() != null) {
830 for (Iterator iter = reportRuntime.getFormFieldList().getFormField().iterator(); iter.hasNext();) {
831 FormFieldType fft = (FormFieldType) iter.next();
832 String fieldId = fft.getFieldId();
833 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
834 String formfield_value = "";
835 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
836 paramValue = nvl(formfield_value);
837 if(paramValue.length()>0) {
838 /*sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
839 paramValue, "NULL"));*/
840 colName = Utils.replaceInString(colName, "'" + fieldDisplay + "'", "'"+nvl(
841 paramValue, "NULL")+"'");
842 colName = Utils.replaceInString(colName, fieldDisplay, nvl(
843 paramValue, "NULL"));
850 } // getColumnSelectStr
854 public String getSelectExpr(DataColumnType dct) {
856 // dct.isCalculated()?dct.getColName():((nvl(dct.getTableId()).length()>0)?(dct.getTableId()+"."+dct.getColName()):dct.getColName());
857 return getSelectExpr(dct, dct.getColName() /* colName */);
860 private String getSelectExpr(DataColumnType dct, String colName) {
861 String colType = dct.getColType();
862 if (colType.equals(AppConstants.CT_CHAR)
863 || ((nvl(dct.getColFormat()).length() == 0) && (!colType
864 .equals(AppConstants.CT_DATE))))
867 return "TO_CHAR(" + colName + ", '"
868 + nvl(dct.getColFormat(), AppConstants.DEFAULT_DATE_FORMAT) + "')";
871 private String formatChartColumn(String colName) {
872 logger.debug(EELFLoggerDelegate.debugLogger, ("Format Chart Column Input colName " + colName));
873 colName = colName.trim();
874 colName = Utils.replaceInString(colName, "TO_CHAR", "to_char");
875 colName = Utils.replaceInString(colName, "to_number", "TO_NUMBER");
876 //reportSQL = reportSQL.replaceAll("[\\s]*\\(", "(");
877 colName = colName.replaceAll(",[\\s]*\\(", ",(");
878 StringBuffer colNameBuf = new StringBuffer(colName);
879 int pos = 0, posFormatStart = 0, posFormatEnd = 0;
882 if(colNameBuf.indexOf("999")==-1 && colNameBuf.indexOf("990")==-1) {
883 logger.debug(EELFLoggerDelegate.debugLogger, (" return colName " + colNameBuf.toString()));
884 return colNameBuf.toString();
887 while (colNameBuf.indexOf("to_char")!=-1) {
888 if(colNameBuf.indexOf("999")!=-1 || colNameBuf.indexOf("990")!=-1) {
889 pos = colNameBuf.indexOf("to_char");
890 colNameBuf.insert(pos, " TO_NUMBER ( CR_RAPTOR.SAFE_TO_NUMBER (");
891 pos = colNameBuf.indexOf("to_char");
892 colNameBuf.replace(pos, pos+7, "TO_CHAR");
893 //colName = Utils.replaceInString(colNameBuf.toString(), "to_char", " TO_NUMBER ( CR_RAPTOR.SAFE_TO_NUMBER ( TO_CHAR ");
894 logger.debug(EELFLoggerDelegate.debugLogger, ("After adding to_number " + colNameBuf.toString()));
895 //posFormatStart = colNameBuf.lastIndexOf(",'")+1;
896 posFormatStart = colNameBuf.indexOf(",'", pos)+1;
897 posFormatEnd = colNameBuf.indexOf(")",posFormatStart);
898 logger.debug(EELFLoggerDelegate.debugLogger, (posFormatStart + " " + posFormatEnd + " "+ pos));
899 format = colNameBuf.substring(posFormatStart, posFormatEnd);
900 //posFormatEnd = colNameBuf.indexOf(")",posFormatEnd);
901 colNameBuf.insert(posFormatEnd+1, " ," + format + ") , "+ format + ")");
902 logger.debug(EELFLoggerDelegate.debugLogger, ("colNameBuf " + colNameBuf.toString()));
905 logger.debug(EELFLoggerDelegate.debugLogger, (" return colName " + colNameBuf.toString()));
906 return colNameBuf.toString();
909 public List getChartValueColumnsList( int filter, HashMap formValues) { /*filter; all=0;create without new chart =1; createNewChart=2 */
910 List reportCols = reportRuntime.getAllColumns();
912 ArrayList chartValueCols = new ArrayList();
914 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
916 DataColumnType dc = (DataColumnType) iter.next();
917 // if(filter == 2 || filter == 1) {
918 flag = reportRuntime.getDependsOnFormFieldFlag(dc, formValues);
920 if( (dc.getChartSeq()!=null && dc.getChartSeq()> 0) && flag == 0 && !(nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
921 if(nvl(dc.getChartGroup()).length()<=0) {
922 if( filter == 2 && (dc.isCreateInNewChart()!=null && dc.isCreateInNewChart().booleanValue())) {
923 chartValueCols.add(dc);
924 } else if (filter == 1 && (dc.isCreateInNewChart()==null || !dc.isCreateInNewChart().booleanValue())) {
925 chartValueCols.add(dc);
928 chartValueCols.add(dc);
929 } else chartValueCols.add(dc);
932 // chartValueCols.add(dc);
934 Collections.sort(chartValueCols, new ChartSeqComparator());
935 return chartValueCols;
936 } // getChartValueColumnsList
938 public String parseTitle(String title, HashMap formValues) {
939 Set set = formValues.entrySet();
940 for(Iterator iter = set.iterator(); iter.hasNext(); ) {
941 Map.Entry entry = (Entry<String,String>) iter.next();
942 if(title.indexOf("["+ entry.getKey() + "]")!= -1) {
943 title = Utils.replaceInString(title, "["+entry.getKey()+"]", nvl(
944 (String) entry.getValue(), ""));
950 public java.util.Date getDateFromDateStr(String dateStr) {
951 SimpleDateFormat MMDDYYYYFormat = new SimpleDateFormat("MM/dd/yyyy");
952 SimpleDateFormat EEEMMDDYYYYFormat = new SimpleDateFormat("EEE, MM/dd/yyyy"); //2012-11-01 00:00:00
953 SimpleDateFormat YYYYMMDDFormat = new SimpleDateFormat("yyyy/MM/dd");
954 SimpleDateFormat MONYYYYFormat = new SimpleDateFormat("MMM yyyy");
955 SimpleDateFormat MMYYYYFormat = new SimpleDateFormat("MM/yyyy");
956 SimpleDateFormat MMMMMDDYYYYFormat = new SimpleDateFormat("MMMMM dd, yyyy");
957 SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
958 SimpleDateFormat timestampHrFormat = new SimpleDateFormat("yyyy-MM-dd HH");
959 SimpleDateFormat timestampDayFormat = new SimpleDateFormat("yyyy-MM-dd");
960 SimpleDateFormat DDMONYYYYFormat = new SimpleDateFormat("dd-MMM-yyyy");
961 SimpleDateFormat MONTHYYYYFormat = new SimpleDateFormat("MMMMM, yyyy");
962 SimpleDateFormat MMDDYYYYHHFormat = new SimpleDateFormat("MM/dd/yyyy HH");
963 SimpleDateFormat MMDDYYYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
964 SimpleDateFormat MMDDYYYYHHMMFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
965 SimpleDateFormat YYYYMMDDHHMMSSFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
966 SimpleDateFormat YYYYMMDDHHMMFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
967 SimpleDateFormat DDMONYYYYHHMMSSFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
968 SimpleDateFormat DDMONYYYYHHMMFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
969 SimpleDateFormat MMDDYYFormat = new SimpleDateFormat("MM/dd/yy");
970 SimpleDateFormat MMDDYYHHMMFormat = new SimpleDateFormat("MM/dd/yy HH:mm");
971 SimpleDateFormat MMDDYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
972 SimpleDateFormat timestampFormat1 = new SimpleDateFormat("yyyy-M-d.HH.mm. s. S");
973 SimpleDateFormat MMDDYYYYHHMMZFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm z");
974 SimpleDateFormat YYYYFormat = new SimpleDateFormat("yyyy");
975 java.util.Date date = null;
979 final int YEARFLAG = 1;
980 final int MONTHFLAG = 2;
981 final int DAYFLAG = 3;
982 final int HOURFLAG = 4;
983 final int MINFLAG = 5;
984 final int SECFLAG = 6;
985 final int MILLISECFLAG = 7;
986 final int DAYOFTHEWEEKFLAG = 8;
987 final int FLAGDATE = 9;
994 int milliSecFlag = 7;
995 int dayoftheweekFlag = 8;
999 date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1001 formatFlag = SECFLAG;
1003 date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1005 formatFlag = DAYOFTHEWEEKFLAG;
1008 date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1010 formatFlag = MINFLAG;
1013 //MMDDYYYYHHFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
1014 date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0));
1016 formatFlag = HOURFLAG;
1019 date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1021 formatFlag = DAYFLAG;
1024 date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0));
1026 formatFlag = DAYFLAG;
1029 date = timestampFormat.parse(dateStr, new ParsePosition(0));
1031 formatFlag = SECFLAG;
1034 date = timestampHrFormat.parse(dateStr, new ParsePosition(0));
1036 formatFlag = HOURFLAG;
1039 date = timestampDayFormat.parse(dateStr, new ParsePosition(0));
1041 formatFlag = DAYFLAG;
1045 date = MONYYYYFormat.parse(dateStr, new ParsePosition(0));
1047 formatFlag = MONTHFLAG;
1050 date = MMYYYYFormat.parse(dateStr, new ParsePosition(0));
1052 formatFlag = MONTHFLAG;
1055 date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1057 formatFlag = DAYFLAG;
1060 date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0));
1062 formatFlag = MONTHFLAG;
1066 date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1068 formatFlag = SECFLAG;
1072 date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0));
1074 formatFlag = MINFLAG;
1078 date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1080 formatFlag = SECFLAG;
1084 date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1086 formatFlag = MINFLAG;
1090 date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0));
1092 formatFlag = DAYFLAG;
1096 date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1098 formatFlag = SECFLAG;
1102 date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1104 formatFlag = MINFLAG;
1108 date = MMDDYYFormat.parse(dateStr, new ParsePosition(0));
1110 formatFlag = DAYFLAG;
1114 date = timestampFormat1.parse(dateStr, new ParsePosition(0));
1116 formatFlag = SECFLAG;
1120 date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0));
1122 formatFlag = MINFLAG;
1126 date = YYYYFormat.parse(dateStr, new ParsePosition(0));
1127 /* Some random numbers should not satisfy this year format. */
1128 if(dateStr.length()>4)
1131 formatFlag = YEARFLAG;
1138 public int getFlagFromDateStr(String dateStr) {
1139 SimpleDateFormat MMDDYYYYFormat = new SimpleDateFormat("MM/dd/yyyy");
1140 SimpleDateFormat EEEMMDDYYYYFormat = new SimpleDateFormat("EEE, MM/dd/yyyy"); //2012-11-01 00:00:00
1141 SimpleDateFormat YYYYMMDDFormat = new SimpleDateFormat("yyyy/MM/dd");
1142 SimpleDateFormat MONYYYYFormat = new SimpleDateFormat("MMM yyyy");
1143 SimpleDateFormat MMYYYYFormat = new SimpleDateFormat("MM/yyyy");
1144 SimpleDateFormat MMMMMDDYYYYFormat = new SimpleDateFormat("MMMMM dd, yyyy");
1145 SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1146 SimpleDateFormat timestampHrFormat = new SimpleDateFormat("yyyy-MM-dd HH");
1147 SimpleDateFormat timestampDayFormat = new SimpleDateFormat("yyyy-MM-dd");
1148 SimpleDateFormat DDMONYYYYFormat = new SimpleDateFormat("dd-MMM-yyyy");
1149 SimpleDateFormat MONTHYYYYFormat = new SimpleDateFormat("MMMMM, yyyy");
1150 SimpleDateFormat MMDDYYYYHHFormat = new SimpleDateFormat("MM/dd/yyyy HH");
1151 SimpleDateFormat MMDDYYYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
1152 SimpleDateFormat MMDDYYYYHHMMFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
1153 SimpleDateFormat YYYYMMDDHHMMSSFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
1154 SimpleDateFormat YYYYMMDDHHMMFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
1155 SimpleDateFormat DDMONYYYYHHMMSSFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
1156 SimpleDateFormat DDMONYYYYHHMMFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
1157 SimpleDateFormat MMDDYYFormat = new SimpleDateFormat("MM/dd/yy");
1158 SimpleDateFormat MMDDYYHHMMFormat = new SimpleDateFormat("MM/dd/yy HH:mm");
1159 SimpleDateFormat MMDDYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
1160 SimpleDateFormat timestampFormat1 = new SimpleDateFormat("yyyy-M-d.HH.mm. s. S");
1161 SimpleDateFormat MMDDYYYYHHMMZFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm z");
1162 SimpleDateFormat YYYYFormat = new SimpleDateFormat("yyyy");
1163 java.util.Date date = null;
1167 final int YEARFLAG = 1;
1168 final int MONTHFLAG = 2;
1169 final int DAYFLAG = 3;
1170 final int HOURFLAG = 4;
1171 final int MINFLAG = 5;
1172 final int SECFLAG = 6;
1173 final int MILLISECFLAG = 7;
1174 final int DAYOFTHEWEEKFLAG = 8;
1175 final int FLAGDATE = 9;
1182 int milliSecFlag = 7;
1183 int dayoftheweekFlag = 8;
1187 date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1189 formatFlag = SECFLAG;
1191 date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1193 formatFlag = DAYOFTHEWEEKFLAG;
1196 date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1198 formatFlag = MINFLAG;
1201 //MMDDYYYYHHFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
1202 date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0));
1204 formatFlag = HOURFLAG;
1207 date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1209 formatFlag = DAYFLAG;
1212 date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0));
1214 formatFlag = DAYFLAG;
1217 date = timestampFormat.parse(dateStr, new ParsePosition(0));
1219 formatFlag = SECFLAG;
1222 date = timestampHrFormat.parse(dateStr, new ParsePosition(0));
1224 formatFlag = HOURFLAG;
1227 date = timestampDayFormat.parse(dateStr, new ParsePosition(0));
1229 formatFlag = DAYFLAG;
1232 date = MONYYYYFormat.parse(dateStr, new ParsePosition(0));
1234 formatFlag = MONTHFLAG;
1237 date = MMYYYYFormat.parse(dateStr, new ParsePosition(0));
1239 formatFlag = MONTHFLAG;
1242 date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1244 formatFlag = DAYFLAG;
1247 date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0));
1249 formatFlag = MONTHFLAG;
1253 date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1255 formatFlag = SECFLAG;
1259 date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0));
1261 formatFlag = MINFLAG;
1265 date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1267 formatFlag = SECFLAG;
1271 date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1273 formatFlag = MINFLAG;
1277 date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0));
1279 formatFlag = DAYFLAG;
1283 date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1285 formatFlag = SECFLAG;
1289 date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1291 formatFlag = MINFLAG;
1295 date = MMDDYYFormat.parse(dateStr, new ParsePosition(0));
1297 formatFlag = DAYFLAG;
1301 date = timestampFormat1.parse(dateStr, new ParsePosition(0));
1303 formatFlag = SECFLAG;
1307 date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0));
1309 formatFlag = MINFLAG;
1313 date = YYYYFormat.parse(dateStr, new ParsePosition(0));
1314 /* Some random numbers should not satisfy this year format. */
1315 if(dateStr.length()>4)
1318 formatFlag = YEARFLAG;
1325 public static String[] reverse(String[] arr) {
1326 List<String> list = Arrays.asList(arr);
1327 Collections.reverse(list);
1328 return (String[])list.toArray();
1331 public int getNumberOfDecimalPlaces(double num) {
1333 String[] splitter = d.toString().split("\\.");
1334 splitter[0].length(); // Before Decimal Count
1335 splitter[1].length(); // After Decimal Count
1336 return splitter[1].length();
1339 public boolean getBooleanValue(String s) {
1340 return getBooleanValue(s,null);
1343 public boolean getBooleanValue(String s, Boolean defaultValue) {
1345 if(s.length()<=0 && defaultValue!=null)
1346 return defaultValue.booleanValue();
1347 else if(s.length()<=0)
1350 if(s.toUpperCase().startsWith("Y") || s.toLowerCase().equals("true"))
1358 public String IntToLetter(int Int) {
1360 return Character.toString((char)(Int+96));
1363 return IntToLetter((Int/26)-1)+IntToLetter((Int%26)+1);
1365 return IntToLetter(Int/26)+IntToLetter(Int%26);
1373 private void clearReportRuntimeBackup(HttpServletRequest request) {
1374 //Session sess = Sessions.getCurrent(true)getCurrent();
1375 //HttpSession session = (HttpSession)sess.getNativeSession();
1376 HttpSession session = request.getSession();
1377 session.removeAttribute(AppConstants.DRILLDOWN_REPORTS_LIST);
1378 request.removeAttribute(AppConstants.DRILLDOWN_INDEX);
1379 session.removeAttribute(AppConstants.DRILLDOWN_INDEX);
1380 request.removeAttribute(AppConstants.FORM_DRILLDOWN_INDEX);
1381 session.removeAttribute(AppConstants.FORM_DRILLDOWN_INDEX);
1382 Enumeration<String> enum1 = session.getAttributeNames();
1383 String attributeName = "";
1384 while(enum1.hasMoreElements()) {
1385 attributeName = enum1.nextElement();
1386 if(attributeName.startsWith("parent_")) {
1387 session.removeAttribute(attributeName);
1390 session.removeAttribute(AppConstants.DRILLDOWN_REPORTS_LIST);
1391 session.removeAttribute(AppConstants.SI_BACKUP_FOR_REP_ID);
1392 session.removeAttribute(AppConstants.SI_COLUMN_LOOKUP);
1393 session.removeAttribute(AppConstants.SI_DASHBOARD_REP_ID);
1394 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP);
1395 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME);
1396 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP);
1397 session.removeAttribute(AppConstants.SI_DASHBOARD_CHARTDATA_MAP);
1398 session.removeAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP);
1399 session.removeAttribute(AppConstants.SI_DATA_SIZE_FOR_TEXTFIELD_POPUP);
1400 session.removeAttribute(AppConstants.SI_MAP);
1401 session.removeAttribute(AppConstants.SI_MAP_OBJECT);
1402 session.removeAttribute(AppConstants.SI_REPORT_DEFINITION);
1403 session.removeAttribute(AppConstants.SI_REPORT_RUNTIME);
1404 session.removeAttribute(AppConstants.SI_REPORT_RUN_BACKUP);
1405 session.removeAttribute(AppConstants.SI_REPORT_SCHEDULE);
1406 session.removeAttribute(AppConstants.RI_REPORT_DATA);
1407 session.removeAttribute(AppConstants.RI_CHART_DATA);
1408 session.removeAttribute(AppConstants.SI_FORMFIELD_INFO);
1409 session.removeAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO);
1411 } // clearReportRuntimeBackup
1414 public static synchronized java.util.HashMap getRequestParametersMap(ReportRuntime rr, HttpServletRequest request)
1416 HashMap valuesMap = new HashMap();
1418 ReportFormFields rff = rr.getReportFormFields();
1421 FormField ff = null;
1423 Map fieldNameMap = new HashMap();
1424 int countOfFields = 0 ;
1427 for(rff.resetNext(); rff.hasNext(); idx++) {
1429 fieldNameMap.put(ff.getFieldName(), ff.getFieldDisplayName());
1433 List formParameter = new ArrayList();
1434 String formField = "";
1435 for(int i = 0 ; i < rff.size(); i++) {
1436 ff = ((FormField)rff.getFormField(i));
1437 formField = ff.getFieldName();
1438 boolean isMultiValue = false;
1439 isMultiValue = ff.getFieldType().equals(FormField.FFT_CHECK_BOX)
1440 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI);
1441 boolean isTextArea = (ff.getFieldType().equals(FormField.FFT_TEXTAREA) && rr.getReportDefType()
1442 .equals(AppConstants.RD_SQL_BASED));
1444 if(request.getParameterValues(formField) != null && isMultiValue ) {
1445 String[] vals = request.getParameterValues(formField);
1446 StringBuffer value = new StringBuffer("");
1447 if(!AppUtils.getRequestFlag(request, AppConstants.RI_RESET_ACTION)) {
1449 if ( isMultiValue ) {
1452 for(int j = 0 ; j < vals.length; j++) {
1456 if(vals[j] !=null && vals[j].length() > 0) {
1457 vals[j] = Utils.oracleSafe(vals[j]);
1458 value.append(java.net.URLDecoder.decode(vals[j], "UTF-8"));// + ",";
1461 value.append(vals[j]);
1462 } catch (UnsupportedEncodingException ex) {value.append(vals[j]);}
1463 catch (IllegalArgumentException ex1){value.append(vals[j]);}
1464 catch (Exception ex2){
1465 value.append(vals[j]);
1472 if(j != vals.length -1) {
1476 if(vals.length > 0) {
1481 //value = value.substring(0 , value.length());
1483 valuesMap.put(fieldNameMap.get(formField), value.toString());
1484 value = new StringBuffer("");
1485 } else if(request.getParameter(formField) != null) {
1488 value = request.getParameter(formField);
1490 value = Utils.oracleSafe(value);
1491 value = "('" + Utils.replaceInString(value, ",", "'|'") + "')";
1492 value = Utils.replaceInString(value, "|", ",");
1493 valuesMap.put(fieldNameMap.get(formField), value);
1497 if(!AppUtils.getRequestFlag(request, AppConstants.RI_RESET_ACTION))
1498 value = request.getParameter(formField);
1499 valuesMap.put(fieldNameMap.get(formField), Utils.oracleSafe(value));
1503 valuesMap.put(fieldNameMap.get(formField), "" );