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============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
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 * private ReportRuntime(CustomReport cr, String reportID,
188 * HttpServletRequest request) { super(cr, reportID);
190 * reportParamValues = new ReportParamValues(this); reportFormFields = new
191 * ReportFormFields(this);
193 * if(request!=null) setParamValues(request); } // ReportRuntime
195 private ReportRuntime(CustomReportType crType, String reportID, HttpServletRequest request,
196 String ownerID, String createID, String createDate, String updateID,
197 String updateDate, String menuID, boolean menuApproved) throws RaptorException {
198 super(crType, reportID, ownerID, createID, createDate, updateID, updateDate, menuID,
200 initializeReportRuntime(request);
203 public ReportRuntime(ReportWrapper rw) throws RaptorException {
207 public ReportRuntime(ReportWrapper rw, HttpServletRequest request)throws RaptorException {
209 initializeReportRuntime(request);
212 private void initializeReportRuntime(HttpServletRequest request) throws RaptorException {
213 reportFormFields = new ReportFormFields(this, request);
214 setParamValues(request, true, true);
216 visualManager = new VisualManager();
217 } // initializeReportRuntime
219 // public void setReportFormFields(HttpServletRequest request) {
220 // reportFormFields = new ReportFormFields(this, request);
221 // setParamValues(request, true, true);
224 public static ReportRuntime unmarshal(String reportXML, String reportID)
225 throws RaptorException {
226 return unmarshal(reportXML, reportID, null);
229 public static ReportRuntime unmarshal(String reportXML, String reportID,
230 HttpServletRequest request) throws RaptorException {
231 CustomReportType crType = ReportWrapper.unmarshalCR(reportXML);
232 ObjectFactory objFactory = new ObjectFactory();
234 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] Report [" + reportID + "]: XML unmarshalled"));
236 return new ReportRuntime(crType, reportID, request, null, null, null, null, null, null,
241 public String getXmlFileURL() {
245 public String getXmlFileName() {
249 public String getFlatFileName() {
253 public String getExcelPageFileName() {
254 return excelPageFileName;
257 public int getReportDataSize() {
258 return reportDataSize;
261 public boolean getDisplayChart() {
265 public boolean getDisplayForm() {
269 public boolean getDisplayContent() {
270 return displayContent;
273 public int getCachedPageNo() {
277 public String getCachedSQL() {
281 public boolean isDashboardType() throws RaptorException {
282 return ReportLoader.isDashboardType(getReportID());
286 public void setXmlFileURL(String xmlFileURL) {
287 this.xmlFileURL = xmlFileURL;
290 public void setXmlFileName(String xmlFileName) {
291 this.xmlFileName = xmlFileName;
294 public void setFlatFileName(String flatFileName) {
295 this.flatFileName = flatFileName;
298 public void setExcelPageFileName(String excelPageFileName) {
299 this.excelPageFileName = excelPageFileName;
302 /*private*/ public void setReportDataSize(int reportDataSize) {
303 this.reportDataSize = reportDataSize;
306 private void setDisplayForm(boolean displayForm) {
307 this.displayForm = displayForm;
310 private void setDisplayContent(boolean displayContent) {
311 this.displayContent = displayContent;
314 public void setDisplayFlags(boolean isFirstAccess, boolean forceDisplayContent) {
316 setDisplayForm(true);
318 if (forceDisplayContent)
319 setDisplayContent(true);
320 else if (Globals.getDisplayFormBeforeRun())
322 setDisplayContent(false);
324 setDisplayContent(true);
326 setDisplayContent(true);
328 setDisplayContent(true);
330 if (Globals.getIncludeFormWithData())
331 setDisplayForm(true);
332 else if (Globals.getDisplayFormBeforeRun())
333 setDisplayForm(false);
335 setDisplayForm(true);
339 public void logReportRun(String userID, String executionTime, String formFields) throws RaptorException {
343 ReportLoader.createReportLogEntry(null, reportID, userID, AppConstants.RLA_RUN,executionTime,formFields );
344 reportRunLogged = true;
347 public void logReportExecutionTime(String userId, String executionTime, String action, String formFields) throws RaptorException {
348 ReportLoader.createReportLogEntryForExecutionTime(null, reportID, userId,executionTime , action, formFields);
351 public void logReportExecutionTimeFromLogList (String userId, String executionTime, String formFields) throws RaptorException {
352 ReportLoader.createReportLogEntryForExecutionTime(null, reportID, userId,executionTime , AppConstants.RLA_FROM_LOG, formFields);
355 public void resetVisualSettings() {
356 boolean haveToResetCachedData = (visualManager.getSortByColId().length() > 0);
357 visualManager = new VisualManager();
359 if (haveToResetCachedData)
360 pageDataCache = null;
362 if (pageDataCache != null)
363 pageDataCache.resetVisualSettings();
364 } // resetVisualSettings
366 /** ************** ReportParamValues processing *************** */
368 public boolean setParamValues(HttpServletRequest request, boolean resetParams, boolean refresh) throws RaptorException {
369 boolean paramsUpdated = false;
371 reportFormFields = new ReportFormFields(this, request);
372 reportParamValues = new ReportParamValues(reportFormFields, getReportDefType());
373 // This is called even in the wizard page. Hence this condition.
374 if((ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)!=null)
375 reportParamValuesFPE = new ReportParamValuesForPDFExcel(reportFormFields, getReportDefType());
376 paramsUpdated = true;
378 reportRunLogged = false;
379 } else if (request != null) {
380 paramsUpdated = reportParamValues.setParamValues(request,refresh);
382 // This is called even in the wizard page. Hence this condition.
383 if((ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)!=null) {
384 if(reportParamValuesFPE!=null) reportParamValuesFPE.setParamValues(request,refresh);
386 reportParamValuesFPE = new ReportParamValuesForPDFExcel(reportFormFields, getReportDefType());
387 reportParamValuesFPE.setParamValues(request,refresh);
390 reportFormFields = new ReportFormFields(this, request);
391 //added below two lines for dashboard default value
392 reportParamValues = new ReportParamValues(reportFormFields, getReportDefType());
393 reportParamValues.setParamValues(request,refresh);
395 reportParamValuesFPE = new ReportParamValuesForPDFExcel(reportFormFields, getReportDefType());
396 reportParamValuesFPE.setParamValues(request,refresh);
401 setReportDataSize(-1);
402 chartDataCache = null;
403 pageDataCache = null;
406 crossTabOrderManager = null;
408 colDataTotalsLinear = null;
409 colDataTotalsCrosstab = null;
410 rowDataTotalsCrosstab = null;
411 grandTotalCrosstab = null;
413 resetVisualSettings();
416 displayChart = (request.getParameter(AppConstants.RI_DISPLAY_CHART) == null) ? !isDisplayOptionHideChart() : request.getParameter("display_chart")
419 return paramsUpdated;
422 public String getParamValue(String key) {
423 //reportParamValues.printValues();
424 return reportParamValues.getParamValue(key);
427 public String getParamDisplayValue(String key) {
428 //reportParamValues.printValues();
429 return reportParamValues.getParamDisplayValue(key);
432 public Enumeration getParamKeys() {
433 return reportParamValues.keys();
436 public Enumeration getParamKeysForPDFExcel() {
437 return reportParamValuesFPE.keys();
440 public String getParamValueForPDFExcel(String key) {
441 return reportParamValuesFPE.getParamValue(key);
444 public ArrayList getParamNameValuePairs() {
445 ArrayList paramList = new ArrayList(getReportFormFields().size());
446 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
447 FormField ff = (FormField) iter.next();
448 paramList.add(new IdNameValue(ff.getFieldDisplayName(), reportParamValues
449 .getParamDisplayValue(ff.getFieldName())));
452 } // getParamNameValuePairs
454 public ArrayList getParamNameValuePairsforPDFExcel(HttpServletRequest request, int type /*excel =1; pdf=2*/) {
455 javax.servlet.http.HttpSession session = request.getSession();
456 ArrayList paramList = new ArrayList(getReportFormFields().size());
457 if(session.getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)!=null) {
458 paramList = (ArrayList) session.getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO);
459 if(paramList!=null && paramList.size()>0)
462 //System.out.println(" getParamNamePairs type " + type + " " + Globals.customizeFormFieldInfo());
463 if ( reportParamValuesFPE == null) {
464 reportParamValuesFPE = new ReportParamValuesForPDFExcel(reportFormFields, getReportDefType());
465 reportParamValuesFPE.setParamValues(request,true);
468 String valueString = "";
469 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
470 FormField ff = (FormField) iter.next();
471 if(ff.isVisible() && /*!ff.getFieldType().equals(FormField.FFT_HIDDEN) &&*/ type == 1){
472 valueString = reportParamValuesFPE.getParamDisplayValue(ff.getFieldName());
473 } else if(ff.isVisible() && type != 1) {
474 valueString = reportParamValuesFPE.getParamDisplayValue(ff.getFieldName());
476 if(valueString.equalsIgnoreCase("NULL"))
478 paramList.add(new IdNameValue(ff.getFieldDisplayName(), valueString));
482 String pdfAttachmentKey = AppUtils.getRequestValue(request, "pdfAttachmentKey");
483 boolean isSchedule = false;
484 if(pdfAttachmentKey != null)
486 if(Globals.customizeFormFieldInfo() && type == 2) {
487 String[] sessionParameters = Globals.getSessionParams().split(",");
489 if(session != null && !isSchedule ) {
490 session.setAttribute("login_id", AppUtils.getUserBackdoorLoginId(request));
491 for (int i = 0; i < sessionParameters.length; i++) {
492 if(session.getAttribute(sessionParameters[i])!=null)
493 paramList.add(new IdNameValue(sessionParameters[i].toUpperCase(), (String)session.getAttribute(sessionParameters[i])));
498 //debugLogger.debug("Globals " + Globals.getSessionParamsForScheduling());
499 String[] scheduleSessionParam = Globals.getSessionParamsForScheduling().split(",");
500 for (int i = 0; i < scheduleSessionParam.length; i++) {
501 //debugLogger.debug(" scheduleSessionParam[i] " + scheduleSessionParam[i] + " " + request.getParameter(scheduleSessionParam[i]) );
502 if(request.getParameter(scheduleSessionParam[i])!=null)
503 paramList.add(new IdNameValue(ESAPI.encoder().canonicalize(scheduleSessionParam[i].toUpperCase()), ESAPI.encoder().canonicalize(request.getParameter(scheduleSessionParam[i]))));
508 SimpleDateFormat oracleDateFormat = new SimpleDateFormat("MM/dd/yyyy kk:mm:ss");
509 Date sysdate = oracleDateFormat.parse(ReportLoader.getSystemDateTime());
510 SimpleDateFormat dtimestamp = new SimpleDateFormat(Globals.getScheduleDatePattern());
511 paramList.add(new IdNameValue("DATE", dtimestamp.format(sysdate)+" "+Globals.getTimeZone()));
512 } catch(Exception ex) {}
515 //System.out.println(" In Else getParamNamePairs type " + type);
516 String[] sessionDisplayParameters = Globals.getDisplaySessionParamInPDFEXCEL().split(",");
517 if(session != null && !isSchedule ) {
518 session.setAttribute("login_id", AppUtils.getUserBackdoorLoginId(request));
519 for (int i = 0; i < sessionDisplayParameters.length; i++) {
520 String sessionDispParam = sessionDisplayParameters[i];
521 if(nvl(sessionDispParam).length()>0) {
522 String sessionDispParamArr[] = sessionDispParam.split(";");
523 //System.out.println("Session " + sessionDispParamArr[1] + " " + (String)session.getAttribute(sessionDispParamArr[0]));
524 paramList.add(new IdNameValue(sessionDispParamArr[1], nvl((String)session.getAttribute(sessionDispParamArr[0]),"")));
529 String[] scheduleSessionParam = Globals.getDisplayScheduleSessionParamInPDFEXCEL().split(",");
530 for (int i = 0; i < scheduleSessionParam.length; i++) {
531 String scheduleSessionDispParam = scheduleSessionParam[i];
532 if(nvl(scheduleSessionDispParam).length()>0) {
533 String scheduleSessionDispParamArr[] = scheduleSessionDispParam.split(";");
534 paramList.add(new IdNameValue(ESAPI.encoder().canonicalize(scheduleSessionDispParamArr[1]), ESAPI.encoder().canonicalize(nvl(request.getParameter(scheduleSessionDispParamArr[0]),""))));
539 SimpleDateFormat oracleDateFormat = new SimpleDateFormat("MM/dd/yyyy kk:mm:ss");
540 Date sysdate = oracleDateFormat.parse(ReportLoader.getSystemDateTime());
541 SimpleDateFormat dtimestamp = new SimpleDateFormat(Globals.getScheduleDatePattern());
542 paramList.add(new IdNameValue("Report Date/Time", dtimestamp.format(sysdate)+" "+Globals.getTimeZone()));
543 } catch(Exception ex) {}
547 for (int i = 0; i < paramList.size(); i++) {
548 IdNameValue value = (IdNameValue) paramList.get(i);
549 String name = value.getName().replaceAll(",","~");
552 //request.getSession().setAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO, paramList);
554 } // getParamNameValuePairs
556 /** ************** ReportFormFields processing *************** */
558 public String getFormFieldComments(HttpServletRequest request) {
560 StringBuffer st = new StringBuffer("");
561 if(getFormFieldList()!=null){
562 comment = nvl(getFormFieldList().getComment());
564 if(comment.length()>0) {
565 al = getParamNameValuePairsforPDFExcel(request, 2);
567 //st = new StringBuffer(comment);
568 for (int i=0; i < al.size(); i++) {
569 IdNameValue idNameValue = (IdNameValue)al.get(i);
570 if(nvl(idNameValue.getId()).equals("DATE"))
571 st.append("<b>Date/Time Report Run:</b>"+ idNameValue.getName() +"<br></br>");
574 for (int i=0; i < al.size(); i++) {
575 IdNameValue idNameValue = (IdNameValue)al.get(i);
576 comment = Utils.replaceInString(comment, "["+ idNameValue.getId()+"]", idNameValue.getName());
583 return st.toString();
586 public boolean needFormInput() {
587 return reportFormFields.getFieldCount() > 0;
590 public FormField getFormField(String fieldName) {
591 return reportFormFields.getFormField(fieldName);
594 public ReportFormFields getReportFormFields() {
595 return reportFormFields;
596 } // getReportFormFields
598 /** ************** Report Data processing *************** */
599 public DataSet loadChartData(String userId, HttpServletRequest request) throws RaptorException {
600 if (nvl(getChartType()).length() == 0)
602 if (!getDisplayChart())
605 DataSet ds = chartDataCache;
608 sql = generateChartSQL(reportParamValues, userId, request);
609 String dbInfo = getDBInfo();
610 ds = ConnectionUtils.getDataSet(sql, dbInfo);
611 if (Globals.getCacheChartData())
618 public String getReportDataSQL(String userId, int downloadLimit, HttpServletRequest request) throws RaptorException {
619 String reportSQL = "";
620 if(doesReportContainsGroupFormField()) {
621 reportSQL = generateSubsetSQL(0, downloadLimit,userId, request, true, reportParamValues);
623 reportSQL = generateSubsetSQL(0, downloadLimit,userId, request, false, reportParamValues);
627 public ReportData loadReportData(int pageNo, String userId, int downloadLimit, HttpServletRequest request, boolean download) throws RaptorException {
628 ReportData rd = null;
629 boolean isGoBackAction = AppUtils.getRequestFlag(request, AppConstants.RI_GO_BACK);
631 if (pageNo == cachedPageNo && pageDataCache != null)
634 if(isGoBackAction && rd!=null) return rd;
635 if (rd == null) { // Commented So that Data is refreshed from DB again
636 if (getReportDataSize() < 0)
637 if (getReportType().equals(AppConstants.RT_CROSSTAB))
638 rd = loadCrossTabReportData(pageNo, userId, downloadLimit, request, download);
639 else if (getReportType().equals(AppConstants.RT_LINEAR))
640 rd = loadLinearReportData(pageNo, userId, downloadLimit, request, download);
642 throw new RuntimeException(
643 "[ReportRuntime.loadReportData] Invalid report type");
646 if (Globals.getCacheCurPageData()) {
648 cachedPageNo = pageNo;
650 } // if // Commented So that Data is refreshed from DB again
655 private ReportData loadCrossTabReportData(int pageNo, String userId, int downloadLimit, HttpServletRequest request, boolean download) throws RaptorException {
656 String reportSQL = generateSQL(reportParamValues, userId, request);
657 setWholeSQL(reportSQL);
658 cachedSQL = reportSQL;
659 wholeSQL = reportSQL;
660 List reportCols = getAllColumns();
661 // replace the request parameter specified in the drill down
662 DataColumnType dataColumnRequest = getCrossTabValueColumn();
663 reportSQL = parseReportSQLForDrillDownParams(reportSQL, dataColumnRequest, request);
668 String dbInfo = getDBInfo();
669 StringBuffer colNames = new StringBuffer();
670 StringBuffer colExtraIdNames = new StringBuffer();
671 StringBuffer colExtraDateNames = new StringBuffer();
674 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
675 DataColumnType dc = (DataColumnType) iter.next();
676 //TODO: commented if (dc.isVisible()) {
677 if (colNames.length() > 0)
678 colNames.append(", ");
679 colNames.append(dc.getColId());
680 //TODO uncomment if it's not working} // if
682 // Checking for extra fields necessary for drill-down
683 if (nvl(dc.getDrillDownURL()).length() > 0) {
684 System.out.println("Drilldown URL " + dc.getDrillDownURL());
689 if (reportSQL.toUpperCase().indexOf("GROUP BY ") < 0)
690 colNames.append(colExtraIdNames.toString());
691 colNames.append(colExtraDateNames.toString());
692 //reportSQL = " SELECT ROWNUM rnum, "
693 // + colNames.toString() + " FROM (" + reportSQL + ") ";
695 String rSQL = Globals.getLoadCrosstabReportData();
696 rSQL = rSQL.replace("[colNames.toString()]", colNames.toString());
697 rSQL = rSQL.replace("[reportSQL]", reportSQL);
699 setWholeSQL(reportSQL);
700 if (crossTabOrderManager == null)
701 crossTabOrderManager = new CrossTabOrderManager(this, userId,request);
702 ds = ConnectionUtils.getDataSet(reportSQL, dbInfo);
704 ReportData rd = new ReportData(pageNo, false);
705 ReportFormFields childReportFormFields = null;
706 if(doesReportContainsGroupFormField()) {
707 List reportCols1 = getAllColumns();
708 reportCols = new Vector();
710 for (Iterator iter = reportCols1.iterator(); iter.hasNext();) {
711 DataColumnType dct = (DataColumnType) iter.next();
712 for (int k=0; k<ds.getColumnCount(); k++) {
713 if(dct.getColId().toUpperCase().trim().equals(ds.getColumnName(k).trim())) {
720 if (getFormFieldList() != null) {
721 String paramValue = "";
722 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
723 FormFieldType fft = (FormFieldType) iter.next();
724 if(fft.isGroupFormField()!=null && fft.isGroupFormField().booleanValue()) {
725 paramValue = Utils.oracleSafe(nvl(reportParamValues
726 .getParamValue(fft.getFieldId())));
728 for (Iterator iter1 = reportCols1.iterator(); iter1.hasNext();) {
729 DataColumnType dct = (DataColumnType) iter1.next();
730 if(("["+fft.getFieldName()+ "]").equals(dct.getColName().trim())) {
731 dct.setDisplayName(paramValue);
742 int dataColumnIdx = (rd.reportRowHeaderCols.size() + rd.reportColumnHeaderRows.size())-1;
743 DataColumnType dataColumn = getCrossTabValueColumn();
745 String columnValue = "";
748 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
749 DataColumnType dct = (DataColumnType) iter.next();
751 if (nvl(dct.getDrillDownURL()).length() > 0) {
752 childReportFormFields = getChildReportFormFields(request,dct.getDrillDownURL());
755 if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_ROW)) {
756 RowHeaderCol rhc = new RowHeaderCol();
757 rhc.setColumnTitle(dct.getDisplayName());
758 // rhc.setColumnWidth("10%");
759 //rhc.setColumnWidth(dct.getDisplayWidth() + "%");
760 if(nvl(dct.getDisplayWidthInPxls()).length()<=0) {
761 dct.setDisplayWidthInPxls("100px");
763 if(dct.getDisplayWidthInPxls().endsWith("px"))
764 rhc.setColumnWidth(dct.getDisplayWidthInPxls());
766 rhc.setColumnWidth(dct.getDisplayWidthInPxls()+"px");
768 rhc.setAlignment(dct.getDisplayAlignment());
769 rhc.setDisplayHeaderAlignment(dct.getDisplayHeaderAlignment());
770 rhc.setNowrap(nvl(dataColumn.getNowrap(),"null").equals("false")?"null":nvl(dataColumn.getNowrap(),"null"));
771 rd.reportRowHeaderCols.addRowHeaderCol(rhc);
772 } else if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_COLUMN)) {
773 ColumnHeaderRow chr = new ColumnHeaderRow();
774 chr.setAlignment(dct.getDisplayHeaderAlignment());
775 chr.setRowHeight("15");
776 if(nvl(dct.getDisplayWidthInPxls()).length()<=0) {
777 dct.setDisplayWidthInPxls("80px");
779 if(dct.getDisplayWidthInPxls().endsWith("px"))
780 chr.setDisplayWidth(dct.getDisplayWidthInPxls());
782 chr.setDisplayWidth(dct.getDisplayWidthInPxls()+"px");
784 rd.reportColumnHeaderRows.addColumnHeaderRow(chr);
785 } else if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_VALUE)) {
786 columnValue = dct.getColId();
788 if(!dct.getColId().toLowerCase().endsWith("_sort")) {
789 RowHeaderCol rhc = new RowHeaderCol();
790 rhc.setVisible(false);
791 rd.reportRowHeaderCols.addRowHeaderCol(rhc);
796 //int dataColumnIdx = getCrossTabValueColumnIndex();
797 FormatProcessor formatProcessor = new FormatProcessor(getSemaphoreById(dataColumn
799 getReportDefType().equals(AppConstants.RD_SQL_BASED) ? AppConstants.CT_NUMBER
800 : dataColumn.getColType(), dataColumn.getColFormat(), false);
801 List dataList = new ArrayList();
802 /* //fillup all rows based on rowheaders
803 Vector rowHeaders = crossTabOrderManager.getRowHeaderValues();
804 CrossTabColumnValues crossTabRowValues;
806 for (int i = 0; i < rowHeaders.size(); i++) {
807 if((i+1)==rowHeaders.size()) {
808 crossTabRowValues = (CrossTabColumnValues) rowHeaders.get(i);
809 size = crossTabRowValues.getValuesCount();
813 for (int i = 0; i < size; i++) {
814 dataList.add(new DataRow());
817 for (int i = 0; i < ds.getRowCount(); i++) {
818 Vector rValues = new Vector();
819 Vector cValues = new Vector();
820 Vector cValuesSort = new Vector();
823 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
825 DataColumnType dct = (DataColumnType) iter.next();
826 if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_ROW))
827 rValues.add(addDataValue(dct, ds.getString(i, dct.getColId())));
828 if (nvl(dct.getCrossTabValue()).trim().length()<=0 && !dct.getColId().toLowerCase().endsWith("_sort"))
829 rValues.add(addDataValue(dct, ds.getString(i, dct.getColId())));
830 if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_COLUMN)) {
831 cValues.add(addDataValue(dct, ds.getString(i, dct.getColId())));
832 if(getColumnById(dct.getColId().toLowerCase()+"_sort")!=null)
833 cValuesSort.add(addDataValue(dct, new Integer(ds.getString(i, dct.getColId()+"_sort")).toString()));
837 } catch (ArrayIndexOutOfBoundsException ex ) {continue;}
838 catch (NumberFormatException ex1) {
839 ex1.printStackTrace();
844 DataValue dv = new DataValue();
845 dv.setDisplayValue(ds.getString(i, columnValue));
846 if (nvl(dataColumn.getCrossTabValue()).trim().length()<=0)
847 dv.setVisible(false);
848 dv.setAlignment(dataColumn.getDisplayAlignment());
849 dv.setDisplayTotal(dataColumn.getDisplayTotal());
850 dv.setColName(dataColumn.getColName());
851 dv.setDisplayName(dataColumn.getDisplayName());
852 dv.setColId(dataColumn.getColId());
853 dv.setNowrap(nvl(dataColumn.getNowrap(),"null").equals("false")?"null":nvl(dataColumn.getNowrap(),"null"));
854 /*StringBuffer indentation = new StringBuffer("");
855 if(dataColumn.getIndentation()!=null && dataColumn.getIndentation().intValue()>0) {
856 for (int indent=0; indent < dataColumn.getIndentation(); indent++) {
857 indentation.append("\t");
859 dv.setNowrap("true");
861 dv.setIndentation(indentation.toString());*/
863 if (nvl(dataColumn.getDrillDownURL()).length() > 0) {
864 if(dv.getDisplayValue().length() > 0) {
865 dv.setDrillDownURL(parseDrillDownURL(i, /* dataColumnIdx, */ds, dataColumn,request, childReportFormFields));
866 dv.setDrillDowninPoPUp(dataColumn.isDrillinPoPUp()!=null?dataColumn.isDrillinPoPUp():false);
868 if (dv.getDisplayValue().length() == 0) {
869 //dv.setDisplayValue("[NULL]");
870 dv.setDisplayValue("");
874 rd.setDataValue(rValues, cValues, cValuesSort.size()==0?null:cValuesSort, dv, formatProcessor, crossTabOrderManager, dataList);
876 rd.setReportDataList(dataList);
877 /*if (getReportDataSize() < 0)
878 setReportDataSize(rd.getDataRowCount());*/
881 rd.truncateData(pageNo * getPageSize(), (pageNo + 1) * getPageSize() - 1);
883 if( downloadLimit != -1)
884 rd.truncateData(0, downloadLimit - 1);
886 rd.truncateData(0, -1);
889 if (colDataTotalsCrosstab == null)
890 colDataTotalsCrosstab = generateDataTotalsCrossTab(AppConstants.CV_COLUMN, userId,request);
891 if (displayColTotals && colDataTotalsCrosstab != null)
892 rd.setColumnDataTotalsCrossTab(colDataTotalsCrosstab, dataColumn
893 .getDisplayAlignment(), getCrossTabDisplayTotal(AppConstants.CV_COLUMN),
894 crossTabOrderManager, dataList);
896 if (rowDataTotalsCrosstab == null)
897 rowDataTotalsCrosstab = generateDataTotalsCrossTab(AppConstants.CV_ROW, userId, request);
898 if (displayRowTotals && rowDataTotalsCrosstab != null)
899 rd.setRowDataTotalsCrossTab(rowDataTotalsCrosstab, dataColumn
900 .getDisplayAlignment(), getCrossTabDisplayTotal(AppConstants.CV_ROW),
901 crossTabOrderManager, dataList);
905 && getCrossTabDisplayTotal(AppConstants.CV_COLUMN).equals(
906 getCrossTabDisplayTotal(AppConstants.CV_ROW))) {
907 // Display grand total
908 if (grandTotalCrosstab == null)
909 grandTotalCrosstab = ((CrossTabTotalValue) generateDataTotalsCrossTab("",
910 userId,request).get(0)).getTotalValue();
911 if (grandTotalCrosstab != null)
912 rd.setGrandTotalCrossTab(Utils.truncateTotalDecimals(grandTotalCrosstab),
913 dataColumn.getDisplayAlignment(),
914 getCrossTabDisplayTotal(AppConstants.CV_COLUMN), dataList);
917 rd.consolidateColumnHeaders(visualManager);
918 //if (Globals.getMergeCrosstabRowHeadings())
919 // rd.consolidateRowHeaders();
920 //rd.addRowNumbers(pageNo, dataList);
922 if (displayColTotals && colDataTotalsCrosstab != null) {
923 String totalLabel = "Total";
924 String colDisplayTotal = getCrossTabDisplayTotal(AppConstants.CV_COLUMN);
925 if (colDisplayTotal.length() > 0
926 && (!colDisplayTotal.equals(AppConstants.TOTAL_SUM_ID)))
927 totalLabel = nvl(AppConstants.TOTAL_FUNCTIONS.getNameById(colDisplayTotal));
928 if (getReportDataSize() > getPageSize())
929 totalLabel += "_nl_(for all pages)";
931 //rd.setCrossTabColumnTotalLabel(totalLabel);
934 //rd.applyVisibility();
935 //Collections.sort((List)dataList, new DataRowComparable());
936 DataRow drInFor1 = null;
937 Vector<DataValue> v1= null, v2 = null;
938 ArrayList<String> temp = new ArrayList<String>();
939 if (Globals.getMergeCrosstabRowHeadings()) {
940 for (int i = 0; i < dataList.size(); i++) {
941 drInFor1 = (DataRow)dataList.get(i);
942 drInFor1.setRowNum(i+1);
943 v1 = drInFor1.getRowValues();
944 if(i<dataList.size()-1) {
945 v2 = ((DataRow)dataList.get(i+1)).getRowValues();
947 v2 = ((DataRow)dataList.get(i-1)).getRowValues();
949 for (int j = 0; j < v1.size(); j++) {
951 if(v1.get(j).getDisplayValue().length()>0) { // another ArrayList
952 temp = new ArrayList();
953 temp.add(v1.get(j).getDisplayValue());
955 if(v2!=null && temp.get(j).equals(v2.get(j).getDisplayValue())) {
956 v2.get(j).setDisplayValue("");
962 rd.setReportDataList(dataList);
963 if (getReportDataSize() < 0) {
964 //setReportDataSize(rd.getDataRowCount());
965 setReportDataSize(rd.getReportDataList().size());
969 } // loadCrossTabReportData
972 public DataValue addDataValue(DataColumnType dataColumn, String columnValue) {
973 DataValue dv = new DataValue();
974 dv.setDisplayValue(columnValue);
975 if (nvl(dataColumn.getCrossTabValue()).trim().length()<=0)
976 dv.setVisible(false);
977 dv.setAlignment(dataColumn.getDisplayAlignment());
978 dv.setDisplayTotal(dataColumn.getDisplayTotal());
979 dv.setColName(dataColumn.getColName());
980 dv.setDisplayName(dataColumn.getDisplayName());
981 dv.setColId(dataColumn.getColId());
982 dv.setNowrap(nvl(dataColumn.getNowrap(),"null").equals("false")?"null":nvl(dataColumn.getNowrap(),"null"));
987 /*private*/ public boolean doesReportContainsGroupFormField() {
989 if(getFormFieldList()!=null) {
990 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
991 FormFieldType fft = (FormFieldType) iter.next();
992 if(fft.isGroupFormField()!=null && fft.isGroupFormField().booleanValue()) {
1001 private ReportData loadLinearReportData(int pageNo, String userId, int downloadLimit, HttpServletRequest request, boolean download) throws RaptorException {
1002 String action = nvl(request.getParameter(AppConstants.RI_ACTION), request.getParameter("action"));;
1004 String reportSQL = "";
1006 if(action.endsWith("session")) {
1007 reportSQL = getWholeSQL();
1008 wholeSQL = reportSQL;
1010 reportSQL = generateSQL(reportParamValues, visualManager.getSortByColId(),
1011 visualManager.getSortByAscDesc(), userId, request);
1012 wholeSQL = reportSQL;
1013 setWholeSQL(wholeSQL);
1016 String dbInfo = getDBInfo();
1017 ds = ConnectionUtils.getDataSet(wholeSQL, dbInfo);
1018 setReportDataSize(ds.getRowCount());
1019 //wholeSQL = reportSQL;
1020 HttpSession session = request.getSession();
1021 //debugLogger.debug(" ******** Download Limit ********* " + downloadLimit + " %%%%%%%%%%PAGE " + pageNo );
1022 List reportCols = null;
1023 StringBuffer colNames = new StringBuffer();
1025 if(download && action.endsWith("session")) {
1026 reportCols = getAllColumns();
1027 colNames = new StringBuffer();
1028 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1030 DataColumnType dc = (DataColumnType) iter.next();
1031 if (colNames.length() > 0)
1032 colNames.append(", ");
1033 colNames.append(dc.getColId());
1038 String pagedSQL = null; // reportSQL;
1040 pagedSQL = generatePagedSQL(pageNo, userId, request, false, null);
1042 pagedSQL = generateSubsetSQL(0, downloadLimit, userId, request, false, null);
1043 // replace the request parameter specified in the drill down
1044 reportCols = getAllColumns();
1045 colNames = new StringBuffer();
1046 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1048 DataColumnType dc = (DataColumnType) iter.next();
1049 if (colNames.length() > 0)
1050 colNames.append(", ");
1051 colNames.append(dc.getColId());
1052 if (dc.isVisible()) {
1053 reportSQL = parseReportSQLForDrillDownParams(reportSQL, dc, request);
1054 pagedSQL = parseReportSQLForDrillDownParams(pagedSQL, dc, request);
1058 cachedSQL = pagedSQL;
1062 if(doesReportContainsGroupFormField()) {
1064 pagedSQL = generatePagedSQL(pageNo, userId, request, true, reportParamValues);
1066 pagedSQL = generateSubsetSQL(0, downloadLimit, userId, request, true, reportParamValues);
1068 //check for Group formfield
1069 //if groupformfield get columns from sql
1071 ds = ConnectionUtils.getDataSet(pagedSQL, dbInfo);
1073 if(doesReportContainsGroupFormField()) {
1074 List reportCols1 = getAllColumns();
1075 reportCols = new Vector();
1077 for (Iterator iter = reportCols1.iterator(); iter.hasNext();) {
1078 DataColumnType dct = (DataColumnType) iter.next();
1079 for (int k=0; k<ds.getColumnCount(); k++) {
1080 if(dct.getColId().toUpperCase().trim().equals(ds.getColumnName(k).trim())) {
1081 reportCols.add(dct);
1087 if (getFormFieldList() != null) {
1088 String paramValue = "";
1089 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
1090 FormFieldType fft = (FormFieldType) iter.next();
1091 if(fft.isGroupFormField()!=null && fft.isGroupFormField().booleanValue()) {
1092 paramValue = Utils.oracleSafe(nvl(reportParamValues
1093 .getParamValue(fft.getFieldId())));
1095 for (Iterator iter1 = reportCols1.iterator(); iter1.hasNext();) {
1096 DataColumnType dct = (DataColumnType) iter1.next();
1097 if(("["+fft.getFieldName()+ "]").equals(dct.getColName().trim())) {
1098 dct.setDisplayName(paramValue);
1110 // if ( (remDbInfo!=null) && (!remDbInfo.equals(AppConstants.DB_LOCAL)))
1112 // Globals.getRDbUtils().setDBPrefix(remDbInfo);
1113 // ds = RemDbUtils.executeQuery(pagedSQL);
1116 // ds = DbUtils.executeQuery(pagedSQL);
1118 * } catch(SQLException e) { throw new
1119 * ReportSQLException("[ReportRuntime.loadLinearReportData]
1120 * "+e.getMessage(), pagedSQL); }
1123 if (getReportDataSize() < 0)
1125 setReportDataSize(ds.getRowCount());
1126 else if (ds.getRowCount() <= getPageSize())
1127 setReportDataSize(ds.getRowCount());
1130 /*Pattern re1 = Pattern.compile("[Oo][Rr][Dd][Ee][Rr](.*?[^\r\n]*)[Bb][Yy]", Pattern.DOTALL);
1131 Pattern re2 = Pattern.compile("[Oo][Rr][Dd][Ee][Rr](.*?[^\r\n]*)[Bb][Yy]((.*?[^\r\n]*)|[\\s]|[^0-9a-zA-Z])\\)", Pattern.DOTALL);
1132 Matcher matcher = re1.matcher(reportSQL);
1133 Matcher matcher2 = null;
1134 int startPoint = reportSQL.length()-30;
1135 String startReportSQL = "";
1136 String endReportSQL = "";
1137 while(reportSQL.indexOf("xid", startPoint)!=-1)startPoint++;
1138 if (matcher.find(startPoint)) {
1139 startReportSQL = reportSQL.substring(0, reportSQL.indexOf(matcher.group()));
1140 endReportSQL = reportSQL.substring(reportSQL.indexOf(matcher.group()));
1141 matcher2 = re2.matcher(endReportSQL);
1143 endReportSQL = endReportSQL.substring(matcher.group().length()-1);
1146 reportSQL = startReportSQL + endReportSQL;
1148 String countSQL = "SELECT count(*) FROM (" + reportSQL + ")"+ (Globals.isPostgreSQL() || Globals.isMySQL()?" AS ":"") +" x ";
1151 if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
1153 org.onap.portalsdk.analytics.util.RemDbInfo remDbInfo = new org.onap.portalsdk.analytics.util.RemDbInfo();
1154 dbType = remDbInfo.getDBType(dbInfo);
1155 if (dbType.equals("DAYTONA") && reportSQL.trim().toUpperCase().startsWith("SELECT")) {
1156 Pattern re1 = Pattern.compile("order(.*?[^\r\n]*)by", Pattern.DOTALL);
1157 Matcher matcher = re1.matcher(reportSQL);
1158 int startPoint = reportSQL.length()-30;
1159 while(reportSQL.indexOf("xid", startPoint)!=-1)startPoint++;
1160 if (matcher.find(startPoint)) {
1161 reportSQL = reportSQL.substring(0, reportSQL.indexOf(matcher.group()));
1163 countSQL = "SELECT count(*) FROM (" + reportSQL + ")"+ (Globals.isPostgreSQL() || Globals.isMySQL()?" AS ":"") +" x";
1164 countSQL = countSQL + " ("+ colNames+ ")";
1165 } else if (dbType.equals("DAYTONA")) {
1166 setReportDataSize(50);
1168 } catch (Exception ex) {
1169 throw new RaptorException(ex);
1175 if(reportSQL.trim().toUpperCase().startsWith("SELECT")) {
1176 ds2 = ConnectionUtils.getDataSet(countSQL, dbInfo);
1177 if (ds2.getRowCount() > 0)
1178 setReportDataSize(ds2.getInt(0, 0));
1180 throw new RuntimeException(
1181 "[ReportRuntime.loadLinearReportData] Unable to load report data size");
1183 setReportDataSize(50);
1184 // if ( (remDbInfo!=null) &&
1185 // (!remDbInfo.equals(AppConstants.DB_LOCAL))){
1186 // Globals.getRDbUtils().setDBPrefix(remDbInfo);
1187 // ds2 = RemDbUtils.executeQuery(countSQL);
1190 // ds2 = DbUtils.executeQuery(countSQL);
1192 * } catch(SQLException e) { throw new
1193 * ReportSQLException("[ReportRuntime.loadLinearReportData size]
1194 * "+e.getMessage(), countSQL); }
1200 ReportData rd = new ReportData(pageNo, true);
1202 // Already defined changed for modifying request parameters
1203 //List reportCols = getAllColumns();
1204 Vector visibleCols = new Vector(reportCols.size());
1205 Vector formatProcessors = new Vector(reportCols.size());
1207 // ColumnHeaderRow chr = new ColumnHeaderRow();
1208 // rd.reportColumnHeaderRows.addColumnHeaderRow(chr);
1209 // chr.setRowHeight("30");
1213 ReportFormFields rff = getReportFormFields();
1214 ReportFormFields childReportFormFields = null;
1215 String fieldDisplayName = "";
1216 String fieldValue = "";
1218 for (int c = 0; c < reportCols.size(); c++) {
1219 if(reportCols.get(c)!=null) {
1220 DataColumnType dct = (DataColumnType) reportCols.get(c);
1221 if(nvl(dct.getDependsOnFormField()).length()>0 && nvl(dct.getDependsOnFormField()).indexOf("[")!=-1) {
1222 for(int i = 0 ; i < rff.size(); i++) {
1223 fieldDisplayName = "["+((FormField)rff.getFormField(i)).getFieldDisplayName()+"]";
1225 //if(dct.getOriginalDisplayName()==null) dct.setOriginalDisplayName(dct.getDisplayName());
1226 if (dct.getDependsOnFormField().equals(fieldDisplayName)) {
1227 fieldValue = nvl(request.getParameter(((FormField)rff.getFormField(i)).getFieldName()));
1229 if (fieldValue.length()>0) {
1230 if(!fieldValue.toUpperCase().equals("Y"))
1231 dct.setDisplayName(fieldValue);
1232 if(!dct.isVisible())
1233 dct.setVisible(true);
1235 dct.setVisible(false);
1244 String displayName = "";
1245 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1247 DataColumnType dc = (DataColumnType) iter.next();
1249 formatProcessors.add(count,new FormatProcessor(
1250 getSemaphoreById(dc.getSemaphoreId()), dc.getColType(), dc
1251 .getColFormat(), getReportDefType().equals(
1252 AppConstants.RD_SQL_BASED)));
1254 if (nvl(dc.getDrillDownURL()).length() > 0) {
1255 childReportFormFields = getChildReportFormFields(request,AppUtils.getDrillActionURL()+""+dc.getDrillDownURL());
1257 if (dc.isVisible()) {
1258 visibleCols.add(count,dc);
1259 //if(dc.getColId().startsWith("group")) {
1260 for (int d = 0; d < reportCols.size(); d++) {
1261 if(reportCols.get(d)!=null) {
1262 DataColumnType dct1 = (DataColumnType) reportCols.get(d);
1263 if(dct1.getColId().equals(dc.getColId()+"_name") && ds.getRowCount()>0) {
1264 displayName = ds.getString(0,dct1.getColId());
1265 dc.setDisplayName(displayName);
1271 String widthInPxls = dc.getDisplayWidthInPxls();
1273 if(nvl(widthInPxls).endsWith("px"))
1274 dc.setDisplayWidthInPxls(widthInPxls);
1276 widthInPxls = widthInPxls+"px";
1277 dc.setDisplayWidthInPxls(widthInPxls+"px");
1280 rd.createColumn(dc.getColId(), dc.getDisplayName(), dc.getDisplayWidthInPxls(), dc.getDisplayHeaderAlignment(),
1281 visualManager.isColumnVisible(dc.getColId()), visualManager
1282 .getSortByColId().equals(dc.getColId()) ? visualManager
1283 .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);
1284 // chr.addColumnHeader(new ColumnHeader(dc.getDisplayName(),
1285 // (dc.getDisplayWidth()>100)?"10%":(""+dc.getDisplayWidth()+"%")));
1288 visibleCols.add(count,null);
1289 rd.createColumn(dc.getColId(), AppConstants.HIDDEN, dc.getDisplayWidthInPxls(), dc.getDisplayHeaderAlignment(),
1290 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);
1291 // formatProcessors.add(count,null);
1296 if(getReportDefType().equals(AppConstants.RD_SQL_BASED_DATAMIN) && pageNo ==0) {
1299 v = addForecastData(reportSQL);
1300 } catch (Exception ex) {
1301 ex.printStackTrace();
1302 throw new RaptorException (ex);
1304 session.setAttribute("FORECASTED_DATA", v);
1305 DataSet dsWhole = ConnectionUtils.getDataSet(wholeSQL, dbInfo);
1307 session.setAttribute(AppConstants.RI_CHART_FORECAST_DATA, dsWhole);
1310 if(getReportDefType().equals(AppConstants.RD_SQL_BASED_DATAMIN) && session.getAttribute("FORECASTED_DATA")!=null) {
1311 Vector vForecastedData = (Vector)session.getAttribute("FORECASTED_DATA");
1312 if(vForecastedData.size() > 0)
1313 ds.addAll(vForecastedData);*/
1317 // Utils._assert(chr.size()==ds.getColumnCount(),
1318 // "[ReportRuntime.loadLinearReportData] The number of visible columns
1319 // does not match the number of data columns");
1320 //TODO: This should be optimized to accept -1 for flat file download
1321 for (int r = 0; r < Math.min(ds.getRowCount(), ((pageNo < 0) ? (downloadLimit == -1?Globals.getFlatFileUpperLimit():Globals.getDownloadLimit() ) : getPageSize())); r++) {
1322 DataRow dr = new DataRow();
1323 rd.reportDataRows.addDataRow(dr);
1325 for (int c = 0; c < reportCols.size(); c++) {
1326 if(reportCols.get(c)!=null) {
1327 DataColumnType dct = (DataColumnType) reportCols.get(c);
1328 DataValue dv = new DataValue();
1329 dr.addDataValue(dv);
1330 dv.setDisplayValue(ds.getString(r, c));
1331 dv.setColName(dct.getColName());
1332 dv.setColId(dct.getColId());
1333 dv.setNowrap(nvl(dct.getNowrap(),"null").equals("false")?"null":nvl(dct.getNowrap(),"null"));
1334 StringBuffer indentation = new StringBuffer("");
1335 if(dct.getIndentation()!=null && dct.getIndentation()>0) {
1336 for (int indent=0; indent< dct.getIndentation(); indent++) {
1337 indentation.append("\t");
1339 dv.setNowrap("true");
1341 dv.setIndentation(indentation.toString());
1342 if(dct.isVisible()) {
1344 dv.setVisible(true);
1345 dv.setAlignment(dct.getDisplayAlignment());
1346 dv.setDisplayTotal(dct.getDisplayTotal());
1347 dv.setDisplayName(dct.getDisplayName());
1349 if (nvl(dct.getDrillDownURL()).length() > 0) {
1351 if(dv.getDisplayValue().length() > 0) {
1352 dv.setDrillDownURL(parseDrillDownURL(r, /* c, */ds, dct,request, childReportFormFields));
1353 dv.setDrillDowninPoPUp(dct.isDrillinPoPUp()!=null?dct.isDrillinPoPUp():false);
1356 if (dv.getDisplayValue().length() == 0) {
1357 //dv.setDisplayValue("[NULL]");
1358 dv.setDisplayValue("");
1363 dv.setVisible(false);
1366 //System.out.println("in Linear report b4" + dr.getFormatId() + dr.getBgColorHtml() + dv.getDisplayValue());
1368 if(dr.getFormatId()!=null)
1369 ((FormatProcessor) formatProcessors.get(c)).setHtmlFormatters(dv, dr, true);
1371 ((FormatProcessor) formatProcessors.get(c)).setHtmlFormatters(dv, dr, false);
1373 //System.out.println("in Linear report After" + dr.getFormatId() + dr.getBgColorHtml() + dv.getDisplayValue());
1378 //Only if rownumber options is needed
1379 //rd.addRowNumbers(pageNo, getPageSize());
1381 if (colDataTotalsLinear == null) {
1382 if(!download && !action.endsWith("session"))
1383 colDataTotalsLinear = generateColumnDataTotalsLinear(new ArrayList(reportCols), userId,
1384 getDbInfo(),request);
1385 if(download && action.endsWith("session"))
1386 colDataTotalsLinear = generateColumnDataTotalsLinear(new ArrayList(reportCols), userId,
1387 getDbInfo(), getTotalSql());
1389 if (displayColTotals && colDataTotalsLinear != null) {
1390 String totalLabel = "Total";
1391 if (getReportDataSize() > getPageSize())
1392 totalLabel += "<br><font size=1>(for all pages)</font>";
1394 rd.setColumnDataTotalsLinear(colDataTotalsLinear, totalLabel);
1396 // Please note the below function doesn't set the visibility for dv since this is set in this function. - Sundar
1397 rd.applyVisibility();
1400 } // loadLinearReportData
1404 public DataRow generateColumnDataTotalsLinear(ArrayList reportCols, String userId,
1405 String dbInfo, String reportSQL) throws RaptorException {
1408 boolean displayColTotals = false;
1409 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1411 DataColumnType dct = (DataColumnType) iter.next();
1413 if (nvl(dct.getDisplayTotal()).length() > 0) {
1414 displayColTotals = true;
1417 } // if checking dct
1421 if (displayColTotals) {
1424 // DbUtils.executeQuery(generateTotalSQLLinear(reportParamValues,
1426 ds = ConnectionUtils.getDataSet(reportSQL,
1429 for (int c = 0; c < reportCols.size(); c++) {
1430 DataColumnType dct = (DataColumnType) reportCols.get(c);
1431 if ( dct != null ) {
1432 DataValue dv = new DataValue();
1434 String totalValue = "";
1436 totalValue = ds.getString(0, c);
1437 if (nvl(dct.getDisplayTotal()).length() > 0
1438 && (!dct.getDisplayTotal().equals(AppConstants.TOTAL_SUM_ID)))
1439 totalValue = nvl(AppConstants.TOTAL_FUNCTIONS.getNameById(dct
1440 .getDisplayTotal()))
1441 + ": " + totalValue;
1442 dv.setDisplayValue(Utils.truncateTotalDecimals(totalValue));
1444 dv.setAlignment(dct.getDisplayAlignment());
1445 dv.setColName(dct.getColName());
1446 dv.setDisplayName(dct.getDisplayName());
1447 dv.setColId(dct.getColId());
1448 dv.setNowrap(nvl(dct.getNowrap(),"null").equals("false")?"null":nvl(dct.getNowrap(),"null"));
1449 StringBuffer indentation = new StringBuffer("");
1450 if(dct.getIndentation()!=null && dct.getIndentation()>0) {
1451 for (int indent=0; indent< dct.getIndentation(); indent++) {
1452 indentation.append("\t");
1454 dv.setNowrap("true");
1456 dv.setIndentation(indentation.toString());
1457 dv.setDisplayTotal(dct.getDisplayTotal());
1459 dv.setVisible(dct.isVisible());
1461 dr.addDataValue(dv);
1467 } // generateColumnDataTotalsLinear
1470 public ReportData loadHiveLinearReportData(String reportSQL, String userId, int downloadLimit, HttpServletRequest request) throws RaptorException {
1471 wholeSQL = reportSQL;
1472 int countRows = getHiveReportCount(wholeSQL);
1473 setReportDataSize(countRows);
1474 if(countRows < 1001)
1475 wholeSQL += " limit "+ countRows;
1477 wholeSQL += " limit "+ downloadLimit;
1478 HttpSession session = request.getSession();
1482 String dbInfo = getDBInfo();
1484 List reportCols = getAllColumns();
1485 StringBuffer colNames = new StringBuffer();
1486 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1488 DataColumnType dc = (DataColumnType) iter.next();
1489 if (colNames.length() > 0)
1490 colNames.append(", ");
1491 colNames.append(dc.getColId());
1494 ds = ConnectionUtils.getDataSet(wholeSQL, dbInfo);
1496 ReportData rd = new ReportData(0, true);
1498 // Already defined changed for modifying request parameters
1499 //List reportCols = getAllColumns();
1500 Vector visibleCols = new Vector(reportCols.size());
1501 Vector formatProcessors = new Vector(reportCols.size());
1503 // ColumnHeaderRow chr = new ColumnHeaderRow();
1504 // rd.reportColumnHeaderRows.addColumnHeaderRow(chr);
1505 // chr.setRowHeight("30");
1509 ReportFormFields rff = getReportFormFields();
1510 ReportFormFields childReportFormFields = null;
1511 String fieldDisplayName = "";
1512 String fieldValue = "";
1514 for (int c = 0; c < reportCols.size(); c++) {
1515 if(reportCols.get(c)!=null) {
1516 DataColumnType dct = (DataColumnType) reportCols.get(c);
1517 if(nvl(dct.getDependsOnFormField()).length()>0 && nvl(dct.getDependsOnFormField()).indexOf("[")!=-1) {
1518 for(int i = 0 ; i < rff.size(); i++) {
1519 fieldDisplayName = "["+((FormField)rff.getFormField(i)).getFieldDisplayName()+"]";
1521 //if(dct.getOriginalDisplayName()==null) dct.setOriginalDisplayName(dct.getDisplayName());
1522 if (dct.getDependsOnFormField().equals(fieldDisplayName)) {
1523 fieldValue = nvl(request.getParameter(((FormField)rff.getFormField(i)).getFieldName()));
1525 if (fieldValue.length()>0) {
1526 if(!fieldValue.toUpperCase().equals("Y"))
1527 dct.setDisplayName(fieldValue);
1528 if(!dct.isVisible())
1529 dct.setVisible(true);
1531 dct.setVisible(false);
1540 String displayName = "";
1541 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1543 DataColumnType dc = (DataColumnType) iter.next();
1545 formatProcessors.add(count,new FormatProcessor(
1546 getSemaphoreById(dc.getSemaphoreId()), dc.getColType(), dc
1547 .getColFormat(), getReportDefType().equals(
1548 AppConstants.RD_SQL_BASED)));
1550 if (nvl(dc.getDrillDownURL()).length() > 0) {
1551 childReportFormFields = getChildReportFormFields(request,dc.getDrillDownURL());
1553 if (dc.isVisible()) {
1554 visibleCols.add(count,dc);
1555 //if(dc.getColId().startsWith("group")) {
1556 for (int d = 0; d < reportCols.size(); d++) {
1557 if(reportCols.get(d)!=null) {
1558 DataColumnType dct1 = (DataColumnType) reportCols.get(d);
1559 if(dct1.getColId().equals(dc.getColId()+"_name") && ds.getRowCount()>0) {
1560 displayName = ds.getString(0,dct1.getColId());
1561 dc.setDisplayName(displayName);
1567 String widthInPxls = dc.getDisplayWidthInPxls();
1569 if(nvl(widthInPxls).endsWith("px"))
1570 dc.setDisplayWidthInPxls(widthInPxls);
1572 widthInPxls = widthInPxls+"px";
1573 dc.setDisplayWidthInPxls(widthInPxls+"px");
1576 rd.createColumn(dc.getColId(), dc.getDisplayName(), dc.getDisplayWidthInPxls(), dc.getDisplayHeaderAlignment(),
1577 visualManager.isColumnVisible(dc.getColId()), visualManager
1578 .getSortByColId().equals(dc.getColId()) ? visualManager
1579 .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);
1580 // chr.addColumnHeader(new ColumnHeader(dc.getDisplayName(),
1581 // (dc.getDisplayWidth()>100)?"10%":(""+dc.getDisplayWidth()+"%")));
1584 visibleCols.add(count,null);
1585 rd.createColumn(dc.getColId(), "", dc.getDisplayWidthInPxls(), dc.getDisplayHeaderAlignment(),
1586 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);
1587 // formatProcessors.add(count,null);
1592 ArrayList reportDataList = new ArrayList();
1593 for (int r = 0; r < ds.getRowCount(); r++) {
1594 DataRow dr = new DataRow();
1595 rd.reportDataRows.addDataRow(dr);
1597 for (int c = 0; c < reportCols.size(); c++) {
1598 if(reportCols.get(c)!=null) {
1599 DataColumnType dct = (DataColumnType) reportCols.get(c);
1600 DataValue dv = new DataValue();
1601 dr.addDataValue(dv);
1602 dv.setDisplayValue(ds.getString(r, c));
1603 dv.setColName(dct.getColName());
1604 dv.setColId(dct.getColId());
1605 dv.setNowrap(nvl(dct.getNowrap(),"null").equals("false")?"null":nvl(dct.getNowrap(),"null"));
1606 StringBuffer indentation = new StringBuffer("");
1607 if(dct.getIndentation()!=null && dct.getIndentation()>0) {
1608 for (int indent=0; indent< dct.getIndentation(); indent++) {
1609 indentation.append("\t");
1611 dv.setNowrap("true");
1613 dv.setIndentation(indentation.toString());
1614 if(dct.isVisible()) {
1616 dv.setVisible(true);
1617 dv.setAlignment(dct.getDisplayAlignment());
1618 dv.setDisplayTotal(dct.getDisplayTotal());
1619 dv.setDisplayName(dct.getDisplayName());
1621 if (nvl(dct.getDrillDownURL()).length() > 0) {
1623 if(dv.getDisplayValue().length() > 0) {
1624 dv.setDrillDownURL(parseDrillDownURL(r, /* c, */ds, dct,request, childReportFormFields));
1625 dv.setDrillDowninPoPUp(dct.isDrillinPoPUp()!=null?dct.isDrillinPoPUp():false);
1628 if (dv.getDisplayValue().length() == 0) {
1629 //dv.setDisplayValue("[NULL]");
1630 dv.setDisplayValue("");
1635 dv.setVisible(false);
1638 //System.out.println("in Linear report b4" + dr.getFormatId() + dr.getBgColorHtml() + dv.getDisplayValue());
1640 if(dr.getFormatId()!=null)
1641 ((FormatProcessor) formatProcessors.get(c)).setHtmlFormatters(dv, dr, true);
1643 ((FormatProcessor) formatProcessors.get(c)).setHtmlFormatters(dv, dr, false);
1645 //System.out.println("in Linear report After" + dr.getFormatId() + dr.getBgColorHtml() + dv.getDisplayValue());
1648 reportDataList.add(dr);
1650 rd.setReportDataList(reportDataList);
1651 //Only if rownumber options is needed
1652 //rd.addRowNumbers(pageNo, getPageSize());
1654 if (colDataTotalsLinear == null)
1655 colDataTotalsLinear = generateColumnDataTotalsLinear(new ArrayList(reportCols), userId,
1656 getDbInfo(),request);
1657 if (displayColTotals && colDataTotalsLinear != null) {
1658 String totalLabel = "Total";
1659 if (getReportDataSize() > getPageSize())
1660 totalLabel += "<br><font size=1>(for all pages)</font>";
1662 rd.setColumnDataTotalsLinear(colDataTotalsLinear, totalLabel);
1664 // Please note the below function doesn't set the visibility for dv since this is set in this function. - Sundar
1665 rd.applyVisibility();
1668 } // loadHiveLinearReportData
1671 public int getHiveReportCount(String sql) throws RaptorException {
1672 //select t from (select count(*) t from (select * from program)x)x1;
1674 String countSql = "select t from (select count(*) t from ("+ sql + ")" + (Globals.isPostgreSQL() || Globals.isMySQL() ?" AS ":"") + " x) AS x1";
1678 String dbInfo = getDBInfo();
1679 System.out.println("SQL getReportCount()- " + countSql);
1681 ds = ConnectionUtils.getDataSet(countSql, dbInfo);
1684 if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
1686 org.onap.portalsdk.analytics.util.RemDbInfo remDbInfo = new org.onap.portalsdk.analytics.util.RemDbInfo();
1687 dbType = remDbInfo.getDBType(dbInfo);
1688 } catch (Exception ex) {
1689 throw new RaptorException(ex);
1692 if( ds.getRowCount()>0) {
1693 count = Integer.parseInt(ds.getString(0,0));
1695 } catch (NumberFormatException ex) {}
1701 /*private*/ public ReportFormFields getChildReportFormFields( HttpServletRequest request, String URL ) throws RaptorException {
1702 String childReportID = getReportID(URL);
1704 ReportRuntime ddRr = (new ReportHandler()).loadReportRuntime(request, childReportID,
1707 ReportFormFields ddReportFormFields = ddRr.getReportFormFields();
1708 return ddReportFormFields;
1711 private String getReportID(String URL) {
1713 int pos = URL.toLowerCase().indexOf("c_master=")+9;
1714 String reportID = "";
1715 if(URL.toLowerCase().indexOf("&", pos)!=-1)
1716 reportID = URL.substring(pos, URL.toLowerCase().indexOf("&", pos));
1718 reportID = URL.substring(pos);
1722 /*private*/ public String parseDrillDownURL(int rowIdx, /* int colIdx, */DataSet ds, DataColumnType dct, HttpServletRequest request, ReportFormFields ddReportFormFields)
1723 throws RaptorException {
1724 Vector viewActions = DataCache.getDataViewActions();
1725 javax.servlet.http.HttpSession session = request.getSession();
1727 StringBuffer dUrl = new StringBuffer();
1729 //String childReportID = getReportID(dct.getDrillDownURL());
1731 //ReportRuntime ddRr = (new ReportHandler()).loadReportRuntime(request, childReportID,
1734 //ReportFormFields ddReportFormFields = ddRr.getReportFormFields();
1736 boolean isViewAction = false;
1738 String requestParam ="";
1739 for (int k = 0; k < viewActions.size(); k++)
1740 if (dct.getDrillDownURL().equals(
1741 AppUtils.getBaseActionURL() + ((String) viewActions.get(k))))
1742 isViewAction = true;
1744 // Drill-down to record details
1745 String param = nvl(dct.getDrillDownParams()); // i.e.
1746 // "c_master=[bo1.RECID$]"
1747 param = param.substring(AppUtils.getBaseActionParam().length() + 1,
1748 param.length() - 1); // i.e. "bo1.RECID$"
1749 param = param.replace('.', '_'); // i.e. "bo1.RECID$"
1751 dUrl.append(AppUtils.getBaseActionParam());
1752 dUrl.append(java.net.URLEncoder.encode(ds.getString(rowIdx, param.toLowerCase())));
1754 // Drill-down to another report
1755 // Replacing col ids with values
1756 String param = nvl(dct.getDrillDownParams());
1757 while (param.indexOf('[') >= 0) {
1758 int startIdx = param.indexOf('[');
1759 int endIdx = param.indexOf(']');
1760 StringBuffer sb = new StringBuffer();
1761 if(startIdx>endIdx) {
1762 if (endIdx < param.length() - 1)
1763 sb.append(param.substring(endIdx + 1));
1764 param = sb.toString();
1768 sb.append(param.substring(0, startIdx));
1770 if (param.charAt(startIdx + 1) == '!') {
1771 // Parameter is a form field value
1772 String fieldId = param.substring(startIdx + 2, endIdx);
1773 String fieldValue = (String) reportParamValues.get(fieldId);
1775 sb.append(java.net.URLEncoder.encode(nvl(fieldValue)));
1776 //TODO Add a else if condition to check whether the param is from request Param
1777 //TODO make a unique symbol like #
1778 }else if (param.charAt(startIdx + 1) == '#') {
1780 String fieldId = param.substring(startIdx + 2, endIdx);
1781 String fieldValue = request.getParameter(fieldId);
1782 sb.append(java.net.URLEncoder.encode(nvl(fieldValue)));
1785 // Parameter is a column value
1786 String fieldValue = "";
1787 String colValue = null;
1788 String colId = null;
1789 if (param.indexOf('!') < 0 || param.indexOf('!') > endIdx)
1790 colId = param.substring(startIdx + 1, endIdx);
1792 // Need to use NVL(column, form field)
1793 colId = param.substring(startIdx + 1, param.indexOf('!'));
1795 String fieldId = param.substring(param.indexOf('!') + 1, endIdx);
1796 FormField ff = getFormField(fieldId);
1797 if (ff.getFieldType().equals(FormField.FFT_TEXTAREA)) {
1798 fieldValue = reportParamValues.getParamValueforTextAreaDrilldown(fieldId);
1800 fieldValue = (String) reportParamValues.get(fieldId);
1803 DataColumnType column = getColumnById(colId);
1804 String columnName = "";
1805 int groupColumn = 0;
1807 if(column.getColName().startsWith("[")) {
1809 columnName = column.getDisplayName();
1810 for(ddReportFormFields.resetNext(); ddReportFormFields.hasNext(); ) {
1811 FormField ff = ddReportFormFields.getNext();
1812 if(ff.getFieldDisplayName().toLowerCase().equals(columnName.toLowerCase())) {
1814 sb.delete(sb.lastIndexOf("&")+1, sb.length());
1815 sb.append(ff.getFieldName()+"=");
1819 if (groupColumn == 0 || (groupColumn == 1 && groupMatch == 1)) {
1820 String dependsOn = column.getDependsOnFormField();
1821 if(nvl(dependsOn).length()>0)
1822 System.out.println("DependsOn " + dependsOn);
1823 if (column != null) {
1824 // if (column.getColType().equals(AppConstants.CT_DATE))
1825 //if (!nvl(column.getColFormat(), AppConstants.DEFAULT_DATE_FORMAT)
1826 // .equals(AppConstants.DEFAULT_DATE_FORMAT))
1827 // Use extra column instead
1828 //commented out below line usually for Visual
1829 //colId += AppConstants.DD_COL_EXTENSION;
1830 colValue = ds.getString(rowIdx, colId.toLowerCase());
1831 // if SQL-Based and drill-down param is a date, decode
1832 // it to the expected Oracle format **/
1833 if (getReportDefType().equals(AppConstants.RD_SQL_BASED))
1834 if (!getColumnNoParseDateFlag(column))
1835 if (ReportParamDateValueParser.isDateParam(colValue))
1836 colValue = ReportParamDateValueParser
1837 .formatDateParamValue(colValue);
1840 String suppressValues = "|" + nvl(dct.getDrillDownType()) + "|";
1841 if (suppressValues.length() > 2
1842 && suppressValues.indexOf("|" + colValue + "|") >= 0)
1843 // Parameter value is suppressed and not passed to the
1844 // drill-down report
1847 sb.append(java.net.URLEncoder.encode(nvl(colValue, fieldValue)));
1849 sb.delete(sb.lastIndexOf("&")+1, sb.length());
1853 if (endIdx < param.length() - 1)
1854 sb.append(param.substring(endIdx + 1));
1855 param = sb.toString();
1857 if(Globals.getPassRequestParamInDrilldown()) {
1858 if(param.indexOf('#') < 0) {
1859 String[] reqParameters = Globals.getRequestParams().split(",");
1860 String[] sessionParameters = Globals.getSessionParams().split(",");
1861 for (int i = 0; i < reqParameters.length; i++) {
1862 if(request.getParameter(reqParameters[i])!=null) {
1863 if(!reqParameters[i].toUpperCase().startsWith("FF")){
1864 if(param.length()>0) {
1865 param += "&" + reqParameters[i]+"="
1866 + request.getParameter(reqParameters[i]);
1868 param += "&" + reqParameters[i]+"="
1869 + request.getParameter(reqParameters[i]);
1875 for (int i = 0; i < sessionParameters.length; i++) {
1876 if(session.getAttribute(sessionParameters[i].toUpperCase())!=null) {
1877 if(!sessionParameters[i].toUpperCase().startsWith("FF")){
1878 if(param.length()>0) {
1879 param += "&" + sessionParameters[i].toUpperCase()+"="
1880 + (String)session.getAttribute(sessionParameters[i].toUpperCase());
1882 param += "&" + sessionParameters[i].toUpperCase()+"="
1883 + (String)session.getAttribute(sessionParameters[i].toUpperCase());
1888 param += "&" + sessionParameters[i].toUpperCase()+"="
1889 + (String)session.getAttribute(sessionParameters[i]);
1897 dUrl.append(param.toString());
1899 dUrl.append(AppConstants.RI_DISPLAY_CONTENT);
1902 if(dct.isDrillinPoPUp()==null || (!dct.isDrillinPoPUp().booleanValue())) {
1903 dUrl.append(AppConstants.RI_SHOW_BACK_BTN);
1907 dUrl.append(AppConstants.DRILLDOWN_INDEX);
1908 int index = Integer.parseInt(nvl(AppUtils.getRequestValue(request, AppConstants.DRILLDOWN_INDEX), "0"));
1910 int form_index = Integer.parseInt(nvl(AppUtils.getRequestValue(request, AppConstants.FORM_DRILLDOWN_INDEX), "0"));
1911 index = index>0 ? --index : 0;
1912 form_index = form_index>0 ? --form_index : 0;*/
1913 request.setAttribute(AppConstants.DRILLDOWN_INDEX, Integer.toString(index));
1914 /*session.setAttribute(AppConstants.DRILLDOWN_INDEX, Integer.toString(index));
1915 request.setAttribute(AppConstants.FORM_DRILLDOWN_INDEX, Integer.toString(form_index));
1916 session.setAttribute(AppConstants.FORM_DRILLDOWN_INDEX, Integer.toString(form_index));*/
1918 dUrl.append("=" + AppUtils.getRequestNvlValue(request, AppConstants.DRILLDOWN_INDEX));
1920 //TODO Add a if condition to check whether the param is request Param
1923 if (dUrl.length() > 0)
1924 dUrl.insert(0, ((dct.getDrillDownURL()).indexOf('&') > 0) ? '&' : '&');
1925 dUrl.insert(0, AppUtils.getDrillActionURL()+dct.getDrillDownURL());
1927 //debugLogger.debug(" [[[[[[[[[[[[[[[[ " + dUrl);
1929 return dUrl.toString();
1930 } // parseDrillDownURL
1932 /** *********************************************************************************** */
1934 public DataRow generateColumnDataTotalsLinear(ArrayList reportCols, String userId,
1935 String dbInfo, HttpServletRequest request) throws RaptorException {
1938 displayColTotals = false;
1939 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1941 DataColumnType dct = (DataColumnType) iter.next();
1943 if (nvl(dct.getDisplayTotal()).length() > 0) {
1944 displayColTotals = true;
1947 } // if checking dct
1951 if (displayColTotals) {
1954 // DbUtils.executeQuery(generateTotalSQLLinear(reportParamValues,
1956 ds = ConnectionUtils.getDataSet(generateTotalSQLLinear(reportParamValues, userId,request),
1959 for (int c = 0; c < reportCols.size(); c++) {
1960 DataColumnType dct = (DataColumnType) reportCols.get(c);
1961 if ( dct != null ) {
1962 DataValue dv = new DataValue();
1964 dr.addDataValue(dv);
1966 String totalValue = "";
1968 totalValue = ds.getString(0, c);
1969 if (nvl(dct.getDisplayTotal()).length() > 0
1970 && (!dct.getDisplayTotal().equals(AppConstants.TOTAL_SUM_ID)))
1971 totalValue = nvl(AppConstants.TOTAL_FUNCTIONS.getNameById(dct
1972 .getDisplayTotal()))
1973 + ": " + totalValue;
1974 dv.setDisplayValue(Utils.truncateTotalDecimals(totalValue));
1976 dv.setAlignment(dct.getDisplayAlignment());
1977 dv.setColName(dct.getColName());
1978 dv.setDisplayName(dct.getDisplayName());
1979 dv.setColId(dct.getColId());
1980 dv.setNowrap(nvl(dct.getNowrap(),"null").equals("false")?"null":nvl(dct.getNowrap(),"null"));
1981 StringBuffer indentation = new StringBuffer("");
1982 if(dct.getIndentation()!=null && dct.getIndentation()>0) {
1983 for (int indent=0; indent< dct.getIndentation(); indent++) {
1984 indentation.append("\t");
1986 dv.setNowrap("true");
1988 dv.setIndentation(indentation.toString());
1989 dv.setDisplayTotal(dct.getDisplayTotal());
1996 } // generateColumnDataTotalsLinear
1998 private Vector generateDataTotalsCrossTab(String rowColPos, String userId, HttpServletRequest request)
1999 throws RaptorException {
2000 String sql = getWholeSQL();
2001 Vector dataTotals = new Vector();
2003 boolean displayTotals = ((rowColPos.length() == 0) || (getCrossTabDisplayTotal(
2004 rowColPos).length() > 0));
2005 if (rowColPos.equals(AppConstants.CV_COLUMN))
2006 displayColTotals = displayTotals;
2007 else if (rowColPos.equals(AppConstants.CV_ROW))
2008 displayRowTotals = displayTotals;
2010 if (displayTotals) {
2012 // DbUtils.executeQuery(generateTotalSQLCrossTab(reportParamValues,
2013 // rowColPos, userId));
2014 String executeSql = generateTotalSQLCrossTab(
2015 sql, rowColPos, userId, request, reportParamValues);
2016 DataSet ds = ConnectionUtils.getDataSet(executeSql, getDbInfo());
2018 for (int i = 0; i < ds.getRowCount(); i++) {
2019 Vector headerValues = new Vector();
2020 String totalValue = null;
2023 for (Iterator iter = getAllColumns().iterator(); iter.hasNext();) {
2024 DataColumnType dct = (DataColumnType) iter.next();
2026 if (rowColPos.length() > 0
2027 && nvl(dct.getCrossTabValue()).equals(rowColPos)) {
2028 DataValue dataValue = new DataValue();
2029 dataValue.setBold(true);
2030 dataValue.setAlignment("center");
2031 dataValue.setDisplayValue(ds.getString(i, cPos++));
2032 headerValues.add(dataValue);
2034 //headerValues.add(ds.getString(i, cPos++));
2036 else if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_VALUE))
2037 totalValue = ds.getString(i, cPos++);
2040 dataTotals.add(new CrossTabTotalValue(headerValues, Utils
2041 .truncateTotalDecimals(totalValue)));
2046 } // generateDataTotalsCrossTab
2048 /** *********************************************************************************** */
2050 public void hideColVisual(String colId) {
2051 visualManager.hideColumn(colId);
2052 if (pageDataCache != null)
2053 pageDataCache.columnVisualShowHide(colId, false);
2056 public void showColVisual(String colId) {
2057 visualManager.showColumn(colId);
2058 if (pageDataCache != null)
2059 pageDataCache.columnVisualShowHide(colId, true);
2062 public void sortColVisual(String colId) {
2063 visualManager.setSortByColumn(colId);
2066 pageDataCache = null;
2070 /** *********************************************************************************** */
2072 public String generateDistinctValuesSQL(DataColumnType dct, String userId, HttpServletRequest request) throws RaptorException {
2073 return super.generateDistinctValuesSQL(reportParamValues, dct, userId, request);
2074 } // generateDistinctValuesSQL
2076 public String getDbInfo() {
2077 return this.cr.getDbInfo();
2080 private String fixSQL(StringBuffer sql) {
2082 int pos_f_format = 0;
2083 int pos_t_format = 0;
2086 String alias = null;
2087 if(sql.indexOf("SELECT", 7)!= -1) {
2088 pos = sql.indexOf("SELECT", 7);
2089 if(sql.indexOf("TO_CHAR", pos)!= -1){
2090 pos = sql.indexOf("TO_CHAR", pos);
2091 if(sql.indexOf("999",pos)!= -1) {
2092 pos = sql.indexOf("999",pos);
2093 pos_f_format = sql.lastIndexOf(", '", pos);
2094 if(pos_f_format == -1 || (pos - pos_f_format > 10)) {
2095 pos_f_format = sql.lastIndexOf(",'", pos);
2099 if(sql.indexOf("')", pos)!= -1) {
2100 pos_t_format = sql.indexOf("')", pos);
2101 //debugLogger.debug("pos_t - " + pos_t_format + " " + pos);
2102 if(pos_t_format == -1 || (pos_t_format - pos > 20)) {
2103 pos_t_format = sql.indexOf("' )", pos);
2106 else if (pos_t_format != -1)
2108 format = sql.substring(pos_f_format+3, pos_t_format);
2109 //alias = sql.substring(pos_t_format+3, pos_t_format+6);
2110 pos_alias = sql.indexOf(" ", pos_t_format);
2111 alias = sql.substring(pos_alias+1, pos_alias+4);
2116 if(sql.indexOf(alias)!=-1) {
2117 pos = sql.indexOf(alias);
2118 //debugLogger.debug(pos + " " + alias.length()+1 + "\n" + sql);
2119 sql.delete(pos,pos+4);
2120 sql.insert(pos, "TO_NUMBER("+alias+", '"+format+"')),'"+ format + "')");
2121 pos = sql.lastIndexOf("SUM", pos);
2123 pos = sql.lastIndexOf("AVG", pos);
2125 pos = sql.lastIndexOf("COUNT", pos);
2127 pos = sql.lastIndexOf("STDDEV", pos);
2129 pos = sql.lastIndexOf("VARIANCE", pos);
2130 sql.insert(pos, "TO_CHAR (");
2135 //debugLogger.debug("Alias|" + alias + "| Format " + format);
2136 //debugLogger.debug(sql.toString());
2137 return sql.toString();
2140 public String parseReportSQL(String sql) throws RaptorException {
2141 StringBuffer parsedSQL = new StringBuffer();
2143 Vector updatedReportCols = new Vector();
2146 int lastParsePos = curSQLParsePos;
2147 String lastToken = null;
2148 logger.debug(EELFLoggerDelegate.debugLogger, ("Flat File parseReportSQL ******* SQL " + sql));
2149 sql = sql.replaceAll("([\\s]*\\() (?!FROM)", "(");
2150 sql = sql.replaceAll("[\\s]*\\)", ")");
2151 //sql = sql.replaceAll("[dD][eE][cC][oO][dD][eE] ", "decode");
2152 //sql = sql.replaceAll("[\\s]*\\(", "(");
2153 //sql = replaceNewLine(sql, "decode ", "decode");
2154 //sql = replaceNewLine(sql, "DECODE ", "decode");
2155 //sql = replaceNewLine(sql, "Decode ", "decode");
2157 String nextToken = getNextSQLParseToken(sql, true);
2158 String dbInfo = getDbInfo();
2159 boolean isCYMBALScript = false;
2160 if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
2162 org.onap.portalsdk.analytics.util.RemDbInfo remDbInfo = new org.onap.portalsdk.analytics.util.RemDbInfo();
2163 String dbType = remDbInfo.getDBType(dbInfo);
2164 if (dbType.equals("DAYTONA") && !(nextToken.toUpperCase().equals("SELECT"))) {
2165 isCYMBALScript = true;
2167 } catch (Exception ex) {
2168 throw new RaptorException(ex);
2171 if ( isCYMBALScript == false ) {
2172 while (nextToken.length() > 0) {
2173 //System.out.println("LastToken " + lastToken + " NextToken " + nextToken);
2176 if (parsedSQL.length() == 0) {
2177 if (nextToken.toUpperCase().equals("SELECT"))
2178 parsedSQL.append("SELECT ");
2180 throw new org.onap.portalsdk.analytics.error.ValidationException(
2181 "The SQL must start with the SELECT keyword.");
2182 } else if (nextToken.toUpperCase().equals("DISTINCT")
2183 && parsedSQL.toString().equals("SELECT ")) {
2184 parsedSQL.append("DISTINCT ");
2185 } else if (nextToken.equals("*")
2186 && (parsedSQL.toString().equals("SELECT ") || parsedSQL.toString().equals(
2187 "SELECT DISTINCT "))) {
2188 throw new org.onap.portalsdk.analytics.error.ValidationException(
2189 "You cannot use \"SELECT *\". Please specify select columns/expressions.");
2190 } else if (nextToken.toUpperCase().equals("FROM")) {
2191 if (lastToken != null) {
2192 updatedReportCols.add(getParseSQLDataColumn(lastToken, null, parsedSQL,
2193 updatedReportCols, false));
2197 parsedSQL.append(" \n");
2198 while (lastParsePos < sql.length()
2199 && Character.isWhitespace(sql.charAt(lastParsePos)))
2201 parsedSQL.append(sql.substring(lastParsePos));
2204 //System.out.println("Next Token " + nextToken);
2205 if (nextToken.charAt(nextToken.length() - 1) == ',') {
2206 // The token ends with ,
2207 nextToken = nextToken.substring(0, nextToken.length() - 1);
2209 if (nextToken.length() == 0) {
2210 if (lastToken != null) {
2211 updatedReportCols.add(getParseSQLDataColumn(lastToken, null,
2212 parsedSQL, updatedReportCols, false));
2214 } // else just comma => ignore it
2216 //System.out.println("Next Token " + nextToken + " is Here" + " Last Token " + lastToken);
2217 if (lastToken != null) {
2218 updatedReportCols.add(getParseSQLDataColumn(lastToken, nextToken,
2219 parsedSQL, updatedReportCols, false));
2222 updatedReportCols.add(getParseSQLDataColumn(nextToken, null,
2223 parsedSQL, updatedReportCols, false));
2226 // The token doesn't end with ,
2227 if (lastToken == null)
2228 lastToken = nextToken;
2230 String token = getNextSQLParseToken(sql, false);
2231 //System.out.println(" ********** " + token + " " + lastToken);
2232 if (!token.toUpperCase().equals("FROM"))
2233 throw new org.onap.portalsdk.analytics.error.ValidationException(
2234 "|FROM keyword or a comma expected after [" + nextToken
2236 //System.out.println("Next Token " + nextToken);
2237 updatedReportCols.add(getParseSQLDataColumn(lastToken, nextToken,
2238 parsedSQL, updatedReportCols, false));
2244 lastParsePos = curSQLParsePos;
2245 nextToken = getNextSQLParseToken(sql, true);
2247 } else { // if CYMBAL Script
2248 nextToken = getNextCYMBALSQLParseToken(sql, true);
2250 Matcher matcher = null;
2251 String extracted = null;
2252 while (nextToken.length() > 0) {
2253 if (lastToken == null) lastToken = nextToken;
2255 if( lastToken.toUpperCase().equals("DO DISPLAY")) {
2256 re = Pattern.compile("each(.*)\\[.(.*?)\\]"); //\\[(.*?)\\]
2257 matcher = re.matcher(nextToken);
2258 if (matcher.find()) {
2259 extracted = matcher.group();
2260 re = Pattern.compile("\\[(.*?)\\]");
2261 matcher = re.matcher(nextToken);
2262 if(matcher.find()) {
2263 extracted = matcher.group();
2264 extracted = extracted.substring(1,extracted.length()-2);
2265 StringTokenizer sToken = new StringTokenizer(extracted);
2266 while(sToken.hasMoreTokens()) {
2267 updatedReportCols.add(getParseSQLDataColumn("", sToken.nextToken(),
2268 new StringBuffer(""), updatedReportCols, true));
2275 lastToken = nextToken;
2276 nextToken = getNextCYMBALSQLParseToken(sql, true);
2280 if (updatedReportCols.size() == 0)
2281 throw new org.onap.portalsdk.analytics.error.ValidationException(
2282 "The SQL statement must have at least one column in the SELECT clause.");
2285 return parsedSQL.toString();
2289 private String getNextCYMBALSQLParseToken(String sql, boolean updateParsePos) {
2290 int braketCount = 0;
2291 boolean isInsideQuote = false;
2292 StringBuffer nextToken = new StringBuffer();
2293 for (int idxNext = curSQLParsePos; idxNext < sql.length(); idxNext++) {
2294 char ch = sql.charAt(idxNext);
2297 nextToken.append(ch);
2301 return nextToken.toString();
2302 } // getNextSQLParseToken
2304 private String getNextSQLParseToken(String sql, boolean updateParsePos) {
2305 int braketCount = 0;
2306 boolean isInsideQuote = false;
2307 StringBuffer nextToken = new StringBuffer();
2308 for (int idxNext = curSQLParsePos; idxNext < sql.length(); idxNext++) {
2309 char ch = sql.charAt(idxNext);
2311 if (Character.isWhitespace(ch) || ch == ',') {
2313 nextToken.append(ch);
2315 if (nextToken.length() == 0)
2317 else if (braketCount == 0 && (!isInsideQuote)) {
2319 curSQLParsePos = idxNext + ((ch == ',') ? 1 : 0);
2321 } else if (ch != ',' && nextToken.charAt(nextToken.length() - 1) != ' ')
2322 nextToken.append(' ');
2324 nextToken.append(ch);
2326 if (ch == '(' || ch == '[')
2328 else if (ch == ')' || ch == ']')
2330 else if (ch == '\''/* ||ch=='\"' */)
2331 isInsideQuote = (!isInsideQuote);
2335 return nextToken.toString();
2336 } // getNextSQLParseToken
2338 private DataColumnType getParseSQLDataColumn(String sqlExpression, String colId,
2339 StringBuffer parsedSQL, Vector updatedReportCols, boolean isCYMBALScript) throws RaptorException {
2340 DataColumnType dct = null;
2342 if (colId != null) {
2343 if (!isParseSQLColID(colId))
2344 throw new org.onap.portalsdk.analytics.error.ValidationException(
2347 + "] must either be a valid column id consisting only of letters, numbers, and underscores, or there must be a comma in front of it.");
2349 dct = getColumnById(colId);
2351 // Getting unique column id
2354 for (int i = 0; (i < sqlExpression.length()) && (colIdN < 2); i++)
2355 if (Character.isLetter(sqlExpression.charAt(i))) {
2356 colId += sqlExpression.toLowerCase().charAt(i);
2360 colIdN = getAllColumns().size() + updatedReportCols.size();
2361 for (boolean idAlreadyUsed = true; idAlreadyUsed; colIdN++) {
2362 String newColId = colId + colIdN;
2363 idAlreadyUsed = false;
2365 for (Iterator iter = getAllColumns().iterator(); iter.hasNext();)
2366 if (newColId.equals(((DataColumnType) iter.next()).getColId())) {
2367 idAlreadyUsed = true;
2372 for (Iterator iter = updatedReportCols.iterator(); iter.hasNext();)
2373 if (newColId.equals(((DataColumnType) iter.next()).getColId())) {
2374 idAlreadyUsed = true;
2379 colId += (colIdN - 1);
2383 dct = (new ObjectFactory()).createDataColumnType();
2384 dct.setColId(colId);
2385 dct.setDisplayWidth(10);
2386 dct.setDisplayAlignment("Left");
2387 dct.setVisible(true);
2388 dct.setGroupBreak(false); // ???
2390 boolean isValidIdentifier = Character.isLetterOrDigit(sqlExpression.charAt(0));
2391 for (int i = 0; i < sqlExpression.length(); i++)
2392 if (!(Character.isLetterOrDigit(sqlExpression.charAt(i))
2393 || (sqlExpression.charAt(i) == '_') || (sqlExpression.charAt(i) == '$'))) {
2394 isValidIdentifier = false;
2398 if (isValidIdentifier) {
2399 dct.setDisplayName(sqlExpression);
2401 dct.setDisplayName(colId);
2405 sqlExpression = sqlExpression.replaceAll(", '", ",'");
2406 dct.setDbColName(sqlExpression);
2407 dct.setColName(sqlExpression);
2408 dct.setCalculated(true);
2409 dct.setColType(AppConstants.CT_CHAR);
2410 dct.setDbColType(AppConstants.CT_CHAR);
2411 adjustColumnType(dct); // ???
2413 if(!isCYMBALScript) {
2414 if (parsedSQL.toString().equals("SELECT ")
2415 || parsedSQL.toString().equals("SELECT DISTINCT "))
2416 parsedSQL.append("\n\t");
2418 parsedSQL.append(", \n\t");
2419 parsedSQL.append(sqlExpression);
2420 parsedSQL.append(" ");
2421 parsedSQL.append(colId);
2425 } // getParseSQLDataColumn
2427 private boolean isParseSQLColID(String token) {
2428 if (nvl(token).length() == 0)
2431 for (int i = 0; i < token.length(); i++) {
2432 char ch = token.charAt(i);
2434 if (i == 0 && ch == '_')
2437 if (!(Character.isLetterOrDigit(ch) || ch == '_'))
2442 } // isParseSQLColID
2444 /*private*/ public String parseReportSQLForDrillDownParams(String reportSQL, DataColumnType dataColumnRequest, HttpServletRequest request){
2445 String param = nvl(dataColumnRequest.getDrillDownParams());
2446 String sql = reportSQL;
2448 while (param.indexOf('[', pos) >= 0) {
2449 int startIdx = param.indexOf('[',pos);
2450 int endIdx = param.indexOf(']',startIdx+1);
2452 StringBuffer sb = new StringBuffer();
2454 sb.append(param.substring(0, startIdx));
2457 if (param.charAt(startIdx + 1) == '#') {
2458 // Parameter is a form field value
2459 String fieldId = param.substring(startIdx + 2, endIdx);
2460 String fieldValue = ESAPI.encoder().encodeForSQL( SecurityCodecUtil.getCodec(), request.getParameter(fieldId));
2461 sql = Utils.replaceInString(sql, "[" + fieldId.toUpperCase()+"]", fieldValue );
2467 public List getMapMarkers(ReportData rd, org.onap.portalsdk.analytics.xmlobj.ReportMap xmlmap){
2469 ArrayList markers = new ArrayList();
2471 HashMap colHash = new HashMap();
2473 for(rd.reportDataRows.resetNext(); rd.reportDataRows.hasNext(); rNum++) {
2474 DataRow dr = rd.reportDataRows.getNext();
2475 for(dr.resetNext(); dr.hasNext(); ) {
2476 DataValue dv = dr.getNext();
2477 colHash.put(dv.getColId(), dv.getDisplayValueLinkHtml());
2480 for (int i = 0; i < xmlmap.getMarkers().size(); i ++){
2481 Marker marker = new Marker("", "", "");
2482 org.onap.portalsdk.analytics.xmlobj.Marker m = (org.onap.portalsdk.analytics.xmlobj.Marker) xmlmap.getMarkers().get(i);
2483 String address = (String) colHash.get(m.getAddressColumn());
2484 String data = (String) colHash.get(m.getDataColumn());
2485 marker.setAddress(address);
2486 if (xmlmap.getAddAddressInDataYN() != null && xmlmap.getAddAddressInDataYN().equals("Y")){
2487 marker.setData(address + "<br/>" + data);
2490 marker.setData(data);
2492 marker.setColor(m.getMarkerColor());
2493 markers.add(marker);
2494 System.out.println("%%%%%%%%%%%% marker is : " + address + data);
2504 public ReportParamValues getReportParamValues() {
2505 return reportParamValues;
2508 public String getFormFieldFilled(String title) {
2509 if( getFormFieldList()!=null && reportParamValues!=null && nvl(title).length()>0) {
2510 for (Iterator iter1 = getFormFieldList().getFormField().iterator(); iter1.hasNext();) {
2511 FormFieldType fft = (FormFieldType) iter1.next();
2512 String fieldDisplay = getFormFieldDisplayName(fft);
2513 String fieldId = fft.getFieldId();
2514 if(!fft.getFieldType().equals(FormField.FFT_BLANK) && !fft.getFieldType().equals(FormField.FFT_LIST_MULTI) && !fft.getFieldType().equals(FormField.FFT_TEXTAREA)) {
2515 String paramValue = Utils.oracleSafe(nvl(reportParamValues.getParamValue(fieldId)));
2516 title = Utils.replaceInString(title, fieldDisplay, nvl(
2524 public synchronized Object clone() {
2526 return super.clone();
2527 } catch (CloneNotSupportedException e) {
2528 // this shouldn't happen, since we are Cloneable
2529 throw new InternalError("Cloning throws error.");
2533 public VisualManager getVisualManager() {
2534 return visualManager;
2537 public String getReportSQLWithRowNum(String _orderBy, boolean asc) {
2538 String sql = getWholeSQL();
2539 int closeBracketPos = 0;
2540 // Added reportSQLOnlyFirstPart which has Column information with Rownum
2541 return nvl(getReportSQLOnlyFirstPart()) + " " + sql + ") x ";
2545 public int getDisplayMode() {
2546 return DISPLAY_MODE;
2549 public void setDisplayMode(int mode) {
2550 DISPLAY_MODE = mode;
2553 public int getDateOption() {
2557 public void setDateOption(int dateOption) {
2558 DATE_OPTION = dateOption;
2561 public boolean isDisplayColTotals() {
2562 return displayColTotals;
2565 public void setDisplayColTotals(boolean displayColTotals) {
2566 this.displayColTotals = displayColTotals;
2569 public boolean isDisplayRowTotals() {
2570 return displayRowTotals;
2573 public void setDisplayRowTotals(boolean displayRowTotals) {
2574 this.displayRowTotals = displayRowTotals;
2578 private boolean canPersistLinearReport() {
2579 boolean visibleColExist = false;
2581 if (getDataSourceList().getDataSource().size() > 0) {
2582 for (Iterator iter = getAllColumns().iterator(); iter.hasNext();) {
2583 DataColumnType dct = (DataColumnType) iter.next();
2585 if (dct.isVisible()) {
2586 visibleColExist = true;
2592 return visibleColExist;
2593 } // canPersistLinearReport
2595 public void persistLinearReport(HttpServletRequest request)
2596 throws RaptorException {
2597 if (!canPersistLinearReport())
2600 Connection connection = null;
2602 String userID = AppUtils.getUserID(request);
2603 String reportXML = marshal();
2604 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] Report " + reportID
2605 + " XML marshalled succesfully"));
2608 verifySQLBasedReportAccess(request);
2609 reportSecurity.reportUpdate(request);
2610 connection = DbUtils.startTransaction();
2611 ReportLoader.updateCustomReportRec(connection, this, reportXML);
2612 ReportLoader.createReportLogEntry(connection, reportID, userID,
2613 AppConstants.RLA_UPDATE, "", "");
2614 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] DB update report "
2615 + reportID + " succesfull"));
2616 DbUtils.commitTransaction(connection);
2617 } catch (RaptorException e) {
2618 e.printStackTrace();
2619 DbUtils.rollbackTransaction(connection);
2622 DbUtils.clearConnection(connection);
2624 } // persistLinearReport
2626 public void persistDashboardReport(HttpServletRequest request)
2627 throws RaptorException {
2629 Connection connection = null;
2631 String userID = AppUtils.getUserID(request);
2632 String reportXML = marshal();
2633 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] Report " + reportID
2634 + " XML marshalled succesfully"));
2637 verifySQLBasedReportAccess(request);
2638 reportSecurity.reportUpdate(request);
2639 connection = DbUtils.startTransaction();
2640 ReportLoader.updateCustomReportRec(connection, this, reportXML);
2641 ReportLoader.createReportLogEntry(connection, reportID, userID,
2642 AppConstants.RLA_UPDATE, "", "");
2643 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] DB update report "
2644 + reportID + " succesfull"));
2645 DbUtils.commitTransaction(connection);
2646 } catch (RaptorException e) {
2647 e.printStackTrace();
2648 DbUtils.rollbackTransaction(connection);
2651 DbUtils.clearConnection(connection);
2653 } // persistDashboardReport
2654 public String getTotalSql() {
2658 public void setTotalSql(String totalSql) {
2659 this.totalSql = totalSql;
2662 public void setTriggerFormFieldCheck( ReportFormFields FormFieldList, FormField selectedFormField) {
2664 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
2665 FormField ff = (FormField) iter.next();
2666 if(!ff.getFieldName().equals(selectedFormField.getFieldName())) {
2667 if(nvl(ff.getBaseSQL()).length()>0 && ff.getBaseSQL().indexOf("["+selectedFormField.getFieldDisplayName() +"]")!= -1) {
2668 selectedFormField.setTriggerOtherFormFields(true);
2676 public void setTriggerThisFormFieldCheck( ReportFormFields FormFieldList, FormField selectedFormField) {
2678 String sql = nvl(selectedFormField.getBaseSQL()).length()>0 ? selectedFormField.getBaseSQL():"";
2679 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
2680 FormField ff = (FormField) iter.next();
2681 if(!ff.getFieldName().equals(selectedFormField.getFieldName())) {
2682 if(sql.indexOf("["+ff.getFieldDisplayName() +"]")!= -1) {
2683 selectedFormField.setTriggerThisFormfield(true);
2692 private boolean isAllowEdit(HttpServletRequest request) {
2693 boolean allowEdit = false;
2694 String userId = AppUtils.getUserID(request);
2696 if( AppUtils.isAdminUser(request) || AppUtils.isSuperUser(request) ) {
2699 if(getOwnerID().equals(userId)) allowEdit = true;
2700 else allowEdit = false;
2702 } catch (RaptorException ex) {
2707 public ReportJSONRuntime createReportJSONRuntime(HttpServletRequest request, ReportData rd) {
2708 String userId = AppUtils.getUserID(request);
2709 ObjectMapper mapper = new ObjectMapper();
2710 ReportJSONRuntime reportJSONRuntime = new ReportJSONRuntime();
2711 reportJSONRuntime.setReportTitle(getReportTitle());
2712 //reportJSONRuntime.setReportSubTitle(getReportSubTitle());
2713 reportJSONRuntime.setReportID(getReportID());
2714 reportJSONRuntime.setReportDescr(getReportDescr());
2715 reportJSONRuntime.setReportName(getReportName());
2716 reportJSONRuntime.setReportSubTitle(getReportSubTitle());
2717 reportJSONRuntime.setAllowSchedule(isAllowSchedule());
2718 reportJSONRuntime.setAllowEdit(isAllowEdit(request));
2719 reportJSONRuntime.setColIdxTobeFreezed(getFrozenColumnId());
2720 reportJSONRuntime.setNumFormCols(getNumFormColsAsInt());
2722 reportJSONRuntime.setBackBtnURL("");
2723 String chartType = getChartType();
2724 boolean displayChart = (nvl(chartType).length()>0)&&getDisplayChart();
2725 boolean displayChartWizard = getDisplayChart();
2726 reportJSONRuntime.setChartAvailable(displayChart);
2727 reportJSONRuntime.setChartWizardAvailable(displayChartWizard);
2728 reportJSONRuntime.setDisplayData(!isDisplayOptionHideData());
2729 reportJSONRuntime.setDisplayForm(!isDisplayOptionHideForm());
2730 reportJSONRuntime.setHideFormFieldsAfterRun(isHideFormFieldAfterRun());
2731 reportJSONRuntime.setDisplayExcel(!isDisplayOptionHideExcelIcons());
2732 reportJSONRuntime.setDisplayPDF(!isDisplayOptionHidePDFIcons());
2733 ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
2734 ArrayList<FormFieldJSON> formFieldJSONList = new ArrayList<FormFieldJSON>();
2735 if(getReportFormFields()!=null) {
2736 formFieldJSONList = new ArrayList<FormFieldJSON>(getReportFormFields().size());
2737 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
2738 formFieldValues = new ArrayList<IdNameValue>();
2739 FormField ff = (FormField) iter.next();
2740 ff.setDbInfo(getDbInfo());
2741 FormFieldJSON ffJSON = new FormFieldJSON();
2742 ffJSON.setFieldId(ff.getFieldName());
2743 ffJSON.setFieldType(ff.getFieldType());
2744 ffJSON.setFieldDisplayName(ff.getFieldDisplayName());
2745 ffJSON.setHelpText(ff.getHelpText());
2746 ffJSON.setValidationType(ff.getValidationType());
2747 ffJSON.setVisible(ff.isVisible());
2748 //ffJSON.setTriggerOtherFormFields(ff.getDependsOn());
2749 IdNameList lookup = null;
2750 lookup = ff.getLookupList();
2751 String selectedValue = "";
2753 IdNameList lookupList = null;
2754 boolean readOnly = false;
2756 if(!ff.hasPredefinedList) {
2757 IdNameSql lu = (IdNameSql) lookup;
2758 String SQL = lu.getSql();
2759 oldSQL = lu.getSql();
2760 setTriggerFormFieldCheck( getReportFormFields(), ff);
2761 ffJSON.setTriggerOtherFormFields(ff.isTriggerOtherFormFields());
2762 SQL = parseAndFillReq_Session_UserValues(request, SQL, userId);
2763 SQL = parseAndFillWithCurrentValues(request, SQL, ff);
2764 String defaultSQL = lu.getDefaultSQL();
2765 defaultSQL = parseAndFillReq_Session_UserValues(request, defaultSQL, userId);
2766 defaultSQL = parseAndFillWithCurrentValues(request, defaultSQL, ff);
2767 lookup = new IdNameSql(-1,SQL,defaultSQL);
2769 lookupList = lookup;
2771 lookup.loadUserData(0, "", ff.getDbInfo(), ff.getUserId());
2772 } catch (Exception e ){ e.printStackTrace(); //throw new RaptorRuntimeException(e);
2775 lookup.trimToSize();
2777 String[] requestValue = request.getParameterValues(ff.getFieldName());
2779 if(lookup != null && lookup.size() > 0) {
2780 for (lookup.resetNext(); lookup.hasNext();) {
2781 IdNameValue value = lookup.getNext();
2782 readOnly = value.isReadOnly();
2783 if(requestValue != null && Arrays.asList(requestValue).contains(value.getId())) {
2784 //if(value.getId().equals(requestValue))
2785 value.setDefaultValue(true);
2786 } else if (AppUtils.nvl(ff.getDefaultValue()).length()>0) {
2787 if(ff.getDefaultValue().equals(value.getId())) {
2788 value.setDefaultValue(true);
2791 if(!(ff.getFieldType().equals(FormField.FFT_CHECK_BOX) || ff.getFieldType().equals(FormField.FFT_COMBO_BOX) || ff.getFieldType().equals(FormField.FFT_LIST_BOX)
2792 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI)) && value.isDefaultValue())
2793 formFieldValues.add(value);
2794 else if(ff.getFieldType().equals(FormField.FFT_CHECK_BOX) || ff.getFieldType().equals(FormField.FFT_COMBO_BOX) || ff.getFieldType().equals(FormField.FFT_LIST_BOX)
2795 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI)) {
2796 formFieldValues.add(value);
2801 if(requestValue!=null && requestValue.length>0) {
2802 IdNameValue value = new IdNameValue(requestValue[0], requestValue[0], true, false);
2803 formFieldValues.add(value);
2808 setTriggerFormFieldCheck( getReportFormFields(), ff);
2809 ffJSON.setTriggerOtherFormFields(ff.isTriggerOtherFormFields());
2810 String[] requestValue = request.getParameterValues(ff.getFieldName());
2811 if(requestValue!=null && requestValue.length>0) {
2812 IdNameValue value = new IdNameValue(requestValue[0], requestValue[0], true, false);
2813 formFieldValues.add(value);
2814 } else if (AppUtils.nvl(ff.getDefaultValue()).length()>0) {
2815 IdNameValue value = new IdNameValue(ff.getDefaultValue(), ff.getDefaultValue(), true, false);
2816 formFieldValues.add(value);
2819 if(!ff.hasPredefinedList) {
2820 if(oldSQL != null && !oldSQL.equals("") && lookup!=null) {
2821 ((IdNameSql)lookup).setSQL(oldSQL);
2827 ffJSON.setFormFieldValues(formFieldValues);
2828 formFieldJSONList.add(ffJSON);
2831 reportJSONRuntime.setFormFieldList(formFieldJSONList);
2832 //reportJSONRuntime.setReportDataColumns(get);
2834 Map<String,Object> dvJSON = null;
2837 reportJSONRuntime.setTotalRows(getReportDataSize());
2838 ArrayList<ColumnHeader> colList = new ArrayList<ColumnHeader>();
2839 ArrayList<Map<String,Object>> reportDataRows = new ArrayList<Map<String,Object>>();
2840 for(rd.reportColumnHeaderRows.resetNext(); rd.reportColumnHeaderRows.hasNext(); ) {
2842 ColumnHeaderRow chr = rd.reportColumnHeaderRows.getNext();
2843 for(chr.resetNext(); chr.hasNext(); ) {
2844 colList.add(chr.getNext());
2847 if(getReportDataSize() > 0) {
2849 for(rd.reportDataRows.resetNext(); rd.reportDataRows.hasNext(); count++) {
2850 dvJSON = new HashMap<String,Object>();
2851 DataRow dr = rd.reportDataRows.getNext();
2852 for(dr.resetNext(); dr.hasNext(); ) {
2853 DataValue dv = dr.getNext();
2855 dvJSON.put(dv.getColId(), dv);
2856 } catch (Exception ex) {
2857 ex.printStackTrace();
2861 reportDataRows.add(dvJSON);
2864 reportJSONRuntime.setReportDataColumns(colList);
2865 reportJSONRuntime.setReportDataRows(reportDataRows);
2866 //reportJSONRuntime.setSqlWhole(getWholeSQL());
2867 reportJSONRuntime.setPageSize(getPageSize());
2871 if(getReportDataSize() <= 0) {
2872 reportJSONRuntime.setMessage(getEmptyMessage());
2874 reportJSONRuntime.setSqlWhole(getWholeSQL());
2875 return reportJSONRuntime;
2879 public ReportJSONRuntime createFormFieldJSONRuntime(HttpServletRequest request) {
2880 String userId = AppUtils.getUserID(request);
2881 ObjectMapper mapper = new ObjectMapper();
2882 ReportJSONRuntime reportJSONRuntime = new ReportJSONRuntime();
2883 reportJSONRuntime.setReportTitle(getReportTitle());
2884 reportJSONRuntime.setReportID(getReportID());
2885 reportJSONRuntime.setReportName(getReportName());
2886 reportJSONRuntime.setReportSubTitle(getReportSubTitle());
2887 reportJSONRuntime.setNumFormCols(getNumFormColsAsInt());
2888 ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
2889 ArrayList<FormFieldJSON> formFieldJSONList = new ArrayList<FormFieldJSON>();
2890 if(reportFormFields!=null) {
2891 formFieldJSONList = new ArrayList<FormFieldJSON>(reportFormFields.size());
2892 for (Iterator iter = reportFormFields.iterator(); iter.hasNext();) {
2893 formFieldValues = new ArrayList<IdNameValue>();
2894 FormField ff = (FormField) iter.next();
2895 FormFieldJSON ffJSON = new FormFieldJSON();
2896 ffJSON.setFieldId(ff.getFieldName());
2897 ffJSON.setFieldType(ff.getFieldType());
2898 ffJSON.setFieldDisplayName(ff.getFieldDisplayName());
2899 ffJSON.setHelpText(ff.getHelpText());
2900 ffJSON.setValidationType(ff.getValidationType());
2901 ffJSON.setFormFieldValues(formFieldValues);
2902 ffJSON.setVisible(ff.isVisible());
2903 formFieldJSONList.add(ffJSON);
2905 for (Iterator iter = reportFormFields.iterator(); iter.hasNext();) {
2906 formFieldValues = new ArrayList<IdNameValue>();
2907 FormField ff = (FormField) iter.next();
2908 ff.setDbInfo(getDbInfo());
2909 for (Iterator iter1 = formFieldJSONList.iterator(); iter1.hasNext();) {
2910 FormFieldJSON ffJSON = (FormFieldJSON) iter1.next();
2911 if(ffJSON.getFieldId().equals(ff.getFieldName())) {
2912 IdNameList lookup = null;
2913 lookup = ff.getLookupList();
2914 String selectedValue = "";
2916 IdNameList lookupList = null;
2917 boolean readOnly = false;
2919 if(!ff.hasPredefinedList) {
2920 IdNameSql lu = (IdNameSql) lookup;
2921 String SQL = lu.getSql();
2922 oldSQL = lu.getSql();
2923 setTriggerFormFieldCheck( getReportFormFields(), ff);
2924 ffJSON.setTriggerOtherFormFields(ff.isTriggerOtherFormFields());
2925 setTriggerThisFormFieldCheck(getReportFormFields(), ff);
2926 SQL = parseAndFillReq_Session_UserValues(request, SQL, userId);
2927 SQL = parseAndFillOtherFormfieldValues(request, SQL, userId, formFieldJSONList);
2928 //SQL = parseAndFillWithCurrentValues(formGrid,SQL, ff);
2929 String defaultSQL = lu.getDefaultSQL();
2930 defaultSQL = parseAndFillReq_Session_UserValues(request, defaultSQL, userId);
2931 //defaultSQL = parseAndFillWithCurrentValues(formGrid,defaultSQL, ff);
2932 lookup = new IdNameSql(-1,SQL,defaultSQL);
2934 lookupList = lookup;
2936 lookup.loadUserData(0, "", ff.getDbInfo(), ff.getUserId());
2937 } catch (Exception e ){ e.printStackTrace(); //throw new RaptorRuntimeException(e);
2940 lookup.trimToSize();
2942 String requestValue = request.getParameter(ff.getFieldName());
2943 ArrayList<String> requestValueList = new ArrayList<String>();
2944 requestValueList.add(requestValue);
2946 /*if(ff.isTriggerThisFormfield()) {
2947 refreshFormFieldsWithLatestValue(request, userId, ff, formFieldJSONList);
2951 for (lookup.resetNext(); lookup.hasNext();) {
2952 IdNameValue value = lookup.getNext();
2953 readOnly = value.isReadOnly();
2954 if(nvl(requestValue).length()>0) {
2955 if(value.getId().equals(requestValue))
2956 value.setDefaultValue(true);
2958 formFieldValues.add(value);
2963 setTriggerFormFieldCheck( getReportFormFields(), ff);
2964 ffJSON.setTriggerOtherFormFields(ff.isTriggerOtherFormFields());
2965 String[] requestValue = request.getParameterValues(ff.getFieldName());
2966 if(requestValue!=null && requestValue.length>0) {
2967 IdNameValue value = new IdNameValue(requestValue[0], requestValue[0], true, false);
2968 formFieldValues.add(value);
2969 } else if (AppUtils.nvl(ff.getDefaultValue()).length()>0) {
2970 IdNameValue value = new IdNameValue(ff.getDefaultValue(), ff.getDefaultValue(), true, false);
2971 formFieldValues.add(value);
2974 if(!ff.hasPredefinedList) {
2975 if(oldSQL != null && !oldSQL.equals("") && lookup!=null) {
2976 ((IdNameSql)lookup).setSQL(oldSQL);
2981 //if(!ff.isTriggerThisFormfield()) {
2982 ffJSON.setFormFieldValues(formFieldValues);
2992 reportJSONRuntime.setFormFieldList(formFieldJSONList);
2993 //reportJSONRuntime.setReportDataColumns(get);
2995 return reportJSONRuntime;
3000 private String parseAndFillOtherFormfieldValues(HttpServletRequest request, String SQL, String userId, ArrayList<FormFieldJSON> formFieldJSONList) {
3001 ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
3002 String selectedValue = "";
3003 String displayName = "";
3004 for (Iterator iter1 = formFieldJSONList.iterator(); iter1.hasNext();) {
3005 FormFieldJSON ffJSON = (FormFieldJSON) iter1.next();
3006 displayName = ffJSON.getFieldDisplayName();
3007 ArrayList<IdNameValue> formfieldvalues = ffJSON.getFormFieldValues();
3008 for (int i = 0; i< formfieldvalues.size(); i++) {
3009 IdNameValue formfieldItem = formfieldvalues.get(i);
3010 if(formfieldItem.isDefaultValue()) {
3011 selectedValue = formfieldItem.getId();
3014 SQL = Utils.replaceInString(SQL, "["+displayName+"]", selectedValue);
3020 private void refreshFormFieldsWithLatestValue(HttpServletRequest request, String userId, FormField ff_src, ArrayList<FormFieldJSON> formFieldJSONList) {
3021 ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
3022 List<String> requestValueList = null;
3023 IdNameList lookup = null;
3024 lookup = ff_src.getLookupList();
3025 IdNameSql lu = (IdNameSql) lookup;
3028 String oldDefaultSQL = "";
3029 String defaultSQL = "";
3030 IdNameList lookupList = null;
3033 oldSQL = lu.getSql();
3034 oldDefaultSQL = lu.getDefaultSQL();
3035 defaultSQL = lu.getDefaultSQL();
3037 boolean readOnly = false;
3038 for (Iterator iter1 = formFieldJSONList.iterator(); iter1.hasNext();) {
3039 FormFieldJSON ffJSON = (FormFieldJSON) iter1.next();
3040 if((ffJSON.getFieldId().equals(ff_src.getFieldName())) && ffJSON.isVisible()) {
3041 for (Iterator iter = reportFormFields.iterator(); iter.hasNext();) {
3042 formFieldValues = new ArrayList<IdNameValue>();
3043 FormField ff = (FormField) iter.next();
3044 if(!ff.getFieldName().equals(ff_src.getFieldName())) {
3045 //IdNameList lookup = null;
3046 //lookup = ff.getLookupList();
3047 String selectedValue = "";
3051 String [] requestParam = request.getParameterValues(ff.getFieldName());
3052 if(requestParam != null) {
3053 requestValueList = Arrays.asList(request.getParameterValues(ff.getFieldName()));
3056 requestValueList = new ArrayList<String>();
3060 if(nvl(ff_src.getBaseSQL()).length()>0 && ff_src.getBaseSQL().indexOf("["+ff.getFieldDisplayName() +"]")!= -1) {
3063 if(!ff_src.hasPredefinedList) {
3064 String formatSelected = null;
3065 if(ff_src.getFieldType().equals(FormField.FFT_LIST_MULTI) || ff_src.getFieldType().equals(FormField.FFT_CHECK_BOX)) {
3066 formatSelected = formatSelectedItems(requestValueList, ff_src.getFieldType());
3068 formatSelected = requestValueList.size()>0?requestValueList.get(0):"";
3069 SQL = Utils.replaceInString(SQL, "["+ff_src.getFieldDisplayName()+"]", formatSelected);
3070 defaultSQL = Utils.replaceInString(defaultSQL, "["+ff_src.getFieldDisplayName()+"]", formatSelected);
3071 defaultSQL = parseAndFillWithCurrentValues(request, defaultSQL, ff_src);
3072 defaultSQL = parseAndFillReq_Session_UserValues(request, defaultSQL, userId);
3073 SQL = parseAndFillReq_Session_UserValues(request, SQL, userId);
3074 SQL = parseAndFillWithCurrentValues(request, SQL, ff_src);
3077 } catch (Exception ex) {
3078 ex.printStackTrace();
3087 if(nvl(ff_src.getBaseSQL()).length()>0) {
3088 lookup = new IdNameSql(-1,SQL,defaultSQL);
3089 lookupList = lookup;
3091 lookup.loadUserData(0, "", ff_src.getDbInfo(), ff_src.getUserId());
3092 } catch (Exception e ){
3093 e.printStackTrace(); //throw new RaptorRuntimeException(e);
3095 if(!ff_src.hasPredefinedList) {
3096 lookup.trimToSize();
3097 for (lookup.resetNext(); lookup.hasNext();) {
3098 IdNameValue value = lookup.getNext();
3099 readOnly = value.isReadOnly();
3100 formFieldValues.add(value);
3103 ffJSON.setFormFieldValues(formFieldValues);
3105 if(!ff_src.hasPredefinedList) {
3106 if(oldSQL != null && !oldSQL.equals("")) {
3107 ((IdNameSql)lookup).setSQL(oldSQL);
3109 if(oldDefaultSQL != null && !oldDefaultSQL.equals("")) {
3110 ((IdNameSql)lookup).setDefaultSQL(oldDefaultSQL);
3120 private void triggerOtherFormFieldsWithThisValue(HttpServletRequest request, String userId, FormField ff_src, ArrayList<String> requestValueList, ArrayList<FormFieldJSON> formFieldJSONList) {
3121 ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
3122 //ArrayList<FormFieldJSON> formFieldJSONList = new ArrayList<FormFieldJSON>();
3123 for (Iterator iter = reportFormFields.iterator(); iter.hasNext();) {
3124 formFieldValues = new ArrayList<IdNameValue>();
3125 FormField ff = (FormField) iter.next();
3126 if(!ff_src.getFieldName().equals(ff.getFieldName())) {
3127 for (Iterator iter1 = formFieldJSONList.iterator(); iter1.hasNext();) {
3128 FormFieldJSON ffJSON = (FormFieldJSON) iter1.next();
3129 if(ffJSON.getFieldId().equals(ff.getFieldName()) && ffJSON.isVisible()) {
3130 if(nvl(ff.getBaseSQL()).length()>0 && ff.getBaseSQL().indexOf("["+ff_src.getFieldDisplayName() +"]")!= -1) {
3131 IdNameList lookup = null;
3132 lookup = ff.getLookupList();
3133 String selectedValue = "";
3135 String oldDefaultSQL = "";
3136 IdNameList lookupList = null;
3137 boolean readOnly = false;
3140 if(!ff.hasPredefinedList) {
3141 IdNameSql lu = (IdNameSql) lookup;
3142 String SQL = lu.getSql();
3143 oldSQL = lu.getSql();
3144 oldDefaultSQL = lu.getDefaultSQL();
3145 String defaultSQL = lu.getDefaultSQL();
3146 String formatSelected = null;
3147 if(ff_src.getFieldType().equals(FormField.FFT_LIST_MULTI) || ff_src.getFieldType().equals(FormField.FFT_CHECK_BOX)) {
3148 formatSelected = formatSelectedItems(requestValueList, ff.getFieldType());
3151 formatSelected = requestValueList.size()>0?requestValueList.get(0):"";
3152 SQL = Utils.replaceInString(SQL, "["+ff_src.getFieldDisplayName()+"]", formatSelected);
3153 defaultSQL = Utils.replaceInString(defaultSQL, "["+ff_src.getFieldDisplayName()+"]", formatSelected);
3154 defaultSQL = parseAndFillWithCurrentValues(request, defaultSQL, ff_src);
3155 defaultSQL = parseAndFillReq_Session_UserValues(request, defaultSQL, userId);
3156 SQL = parseAndFillReq_Session_UserValues(request, SQL, userId);
3157 SQL = parseAndFillWithCurrentValues(request, SQL, ff_src);
3158 lookup = new IdNameSql(-1,SQL,defaultSQL);
3159 lookupList = lookup;
3161 lookup.loadUserData(0, "", ff.getDbInfo(), ff.getUserId());
3162 } catch (Exception e ){
3163 e.printStackTrace(); //throw new RaptorRuntimeException(e);
3166 lookup.trimToSize();
3170 for (lookup.resetNext(); lookup.hasNext();) {
3171 IdNameValue value = lookup.getNext();
3172 readOnly = value.isReadOnly();
3173 // if(nvl(requestValue).length()>0) {
3174 // if(value.getId().equals(requestValue))
3175 // value.setDefaultValue(true);
3177 formFieldValues.add(value);
3181 ffJSON.setFormFieldValues(formFieldValues);
3183 if(!ff.hasPredefinedList) {
3184 if(oldSQL != null && !oldSQL.equals("")) {
3185 ((IdNameSql)lookup).setSQL(oldSQL);
3187 if(oldDefaultSQL != null && !oldDefaultSQL.equals("")) {
3188 ((IdNameSql)lookup).setDefaultSQL(oldDefaultSQL);
3191 } catch (Exception ex) {
3192 ex.printStackTrace();
3204 public String formatSelectedItems(List selectedItems, String type) {
3205 StringBuffer value = new StringBuffer("");
3207 boolean multiple = false;
3208 if(type.equals("LIST_MULTI_SELECT"))
3210 //multiple = (selectedItems.size()>1);
3211 for(Iterator iter = selectedItems.iterator(); iter.hasNext(); ) {
3213 String entry = (String) iter.next();
3214 if(count == 1 && multiple)
3216 //if(type.equals(FormField.FFT_CHECK_BOX))
3217 /*if(type.equals(FormField.FFT_CHECK_BOX))
3218 value.append("'"+Utils.oracleSafe(entry)+"'");
3219 else*/ if (type.equals(FormField.FFT_LIST_MULTI))
3220 value.append("'"+Utils.oracleSafe(entry)+"'");
3221 else if(type.equals(FormField.FFT_LIST_BOX))
3222 value.append(Utils.oracleSafe(entry));
3224 value.append("'"+Utils.oracleSafe(entry)+"'");
3225 if((count < selectedItems.size()) && multiple)
3227 if((count == selectedItems.size()) && multiple)
3231 if(value.length()>0)
3232 return value.toString();
3237 public String parseAndFillWithCurrentValues(HttpServletRequest request, String sql, FormField source_Formfield) {
3239 if (getFormFieldList() != null) {
3240 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
3241 FormFieldType fft = (FormFieldType) iter.next();
3242 String fieldId = fft.getFieldId();
3243 String fieldDisplay = getFormFieldDisplayName(fft);
3244 String formfield_value = "";
3245 List<String> selectedItems = new ArrayList<String>();
3246 //Added so that Combo Box in old RAPTOR definition is translated to List box
3247 if(fft.getFieldType().equals(FormField.FFT_COMBO_BOX)) {
3248 fft.setFieldType(FormField.FFT_LIST_BOX);
3250 if(!fft.getFieldType().equals(FormField.FFT_BLANK)) {
3251 //if(source_Formfield==null || (source_Formfield!=null && !fft.getFieldId().equals(source_Formfield.getFieldName()))) {
3253 // Add param base sql
3254 if(fft.getFieldType().equals(FormField.FFT_LIST_MULTI) || fft.getFieldType().equals(FormField.FFT_CHECK_BOX)) {
3255 if(request.getParameterValues(fieldId)!=null && request.getParameterValues(fieldId).length > 0) {
3257 selectedItems = Arrays.asList(request.getParameterValues(fieldId));
3258 formfield_value = formatSelectedItems(selectedItems, fft.getFieldType());
3260 formfield_value = "";
3262 } else if(fft.getFieldType().equals(FormField.FFT_RADIO_BTN)) {
3263 if(request.getParameter(fieldId)!=null) {
3264 formfield_value = request.getParameter(fieldId);
3266 formfield_value = "";
3268 } else if (fft.getFieldType().equals(FormField.FFT_HIDDEN)) {
3269 if(request.getParameter(fieldId)!=null) {
3270 formfield_value = request.getParameter(fieldId);
3272 formfield_value = "";
3274 } else if((fft.getFieldType().equals(FormField.FFT_TEXT) || fft.getFieldType().equals(FormField.FFT_TEXTAREA)) &&
3275 (!fft.getValidationType().equals(FormField.VT_DATE) && !fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)&&
3276 !fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) && !fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) ) {
3277 if(request.getParameter(fieldId)!=null) {
3278 formfield_value = request.getParameter(fieldId);
3280 formfield_value = "";
3282 } else if (fft.getValidationType().equals(FormField.VT_DATE) || fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)||
3283 fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) || fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
3284 /*if(formGrid.hasFellow(fieldId, true)) {
3285 Datebox tb = (Datebox) formGrid.getFellowIfAny(fieldId, true);
3287 formfield_value = tb.getText();
3288 } catch (WrongValueException ex) {
3289 formfield_value = "";
3291 if(AppUtils.nvl(formfield_value).length() > 0) {
3292 if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)) {
3293 if(formGrid.hasFellow(fieldId+"_Hr", true)) {
3294 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3295 formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3297 } else if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN)) {
3298 if(formGrid.hasFellow(fieldId+"_Min", true)) {
3299 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3300 //formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3301 Label hiddenLbMin = (Label) formGrid.getFellowIfAny(fieldId+"_Min", true);
3302 formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue();
3305 } else if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
3306 if(formGrid.hasFellow(fieldId+"_Sec", true)) {
3307 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3308 //formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3309 Label hiddenLbMin = (Label) formGrid.getFellowIfAny(fieldId+"_Min", true);
3310 //formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue();
3311 Label hiddenLbSec = (Label) formGrid.getFellowIfAny(fieldId+"_Sec", true);
3312 formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue()+ ":" +hiddenLbSec.getValue();
3319 formfield_value = "";
3321 } else if ((fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)||
3322 fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) || fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC))) {
3323 /*if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)||
3324 fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) || fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
3325 if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)) {
3326 if(formGrid.hasFellow(fieldId+"_Hr", true)) {
3327 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3328 formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3330 } else if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN)) {
3331 if(formGrid.hasFellow(fieldId+"_Min", true)) {
3332 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3333 //formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3334 Label hiddenLbMin = (Label) formGrid.getFellowIfAny(fieldId+"_Min", true);
3335 formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue();
3338 } else if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
3339 if(formGrid.hasFellow(fieldId+"_Sec", true)) {
3340 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3341 //formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3342 Label hiddenLbMin = (Label) formGrid.getFellowIfAny(fieldId+"_Min", true);
3343 //formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue();
3344 Label hiddenLbSec = (Label) formGrid.getFellowIfAny(fieldId+"_Sec", true);
3345 formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue()+ ":" +hiddenLbSec.getValue();
3351 } else if (fft.getFieldType().equals(FormField.FFT_TEXT_W_POPUP)) {
3352 if(request.getParameter(fieldId)!=null) {
3353 formfield_value = request.getParameter(fieldId);
3355 formfield_value = "";
3357 } else if (fft.getFieldType().equals(FormField.FFT_LIST_BOX)) {
3358 if(request.getParameter(fieldId)!=null) {
3359 formfield_value = request.getParameter(fieldId);
3361 formfield_value = "";
3365 if(nvl(formfield_value).length()>0) {
3366 sql = Utils.replaceInString(sql, fieldDisplay, formfield_value);
3368 sql = Utils.replaceInString(sql, "'"+fieldDisplay+"'", "null");
3369 sql = Utils.replaceInString(sql, fieldDisplay, "null");
3370 //sql = Utils.replaceInString(sql, fieldDisplay, "''");
3377 public String parseAndFillReq_Session_UserValues(HttpServletRequest request, String sql, String user_id) {
3378 HttpSession session = request.getSession();
3380 String[] reqParameters = Globals.getRequestParams().split(",");
3381 String[] sessionParameters = Globals.getSessionParams().split(",");
3382 String[] scheduleSessionParameters = Globals.getSessionParamsForScheduling().split(",");
3385 if(AppUtils.nvl(sql).length()>0) {
3386 for (int i = 0; i < reqParameters.length; i++) {
3387 if(!reqParameters[i].startsWith("ff") && (request.getParameter(reqParameters[i].toUpperCase())!=null && request.getParameter(reqParameters[i].toUpperCase()).length() > 0))
3388 sql = Utils.replaceInString(sql, "[" + reqParameters[i].toUpperCase()+"]", request.getParameter(reqParameters[i].toUpperCase()) );
3389 else if (request.getParameter(reqParameters[i])!=null && request.getParameter(reqParameters[i]).length() > 0)
3390 sql = Utils.replaceInString(sql, "[" + reqParameters[i].toUpperCase()+"]", request.getParameter(reqParameters[i]) );
3393 for (int i = 0; i < scheduleSessionParameters.length; i++) {
3394 //debugLogger.debug(" Session " + " scheduleSessionParameters[i] " + scheduleSessionParameters[i].toUpperCase() + " " + request.getParameter(scheduleSessionParameters[i]));
3395 if(request.getParameter(scheduleSessionParameters[i])!=null && request.getParameter(scheduleSessionParameters[i]).trim().length()>0 )
3396 sql = Utils.replaceInString(sql, "[" + scheduleSessionParameters[i].toUpperCase()+"]", request.getParameter(scheduleSessionParameters[i]) );
3397 if(request.getAttribute(scheduleSessionParameters[i])!=null && ((String)request.getAttribute(scheduleSessionParameters[i])).trim().length()>0 )
3398 sql = Utils.replaceInString(sql, "[" + scheduleSessionParameters[i].toUpperCase()+"]", (String) request.getAttribute(scheduleSessionParameters[i]) );
3402 for (int i = 0; i < sessionParameters.length; i++) {
3403 //if(!sessionParameters[i].startsWith("ff"))
3404 //fieldSQL = Utils.replaceInString(fieldSQL, "[" + sessionParameters[i].toUpperCase()+"]", (String)session.getAttribute(sessionParameters[i].toUpperCase()) );
3406 if (session.getAttribute(sessionParameters[i])!=null && ((String)session.getAttribute(sessionParameters[i])).length() > 0) {
3407 //debugLogger.debug(" Session " + " sessionParameters[i] " + sessionParameters[i] + " " + (String)session.getAttribute(sessionParameters[i]));
3408 sql = Utils.replaceInString(sql, "[" + sessionParameters[i].toUpperCase()+"]", (String)session.getAttribute(sessionParameters[i]) );
3412 sql = Utils.replaceInString(sql, "[USERID]", user_id);
3413 sql = Utils.replaceInString(sql, "[USER_ID]", user_id);
3414 sql = Utils.replaceInString(sql, "[LOGGED_USERID]", user_id);