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.Serializable;
41 import java.sql.Connection;
42 import java.text.SimpleDateFormat;
43 import java.util.ArrayList;
44 import java.util.Arrays;
45 import java.util.Date;
46 import java.util.Enumeration;
47 import java.util.HashMap;
48 import java.util.Iterator;
49 import java.util.List;
51 import java.util.StringTokenizer;
52 import java.util.Vector;
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.DataCache;
61 import org.onap.portalsdk.analytics.model.ReportHandler;
62 import org.onap.portalsdk.analytics.model.ReportLoader;
63 import org.onap.portalsdk.analytics.model.base.IdNameList;
64 import org.onap.portalsdk.analytics.model.base.IdNameSql;
65 import org.onap.portalsdk.analytics.model.base.IdNameValue;
66 import org.onap.portalsdk.analytics.model.base.ReportWrapper;
67 import org.onap.portalsdk.analytics.model.definition.Marker;
68 import org.onap.portalsdk.analytics.system.AppUtils;
69 import org.onap.portalsdk.analytics.system.ConnectionUtils;
70 import org.onap.portalsdk.analytics.system.DbUtils;
71 import org.onap.portalsdk.analytics.system.Globals;
72 import org.onap.portalsdk.analytics.util.AppConstants;
73 import org.onap.portalsdk.analytics.util.DataSet;
74 import org.onap.portalsdk.analytics.util.Utils;
75 import org.onap.portalsdk.analytics.view.ColumnHeader;
76 import org.onap.portalsdk.analytics.view.ColumnHeaderRow;
77 import org.onap.portalsdk.analytics.view.CrossTabOrderManager;
78 import org.onap.portalsdk.analytics.view.CrossTabTotalValue;
79 import org.onap.portalsdk.analytics.view.DataRow;
80 import org.onap.portalsdk.analytics.view.DataValue;
81 import org.onap.portalsdk.analytics.view.ReportData;
82 import org.onap.portalsdk.analytics.view.RowHeaderCol;
83 import org.onap.portalsdk.analytics.xmlobj.CustomReportType;
84 import org.onap.portalsdk.analytics.xmlobj.DataColumnType;
85 import org.onap.portalsdk.analytics.xmlobj.FormFieldType;
86 import org.onap.portalsdk.analytics.xmlobj.ObjectFactory;
87 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
88 import org.onap.portalsdk.core.util.SecurityCodecUtil;
89 import org.owasp.esapi.ESAPI;
91 import com.fasterxml.jackson.databind.ObjectMapper;
95 * This class is part of <B><I>RAPTOR (Rapid Application Programming Tool for OLAP Reporting)</I></B><BR/>
98 * --------------------------------------------------------------------------------------------------<BR/>
99 * <B>ReportRuntime.java</B> - This class involves in running, downloading RAPTOR reports.
100 * --------------------------------------------------------------------------------------------------<BR/>
103 * <U>Change Log</U><BR/><BR/>
105 * 27-Aug-2009 : Version 8.5 (Sundar); <UL><LI>Order by logic is restored for DAYTONA.</LI></UL>
106 * 13-Aug-2009 : Version 8.5 (Sundar); <UL><LI>Removing order by logic is rollbacked.</LI></UL>
107 * 22-Jun-2009 : Version 8.4 (Sundar); <UL><LI>Bug while parsing SQL for text download is fixed.</LI></UL>
111 public class ReportRuntime extends ReportWrapper implements Cloneable, Serializable {
113 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ReportRuntime.class);
115 //TODO DELETE IF PARSE SQL is not working
116 private int curSQLParsePos = 0;
118 private String xmlFileURL = null;
120 private String xmlFileName = null;
122 private String flatFileName = null;
124 private String excelPageFileName = null;
126 private int reportDataSize = -1;
128 private boolean displayChart = true;
130 private boolean displayForm = true;
132 private boolean displayContent = true;
134 private boolean reportRunLogged = false; // Used to avoid multiple
135 // entries in the report log
136 // when executing with different
137 // params or going to next page
139 private DataSet chartDataCache = null;
141 private ReportData pageDataCache = null;
143 private int cachedPageNo = -1;
145 private String cachedSQL = null; // For display purposes only
147 private String wholeSQL = null; // For display purposes only
149 private String totalSql = null; // For display purposes only
151 private ReportParamValues reportParamValues = null;
153 private ReportParamValuesForPDFExcel reportParamValuesFPE = null;
155 private ReportFormFields reportFormFields = null;
157 private VisualManager visualManager = null;
159 private CrossTabOrderManager crossTabOrderManager = null;
161 private boolean displayColTotals = false;
163 private boolean displayRowTotals = false;
165 private DataRow colDataTotalsLinear = null;
167 private Vector colDataTotalsCrosstab = null;
169 private Vector rowDataTotalsCrosstab = null;
171 private String grandTotalCrosstab = null;
173 public static int DISPLAY_DATA_ONLY = 1;
174 public static int DISPLAY_CHART_ONLY = 2;
175 public static int DISPLAY_CHART_AND_DATA = 3;
177 public static final int DATE_OPTION_MONTHLY = 1;
178 public static final int DATE_OPTION_YEARLY = 2;
179 public static final int DATE_OPTION_DAILY = 3;
182 private int DISPLAY_MODE = 0;
184 private int DATE_OPTION = -1;
187 public void setReportFormFields(ReportFormFields reportFormFields) {
188 this.reportFormFields = reportFormFields;
193 * private ReportRuntime(CustomReport cr, String reportID,
194 * HttpServletRequest request) { super(cr, reportID);
196 * reportParamValues = new ReportParamValues(this); reportFormFields = new
197 * ReportFormFields(this);
199 * if(request!=null) setParamValues(request); } // ReportRuntime
201 private ReportRuntime(CustomReportType crType, String reportID, HttpServletRequest request,
202 String ownerID, String createID, String createDate, String updateID,
203 String updateDate, String menuID, boolean menuApproved) throws RaptorException {
204 super(crType, reportID, ownerID, createID, createDate, updateID, updateDate, menuID,
206 initializeReportRuntime(request);
209 public ReportRuntime(ReportWrapper rw) throws RaptorException {
213 public ReportRuntime(ReportWrapper rw, HttpServletRequest request)throws RaptorException {
215 initializeReportRuntime(request);
218 private void initializeReportRuntime(HttpServletRequest request) throws RaptorException {
219 reportFormFields = new ReportFormFields(this, request);
220 setParamValues(request, true, true);
222 visualManager = new VisualManager();
223 } // initializeReportRuntime
225 // public void setReportFormFields(HttpServletRequest request) {
226 // reportFormFields = new ReportFormFields(this, request);
227 // setParamValues(request, true, true);
230 public static ReportRuntime unmarshal(String reportXML, String reportID)
231 throws RaptorException {
232 return unmarshal(reportXML, reportID, null);
235 public static ReportRuntime unmarshal(String reportXML, String reportID,
236 HttpServletRequest request) throws RaptorException {
237 CustomReportType crType = ReportWrapper.unmarshalCR(reportXML);
238 ObjectFactory objFactory = new ObjectFactory();
240 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] Report [" + reportID + "]: XML unmarshalled"));
242 return new ReportRuntime(crType, reportID, request, null, null, null, null, null, null,
247 public String getXmlFileURL() {
251 public String getXmlFileName() {
255 public String getFlatFileName() {
259 public String getExcelPageFileName() {
260 return excelPageFileName;
263 public int getReportDataSize() {
264 return reportDataSize;
267 public boolean getDisplayChart() {
271 public boolean getDisplayForm() {
275 public boolean getDisplayContent() {
276 return displayContent;
279 public int getCachedPageNo() {
283 public String getCachedSQL() {
287 public boolean isDashboardType() throws RaptorException {
288 return ReportLoader.isDashboardType(getReportID());
292 public void setXmlFileURL(String xmlFileURL) {
293 this.xmlFileURL = xmlFileURL;
296 public void setXmlFileName(String xmlFileName) {
297 this.xmlFileName = xmlFileName;
300 public void setFlatFileName(String flatFileName) {
301 this.flatFileName = flatFileName;
304 public void setExcelPageFileName(String excelPageFileName) {
305 this.excelPageFileName = excelPageFileName;
308 /*private*/ public void setReportDataSize(int reportDataSize) {
309 this.reportDataSize = reportDataSize;
312 private void setDisplayForm(boolean displayForm) {
313 this.displayForm = displayForm;
316 private void setDisplayContent(boolean displayContent) {
317 this.displayContent = displayContent;
320 public void setDisplayFlags(boolean isFirstAccess, boolean forceDisplayContent) {
322 setDisplayForm(true);
324 if (forceDisplayContent)
325 setDisplayContent(true);
326 else if (Globals.getDisplayFormBeforeRun())
328 setDisplayContent(false);
330 setDisplayContent(true);
332 setDisplayContent(true);
334 setDisplayContent(true);
336 if (Globals.getIncludeFormWithData())
337 setDisplayForm(true);
338 else if (Globals.getDisplayFormBeforeRun())
339 setDisplayForm(false);
341 setDisplayForm(true);
345 public void logReportRun(String userID, String executionTime, String formFields) throws RaptorException {
349 ReportLoader.createReportLogEntry(null, reportID, userID, AppConstants.RLA_RUN,executionTime,formFields );
350 reportRunLogged = true;
353 public void logReportExecutionTime(String userId, String executionTime, String action, String formFields) throws RaptorException {
354 ReportLoader.createReportLogEntryForExecutionTime(null, reportID, userId,executionTime , action, formFields);
357 public void logReportExecutionTimeFromLogList (String userId, String executionTime, String formFields) throws RaptorException {
358 ReportLoader.createReportLogEntryForExecutionTime(null, reportID, userId,executionTime , AppConstants.RLA_FROM_LOG, formFields);
361 public void resetVisualSettings() {
362 boolean haveToResetCachedData = (visualManager.getSortByColId().length() > 0);
363 visualManager = new VisualManager();
365 if (haveToResetCachedData)
366 pageDataCache = null;
368 if (pageDataCache != null)
369 pageDataCache.resetVisualSettings();
370 } // resetVisualSettings
372 /** ************** ReportParamValues processing *************** */
374 public boolean setParamValues(HttpServletRequest request, boolean resetParams, boolean refresh) throws RaptorException {
375 boolean paramsUpdated = false;
377 reportFormFields = new ReportFormFields(this, request);
378 reportParamValues = new ReportParamValues(reportFormFields, getReportDefType());
379 // This is called even in the wizard page. Hence this condition.
380 if((ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)!=null)
381 reportParamValuesFPE = new ReportParamValuesForPDFExcel(reportFormFields, getReportDefType());
382 paramsUpdated = true;
384 reportRunLogged = false;
385 } else if (request != null) {
386 paramsUpdated = reportParamValues.setParamValues(request,refresh);
388 // This is called even in the wizard page. Hence this condition.
389 if((ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)!=null) {
390 if(reportParamValuesFPE!=null) reportParamValuesFPE.setParamValues(request,refresh);
392 reportParamValuesFPE = new ReportParamValuesForPDFExcel(reportFormFields, getReportDefType());
393 reportParamValuesFPE.setParamValues(request,refresh);
396 reportFormFields = new ReportFormFields(this, request);
397 //added below two lines for dashboard default value
398 reportParamValues = new ReportParamValues(reportFormFields, getReportDefType());
399 reportParamValues.setParamValues(request,refresh);
401 reportParamValuesFPE = new ReportParamValuesForPDFExcel(reportFormFields, getReportDefType());
402 reportParamValuesFPE.setParamValues(request,refresh);
407 setReportDataSize(-1);
408 chartDataCache = null;
409 pageDataCache = null;
412 crossTabOrderManager = null;
414 colDataTotalsLinear = null;
415 colDataTotalsCrosstab = null;
416 rowDataTotalsCrosstab = null;
417 grandTotalCrosstab = null;
419 resetVisualSettings();
422 displayChart = (request.getParameter(AppConstants.RI_DISPLAY_CHART) == null) ? !isDisplayOptionHideChart() : request.getParameter("display_chart")
425 return paramsUpdated;
428 public String getParamValue(String key) {
429 //reportParamValues.printValues();
430 return reportParamValues.getParamValue(key);
433 public String getParamDisplayValue(String key) {
434 //reportParamValues.printValues();
435 return reportParamValues.getParamDisplayValue(key);
438 public Enumeration getParamKeys() {
439 return reportParamValues.keys();
442 public Enumeration getParamKeysForPDFExcel() {
443 return reportParamValuesFPE.keys();
446 public String getParamValueForPDFExcel(String key) {
447 return reportParamValuesFPE.getParamValue(key);
450 public ArrayList getParamNameValuePairs() {
451 ArrayList paramList = new ArrayList(getReportFormFields().size());
452 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
453 FormField ff = (FormField) iter.next();
454 paramList.add(new IdNameValue(ff.getFieldDisplayName(), reportParamValues
455 .getParamDisplayValue(ff.getFieldName())));
458 } // getParamNameValuePairs
460 public ArrayList getParamNameValuePairsforPDFExcel(HttpServletRequest request, int type /*excel =1; pdf=2*/) {
461 javax.servlet.http.HttpSession session = request.getSession();
462 ArrayList paramList = new ArrayList(getReportFormFields().size());
463 if(session.getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)!=null) {
464 paramList = (ArrayList) session.getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO);
465 if(paramList!=null && paramList.size()>0)
468 //System.out.println(" getParamNamePairs type " + type + " " + Globals.customizeFormFieldInfo());
469 if ( reportParamValuesFPE == null) {
470 reportParamValuesFPE = new ReportParamValuesForPDFExcel(reportFormFields, getReportDefType());
471 reportParamValuesFPE.setParamValues(request,true);
474 String valueString = "";
475 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
476 FormField ff = (FormField) iter.next();
477 if(ff.isVisible() && /*!ff.getFieldType().equals(FormField.FFT_HIDDEN) &&*/ type == 1){
478 valueString = reportParamValuesFPE.getParamDisplayValue(ff.getFieldName());
479 } else if(ff.isVisible() && type != 1) {
480 valueString = reportParamValuesFPE.getParamDisplayValue(ff.getFieldName());
482 if(valueString.equalsIgnoreCase("NULL"))
484 paramList.add(new IdNameValue(ff.getFieldDisplayName(), valueString));
488 String pdfAttachmentKey = AppUtils.getRequestValue(request, "pdfAttachmentKey");
489 boolean isSchedule = false;
490 if(pdfAttachmentKey != null)
492 if(Globals.customizeFormFieldInfo() && type == 2) {
493 String[] sessionParameters = Globals.getSessionParams().split(",");
495 if(session != null && !isSchedule ) {
496 session.setAttribute("login_id", AppUtils.getUserBackdoorLoginId(request));
497 for (int i = 0; i < sessionParameters.length; i++) {
498 if(session.getAttribute(sessionParameters[i])!=null)
499 paramList.add(new IdNameValue(sessionParameters[i].toUpperCase(), (String)session.getAttribute(sessionParameters[i])));
504 //debugLogger.debug("Globals " + Globals.getSessionParamsForScheduling());
505 String[] scheduleSessionParam = Globals.getSessionParamsForScheduling().split(",");
506 for (int i = 0; i < scheduleSessionParam.length; i++) {
507 //debugLogger.debug(" scheduleSessionParam[i] " + scheduleSessionParam[i] + " " + request.getParameter(scheduleSessionParam[i]) );
508 if(request.getParameter(scheduleSessionParam[i])!=null)
509 paramList.add(new IdNameValue(ESAPI.encoder().canonicalize(scheduleSessionParam[i].toUpperCase()), ESAPI.encoder().canonicalize(request.getParameter(scheduleSessionParam[i]))));
514 SimpleDateFormat oracleDateFormat = new SimpleDateFormat("MM/dd/yyyy kk:mm:ss");
515 Date sysdate = oracleDateFormat.parse(ReportLoader.getSystemDateTime());
516 SimpleDateFormat dtimestamp = new SimpleDateFormat(Globals.getScheduleDatePattern());
517 paramList.add(new IdNameValue("DATE", dtimestamp.format(sysdate)+" "+Globals.getTimeZone()));
518 } catch(Exception ex) {}
521 //System.out.println(" In Else getParamNamePairs type " + type);
522 String[] sessionDisplayParameters = Globals.getDisplaySessionParamInPDFEXCEL().split(",");
523 if(session != null && !isSchedule ) {
524 session.setAttribute("login_id", AppUtils.getUserBackdoorLoginId(request));
525 for (int i = 0; i < sessionDisplayParameters.length; i++) {
526 String sessionDispParam = sessionDisplayParameters[i];
527 if(nvl(sessionDispParam).length()>0) {
528 String sessionDispParamArr[] = sessionDispParam.split(";");
529 //System.out.println("Session " + sessionDispParamArr[1] + " " + (String)session.getAttribute(sessionDispParamArr[0]));
530 paramList.add(new IdNameValue(sessionDispParamArr[1], nvl((String)session.getAttribute(sessionDispParamArr[0]),"")));
535 String[] scheduleSessionParam = Globals.getDisplayScheduleSessionParamInPDFEXCEL().split(",");
536 for (int i = 0; i < scheduleSessionParam.length; i++) {
537 String scheduleSessionDispParam = scheduleSessionParam[i];
538 if(nvl(scheduleSessionDispParam).length()>0) {
539 String scheduleSessionDispParamArr[] = scheduleSessionDispParam.split(";");
540 paramList.add(new IdNameValue(ESAPI.encoder().canonicalize(scheduleSessionDispParamArr[1]), ESAPI.encoder().canonicalize(nvl(request.getParameter(scheduleSessionDispParamArr[0]),""))));
545 SimpleDateFormat oracleDateFormat = new SimpleDateFormat("MM/dd/yyyy kk:mm:ss");
546 Date sysdate = oracleDateFormat.parse(ReportLoader.getSystemDateTime());
547 SimpleDateFormat dtimestamp = new SimpleDateFormat(Globals.getScheduleDatePattern());
548 paramList.add(new IdNameValue("Report Date/Time", dtimestamp.format(sysdate)+" "+Globals.getTimeZone()));
549 } catch(Exception ex) {}
553 for (int i = 0; i < paramList.size(); i++) {
554 IdNameValue value = (IdNameValue) paramList.get(i);
555 String name = value.getName().replaceAll(",","~");
558 //request.getSession().setAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO, paramList);
560 } // getParamNameValuePairs
562 /** ************** ReportFormFields processing *************** */
564 public String getFormFieldComments(HttpServletRequest request) {
566 StringBuffer st = new StringBuffer("");
567 if(getFormFieldList()!=null){
568 comment = nvl(getFormFieldList().getComment());
570 if(comment.length()>0) {
571 al = getParamNameValuePairsforPDFExcel(request, 2);
573 //st = new StringBuffer(comment);
574 for (int i=0; i < al.size(); i++) {
575 IdNameValue idNameValue = (IdNameValue)al.get(i);
576 if(nvl(idNameValue.getId()).equals("DATE"))
577 st.append("<b>Date/Time Report Run:</b>"+ idNameValue.getName() +"<br></br>");
580 for (int i=0; i < al.size(); i++) {
581 IdNameValue idNameValue = (IdNameValue)al.get(i);
582 comment = Utils.replaceInString(comment, "["+ idNameValue.getId()+"]", idNameValue.getName());
589 return st.toString();
592 public boolean needFormInput() {
593 return reportFormFields.getFieldCount() > 0;
596 public FormField getFormField(String fieldName) {
597 return reportFormFields.getFormField(fieldName);
600 public ReportFormFields getReportFormFields() {
601 return reportFormFields;
602 } // getReportFormFields
604 public void setChartDataCache(DataSet chartDataCache) {
605 this.chartDataCache = chartDataCache;
609 /** ************** Report Data processing *************** */
610 public DataSet loadChartData(String userId, HttpServletRequest request) throws RaptorException {
611 if (nvl(getChartType()).length() == 0)
613 if (!getDisplayChart())
616 DataSet ds = chartDataCache;
619 sql = generateChartSQL(reportParamValues, userId, request);
620 String dbInfo = getDBInfo();
621 ds = ConnectionUtils.getDataSet(sql, dbInfo);
622 if (Globals.getCacheChartData())
629 public String getReportDataSQL(String userId, int downloadLimit, HttpServletRequest request) throws RaptorException {
630 String reportSQL = "";
631 if(doesReportContainsGroupFormField()) {
632 reportSQL = generateSubsetSQL(0, downloadLimit,userId, request, true, reportParamValues);
634 reportSQL = generateSubsetSQL(0, downloadLimit,userId, request, false, reportParamValues);
638 public ReportData loadReportData(int pageNo, String userId, int downloadLimit, HttpServletRequest request, boolean download) throws RaptorException {
639 ReportData rd = null;
640 boolean isGoBackAction = AppUtils.getRequestFlag(request, AppConstants.RI_GO_BACK);
642 if (pageNo == cachedPageNo && pageDataCache != null)
645 if(isGoBackAction && rd!=null) return rd;
646 if (rd == null) { // Commented So that Data is refreshed from DB again
647 if (getReportDataSize() < 0)
648 if (getReportType().equals(AppConstants.RT_CROSSTAB))
649 rd = loadCrossTabReportData(pageNo, userId, downloadLimit, request, download);
650 else if (getReportType().equals(AppConstants.RT_LINEAR))
651 rd = loadLinearReportData(pageNo, userId, downloadLimit, request, download);
653 throw new RuntimeException(
654 "[ReportRuntime.loadReportData] Invalid report type");
657 if (Globals.getCacheCurPageData()) {
659 cachedPageNo = pageNo;
661 } // if // Commented So that Data is refreshed from DB again
666 private ReportData loadCrossTabReportData(int pageNo, String userId, int downloadLimit, HttpServletRequest request, boolean download) throws RaptorException {
667 String reportSQL = generateSQL(reportParamValues, userId, request);
668 setWholeSQL(reportSQL);
669 cachedSQL = reportSQL;
670 wholeSQL = reportSQL;
671 List reportCols = getAllColumns();
672 // replace the request parameter specified in the drill down
673 DataColumnType dataColumnRequest = getCrossTabValueColumn();
674 reportSQL = parseReportSQLForDrillDownParams(reportSQL, dataColumnRequest, request);
679 String dbInfo = getDBInfo();
680 StringBuffer colNames = new StringBuffer();
681 StringBuffer colExtraIdNames = new StringBuffer();
682 StringBuffer colExtraDateNames = new StringBuffer();
685 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
686 DataColumnType dc = (DataColumnType) iter.next();
687 //TODO: commented if (dc.isVisible()) {
688 if (colNames.length() > 0)
689 colNames.append(", ");
690 colNames.append(dc.getColId());
691 //TODO uncomment if it's not working} // if
693 // Checking for extra fields necessary for drill-down
694 if (nvl(dc.getDrillDownURL()).length() > 0) {
695 System.out.println("Drilldown URL " + dc.getDrillDownURL());
700 if (reportSQL.toUpperCase().indexOf("GROUP BY ") < 0)
701 colNames.append(colExtraIdNames.toString());
702 colNames.append(colExtraDateNames.toString());
703 //reportSQL = " SELECT ROWNUM rnum, "
704 // + colNames.toString() + " FROM (" + reportSQL + ") ";
706 String rSQL = Globals.getLoadCrosstabReportData();
707 rSQL = rSQL.replace("[colNames.toString()]", colNames.toString());
708 rSQL = rSQL.replace("[reportSQL]", reportSQL);
710 setWholeSQL(reportSQL);
711 if (crossTabOrderManager == null)
712 crossTabOrderManager = new CrossTabOrderManager(this, userId,request);
713 ds = ConnectionUtils.getDataSet(reportSQL, dbInfo);
715 ReportData rd = new ReportData(pageNo, false);
716 ReportFormFields childReportFormFields = null;
717 if(doesReportContainsGroupFormField()) {
718 List reportCols1 = getAllColumns();
719 reportCols = new Vector();
721 for (Iterator iter = reportCols1.iterator(); iter.hasNext();) {
722 DataColumnType dct = (DataColumnType) iter.next();
723 for (int k=0; k<ds.getColumnCount(); k++) {
724 if(dct.getColId().toUpperCase().trim().equals(ds.getColumnName(k).trim())) {
731 if (getFormFieldList() != null) {
732 String paramValue = "";
733 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
734 FormFieldType fft = (FormFieldType) iter.next();
735 if(fft.isGroupFormField()!=null && fft.isGroupFormField().booleanValue()) {
736 paramValue = Utils.oracleSafe(nvl(reportParamValues
737 .getParamValue(fft.getFieldId())));
739 for (Iterator iter1 = reportCols1.iterator(); iter1.hasNext();) {
740 DataColumnType dct = (DataColumnType) iter1.next();
741 if(("["+fft.getFieldName()+ "]").equals(dct.getColName().trim())) {
742 dct.setDisplayName(paramValue);
753 int dataColumnIdx = (rd.reportRowHeaderCols.size() + rd.reportColumnHeaderRows.size())-1;
754 DataColumnType dataColumn = getCrossTabValueColumn();
756 String columnValue = "";
759 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
760 DataColumnType dct = (DataColumnType) iter.next();
762 if (nvl(dct.getDrillDownURL()).length() > 0) {
763 childReportFormFields = getChildReportFormFields(request,dct.getDrillDownURL());
766 if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_ROW)) {
767 RowHeaderCol rhc = new RowHeaderCol();
768 rhc.setColumnTitle(dct.getDisplayName());
769 // rhc.setColumnWidth("10%");
770 //rhc.setColumnWidth(dct.getDisplayWidth() + "%");
771 if(nvl(dct.getDisplayWidthInPxls()).length()<=0) {
772 dct.setDisplayWidthInPxls("100px");
774 if(dct.getDisplayWidthInPxls().endsWith("px"))
775 rhc.setColumnWidth(dct.getDisplayWidthInPxls());
777 rhc.setColumnWidth(dct.getDisplayWidthInPxls()+"px");
779 rhc.setAlignment(dct.getDisplayAlignment());
780 rhc.setDisplayHeaderAlignment(dct.getDisplayHeaderAlignment());
781 rhc.setNowrap(nvl(dataColumn.getNowrap(),"null").equals("false")?"null":nvl(dataColumn.getNowrap(),"null"));
782 rd.reportRowHeaderCols.addRowHeaderCol(rhc);
783 } else if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_COLUMN)) {
784 ColumnHeaderRow chr = new ColumnHeaderRow();
785 chr.setAlignment(dct.getDisplayHeaderAlignment());
786 chr.setRowHeight("15");
787 if(nvl(dct.getDisplayWidthInPxls()).length()<=0) {
788 dct.setDisplayWidthInPxls("80px");
790 if(dct.getDisplayWidthInPxls().endsWith("px"))
791 chr.setDisplayWidth(dct.getDisplayWidthInPxls());
793 chr.setDisplayWidth(dct.getDisplayWidthInPxls()+"px");
795 rd.reportColumnHeaderRows.addColumnHeaderRow(chr);
796 } else if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_VALUE)) {
797 columnValue = dct.getColId();
799 if(!dct.getColId().toLowerCase().endsWith("_sort")) {
800 RowHeaderCol rhc = new RowHeaderCol();
801 rhc.setVisible(false);
802 rd.reportRowHeaderCols.addRowHeaderCol(rhc);
807 //int dataColumnIdx = getCrossTabValueColumnIndex();
808 FormatProcessor formatProcessor = new FormatProcessor(getSemaphoreById(dataColumn
810 getReportDefType().equals(AppConstants.RD_SQL_BASED) ? AppConstants.CT_NUMBER
811 : dataColumn.getColType(), dataColumn.getColFormat(), false);
812 List dataList = new ArrayList();
813 /* //fillup all rows based on rowheaders
814 Vector rowHeaders = crossTabOrderManager.getRowHeaderValues();
815 CrossTabColumnValues crossTabRowValues;
817 for (int i = 0; i < rowHeaders.size(); i++) {
818 if((i+1)==rowHeaders.size()) {
819 crossTabRowValues = (CrossTabColumnValues) rowHeaders.get(i);
820 size = crossTabRowValues.getValuesCount();
824 for (int i = 0; i < size; i++) {
825 dataList.add(new DataRow());
828 for (int i = 0; i < ds.getRowCount(); i++) {
829 Vector rValues = new Vector();
830 Vector cValues = new Vector();
831 Vector cValuesSort = new Vector();
834 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
836 DataColumnType dct = (DataColumnType) iter.next();
837 if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_ROW))
838 rValues.add(addDataValue(dct, ds.getString(i, dct.getColId())));
839 if (nvl(dct.getCrossTabValue()).trim().length()<=0 && !dct.getColId().toLowerCase().endsWith("_sort"))
840 rValues.add(addDataValue(dct, ds.getString(i, dct.getColId())));
841 if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_COLUMN)) {
842 cValues.add(addDataValue(dct, ds.getString(i, dct.getColId())));
843 if(getColumnById(dct.getColId().toLowerCase()+"_sort")!=null)
844 cValuesSort.add(addDataValue(dct, new Integer(ds.getString(i, dct.getColId()+"_sort")).toString()));
848 } catch (ArrayIndexOutOfBoundsException ex ) {continue;}
849 catch (NumberFormatException ex1) {
850 ex1.printStackTrace();
855 DataValue dv = new DataValue();
856 dv.setDisplayValue(ds.getString(i, columnValue));
857 if (nvl(dataColumn.getCrossTabValue()).trim().length()<=0)
858 dv.setVisible(false);
859 dv.setAlignment(dataColumn.getDisplayAlignment());
860 dv.setDisplayTotal(dataColumn.getDisplayTotal());
861 dv.setColName(dataColumn.getColName());
862 dv.setDisplayName(dataColumn.getDisplayName());
863 dv.setColId(dataColumn.getColId());
864 dv.setNowrap(nvl(dataColumn.getNowrap(),"null").equals("false")?"null":nvl(dataColumn.getNowrap(),"null"));
865 /*StringBuffer indentation = new StringBuffer("");
866 if(dataColumn.getIndentation()!=null && dataColumn.getIndentation().intValue()>0) {
867 for (int indent=0; indent < dataColumn.getIndentation(); indent++) {
868 indentation.append("\t");
870 dv.setNowrap("true");
872 dv.setIndentation(indentation.toString());*/
874 if (nvl(dataColumn.getDrillDownURL()).length() > 0) {
875 if(dv.getDisplayValue().length() > 0) {
876 dv.setDrillDownURL(parseDrillDownURL(i, /* dataColumnIdx, */ds, dataColumn,request, childReportFormFields));
877 dv.setDrillDowninPoPUp(dataColumn.isDrillinPoPUp()!=null?dataColumn.isDrillinPoPUp():false);
879 if (dv.getDisplayValue().length() == 0) {
880 //dv.setDisplayValue("[NULL]");
881 dv.setDisplayValue("");
885 rd.setDataValue(rValues, cValues, cValuesSort.size()==0?null:cValuesSort, dv, formatProcessor, crossTabOrderManager, dataList);
887 rd.setReportDataList(dataList);
888 /*if (getReportDataSize() < 0)
889 setReportDataSize(rd.getDataRowCount());*/
892 rd.truncateData(pageNo * getPageSize(), (pageNo + 1) * getPageSize() - 1);
894 if( downloadLimit != -1)
895 rd.truncateData(0, downloadLimit - 1);
897 rd.truncateData(0, -1);
900 if (colDataTotalsCrosstab == null)
901 colDataTotalsCrosstab = generateDataTotalsCrossTab(AppConstants.CV_COLUMN, userId,request);
902 if (displayColTotals && colDataTotalsCrosstab != null)
903 rd.setColumnDataTotalsCrossTab(colDataTotalsCrosstab, dataColumn
904 .getDisplayAlignment(), getCrossTabDisplayTotal(AppConstants.CV_COLUMN),
905 crossTabOrderManager, dataList);
907 if (rowDataTotalsCrosstab == null)
908 rowDataTotalsCrosstab = generateDataTotalsCrossTab(AppConstants.CV_ROW, userId, request);
909 if (displayRowTotals && rowDataTotalsCrosstab != null)
910 rd.setRowDataTotalsCrossTab(rowDataTotalsCrosstab, dataColumn
911 .getDisplayAlignment(), getCrossTabDisplayTotal(AppConstants.CV_ROW),
912 crossTabOrderManager, dataList);
916 && getCrossTabDisplayTotal(AppConstants.CV_COLUMN).equals(
917 getCrossTabDisplayTotal(AppConstants.CV_ROW))) {
918 // Display grand total
919 if (grandTotalCrosstab == null)
920 grandTotalCrosstab = ((CrossTabTotalValue) generateDataTotalsCrossTab("",
921 userId,request).get(0)).getTotalValue();
922 if (grandTotalCrosstab != null)
923 rd.setGrandTotalCrossTab(Utils.truncateTotalDecimals(grandTotalCrosstab),
924 dataColumn.getDisplayAlignment(),
925 getCrossTabDisplayTotal(AppConstants.CV_COLUMN), dataList);
928 rd.consolidateColumnHeaders(visualManager);
929 //if (Globals.getMergeCrosstabRowHeadings())
930 // rd.consolidateRowHeaders();
931 //rd.addRowNumbers(pageNo, dataList);
933 if (displayColTotals && colDataTotalsCrosstab != null) {
934 String totalLabel = "Total";
935 String colDisplayTotal = getCrossTabDisplayTotal(AppConstants.CV_COLUMN);
936 if (colDisplayTotal.length() > 0
937 && (!colDisplayTotal.equals(AppConstants.TOTAL_SUM_ID)))
938 totalLabel = nvl(AppConstants.TOTAL_FUNCTIONS.getNameById(colDisplayTotal));
939 if (getReportDataSize() > getPageSize())
940 totalLabel += "_nl_(for all pages)";
942 //rd.setCrossTabColumnTotalLabel(totalLabel);
945 //rd.applyVisibility();
946 //Collections.sort((List)dataList, new DataRowComparable());
947 DataRow drInFor1 = null;
948 Vector<DataValue> v1= null, v2 = null;
949 ArrayList<String> temp = new ArrayList<String>();
950 if (Globals.getMergeCrosstabRowHeadings()) {
951 for (int i = 0; i < dataList.size(); i++) {
952 drInFor1 = (DataRow)dataList.get(i);
953 drInFor1.setRowNum(i+1);
954 v1 = drInFor1.getRowValues();
955 if(i<dataList.size()-1) {
956 v2 = ((DataRow)dataList.get(i+1)).getRowValues();
958 v2 = ((DataRow)dataList.get(i-1)).getRowValues();
960 for (int j = 0; j < v1.size(); j++) {
962 if(v1.get(j).getDisplayValue().length()>0) { // another ArrayList
963 temp = new ArrayList();
964 temp.add(v1.get(j).getDisplayValue());
966 if(v2!=null && temp.get(j).equals(v2.get(j).getDisplayValue())) {
967 v2.get(j).setDisplayValue("");
973 rd.setReportDataList(dataList);
974 if (getReportDataSize() < 0) {
975 //setReportDataSize(rd.getDataRowCount());
976 setReportDataSize(rd.getReportDataList().size());
980 } // loadCrossTabReportData
983 public DataValue addDataValue(DataColumnType dataColumn, String columnValue) {
984 DataValue dv = new DataValue();
985 dv.setDisplayValue(columnValue);
986 if (nvl(dataColumn.getCrossTabValue()).trim().length()<=0)
987 dv.setVisible(false);
988 dv.setAlignment(dataColumn.getDisplayAlignment());
989 dv.setDisplayTotal(dataColumn.getDisplayTotal());
990 dv.setColName(dataColumn.getColName());
991 dv.setDisplayName(dataColumn.getDisplayName());
992 dv.setColId(dataColumn.getColId());
993 dv.setNowrap(nvl(dataColumn.getNowrap(),"null").equals("false")?"null":nvl(dataColumn.getNowrap(),"null"));
998 /*private*/ public boolean doesReportContainsGroupFormField() {
1000 if(getFormFieldList()!=null) {
1001 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
1002 FormFieldType fft = (FormFieldType) iter.next();
1003 if(fft.isGroupFormField()!=null && fft.isGroupFormField().booleanValue()) {
1012 private ReportData loadLinearReportData(int pageNo, String userId, int downloadLimit, HttpServletRequest request, boolean download) throws RaptorException {
1013 String action = nvl(request.getParameter(AppConstants.RI_ACTION), request.getParameter("action"));;
1015 String reportSQL = "";
1017 if(action.endsWith("session")) {
1018 reportSQL = getWholeSQL();
1019 wholeSQL = reportSQL;
1021 reportSQL = generateSQL(reportParamValues, visualManager.getSortByColId(),
1022 visualManager.getSortByAscDesc(), userId, request);
1023 wholeSQL = reportSQL;
1024 setWholeSQL(wholeSQL);
1027 String dbInfo = getDBInfo();
1028 ds = ConnectionUtils.getDataSet(wholeSQL, dbInfo);
1029 setReportDataSize(ds.getRowCount());
1030 //wholeSQL = reportSQL;
1031 HttpSession session = request.getSession();
1032 //debugLogger.debug(" ******** Download Limit ********* " + downloadLimit + " %%%%%%%%%%PAGE " + pageNo );
1033 List reportCols = null;
1034 StringBuffer colNames = new StringBuffer();
1036 if(download && action.endsWith("session")) {
1037 reportCols = getAllColumns();
1038 colNames = new StringBuffer();
1039 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1041 DataColumnType dc = (DataColumnType) iter.next();
1042 if (colNames.length() > 0)
1043 colNames.append(", ");
1044 colNames.append(dc.getColId());
1049 String pagedSQL = null; // reportSQL;
1051 pagedSQL = generatePagedSQL(pageNo, userId, request, false, null);
1053 pagedSQL = generateSubsetSQL(0, downloadLimit, userId, request, false, null);
1054 // replace the request parameter specified in the drill down
1055 reportCols = getAllColumns();
1056 colNames = new StringBuffer();
1057 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1059 DataColumnType dc = (DataColumnType) iter.next();
1060 if (colNames.length() > 0)
1061 colNames.append(", ");
1062 colNames.append(dc.getColId());
1063 if (dc.isVisible()) {
1064 reportSQL = parseReportSQLForDrillDownParams(reportSQL, dc, request);
1065 pagedSQL = parseReportSQLForDrillDownParams(pagedSQL, dc, request);
1069 cachedSQL = pagedSQL;
1073 if(doesReportContainsGroupFormField()) {
1075 pagedSQL = generatePagedSQL(pageNo, userId, request, true, reportParamValues);
1077 pagedSQL = generateSubsetSQL(0, downloadLimit, userId, request, true, reportParamValues);
1079 //check for Group formfield
1080 //if groupformfield get columns from sql
1082 ds = ConnectionUtils.getDataSet(pagedSQL, dbInfo);
1084 if(doesReportContainsGroupFormField()) {
1085 List reportCols1 = getAllColumns();
1086 reportCols = new Vector();
1088 for (Iterator iter = reportCols1.iterator(); iter.hasNext();) {
1089 DataColumnType dct = (DataColumnType) iter.next();
1090 for (int k=0; k<ds.getColumnCount(); k++) {
1091 if(dct.getColId().toUpperCase().trim().equals(ds.getColumnName(k).trim())) {
1092 reportCols.add(dct);
1098 if (getFormFieldList() != null) {
1099 String paramValue = "";
1100 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
1101 FormFieldType fft = (FormFieldType) iter.next();
1102 if(fft.isGroupFormField()!=null && fft.isGroupFormField().booleanValue()) {
1103 paramValue = Utils.oracleSafe(nvl(reportParamValues
1104 .getParamValue(fft.getFieldId())));
1106 for (Iterator iter1 = reportCols1.iterator(); iter1.hasNext();) {
1107 DataColumnType dct = (DataColumnType) iter1.next();
1108 if(("["+fft.getFieldName()+ "]").equals(dct.getColName().trim())) {
1109 dct.setDisplayName(paramValue);
1121 // if ( (remDbInfo!=null) && (!remDbInfo.equals(AppConstants.DB_LOCAL)))
1123 // Globals.getRDbUtils().setDBPrefix(remDbInfo);
1124 // ds = RemDbUtils.executeQuery(pagedSQL);
1127 // ds = DbUtils.executeQuery(pagedSQL);
1129 * } catch(SQLException e) { throw new
1130 * ReportSQLException("[ReportRuntime.loadLinearReportData]
1131 * "+e.getMessage(), pagedSQL); }
1134 if (getReportDataSize() < 0)
1136 setReportDataSize(ds.getRowCount());
1137 else if (ds.getRowCount() <= getPageSize())
1138 setReportDataSize(ds.getRowCount());
1141 /*Pattern re1 = Pattern.compile("[Oo][Rr][Dd][Ee][Rr](.*?[^\r\n]*)[Bb][Yy]", Pattern.DOTALL);
1142 Pattern re2 = Pattern.compile("[Oo][Rr][Dd][Ee][Rr](.*?[^\r\n]*)[Bb][Yy]((.*?[^\r\n]*)|[\\s]|[^0-9a-zA-Z])\\)", Pattern.DOTALL);
1143 Matcher matcher = re1.matcher(reportSQL);
1144 Matcher matcher2 = null;
1145 int startPoint = reportSQL.length()-30;
1146 String startReportSQL = "";
1147 String endReportSQL = "";
1148 while(reportSQL.indexOf("xid", startPoint)!=-1)startPoint++;
1149 if (matcher.find(startPoint)) {
1150 startReportSQL = reportSQL.substring(0, reportSQL.indexOf(matcher.group()));
1151 endReportSQL = reportSQL.substring(reportSQL.indexOf(matcher.group()));
1152 matcher2 = re2.matcher(endReportSQL);
1154 endReportSQL = endReportSQL.substring(matcher.group().length()-1);
1157 reportSQL = startReportSQL + endReportSQL;
1159 String countSQL = "SELECT count(*) FROM (" + reportSQL + ")"+ (Globals.isPostgreSQL() || Globals.isMySQL()?" AS ":"") +" x ";
1162 if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
1164 org.onap.portalsdk.analytics.util.RemDbInfo remDbInfo = new org.onap.portalsdk.analytics.util.RemDbInfo();
1165 dbType = remDbInfo.getDBType(dbInfo);
1166 if (dbType.equals("DAYTONA") && reportSQL.trim().toUpperCase().startsWith("SELECT")) {
1167 Pattern re1 = Pattern.compile("order(.*?[^\r\n]*)by", Pattern.DOTALL);
1168 Matcher matcher = re1.matcher(reportSQL);
1169 int startPoint = reportSQL.length()-30;
1170 while(reportSQL.indexOf("xid", startPoint)!=-1)startPoint++;
1171 if (matcher.find(startPoint)) {
1172 reportSQL = reportSQL.substring(0, reportSQL.indexOf(matcher.group()));
1174 countSQL = "SELECT count(*) FROM (" + reportSQL + ")"+ (Globals.isPostgreSQL() || Globals.isMySQL()?" AS ":"") +" x";
1175 countSQL = countSQL + " ("+ colNames+ ")";
1176 } else if (dbType.equals("DAYTONA")) {
1177 setReportDataSize(50);
1179 } catch (Exception ex) {
1180 throw new RaptorException(ex);
1186 if(reportSQL.trim().toUpperCase().startsWith("SELECT")) {
1187 ds2 = ConnectionUtils.getDataSet(countSQL, dbInfo);
1188 if (ds2.getRowCount() > 0)
1189 setReportDataSize(ds2.getInt(0, 0));
1191 throw new RuntimeException(
1192 "[ReportRuntime.loadLinearReportData] Unable to load report data size");
1194 setReportDataSize(50);
1195 // if ( (remDbInfo!=null) &&
1196 // (!remDbInfo.equals(AppConstants.DB_LOCAL))){
1197 // Globals.getRDbUtils().setDBPrefix(remDbInfo);
1198 // ds2 = RemDbUtils.executeQuery(countSQL);
1201 // ds2 = DbUtils.executeQuery(countSQL);
1203 * } catch(SQLException e) { throw new
1204 * ReportSQLException("[ReportRuntime.loadLinearReportData size]
1205 * "+e.getMessage(), countSQL); }
1211 ReportData rd = new ReportData(pageNo, true);
1213 // Already defined changed for modifying request parameters
1214 //List reportCols = getAllColumns();
1215 Vector visibleCols = new Vector(reportCols.size());
1216 Vector formatProcessors = new Vector(reportCols.size());
1218 // ColumnHeaderRow chr = new ColumnHeaderRow();
1219 // rd.reportColumnHeaderRows.addColumnHeaderRow(chr);
1220 // chr.setRowHeight("30");
1224 ReportFormFields rff = getReportFormFields();
1225 ReportFormFields childReportFormFields = null;
1226 String fieldDisplayName = "";
1227 String fieldValue = "";
1229 for (int c = 0; c < reportCols.size(); c++) {
1230 if(reportCols.get(c)!=null) {
1231 DataColumnType dct = (DataColumnType) reportCols.get(c);
1232 if(nvl(dct.getDependsOnFormField()).length()>0 && nvl(dct.getDependsOnFormField()).indexOf("[")!=-1) {
1233 for(int i = 0 ; i < rff.size(); i++) {
1234 fieldDisplayName = "["+((FormField)rff.getFormField(i)).getFieldDisplayName()+"]";
1236 //if(dct.getOriginalDisplayName()==null) dct.setOriginalDisplayName(dct.getDisplayName());
1237 if (dct.getDependsOnFormField().equals(fieldDisplayName)) {
1238 fieldValue = nvl(request.getParameter(((FormField)rff.getFormField(i)).getFieldName()));
1240 if (fieldValue.length()>0) {
1241 if(!fieldValue.toUpperCase().equals("Y"))
1242 dct.setDisplayName(fieldValue);
1243 if(!dct.isVisible())
1244 dct.setVisible(true);
1246 dct.setVisible(false);
1255 String displayName = "";
1256 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1258 DataColumnType dc = (DataColumnType) iter.next();
1260 formatProcessors.add(count,new FormatProcessor(
1261 getSemaphoreById(dc.getSemaphoreId()), dc.getColType(), dc
1262 .getColFormat(), getReportDefType().equals(
1263 AppConstants.RD_SQL_BASED)));
1265 if (nvl(dc.getDrillDownURL()).length() > 0) {
1266 childReportFormFields = getChildReportFormFields(request,AppUtils.getDrillActionURL()+""+dc.getDrillDownURL());
1268 if (dc.isVisible()) {
1269 visibleCols.add(count,dc);
1270 //if(dc.getColId().startsWith("group")) {
1271 for (int d = 0; d < reportCols.size(); d++) {
1272 if(reportCols.get(d)!=null) {
1273 DataColumnType dct1 = (DataColumnType) reportCols.get(d);
1274 if(dct1.getColId().equals(dc.getColId()+"_name") && ds.getRowCount()>0) {
1275 displayName = ds.getString(0,dct1.getColId());
1276 dc.setDisplayName(displayName);
1282 String widthInPxls = dc.getDisplayWidthInPxls();
1284 if(nvl(widthInPxls).endsWith("px"))
1285 dc.setDisplayWidthInPxls(widthInPxls);
1287 widthInPxls = widthInPxls+"px";
1288 dc.setDisplayWidthInPxls(widthInPxls+"px");
1291 rd.createColumn(dc.getColId(), dc.getDisplayName(), dc.getDisplayWidthInPxls(), dc.getDisplayHeaderAlignment(),
1292 visualManager.isColumnVisible(dc.getColId()), visualManager
1293 .getSortByColId().equals(dc.getColId()) ? visualManager
1294 .getSortByAscDesc() : null, isRuntimeColSortDisabled(), dc.getLevel()!=null?dc.getLevel():0, dc.getStart()!=null?dc.getStart():0, dc.getColspan()!=null?dc.getColspan():0, dc.isIsSortable()!=null?dc.isIsSortable():false);
1295 // chr.addColumnHeader(new ColumnHeader(dc.getDisplayName(),
1296 // (dc.getDisplayWidth()>100)?"10%":(""+dc.getDisplayWidth()+"%")));
1299 visibleCols.add(count,null);
1300 rd.createColumn(dc.getColId(), AppConstants.HIDDEN, dc.getDisplayWidthInPxls(), dc.getDisplayHeaderAlignment(),
1301 true, null,false, dc.getLevel()!=null?dc.getLevel():0, dc.getStart()!=null?dc.getStart():0, dc.getColspan()!=null?dc.getColspan():0, dc.isIsSortable()!=null?dc.isIsSortable():false);
1302 // formatProcessors.add(count,null);
1307 if(getReportDefType().equals(AppConstants.RD_SQL_BASED_DATAMIN) && pageNo ==0) {
1310 v = addForecastData(reportSQL);
1311 } catch (Exception ex) {
1312 ex.printStackTrace();
1313 throw new RaptorException (ex);
1315 session.setAttribute("FORECASTED_DATA", v);
1316 DataSet dsWhole = ConnectionUtils.getDataSet(wholeSQL, dbInfo);
1318 session.setAttribute(AppConstants.RI_CHART_FORECAST_DATA, dsWhole);
1321 if(getReportDefType().equals(AppConstants.RD_SQL_BASED_DATAMIN) && session.getAttribute("FORECASTED_DATA")!=null) {
1322 Vector vForecastedData = (Vector)session.getAttribute("FORECASTED_DATA");
1323 if(vForecastedData.size() > 0)
1324 ds.addAll(vForecastedData);*/
1328 // Utils._assert(chr.size()==ds.getColumnCount(),
1329 // "[ReportRuntime.loadLinearReportData] The number of visible columns
1330 // does not match the number of data columns");
1331 //TODO: This should be optimized to accept -1 for flat file download
1332 for (int r = 0; r < Math.min(ds.getRowCount(), ((pageNo < 0) ? (downloadLimit == -1?Globals.getFlatFileUpperLimit():Globals.getDownloadLimit() ) : getPageSize())); r++) {
1333 DataRow dr = new DataRow();
1334 rd.reportDataRows.addDataRow(dr);
1336 for (int c = 0; c < reportCols.size(); c++) {
1337 if(reportCols.get(c)!=null) {
1338 DataColumnType dct = (DataColumnType) reportCols.get(c);
1339 DataValue dv = new DataValue();
1340 dr.addDataValue(dv);
1341 dv.setDisplayValue(ds.getString(r, c));
1342 dv.setColName(dct.getColName());
1343 dv.setColId(dct.getColId());
1344 dv.setNowrap(nvl(dct.getNowrap(),"null").equals("false")?"null":nvl(dct.getNowrap(),"null"));
1345 StringBuffer indentation = new StringBuffer("");
1346 if(dct.getIndentation()!=null && dct.getIndentation()>0) {
1347 for (int indent=0; indent< dct.getIndentation(); indent++) {
1348 indentation.append("\t");
1350 dv.setNowrap("true");
1352 dv.setIndentation(indentation.toString());
1353 if(dct.isVisible()) {
1355 dv.setVisible(true);
1356 dv.setAlignment(dct.getDisplayAlignment());
1357 dv.setDisplayTotal(dct.getDisplayTotal());
1358 dv.setDisplayName(dct.getDisplayName());
1360 if (nvl(dct.getDrillDownURL()).length() > 0) {
1362 if(dv.getDisplayValue().length() > 0) {
1363 dv.setDrillDownURL(parseDrillDownURL(r, /* c, */ds, dct,request, childReportFormFields));
1364 dv.setDrillDowninPoPUp(dct.isDrillinPoPUp()!=null?dct.isDrillinPoPUp():false);
1367 if (dv.getDisplayValue().length() == 0) {
1368 //dv.setDisplayValue("[NULL]");
1369 dv.setDisplayValue("");
1374 dv.setVisible(false);
1377 //System.out.println("in Linear report b4" + dr.getFormatId() + dr.getBgColorHtml() + dv.getDisplayValue());
1379 if(dr.getFormatId()!=null)
1380 ((FormatProcessor) formatProcessors.get(c)).setHtmlFormatters(dv, dr, true);
1382 ((FormatProcessor) formatProcessors.get(c)).setHtmlFormatters(dv, dr, false);
1384 //System.out.println("in Linear report After" + dr.getFormatId() + dr.getBgColorHtml() + dv.getDisplayValue());
1389 //Only if rownumber options is needed
1390 //rd.addRowNumbers(pageNo, getPageSize());
1392 if (colDataTotalsLinear == null) {
1393 if(!download && !action.endsWith("session"))
1394 colDataTotalsLinear = generateColumnDataTotalsLinear(new ArrayList(reportCols), userId,
1395 getDbInfo(),request);
1396 if(download && action.endsWith("session"))
1397 colDataTotalsLinear = generateColumnDataTotalsLinear(new ArrayList(reportCols), userId,
1398 getDbInfo(), getTotalSql());
1400 if (displayColTotals && colDataTotalsLinear != null) {
1401 String totalLabel = "Total";
1402 if (getReportDataSize() > getPageSize())
1403 totalLabel += "<br><font size=1>(for all pages)</font>";
1405 rd.setColumnDataTotalsLinear(colDataTotalsLinear, totalLabel);
1407 // Please note the below function doesn't set the visibility for dv since this is set in this function. - Sundar
1408 rd.applyVisibility();
1411 } // loadLinearReportData
1415 public DataRow generateColumnDataTotalsLinear(ArrayList reportCols, String userId,
1416 String dbInfo, String reportSQL) throws RaptorException {
1419 boolean displayColTotals = false;
1420 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1422 DataColumnType dct = (DataColumnType) iter.next();
1424 if (nvl(dct.getDisplayTotal()).length() > 0) {
1425 displayColTotals = true;
1428 } // if checking dct
1432 if (displayColTotals) {
1435 // DbUtils.executeQuery(generateTotalSQLLinear(reportParamValues,
1437 ds = ConnectionUtils.getDataSet(reportSQL,
1440 for (int c = 0; c < reportCols.size(); c++) {
1441 DataColumnType dct = (DataColumnType) reportCols.get(c);
1442 if ( dct != null ) {
1443 DataValue dv = new DataValue();
1445 String totalValue = "";
1447 totalValue = ds.getString(0, c);
1448 if (nvl(dct.getDisplayTotal()).length() > 0
1449 && (!dct.getDisplayTotal().equals(AppConstants.TOTAL_SUM_ID)))
1450 totalValue = nvl(AppConstants.TOTAL_FUNCTIONS.getNameById(dct
1451 .getDisplayTotal()))
1452 + ": " + totalValue;
1453 dv.setDisplayValue(Utils.truncateTotalDecimals(totalValue));
1455 dv.setAlignment(dct.getDisplayAlignment());
1456 dv.setColName(dct.getColName());
1457 dv.setDisplayName(dct.getDisplayName());
1458 dv.setColId(dct.getColId());
1459 dv.setNowrap(nvl(dct.getNowrap(),"null").equals("false")?"null":nvl(dct.getNowrap(),"null"));
1460 StringBuffer indentation = new StringBuffer("");
1461 if(dct.getIndentation()!=null && dct.getIndentation()>0) {
1462 for (int indent=0; indent< dct.getIndentation(); indent++) {
1463 indentation.append("\t");
1465 dv.setNowrap("true");
1467 dv.setIndentation(indentation.toString());
1468 dv.setDisplayTotal(dct.getDisplayTotal());
1470 dv.setVisible(dct.isVisible());
1472 dr.addDataValue(dv);
1478 } // generateColumnDataTotalsLinear
1481 public ReportData loadHiveLinearReportData(String reportSQL, String userId, int downloadLimit, HttpServletRequest request) throws RaptorException {
1482 wholeSQL = reportSQL;
1483 int countRows = getHiveReportCount(wholeSQL);
1484 setReportDataSize(countRows);
1485 if(countRows < 1001)
1486 wholeSQL += " limit "+ countRows;
1488 wholeSQL += " limit "+ downloadLimit;
1489 HttpSession session = request.getSession();
1493 String dbInfo = getDBInfo();
1495 List reportCols = getAllColumns();
1496 StringBuffer colNames = new StringBuffer();
1497 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1499 DataColumnType dc = (DataColumnType) iter.next();
1500 if (colNames.length() > 0)
1501 colNames.append(", ");
1502 colNames.append(dc.getColId());
1505 ds = ConnectionUtils.getDataSet(wholeSQL, dbInfo);
1507 ReportData rd = new ReportData(0, true);
1509 // Already defined changed for modifying request parameters
1510 //List reportCols = getAllColumns();
1511 Vector visibleCols = new Vector(reportCols.size());
1512 Vector formatProcessors = new Vector(reportCols.size());
1514 // ColumnHeaderRow chr = new ColumnHeaderRow();
1515 // rd.reportColumnHeaderRows.addColumnHeaderRow(chr);
1516 // chr.setRowHeight("30");
1520 ReportFormFields rff = getReportFormFields();
1521 ReportFormFields childReportFormFields = null;
1522 String fieldDisplayName = "";
1523 String fieldValue = "";
1525 for (int c = 0; c < reportCols.size(); c++) {
1526 if(reportCols.get(c)!=null) {
1527 DataColumnType dct = (DataColumnType) reportCols.get(c);
1528 if(nvl(dct.getDependsOnFormField()).length()>0 && nvl(dct.getDependsOnFormField()).indexOf("[")!=-1) {
1529 for(int i = 0 ; i < rff.size(); i++) {
1530 fieldDisplayName = "["+((FormField)rff.getFormField(i)).getFieldDisplayName()+"]";
1532 //if(dct.getOriginalDisplayName()==null) dct.setOriginalDisplayName(dct.getDisplayName());
1533 if (dct.getDependsOnFormField().equals(fieldDisplayName)) {
1534 fieldValue = nvl(request.getParameter(((FormField)rff.getFormField(i)).getFieldName()));
1536 if (fieldValue.length()>0) {
1537 if(!fieldValue.toUpperCase().equals("Y"))
1538 dct.setDisplayName(fieldValue);
1539 if(!dct.isVisible())
1540 dct.setVisible(true);
1542 dct.setVisible(false);
1551 String displayName = "";
1552 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1554 DataColumnType dc = (DataColumnType) iter.next();
1556 formatProcessors.add(count,new FormatProcessor(
1557 getSemaphoreById(dc.getSemaphoreId()), dc.getColType(), dc
1558 .getColFormat(), getReportDefType().equals(
1559 AppConstants.RD_SQL_BASED)));
1561 if (nvl(dc.getDrillDownURL()).length() > 0) {
1562 childReportFormFields = getChildReportFormFields(request,dc.getDrillDownURL());
1564 if (dc.isVisible()) {
1565 visibleCols.add(count,dc);
1566 //if(dc.getColId().startsWith("group")) {
1567 for (int d = 0; d < reportCols.size(); d++) {
1568 if(reportCols.get(d)!=null) {
1569 DataColumnType dct1 = (DataColumnType) reportCols.get(d);
1570 if(dct1.getColId().equals(dc.getColId()+"_name") && ds.getRowCount()>0) {
1571 displayName = ds.getString(0,dct1.getColId());
1572 dc.setDisplayName(displayName);
1578 String widthInPxls = dc.getDisplayWidthInPxls();
1580 if(nvl(widthInPxls).endsWith("px"))
1581 dc.setDisplayWidthInPxls(widthInPxls);
1583 widthInPxls = widthInPxls+"px";
1584 dc.setDisplayWidthInPxls(widthInPxls+"px");
1587 rd.createColumn(dc.getColId(), dc.getDisplayName(), dc.getDisplayWidthInPxls(), dc.getDisplayHeaderAlignment(),
1588 visualManager.isColumnVisible(dc.getColId()), visualManager
1589 .getSortByColId().equals(dc.getColId()) ? visualManager
1590 .getSortByAscDesc() : null, isRuntimeColSortDisabled(), dc.getLevel()!=null?dc.getLevel():0, dc.getStart()!=null?dc.getStart():0, dc.getColspan()!=null?dc.getColspan():0, dc.isIsSortable()!=null?dc.isIsSortable():false);
1591 // chr.addColumnHeader(new ColumnHeader(dc.getDisplayName(),
1592 // (dc.getDisplayWidth()>100)?"10%":(""+dc.getDisplayWidth()+"%")));
1595 visibleCols.add(count,null);
1596 rd.createColumn(dc.getColId(), "", dc.getDisplayWidthInPxls(), dc.getDisplayHeaderAlignment(),
1597 true, null,false, dc.getLevel()!=null?dc.getLevel():0, dc.getStart()!=null?dc.getStart():0, dc.getColspan()!=null?dc.getColspan():0, dc.isIsSortable()!=null?dc.isIsSortable():false);
1598 // formatProcessors.add(count,null);
1603 ArrayList reportDataList = new ArrayList();
1604 for (int r = 0; r < ds.getRowCount(); r++) {
1605 DataRow dr = new DataRow();
1606 rd.reportDataRows.addDataRow(dr);
1608 for (int c = 0; c < reportCols.size(); c++) {
1609 if(reportCols.get(c)!=null) {
1610 DataColumnType dct = (DataColumnType) reportCols.get(c);
1611 DataValue dv = new DataValue();
1612 dr.addDataValue(dv);
1613 dv.setDisplayValue(ds.getString(r, c));
1614 dv.setColName(dct.getColName());
1615 dv.setColId(dct.getColId());
1616 dv.setNowrap(nvl(dct.getNowrap(),"null").equals("false")?"null":nvl(dct.getNowrap(),"null"));
1617 StringBuffer indentation = new StringBuffer("");
1618 if(dct.getIndentation()!=null && dct.getIndentation()>0) {
1619 for (int indent=0; indent< dct.getIndentation(); indent++) {
1620 indentation.append("\t");
1622 dv.setNowrap("true");
1624 dv.setIndentation(indentation.toString());
1625 if(dct.isVisible()) {
1627 dv.setVisible(true);
1628 dv.setAlignment(dct.getDisplayAlignment());
1629 dv.setDisplayTotal(dct.getDisplayTotal());
1630 dv.setDisplayName(dct.getDisplayName());
1632 if (nvl(dct.getDrillDownURL()).length() > 0) {
1634 if(dv.getDisplayValue().length() > 0) {
1635 dv.setDrillDownURL(parseDrillDownURL(r, /* c, */ds, dct,request, childReportFormFields));
1636 dv.setDrillDowninPoPUp(dct.isDrillinPoPUp()!=null?dct.isDrillinPoPUp():false);
1639 if (dv.getDisplayValue().length() == 0) {
1640 //dv.setDisplayValue("[NULL]");
1641 dv.setDisplayValue("");
1646 dv.setVisible(false);
1649 //System.out.println("in Linear report b4" + dr.getFormatId() + dr.getBgColorHtml() + dv.getDisplayValue());
1651 if(dr.getFormatId()!=null)
1652 ((FormatProcessor) formatProcessors.get(c)).setHtmlFormatters(dv, dr, true);
1654 ((FormatProcessor) formatProcessors.get(c)).setHtmlFormatters(dv, dr, false);
1656 //System.out.println("in Linear report After" + dr.getFormatId() + dr.getBgColorHtml() + dv.getDisplayValue());
1659 reportDataList.add(dr);
1661 rd.setReportDataList(reportDataList);
1662 //Only if rownumber options is needed
1663 //rd.addRowNumbers(pageNo, getPageSize());
1665 if (colDataTotalsLinear == null)
1666 colDataTotalsLinear = generateColumnDataTotalsLinear(new ArrayList(reportCols), userId,
1667 getDbInfo(),request);
1668 if (displayColTotals && colDataTotalsLinear != null) {
1669 String totalLabel = "Total";
1670 if (getReportDataSize() > getPageSize())
1671 totalLabel += "<br><font size=1>(for all pages)</font>";
1673 rd.setColumnDataTotalsLinear(colDataTotalsLinear, totalLabel);
1675 // Please note the below function doesn't set the visibility for dv since this is set in this function. - Sundar
1676 rd.applyVisibility();
1679 } // loadHiveLinearReportData
1682 public int getHiveReportCount(String sql) throws RaptorException {
1683 //select t from (select count(*) t from (select * from program)x)x1;
1685 String countSql = "select t from (select count(*) t from ("+ sql + ")" + (Globals.isPostgreSQL() || Globals.isMySQL() ?" AS ":"") + " x) AS x1";
1689 String dbInfo = getDBInfo();
1690 System.out.println("SQL getReportCount()- " + countSql);
1692 ds = ConnectionUtils.getDataSet(countSql, dbInfo);
1695 if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
1697 org.onap.portalsdk.analytics.util.RemDbInfo remDbInfo = new org.onap.portalsdk.analytics.util.RemDbInfo();
1698 dbType = remDbInfo.getDBType(dbInfo);
1699 } catch (Exception ex) {
1700 throw new RaptorException(ex);
1703 if( ds.getRowCount()>0) {
1704 count = Integer.parseInt(ds.getString(0,0));
1706 } catch (NumberFormatException ex) {}
1712 /*private*/ public ReportFormFields getChildReportFormFields( HttpServletRequest request, String URL ) throws RaptorException {
1713 String childReportID = getReportID(URL);
1715 ReportRuntime ddRr = (new ReportHandler()).loadReportRuntime(request, childReportID,
1718 ReportFormFields ddReportFormFields = ddRr.getReportFormFields();
1719 return ddReportFormFields;
1722 private String getReportID(String URL) {
1724 int pos = URL.toLowerCase().indexOf("c_master=")+9;
1725 String reportID = "";
1726 if(URL.toLowerCase().indexOf("&", pos)!=-1)
1727 reportID = URL.substring(pos, URL.toLowerCase().indexOf("&", pos));
1729 reportID = URL.substring(pos);
1733 /*private*/ public String parseDrillDownURL(int rowIdx, /* int colIdx, */DataSet ds, DataColumnType dct, HttpServletRequest request, ReportFormFields ddReportFormFields)
1734 throws RaptorException {
1735 Vector viewActions = DataCache.getDataViewActions();
1736 javax.servlet.http.HttpSession session = request.getSession();
1738 StringBuffer dUrl = new StringBuffer();
1740 //String childReportID = getReportID(dct.getDrillDownURL());
1742 //ReportRuntime ddRr = (new ReportHandler()).loadReportRuntime(request, childReportID,
1745 //ReportFormFields ddReportFormFields = ddRr.getReportFormFields();
1747 boolean isViewAction = false;
1749 String requestParam ="";
1750 for (int k = 0; k < viewActions.size(); k++)
1751 if (dct.getDrillDownURL().equals(
1752 AppUtils.getBaseActionURL() + ((String) viewActions.get(k))))
1753 isViewAction = true;
1755 // Drill-down to record details
1756 String param = nvl(dct.getDrillDownParams()); // i.e.
1757 // "c_master=[bo1.RECID$]"
1758 param = param.substring(AppUtils.getBaseActionParam().length() + 1,
1759 param.length() - 1); // i.e. "bo1.RECID$"
1760 param = param.replace('.', '_'); // i.e. "bo1.RECID$"
1762 dUrl.append(AppUtils.getBaseActionParam());
1763 dUrl.append(java.net.URLEncoder.encode(ds.getString(rowIdx, param.toLowerCase())));
1765 // Drill-down to another report
1766 // Replacing col ids with values
1767 String param = nvl(dct.getDrillDownParams());
1768 while (param.indexOf('[') >= 0) {
1769 int startIdx = param.indexOf('[');
1770 int endIdx = param.indexOf(']');
1771 StringBuffer sb = new StringBuffer();
1772 if(startIdx>endIdx) {
1773 if (endIdx < param.length() - 1)
1774 sb.append(param.substring(endIdx + 1));
1775 param = sb.toString();
1779 sb.append(param.substring(0, startIdx));
1781 if (param.charAt(startIdx + 1) == '!') {
1782 // Parameter is a form field value
1783 String fieldId = param.substring(startIdx + 2, endIdx);
1784 String fieldValue = (String) reportParamValues.get(fieldId);
1786 sb.append(java.net.URLEncoder.encode(nvl(fieldValue)));
1787 //TODO Add a else if condition to check whether the param is from request Param
1788 //TODO make a unique symbol like #
1789 }else if (param.charAt(startIdx + 1) == '#') {
1791 String fieldId = param.substring(startIdx + 2, endIdx);
1792 String fieldValue = request.getParameter(fieldId);
1793 sb.append(java.net.URLEncoder.encode(nvl(fieldValue)));
1796 // Parameter is a column value
1797 String fieldValue = "";
1798 String colValue = null;
1799 String colId = null;
1800 if (param.indexOf('!') < 0 || param.indexOf('!') > endIdx)
1801 colId = param.substring(startIdx + 1, endIdx);
1803 // Need to use NVL(column, form field)
1804 colId = param.substring(startIdx + 1, param.indexOf('!'));
1806 String fieldId = param.substring(param.indexOf('!') + 1, endIdx);
1807 FormField ff = getFormField(fieldId);
1808 if (ff.getFieldType().equals(FormField.FFT_TEXTAREA)) {
1809 fieldValue = reportParamValues.getParamValueforTextAreaDrilldown(fieldId);
1811 fieldValue = (String) reportParamValues.get(fieldId);
1814 DataColumnType column = getColumnById(colId);
1815 String columnName = "";
1816 int groupColumn = 0;
1818 if(column.getColName().startsWith("[")) {
1820 columnName = column.getDisplayName();
1821 for(ddReportFormFields.resetNext(); ddReportFormFields.hasNext(); ) {
1822 FormField ff = ddReportFormFields.getNext();
1823 if(ff.getFieldDisplayName().toLowerCase().equals(columnName.toLowerCase())) {
1825 sb.delete(sb.lastIndexOf("&")+1, sb.length());
1826 sb.append(ff.getFieldName()+"=");
1830 if (groupColumn == 0 || (groupColumn == 1 && groupMatch == 1)) {
1831 String dependsOn = column.getDependsOnFormField();
1832 if(nvl(dependsOn).length()>0)
1833 System.out.println("DependsOn " + dependsOn);
1834 if (column != null) {
1835 // if (column.getColType().equals(AppConstants.CT_DATE))
1836 //if (!nvl(column.getColFormat(), AppConstants.DEFAULT_DATE_FORMAT)
1837 // .equals(AppConstants.DEFAULT_DATE_FORMAT))
1838 // Use extra column instead
1839 //commented out below line usually for Visual
1840 //colId += AppConstants.DD_COL_EXTENSION;
1841 colValue = ds.getString(rowIdx, colId.toLowerCase());
1842 // if SQL-Based and drill-down param is a date, decode
1843 // it to the expected Oracle format **/
1844 if (getReportDefType().equals(AppConstants.RD_SQL_BASED))
1845 if (!getColumnNoParseDateFlag(column))
1846 if (ReportParamDateValueParser.isDateParam(colValue))
1847 colValue = ReportParamDateValueParser
1848 .formatDateParamValue(colValue);
1851 String suppressValues = "|" + nvl(dct.getDrillDownType()) + "|";
1852 if (suppressValues.length() > 2
1853 && suppressValues.indexOf("|" + colValue + "|") >= 0)
1854 // Parameter value is suppressed and not passed to the
1855 // drill-down report
1858 sb.append(java.net.URLEncoder.encode(nvl(colValue, fieldValue)));
1860 sb.delete(sb.lastIndexOf("&")+1, sb.length());
1864 if (endIdx < param.length() - 1)
1865 sb.append(param.substring(endIdx + 1));
1866 param = sb.toString();
1868 if(Globals.getPassRequestParamInDrilldown()) {
1869 if(param.indexOf('#') < 0) {
1870 String[] reqParameters = Globals.getRequestParams().split(",");
1871 String[] sessionParameters = Globals.getSessionParams().split(",");
1872 for (int i = 0; i < reqParameters.length; i++) {
1873 if(request.getParameter(reqParameters[i])!=null) {
1874 if(!reqParameters[i].toUpperCase().startsWith("FF")){
1875 if(param.length()>0) {
1876 param += "&" + reqParameters[i]+"="
1877 + request.getParameter(reqParameters[i]);
1879 param += "&" + reqParameters[i]+"="
1880 + request.getParameter(reqParameters[i]);
1886 for (int i = 0; i < sessionParameters.length; i++) {
1887 if(session.getAttribute(sessionParameters[i].toUpperCase())!=null) {
1888 if(!sessionParameters[i].toUpperCase().startsWith("FF")){
1889 if(param.length()>0) {
1890 param += "&" + sessionParameters[i].toUpperCase()+"="
1891 + (String)session.getAttribute(sessionParameters[i].toUpperCase());
1893 param += "&" + sessionParameters[i].toUpperCase()+"="
1894 + (String)session.getAttribute(sessionParameters[i].toUpperCase());
1899 param += "&" + sessionParameters[i].toUpperCase()+"="
1900 + (String)session.getAttribute(sessionParameters[i]);
1908 dUrl.append(param.toString());
1910 dUrl.append(AppConstants.RI_DISPLAY_CONTENT);
1913 if(dct.isDrillinPoPUp()==null || (!dct.isDrillinPoPUp().booleanValue())) {
1914 dUrl.append(AppConstants.RI_SHOW_BACK_BTN);
1918 dUrl.append(AppConstants.DRILLDOWN_INDEX);
1919 int index = Integer.parseInt(nvl(AppUtils.getRequestValue(request, AppConstants.DRILLDOWN_INDEX), "0"));
1921 int form_index = Integer.parseInt(nvl(AppUtils.getRequestValue(request, AppConstants.FORM_DRILLDOWN_INDEX), "0"));
1922 index = index>0 ? --index : 0;
1923 form_index = form_index>0 ? --form_index : 0;*/
1924 request.setAttribute(AppConstants.DRILLDOWN_INDEX, Integer.toString(index));
1925 /*session.setAttribute(AppConstants.DRILLDOWN_INDEX, Integer.toString(index));
1926 request.setAttribute(AppConstants.FORM_DRILLDOWN_INDEX, Integer.toString(form_index));
1927 session.setAttribute(AppConstants.FORM_DRILLDOWN_INDEX, Integer.toString(form_index));*/
1929 dUrl.append("=" + AppUtils.getRequestNvlValue(request, AppConstants.DRILLDOWN_INDEX));
1931 //TODO Add a if condition to check whether the param is request Param
1934 if (dUrl.length() > 0)
1935 dUrl.insert(0, ((dct.getDrillDownURL()).indexOf('&') > 0) ? '&' : '&');
1936 dUrl.insert(0, AppUtils.getDrillActionURL()+dct.getDrillDownURL());
1938 //debugLogger.debug(" [[[[[[[[[[[[[[[[ " + dUrl);
1940 return dUrl.toString();
1941 } // parseDrillDownURL
1943 /** *********************************************************************************** */
1945 public DataRow generateColumnDataTotalsLinear(ArrayList reportCols, String userId,
1946 String dbInfo, HttpServletRequest request) throws RaptorException {
1949 displayColTotals = false;
1950 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1952 DataColumnType dct = (DataColumnType) iter.next();
1954 if (nvl(dct.getDisplayTotal()).length() > 0) {
1955 displayColTotals = true;
1958 } // if checking dct
1962 if (displayColTotals) {
1965 // DbUtils.executeQuery(generateTotalSQLLinear(reportParamValues,
1967 ds = ConnectionUtils.getDataSet(generateTotalSQLLinear(reportParamValues, userId,request),
1970 for (int c = 0; c < reportCols.size(); c++) {
1971 DataColumnType dct = (DataColumnType) reportCols.get(c);
1972 if ( dct != null ) {
1973 DataValue dv = new DataValue();
1975 dr.addDataValue(dv);
1977 String totalValue = "";
1979 totalValue = ds.getString(0, c);
1980 if (nvl(dct.getDisplayTotal()).length() > 0
1981 && (!dct.getDisplayTotal().equals(AppConstants.TOTAL_SUM_ID)))
1982 totalValue = nvl(AppConstants.TOTAL_FUNCTIONS.getNameById(dct
1983 .getDisplayTotal()))
1984 + ": " + totalValue;
1985 dv.setDisplayValue(Utils.truncateTotalDecimals(totalValue));
1987 dv.setAlignment(dct.getDisplayAlignment());
1988 dv.setColName(dct.getColName());
1989 dv.setDisplayName(dct.getDisplayName());
1990 dv.setColId(dct.getColId());
1991 dv.setNowrap(nvl(dct.getNowrap(),"null").equals("false")?"null":nvl(dct.getNowrap(),"null"));
1992 StringBuffer indentation = new StringBuffer("");
1993 if(dct.getIndentation()!=null && dct.getIndentation()>0) {
1994 for (int indent=0; indent< dct.getIndentation(); indent++) {
1995 indentation.append("\t");
1997 dv.setNowrap("true");
1999 dv.setIndentation(indentation.toString());
2000 dv.setDisplayTotal(dct.getDisplayTotal());
2007 } // generateColumnDataTotalsLinear
2009 private Vector generateDataTotalsCrossTab(String rowColPos, String userId, HttpServletRequest request)
2010 throws RaptorException {
2011 String sql = getWholeSQL();
2012 Vector dataTotals = new Vector();
2014 boolean displayTotals = ((rowColPos.length() == 0) || (getCrossTabDisplayTotal(
2015 rowColPos).length() > 0));
2016 if (rowColPos.equals(AppConstants.CV_COLUMN))
2017 displayColTotals = displayTotals;
2018 else if (rowColPos.equals(AppConstants.CV_ROW))
2019 displayRowTotals = displayTotals;
2021 if (displayTotals) {
2023 // DbUtils.executeQuery(generateTotalSQLCrossTab(reportParamValues,
2024 // rowColPos, userId));
2025 String executeSql = generateTotalSQLCrossTab(
2026 sql, rowColPos, userId, request, reportParamValues);
2027 DataSet ds = ConnectionUtils.getDataSet(executeSql, getDbInfo());
2029 for (int i = 0; i < ds.getRowCount(); i++) {
2030 Vector headerValues = new Vector();
2031 String totalValue = null;
2034 for (Iterator iter = getAllColumns().iterator(); iter.hasNext();) {
2035 DataColumnType dct = (DataColumnType) iter.next();
2037 if (rowColPos.length() > 0
2038 && nvl(dct.getCrossTabValue()).equals(rowColPos)) {
2039 DataValue dataValue = new DataValue();
2040 dataValue.setBold(true);
2041 dataValue.setAlignment("center");
2042 dataValue.setDisplayValue(ds.getString(i, cPos++));
2043 headerValues.add(dataValue);
2045 //headerValues.add(ds.getString(i, cPos++));
2047 else if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_VALUE))
2048 totalValue = ds.getString(i, cPos++);
2051 dataTotals.add(new CrossTabTotalValue(headerValues, Utils
2052 .truncateTotalDecimals(totalValue)));
2057 } // generateDataTotalsCrossTab
2059 /** *********************************************************************************** */
2061 public void hideColVisual(String colId) {
2062 visualManager.hideColumn(colId);
2063 if (pageDataCache != null)
2064 pageDataCache.columnVisualShowHide(colId, false);
2067 public void showColVisual(String colId) {
2068 visualManager.showColumn(colId);
2069 if (pageDataCache != null)
2070 pageDataCache.columnVisualShowHide(colId, true);
2073 public void sortColVisual(String colId) {
2074 visualManager.setSortByColumn(colId);
2077 pageDataCache = null;
2081 /** *********************************************************************************** */
2083 public String generateDistinctValuesSQL(DataColumnType dct, String userId, HttpServletRequest request) throws RaptorException {
2084 return super.generateDistinctValuesSQL(reportParamValues, dct, userId, request);
2085 } // generateDistinctValuesSQL
2087 public String getDbInfo() {
2088 return this.cr.getDbInfo();
2091 // private String fixSQL(StringBuffer sql) {
2093 // int pos_f_format = 0;
2094 // int pos_t_format = 0;
2095 // int pos_alias = 0;
2096 // String format = "";
2097 // String alias = null;
2098 // if(sql.indexOf("SELECT", 7)!= -1) {
2099 // pos = sql.indexOf("SELECT", 7);
2100 // if(sql.indexOf("TO_CHAR", pos)!= -1){
2101 // pos = sql.indexOf("TO_CHAR", pos);
2102 // if(sql.indexOf("999",pos)!= -1) {
2103 // pos = sql.indexOf("999",pos);
2104 // pos_f_format = sql.lastIndexOf(", '", pos);
2105 // if(pos_f_format == -1 || (pos - pos_f_format > 10)) {
2106 // pos_f_format = sql.lastIndexOf(",'", pos);
2107 // pos_f_format -= 1;
2109 // pos = pos_f_format;
2110 // if(sql.indexOf("')", pos)!= -1) {
2111 // pos_t_format = sql.indexOf("')", pos);
2112 // //debugLogger.debug("pos_t - " + pos_t_format + " " + pos);
2113 // if(pos_t_format == -1 || (pos_t_format - pos > 20)) {
2114 // pos_t_format = sql.indexOf("' )", pos);
2115 // pos_t_format += 3;
2117 // else if (pos_t_format != -1)
2118 // pos_t_format += 2;
2119 // format = sql.substring(pos_f_format+3, pos_t_format);
2120 // //alias = sql.substring(pos_t_format+3, pos_t_format+6);
2121 // pos_alias = sql.indexOf(" ", pos_t_format);
2122 // alias = sql.substring(pos_alias+1, pos_alias+4);
2127 // if(sql.indexOf(alias)!=-1) {
2128 // pos = sql.indexOf(alias);
2129 // //debugLogger.debug(pos + " " + alias.length()+1 + "\n" + sql);
2130 // sql.delete(pos,pos+4);
2131 // sql.insert(pos, "TO_NUMBER("+alias+", '"+format+"')),'"+ format + "')");
2132 // pos = sql.lastIndexOf("SUM", pos);
2134 // pos = sql.lastIndexOf("AVG", pos);
2135 // else if (pos==-1)
2136 // pos = sql.lastIndexOf("COUNT", pos);
2137 // else if (pos == -1)
2138 // pos = sql.lastIndexOf("STDDEV", pos);
2139 // else if (pos == -1)
2140 // pos = sql.lastIndexOf("VARIANCE", pos);
2141 // sql.insert(pos, "TO_CHAR (");
2146 // //debugLogger.debug("Alias|" + alias + "| Format " + format);
2147 // //debugLogger.debug(sql.toString());
2148 // return sql.toString();
2151 public String parseReportSQL(String sql) throws RaptorException {
2152 StringBuffer parsedSQL = new StringBuffer();
2154 Vector updatedReportCols = new Vector();
2157 int lastParsePos = curSQLParsePos;
2158 String lastToken = null;
2159 logger.debug(EELFLoggerDelegate.debugLogger, ("Flat File parseReportSQL ******* SQL " + sql));
2160 sql = sql.replaceAll("([\\s]*\\() (?!FROM)", "(");
2161 sql = sql.replaceAll("[\\s]*\\)", ")");
2162 //sql = sql.replaceAll("[dD][eE][cC][oO][dD][eE] ", "decode");
2163 //sql = sql.replaceAll("[\\s]*\\(", "(");
2164 //sql = replaceNewLine(sql, "decode ", "decode");
2165 //sql = replaceNewLine(sql, "DECODE ", "decode");
2166 //sql = replaceNewLine(sql, "Decode ", "decode");
2168 String nextToken = getNextSQLParseToken(sql, true);
2169 String dbInfo = getDbInfo();
2170 boolean isCYMBALScript = false;
2171 if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
2173 org.onap.portalsdk.analytics.util.RemDbInfo remDbInfo = new org.onap.portalsdk.analytics.util.RemDbInfo();
2174 String dbType = remDbInfo.getDBType(dbInfo);
2175 if (dbType.equals("DAYTONA") && !(nextToken.toUpperCase().equals("SELECT"))) {
2176 isCYMBALScript = true;
2178 } catch (Exception ex) {
2179 throw new RaptorException(ex);
2182 if ( isCYMBALScript == false ) {
2183 while (nextToken.length() > 0) {
2184 //System.out.println("LastToken " + lastToken + " NextToken " + nextToken);
2187 if (parsedSQL.length() == 0) {
2188 if (nextToken.toUpperCase().equals("SELECT"))
2189 parsedSQL.append("SELECT ");
2191 throw new org.onap.portalsdk.analytics.error.ValidationException(
2192 "The SQL must start with the SELECT keyword.");
2193 } else if (nextToken.toUpperCase().equals("DISTINCT")
2194 && parsedSQL.toString().equals("SELECT ")) {
2195 parsedSQL.append("DISTINCT ");
2196 } else if (nextToken.equals("*")
2197 && (parsedSQL.toString().equals("SELECT ") || parsedSQL.toString().equals(
2198 "SELECT DISTINCT "))) {
2199 throw new org.onap.portalsdk.analytics.error.ValidationException(
2200 "You cannot use \"SELECT *\". Please specify select columns/expressions.");
2201 } else if (nextToken.toUpperCase().equals("FROM")) {
2202 if (lastToken != null) {
2203 updatedReportCols.add(getParseSQLDataColumn(lastToken, null, parsedSQL,
2204 updatedReportCols, false));
2208 parsedSQL.append(" \n");
2209 while (lastParsePos < sql.length()
2210 && Character.isWhitespace(sql.charAt(lastParsePos)))
2212 parsedSQL.append(sql.substring(lastParsePos));
2215 //System.out.println("Next Token " + nextToken);
2216 if (nextToken.charAt(nextToken.length() - 1) == ',') {
2217 // The token ends with ,
2218 nextToken = nextToken.substring(0, nextToken.length() - 1);
2220 if (nextToken.length() == 0) {
2221 if (lastToken != null) {
2222 updatedReportCols.add(getParseSQLDataColumn(lastToken, null,
2223 parsedSQL, updatedReportCols, false));
2225 } // else just comma => ignore it
2227 //System.out.println("Next Token " + nextToken + " is Here" + " Last Token " + lastToken);
2228 if (lastToken != null) {
2229 updatedReportCols.add(getParseSQLDataColumn(lastToken, nextToken,
2230 parsedSQL, updatedReportCols, false));
2233 updatedReportCols.add(getParseSQLDataColumn(nextToken, null,
2234 parsedSQL, updatedReportCols, false));
2237 // The token doesn't end with ,
2238 if (lastToken == null)
2239 lastToken = nextToken;
2241 String token = getNextSQLParseToken(sql, false);
2242 //System.out.println(" ********** " + token + " " + lastToken);
2243 if (!token.toUpperCase().equals("FROM"))
2244 throw new org.onap.portalsdk.analytics.error.ValidationException(
2245 "|FROM keyword or a comma expected after [" + nextToken
2247 //System.out.println("Next Token " + nextToken);
2248 updatedReportCols.add(getParseSQLDataColumn(lastToken, nextToken,
2249 parsedSQL, updatedReportCols, false));
2255 lastParsePos = curSQLParsePos;
2256 nextToken = getNextSQLParseToken(sql, true);
2258 } else { // if CYMBAL Script
2259 nextToken = getNextCYMBALSQLParseToken(sql, true);
2261 Matcher matcher = null;
2262 String extracted = null;
2263 while (nextToken.length() > 0) {
2264 if (lastToken == null) lastToken = nextToken;
2266 if( lastToken.toUpperCase().equals("DO DISPLAY")) {
2267 re = Pattern.compile("each(.*)\\[.(.*?)\\]"); //\\[(.*?)\\]
2268 matcher = re.matcher(nextToken);
2269 if (matcher.find()) {
2270 extracted = matcher.group();
2271 re = Pattern.compile("\\[(.*?)\\]");
2272 matcher = re.matcher(nextToken);
2273 if(matcher.find()) {
2274 extracted = matcher.group();
2275 extracted = extracted.substring(1,extracted.length()-2);
2276 StringTokenizer sToken = new StringTokenizer(extracted);
2277 while(sToken.hasMoreTokens()) {
2278 updatedReportCols.add(getParseSQLDataColumn("", sToken.nextToken(),
2279 new StringBuffer(""), updatedReportCols, true));
2286 lastToken = nextToken;
2287 nextToken = getNextCYMBALSQLParseToken(sql, true);
2291 if (updatedReportCols.size() == 0)
2292 throw new org.onap.portalsdk.analytics.error.ValidationException(
2293 "The SQL statement must have at least one column in the SELECT clause.");
2296 return parsedSQL.toString();
2300 private String getNextCYMBALSQLParseToken(String sql, boolean updateParsePos) {
2301 int braketCount = 0;
2302 boolean isInsideQuote = false;
2303 StringBuffer nextToken = new StringBuffer();
2304 for (int idxNext = curSQLParsePos; idxNext < sql.length(); idxNext++) {
2305 char ch = sql.charAt(idxNext);
2308 nextToken.append(ch);
2312 return nextToken.toString();
2313 } // getNextSQLParseToken
2315 private String getNextSQLParseToken(String sql, boolean updateParsePos) {
2316 int braketCount = 0;
2317 boolean isInsideQuote = false;
2318 StringBuffer nextToken = new StringBuffer();
2319 for (int idxNext = curSQLParsePos; idxNext < sql.length(); idxNext++) {
2320 char ch = sql.charAt(idxNext);
2322 if (Character.isWhitespace(ch) || ch == ',') {
2324 nextToken.append(ch);
2326 if (nextToken.length() == 0)
2328 else if (braketCount == 0 && (!isInsideQuote)) {
2330 curSQLParsePos = idxNext + ((ch == ',') ? 1 : 0);
2332 } else if (ch != ',' && nextToken.charAt(nextToken.length() - 1) != ' ')
2333 nextToken.append(' ');
2335 nextToken.append(ch);
2337 if (ch == '(' || ch == '[')
2339 else if (ch == ')' || ch == ']')
2341 else if (ch == '\''/* ||ch=='\"' */)
2342 isInsideQuote = (!isInsideQuote);
2346 return nextToken.toString();
2347 } // getNextSQLParseToken
2349 private DataColumnType getParseSQLDataColumn(String sqlExpression, String colId,
2350 StringBuffer parsedSQL, Vector updatedReportCols, boolean isCYMBALScript) throws RaptorException {
2351 DataColumnType dct = null;
2353 if (colId != null) {
2354 if (!isParseSQLColID(colId))
2355 throw new org.onap.portalsdk.analytics.error.ValidationException(
2358 + "] must either be a valid column id consisting only of letters, numbers, and underscores, or there must be a comma in front of it.");
2360 dct = getColumnById(colId);
2362 // Getting unique column id
2365 for (int i = 0; (i < sqlExpression.length()) && (colIdN < 2); i++)
2366 if (Character.isLetter(sqlExpression.charAt(i))) {
2367 colId += sqlExpression.toLowerCase().charAt(i);
2371 colIdN = getAllColumns().size() + updatedReportCols.size();
2372 for (boolean idAlreadyUsed = true; idAlreadyUsed; colIdN++) {
2373 String newColId = colId + colIdN;
2374 idAlreadyUsed = false;
2376 for (Iterator iter = getAllColumns().iterator(); iter.hasNext();)
2377 if (newColId.equals(((DataColumnType) iter.next()).getColId())) {
2378 idAlreadyUsed = true;
2383 for (Iterator iter = updatedReportCols.iterator(); iter.hasNext();)
2384 if (newColId.equals(((DataColumnType) iter.next()).getColId())) {
2385 idAlreadyUsed = true;
2390 colId += (colIdN - 1);
2394 dct = (new ObjectFactory()).createDataColumnType();
2395 dct.setColId(colId);
2396 dct.setDisplayWidth(10);
2397 dct.setDisplayAlignment("Left");
2398 dct.setVisible(true);
2399 dct.setGroupBreak(false); // ???
2401 boolean isValidIdentifier = Character.isLetterOrDigit(sqlExpression.charAt(0));
2402 for (int i = 0; i < sqlExpression.length(); i++)
2403 if (!(Character.isLetterOrDigit(sqlExpression.charAt(i))
2404 || (sqlExpression.charAt(i) == '_') || (sqlExpression.charAt(i) == '$'))) {
2405 isValidIdentifier = false;
2409 if (isValidIdentifier) {
2410 dct.setDisplayName(sqlExpression);
2412 dct.setDisplayName(colId);
2416 sqlExpression = sqlExpression.replaceAll(", '", ",'");
2417 dct.setDbColName(sqlExpression);
2418 dct.setColName(sqlExpression);
2419 dct.setCalculated(true);
2420 dct.setColType(AppConstants.CT_CHAR);
2421 dct.setDbColType(AppConstants.CT_CHAR);
2422 adjustColumnType(dct); // ???
2424 if(!isCYMBALScript) {
2425 if (parsedSQL.toString().equals("SELECT ")
2426 || parsedSQL.toString().equals("SELECT DISTINCT "))
2427 parsedSQL.append("\n\t");
2429 parsedSQL.append(", \n\t");
2430 parsedSQL.append(sqlExpression);
2431 parsedSQL.append(" ");
2432 parsedSQL.append(colId);
2436 } // getParseSQLDataColumn
2438 private boolean isParseSQLColID(String token) {
2439 if (nvl(token).length() == 0)
2442 for (int i = 0; i < token.length(); i++) {
2443 char ch = token.charAt(i);
2445 if (i == 0 && ch == '_')
2448 if (!(Character.isLetterOrDigit(ch) || ch == '_'))
2453 } // isParseSQLColID
2455 /*private*/ public String parseReportSQLForDrillDownParams(String reportSQL, DataColumnType dataColumnRequest, HttpServletRequest request){
2456 String param = nvl(dataColumnRequest.getDrillDownParams());
2457 String sql = reportSQL;
2459 while (param.indexOf('[', pos) >= 0) {
2460 int startIdx = param.indexOf('[',pos);
2461 int endIdx = param.indexOf(']',startIdx+1);
2463 StringBuffer sb = new StringBuffer();
2465 sb.append(param.substring(0, startIdx));
2468 if (param.charAt(startIdx + 1) == '#') {
2469 // Parameter is a form field value
2470 String fieldId = param.substring(startIdx + 2, endIdx);
2471 String fieldValue = ESAPI.encoder().encodeForSQL( SecurityCodecUtil.getCodec(), request.getParameter(fieldId));
2472 sql = Utils.replaceInString(sql, "[" + fieldId.toUpperCase()+"]", fieldValue );
2478 public List getMapMarkers(ReportData rd, org.onap.portalsdk.analytics.xmlobj.ReportMap xmlmap){
2480 ArrayList markers = new ArrayList();
2482 HashMap colHash = new HashMap();
2484 for(rd.reportDataRows.resetNext(); rd.reportDataRows.hasNext(); rNum++) {
2485 DataRow dr = rd.reportDataRows.getNext();
2486 for(dr.resetNext(); dr.hasNext(); ) {
2487 DataValue dv = dr.getNext();
2488 colHash.put(dv.getColId(), dv.getDisplayValueLinkHtml());
2491 for (int i = 0; i < xmlmap.getMarkers().size(); i ++){
2492 Marker marker = new Marker("", "", "");
2493 org.onap.portalsdk.analytics.xmlobj.Marker m = (org.onap.portalsdk.analytics.xmlobj.Marker) xmlmap.getMarkers().get(i);
2494 String address = (String) colHash.get(m.getAddressColumn());
2495 String data = (String) colHash.get(m.getDataColumn());
2496 marker.setAddress(address);
2497 if (xmlmap.getAddAddressInDataYN() != null && xmlmap.getAddAddressInDataYN().equals("Y")){
2498 marker.setData(address + "<br/>" + data);
2501 marker.setData(data);
2503 marker.setColor(m.getMarkerColor());
2504 markers.add(marker);
2505 System.out.println("%%%%%%%%%%%% marker is : " + address + data);
2515 public ReportParamValues getReportParamValues() {
2516 return reportParamValues;
2519 public String getFormFieldFilled(String title) {
2520 if( getFormFieldList()!=null && reportParamValues!=null && nvl(title).length()>0) {
2521 for (Iterator iter1 = getFormFieldList().getFormField().iterator(); iter1.hasNext();) {
2522 FormFieldType fft = (FormFieldType) iter1.next();
2523 String fieldDisplay = getFormFieldDisplayName(fft);
2524 String fieldId = fft.getFieldId();
2525 if(!fft.getFieldType().equals(FormField.FFT_BLANK) && !fft.getFieldType().equals(FormField.FFT_LIST_MULTI) && !fft.getFieldType().equals(FormField.FFT_TEXTAREA)) {
2526 String paramValue = Utils.oracleSafe(nvl(reportParamValues.getParamValue(fieldId)));
2527 title = Utils.replaceInString(title, fieldDisplay, nvl(
2535 public synchronized Object clone() {
2537 return super.clone();
2538 } catch (CloneNotSupportedException e) {
2539 // this shouldn't happen, since we are Cloneable
2540 throw new InternalError("Cloning throws error.");
2544 public VisualManager getVisualManager() {
2545 return visualManager;
2548 public String getReportSQLWithRowNum(String _orderBy, boolean asc) {
2549 String sql = getWholeSQL();
2550 int closeBracketPos = 0;
2551 // Added reportSQLOnlyFirstPart which has Column information with Rownum
2552 return nvl(getReportSQLOnlyFirstPart()) + " " + sql + ") x ";
2556 public int getDisplayMode() {
2557 return DISPLAY_MODE;
2560 public void setDisplayMode(int mode) {
2561 DISPLAY_MODE = mode;
2564 public int getDateOption() {
2568 public void setDateOption(int dateOption) {
2569 DATE_OPTION = dateOption;
2572 public boolean isDisplayColTotals() {
2573 return displayColTotals;
2576 public void setDisplayColTotals(boolean displayColTotals) {
2577 this.displayColTotals = displayColTotals;
2580 public boolean isDisplayRowTotals() {
2581 return displayRowTotals;
2584 public void setDisplayRowTotals(boolean displayRowTotals) {
2585 this.displayRowTotals = displayRowTotals;
2589 private boolean canPersistLinearReport() {
2590 boolean visibleColExist = false;
2592 if (getDataSourceList().getDataSource().size() > 0) {
2593 for (Iterator iter = getAllColumns().iterator(); iter.hasNext();) {
2594 DataColumnType dct = (DataColumnType) iter.next();
2596 if (dct.isVisible()) {
2597 visibleColExist = true;
2603 return visibleColExist;
2604 } // canPersistLinearReport
2606 public void persistLinearReport(HttpServletRequest request)
2607 throws RaptorException {
2608 if (!canPersistLinearReport())
2611 Connection connection = null;
2613 String userID = AppUtils.getUserID(request);
2614 String reportXML = marshal();
2615 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] Report " + reportID
2616 + " XML marshalled succesfully"));
2619 verifySQLBasedReportAccess(request);
2620 reportSecurity.reportUpdate(request);
2621 connection = DbUtils.startTransaction();
2622 ReportLoader.updateCustomReportRec(connection, this, reportXML);
2623 ReportLoader.createReportLogEntry(connection, reportID, userID,
2624 AppConstants.RLA_UPDATE, "", "");
2625 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] DB update report "
2626 + reportID + " succesfull"));
2627 DbUtils.commitTransaction(connection);
2628 } catch (RaptorException e) {
2629 e.printStackTrace();
2630 DbUtils.rollbackTransaction(connection);
2633 DbUtils.clearConnection(connection);
2635 } // persistLinearReport
2637 public void persistDashboardReport(HttpServletRequest request)
2638 throws RaptorException {
2640 Connection connection = null;
2642 String userID = AppUtils.getUserID(request);
2643 String reportXML = marshal();
2644 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] Report " + reportID
2645 + " XML marshalled succesfully"));
2648 verifySQLBasedReportAccess(request);
2649 reportSecurity.reportUpdate(request);
2650 connection = DbUtils.startTransaction();
2651 ReportLoader.updateCustomReportRec(connection, this, reportXML);
2652 ReportLoader.createReportLogEntry(connection, reportID, userID,
2653 AppConstants.RLA_UPDATE, "", "");
2654 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] DB update report "
2655 + reportID + " succesfull"));
2656 DbUtils.commitTransaction(connection);
2657 } catch (RaptorException e) {
2658 e.printStackTrace();
2659 DbUtils.rollbackTransaction(connection);
2662 DbUtils.clearConnection(connection);
2664 } // persistDashboardReport
2665 public String getTotalSql() {
2669 public void setTotalSql(String totalSql) {
2670 this.totalSql = totalSql;
2673 public void setTriggerFormFieldCheck( ReportFormFields FormFieldList, FormField selectedFormField) {
2675 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
2676 FormField ff = (FormField) iter.next();
2677 if(!ff.getFieldName().equals(selectedFormField.getFieldName())) {
2678 if(nvl(ff.getBaseSQL()).length()>0 && ff.getBaseSQL().indexOf("["+selectedFormField.getFieldDisplayName() +"]")!= -1) {
2679 selectedFormField.setTriggerOtherFormFields(true);
2687 public void setTriggerThisFormFieldCheck( ReportFormFields FormFieldList, FormField selectedFormField) {
2689 String sql = nvl(selectedFormField.getBaseSQL()).length()>0 ? selectedFormField.getBaseSQL():"";
2690 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
2691 FormField ff = (FormField) iter.next();
2692 if(!ff.getFieldName().equals(selectedFormField.getFieldName())) {
2693 if(sql.indexOf("["+ff.getFieldDisplayName() +"]")!= -1) {
2694 selectedFormField.setTriggerThisFormfield(true);
2703 private boolean isAllowEdit(HttpServletRequest request) {
2704 boolean allowEdit = false;
2705 String userId = AppUtils.getUserID(request);
2707 if( AppUtils.isAdminUser(request) || AppUtils.isSuperUser(request) ) {
2710 if(getOwnerID().equals(userId)) allowEdit = true;
2711 else allowEdit = false;
2713 } catch (RaptorException ex) {
2718 public ReportJSONRuntime createReportJSONRuntime(HttpServletRequest request, ReportData rd) {
2719 String userId = AppUtils.getUserID(request);
2720 ObjectMapper mapper = new ObjectMapper();
2721 ReportJSONRuntime reportJSONRuntime = new ReportJSONRuntime();
2722 reportJSONRuntime.setReportTitle(getReportTitle());
2723 //reportJSONRuntime.setReportSubTitle(getReportSubTitle());
2724 reportJSONRuntime.setReportID(getReportID());
2725 reportJSONRuntime.setReportDescr(getReportDescr());
2726 reportJSONRuntime.setReportName(getReportName());
2727 reportJSONRuntime.setReportSubTitle(getReportSubTitle());
2728 reportJSONRuntime.setAllowSchedule(isAllowSchedule());
2729 reportJSONRuntime.setAllowEdit(isAllowEdit(request));
2730 reportJSONRuntime.setColIdxTobeFreezed(getFrozenColumnId());
2731 reportJSONRuntime.setNumFormCols(getNumFormColsAsInt());
2733 reportJSONRuntime.setBackBtnURL("");
2734 String chartType = getChartType();
2735 boolean displayChart = (nvl(chartType).length()>0)&&getDisplayChart();
2736 boolean displayChartWizard = getDisplayChart();
2737 reportJSONRuntime.setChartAvailable(displayChart);
2738 reportJSONRuntime.setChartWizardAvailable(displayChartWizard);
2739 reportJSONRuntime.setDisplayData(!isDisplayOptionHideData());
2740 reportJSONRuntime.setDisplayForm(!isDisplayOptionHideForm());
2741 reportJSONRuntime.setHideFormFieldsAfterRun(isHideFormFieldAfterRun());
2742 reportJSONRuntime.setDisplayExcel(!isDisplayOptionHideExcelIcons());
2743 reportJSONRuntime.setDisplayPDF(!isDisplayOptionHidePDFIcons());
2744 ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
2745 ArrayList<FormFieldJSON> formFieldJSONList = new ArrayList<FormFieldJSON>();
2746 if(getReportFormFields()!=null) {
2747 formFieldJSONList = new ArrayList<FormFieldJSON>(getReportFormFields().size());
2748 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
2749 formFieldValues = new ArrayList<IdNameValue>();
2750 FormField ff = (FormField) iter.next();
2751 ff.setDbInfo(getDbInfo());
2752 FormFieldJSON ffJSON = new FormFieldJSON();
2753 ffJSON.setFieldId(ff.getFieldName());
2754 ffJSON.setFieldType(ff.getFieldType());
2755 ffJSON.setFieldDisplayName(ff.getFieldDisplayName());
2756 ffJSON.setHelpText(ff.getHelpText());
2757 ffJSON.setValidationType(ff.getValidationType());
2758 ffJSON.setVisible(ff.isVisible());
2759 //ffJSON.setTriggerOtherFormFields(ff.getDependsOn());
2760 IdNameList lookup = null;
2761 lookup = ff.getLookupList();
2762 String selectedValue = "";
2764 IdNameList lookupList = null;
2765 boolean readOnly = false;
2767 if(!ff.hasPredefinedList) {
2768 IdNameSql lu = (IdNameSql) lookup;
2769 String SQL = lu.getSql();
2770 oldSQL = lu.getSql();
2771 setTriggerFormFieldCheck( getReportFormFields(), ff);
2772 ffJSON.setTriggerOtherFormFields(ff.isTriggerOtherFormFields());
2773 SQL = parseAndFillReq_Session_UserValues(request, SQL, userId);
2774 SQL = parseAndFillWithCurrentValues(request, SQL, ff);
2775 String defaultSQL = lu.getDefaultSQL();
2776 defaultSQL = parseAndFillReq_Session_UserValues(request, defaultSQL, userId);
2777 defaultSQL = parseAndFillWithCurrentValues(request, defaultSQL, ff);
2778 lookup = new IdNameSql(-1,SQL,defaultSQL);
2780 lookupList = lookup;
2782 lookup.loadUserData(0, "", ff.getDbInfo(), ff.getUserId());
2783 } catch (Exception e ){ e.printStackTrace(); //throw new RaptorRuntimeException(e);
2786 lookup.trimToSize();
2788 String[] requestValue = request.getParameterValues(ff.getFieldName());
2790 if(lookup != null && lookup.size() > 0) {
2791 for (lookup.resetNext(); lookup.hasNext();) {
2792 IdNameValue value = lookup.getNext();
2793 readOnly = value.isReadOnly();
2794 if(requestValue != null && Arrays.asList(requestValue).contains(value.getId())) {
2795 //if(value.getId().equals(requestValue))
2796 value.setDefaultValue(true);
2797 } else if (AppUtils.nvl(ff.getDefaultValue()).length()>0) {
2798 if(ff.getDefaultValue().equals(value.getId())) {
2799 value.setDefaultValue(true);
2802 if(!(ff.getFieldType().equals(FormField.FFT_CHECK_BOX) || ff.getFieldType().equals(FormField.FFT_COMBO_BOX) || ff.getFieldType().equals(FormField.FFT_LIST_BOX)
2803 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI)) && value.isDefaultValue())
2804 formFieldValues.add(value);
2805 else if(ff.getFieldType().equals(FormField.FFT_CHECK_BOX) || ff.getFieldType().equals(FormField.FFT_COMBO_BOX) || ff.getFieldType().equals(FormField.FFT_LIST_BOX)
2806 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI)) {
2807 formFieldValues.add(value);
2812 if(requestValue!=null && requestValue.length>0) {
2813 IdNameValue value = new IdNameValue(requestValue[0], requestValue[0], true, false);
2814 formFieldValues.add(value);
2819 setTriggerFormFieldCheck( getReportFormFields(), ff);
2820 ffJSON.setTriggerOtherFormFields(ff.isTriggerOtherFormFields());
2821 String[] requestValue = request.getParameterValues(ff.getFieldName());
2822 if(requestValue!=null && requestValue.length>0) {
2823 IdNameValue value = new IdNameValue(requestValue[0], requestValue[0], true, false);
2824 formFieldValues.add(value);
2825 } else if (AppUtils.nvl(ff.getDefaultValue()).length()>0) {
2826 IdNameValue value = new IdNameValue(ff.getDefaultValue(), ff.getDefaultValue(), true, false);
2827 formFieldValues.add(value);
2830 if(!ff.hasPredefinedList) {
2831 if(oldSQL != null && !oldSQL.equals("") && lookup!=null) {
2832 ((IdNameSql)lookup).setSQL(oldSQL);
2838 ffJSON.setFormFieldValues(formFieldValues);
2839 formFieldJSONList.add(ffJSON);
2842 reportJSONRuntime.setFormFieldList(formFieldJSONList);
2843 //reportJSONRuntime.setReportDataColumns(get);
2845 Map<String,Object> dvJSON = null;
2848 reportJSONRuntime.setTotalRows(getReportDataSize());
2849 ArrayList<ColumnHeader> colList = new ArrayList<ColumnHeader>();
2850 ArrayList<Map<String,Object>> reportDataRows = new ArrayList<Map<String,Object>>();
2851 for(rd.reportColumnHeaderRows.resetNext(); rd.reportColumnHeaderRows.hasNext(); ) {
2853 ColumnHeaderRow chr = rd.reportColumnHeaderRows.getNext();
2854 for(chr.resetNext(); chr.hasNext(); ) {
2855 colList.add(chr.getNext());
2858 if(getReportDataSize() > 0) {
2860 for(rd.reportDataRows.resetNext(); rd.reportDataRows.hasNext(); count++) {
2861 dvJSON = new HashMap<String,Object>();
2862 DataRow dr = rd.reportDataRows.getNext();
2863 for(dr.resetNext(); dr.hasNext(); ) {
2864 DataValue dv = dr.getNext();
2866 dvJSON.put(dv.getColId(), dv);
2867 } catch (Exception ex) {
2868 ex.printStackTrace();
2872 reportDataRows.add(dvJSON);
2875 reportJSONRuntime.setReportDataColumns(colList);
2876 reportJSONRuntime.setReportDataRows(reportDataRows);
2877 //reportJSONRuntime.setSqlWhole(getWholeSQL());
2878 reportJSONRuntime.setPageSize(getPageSize());
2882 if(getReportDataSize() <= 0) {
2883 reportJSONRuntime.setMessage(getEmptyMessage());
2885 reportJSONRuntime.setSqlWhole(getWholeSQL());
2886 return reportJSONRuntime;
2890 public ReportJSONRuntime createFormFieldJSONRuntime(HttpServletRequest request) {
2891 String userId = AppUtils.getUserID(request);
2892 ObjectMapper mapper = new ObjectMapper();
2893 ReportJSONRuntime reportJSONRuntime = new ReportJSONRuntime();
2894 reportJSONRuntime.setReportTitle(getReportTitle());
2895 reportJSONRuntime.setReportID(getReportID());
2896 reportJSONRuntime.setReportName(getReportName());
2897 reportJSONRuntime.setReportSubTitle(getReportSubTitle());
2898 reportJSONRuntime.setAllowEdit(isAllowEdit(request));
2899 reportJSONRuntime.setNumFormCols(getNumFormColsAsInt());
2900 ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
2901 ArrayList<FormFieldJSON> formFieldJSONList = new ArrayList<FormFieldJSON>();
2902 if(reportFormFields!=null) {
2903 formFieldJSONList = new ArrayList<FormFieldJSON>(reportFormFields.size());
2904 for (Iterator iter = reportFormFields.iterator(); iter.hasNext();) {
2905 formFieldValues = new ArrayList<IdNameValue>();
2906 FormField ff = (FormField) iter.next();
2907 FormFieldJSON ffJSON = new FormFieldJSON();
2908 ffJSON.setFieldId(ff.getFieldName());
2909 ffJSON.setFieldType(ff.getFieldType());
2910 ffJSON.setFieldDisplayName(ff.getFieldDisplayName());
2911 ffJSON.setHelpText(ff.getHelpText());
2912 ffJSON.setValidationType(ff.getValidationType());
2913 ffJSON.setFormFieldValues(formFieldValues);
2914 ffJSON.setVisible(ff.isVisible());
2915 formFieldJSONList.add(ffJSON);
2917 for (Iterator iter = reportFormFields.iterator(); iter.hasNext();) {
2918 formFieldValues = new ArrayList<IdNameValue>();
2919 FormField ff = (FormField) iter.next();
2920 ff.setDbInfo(getDbInfo());
2921 for (Iterator iter1 = formFieldJSONList.iterator(); iter1.hasNext();) {
2922 FormFieldJSON ffJSON = (FormFieldJSON) iter1.next();
2923 if(ffJSON.getFieldId().equals(ff.getFieldName())) {
2924 IdNameList lookup = null;
2925 lookup = ff.getLookupList();
2926 String selectedValue = "";
2928 IdNameList lookupList = null;
2929 boolean readOnly = false;
2931 if(!ff.hasPredefinedList) {
2932 IdNameSql lu = (IdNameSql) lookup;
2933 String SQL = lu.getSql();
2934 oldSQL = lu.getSql();
2935 setTriggerFormFieldCheck( getReportFormFields(), ff);
2936 ffJSON.setTriggerOtherFormFields(ff.isTriggerOtherFormFields());
2937 setTriggerThisFormFieldCheck(getReportFormFields(), ff);
2938 SQL = parseAndFillReq_Session_UserValues(request, SQL, userId);
2939 SQL = parseAndFillOtherFormfieldValues(request, SQL, userId, formFieldJSONList);
2940 //SQL = parseAndFillWithCurrentValues(formGrid,SQL, ff);
2941 String defaultSQL = lu.getDefaultSQL();
2942 defaultSQL = parseAndFillReq_Session_UserValues(request, defaultSQL, userId);
2943 //defaultSQL = parseAndFillWithCurrentValues(formGrid,defaultSQL, ff);
2944 lookup = new IdNameSql(-1,SQL,defaultSQL);
2946 lookupList = lookup;
2948 lookup.loadUserData(0, "", ff.getDbInfo(), ff.getUserId());
2949 } catch (Exception e ){ e.printStackTrace(); //throw new RaptorRuntimeException(e);
2952 lookup.trimToSize();
2954 String requestValue = request.getParameter(ff.getFieldName());
2955 ArrayList<String> requestValueList = new ArrayList<String>();
2956 requestValueList.add(requestValue);
2958 /*if(ff.isTriggerThisFormfield()) {
2959 refreshFormFieldsWithLatestValue(request, userId, ff, formFieldJSONList);
2963 for (lookup.resetNext(); lookup.hasNext();) {
2964 IdNameValue value = lookup.getNext();
2965 readOnly = value.isReadOnly();
2966 if(nvl(requestValue).length()>0) {
2967 if(value.getId().equals(requestValue))
2968 value.setDefaultValue(true);
2970 formFieldValues.add(value);
2975 setTriggerFormFieldCheck( getReportFormFields(), ff);
2976 ffJSON.setTriggerOtherFormFields(ff.isTriggerOtherFormFields());
2977 String[] requestValue = request.getParameterValues(ff.getFieldName());
2978 if(requestValue!=null && requestValue.length>0) {
2979 IdNameValue value = new IdNameValue(requestValue[0], requestValue[0], true, false);
2980 formFieldValues.add(value);
2981 } else if (AppUtils.nvl(ff.getDefaultValue()).length()>0) {
2982 IdNameValue value = new IdNameValue(ff.getDefaultValue(), ff.getDefaultValue(), true, false);
2983 formFieldValues.add(value);
2986 if(!ff.hasPredefinedList) {
2987 if(oldSQL != null && !oldSQL.equals("") && lookup!=null) {
2988 ((IdNameSql)lookup).setSQL(oldSQL);
2993 //if(!ff.isTriggerThisFormfield()) {
2994 ffJSON.setFormFieldValues(formFieldValues);
3004 reportJSONRuntime.setFormFieldList(formFieldJSONList);
3005 //reportJSONRuntime.setReportDataColumns(get);
3007 return reportJSONRuntime;
3012 private String parseAndFillOtherFormfieldValues(HttpServletRequest request, String SQL, String userId, ArrayList<FormFieldJSON> formFieldJSONList) {
3013 ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
3014 String selectedValue = "";
3015 String displayName = "";
3016 for (Iterator iter1 = formFieldJSONList.iterator(); iter1.hasNext();) {
3017 FormFieldJSON ffJSON = (FormFieldJSON) iter1.next();
3018 displayName = ffJSON.getFieldDisplayName();
3019 ArrayList<IdNameValue> formfieldvalues = ffJSON.getFormFieldValues();
3020 for (int i = 0; i< formfieldvalues.size(); i++) {
3021 IdNameValue formfieldItem = formfieldvalues.get(i);
3022 if(formfieldItem.isDefaultValue()) {
3023 selectedValue = formfieldItem.getId();
3026 SQL = Utils.replaceInString(SQL, "["+displayName+"]", selectedValue);
3032 // private void refreshFormFieldsWithLatestValue(HttpServletRequest request, String userId, FormField ff_src, ArrayList<FormFieldJSON> formFieldJSONList) {
3033 // ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
3034 // List<String> requestValueList = null;
3035 // IdNameList lookup = null;
3036 // lookup = ff_src.getLookupList();
3037 // IdNameSql lu = (IdNameSql) lookup;
3038 // String SQL = "" ;
3039 // String oldSQL = "";
3040 // String oldDefaultSQL = "";
3041 // String defaultSQL = "";
3042 // IdNameList lookupList = null;
3044 // SQL = lu.getSql();
3045 // oldSQL = lu.getSql();
3046 // oldDefaultSQL = lu.getDefaultSQL();
3047 // defaultSQL = lu.getDefaultSQL();
3049 // boolean readOnly = false;
3050 // for (Iterator iter1 = formFieldJSONList.iterator(); iter1.hasNext();) {
3051 // FormFieldJSON ffJSON = (FormFieldJSON) iter1.next();
3052 // if((ffJSON.getFieldId().equals(ff_src.getFieldName())) && ffJSON.isVisible()) {
3053 // for (Iterator iter = reportFormFields.iterator(); iter.hasNext();) {
3054 // formFieldValues = new ArrayList<IdNameValue>();
3055 // FormField ff = (FormField) iter.next();
3056 // if(!ff.getFieldName().equals(ff_src.getFieldName())) {
3057 // //IdNameList lookup = null;
3058 // //lookup = ff.getLookupList();
3059 // String selectedValue = "";
3063 // String [] requestParam = request.getParameterValues(ff.getFieldName());
3064 // if(requestParam != null) {
3065 // requestValueList = Arrays.asList(request.getParameterValues(ff.getFieldName()));
3068 // requestValueList = new ArrayList<String>();
3072 // if(nvl(ff_src.getBaseSQL()).length()>0 && ff_src.getBaseSQL().indexOf("["+ff.getFieldDisplayName() +"]")!= -1) {
3073 // if(lookup!=null) {
3075 // if(!ff_src.hasPredefinedList) {
3076 // String formatSelected = null;
3077 // if(ff_src.getFieldType().equals(FormField.FFT_LIST_MULTI) || ff_src.getFieldType().equals(FormField.FFT_CHECK_BOX)) {
3078 // formatSelected = formatSelectedItems(requestValueList, ff_src.getFieldType());
3080 // formatSelected = requestValueList.size()>0?requestValueList.get(0):"";
3081 // SQL = Utils.replaceInString(SQL, "["+ff_src.getFieldDisplayName()+"]", formatSelected);
3082 // defaultSQL = Utils.replaceInString(defaultSQL, "["+ff_src.getFieldDisplayName()+"]", formatSelected);
3083 // defaultSQL = parseAndFillWithCurrentValues(request, defaultSQL, ff_src);
3084 // defaultSQL = parseAndFillReq_Session_UserValues(request, defaultSQL, userId);
3085 // SQL = parseAndFillReq_Session_UserValues(request, SQL, userId);
3086 // SQL = parseAndFillWithCurrentValues(request, SQL, ff_src);
3089 // } catch (Exception ex) {
3090 // ex.printStackTrace();
3099 // if(nvl(ff_src.getBaseSQL()).length()>0) {
3100 // lookup = new IdNameSql(-1,SQL,defaultSQL);
3101 // lookupList = lookup;
3103 // lookup.loadUserData(0, "", ff_src.getDbInfo(), ff_src.getUserId());
3104 // } catch (Exception e ){
3105 // e.printStackTrace(); //throw new RaptorRuntimeException(e);
3107 // if(!ff_src.hasPredefinedList) {
3108 // lookup.trimToSize();
3109 // for (lookup.resetNext(); lookup.hasNext();) {
3110 // IdNameValue value = lookup.getNext();
3111 // readOnly = value.isReadOnly();
3112 // formFieldValues.add(value);
3115 // ffJSON.setFormFieldValues(formFieldValues);
3117 // if(!ff_src.hasPredefinedList) {
3118 // if(oldSQL != null && !oldSQL.equals("")) {
3119 // ((IdNameSql)lookup).setSQL(oldSQL);
3121 // if(oldDefaultSQL != null && !oldDefaultSQL.equals("")) {
3122 // ((IdNameSql)lookup).setDefaultSQL(oldDefaultSQL);
3132 // private void triggerOtherFormFieldsWithThisValue(HttpServletRequest request, String userId, FormField ff_src, ArrayList<String> requestValueList, ArrayList<FormFieldJSON> formFieldJSONList) {
3133 // ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
3134 // //ArrayList<FormFieldJSON> formFieldJSONList = new ArrayList<FormFieldJSON>();
3135 // for (Iterator iter = reportFormFields.iterator(); iter.hasNext();) {
3136 // formFieldValues = new ArrayList<IdNameValue>();
3137 // FormField ff = (FormField) iter.next();
3138 // if(!ff_src.getFieldName().equals(ff.getFieldName())) {
3139 // for (Iterator iter1 = formFieldJSONList.iterator(); iter1.hasNext();) {
3140 // FormFieldJSON ffJSON = (FormFieldJSON) iter1.next();
3141 // if(ffJSON.getFieldId().equals(ff.getFieldName()) && ffJSON.isVisible()) {
3142 // if(nvl(ff.getBaseSQL()).length()>0 && ff.getBaseSQL().indexOf("["+ff_src.getFieldDisplayName() +"]")!= -1) {
3143 // IdNameList lookup = null;
3144 // lookup = ff.getLookupList();
3145 // String selectedValue = "";
3146 // String oldSQL = "";
3147 // String oldDefaultSQL = "";
3148 // IdNameList lookupList = null;
3149 // boolean readOnly = false;
3150 // if(lookup!=null) {
3152 // if(!ff.hasPredefinedList) {
3153 // IdNameSql lu = (IdNameSql) lookup;
3154 // String SQL = lu.getSql();
3155 // oldSQL = lu.getSql();
3156 // oldDefaultSQL = lu.getDefaultSQL();
3157 // String defaultSQL = lu.getDefaultSQL();
3158 // String formatSelected = null;
3159 // if(ff_src.getFieldType().equals(FormField.FFT_LIST_MULTI) || ff_src.getFieldType().equals(FormField.FFT_CHECK_BOX)) {
3160 // formatSelected = formatSelectedItems(requestValueList, ff.getFieldType());
3163 // formatSelected = requestValueList.size()>0?requestValueList.get(0):"";
3164 // SQL = Utils.replaceInString(SQL, "["+ff_src.getFieldDisplayName()+"]", formatSelected);
3165 // defaultSQL = Utils.replaceInString(defaultSQL, "["+ff_src.getFieldDisplayName()+"]", formatSelected);
3166 // defaultSQL = parseAndFillWithCurrentValues(request, defaultSQL, ff_src);
3167 // defaultSQL = parseAndFillReq_Session_UserValues(request, defaultSQL, userId);
3168 // SQL = parseAndFillReq_Session_UserValues(request, SQL, userId);
3169 // SQL = parseAndFillWithCurrentValues(request, SQL, ff_src);
3170 // lookup = new IdNameSql(-1,SQL,defaultSQL);
3171 // lookupList = lookup;
3173 // lookup.loadUserData(0, "", ff.getDbInfo(), ff.getUserId());
3174 // } catch (Exception e ){
3175 // e.printStackTrace(); //throw new RaptorRuntimeException(e);
3178 // lookup.trimToSize();
3182 // for (lookup.resetNext(); lookup.hasNext();) {
3183 // IdNameValue value = lookup.getNext();
3184 // readOnly = value.isReadOnly();
3185 //// if(nvl(requestValue).length()>0) {
3186 //// if(value.getId().equals(requestValue))
3187 //// value.setDefaultValue(true);
3189 // formFieldValues.add(value);
3193 // ffJSON.setFormFieldValues(formFieldValues);
3195 // if(!ff.hasPredefinedList) {
3196 // if(oldSQL != null && !oldSQL.equals("")) {
3197 // ((IdNameSql)lookup).setSQL(oldSQL);
3199 // if(oldDefaultSQL != null && !oldDefaultSQL.equals("")) {
3200 // ((IdNameSql)lookup).setDefaultSQL(oldDefaultSQL);
3203 // } catch (Exception ex) {
3204 // ex.printStackTrace();
3216 public String formatSelectedItems(List selectedItems, String type) {
3217 StringBuffer value = new StringBuffer("");
3219 boolean multiple = false;
3220 if(type.equals("LIST_MULTI_SELECT"))
3222 //multiple = (selectedItems.size()>1);
3223 for(Iterator iter = selectedItems.iterator(); iter.hasNext(); ) {
3225 String entry = (String) iter.next();
3226 if(count == 1 && multiple)
3228 //if(type.equals(FormField.FFT_CHECK_BOX))
3229 /*if(type.equals(FormField.FFT_CHECK_BOX))
3230 value.append("'"+Utils.oracleSafe(entry)+"'");
3231 else*/ if (type.equals(FormField.FFT_LIST_MULTI))
3232 value.append("'"+Utils.oracleSafe(entry)+"'");
3233 else if(type.equals(FormField.FFT_LIST_BOX))
3234 value.append(Utils.oracleSafe(entry));
3236 value.append("'"+Utils.oracleSafe(entry)+"'");
3237 if((count < selectedItems.size()) && multiple)
3239 if((count == selectedItems.size()) && multiple)
3243 if(value.length()>0)
3244 return value.toString();
3249 public String parseAndFillWithCurrentValues(HttpServletRequest request, String sql, FormField source_Formfield) {
3251 if (getFormFieldList() != null) {
3252 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
3253 FormFieldType fft = (FormFieldType) iter.next();
3254 String fieldId = fft.getFieldId();
3255 String fieldDisplay = getFormFieldDisplayName(fft);
3256 String formfield_value = "";
3257 List<String> selectedItems = new ArrayList<String>();
3258 //Added so that Combo Box in old RAPTOR definition is translated to List box
3259 if(fft.getFieldType().equals(FormField.FFT_COMBO_BOX)) {
3260 fft.setFieldType(FormField.FFT_LIST_BOX);
3262 if(!fft.getFieldType().equals(FormField.FFT_BLANK)) {
3263 //if(source_Formfield==null || (source_Formfield!=null && !fft.getFieldId().equals(source_Formfield.getFieldName()))) {
3265 // Add param base sql
3266 if(fft.getFieldType().equals(FormField.FFT_LIST_MULTI) || fft.getFieldType().equals(FormField.FFT_CHECK_BOX)) {
3267 if(request.getParameterValues(fieldId)!=null && request.getParameterValues(fieldId).length > 0) {
3269 selectedItems = Arrays.asList(request.getParameterValues(fieldId));
3270 formfield_value = formatSelectedItems(selectedItems, fft.getFieldType());
3272 formfield_value = "";
3274 } else if(fft.getFieldType().equals(FormField.FFT_RADIO_BTN)) {
3275 if(request.getParameter(fieldId)!=null) {
3276 formfield_value = request.getParameter(fieldId);
3278 formfield_value = "";
3280 } else if (fft.getFieldType().equals(FormField.FFT_HIDDEN)) {
3281 if(request.getParameter(fieldId)!=null) {
3282 formfield_value = request.getParameter(fieldId);
3284 formfield_value = "";
3286 } else if((fft.getFieldType().equals(FormField.FFT_TEXT) || fft.getFieldType().equals(FormField.FFT_TEXTAREA)) &&
3287 (!fft.getValidationType().equals(FormField.VT_DATE) && !fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)&&
3288 !fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) && !fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) ) {
3289 if(request.getParameter(fieldId)!=null) {
3290 formfield_value = request.getParameter(fieldId);
3292 formfield_value = "";
3294 } else if (fft.getValidationType().equals(FormField.VT_DATE) || fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)||
3295 fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) || fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
3296 /*if(formGrid.hasFellow(fieldId, true)) {
3297 Datebox tb = (Datebox) formGrid.getFellowIfAny(fieldId, true);
3299 formfield_value = tb.getText();
3300 } catch (WrongValueException ex) {
3301 formfield_value = "";
3303 if(AppUtils.nvl(formfield_value).length() > 0) {
3304 if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)) {
3305 if(formGrid.hasFellow(fieldId+"_Hr", true)) {
3306 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3307 formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3309 } else if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN)) {
3310 if(formGrid.hasFellow(fieldId+"_Min", true)) {
3311 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3312 //formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3313 Label hiddenLbMin = (Label) formGrid.getFellowIfAny(fieldId+"_Min", true);
3314 formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue();
3317 } else if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
3318 if(formGrid.hasFellow(fieldId+"_Sec", true)) {
3319 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3320 //formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3321 Label hiddenLbMin = (Label) formGrid.getFellowIfAny(fieldId+"_Min", true);
3322 //formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue();
3323 Label hiddenLbSec = (Label) formGrid.getFellowIfAny(fieldId+"_Sec", true);
3324 formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue()+ ":" +hiddenLbSec.getValue();
3331 formfield_value = "";
3333 } else if ((fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)||
3334 fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) || fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC))) {
3335 /*if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)||
3336 fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) || fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
3337 if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)) {
3338 if(formGrid.hasFellow(fieldId+"_Hr", true)) {
3339 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3340 formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3342 } else if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN)) {
3343 if(formGrid.hasFellow(fieldId+"_Min", true)) {
3344 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3345 //formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3346 Label hiddenLbMin = (Label) formGrid.getFellowIfAny(fieldId+"_Min", true);
3347 formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue();
3350 } else if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
3351 if(formGrid.hasFellow(fieldId+"_Sec", true)) {
3352 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3353 //formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3354 Label hiddenLbMin = (Label) formGrid.getFellowIfAny(fieldId+"_Min", true);
3355 //formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue();
3356 Label hiddenLbSec = (Label) formGrid.getFellowIfAny(fieldId+"_Sec", true);
3357 formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue()+ ":" +hiddenLbSec.getValue();
3363 } else if (fft.getFieldType().equals(FormField.FFT_TEXT_W_POPUP)) {
3364 if(request.getParameter(fieldId)!=null) {
3365 formfield_value = request.getParameter(fieldId);
3367 formfield_value = "";
3369 } else if (fft.getFieldType().equals(FormField.FFT_LIST_BOX)) {
3370 if(request.getParameter(fieldId)!=null) {
3371 formfield_value = request.getParameter(fieldId);
3373 formfield_value = "";
3377 if(nvl(formfield_value).length()>0) {
3378 sql = Utils.replaceInString(sql, fieldDisplay, formfield_value);
3380 sql = Utils.replaceInString(sql, "'"+fieldDisplay+"'", "null");
3381 sql = Utils.replaceInString(sql, fieldDisplay, "null");
3382 //sql = Utils.replaceInString(sql, fieldDisplay, "''");
3389 public String parseAndFillReq_Session_UserValues(HttpServletRequest request, String sql, String user_id) {
3390 HttpSession session = request.getSession();
3392 String[] reqParameters = Globals.getRequestParams().split(",");
3393 String[] sessionParameters = Globals.getSessionParams().split(",");
3394 String[] scheduleSessionParameters = Globals.getSessionParamsForScheduling().split(",");
3397 if(AppUtils.nvl(sql).length()>0) {
3398 for (int i = 0; i < reqParameters.length; i++) {
3399 if(!reqParameters[i].startsWith("ff") && (request.getParameter(reqParameters[i].toUpperCase())!=null && request.getParameter(reqParameters[i].toUpperCase()).length() > 0))
3400 sql = Utils.replaceInString(sql, "[" + reqParameters[i].toUpperCase()+"]", request.getParameter(reqParameters[i].toUpperCase()) );
3401 else if (request.getParameter(reqParameters[i])!=null && request.getParameter(reqParameters[i]).length() > 0)
3402 sql = Utils.replaceInString(sql, "[" + reqParameters[i].toUpperCase()+"]", request.getParameter(reqParameters[i]) );
3405 for (int i = 0; i < scheduleSessionParameters.length; i++) {
3406 //debugLogger.debug(" Session " + " scheduleSessionParameters[i] " + scheduleSessionParameters[i].toUpperCase() + " " + request.getParameter(scheduleSessionParameters[i]));
3407 if(request.getParameter(scheduleSessionParameters[i])!=null && request.getParameter(scheduleSessionParameters[i]).trim().length()>0 )
3408 sql = Utils.replaceInString(sql, "[" + scheduleSessionParameters[i].toUpperCase()+"]", request.getParameter(scheduleSessionParameters[i]) );
3409 if(request.getAttribute(scheduleSessionParameters[i])!=null && ((String)request.getAttribute(scheduleSessionParameters[i])).trim().length()>0 )
3410 sql = Utils.replaceInString(sql, "[" + scheduleSessionParameters[i].toUpperCase()+"]", (String) request.getAttribute(scheduleSessionParameters[i]) );
3414 for (int i = 0; i < sessionParameters.length; i++) {
3415 //if(!sessionParameters[i].startsWith("ff"))
3416 //fieldSQL = Utils.replaceInString(fieldSQL, "[" + sessionParameters[i].toUpperCase()+"]", (String)session.getAttribute(sessionParameters[i].toUpperCase()) );
3418 if (session.getAttribute(sessionParameters[i])!=null && ((String)session.getAttribute(sessionParameters[i])).length() > 0) {
3419 //debugLogger.debug(" Session " + " sessionParameters[i] " + sessionParameters[i] + " " + (String)session.getAttribute(sessionParameters[i]));
3420 sql = Utils.replaceInString(sql, "[" + sessionParameters[i].toUpperCase()+"]", (String)session.getAttribute(sessionParameters[i]) );
3424 sql = Utils.replaceInString(sql, "[USERID]", user_id);
3425 sql = Utils.replaceInString(sql, "[USER_ID]", user_id);
3426 sql = Utils.replaceInString(sql, "[LOGGED_USERID]", user_id);