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 = 3600*1000;
84 public static final long DAY = 3600*1000*24;
85 public static final long MONTH = 3600*1000*24*31;
86 public static final long YEAR = 3600*1000*24*365;
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) throws RaptorException {
112 //From annotations chart
113 clearReportRuntimeBackup(request);
115 //HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest();
116 final Long user_id = new Long((long) UserUtils.getUserId(request));
117 //String action = request.getParameter(AppConstants.RI_ACTION);
118 //String reportID = AppUtils.getRequestValue(request, AppConstants.RI_REPORT_ID);
120 ReportHandler rh = new ReportHandler();
121 //ReportData reportData = null;
122 HashMap<String, String> chartOptionsMap = new HashMap<String, String>();
124 if(reportID !=null) {
125 reportRuntime = rh.loadReportRuntime(request, reportID, true, 1);
126 setChartType(reportRuntime.getChartType());
127 //reportData = reportRuntime.loadReportData(0, user_id.toString(), 10000,request, false);
132 String rotateLabelsStr = "";
133 rotateLabelsStr = AppUtils.nvl(reportRuntime.getLegendLabelAngle());
134 if(rotateLabelsStr.toLowerCase().equals("standard")) {
135 rotateLabelsStr = "0";
136 } else if (rotateLabelsStr.toLowerCase().equals("up45")) {
137 rotateLabelsStr = "45";
138 } else if (rotateLabelsStr.toLowerCase().equals("down45")) {
139 rotateLabelsStr = "-45";
140 } else if (rotateLabelsStr.toLowerCase().equals("up90")) {
141 rotateLabelsStr = "90";
142 } else if (rotateLabelsStr.toLowerCase().equals("down90")) {
143 rotateLabelsStr = "-90";
145 rotateLabelsStr = "0";
147 String width = (AppUtils.getRequestNvlValue(request, "width").length()>0?AppUtils.getRequestNvlValue(request, "width"):(AppUtils.nvl(reportRuntime.getChartWidth()).length()>0?reportRuntime.getChartWidth():"700"));
148 String height = (AppUtils.getRequestNvlValue(request, "height").length()>0?AppUtils.getRequestNvlValue(request, "height"):(AppUtils.nvl(reportRuntime.getChartHeight()).length()>0?reportRuntime.getChartHeight():"300"));
149 String animationStr = (AppUtils.getRequestNvlValue(request, "animation").length()>0?AppUtils.getRequestNvlValue(request, "animation"):new Boolean(reportRuntime.isAnimateAnimatedChart()).toString());
151 String rotateLabels = (AppUtils.getRequestNvlValue(request, "rotateLabels").length()>0?AppUtils.getRequestNvlValue(request, "rotateLabels"):(rotateLabelsStr.length()>0?rotateLabelsStr:"0"));
152 String staggerLabelsStr = (AppUtils.getRequestNvlValue(request, "staggerLabels").length()>0?AppUtils.getRequestNvlValue(request, "staggerLabels"):"false");
153 String showMaxMinStr = (AppUtils.getRequestNvlValue(request, "showMaxMin").length()>0?AppUtils.getRequestNvlValue(request, "showMaxMin"):"false");
154 String showControlsStr = (AppUtils.getRequestNvlValue(request, "showControls").length()>0?AppUtils.getRequestNvlValue(request, "showControls"):new Boolean(reportRuntime.displayBarControls()).toString());
155 String showLegendStr = (AppUtils.getRequestNvlValue(request, "showLegend").length()>0?AppUtils.getRequestNvlValue(request, "showLegend"):new Boolean(!new Boolean(reportRuntime.hideChartLegend())).toString());
156 String topMarginStr = AppUtils.getRequestNvlValue(request, "topMargin");
157 String topMargin = (AppUtils.nvl(topMarginStr).length()<=0)?(reportRuntime.getTopMargin()!=null?reportRuntime.getTopMargin().toString():"30"):topMarginStr;
158 String bottomMarginStr = AppUtils.getRequestNvlValue(request, "bottomMargin");
159 String bottomMargin = (AppUtils.nvl(bottomMarginStr).length()<=0)?(reportRuntime.getBottomMargin()!=null?reportRuntime.getBottomMargin().toString():"50"):bottomMarginStr;
160 String leftMarginStr = AppUtils.getRequestNvlValue(request, "leftMargin");
161 String leftMargin = (AppUtils.nvl(leftMarginStr).length()<=0)?(reportRuntime.getLeftMargin()!=null?reportRuntime.getLeftMargin().toString():"100"):leftMarginStr;
162 String rightMarginStr = AppUtils.getRequestNvlValue(request, "rightMargin");
163 String rightMargin = (AppUtils.nvl(rightMarginStr).length()<=0)?(reportRuntime.getRightMargin()!=null?reportRuntime.getRightMargin().toString():"160"):rightMarginStr;
164 String showTitleStr = (AppUtils.getRequestNvlValue(request, "showTitle").length()>0?AppUtils.getRequestNvlValue(request, "showTitle"):new Boolean(reportRuntime.displayChartTitle()).toString());
165 String subType = AppUtils.getRequestNvlValue(request, "subType").length()>0?AppUtils.getRequestNvlValue(request, "subType"):(AppUtils.nvl(reportRuntime.getTimeSeriesRender()).equals("area")?reportRuntime.getTimeSeriesRender():"");
166 String stackedStr = AppUtils.getRequestNvlValue(request, "stacked").length()>0?AppUtils.getRequestNvlValue(request, "stacked"):new Boolean(reportRuntime.isChartStacked()).toString();
167 String horizontalBar = AppUtils.getRequestNvlValue(request, "horizontalBar").length()>0?AppUtils.getRequestNvlValue(request, "horizontalBar"):new Boolean(reportRuntime.isHorizontalOrientation()).toString();
168 String barRealTimeAxis = AppUtils.getRequestNvlValue(request, "barRealTimeAxis");
169 String barReduceXAxisLabels = AppUtils.getRequestNvlValue(request, "barReduceXAxisLabels").length()>0?AppUtils.getRequestNvlValue(request, "barReduceXAxisLabels"):new Boolean(reportRuntime.isLessXaxisTickers()).toString();;
170 String timeAxis = AppUtils.getRequestNvlValue(request, "timeAxis").length()>0?AppUtils.getRequestNvlValue(request, "timeAxis"):new Boolean(reportRuntime.isTimeAxis()).toString();
171 String logScale = AppUtils.getRequestNvlValue(request, "logScale").length()>0?AppUtils.getRequestNvlValue(request, "logScale"):new Boolean(reportRuntime.isLogScale()).toString();
172 String precision = AppUtils.getRequestNvlValue(request, "precision").length()>0?AppUtils.getRequestNvlValue(request, "precision"):"2";
175 chartOptionsMap.put("width", width);
176 chartOptionsMap.put("height", height);
177 chartOptionsMap.put("animation", animationStr);
178 chartOptionsMap.put("rotateLabels", rotateLabels);
179 chartOptionsMap.put("staggerLabels", staggerLabelsStr);
180 chartOptionsMap.put("showMaxMin", showMaxMinStr);
181 chartOptionsMap.put("showControls", showControlsStr);
182 chartOptionsMap.put("showLegend", showLegendStr);
183 chartOptionsMap.put("topMargin", topMargin);
184 chartOptionsMap.put("bottomMargin", bottomMargin);
185 chartOptionsMap.put("leftMargin", leftMargin);
186 chartOptionsMap.put("rightMargin", rightMargin);
187 chartOptionsMap.put("showTitle", showTitleStr);
188 chartOptionsMap.put("subType", subType);
189 chartOptionsMap.put("stacked", stackedStr);
190 chartOptionsMap.put("horizontalBar", horizontalBar);
191 chartOptionsMap.put("timeAxis", timeAxis);
192 chartOptionsMap.put("barRealTimeAxis", barRealTimeAxis);
193 chartOptionsMap.put("barReduceXAxisLabels", barReduceXAxisLabels);
195 chartOptionsMap.put("logScale", logScale);
196 chartOptionsMap.put("precision", precision);
199 } catch (RaptorException ex) {
200 ex.printStackTrace();
202 return generateJSON(reportRuntime, chartOptionsMap, request, showData);
205 public String generateJSON(ReportRuntime reportRuntime, HttpServletRequest request, boolean showData) throws RaptorException {
207 String rotateLabelsStr = "";
208 rotateLabelsStr = AppUtils.nvl(reportRuntime.getLegendLabelAngle());
209 if(rotateLabelsStr.toLowerCase().equals("standard")) {
210 rotateLabelsStr = "0";
211 } else if (rotateLabelsStr.toLowerCase().equals("up45")) {
212 rotateLabelsStr = "45";
213 } else if (rotateLabelsStr.toLowerCase().equals("down45")) {
214 rotateLabelsStr = "-45";
215 } else if (rotateLabelsStr.toLowerCase().equals("up90")) {
216 rotateLabelsStr = "90";
217 } else if (rotateLabelsStr.toLowerCase().equals("down90")) {
218 rotateLabelsStr = "-90";
220 rotateLabelsStr = "0";
222 HashMap<String,String> chartOptionsMap = new HashMap<String, String>();
223 chartOptionsMap.put("width", reportRuntime.getChartWidth());
224 chartOptionsMap.put("height", reportRuntime.getChartHeight());
225 chartOptionsMap.put("animation", new Boolean(reportRuntime.isAnimateAnimatedChart()).toString());
226 chartOptionsMap.put("rotateLabels", rotateLabelsStr);
227 chartOptionsMap.put("staggerLabels", "false");
228 chartOptionsMap.put("showMaxMin", "false");
229 chartOptionsMap.put("showControls", new Boolean(reportRuntime.displayBarControls()).toString());
230 chartOptionsMap.put("showLegend", new Boolean(!reportRuntime.hideChartLegend()).toString());
231 chartOptionsMap.put("topMargin", reportRuntime.getTopMargin()!=null?reportRuntime.getTopMargin().toString():"30");
232 chartOptionsMap.put("bottomMargin", reportRuntime.getBottomMargin()!=null?reportRuntime.getBottomMargin().toString():"50");
233 chartOptionsMap.put("leftMargin", reportRuntime.getLeftMargin()!=null?reportRuntime.getLeftMargin().toString():"100");
234 chartOptionsMap.put("rightMargin", reportRuntime.getRightMargin()!=null?reportRuntime.getRightMargin().toString():"160");
235 chartOptionsMap.put("showTitle", new Boolean(reportRuntime.displayChartTitle()).toString());
236 chartOptionsMap.put("subType", (AppUtils.nvl(reportRuntime.getTimeSeriesRender()).equals("area")?reportRuntime.getTimeSeriesRender():""));
237 chartOptionsMap.put("stacked", new Boolean(reportRuntime.isChartStacked()).toString());
238 chartOptionsMap.put("horizontalBar", new Boolean(reportRuntime.isHorizontalOrientation()).toString());
239 chartOptionsMap.put("timeAxis", new Boolean(reportRuntime.isTimeAxis()).toString());
240 chartOptionsMap.put("barReduceXAxisLabels", new Boolean(reportRuntime.isLessXaxisTickers()).toString());
242 chartOptionsMap.put("logScale", new Boolean(reportRuntime.isLogScale()).toString());
243 chartOptionsMap.put("precision", "2");
247 return generateJSON(reportRuntime, chartOptionsMap, request, showData);
250 public String generateJSON(ReportRuntime reportRuntime, HashMap<String,String> chartOptionsMap, HttpServletRequest request, boolean showData) throws RaptorException {
252 //String width, String height, boolean animation, String rotateLabels, boolean staggerLabels, boolean showMaxMin, boolean showLegend, boolean showControls, String topMargin, String bottomMargin, boolean showTitle, String subType
253 String userId = AppUtils.getUserID(request);
254 String width = chartOptionsMap.get("width");
255 String height = chartOptionsMap.get("height");
256 boolean animation = getBooleanValue(chartOptionsMap.get("animation"), true);
257 String rotateLabels = chartOptionsMap.get("rotateLabels");
258 boolean staggerLabels = getBooleanValue(chartOptionsMap.get("staggerLabels"));
259 boolean showMaxMin = getBooleanValue(chartOptionsMap.get("showMaxMin"), false);
260 boolean showLegend = getBooleanValue(chartOptionsMap.get("showLegend"), true);
261 boolean showControls = getBooleanValue(chartOptionsMap.get("showControls"), true);
262 String topMargin = chartOptionsMap.get("topMargin");
263 String bottomMargin = chartOptionsMap.get("bottomMargin");
264 String leftMargin = chartOptionsMap.get("leftMargin");
265 String rightMargin = chartOptionsMap.get("rightMargin");
266 boolean showTitle = getBooleanValue(chartOptionsMap.get("showTitle"), true);
267 String subType = chartOptionsMap.get("subType");
268 boolean stacked = getBooleanValue(chartOptionsMap.get("stacked"), false);
269 boolean horizontalBar = getBooleanValue(chartOptionsMap.get("horizontalBar"), false);
270 boolean barRealTimeAxis = getBooleanValue(chartOptionsMap.get("barRealTimeAxis"), true);
271 boolean barReduceXAxisLabels= getBooleanValue(chartOptionsMap.get("barReduceXAxisLabels"), false);
272 boolean timeAxis = getBooleanValue(chartOptionsMap.get("timeAxis"), true);
275 boolean logScale = getBooleanValue(chartOptionsMap.get("logScale"), false);
280 precision = Integer.parseInt(chartOptionsMap.get("precision"));
281 } catch (NumberFormatException ex) {
285 final Long user_id = new Long((long) UserUtils.getUserId(request));
287 HttpSession session = null;
288 session = request.getSession();
289 String chartType = reportRuntime.getChartType();
290 List l = reportRuntime.getAllColumns();
291 List lGroups = reportRuntime.getAllChartGroups();
292 HashMap mapYAxis = reportRuntime.getAllChartYAxis(reportRuntime.getReportParamValues());
293 //ReportParamValues reportParamValues = reportRuntime.getReportParamValues();
294 String chartLeftAxisLabel = reportRuntime.getFormFieldFilled(nvl(reportRuntime.getChartLeftAxisLabel()));
295 String chartRightAxisLabel = reportRuntime.getFormFieldFilled(nvl(reportRuntime.getChartRightAxisLabel()));
297 boolean multipleSeries = reportRuntime.isMultiSeries();
299 java.util.HashMap formValues = null;
300 formValues = getRequestParametersMap(reportRuntime, request);
303 String legendColumnName = (reportRuntime.getChartLegendColumn()!=null)?reportRuntime.getChartLegendColumn().getDisplayName():"Legend Column";
304 boolean displayChart = reportRuntime.getDisplayChart();
305 HashMap additionalChartOptionsMap = new HashMap();
307 StringBuffer wholeScript = new StringBuffer("");
309 String title = reportRuntime.getReportTitle();
311 title = parseTitle(title, formValues);
312 ObjectMapper mapper = new ObjectMapper();
313 ChartJSON chartJSON = new ChartJSON();
320 if (!(chartType.equals(AppConstants.GT_HIERARCHICAL) || chartType.equals(AppConstants.GT_HIERARCHICAL_SUNBURST) || chartType.equals(AppConstants.GT_ANNOTATION_CHART))) {
321 sql = generateChartSQL(userId, request );
322 ds = (DataSet) loadChartData(new Long(user_id).toString(), request);
323 } else if(chartType.equals(AppConstants.GT_ANNOTATION_CHART)) {
324 sql = reportRuntime.getWholeSQL();
325 String reportSQL = reportRuntime.getWholeSQL();
326 String dbInfo = reportRuntime.getDBInfo();
327 ds = ConnectionUtils.getDataSet(reportSQL, dbInfo);
328 if(ds.getRowCount()<=0) {
329 logger.debug(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
330 logger.info(EELFLoggerDelegate.debugLogger, (chartType.toUpperCase()+" - " + "Report ID : " + reportRuntime.getReportID() + " DATA IS EMPTY" ));
331 logger.info(EELFLoggerDelegate.debugLogger, ("QUERY - " + reportSQL));
332 logger.info(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
334 } else if(chartType.equals(AppConstants.GT_HIERARCHICAL)||chartType.equals(AppConstants.GT_HIERARCHICAL_SUNBURST)) {
335 sql = reportRuntime.getWholeSQL();
336 String reportSQL = reportRuntime.getWholeSQL();
337 String dbInfo = reportRuntime.getDBInfo();
338 ds = ConnectionUtils.getDataSet(reportSQL, dbInfo);
340 } catch (RaptorException ex) {
341 //throw new RaptorException("Error while loading chart data", ex);
342 logger.error(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
343 logger.error(EELFLoggerDelegate.debugLogger, (chartType.toUpperCase()+" - " + "Report ID : " + reportRuntime.getReportID() + " ERROR THROWN FOR GIVEN QUERY "));
344 logger.error(EELFLoggerDelegate.debugLogger, ("QUERY - " + reportRuntime.getWholeSQL()));
345 logger.error(EELFLoggerDelegate.debugLogger, ("ERROR STACK TRACE" + ex.getMessage()));
346 logger.error(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
350 //displayChart = false;
351 if(chartType.equals(AppConstants.GT_ANNOTATION_CHART))
354 displayChart = false;
359 chartJSON.setReportID(reportRuntime.getReportID());
360 chartJSON.setReportName(reportRuntime.getReportName());
361 chartJSON.setReportDescr(reportRuntime.getReportDescr());
362 chartJSON.setReportTitle(reportRuntime.getReportTitle());
363 chartJSON.setReportSubTitle(reportRuntime.getReportSubTitle());
365 List<DataColumnType> dcList = reportRuntime.getOnlyVisibleColumns();
367 ArrayList<ChartColumnJSON> chartColumnJSONList = new ArrayList<ChartColumnJSON>();
368 for(Iterator iter = dcList.iterator(); iter.hasNext(); ) {
369 ChartColumnJSON ccJSON = new ChartColumnJSON();
370 DataColumnType dc = (DataColumnType) iter.next();
371 ccJSON.setIndex(countIndex);
372 ccJSON.setValue(dc.getColId());
373 ccJSON.setTitle(dc.getDisplayName());
375 chartColumnJSONList.add(ccJSON);
377 chartJSON.setChartColumnJSONList(chartColumnJSONList);
378 /* setting formfields show only showForm got triggered*/
379 /*ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
380 ArrayList<FormFieldJSON> formFieldJSONList = new ArrayList<FormFieldJSON>();
381 if(reportRuntime.getReportFormFields()!=null) {
382 formFieldJSONList = new ArrayList<FormFieldJSON>(reportRuntime.getReportFormFields().size());
383 for (Iterator iter = reportRuntime.getReportFormFields().iterator(); iter.hasNext();) {
384 formFieldValues = new ArrayList<IdNameValue>();
385 FormField ff = (FormField) iter.next();
386 ff.setDbInfo(reportRuntime.getDbInfo());
387 FormFieldJSON ffJSON = new FormFieldJSON();
388 ffJSON.setFieldId(ff.getFieldName());
389 ffJSON.setFieldType(ff.getFieldType());
390 ffJSON.setFieldDisplayName(ff.getFieldDisplayName());
391 ffJSON.setHelpText(ff.getHelpText());
392 ffJSON.setValidationType(ff.getValidationType());
393 //ffJSON.setTriggerOtherFormFields(ff.getDependsOn());
394 IdNameList lookup = null;
395 lookup = ff.getLookupList();
396 String selectedValue = "";
398 IdNameList lookupList = null;
399 boolean readOnly = false;
401 if(!ff.hasPredefinedList) {
402 IdNameSql lu = (IdNameSql) lookup;
403 String SQL = lu.getSql();
404 oldSQL = lu.getSql();
405 reportRuntime.setTriggerFormFieldCheck( reportRuntime.getReportFormFields(), ff);
406 ffJSON.setTriggerOtherFormFields(ff.isTriggerOtherFormFields());
407 SQL = reportRuntime.parseAndFillReq_Session_UserValues(request, SQL, userId);
408 SQL = reportRuntime.parseAndFillWithCurrentValues(request, SQL, ff);
409 String defaultSQL = lu.getDefaultSQL();
410 defaultSQL = reportRuntime.parseAndFillReq_Session_UserValues(request, defaultSQL, userId);
411 defaultSQL = reportRuntime.parseAndFillWithCurrentValues(request, SQL, ff);
412 lookup = new IdNameSql(-1,SQL,defaultSQL);
416 lookup.loadUserData(0, "", ff.getDbInfo(), ff.getUserId());
417 } catch (Exception e ){ e.printStackTrace(); //throw new RaptorRuntimeException(e);
422 String[] requestValue = request.getParameterValues(ff.getFieldName());
424 if(lookup != null && lookup.size() > 0) {
425 for (lookup.resetNext(); lookup.hasNext();) {
426 IdNameValue value = lookup.getNext();
427 readOnly = value.isReadOnly();
428 if(requestValue != null && Arrays.asList(requestValue).contains(value.getId())) {
429 //if(value.getId().equals(requestValue))
430 value.setDefaultValue(true);
432 if(!(ff.getFieldType().equals(FormField.FFT_CHECK_BOX) || ff.getFieldType().equals(FormField.FFT_COMBO_BOX) || ff.getFieldType().equals(FormField.FFT_LIST_BOX)
433 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI)) && value.isDefaultValue())
434 formFieldValues.add(value);
435 else if(ff.getFieldType().equals(FormField.FFT_CHECK_BOX) || ff.getFieldType().equals(FormField.FFT_COMBO_BOX) || ff.getFieldType().equals(FormField.FFT_LIST_BOX)
436 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI)) {
437 formFieldValues.add(value);
442 if(requestValue!=null && requestValue.length>0) {
443 IdNameValue value = new IdNameValue(requestValue[0], requestValue[0], true, false);
444 formFieldValues.add(value);
449 String[] requestValue = request.getParameterValues(ff.getFieldName());
450 if(requestValue!=null && requestValue.length>0) {
451 IdNameValue value = new IdNameValue(requestValue[0], requestValue[0], true, false);
452 formFieldValues.add(value);
455 if(!ff.hasPredefinedList) {
456 if(oldSQL != null && !oldSQL.equals("")) {
457 ((IdNameSql)lookup).setSQL(oldSQL);
463 ffJSON.setFormFieldValues(formFieldValues);
464 formFieldJSONList.add(ffJSON);
467 chartJSON.setFormFieldList(formFieldJSONList);
468 chartJSON.setChartSqlWhole(sql);*/
469 chartJSON.setChartAvailable(displayChart);
471 ChartTypeJSON chartTypeJSON = new ChartTypeJSON();
472 chartTypeJSON.setIndex(0);
473 chartTypeJSON.setTitle("");
474 chartTypeJSON.setValue(chartType);
475 chartJSON.setChartTypeJSON(chartTypeJSON);
476 chartJSON.setWidth(width);
477 chartJSON.setHeight(height);
478 chartJSON.setAnimation(animation);
479 chartJSON.setRotateLabels(rotateLabels);
480 chartJSON.setStaggerLabels(staggerLabels);
481 chartJSON.setShowTitle(showTitle);
482 DomainAxisJSON domainAxisJSON = new DomainAxisJSON();
483 domainAxisJSON.setIndex(0);
484 if(reportRuntime.getChartLegendColumn()!=null)
485 domainAxisJSON.setTitle(reportRuntime.getChartLegendColumn().getDisplayName());
487 domainAxisJSON.setTitle("");
488 if(reportRuntime.getChartLegendColumn()!=null)
489 domainAxisJSON.setValue(reportRuntime.getChartLegendColumn().getColId());
491 domainAxisJSON.setValue("");
492 chartJSON.setDomainAxisJSON(domainAxisJSON);
495 List<DataColumnType> reportCols = reportRuntime.getAllColumns();
496 boolean hasSeriesColumn = false;
498 for (Iterator<DataColumnType> iter = reportCols.iterator(); iter
500 DataColumnType dct = (DataColumnType) iter.next();
501 if(dct.isChartSeries()!=null && dct.isChartSeries().booleanValue()) {
502 chartJSON.setHasCategoryAxis(true);
503 CategoryAxisJSON categoryAxisJSON = new CategoryAxisJSON();
504 categoryAxisJSON.setIndex(0);
505 categoryAxisJSON.setTitle(dct.getDisplayName());
506 categoryAxisJSON.setValue(dct.getColId());
507 chartJSON.setCategoryAxisJSON(categoryAxisJSON);
510 //.add(new Item(dct.getColId(), dct.getDisplayName()));
512 //chartJSON.setCategoryAxis(categoryAxis);
515 List<DataColumnType> chartValueCols = reportRuntime.getChartValueColumnsList(AppConstants.CHART_ALL_COLUMNS, null);
516 DataColumnType dct_RangeAxis = null;
518 //if(chartValueCols.size()<=0) {
519 //chartValueCols.addAll(reportCols);
522 if(chartValueCols.size() <= 0) {
523 chartValueCols = reportCols;
525 ArrayList<RangeAxisJSON> rangeAxisJSONList = new ArrayList<RangeAxisJSON>();
526 for (int k = 0; k < chartValueCols.size(); k++) {
527 dct_RangeAxis = chartValueCols.get(k);
528 RangeAxisJSON rangeAxisJSON = new RangeAxisJSON();
530 RangeAxisLabelJSON rangeAxisLabelJSON = new RangeAxisLabelJSON();
531 rangeAxisLabelJSON.setIndex(0);
532 rangeAxisLabelJSON.setTitle(dct_RangeAxis.getDisplayName());
533 rangeAxisLabelJSON.setValue(dct_RangeAxis.getColId());
534 rangeAxisJSON.setRangeAxisLabelJSON(rangeAxisLabelJSON);
535 RangeLineTypeJSON rangeLineTypeJSON = new RangeLineTypeJSON();
536 rangeLineTypeJSON.setIndex(0);
537 rangeLineTypeJSON.setTitle("");
538 rangeLineTypeJSON.setValue(dct_RangeAxis.getChartLineType());
539 rangeAxisJSON.setRangeLineTypeJSON(rangeLineTypeJSON);
541 RangeColorJSON rangeColorJSON = new RangeColorJSON();
542 rangeColorJSON.setIndex(0);
543 rangeColorJSON.setTitle("");
544 rangeColorJSON.setValue(dct_RangeAxis.getChartColor());
545 rangeAxisJSON.setRangeColorJSON(rangeColorJSON);
546 String chartGroup = "";
547 chartGroup = AppUtils.nvl(dct_RangeAxis.getChartGroup());
548 if(chartGroup.indexOf("|")!=-1)
549 chartGroup = chartGroup.substring(0, chartGroup.indexOf("|"));
552 rangeAxisJSON.setRangeChartGroup(chartGroup);
554 yAxis = AppUtils.nvl(dct_RangeAxis.getYAxis());
555 if(yAxis.indexOf("|")!=-1)
556 yAxis = yAxis.substring(0, yAxis.indexOf("|"));
558 rangeAxisJSON.setRangeYAxis(yAxis);
559 rangeAxisJSON.setShowAsArea((dct_RangeAxis.isIsRangeAxisFilled()!=null && dct_RangeAxis.isIsRangeAxisFilled().booleanValue())?true:false);
560 rangeAxisJSONList.add(rangeAxisJSON);
562 CommonChartOptions commonChartOptions = new CommonChartOptions();
563 commonChartOptions.setLegendPosition(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>0?reportRuntime.getLegendPosition().toLowerCase():"top");
564 String legendLabelAngle = "";
565 legendLabelAngle = reportRuntime.getLegendLabelAngle().toLowerCase();
566 commonChartOptions.setLegendLabelAngle(AppUtils.nvl(legendLabelAngle).length()>0?legendLabelAngle:"up45");
567 commonChartOptions.setHideLegend(reportRuntime.hideChartLegend());
568 commonChartOptions.setAnimateAnimatedChart(reportRuntime.isAnimateAnimatedChart());
569 commonChartOptions.setTopMargin(reportRuntime.getTopMargin()!=null?reportRuntime.getTopMargin():new Integer("30"));
570 commonChartOptions.setBottomMargin(reportRuntime.getBottomMargin()!=null?reportRuntime.getBottomMargin():new Integer("50"));
571 commonChartOptions.setLeftMargin(reportRuntime.getLeftMargin()!=null?reportRuntime.getLeftMargin():new Integer("100"));
572 commonChartOptions.setRightMargin(reportRuntime.getRightMargin()!=null?reportRuntime.getRightMargin():new Integer("60"));
573 chartJSON.setCommonChartOptions(commonChartOptions);
575 if(chartType.equals(AppConstants.GT_BAR_3D)) {
576 BarChartOptions barChartOptions = new BarChartOptions();
577 barChartOptions.setDisplayBarControls(reportRuntime.displayBarControls()?true:false);
578 barChartOptions.setMinimizeXAxisTickers(reportRuntime.isLessXaxisTickers()?true:false);
579 barChartOptions.setStackedChart(reportRuntime.isChartStacked()?true:false);
580 barChartOptions.setTimeAxis(reportRuntime.isTimeAxis()?true:false);
581 barChartOptions.setVerticalOrientation(reportRuntime.isVerticalOrientation()?true:false);
582 barChartOptions.setxAxisDateType(reportRuntime.isXAxisDateType()?true:false);
583 barChartOptions.setyAxisLogScale(reportRuntime.isLogScale()?true:false);
584 chartJSON.setBarChartOptions(barChartOptions);
585 chartJSON.setTimeSeriesChartOptions(null);
586 chartJSON.setPieChartOptions(null);
587 chartJSON.setFlexTimeSeriesChartOptions(null);
589 } else if(chartType.equals(AppConstants.GT_TIME_SERIES)) {
590 TimeSeriesChartOptions timeSeriesChartOptions = new TimeSeriesChartOptions();
591 timeSeriesChartOptions.setAddXAxisTicker(reportRuntime.isAddXAxisTickers());
592 timeSeriesChartOptions.setLineChartRenderer(AppUtils.nvl(reportRuntime.getTimeSeriesRender()).length()>0?reportRuntime.getTimeSeriesRender():"line");
593 timeSeriesChartOptions.setMultiSeries(reportRuntime.isMultiSeries());
594 timeSeriesChartOptions.setNonTimeAxis(reportRuntime.isTimeAxis());
595 timeSeriesChartOptions.setShowXAxisLabel(reportRuntime.isShowXaxisLabel());
596 chartJSON.setBarChartOptions(null);
597 chartJSON.setTimeSeriesChartOptions(timeSeriesChartOptions);
598 chartJSON.setPieChartOptions(null);
599 chartJSON.setFlexTimeSeriesChartOptions(null);
600 } else if(chartType.equals(AppConstants.GT_ANNOTATION_CHART) || chartType.equals(AppConstants.GT_FLEX_TIME_CHARTS)) {
601 FlexTimeSeriesChartOptions flexTimeSeriesChartOptions = new FlexTimeSeriesChartOptions();
602 flexTimeSeriesChartOptions.setZoomIn(reportRuntime.getZoomIn()!=null?reportRuntime.getZoomIn():new Integer("25"));
603 String timeAxisTypeStr = "";
604 timeAxisTypeStr = reportRuntime.getTimeAxisType().toLowerCase();
605 flexTimeSeriesChartOptions.setTimeAxisType(timeAxisTypeStr);
606 chartJSON.setBarChartOptions(null);
607 chartJSON.setTimeSeriesChartOptions(null);
608 chartJSON.setPieChartOptions(null);
609 chartJSON.setFlexTimeSeriesChartOptions(flexTimeSeriesChartOptions);
611 chartJSON.setRangeAxisList(rangeAxisJSONList);
612 chartJSON.setPrimaryAxisLabel(reportRuntime.getChartLeftAxisLabel());
613 chartJSON.setSecondaryAxisLabel(reportRuntime.getChartRightAxisLabel());
614 chartJSON.setMinRange(reportRuntime.getRangeAxisLowerLimit());
615 chartJSON.setMaxRange(reportRuntime.getRangeAxisUpperLimit());
618 ArrayList<ArrayList<Row>> wholeList = new ArrayList<ArrayList<Row>>();
620 ArrayList<Row> rowList = new ArrayList<Row>();
622 for (int i = 0; i < ds.getRowCount(); i++) {
623 rowList = new ArrayList<Row>();
624 for (int j = 0; j<ds.getColumnCount(); j++) {
626 row.setColId(ds.getColumnName(j));
627 row.setDisplayValue(ds.getString(i, j));
628 row.setDataType(ds.getColumnType(j));
631 wholeList.add(rowList);
635 chartJSON.setWholeList(wholeList);
645 // chart is not visible
646 chartJSON.setReportID(reportRuntime.getReportID());
647 chartJSON.setReportName(reportRuntime.getReportName());
648 chartJSON.setReportDescr(reportRuntime.getReportDescr());
649 chartJSON.setReportTitle(reportRuntime.getReportTitle());
650 chartJSON.setReportSubTitle(reportRuntime.getReportSubTitle());
651 chartJSON.setChartAvailable(displayChart);
652 ChartTypeJSON chartTypeJSON = new ChartTypeJSON();
653 chartTypeJSON.setIndex(0);
654 chartTypeJSON.setTitle("");
655 chartTypeJSON.setValue(chartType);
656 chartJSON.setChartTypeJSON(chartTypeJSON);
658 //mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
659 //mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
660 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
661 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
662 String jsonInString = "";
664 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(chartJSON);
665 } catch (Exception ex) {
666 ex.printStackTrace();
673 public String nvl(String s) {
674 return (s == null) ? "" : s;
677 public String nvl(String s, String sDefault) {
678 return nvl(s).equals("") ? sDefault : s;
681 public static String nvls(String s) {
682 return (s == null) ? "" : s;
685 public static String nvls(String s, String sDefault) {
686 return nvls(s).equals("") ? sDefault : s;
689 public boolean getFlagInBoolean(String s) {
690 return nvl(s).toUpperCase().startsWith("Y") || nvl(s).toLowerCase().equals("true");
693 public DataSet loadChartData(String userId, HttpServletRequest request) throws RaptorException {
694 if (nvl(getChartType()).length() == 0)
696 //TODO: display chart function to be added.
697 //if (!getDisplayChart())
701 sql = generateChartSQL(userId, request);
702 logger.debug(EELFLoggerDelegate.debugLogger, ("SQL generated " + sql));
703 String dbInfo = reportRuntime.getDBInfo();
704 DataSet ds = ConnectionUtils.getDataSet(sql, dbInfo);
705 if(ds.getRowCount()<=0) {
706 logger.info(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
707 logger.info(EELFLoggerDelegate.debugLogger, (getChartType().toUpperCase()+" - " + "Report ID : " + reportRuntime.getReportID() + " DATA IS EMPTY"));
708 logger.info(EELFLoggerDelegate.debugLogger, ("QUERY - " + sql));
709 logger.info(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
715 public String generateChartSQL(String userId, HttpServletRequest request ) throws RaptorException {
716 List reportCols = reportRuntime.getAllColumns();
717 List chartValueCols = getChartValueColumnsList(AppConstants.CHART_ALL_COLUMNS, null); // parameter is 0 has this requires all columns.
718 String reportSQL = reportRuntime.getWholeSQL();
720 //Add order by clause
721 Pattern re1 = Pattern.compile("(^[\r\n]*|([\\s]))[Oo][Rr][Dd][Ee][Rr](.*?[^\r\n]*)[Bb][Yy]",Pattern.DOTALL);
722 //Pattern re1 = Pattern.compile("order(.*?[^\r\n]*)by", Pattern.DOTALL);
723 Matcher matcher = re1.matcher(reportSQL);
724 //Pattern re1 = Pattern.compile("(^[\r\n]*|([\\s]))[Oo][Rr][Dd][Ee][Rr][Tt](.*?[^\r\n]*)[Bb][Yy]",Pattern.DOTALL);
725 //int startPoint = sql.length()-30;
727 reportSQL = reportSQL + " ";
728 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ss][Ee][Ll][Ee][Cc][Tt]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" SELECT ");
729 //reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ff][Rr][Oo][Mm]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" FROM ");
730 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ww][Hh][Ee][Rr][Ee]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" WHERE ");
731 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ww][Hh][Ee][Nn]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" WHEN ");
732 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Aa][Nn][Dd]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" AND ");
734 if(!reportRuntime.getReportType().equals(AppConstants.RT_HIVE)) {
735 int startPoint = reportSQL.lastIndexOf(" FROM ");
736 if(startPoint <= 0) {
737 startPoint = reportSQL.lastIndexOf(" from ");
739 if(startPoint <= 0) {
740 startPoint = reportSQL.lastIndexOf("from ");
742 if(startPoint <= 0) {
743 startPoint = reportSQL.lastIndexOf("FROM ");
746 if (!matcher.find(startPoint)) {
747 reportSQL = reportSQL + " ORDER BY 1" ;
750 reportRuntime.setWholeSQL(reportSQL);
752 logger.debug(EELFLoggerDelegate.debugLogger, (" *************************************************************************************** "));
753 logger.debug(EELFLoggerDelegate.debugLogger, ("WHOLE_SQL" + reportSQL));
754 logger.debug(EELFLoggerDelegate.debugLogger, (" *************************************************************************************** "));
756 if (reportRuntime.getFormFieldList() != null) {
757 for (Iterator iter = reportRuntime.getFormFieldList().getFormField().iterator(); iter.hasNext();) {
758 FormFieldType fft = (FormFieldType) iter.next();
759 String fieldId = fft.getFieldId();
760 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
761 String formfield_value = "";
762 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
763 String paramValue = nvl(formfield_value);
764 if(paramValue.length()>0) {
765 /*sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
766 paramValue, "NULL"));*/
767 reportSQL = Utils.replaceInString(reportSQL, fieldDisplay, nvl(
768 paramValue, "NULL"));
770 /*sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
771 paramValue, "NULL"));*/
772 reportSQL = Utils.replaceInString(reportSQL, "'" + fieldDisplay + "'", nvl(
773 paramValue, "NULL"));
774 reportSQL = Utils.replaceInString(reportSQL, fieldDisplay , nvl(
775 paramValue, "NULL"));
778 logger.debug(EELFLoggerDelegate.debugLogger, ("SQL " + reportSQL));
779 String legendCol = "1 a";
780 // String valueCol = "1";
781 StringBuffer groupCol = new StringBuffer();
782 StringBuffer seriesCol = new StringBuffer();
783 StringBuffer valueCols = new StringBuffer();
785 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
786 DataColumnType dc = (DataColumnType) iter.next();
787 String colName = getColumnSelectStr(dc, request);
788 if (nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
789 legendCol = getSelectExpr(dc, colName)+" " + dc.getColId();
790 // if(dc.getChartSeq()>0)
791 // valueCol = "NVL("+colName+", 0) "+dc.getColId();
792 if ((!nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
793 && (dc.getChartSeq()!=null && dc.getChartSeq().intValue() <= 0) && dc.isGroupBreak()) {
794 groupCol.append(", ");
795 groupCol.append(colName + " " + dc.getColId());
798 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
799 DataColumnType dc = (DataColumnType) iter.next();
800 if(dc.isChartSeries()!=null && dc.isChartSeries().booleanValue()) {
801 //System.out.println("*****************, "+ " " +getColumnSelectStr(dc, paramValues)+ " "+ getSelectExpr(dc,getColumnSelectStr(dc, paramValues)));
802 seriesCol.append(", "+ getSelectExpr(dc,getColumnSelectStr(dc, request))+ " " + dc.getColId());
806 /*for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
807 DataColumnType dc = (DataColumnType) iter.next();
808 if(!dc.isChartSeries() && !(nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
809 //System.out.println("*****************, "+ " " +getColumnSelectStr(dc, paramValues)+ " "+ getSelectExpr(dc,getColumnSelectStr(dc, paramValues)));
810 seriesCol.append(", "+ formatChartColumn(getSelectExpr(dc,getColumnSelectStr(dc, paramValues)))+ " " + dc.getColId());
814 for (Iterator iter = chartValueCols.iterator(); iter.hasNext();) {
815 DataColumnType dc = (DataColumnType) iter.next();
816 String colName = getColumnSelectStr(dc, request);
817 String paramValue = "";
818 if(AppUtils.nvl(colName).startsWith("[")) {
819 if (reportRuntime.getFormFieldList() != null) {
820 for (Iterator iterC = reportRuntime.getFormFieldList().getFormField().iterator(); iterC.hasNext();) {
821 FormFieldType fft = (FormFieldType) iterC.next();
822 String fieldId = fft.getFieldId();
823 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
824 String formfield_value = "";
825 if(AppUtils.nvl(fieldDisplay).equals(colName)) {
826 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
827 paramValue = nvl(formfield_value);
833 seriesCol.append("," + (AppUtils.nvl(paramValue).length()>0? paramValue:"null") + " " + dc.getColId());
835 //valueCols.append(", NVL(" + formatChartColumn(colName) + ",0) " + dc.getColId());
836 seriesCol.append("," + (AppUtils.nvl(paramValue).length()>0? paramValue:formatChartColumn(colName)) + " " + dc.getColId());
840 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
841 DataColumnType dc = (DataColumnType) iter.next();
842 String colName = dc.getDisplayName();
843 String colValue = getColumnSelectStr(dc, request);
844 //String colName = getColumnSelectStr(dc, formGrid);
845 if(colName.equals(AppConstants.RI_CHART_TOTAL_COL))
846 seriesCol.append(", " + AppConstants.RI_CHART_TOTAL_COL + " " + AppConstants.RI_CHART_TOTAL_COL );
847 if (colName.equals(AppConstants.RI_CHART_COLOR))
848 seriesCol.append(", " + colValue + " " + AppConstants.RI_CHART_COLOR );
849 if(colName.equals(AppConstants.RI_CHART_MARKER_START))
850 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_START + " " + AppConstants.RI_CHART_MARKER_START );
851 if(colName.equals(AppConstants.RI_CHART_MARKER_END))
852 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_END + " " + AppConstants.RI_CHART_MARKER_END );
853 if(colName.equals(AppConstants.RI_CHART_MARKER_TEXT_LEFT))
854 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_TEXT_LEFT + " " + AppConstants.RI_CHART_MARKER_TEXT_LEFT );
855 if(colName.equals(AppConstants.RI_CHART_MARKER_TEXT_RIGHT))
856 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_TEXT_RIGHT + " " + AppConstants.RI_CHART_MARKER_TEXT_RIGHT );
857 //if(colName.equals(AppConstants.RI_ANOMALY_TEXT))
858 //seriesCol.append(", " + AppConstants.RI_ANOMALY_TEXT + " " + AppConstants.RI_ANOMALY_TEXT );
861 //debugLogger.debug("ReportSQL Chart " + reportSQL );
862 /*for (Iterator iter = chartValueCols.iterator(); iter.hasNext();) {
863 DataColumnType dc = (DataColumnType) iter.next();
864 String colName = getColumnSelectStr(dc, paramValues);
865 //valueCols.append(", NVL(" + formatChartColumn(colName) + ",0) " + dc.getColId());
866 valueCols.append("," + formatChartColumn(colName) + " " + dc.getColId());
868 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
869 DataColumnType dc = (DataColumnType) iter.next();
870 String colName = getColumnSelectStr(dc, paramValues);
871 //if(colName.equals(AppConstants.RI_CHART_TOTAL_COL) || colName.equals(AppConstants.RI_CHART_COLOR)) {
872 if(colName.equals(AppConstants.RI_CHART_TOTAL_COL))
873 valueCols.append(", " + AppConstants.RI_CHART_TOTAL_COL + " " + AppConstants.RI_CHART_TOTAL_COL );
874 if (colName.equals(AppConstants.RI_CHART_COLOR))
875 valueCols.append(", " + AppConstants.RI_CHART_COLOR + " " + AppConstants.RI_CHART_COLOR );
876 if (colName.equals(AppConstants.RI_CHART_INCLUDE))
877 valueCols.append(", " + AppConstants.RI_CHART_INCLUDE + " " + AppConstants.RI_CHART_INCLUDE );
880 String final_sql = "";
881 reportSQL = Utils.replaceInString(reportSQL, " from ", " FROM ");
882 reportSQL = Utils.replaceInString(reportSQL, " From ", " FROM ");
883 reportSQL = Utils.replaceInString(reportSQL, " select ", " SELECT ");
884 reportSQL = Utils.replaceInString(reportSQL, " union ", " UNION ");
885 //reportSQL = reportSQL.replaceAll("[\\s]*\\(", "(");
886 // if(reportSQL.indexOf("UNION") != -1) {
887 // if(reportSQL.indexOf("FROM(")!=-1)
888 // final_sql += " "+reportSQL.substring(reportSQL.indexOf("FROM(") );
889 // else if (reportSQL.indexOf("FROM (")!=-1)
890 // final_sql += " "+reportSQL.substring(reportSQL.indexOf("FROM (") );
891 // //TODO ELSE THROW ERROR
894 // final_sql += " "+reportSQL.substring(reportSQL.toUpperCase().indexOf(" FROM "));
897 int pos_first_select = 0;
898 int pos_dup_select = 0;
899 int pos_prev_select = 0;
900 int pos_last_select = 0;
901 if (reportSQL.indexOf("FROM", pos)!=-1) {
902 pos = reportSQL.indexOf("FROM", pos);
903 pos_dup_select = reportSQL.lastIndexOf("SELECT",pos);
904 pos_first_select = reportSQL.indexOf("SELECT");//,pos);
905 logger.debug(EELFLoggerDelegate.debugLogger, ("pos_select " + pos_first_select + " " + pos_dup_select));
906 if(pos_dup_select > pos_first_select) {
907 logger.debug(EELFLoggerDelegate.debugLogger, ("********pos_dup_select ********" + pos_dup_select));
908 //pos_dup_select1 = pos_dup_select;
909 pos_prev_select = pos_first_select;
910 pos_last_select = pos_dup_select;
911 while (pos_last_select > pos_prev_select) {
912 logger.debug(EELFLoggerDelegate.debugLogger, ("pos_last , pos_prev " + pos_last_select + " " + pos_prev_select));
913 pos = reportSQL.indexOf("FROM", pos+2);
914 pos_prev_select = pos_last_select;
915 pos_last_select = reportSQL.lastIndexOf("SELECT",pos);
916 logger.debug(EELFLoggerDelegate.debugLogger, ("in WHILE LOOP LAST " + pos_last_select));
921 final_sql += " "+reportSQL.substring(pos);
922 logger.debug(EELFLoggerDelegate.debugLogger, ("Final SQL " + final_sql));
923 String sql = "SELECT " + legendCol + ", " + legendCol+"_1" + seriesCol.toString()+ nvl(valueCols.toString(), ", 1")
924 + groupCol.toString()
926 logger.debug(EELFLoggerDelegate.debugLogger, ("Final sql in generateChartSQL " +sql));
929 } // generateChartSQL
931 private String getColumnSelectStr(DataColumnType dc, HttpServletRequest request) {
932 //String colName = dc.isCalculated() ? dc.getColName()
933 // : ((nvl(dc.getTableId()).length() > 0) ? (dc.getTableId() + "." + dc
934 // .getColName()) : dc.getColName());
935 String colName = dc.getColName();
936 String paramValue = null;
937 //if (dc.isCalculated()) {
938 if (reportRuntime.getFormFieldList() != null) {
939 for (Iterator iter = reportRuntime.getFormFieldList().getFormField().iterator(); iter.hasNext();) {
940 FormFieldType fft = (FormFieldType) iter.next();
941 String fieldId = fft.getFieldId();
942 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
943 String formfield_value = "";
944 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
945 paramValue = nvl(formfield_value);
946 if(paramValue.length()>0) {
947 /*sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
948 paramValue, "NULL"));*/
949 colName = Utils.replaceInString(colName, "'" + fieldDisplay + "'", "'"+nvl(
950 paramValue, "NULL")+"'");
951 colName = Utils.replaceInString(colName, fieldDisplay, nvl(
952 paramValue, "NULL"));
959 } // getColumnSelectStr
963 public String getSelectExpr(DataColumnType dct) {
965 // dct.isCalculated()?dct.getColName():((nvl(dct.getTableId()).length()>0)?(dct.getTableId()+"."+dct.getColName()):dct.getColName());
966 return getSelectExpr(dct, dct.getColName() /* colName */);
969 private String getSelectExpr(DataColumnType dct, String colName) {
970 String colType = dct.getColType();
971 if (colType.equals(AppConstants.CT_CHAR)
972 || ((nvl(dct.getColFormat()).length() == 0) && (!colType
973 .equals(AppConstants.CT_DATE))))
976 return "TO_CHAR(" + colName + ", '"
977 + nvl(dct.getColFormat(), AppConstants.DEFAULT_DATE_FORMAT) + "')";
980 private String formatChartColumn(String colName) {
981 logger.debug(EELFLoggerDelegate.debugLogger, ("Format Chart Column Input colName " + colName));
982 colName = colName.trim();
983 colName = Utils.replaceInString(colName, "TO_CHAR", "to_char");
984 colName = Utils.replaceInString(colName, "to_number", "TO_NUMBER");
985 //reportSQL = reportSQL.replaceAll("[\\s]*\\(", "(");
986 colName = colName.replaceAll(",[\\s]*\\(", ",(");
987 StringBuffer colNameBuf = new StringBuffer(colName);
988 int pos = 0, posFormatStart = 0, posFormatEnd = 0;
991 if(colNameBuf.indexOf("999")==-1 && colNameBuf.indexOf("990")==-1) {
992 logger.debug(EELFLoggerDelegate.debugLogger, (" return colName " + colNameBuf.toString()));
993 return colNameBuf.toString();
996 while (colNameBuf.indexOf("to_char")!=-1) {
997 if(colNameBuf.indexOf("999")!=-1 || colNameBuf.indexOf("990")!=-1) {
998 pos = colNameBuf.indexOf("to_char");
999 colNameBuf.insert(pos, " TO_NUMBER ( CR_RAPTOR.SAFE_TO_NUMBER (");
1000 pos = colNameBuf.indexOf("to_char");
1001 colNameBuf.replace(pos, pos+7, "TO_CHAR");
1002 //colName = Utils.replaceInString(colNameBuf.toString(), "to_char", " TO_NUMBER ( CR_RAPTOR.SAFE_TO_NUMBER ( TO_CHAR ");
1003 logger.debug(EELFLoggerDelegate.debugLogger, ("After adding to_number " + colNameBuf.toString()));
1004 //posFormatStart = colNameBuf.lastIndexOf(",'")+1;
1005 posFormatStart = colNameBuf.indexOf(",'", pos)+1;
1006 posFormatEnd = colNameBuf.indexOf(")",posFormatStart);
1007 logger.debug(EELFLoggerDelegate.debugLogger, (posFormatStart + " " + posFormatEnd + " "+ pos));
1008 format = colNameBuf.substring(posFormatStart, posFormatEnd);
1009 //posFormatEnd = colNameBuf.indexOf(")",posFormatEnd);
1010 colNameBuf.insert(posFormatEnd+1, " ," + format + ") , "+ format + ")");
1011 logger.debug(EELFLoggerDelegate.debugLogger, ("colNameBuf " + colNameBuf.toString()));
1014 logger.debug(EELFLoggerDelegate.debugLogger, (" return colName " + colNameBuf.toString()));
1015 return colNameBuf.toString();
1018 public List getChartValueColumnsList( int filter, HashMap formValues) { /*filter; all=0;create without new chart =1; createNewChart=2 */
1019 List reportCols = reportRuntime.getAllColumns();
1021 ArrayList chartValueCols = new ArrayList();
1023 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1025 DataColumnType dc = (DataColumnType) iter.next();
1026 // if(filter == 2 || filter == 1) {
1027 flag = reportRuntime.getDependsOnFormFieldFlag(dc, formValues);
1029 if( (dc.getChartSeq()!=null && dc.getChartSeq()> 0) && flag == 0 && !(nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
1030 if(nvl(dc.getChartGroup()).length()<=0) {
1031 if( filter == 2 && (dc.isCreateInNewChart()!=null && dc.isCreateInNewChart().booleanValue())) {
1032 chartValueCols.add(dc);
1033 } else if (filter == 1 && (dc.isCreateInNewChart()==null || !dc.isCreateInNewChart().booleanValue())) {
1034 chartValueCols.add(dc);
1036 else if(filter == 0) chartValueCols.add(dc);
1037 } else chartValueCols.add(dc);
1040 // chartValueCols.add(dc);
1042 Collections.sort(chartValueCols, new ChartSeqComparator());
1043 return chartValueCols;
1044 } // getChartValueColumnsList
1046 public String parseTitle(String title, HashMap formValues) {
1047 Set set = formValues.entrySet();
1048 for(Iterator iter = set.iterator(); iter.hasNext(); ) {
1049 Map.Entry entry = (Entry<String,String>) iter.next();
1050 if(title.indexOf("["+ entry.getKey() + "]")!= -1) {
1051 title = Utils.replaceInString(title, "["+entry.getKey()+"]", nvl(
1052 (String) entry.getValue(), ""));
1058 public java.util.Date getDateFromDateStr(String dateStr) {
1059 SimpleDateFormat MMDDYYYYFormat = new SimpleDateFormat("MM/dd/yyyy");
1060 SimpleDateFormat EEEMMDDYYYYFormat = new SimpleDateFormat("EEE, MM/dd/yyyy"); //2012-11-01 00:00:00
1061 SimpleDateFormat YYYYMMDDFormat = new SimpleDateFormat("yyyy/MM/dd");
1062 SimpleDateFormat MONYYYYFormat = new SimpleDateFormat("MMM yyyy");
1063 SimpleDateFormat MMYYYYFormat = new SimpleDateFormat("MM/yyyy");
1064 SimpleDateFormat MMMMMDDYYYYFormat = new SimpleDateFormat("MMMMM dd, yyyy");
1065 SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1066 SimpleDateFormat timestampHrFormat = new SimpleDateFormat("yyyy-MM-dd HH");
1067 SimpleDateFormat timestampDayFormat = new SimpleDateFormat("yyyy-MM-dd");
1068 SimpleDateFormat DDMONYYYYFormat = new SimpleDateFormat("dd-MMM-yyyy");
1069 SimpleDateFormat MONTHYYYYFormat = new SimpleDateFormat("MMMMM, yyyy");
1070 SimpleDateFormat MMDDYYYYHHFormat = new SimpleDateFormat("MM/dd/yyyy HH");
1071 SimpleDateFormat MMDDYYYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
1072 SimpleDateFormat MMDDYYYYHHMMFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
1073 SimpleDateFormat YYYYMMDDHHMMSSFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
1074 SimpleDateFormat YYYYMMDDHHMMFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
1075 SimpleDateFormat DDMONYYYYHHMMSSFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
1076 SimpleDateFormat DDMONYYYYHHMMFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
1077 SimpleDateFormat MMDDYYFormat = new SimpleDateFormat("MM/dd/yy");
1078 SimpleDateFormat MMDDYYHHMMFormat = new SimpleDateFormat("MM/dd/yy HH:mm");
1079 SimpleDateFormat MMDDYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
1080 SimpleDateFormat timestampFormat1 = new SimpleDateFormat("yyyy-M-d.HH.mm. s. S");
1081 SimpleDateFormat MMDDYYYYHHMMZFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm z");
1082 SimpleDateFormat YYYYFormat = new SimpleDateFormat("yyyy");
1083 java.util.Date date = null;
1087 final int YEARFLAG = 1;
1088 final int MONTHFLAG = 2;
1089 final int DAYFLAG = 3;
1090 final int HOURFLAG = 4;
1091 final int MINFLAG = 5;
1092 final int SECFLAG = 6;
1093 final int MILLISECFLAG = 7;
1094 final int DAYOFTHEWEEKFLAG = 8;
1095 final int FLAGDATE = 9;
1102 int milliSecFlag = 7;
1103 int dayoftheweekFlag = 8;
1107 date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1108 if(date!=null) formatFlag = SECFLAG;
1110 date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1111 if(date!=null) formatFlag = DAYOFTHEWEEKFLAG;
1114 date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1115 if(date!=null) formatFlag = MINFLAG;
1118 //MMDDYYYYHHFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
1119 date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0));
1120 if(date!=null) formatFlag = HOURFLAG;
1123 date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1124 if(date!=null) formatFlag = DAYFLAG;
1127 date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0));
1128 if(date!=null) formatFlag = DAYFLAG;
1131 date = timestampFormat.parse(dateStr, new ParsePosition(0));
1132 if(date!=null) formatFlag = SECFLAG;
1135 date = timestampHrFormat.parse(dateStr, new ParsePosition(0));
1136 if(date!=null) formatFlag = HOURFLAG;
1139 date = timestampDayFormat.parse(dateStr, new ParsePosition(0));
1140 if(date!=null) formatFlag = DAYFLAG;
1144 date = MONYYYYFormat.parse(dateStr, new ParsePosition(0));
1145 if(date!=null) formatFlag = MONTHFLAG;
1148 date = MMYYYYFormat.parse(dateStr, new ParsePosition(0));
1149 if(date!=null) formatFlag = MONTHFLAG;
1152 date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1153 if(date!=null) formatFlag = DAYFLAG;
1156 date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0));
1157 if(date!=null) formatFlag = MONTHFLAG;
1161 date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1162 if(date!=null) formatFlag = SECFLAG;
1166 date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0));
1167 if(date!=null) formatFlag = MINFLAG;
1171 date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1172 if(date!=null) formatFlag = SECFLAG;
1176 date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1177 if(date!=null) formatFlag = MINFLAG;
1181 date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0));
1182 if(date!=null) formatFlag = DAYFLAG;
1186 date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1187 if(date!=null) formatFlag = SECFLAG;
1191 date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1192 if(date!=null) formatFlag = MINFLAG;
1196 date = MMDDYYFormat.parse(dateStr, new ParsePosition(0));
1197 if(date!=null) formatFlag = DAYFLAG;
1201 date = timestampFormat1.parse(dateStr, new ParsePosition(0));
1202 if(date!=null) formatFlag = SECFLAG;
1206 date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0));
1207 if(date!=null) formatFlag = MINFLAG;
1211 date = YYYYFormat.parse(dateStr, new ParsePosition(0));
1212 /* Some random numbers should not satisfy this year format. */
1213 if(dateStr.length()>4) date = null;
1214 if(date!=null) formatFlag = YEARFLAG;
1221 public int getFlagFromDateStr(String dateStr) {
1222 SimpleDateFormat MMDDYYYYFormat = new SimpleDateFormat("MM/dd/yyyy");
1223 SimpleDateFormat EEEMMDDYYYYFormat = new SimpleDateFormat("EEE, MM/dd/yyyy"); //2012-11-01 00:00:00
1224 SimpleDateFormat YYYYMMDDFormat = new SimpleDateFormat("yyyy/MM/dd");
1225 SimpleDateFormat MONYYYYFormat = new SimpleDateFormat("MMM yyyy");
1226 SimpleDateFormat MMYYYYFormat = new SimpleDateFormat("MM/yyyy");
1227 SimpleDateFormat MMMMMDDYYYYFormat = new SimpleDateFormat("MMMMM dd, yyyy");
1228 SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1229 SimpleDateFormat timestampHrFormat = new SimpleDateFormat("yyyy-MM-dd HH");
1230 SimpleDateFormat timestampDayFormat = new SimpleDateFormat("yyyy-MM-dd");
1231 SimpleDateFormat DDMONYYYYFormat = new SimpleDateFormat("dd-MMM-yyyy");
1232 SimpleDateFormat MONTHYYYYFormat = new SimpleDateFormat("MMMMM, yyyy");
1233 SimpleDateFormat MMDDYYYYHHFormat = new SimpleDateFormat("MM/dd/yyyy HH");
1234 SimpleDateFormat MMDDYYYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
1235 SimpleDateFormat MMDDYYYYHHMMFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
1236 SimpleDateFormat YYYYMMDDHHMMSSFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
1237 SimpleDateFormat YYYYMMDDHHMMFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
1238 SimpleDateFormat DDMONYYYYHHMMSSFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
1239 SimpleDateFormat DDMONYYYYHHMMFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
1240 SimpleDateFormat MMDDYYFormat = new SimpleDateFormat("MM/dd/yy");
1241 SimpleDateFormat MMDDYYHHMMFormat = new SimpleDateFormat("MM/dd/yy HH:mm");
1242 SimpleDateFormat MMDDYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
1243 SimpleDateFormat timestampFormat1 = new SimpleDateFormat("yyyy-M-d.HH.mm. s. S");
1244 SimpleDateFormat MMDDYYYYHHMMZFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm z");
1245 SimpleDateFormat YYYYFormat = new SimpleDateFormat("yyyy");
1246 java.util.Date date = null;
1250 final int YEARFLAG = 1;
1251 final int MONTHFLAG = 2;
1252 final int DAYFLAG = 3;
1253 final int HOURFLAG = 4;
1254 final int MINFLAG = 5;
1255 final int SECFLAG = 6;
1256 final int MILLISECFLAG = 7;
1257 final int DAYOFTHEWEEKFLAG = 8;
1258 final int FLAGDATE = 9;
1265 int milliSecFlag = 7;
1266 int dayoftheweekFlag = 8;
1270 date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1271 if(date!=null) formatFlag = SECFLAG;
1273 date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1274 if(date!=null) formatFlag = DAYOFTHEWEEKFLAG;
1277 date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1278 if(date!=null) formatFlag = MINFLAG;
1281 //MMDDYYYYHHFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
1282 date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0));
1283 if(date!=null) formatFlag = HOURFLAG;
1286 date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1287 if(date!=null) formatFlag = DAYFLAG;
1290 date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0));
1291 if(date!=null) formatFlag = DAYFLAG;
1294 date = timestampFormat.parse(dateStr, new ParsePosition(0));
1295 if(date!=null) formatFlag = SECFLAG;
1298 date = timestampHrFormat.parse(dateStr, new ParsePosition(0));
1299 if(date!=null) formatFlag = HOURFLAG;
1302 date = timestampDayFormat.parse(dateStr, new ParsePosition(0));
1303 if(date!=null) formatFlag = DAYFLAG;
1306 date = MONYYYYFormat.parse(dateStr, new ParsePosition(0));
1307 if(date!=null) formatFlag = MONTHFLAG;
1310 date = MMYYYYFormat.parse(dateStr, new ParsePosition(0));
1311 if(date!=null) formatFlag = MONTHFLAG;
1314 date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
1315 if(date!=null) formatFlag = DAYFLAG;
1318 date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0));
1319 if(date!=null) formatFlag = MONTHFLAG;
1323 date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1324 if(date!=null) formatFlag = SECFLAG;
1328 date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0));
1329 if(date!=null) formatFlag = MINFLAG;
1333 date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1334 if(date!=null) formatFlag = SECFLAG;
1338 date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1339 if(date!=null) formatFlag = MINFLAG;
1343 date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0));
1344 if(date!=null) formatFlag = DAYFLAG;
1348 date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
1349 if(date!=null) formatFlag = SECFLAG;
1353 date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0));
1354 if(date!=null) formatFlag = MINFLAG;
1358 date = MMDDYYFormat.parse(dateStr, new ParsePosition(0));
1359 if(date!=null) formatFlag = DAYFLAG;
1363 date = timestampFormat1.parse(dateStr, new ParsePosition(0));
1364 if(date!=null) formatFlag = SECFLAG;
1368 date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0));
1369 if(date!=null) formatFlag = MINFLAG;
1373 date = YYYYFormat.parse(dateStr, new ParsePosition(0));
1374 /* Some random numbers should not satisfy this year format. */
1375 if(dateStr.length()>4) date = null;
1376 if(date!=null) formatFlag = YEARFLAG;
1383 public static String[] reverse(String[] arr) {
1384 List<String> list = Arrays.asList(arr);
1385 Collections.reverse(list);
1386 return (String[])list.toArray();
1389 public int getNumberOfDecimalPlaces(double num) {
1391 String[] splitter = d.toString().split("\\.");
1392 splitter[0].length(); // Before Decimal Count
1393 splitter[1].length(); // After Decimal Count
1394 return splitter[1].length();
1397 public boolean getBooleanValue(String s) {
1398 return getBooleanValue(s,null);
1401 public boolean getBooleanValue(String s, Boolean defaultValue) {
1403 if(s.length()<=0 && defaultValue!=null) return defaultValue.booleanValue();
1404 else if(s.length()<=0) return false;
1406 if(s.toUpperCase().startsWith("Y") || s.toLowerCase().equals("true"))
1414 public String IntToLetter(int Int) {
1416 return Character.toString((char)(Int+96));
1419 return IntToLetter((Int/26)-1)+IntToLetter((Int%26)+1);
1421 return IntToLetter(Int/26)+IntToLetter(Int%26);
1429 private void clearReportRuntimeBackup(HttpServletRequest request) {
1430 //Session sess = Sessions.getCurrent(true)getCurrent();
1431 //HttpSession session = (HttpSession)sess.getNativeSession();
1432 HttpSession session = request.getSession();
1433 session.removeAttribute(AppConstants.DRILLDOWN_REPORTS_LIST);
1434 request.removeAttribute(AppConstants.DRILLDOWN_INDEX);
1435 session.removeAttribute(AppConstants.DRILLDOWN_INDEX);
1436 request.removeAttribute(AppConstants.FORM_DRILLDOWN_INDEX);
1437 session.removeAttribute(AppConstants.FORM_DRILLDOWN_INDEX);
1438 Enumeration<String> enum1 = session.getAttributeNames();
1439 String attributeName = "";
1440 while(enum1.hasMoreElements()) {
1441 attributeName = enum1.nextElement();
1442 if(attributeName.startsWith("parent_")) {
1443 session.removeAttribute(attributeName);
1446 session.removeAttribute(AppConstants.DRILLDOWN_REPORTS_LIST);
1447 session.removeAttribute(AppConstants.SI_BACKUP_FOR_REP_ID);
1448 session.removeAttribute(AppConstants.SI_COLUMN_LOOKUP);
1449 session.removeAttribute(AppConstants.SI_DASHBOARD_REP_ID);
1450 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP);
1451 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME);
1452 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP);
1453 session.removeAttribute(AppConstants.SI_DASHBOARD_CHARTDATA_MAP);
1454 session.removeAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP);
1455 session.removeAttribute(AppConstants.SI_DATA_SIZE_FOR_TEXTFIELD_POPUP);
1456 session.removeAttribute(AppConstants.SI_MAP);
1457 session.removeAttribute(AppConstants.SI_MAP_OBJECT);
1458 session.removeAttribute(AppConstants.SI_REPORT_DEFINITION);
1459 session.removeAttribute(AppConstants.SI_REPORT_RUNTIME);
1460 session.removeAttribute(AppConstants.SI_REPORT_RUN_BACKUP);
1461 session.removeAttribute(AppConstants.SI_REPORT_SCHEDULE);
1462 session.removeAttribute(AppConstants.RI_REPORT_DATA);
1463 session.removeAttribute(AppConstants.RI_CHART_DATA);
1464 session.removeAttribute(AppConstants.SI_FORMFIELD_INFO);
1465 session.removeAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO);
1467 } // clearReportRuntimeBackup
1470 public static synchronized java.util.HashMap getRequestParametersMap(ReportRuntime rr, HttpServletRequest request)
1472 HashMap valuesMap = new HashMap();
1474 ReportFormFields rff = rr.getReportFormFields();
1477 FormField ff = null;
1479 Map fieldNameMap = new HashMap();
1480 int countOfFields = 0 ;
1483 for(rff.resetNext(); rff.hasNext(); idx++) {
1485 fieldNameMap.put(ff.getFieldName(), ff.getFieldDisplayName());
1489 List formParameter = new ArrayList();
1490 String formField = "";
1491 for(int i = 0 ; i < rff.size(); i++) {
1492 ff = ((FormField)rff.getFormField(i));
1493 formField = ff.getFieldName();
1494 boolean isMultiValue = false;
1495 isMultiValue = ff.getFieldType().equals(FormField.FFT_CHECK_BOX)
1496 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI);
1497 boolean isTextArea = (ff.getFieldType().equals(FormField.FFT_TEXTAREA) && rr.getReportDefType()
1498 .equals(AppConstants.RD_SQL_BASED));
1500 if(request.getParameterValues(formField) != null && isMultiValue ) {
1501 String[] vals = request.getParameterValues(formField);
1502 StringBuffer value = new StringBuffer("");
1503 if(!AppUtils.getRequestFlag(request, AppConstants.RI_RESET_ACTION)) {
1505 if ( isMultiValue ) {
1508 for(int j = 0 ; j < vals.length; j++) {
1509 if(isMultiValue) value.append("'");
1511 if(vals[j] !=null && vals[j].length() > 0) {
1512 vals[j] = Utils.oracleSafe(vals[j]);
1513 value.append(java.net.URLDecoder.decode(vals[j], "UTF-8"));// + ",";
1516 value.append(vals[j]);
1517 } catch (UnsupportedEncodingException ex) {value.append(vals[j]);}
1518 catch (IllegalArgumentException ex1){value.append(vals[j]);}
1519 catch (Exception ex2){
1520 value.append(vals[j]);
1524 if(isMultiValue) value.append("'");
1526 if(j != vals.length -1) {
1530 if(vals.length > 0) {
1535 //value = value.substring(0 , value.length());
1537 valuesMap.put(fieldNameMap.get(formField), value.toString());
1538 value = new StringBuffer("");
1539 } else if(request.getParameter(formField) != null) {
1542 value = request.getParameter(formField);
1544 value = Utils.oracleSafe(value);
1545 value = "('" + Utils.replaceInString(value, ",", "'|'") + "')";
1546 value = Utils.replaceInString(value, "|", ",");
1547 valuesMap.put(fieldNameMap.get(formField), value);
1551 if(!AppUtils.getRequestFlag(request, AppConstants.RI_RESET_ACTION))
1552 value = request.getParameter(formField);
1553 valuesMap.put(fieldNameMap.get(formField), Utils.oracleSafe(value));
1557 valuesMap.put(fieldNameMap.get(formField), "" );