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;
89 import com.fasterxml.jackson.databind.ObjectMapper;
93 * This class is part of <B><I>RAPTOR (Rapid Application Programming Tool for OLAP Reporting)</I></B><BR/>
96 * --------------------------------------------------------------------------------------------------<BR/>
97 * <B>ReportRuntime.java</B> - This class involves in running, downloading RAPTOR reports.
98 * --------------------------------------------------------------------------------------------------<BR/>
101 * <U>Change Log</U><BR/><BR/>
103 * 27-Aug-2009 : Version 8.5 (Sundar); <UL><LI>Order by logic is restored for DAYTONA.</LI></UL>
104 * 13-Aug-2009 : Version 8.5 (Sundar); <UL><LI>Removing order by logic is rollbacked.</LI></UL>
105 * 22-Jun-2009 : Version 8.4 (Sundar); <UL><LI>Bug while parsing SQL for text download is fixed.</LI></UL>
109 public class ReportRuntime extends ReportWrapper implements Cloneable, Serializable {
111 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ReportRuntime.class);
113 //TODO DELETE IF PARSE SQL is not working
114 private int curSQLParsePos = 0;
116 private String xmlFileURL = null;
118 private String xmlFileName = null;
120 private String flatFileName = null;
122 private String excelPageFileName = null;
124 private int reportDataSize = -1;
126 private boolean displayChart = true;
128 private boolean displayForm = true;
130 private boolean displayContent = true;
132 private boolean reportRunLogged = false; // Used to avoid multiple
133 // entries in the report log
134 // when executing with different
135 // params or going to next page
137 private DataSet chartDataCache = null;
139 private ReportData pageDataCache = null;
141 private int cachedPageNo = -1;
143 private String cachedSQL = null; // For display purposes only
145 private String wholeSQL = null; // For display purposes only
147 private String totalSql = null; // For display purposes only
149 private ReportParamValues reportParamValues = null;
151 private ReportParamValuesForPDFExcel reportParamValuesFPE = null;
153 private ReportFormFields reportFormFields = null;
155 private VisualManager visualManager = null;
157 private CrossTabOrderManager crossTabOrderManager = null;
159 private boolean displayColTotals = false;
161 private boolean displayRowTotals = false;
163 private DataRow colDataTotalsLinear = null;
165 private Vector colDataTotalsCrosstab = null;
167 private Vector rowDataTotalsCrosstab = null;
169 private String grandTotalCrosstab = null;
171 public static int DISPLAY_DATA_ONLY = 1;
172 public static int DISPLAY_CHART_ONLY = 2;
173 public static int DISPLAY_CHART_AND_DATA = 3;
175 public static final int DATE_OPTION_MONTHLY = 1;
176 public static final int DATE_OPTION_YEARLY = 2;
177 public static final int DATE_OPTION_DAILY = 3;
180 private int DISPLAY_MODE = 0;
182 private int DATE_OPTION = -1;
185 * private ReportRuntime(CustomReport cr, String reportID,
186 * HttpServletRequest request) { super(cr, reportID);
188 * reportParamValues = new ReportParamValues(this); reportFormFields = new
189 * ReportFormFields(this);
191 * if(request!=null) setParamValues(request); } // ReportRuntime
193 private ReportRuntime(CustomReportType crType, String reportID, HttpServletRequest request,
194 String ownerID, String createID, String createDate, String updateID,
195 String updateDate, String menuID, boolean menuApproved) throws RaptorException {
196 super(crType, reportID, ownerID, createID, createDate, updateID, updateDate, menuID,
198 initializeReportRuntime(request);
201 public ReportRuntime(ReportWrapper rw) throws RaptorException {
205 public ReportRuntime(ReportWrapper rw, HttpServletRequest request)throws RaptorException {
207 initializeReportRuntime(request);
210 private void initializeReportRuntime(HttpServletRequest request) throws RaptorException {
211 reportFormFields = new ReportFormFields(this, request);
212 setParamValues(request, true, true);
214 visualManager = new VisualManager();
215 } // initializeReportRuntime
217 // public void setReportFormFields(HttpServletRequest request) {
218 // reportFormFields = new ReportFormFields(this, request);
219 // setParamValues(request, true, true);
222 public static ReportRuntime unmarshal(String reportXML, String reportID)
223 throws RaptorException {
224 return unmarshal(reportXML, reportID, null);
227 public static ReportRuntime unmarshal(String reportXML, String reportID,
228 HttpServletRequest request) throws RaptorException {
229 CustomReportType crType = ReportWrapper.unmarshalCR(reportXML);
230 ObjectFactory objFactory = new ObjectFactory();
232 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] Report [" + reportID + "]: XML unmarshalled"));
234 return new ReportRuntime(crType, reportID, request, null, null, null, null, null, null,
239 public String getXmlFileURL() {
243 public String getXmlFileName() {
247 public String getFlatFileName() {
251 public String getExcelPageFileName() {
252 return excelPageFileName;
255 public int getReportDataSize() {
256 return reportDataSize;
259 public boolean getDisplayChart() {
263 public boolean getDisplayForm() {
267 public boolean getDisplayContent() {
268 return displayContent;
271 public int getCachedPageNo() {
275 public String getCachedSQL() {
279 public boolean isDashboardType() throws RaptorException {
280 return ReportLoader.isDashboardType(getReportID());
284 public void setXmlFileURL(String xmlFileURL) {
285 this.xmlFileURL = xmlFileURL;
288 public void setXmlFileName(String xmlFileName) {
289 this.xmlFileName = xmlFileName;
292 public void setFlatFileName(String flatFileName) {
293 this.flatFileName = flatFileName;
296 public void setExcelPageFileName(String excelPageFileName) {
297 this.excelPageFileName = excelPageFileName;
300 /*private*/ public void setReportDataSize(int reportDataSize) {
301 this.reportDataSize = reportDataSize;
304 private void setDisplayForm(boolean displayForm) {
305 this.displayForm = displayForm;
308 private void setDisplayContent(boolean displayContent) {
309 this.displayContent = displayContent;
312 public void setDisplayFlags(boolean isFirstAccess, boolean forceDisplayContent) {
314 setDisplayForm(true);
316 if (forceDisplayContent)
317 setDisplayContent(true);
318 else if (Globals.getDisplayFormBeforeRun())
320 setDisplayContent(false);
322 setDisplayContent(true);
324 setDisplayContent(true);
326 setDisplayContent(true);
328 if (Globals.getIncludeFormWithData())
329 setDisplayForm(true);
330 else if (Globals.getDisplayFormBeforeRun())
331 setDisplayForm(false);
333 setDisplayForm(true);
337 public void logReportRun(String userID, String executionTime, String formFields) throws RaptorException {
341 ReportLoader.createReportLogEntry(null, reportID, userID, AppConstants.RLA_RUN,executionTime,formFields );
342 reportRunLogged = true;
345 public void logReportExecutionTime(String userId, String executionTime, String action, String formFields) throws RaptorException {
346 ReportLoader.createReportLogEntryForExecutionTime(null, reportID, userId,executionTime , action, formFields);
349 public void logReportExecutionTimeFromLogList (String userId, String executionTime, String formFields) throws RaptorException {
350 ReportLoader.createReportLogEntryForExecutionTime(null, reportID, userId,executionTime , AppConstants.RLA_FROM_LOG, formFields);
353 public void resetVisualSettings() {
354 boolean haveToResetCachedData = (visualManager.getSortByColId().length() > 0);
355 visualManager = new VisualManager();
357 if (haveToResetCachedData)
358 pageDataCache = null;
360 if (pageDataCache != null)
361 pageDataCache.resetVisualSettings();
362 } // resetVisualSettings
364 /** ************** ReportParamValues processing *************** */
366 public boolean setParamValues(HttpServletRequest request, boolean resetParams, boolean refresh) throws RaptorException {
367 boolean paramsUpdated = false;
369 reportFormFields = new ReportFormFields(this, request);
370 reportParamValues = new ReportParamValues(reportFormFields, getReportDefType());
371 // This is called even in the wizard page. Hence this condition.
372 if((ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)!=null)
373 reportParamValuesFPE = new ReportParamValuesForPDFExcel(reportFormFields, getReportDefType());
374 paramsUpdated = true;
376 reportRunLogged = false;
377 } else if (request != null) {
378 paramsUpdated = reportParamValues.setParamValues(request,refresh);
380 // This is called even in the wizard page. Hence this condition.
381 if((ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)!=null) {
382 if(reportParamValuesFPE!=null) reportParamValuesFPE.setParamValues(request,refresh);
384 reportParamValuesFPE = new ReportParamValuesForPDFExcel(reportFormFields, getReportDefType());
385 reportParamValuesFPE.setParamValues(request,refresh);
388 reportFormFields = new ReportFormFields(this, request);
389 //added below two lines for dashboard default value
390 reportParamValues = new ReportParamValues(reportFormFields, getReportDefType());
391 reportParamValues.setParamValues(request,refresh);
393 reportParamValuesFPE = new ReportParamValuesForPDFExcel(reportFormFields, getReportDefType());
394 reportParamValuesFPE.setParamValues(request,refresh);
399 setReportDataSize(-1);
400 chartDataCache = null;
401 pageDataCache = null;
404 crossTabOrderManager = null;
406 colDataTotalsLinear = null;
407 colDataTotalsCrosstab = null;
408 rowDataTotalsCrosstab = null;
409 grandTotalCrosstab = null;
411 resetVisualSettings();
414 displayChart = (request.getParameter(AppConstants.RI_DISPLAY_CHART) == null) ? !isDisplayOptionHideChart() : request.getParameter("display_chart")
417 return paramsUpdated;
420 public String getParamValue(String key) {
421 //reportParamValues.printValues();
422 return reportParamValues.getParamValue(key);
425 public String getParamDisplayValue(String key) {
426 //reportParamValues.printValues();
427 return reportParamValues.getParamDisplayValue(key);
430 public Enumeration getParamKeys() {
431 return reportParamValues.keys();
434 public Enumeration getParamKeysForPDFExcel() {
435 return reportParamValuesFPE.keys();
438 public String getParamValueForPDFExcel(String key) {
439 return reportParamValuesFPE.getParamValue(key);
442 public ArrayList getParamNameValuePairs() {
443 ArrayList paramList = new ArrayList(getReportFormFields().size());
444 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
445 FormField ff = (FormField) iter.next();
446 paramList.add(new IdNameValue(ff.getFieldDisplayName(), reportParamValues
447 .getParamDisplayValue(ff.getFieldName())));
450 } // getParamNameValuePairs
452 public ArrayList getParamNameValuePairsforPDFExcel(HttpServletRequest request, int type /*excel =1; pdf=2*/) {
453 javax.servlet.http.HttpSession session = request.getSession();
454 ArrayList paramList = new ArrayList(getReportFormFields().size());
455 if(session.getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)!=null) {
456 paramList = (ArrayList) session.getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO);
457 if(paramList!=null && paramList.size()>0)
460 //System.out.println(" getParamNamePairs type " + type + " " + Globals.customizeFormFieldInfo());
461 if ( reportParamValuesFPE == null) {
462 reportParamValuesFPE = new ReportParamValuesForPDFExcel(reportFormFields, getReportDefType());
463 reportParamValuesFPE.setParamValues(request,true);
466 String valueString = "";
467 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
468 FormField ff = (FormField) iter.next();
469 if(ff.isVisible() && /*!ff.getFieldType().equals(FormField.FFT_HIDDEN) &&*/ type == 1){
470 valueString = reportParamValuesFPE.getParamDisplayValue(ff.getFieldName());
471 } else if(ff.isVisible() && type != 1) {
472 valueString = reportParamValuesFPE.getParamDisplayValue(ff.getFieldName());
474 if(valueString.equalsIgnoreCase("NULL"))
476 paramList.add(new IdNameValue(ff.getFieldDisplayName(), valueString));
480 String pdfAttachmentKey = AppUtils.getRequestValue(request, "pdfAttachmentKey");
481 boolean isSchedule = false;
482 if(pdfAttachmentKey != null)
484 if(Globals.customizeFormFieldInfo() && type == 2) {
485 String[] sessionParameters = Globals.getSessionParams().split(",");
487 if(session != null && !isSchedule ) {
488 session.setAttribute("login_id", AppUtils.getUserBackdoorLoginId(request));
489 for (int i = 0; i < sessionParameters.length; i++) {
490 if(session.getAttribute(sessionParameters[i])!=null)
491 paramList.add(new IdNameValue(sessionParameters[i].toUpperCase(), (String)session.getAttribute(sessionParameters[i])));
496 //debugLogger.debug("Globals " + Globals.getSessionParamsForScheduling());
497 String[] scheduleSessionParam = Globals.getSessionParamsForScheduling().split(",");
498 for (int i = 0; i < scheduleSessionParam.length; i++) {
499 //debugLogger.debug(" scheduleSessionParam[i] " + scheduleSessionParam[i] + " " + request.getParameter(scheduleSessionParam[i]) );
500 if(request.getParameter(scheduleSessionParam[i])!=null)
501 paramList.add(new IdNameValue(scheduleSessionParam[i].toUpperCase(), request.getParameter(scheduleSessionParam[i])));
506 SimpleDateFormat oracleDateFormat = new SimpleDateFormat("MM/dd/yyyy kk:mm:ss");
507 Date sysdate = oracleDateFormat.parse(ReportLoader.getSystemDateTime());
508 SimpleDateFormat dtimestamp = new SimpleDateFormat(Globals.getScheduleDatePattern());
509 paramList.add(new IdNameValue("DATE", dtimestamp.format(sysdate)+" "+Globals.getTimeZone()));
510 } catch(Exception ex) {}
513 //System.out.println(" In Else getParamNamePairs type " + type);
514 String[] sessionDisplayParameters = Globals.getDisplaySessionParamInPDFEXCEL().split(",");
515 if(session != null && !isSchedule ) {
516 session.setAttribute("login_id", AppUtils.getUserBackdoorLoginId(request));
517 for (int i = 0; i < sessionDisplayParameters.length; i++) {
518 String sessionDispParam = sessionDisplayParameters[i];
519 if(nvl(sessionDispParam).length()>0) {
520 String sessionDispParamArr[] = sessionDispParam.split(";");
521 //System.out.println("Session " + sessionDispParamArr[1] + " " + (String)session.getAttribute(sessionDispParamArr[0]));
522 paramList.add(new IdNameValue(sessionDispParamArr[1], nvl((String)session.getAttribute(sessionDispParamArr[0]),"")));
527 String[] scheduleSessionParam = Globals.getDisplayScheduleSessionParamInPDFEXCEL().split(",");
528 for (int i = 0; i < scheduleSessionParam.length; i++) {
529 String scheduleSessionDispParam = scheduleSessionParam[i];
530 if(nvl(scheduleSessionDispParam).length()>0) {
531 String scheduleSessionDispParamArr[] = scheduleSessionDispParam.split(";");
532 paramList.add(new IdNameValue(scheduleSessionDispParamArr[1], nvl(request.getParameter(scheduleSessionDispParamArr[0]),"")));
537 SimpleDateFormat oracleDateFormat = new SimpleDateFormat("MM/dd/yyyy kk:mm:ss");
538 Date sysdate = oracleDateFormat.parse(ReportLoader.getSystemDateTime());
539 SimpleDateFormat dtimestamp = new SimpleDateFormat(Globals.getScheduleDatePattern());
540 paramList.add(new IdNameValue("Report Date/Time", dtimestamp.format(sysdate)+" "+Globals.getTimeZone()));
541 } catch(Exception ex) {}
545 for (int i = 0; i < paramList.size(); i++) {
546 IdNameValue value = (IdNameValue) paramList.get(i);
547 String name = value.getName().replaceAll(",","~");
550 //request.getSession().setAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO, paramList);
552 } // getParamNameValuePairs
554 /** ************** ReportFormFields processing *************** */
556 public String getFormFieldComments(HttpServletRequest request) {
558 StringBuffer st = new StringBuffer("");
559 if(getFormFieldList()!=null){
560 comment = nvl(getFormFieldList().getComment());
562 if(comment.length()>0) {
563 al = getParamNameValuePairsforPDFExcel(request, 2);
565 //st = new StringBuffer(comment);
566 for (int i=0; i < al.size(); i++) {
567 IdNameValue idNameValue = (IdNameValue)al.get(i);
568 if(nvl(idNameValue.getId()).equals("DATE"))
569 st.append("<b>Date/Time Report Run:</b>"+ idNameValue.getName() +"<br></br>");
572 for (int i=0; i < al.size(); i++) {
573 IdNameValue idNameValue = (IdNameValue)al.get(i);
574 comment = Utils.replaceInString(comment, "["+ idNameValue.getId()+"]", idNameValue.getName());
581 return st.toString();
584 public boolean needFormInput() {
585 return reportFormFields.getFieldCount() > 0;
588 public FormField getFormField(String fieldName) {
589 return reportFormFields.getFormField(fieldName);
592 public ReportFormFields getReportFormFields() {
593 return reportFormFields;
594 } // getReportFormFields
596 /** ************** Report Data processing *************** */
597 public DataSet loadChartData(String userId, HttpServletRequest request) throws RaptorException {
598 if (nvl(getChartType()).length() == 0)
600 if (!getDisplayChart())
603 DataSet ds = chartDataCache;
606 sql = generateChartSQL(reportParamValues, userId, request);
607 String dbInfo = getDBInfo();
608 ds = ConnectionUtils.getDataSet(sql, dbInfo);
609 if (Globals.getCacheChartData())
616 public String getReportDataSQL(String userId, int downloadLimit, HttpServletRequest request) throws RaptorException {
617 String reportSQL = "";
618 if(doesReportContainsGroupFormField()) {
619 reportSQL = generateSubsetSQL(0, downloadLimit,userId, request, true, reportParamValues);
621 reportSQL = generateSubsetSQL(0, downloadLimit,userId, request, false, reportParamValues);
625 public ReportData loadReportData(int pageNo, String userId, int downloadLimit, HttpServletRequest request, boolean download) throws RaptorException {
626 ReportData rd = null;
627 boolean isGoBackAction = AppUtils.getRequestFlag(request, AppConstants.RI_GO_BACK);
629 if (pageNo == cachedPageNo && pageDataCache != null)
632 if(isGoBackAction && rd!=null) return rd;
633 if (rd == null) { // Commented So that Data is refreshed from DB again
634 if (getReportDataSize() < 0)
635 if (getReportType().equals(AppConstants.RT_CROSSTAB))
636 rd = loadCrossTabReportData(pageNo, userId, downloadLimit, request, download);
637 else if (getReportType().equals(AppConstants.RT_LINEAR))
638 rd = loadLinearReportData(pageNo, userId, downloadLimit, request, download);
640 throw new RuntimeException(
641 "[ReportRuntime.loadReportData] Invalid report type");
644 if (Globals.getCacheCurPageData()) {
646 cachedPageNo = pageNo;
648 } // if // Commented So that Data is refreshed from DB again
653 private ReportData loadCrossTabReportData(int pageNo, String userId, int downloadLimit, HttpServletRequest request, boolean download) throws RaptorException {
654 String reportSQL = generateSQL(reportParamValues, userId, request);
655 setWholeSQL(reportSQL);
656 cachedSQL = reportSQL;
657 wholeSQL = reportSQL;
658 List reportCols = getAllColumns();
659 // replace the request parameter specified in the drill down
660 DataColumnType dataColumnRequest = getCrossTabValueColumn();
661 reportSQL = parseReportSQLForDrillDownParams(reportSQL, dataColumnRequest, request);
666 String dbInfo = getDBInfo();
667 StringBuffer colNames = new StringBuffer();
668 StringBuffer colExtraIdNames = new StringBuffer();
669 StringBuffer colExtraDateNames = new StringBuffer();
672 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
673 DataColumnType dc = (DataColumnType) iter.next();
674 //TODO: commented if (dc.isVisible()) {
675 if (colNames.length() > 0)
676 colNames.append(", ");
677 colNames.append(dc.getColId());
678 //TODO uncomment if it's not working} // if
680 // Checking for extra fields necessary for drill-down
681 if (nvl(dc.getDrillDownURL()).length() > 0) {
682 System.out.println("Drilldown URL " + dc.getDrillDownURL());
687 if (reportSQL.toUpperCase().indexOf("GROUP BY ") < 0)
688 colNames.append(colExtraIdNames.toString());
689 colNames.append(colExtraDateNames.toString());
690 //reportSQL = " SELECT ROWNUM rnum, "
691 // + colNames.toString() + " FROM (" + reportSQL + ") ";
693 String rSQL = Globals.getLoadCrosstabReportData();
694 rSQL = rSQL.replace("[colNames.toString()]", colNames.toString());
695 rSQL = rSQL.replace("[reportSQL]", reportSQL);
697 setWholeSQL(reportSQL);
698 if (crossTabOrderManager == null)
699 crossTabOrderManager = new CrossTabOrderManager(this, userId,request);
700 ds = ConnectionUtils.getDataSet(reportSQL, dbInfo);
702 ReportData rd = new ReportData(pageNo, false);
703 ReportFormFields childReportFormFields = null;
704 if(doesReportContainsGroupFormField()) {
705 List reportCols1 = getAllColumns();
706 reportCols = new Vector();
708 for (Iterator iter = reportCols1.iterator(); iter.hasNext();) {
709 DataColumnType dct = (DataColumnType) iter.next();
710 for (int k=0; k<ds.getColumnCount(); k++) {
711 if(dct.getColId().toUpperCase().trim().equals(ds.getColumnName(k).trim())) {
718 if (getFormFieldList() != null) {
719 String paramValue = "";
720 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
721 FormFieldType fft = (FormFieldType) iter.next();
722 if(fft.isGroupFormField()!=null && fft.isGroupFormField().booleanValue()) {
723 paramValue = Utils.oracleSafe(nvl(reportParamValues
724 .getParamValue(fft.getFieldId())));
726 for (Iterator iter1 = reportCols1.iterator(); iter1.hasNext();) {
727 DataColumnType dct = (DataColumnType) iter1.next();
728 if(("["+fft.getFieldName()+ "]").equals(dct.getColName().trim())) {
729 dct.setDisplayName(paramValue);
740 int dataColumnIdx = (rd.reportRowHeaderCols.size() + rd.reportColumnHeaderRows.size())-1;
741 DataColumnType dataColumn = getCrossTabValueColumn();
743 String columnValue = "";
746 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
747 DataColumnType dct = (DataColumnType) iter.next();
749 if (nvl(dct.getDrillDownURL()).length() > 0) {
750 childReportFormFields = getChildReportFormFields(request,dct.getDrillDownURL());
753 if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_ROW)) {
754 RowHeaderCol rhc = new RowHeaderCol();
755 rhc.setColumnTitle(dct.getDisplayName());
756 // rhc.setColumnWidth("10%");
757 //rhc.setColumnWidth(dct.getDisplayWidth() + "%");
758 if(nvl(dct.getDisplayWidthInPxls()).length()<=0) {
759 dct.setDisplayWidthInPxls("100px");
761 if(dct.getDisplayWidthInPxls().endsWith("px"))
762 rhc.setColumnWidth(dct.getDisplayWidthInPxls());
764 rhc.setColumnWidth(dct.getDisplayWidthInPxls()+"px");
766 rhc.setAlignment(dct.getDisplayAlignment());
767 rhc.setDisplayHeaderAlignment(dct.getDisplayHeaderAlignment());
768 rhc.setNowrap(nvl(dataColumn.getNowrap(),"null").equals("false")?"null":nvl(dataColumn.getNowrap(),"null"));
769 rd.reportRowHeaderCols.addRowHeaderCol(rhc);
770 } else if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_COLUMN)) {
771 ColumnHeaderRow chr = new ColumnHeaderRow();
772 chr.setAlignment(dct.getDisplayHeaderAlignment());
773 chr.setRowHeight("15");
774 if(nvl(dct.getDisplayWidthInPxls()).length()<=0) {
775 dct.setDisplayWidthInPxls("80px");
777 if(dct.getDisplayWidthInPxls().endsWith("px"))
778 chr.setDisplayWidth(dct.getDisplayWidthInPxls());
780 chr.setDisplayWidth(dct.getDisplayWidthInPxls()+"px");
782 rd.reportColumnHeaderRows.addColumnHeaderRow(chr);
783 } else if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_VALUE)) {
784 columnValue = dct.getColId();
786 if(!dct.getColId().toLowerCase().endsWith("_sort")) {
787 RowHeaderCol rhc = new RowHeaderCol();
788 rhc.setVisible(false);
789 rd.reportRowHeaderCols.addRowHeaderCol(rhc);
794 //int dataColumnIdx = getCrossTabValueColumnIndex();
795 FormatProcessor formatProcessor = new FormatProcessor(getSemaphoreById(dataColumn
797 getReportDefType().equals(AppConstants.RD_SQL_BASED) ? AppConstants.CT_NUMBER
798 : dataColumn.getColType(), dataColumn.getColFormat(), false);
799 List dataList = new ArrayList();
800 /* //fillup all rows based on rowheaders
801 Vector rowHeaders = crossTabOrderManager.getRowHeaderValues();
802 CrossTabColumnValues crossTabRowValues;
804 for (int i = 0; i < rowHeaders.size(); i++) {
805 if((i+1)==rowHeaders.size()) {
806 crossTabRowValues = (CrossTabColumnValues) rowHeaders.get(i);
807 size = crossTabRowValues.getValuesCount();
811 for (int i = 0; i < size; i++) {
812 dataList.add(new DataRow());
815 for (int i = 0; i < ds.getRowCount(); i++) {
816 Vector rValues = new Vector();
817 Vector cValues = new Vector();
818 Vector cValuesSort = new Vector();
821 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
823 DataColumnType dct = (DataColumnType) iter.next();
824 if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_ROW))
825 rValues.add(addDataValue(dct, ds.getString(i, dct.getColId())));
826 if (nvl(dct.getCrossTabValue()).trim().length()<=0 && !dct.getColId().toLowerCase().endsWith("_sort"))
827 rValues.add(addDataValue(dct, ds.getString(i, dct.getColId())));
828 if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_COLUMN)) {
829 cValues.add(addDataValue(dct, ds.getString(i, dct.getColId())));
830 if(getColumnById(dct.getColId().toLowerCase()+"_sort")!=null)
831 cValuesSort.add(addDataValue(dct, new Integer(ds.getString(i, dct.getColId()+"_sort")).toString()));
835 } catch (ArrayIndexOutOfBoundsException ex ) {continue;}
836 catch (NumberFormatException ex1) {
837 ex1.printStackTrace();
842 DataValue dv = new DataValue();
843 dv.setDisplayValue(ds.getString(i, columnValue));
844 if (nvl(dataColumn.getCrossTabValue()).trim().length()<=0)
845 dv.setVisible(false);
846 dv.setAlignment(dataColumn.getDisplayAlignment());
847 dv.setDisplayTotal(dataColumn.getDisplayTotal());
848 dv.setColName(dataColumn.getColName());
849 dv.setDisplayName(dataColumn.getDisplayName());
850 dv.setColId(dataColumn.getColId());
851 dv.setNowrap(nvl(dataColumn.getNowrap(),"null").equals("false")?"null":nvl(dataColumn.getNowrap(),"null"));
852 /*StringBuffer indentation = new StringBuffer("");
853 if(dataColumn.getIndentation()!=null && dataColumn.getIndentation().intValue()>0) {
854 for (int indent=0; indent < dataColumn.getIndentation(); indent++) {
855 indentation.append("\t");
857 dv.setNowrap("true");
859 dv.setIndentation(indentation.toString());*/
861 if (nvl(dataColumn.getDrillDownURL()).length() > 0) {
862 if(dv.getDisplayValue().length() > 0) {
863 dv.setDrillDownURL(parseDrillDownURL(i, /* dataColumnIdx, */ds, dataColumn,request, childReportFormFields));
864 dv.setDrillDowninPoPUp(dataColumn.isDrillinPoPUp()!=null?dataColumn.isDrillinPoPUp():false);
866 if (dv.getDisplayValue().length() == 0) {
867 //dv.setDisplayValue("[NULL]");
868 dv.setDisplayValue("");
872 rd.setDataValue(rValues, cValues, cValuesSort.size()==0?null:cValuesSort, dv, formatProcessor, crossTabOrderManager, dataList);
874 rd.setReportDataList(dataList);
875 /*if (getReportDataSize() < 0)
876 setReportDataSize(rd.getDataRowCount());*/
879 rd.truncateData(pageNo * getPageSize(), (pageNo + 1) * getPageSize() - 1);
881 if( downloadLimit != -1)
882 rd.truncateData(0, downloadLimit - 1);
884 rd.truncateData(0, -1);
887 if (colDataTotalsCrosstab == null)
888 colDataTotalsCrosstab = generateDataTotalsCrossTab(AppConstants.CV_COLUMN, userId,request);
889 if (displayColTotals && colDataTotalsCrosstab != null)
890 rd.setColumnDataTotalsCrossTab(colDataTotalsCrosstab, dataColumn
891 .getDisplayAlignment(), getCrossTabDisplayTotal(AppConstants.CV_COLUMN),
892 crossTabOrderManager, dataList);
894 if (rowDataTotalsCrosstab == null)
895 rowDataTotalsCrosstab = generateDataTotalsCrossTab(AppConstants.CV_ROW, userId, request);
896 if (displayRowTotals && rowDataTotalsCrosstab != null)
897 rd.setRowDataTotalsCrossTab(rowDataTotalsCrosstab, dataColumn
898 .getDisplayAlignment(), getCrossTabDisplayTotal(AppConstants.CV_ROW),
899 crossTabOrderManager, dataList);
903 && getCrossTabDisplayTotal(AppConstants.CV_COLUMN).equals(
904 getCrossTabDisplayTotal(AppConstants.CV_ROW))) {
905 // Display grand total
906 if (grandTotalCrosstab == null)
907 grandTotalCrosstab = ((CrossTabTotalValue) generateDataTotalsCrossTab("",
908 userId,request).get(0)).getTotalValue();
909 if (grandTotalCrosstab != null)
910 rd.setGrandTotalCrossTab(Utils.truncateTotalDecimals(grandTotalCrosstab),
911 dataColumn.getDisplayAlignment(),
912 getCrossTabDisplayTotal(AppConstants.CV_COLUMN), dataList);
915 rd.consolidateColumnHeaders(visualManager);
916 //if (Globals.getMergeCrosstabRowHeadings())
917 // rd.consolidateRowHeaders();
918 //rd.addRowNumbers(pageNo, dataList);
920 if (displayColTotals && colDataTotalsCrosstab != null) {
921 String totalLabel = "Total";
922 String colDisplayTotal = getCrossTabDisplayTotal(AppConstants.CV_COLUMN);
923 if (colDisplayTotal.length() > 0
924 && (!colDisplayTotal.equals(AppConstants.TOTAL_SUM_ID)))
925 totalLabel = nvl(AppConstants.TOTAL_FUNCTIONS.getNameById(colDisplayTotal));
926 if (getReportDataSize() > getPageSize())
927 totalLabel += "_nl_(for all pages)";
929 //rd.setCrossTabColumnTotalLabel(totalLabel);
932 //rd.applyVisibility();
933 //Collections.sort((List)dataList, new DataRowComparable());
934 DataRow drInFor1 = null;
935 Vector<DataValue> v1= null, v2 = null;
936 ArrayList<String> temp = new ArrayList<String>();
937 if (Globals.getMergeCrosstabRowHeadings()) {
938 for (int i = 0; i < dataList.size(); i++) {
939 drInFor1 = (DataRow)dataList.get(i);
940 drInFor1.setRowNum(i+1);
941 v1 = drInFor1.getRowValues();
942 if(i<dataList.size()-1) {
943 v2 = ((DataRow)dataList.get(i+1)).getRowValues();
945 v2 = ((DataRow)dataList.get(i-1)).getRowValues();
947 for (int j = 0; j < v1.size(); j++) {
949 if(v1.get(j).getDisplayValue().length()>0) { // another ArrayList
950 temp = new ArrayList();
951 temp.add(v1.get(j).getDisplayValue());
953 if(v2!=null && temp.get(j).equals(v2.get(j).getDisplayValue())) {
954 v2.get(j).setDisplayValue("");
960 rd.setReportDataList(dataList);
961 if (getReportDataSize() < 0) {
962 //setReportDataSize(rd.getDataRowCount());
963 setReportDataSize(rd.getReportDataList().size());
967 } // loadCrossTabReportData
970 public DataValue addDataValue(DataColumnType dataColumn, String columnValue) {
971 DataValue dv = new DataValue();
972 dv.setDisplayValue(columnValue);
973 if (nvl(dataColumn.getCrossTabValue()).trim().length()<=0)
974 dv.setVisible(false);
975 dv.setAlignment(dataColumn.getDisplayAlignment());
976 dv.setDisplayTotal(dataColumn.getDisplayTotal());
977 dv.setColName(dataColumn.getColName());
978 dv.setDisplayName(dataColumn.getDisplayName());
979 dv.setColId(dataColumn.getColId());
980 dv.setNowrap(nvl(dataColumn.getNowrap(),"null").equals("false")?"null":nvl(dataColumn.getNowrap(),"null"));
985 /*private*/ public boolean doesReportContainsGroupFormField() {
987 if(getFormFieldList()!=null) {
988 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
989 FormFieldType fft = (FormFieldType) iter.next();
990 if(fft.isGroupFormField()!=null && fft.isGroupFormField().booleanValue()) {
999 private ReportData loadLinearReportData(int pageNo, String userId, int downloadLimit, HttpServletRequest request, boolean download) throws RaptorException {
1000 String action = nvl(request.getParameter(AppConstants.RI_ACTION), request.getParameter("action"));;
1002 String reportSQL = "";
1004 if(action.endsWith("session")) {
1005 reportSQL = getWholeSQL();
1006 wholeSQL = reportSQL;
1008 reportSQL = generateSQL(reportParamValues, visualManager.getSortByColId(),
1009 visualManager.getSortByAscDesc(), userId, request);
1010 wholeSQL = reportSQL;
1011 setWholeSQL(wholeSQL);
1014 String dbInfo = getDBInfo();
1015 ds = ConnectionUtils.getDataSet(wholeSQL, dbInfo);
1016 setReportDataSize(ds.getRowCount());
1017 //wholeSQL = reportSQL;
1018 HttpSession session = request.getSession();
1019 //debugLogger.debug(" ******** Download Limit ********* " + downloadLimit + " %%%%%%%%%%PAGE " + pageNo );
1020 List reportCols = null;
1021 StringBuffer colNames = new StringBuffer();
1023 if(download && action.endsWith("session")) {
1024 reportCols = getAllColumns();
1025 colNames = new StringBuffer();
1026 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1028 DataColumnType dc = (DataColumnType) iter.next();
1029 if (colNames.length() > 0)
1030 colNames.append(", ");
1031 colNames.append(dc.getColId());
1036 String pagedSQL = null; // reportSQL;
1038 pagedSQL = generatePagedSQL(pageNo, userId, request, false, null);
1040 pagedSQL = generateSubsetSQL(0, downloadLimit, userId, request, false, null);
1041 // replace the request parameter specified in the drill down
1042 reportCols = getAllColumns();
1043 colNames = new StringBuffer();
1044 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1046 DataColumnType dc = (DataColumnType) iter.next();
1047 if (colNames.length() > 0)
1048 colNames.append(", ");
1049 colNames.append(dc.getColId());
1050 if (dc.isVisible()) {
1051 reportSQL = parseReportSQLForDrillDownParams(reportSQL, dc, request);
1052 pagedSQL = parseReportSQLForDrillDownParams(pagedSQL, dc, request);
1056 cachedSQL = pagedSQL;
1060 if(doesReportContainsGroupFormField()) {
1062 pagedSQL = generatePagedSQL(pageNo, userId, request, true, reportParamValues);
1064 pagedSQL = generateSubsetSQL(0, downloadLimit, userId, request, true, reportParamValues);
1066 //check for Group formfield
1067 //if groupformfield get columns from sql
1069 ds = ConnectionUtils.getDataSet(pagedSQL, dbInfo);
1071 if(doesReportContainsGroupFormField()) {
1072 List reportCols1 = getAllColumns();
1073 reportCols = new Vector();
1075 for (Iterator iter = reportCols1.iterator(); iter.hasNext();) {
1076 DataColumnType dct = (DataColumnType) iter.next();
1077 for (int k=0; k<ds.getColumnCount(); k++) {
1078 if(dct.getColId().toUpperCase().trim().equals(ds.getColumnName(k).trim())) {
1079 reportCols.add(dct);
1085 if (getFormFieldList() != null) {
1086 String paramValue = "";
1087 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
1088 FormFieldType fft = (FormFieldType) iter.next();
1089 if(fft.isGroupFormField()!=null && fft.isGroupFormField().booleanValue()) {
1090 paramValue = Utils.oracleSafe(nvl(reportParamValues
1091 .getParamValue(fft.getFieldId())));
1093 for (Iterator iter1 = reportCols1.iterator(); iter1.hasNext();) {
1094 DataColumnType dct = (DataColumnType) iter1.next();
1095 if(("["+fft.getFieldName()+ "]").equals(dct.getColName().trim())) {
1096 dct.setDisplayName(paramValue);
1108 // if ( (remDbInfo!=null) && (!remDbInfo.equals(AppConstants.DB_LOCAL)))
1110 // Globals.getRDbUtils().setDBPrefix(remDbInfo);
1111 // ds = RemDbUtils.executeQuery(pagedSQL);
1114 // ds = DbUtils.executeQuery(pagedSQL);
1116 * } catch(SQLException e) { throw new
1117 * ReportSQLException("[ReportRuntime.loadLinearReportData]
1118 * "+e.getMessage(), pagedSQL); }
1121 if (getReportDataSize() < 0)
1123 setReportDataSize(ds.getRowCount());
1124 else if (ds.getRowCount() <= getPageSize())
1125 setReportDataSize(ds.getRowCount());
1128 /*Pattern re1 = Pattern.compile("[Oo][Rr][Dd][Ee][Rr](.*?[^\r\n]*)[Bb][Yy]", Pattern.DOTALL);
1129 Pattern re2 = Pattern.compile("[Oo][Rr][Dd][Ee][Rr](.*?[^\r\n]*)[Bb][Yy]((.*?[^\r\n]*)|[\\s]|[^0-9a-zA-Z])\\)", Pattern.DOTALL);
1130 Matcher matcher = re1.matcher(reportSQL);
1131 Matcher matcher2 = null;
1132 int startPoint = reportSQL.length()-30;
1133 String startReportSQL = "";
1134 String endReportSQL = "";
1135 while(reportSQL.indexOf("xid", startPoint)!=-1)startPoint++;
1136 if (matcher.find(startPoint)) {
1137 startReportSQL = reportSQL.substring(0, reportSQL.indexOf(matcher.group()));
1138 endReportSQL = reportSQL.substring(reportSQL.indexOf(matcher.group()));
1139 matcher2 = re2.matcher(endReportSQL);
1141 endReportSQL = endReportSQL.substring(matcher.group().length()-1);
1144 reportSQL = startReportSQL + endReportSQL;
1146 String countSQL = "SELECT count(*) FROM (" + reportSQL + ")"+ (Globals.isPostgreSQL() || Globals.isMySQL()?" AS ":"") +" x ";
1149 if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
1151 org.onap.portalsdk.analytics.util.RemDbInfo remDbInfo = new org.onap.portalsdk.analytics.util.RemDbInfo();
1152 dbType = remDbInfo.getDBType(dbInfo);
1153 if (dbType.equals("DAYTONA") && reportSQL.trim().toUpperCase().startsWith("SELECT")) {
1154 Pattern re1 = Pattern.compile("order(.*?[^\r\n]*)by", Pattern.DOTALL);
1155 Matcher matcher = re1.matcher(reportSQL);
1156 int startPoint = reportSQL.length()-30;
1157 while(reportSQL.indexOf("xid", startPoint)!=-1)startPoint++;
1158 if (matcher.find(startPoint)) {
1159 reportSQL = reportSQL.substring(0, reportSQL.indexOf(matcher.group()));
1161 countSQL = "SELECT count(*) FROM (" + reportSQL + ")"+ (Globals.isPostgreSQL() || Globals.isMySQL()?" AS ":"") +" x";
1162 countSQL = countSQL + " ("+ colNames+ ")";
1163 } else if (dbType.equals("DAYTONA")) {
1164 setReportDataSize(50);
1166 } catch (Exception ex) {
1167 throw new RaptorException(ex);
1173 if(reportSQL.trim().toUpperCase().startsWith("SELECT")) {
1174 ds2 = ConnectionUtils.getDataSet(countSQL, dbInfo);
1175 if (ds2.getRowCount() > 0)
1176 setReportDataSize(ds2.getInt(0, 0));
1178 throw new RuntimeException(
1179 "[ReportRuntime.loadLinearReportData] Unable to load report data size");
1181 setReportDataSize(50);
1182 // if ( (remDbInfo!=null) &&
1183 // (!remDbInfo.equals(AppConstants.DB_LOCAL))){
1184 // Globals.getRDbUtils().setDBPrefix(remDbInfo);
1185 // ds2 = RemDbUtils.executeQuery(countSQL);
1188 // ds2 = DbUtils.executeQuery(countSQL);
1190 * } catch(SQLException e) { throw new
1191 * ReportSQLException("[ReportRuntime.loadLinearReportData size]
1192 * "+e.getMessage(), countSQL); }
1198 ReportData rd = new ReportData(pageNo, true);
1200 // Already defined changed for modifying request parameters
1201 //List reportCols = getAllColumns();
1202 Vector visibleCols = new Vector(reportCols.size());
1203 Vector formatProcessors = new Vector(reportCols.size());
1205 // ColumnHeaderRow chr = new ColumnHeaderRow();
1206 // rd.reportColumnHeaderRows.addColumnHeaderRow(chr);
1207 // chr.setRowHeight("30");
1211 ReportFormFields rff = getReportFormFields();
1212 ReportFormFields childReportFormFields = null;
1213 String fieldDisplayName = "";
1214 String fieldValue = "";
1216 for (int c = 0; c < reportCols.size(); c++) {
1217 if(reportCols.get(c)!=null) {
1218 DataColumnType dct = (DataColumnType) reportCols.get(c);
1219 if(nvl(dct.getDependsOnFormField()).length()>0 && nvl(dct.getDependsOnFormField()).indexOf("[")!=-1) {
1220 for(int i = 0 ; i < rff.size(); i++) {
1221 fieldDisplayName = "["+((FormField)rff.getFormField(i)).getFieldDisplayName()+"]";
1223 //if(dct.getOriginalDisplayName()==null) dct.setOriginalDisplayName(dct.getDisplayName());
1224 if (dct.getDependsOnFormField().equals(fieldDisplayName)) {
1225 fieldValue = nvl(request.getParameter(((FormField)rff.getFormField(i)).getFieldName()));
1227 if (fieldValue.length()>0) {
1228 if(!fieldValue.toUpperCase().equals("Y"))
1229 dct.setDisplayName(fieldValue);
1230 if(!dct.isVisible())
1231 dct.setVisible(true);
1233 dct.setVisible(false);
1242 String displayName = "";
1243 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1245 DataColumnType dc = (DataColumnType) iter.next();
1247 formatProcessors.add(count,new FormatProcessor(
1248 getSemaphoreById(dc.getSemaphoreId()), dc.getColType(), dc
1249 .getColFormat(), getReportDefType().equals(
1250 AppConstants.RD_SQL_BASED)));
1252 if (nvl(dc.getDrillDownURL()).length() > 0) {
1253 childReportFormFields = getChildReportFormFields(request,AppUtils.getDrillActionURL()+""+dc.getDrillDownURL());
1255 if (dc.isVisible()) {
1256 visibleCols.add(count,dc);
1257 //if(dc.getColId().startsWith("group")) {
1258 for (int d = 0; d < reportCols.size(); d++) {
1259 if(reportCols.get(d)!=null) {
1260 DataColumnType dct1 = (DataColumnType) reportCols.get(d);
1261 if(dct1.getColId().equals(dc.getColId()+"_name") && ds.getRowCount()>0) {
1262 displayName = ds.getString(0,dct1.getColId());
1263 dc.setDisplayName(displayName);
1269 String widthInPxls = dc.getDisplayWidthInPxls();
1271 if(nvl(widthInPxls).endsWith("px"))
1272 dc.setDisplayWidthInPxls(widthInPxls);
1274 widthInPxls = widthInPxls+"px";
1275 dc.setDisplayWidthInPxls(widthInPxls+"px");
1278 rd.createColumn(dc.getColId(), dc.getDisplayName(), dc.getDisplayWidthInPxls(), dc.getDisplayHeaderAlignment(),
1279 visualManager.isColumnVisible(dc.getColId()), visualManager
1280 .getSortByColId().equals(dc.getColId()) ? visualManager
1281 .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);
1282 // chr.addColumnHeader(new ColumnHeader(dc.getDisplayName(),
1283 // (dc.getDisplayWidth()>100)?"10%":(""+dc.getDisplayWidth()+"%")));
1286 visibleCols.add(count,null);
1287 rd.createColumn(dc.getColId(), AppConstants.HIDDEN, dc.getDisplayWidthInPxls(), dc.getDisplayHeaderAlignment(),
1288 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);
1289 // formatProcessors.add(count,null);
1294 if(getReportDefType().equals(AppConstants.RD_SQL_BASED_DATAMIN) && pageNo ==0) {
1297 v = addForecastData(reportSQL);
1298 } catch (Exception ex) {
1299 ex.printStackTrace();
1300 throw new RaptorException (ex);
1302 session.setAttribute("FORECASTED_DATA", v);
1303 DataSet dsWhole = ConnectionUtils.getDataSet(wholeSQL, dbInfo);
1305 session.setAttribute(AppConstants.RI_CHART_FORECAST_DATA, dsWhole);
1308 if(getReportDefType().equals(AppConstants.RD_SQL_BASED_DATAMIN) && session.getAttribute("FORECASTED_DATA")!=null) {
1309 Vector vForecastedData = (Vector)session.getAttribute("FORECASTED_DATA");
1310 if(vForecastedData.size() > 0)
1311 ds.addAll(vForecastedData);*/
1315 // Utils._assert(chr.size()==ds.getColumnCount(),
1316 // "[ReportRuntime.loadLinearReportData] The number of visible columns
1317 // does not match the number of data columns");
1318 //TODO: This should be optimized to accept -1 for flat file download
1319 for (int r = 0; r < Math.min(ds.getRowCount(), ((pageNo < 0) ? (downloadLimit == -1?Globals.getFlatFileUpperLimit():Globals.getDownloadLimit() ) : getPageSize())); r++) {
1320 DataRow dr = new DataRow();
1321 rd.reportDataRows.addDataRow(dr);
1323 for (int c = 0; c < reportCols.size(); c++) {
1324 if(reportCols.get(c)!=null) {
1325 DataColumnType dct = (DataColumnType) reportCols.get(c);
1326 DataValue dv = new DataValue();
1327 dr.addDataValue(dv);
1328 dv.setDisplayValue(ds.getString(r, c));
1329 dv.setColName(dct.getColName());
1330 dv.setColId(dct.getColId());
1331 dv.setNowrap(nvl(dct.getNowrap(),"null").equals("false")?"null":nvl(dct.getNowrap(),"null"));
1332 StringBuffer indentation = new StringBuffer("");
1333 if(dct.getIndentation()!=null && dct.getIndentation()>0) {
1334 for (int indent=0; indent< dct.getIndentation(); indent++) {
1335 indentation.append("\t");
1337 dv.setNowrap("true");
1339 dv.setIndentation(indentation.toString());
1340 if(dct.isVisible()) {
1342 dv.setVisible(true);
1343 dv.setAlignment(dct.getDisplayAlignment());
1344 dv.setDisplayTotal(dct.getDisplayTotal());
1345 dv.setDisplayName(dct.getDisplayName());
1347 if (nvl(dct.getDrillDownURL()).length() > 0) {
1349 if(dv.getDisplayValue().length() > 0) {
1350 dv.setDrillDownURL(parseDrillDownURL(r, /* c, */ds, dct,request, childReportFormFields));
1351 dv.setDrillDowninPoPUp(dct.isDrillinPoPUp()!=null?dct.isDrillinPoPUp():false);
1354 if (dv.getDisplayValue().length() == 0) {
1355 //dv.setDisplayValue("[NULL]");
1356 dv.setDisplayValue("");
1361 dv.setVisible(false);
1364 //System.out.println("in Linear report b4" + dr.getFormatId() + dr.getBgColorHtml() + dv.getDisplayValue());
1366 if(dr.getFormatId()!=null)
1367 ((FormatProcessor) formatProcessors.get(c)).setHtmlFormatters(dv, dr, true);
1369 ((FormatProcessor) formatProcessors.get(c)).setHtmlFormatters(dv, dr, false);
1371 //System.out.println("in Linear report After" + dr.getFormatId() + dr.getBgColorHtml() + dv.getDisplayValue());
1376 //Only if rownumber options is needed
1377 //rd.addRowNumbers(pageNo, getPageSize());
1379 if (colDataTotalsLinear == null) {
1380 if(!download && !action.endsWith("session"))
1381 colDataTotalsLinear = generateColumnDataTotalsLinear(new ArrayList(reportCols), userId,
1382 getDbInfo(),request);
1383 if(download && action.endsWith("session"))
1384 colDataTotalsLinear = generateColumnDataTotalsLinear(new ArrayList(reportCols), userId,
1385 getDbInfo(), getTotalSql());
1387 if (displayColTotals && colDataTotalsLinear != null) {
1388 String totalLabel = "Total";
1389 if (getReportDataSize() > getPageSize())
1390 totalLabel += "<br><font size=1>(for all pages)</font>";
1392 rd.setColumnDataTotalsLinear(colDataTotalsLinear, totalLabel);
1394 // Please note the below function doesn't set the visibility for dv since this is set in this function. - Sundar
1395 rd.applyVisibility();
1398 } // loadLinearReportData
1402 public DataRow generateColumnDataTotalsLinear(ArrayList reportCols, String userId,
1403 String dbInfo, String reportSQL) throws RaptorException {
1406 boolean displayColTotals = false;
1407 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1409 DataColumnType dct = (DataColumnType) iter.next();
1411 if (nvl(dct.getDisplayTotal()).length() > 0) {
1412 displayColTotals = true;
1415 } // if checking dct
1419 if (displayColTotals) {
1422 // DbUtils.executeQuery(generateTotalSQLLinear(reportParamValues,
1424 ds = ConnectionUtils.getDataSet(reportSQL,
1427 for (int c = 0; c < reportCols.size(); c++) {
1428 DataColumnType dct = (DataColumnType) reportCols.get(c);
1429 if ( dct != null ) {
1430 DataValue dv = new DataValue();
1432 String totalValue = "";
1434 totalValue = ds.getString(0, c);
1435 if (nvl(dct.getDisplayTotal()).length() > 0
1436 && (!dct.getDisplayTotal().equals(AppConstants.TOTAL_SUM_ID)))
1437 totalValue = nvl(AppConstants.TOTAL_FUNCTIONS.getNameById(dct
1438 .getDisplayTotal()))
1439 + ": " + totalValue;
1440 dv.setDisplayValue(Utils.truncateTotalDecimals(totalValue));
1442 dv.setAlignment(dct.getDisplayAlignment());
1443 dv.setColName(dct.getColName());
1444 dv.setDisplayName(dct.getDisplayName());
1445 dv.setColId(dct.getColId());
1446 dv.setNowrap(nvl(dct.getNowrap(),"null").equals("false")?"null":nvl(dct.getNowrap(),"null"));
1447 StringBuffer indentation = new StringBuffer("");
1448 if(dct.getIndentation()!=null && dct.getIndentation()>0) {
1449 for (int indent=0; indent< dct.getIndentation(); indent++) {
1450 indentation.append("\t");
1452 dv.setNowrap("true");
1454 dv.setIndentation(indentation.toString());
1455 dv.setDisplayTotal(dct.getDisplayTotal());
1457 dv.setVisible(dct.isVisible());
1459 dr.addDataValue(dv);
1465 } // generateColumnDataTotalsLinear
1468 public ReportData loadHiveLinearReportData(String reportSQL, String userId, int downloadLimit, HttpServletRequest request) throws RaptorException {
1469 wholeSQL = reportSQL;
1470 int countRows = getHiveReportCount(wholeSQL);
1471 setReportDataSize(countRows);
1472 if(countRows < 1001)
1473 wholeSQL += " limit "+ countRows;
1475 wholeSQL += " limit "+ downloadLimit;
1476 HttpSession session = request.getSession();
1480 String dbInfo = getDBInfo();
1482 List reportCols = getAllColumns();
1483 StringBuffer colNames = new StringBuffer();
1484 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1486 DataColumnType dc = (DataColumnType) iter.next();
1487 if (colNames.length() > 0)
1488 colNames.append(", ");
1489 colNames.append(dc.getColId());
1492 ds = ConnectionUtils.getDataSet(wholeSQL, dbInfo);
1494 ReportData rd = new ReportData(0, true);
1496 // Already defined changed for modifying request parameters
1497 //List reportCols = getAllColumns();
1498 Vector visibleCols = new Vector(reportCols.size());
1499 Vector formatProcessors = new Vector(reportCols.size());
1501 // ColumnHeaderRow chr = new ColumnHeaderRow();
1502 // rd.reportColumnHeaderRows.addColumnHeaderRow(chr);
1503 // chr.setRowHeight("30");
1507 ReportFormFields rff = getReportFormFields();
1508 ReportFormFields childReportFormFields = null;
1509 String fieldDisplayName = "";
1510 String fieldValue = "";
1512 for (int c = 0; c < reportCols.size(); c++) {
1513 if(reportCols.get(c)!=null) {
1514 DataColumnType dct = (DataColumnType) reportCols.get(c);
1515 if(nvl(dct.getDependsOnFormField()).length()>0 && nvl(dct.getDependsOnFormField()).indexOf("[")!=-1) {
1516 for(int i = 0 ; i < rff.size(); i++) {
1517 fieldDisplayName = "["+((FormField)rff.getFormField(i)).getFieldDisplayName()+"]";
1519 //if(dct.getOriginalDisplayName()==null) dct.setOriginalDisplayName(dct.getDisplayName());
1520 if (dct.getDependsOnFormField().equals(fieldDisplayName)) {
1521 fieldValue = nvl(request.getParameter(((FormField)rff.getFormField(i)).getFieldName()));
1523 if (fieldValue.length()>0) {
1524 if(!fieldValue.toUpperCase().equals("Y"))
1525 dct.setDisplayName(fieldValue);
1526 if(!dct.isVisible())
1527 dct.setVisible(true);
1529 dct.setVisible(false);
1538 String displayName = "";
1539 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1541 DataColumnType dc = (DataColumnType) iter.next();
1543 formatProcessors.add(count,new FormatProcessor(
1544 getSemaphoreById(dc.getSemaphoreId()), dc.getColType(), dc
1545 .getColFormat(), getReportDefType().equals(
1546 AppConstants.RD_SQL_BASED)));
1548 if (nvl(dc.getDrillDownURL()).length() > 0) {
1549 childReportFormFields = getChildReportFormFields(request,dc.getDrillDownURL());
1551 if (dc.isVisible()) {
1552 visibleCols.add(count,dc);
1553 //if(dc.getColId().startsWith("group")) {
1554 for (int d = 0; d < reportCols.size(); d++) {
1555 if(reportCols.get(d)!=null) {
1556 DataColumnType dct1 = (DataColumnType) reportCols.get(d);
1557 if(dct1.getColId().equals(dc.getColId()+"_name") && ds.getRowCount()>0) {
1558 displayName = ds.getString(0,dct1.getColId());
1559 dc.setDisplayName(displayName);
1565 String widthInPxls = dc.getDisplayWidthInPxls();
1567 if(nvl(widthInPxls).endsWith("px"))
1568 dc.setDisplayWidthInPxls(widthInPxls);
1570 widthInPxls = widthInPxls+"px";
1571 dc.setDisplayWidthInPxls(widthInPxls+"px");
1574 rd.createColumn(dc.getColId(), dc.getDisplayName(), dc.getDisplayWidthInPxls(), dc.getDisplayHeaderAlignment(),
1575 visualManager.isColumnVisible(dc.getColId()), visualManager
1576 .getSortByColId().equals(dc.getColId()) ? visualManager
1577 .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);
1578 // chr.addColumnHeader(new ColumnHeader(dc.getDisplayName(),
1579 // (dc.getDisplayWidth()>100)?"10%":(""+dc.getDisplayWidth()+"%")));
1582 visibleCols.add(count,null);
1583 rd.createColumn(dc.getColId(), "", dc.getDisplayWidthInPxls(), dc.getDisplayHeaderAlignment(),
1584 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);
1585 // formatProcessors.add(count,null);
1590 ArrayList reportDataList = new ArrayList();
1591 for (int r = 0; r < ds.getRowCount(); r++) {
1592 DataRow dr = new DataRow();
1593 rd.reportDataRows.addDataRow(dr);
1595 for (int c = 0; c < reportCols.size(); c++) {
1596 if(reportCols.get(c)!=null) {
1597 DataColumnType dct = (DataColumnType) reportCols.get(c);
1598 DataValue dv = new DataValue();
1599 dr.addDataValue(dv);
1600 dv.setDisplayValue(ds.getString(r, c));
1601 dv.setColName(dct.getColName());
1602 dv.setColId(dct.getColId());
1603 dv.setNowrap(nvl(dct.getNowrap(),"null").equals("false")?"null":nvl(dct.getNowrap(),"null"));
1604 StringBuffer indentation = new StringBuffer("");
1605 if(dct.getIndentation()!=null && dct.getIndentation()>0) {
1606 for (int indent=0; indent< dct.getIndentation(); indent++) {
1607 indentation.append("\t");
1609 dv.setNowrap("true");
1611 dv.setIndentation(indentation.toString());
1612 if(dct.isVisible()) {
1614 dv.setVisible(true);
1615 dv.setAlignment(dct.getDisplayAlignment());
1616 dv.setDisplayTotal(dct.getDisplayTotal());
1617 dv.setDisplayName(dct.getDisplayName());
1619 if (nvl(dct.getDrillDownURL()).length() > 0) {
1621 if(dv.getDisplayValue().length() > 0) {
1622 dv.setDrillDownURL(parseDrillDownURL(r, /* c, */ds, dct,request, childReportFormFields));
1623 dv.setDrillDowninPoPUp(dct.isDrillinPoPUp()!=null?dct.isDrillinPoPUp():false);
1626 if (dv.getDisplayValue().length() == 0) {
1627 //dv.setDisplayValue("[NULL]");
1628 dv.setDisplayValue("");
1633 dv.setVisible(false);
1636 //System.out.println("in Linear report b4" + dr.getFormatId() + dr.getBgColorHtml() + dv.getDisplayValue());
1638 if(dr.getFormatId()!=null)
1639 ((FormatProcessor) formatProcessors.get(c)).setHtmlFormatters(dv, dr, true);
1641 ((FormatProcessor) formatProcessors.get(c)).setHtmlFormatters(dv, dr, false);
1643 //System.out.println("in Linear report After" + dr.getFormatId() + dr.getBgColorHtml() + dv.getDisplayValue());
1646 reportDataList.add(dr);
1648 rd.setReportDataList(reportDataList);
1649 //Only if rownumber options is needed
1650 //rd.addRowNumbers(pageNo, getPageSize());
1652 if (colDataTotalsLinear == null)
1653 colDataTotalsLinear = generateColumnDataTotalsLinear(new ArrayList(reportCols), userId,
1654 getDbInfo(),request);
1655 if (displayColTotals && colDataTotalsLinear != null) {
1656 String totalLabel = "Total";
1657 if (getReportDataSize() > getPageSize())
1658 totalLabel += "<br><font size=1>(for all pages)</font>";
1660 rd.setColumnDataTotalsLinear(colDataTotalsLinear, totalLabel);
1662 // Please note the below function doesn't set the visibility for dv since this is set in this function. - Sundar
1663 rd.applyVisibility();
1666 } // loadHiveLinearReportData
1669 public int getHiveReportCount(String sql) throws RaptorException {
1670 //select t from (select count(*) t from (select * from program)x)x1;
1672 String countSql = "select t from (select count(*) t from ("+ sql + ")" + (Globals.isPostgreSQL() || Globals.isMySQL() ?" AS ":"") + " x) AS x1";
1676 String dbInfo = getDBInfo();
1677 System.out.println("SQL getReportCount()- " + countSql);
1679 ds = ConnectionUtils.getDataSet(countSql, dbInfo);
1682 if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
1684 org.onap.portalsdk.analytics.util.RemDbInfo remDbInfo = new org.onap.portalsdk.analytics.util.RemDbInfo();
1685 dbType = remDbInfo.getDBType(dbInfo);
1686 } catch (Exception ex) {
1687 throw new RaptorException(ex);
1690 if( ds.getRowCount()>0) {
1691 count = Integer.parseInt(ds.getString(0,0));
1693 } catch (NumberFormatException ex) {}
1699 /*private*/ public ReportFormFields getChildReportFormFields( HttpServletRequest request, String URL ) throws RaptorException {
1700 String childReportID = getReportID(URL);
1702 ReportRuntime ddRr = (new ReportHandler()).loadReportRuntime(request, childReportID,
1705 ReportFormFields ddReportFormFields = ddRr.getReportFormFields();
1706 return ddReportFormFields;
1709 private String getReportID(String URL) {
1711 int pos = URL.toLowerCase().indexOf("c_master=")+9;
1712 String reportID = "";
1713 if(URL.toLowerCase().indexOf("&", pos)!=-1)
1714 reportID = URL.substring(pos, URL.toLowerCase().indexOf("&", pos));
1716 reportID = URL.substring(pos);
1720 /*private*/ public String parseDrillDownURL(int rowIdx, /* int colIdx, */DataSet ds, DataColumnType dct, HttpServletRequest request, ReportFormFields ddReportFormFields)
1721 throws RaptorException {
1722 Vector viewActions = DataCache.getDataViewActions();
1723 javax.servlet.http.HttpSession session = request.getSession();
1725 StringBuffer dUrl = new StringBuffer();
1727 //String childReportID = getReportID(dct.getDrillDownURL());
1729 //ReportRuntime ddRr = (new ReportHandler()).loadReportRuntime(request, childReportID,
1732 //ReportFormFields ddReportFormFields = ddRr.getReportFormFields();
1734 boolean isViewAction = false;
1736 String requestParam ="";
1737 for (int k = 0; k < viewActions.size(); k++)
1738 if (dct.getDrillDownURL().equals(
1739 AppUtils.getBaseActionURL() + ((String) viewActions.get(k))))
1740 isViewAction = true;
1742 // Drill-down to record details
1743 String param = nvl(dct.getDrillDownParams()); // i.e.
1744 // "c_master=[bo1.RECID$]"
1745 param = param.substring(AppUtils.getBaseActionParam().length() + 1,
1746 param.length() - 1); // i.e. "bo1.RECID$"
1747 param = param.replace('.', '_'); // i.e. "bo1.RECID$"
1749 dUrl.append(AppUtils.getBaseActionParam());
1750 dUrl.append(java.net.URLEncoder.encode(ds.getString(rowIdx, param.toLowerCase())));
1752 // Drill-down to another report
1753 // Replacing col ids with values
1754 String param = nvl(dct.getDrillDownParams());
1755 while (param.indexOf('[') >= 0) {
1756 int startIdx = param.indexOf('[');
1757 int endIdx = param.indexOf(']');
1758 StringBuffer sb = new StringBuffer();
1759 if(startIdx>endIdx) {
1760 if (endIdx < param.length() - 1)
1761 sb.append(param.substring(endIdx + 1));
1762 param = sb.toString();
1766 sb.append(param.substring(0, startIdx));
1768 if (param.charAt(startIdx + 1) == '!') {
1769 // Parameter is a form field value
1770 String fieldId = param.substring(startIdx + 2, endIdx);
1771 String fieldValue = (String) reportParamValues.get(fieldId);
1773 sb.append(java.net.URLEncoder.encode(nvl(fieldValue)));
1774 //TODO Add a else if condition to check whether the param is from request Param
1775 //TODO make a unique symbol like #
1776 }else if (param.charAt(startIdx + 1) == '#') {
1778 String fieldId = param.substring(startIdx + 2, endIdx);
1779 String fieldValue = request.getParameter(fieldId);
1780 sb.append(java.net.URLEncoder.encode(nvl(fieldValue)));
1783 // Parameter is a column value
1784 String fieldValue = "";
1785 String colValue = null;
1786 String colId = null;
1787 if (param.indexOf('!') < 0 || param.indexOf('!') > endIdx)
1788 colId = param.substring(startIdx + 1, endIdx);
1790 // Need to use NVL(column, form field)
1791 colId = param.substring(startIdx + 1, param.indexOf('!'));
1793 String fieldId = param.substring(param.indexOf('!') + 1, endIdx);
1794 FormField ff = getFormField(fieldId);
1795 if (ff.getFieldType().equals(FormField.FFT_TEXTAREA)) {
1796 fieldValue = reportParamValues.getParamValueforTextAreaDrilldown(fieldId);
1798 fieldValue = (String) reportParamValues.get(fieldId);
1801 DataColumnType column = getColumnById(colId);
1802 String columnName = "";
1803 int groupColumn = 0;
1805 if(column.getColName().startsWith("[")) {
1807 columnName = column.getDisplayName();
1808 for(ddReportFormFields.resetNext(); ddReportFormFields.hasNext(); ) {
1809 FormField ff = ddReportFormFields.getNext();
1810 if(ff.getFieldDisplayName().toLowerCase().equals(columnName.toLowerCase())) {
1812 sb.delete(sb.lastIndexOf("&")+1, sb.length());
1813 sb.append(ff.getFieldName()+"=");
1817 if (groupColumn == 0 || (groupColumn == 1 && groupMatch == 1)) {
1818 String dependsOn = column.getDependsOnFormField();
1819 if(nvl(dependsOn).length()>0)
1820 System.out.println("DependsOn " + dependsOn);
1821 if (column != null) {
1822 // if (column.getColType().equals(AppConstants.CT_DATE))
1823 //if (!nvl(column.getColFormat(), AppConstants.DEFAULT_DATE_FORMAT)
1824 // .equals(AppConstants.DEFAULT_DATE_FORMAT))
1825 // Use extra column instead
1826 //commented out below line usually for Visual
1827 //colId += AppConstants.DD_COL_EXTENSION;
1828 colValue = ds.getString(rowIdx, colId.toLowerCase());
1829 // if SQL-Based and drill-down param is a date, decode
1830 // it to the expected Oracle format **/
1831 if (getReportDefType().equals(AppConstants.RD_SQL_BASED))
1832 if (!getColumnNoParseDateFlag(column))
1833 if (ReportParamDateValueParser.isDateParam(colValue))
1834 colValue = ReportParamDateValueParser
1835 .formatDateParamValue(colValue);
1838 String suppressValues = "|" + nvl(dct.getDrillDownType()) + "|";
1839 if (suppressValues.length() > 2
1840 && suppressValues.indexOf("|" + colValue + "|") >= 0)
1841 // Parameter value is suppressed and not passed to the
1842 // drill-down report
1845 sb.append(java.net.URLEncoder.encode(nvl(colValue, fieldValue)));
1847 sb.delete(sb.lastIndexOf("&")+1, sb.length());
1851 if (endIdx < param.length() - 1)
1852 sb.append(param.substring(endIdx + 1));
1853 param = sb.toString();
1855 if(Globals.getPassRequestParamInDrilldown()) {
1856 if(param.indexOf('#') < 0) {
1857 String[] reqParameters = Globals.getRequestParams().split(",");
1858 String[] sessionParameters = Globals.getSessionParams().split(",");
1859 for (int i = 0; i < reqParameters.length; i++) {
1860 if(request.getParameter(reqParameters[i])!=null) {
1861 if(!reqParameters[i].toUpperCase().startsWith("FF")){
1862 if(param.length()>0) {
1863 param += "&" + reqParameters[i]+"="
1864 + request.getParameter(reqParameters[i]);
1866 param += "&" + reqParameters[i]+"="
1867 + request.getParameter(reqParameters[i]);
1873 for (int i = 0; i < sessionParameters.length; i++) {
1874 if(session.getAttribute(sessionParameters[i].toUpperCase())!=null) {
1875 if(!sessionParameters[i].toUpperCase().startsWith("FF")){
1876 if(param.length()>0) {
1877 param += "&" + sessionParameters[i].toUpperCase()+"="
1878 + (String)session.getAttribute(sessionParameters[i].toUpperCase());
1880 param += "&" + sessionParameters[i].toUpperCase()+"="
1881 + (String)session.getAttribute(sessionParameters[i].toUpperCase());
1886 param += "&" + sessionParameters[i].toUpperCase()+"="
1887 + (String)session.getAttribute(sessionParameters[i]);
1895 dUrl.append(param.toString());
1897 dUrl.append(AppConstants.RI_DISPLAY_CONTENT);
1900 if(dct.isDrillinPoPUp()==null || (!dct.isDrillinPoPUp().booleanValue())) {
1901 dUrl.append(AppConstants.RI_SHOW_BACK_BTN);
1905 dUrl.append(AppConstants.DRILLDOWN_INDEX);
1906 int index = Integer.parseInt(nvl(AppUtils.getRequestValue(request, AppConstants.DRILLDOWN_INDEX), "0"));
1908 int form_index = Integer.parseInt(nvl(AppUtils.getRequestValue(request, AppConstants.FORM_DRILLDOWN_INDEX), "0"));
1909 index = index>0 ? --index : 0;
1910 form_index = form_index>0 ? --form_index : 0;*/
1911 request.setAttribute(AppConstants.DRILLDOWN_INDEX, Integer.toString(index));
1912 /*session.setAttribute(AppConstants.DRILLDOWN_INDEX, Integer.toString(index));
1913 request.setAttribute(AppConstants.FORM_DRILLDOWN_INDEX, Integer.toString(form_index));
1914 session.setAttribute(AppConstants.FORM_DRILLDOWN_INDEX, Integer.toString(form_index));*/
1916 dUrl.append("=" + AppUtils.getRequestNvlValue(request, AppConstants.DRILLDOWN_INDEX));
1918 //TODO Add a if condition to check whether the param is request Param
1921 if (dUrl.length() > 0)
1922 dUrl.insert(0, ((dct.getDrillDownURL()).indexOf('&') > 0) ? '&' : '&');
1923 dUrl.insert(0, AppUtils.getDrillActionURL()+dct.getDrillDownURL());
1925 //debugLogger.debug(" [[[[[[[[[[[[[[[[ " + dUrl);
1927 return dUrl.toString();
1928 } // parseDrillDownURL
1930 /** *********************************************************************************** */
1932 public DataRow generateColumnDataTotalsLinear(ArrayList reportCols, String userId,
1933 String dbInfo, HttpServletRequest request) throws RaptorException {
1936 displayColTotals = false;
1937 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
1939 DataColumnType dct = (DataColumnType) iter.next();
1941 if (nvl(dct.getDisplayTotal()).length() > 0) {
1942 displayColTotals = true;
1945 } // if checking dct
1949 if (displayColTotals) {
1952 // DbUtils.executeQuery(generateTotalSQLLinear(reportParamValues,
1954 ds = ConnectionUtils.getDataSet(generateTotalSQLLinear(reportParamValues, userId,request),
1957 for (int c = 0; c < reportCols.size(); c++) {
1958 DataColumnType dct = (DataColumnType) reportCols.get(c);
1959 if ( dct != null ) {
1960 DataValue dv = new DataValue();
1962 dr.addDataValue(dv);
1964 String totalValue = "";
1966 totalValue = ds.getString(0, c);
1967 if (nvl(dct.getDisplayTotal()).length() > 0
1968 && (!dct.getDisplayTotal().equals(AppConstants.TOTAL_SUM_ID)))
1969 totalValue = nvl(AppConstants.TOTAL_FUNCTIONS.getNameById(dct
1970 .getDisplayTotal()))
1971 + ": " + totalValue;
1972 dv.setDisplayValue(Utils.truncateTotalDecimals(totalValue));
1974 dv.setAlignment(dct.getDisplayAlignment());
1975 dv.setColName(dct.getColName());
1976 dv.setDisplayName(dct.getDisplayName());
1977 dv.setColId(dct.getColId());
1978 dv.setNowrap(nvl(dct.getNowrap(),"null").equals("false")?"null":nvl(dct.getNowrap(),"null"));
1979 StringBuffer indentation = new StringBuffer("");
1980 if(dct.getIndentation()!=null && dct.getIndentation()>0) {
1981 for (int indent=0; indent< dct.getIndentation(); indent++) {
1982 indentation.append("\t");
1984 dv.setNowrap("true");
1986 dv.setIndentation(indentation.toString());
1987 dv.setDisplayTotal(dct.getDisplayTotal());
1994 } // generateColumnDataTotalsLinear
1996 private Vector generateDataTotalsCrossTab(String rowColPos, String userId, HttpServletRequest request)
1997 throws RaptorException {
1998 String sql = getWholeSQL();
1999 Vector dataTotals = new Vector();
2001 boolean displayTotals = ((rowColPos.length() == 0) || (getCrossTabDisplayTotal(
2002 rowColPos).length() > 0));
2003 if (rowColPos.equals(AppConstants.CV_COLUMN))
2004 displayColTotals = displayTotals;
2005 else if (rowColPos.equals(AppConstants.CV_ROW))
2006 displayRowTotals = displayTotals;
2008 if (displayTotals) {
2010 // DbUtils.executeQuery(generateTotalSQLCrossTab(reportParamValues,
2011 // rowColPos, userId));
2012 String executeSql = generateTotalSQLCrossTab(
2013 sql, rowColPos, userId, request, reportParamValues);
2014 DataSet ds = ConnectionUtils.getDataSet(executeSql, getDbInfo());
2016 for (int i = 0; i < ds.getRowCount(); i++) {
2017 Vector headerValues = new Vector();
2018 String totalValue = null;
2021 for (Iterator iter = getAllColumns().iterator(); iter.hasNext();) {
2022 DataColumnType dct = (DataColumnType) iter.next();
2024 if (rowColPos.length() > 0
2025 && nvl(dct.getCrossTabValue()).equals(rowColPos)) {
2026 DataValue dataValue = new DataValue();
2027 dataValue.setBold(true);
2028 dataValue.setAlignment("center");
2029 dataValue.setDisplayValue(ds.getString(i, cPos++));
2030 headerValues.add(dataValue);
2032 //headerValues.add(ds.getString(i, cPos++));
2034 else if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_VALUE))
2035 totalValue = ds.getString(i, cPos++);
2038 dataTotals.add(new CrossTabTotalValue(headerValues, Utils
2039 .truncateTotalDecimals(totalValue)));
2044 } // generateDataTotalsCrossTab
2046 /** *********************************************************************************** */
2048 public void hideColVisual(String colId) {
2049 visualManager.hideColumn(colId);
2050 if (pageDataCache != null)
2051 pageDataCache.columnVisualShowHide(colId, false);
2054 public void showColVisual(String colId) {
2055 visualManager.showColumn(colId);
2056 if (pageDataCache != null)
2057 pageDataCache.columnVisualShowHide(colId, true);
2060 public void sortColVisual(String colId) {
2061 visualManager.setSortByColumn(colId);
2064 pageDataCache = null;
2068 /** *********************************************************************************** */
2070 public String generateDistinctValuesSQL(DataColumnType dct, String userId, HttpServletRequest request) throws RaptorException {
2071 return super.generateDistinctValuesSQL(reportParamValues, dct, userId, request);
2072 } // generateDistinctValuesSQL
2074 public String getDbInfo() {
2075 return this.cr.getDbInfo();
2078 private String fixSQL(StringBuffer sql) {
2080 int pos_f_format = 0;
2081 int pos_t_format = 0;
2084 String alias = null;
2085 if(sql.indexOf("SELECT", 7)!= -1) {
2086 pos = sql.indexOf("SELECT", 7);
2087 if(sql.indexOf("TO_CHAR", pos)!= -1){
2088 pos = sql.indexOf("TO_CHAR", pos);
2089 if(sql.indexOf("999",pos)!= -1) {
2090 pos = sql.indexOf("999",pos);
2091 pos_f_format = sql.lastIndexOf(", '", pos);
2092 if(pos_f_format == -1 || (pos - pos_f_format > 10)) {
2093 pos_f_format = sql.lastIndexOf(",'", pos);
2097 if(sql.indexOf("')", pos)!= -1) {
2098 pos_t_format = sql.indexOf("')", pos);
2099 //debugLogger.debug("pos_t - " + pos_t_format + " " + pos);
2100 if(pos_t_format == -1 || (pos_t_format - pos > 20)) {
2101 pos_t_format = sql.indexOf("' )", pos);
2104 else if (pos_t_format != -1)
2106 format = sql.substring(pos_f_format+3, pos_t_format);
2107 //alias = sql.substring(pos_t_format+3, pos_t_format+6);
2108 pos_alias = sql.indexOf(" ", pos_t_format);
2109 alias = sql.substring(pos_alias+1, pos_alias+4);
2114 if(sql.indexOf(alias)!=-1) {
2115 pos = sql.indexOf(alias);
2116 //debugLogger.debug(pos + " " + alias.length()+1 + "\n" + sql);
2117 sql.delete(pos,pos+4);
2118 sql.insert(pos, "TO_NUMBER("+alias+", '"+format+"')),'"+ format + "')");
2119 pos = sql.lastIndexOf("SUM", pos);
2121 pos = sql.lastIndexOf("AVG", pos);
2123 pos = sql.lastIndexOf("COUNT", pos);
2125 pos = sql.lastIndexOf("STDDEV", pos);
2127 pos = sql.lastIndexOf("VARIANCE", pos);
2128 sql.insert(pos, "TO_CHAR (");
2133 //debugLogger.debug("Alias|" + alias + "| Format " + format);
2134 //debugLogger.debug(sql.toString());
2135 return sql.toString();
2138 public String parseReportSQL(String sql) throws RaptorException {
2139 StringBuffer parsedSQL = new StringBuffer();
2141 Vector updatedReportCols = new Vector();
2144 int lastParsePos = curSQLParsePos;
2145 String lastToken = null;
2146 logger.debug(EELFLoggerDelegate.debugLogger, ("Flat File parseReportSQL ******* SQL " + sql));
2147 sql = sql.replaceAll("([\\s]*\\() (?!FROM)", "(");
2148 sql = sql.replaceAll("[\\s]*\\)", ")");
2149 //sql = sql.replaceAll("[dD][eE][cC][oO][dD][eE] ", "decode");
2150 //sql = sql.replaceAll("[\\s]*\\(", "(");
2151 //sql = replaceNewLine(sql, "decode ", "decode");
2152 //sql = replaceNewLine(sql, "DECODE ", "decode");
2153 //sql = replaceNewLine(sql, "Decode ", "decode");
2155 String nextToken = getNextSQLParseToken(sql, true);
2156 String dbInfo = getDbInfo();
2157 boolean isCYMBALScript = false;
2158 if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
2160 org.onap.portalsdk.analytics.util.RemDbInfo remDbInfo = new org.onap.portalsdk.analytics.util.RemDbInfo();
2161 String dbType = remDbInfo.getDBType(dbInfo);
2162 if (dbType.equals("DAYTONA") && !(nextToken.toUpperCase().equals("SELECT"))) {
2163 isCYMBALScript = true;
2165 } catch (Exception ex) {
2166 throw new RaptorException(ex);
2169 if ( isCYMBALScript == false ) {
2170 while (nextToken.length() > 0) {
2171 //System.out.println("LastToken " + lastToken + " NextToken " + nextToken);
2174 if (parsedSQL.length() == 0) {
2175 if (nextToken.toUpperCase().equals("SELECT"))
2176 parsedSQL.append("SELECT ");
2178 throw new org.onap.portalsdk.analytics.error.ValidationException(
2179 "The SQL must start with the SELECT keyword.");
2180 } else if (nextToken.toUpperCase().equals("DISTINCT")
2181 && parsedSQL.toString().equals("SELECT ")) {
2182 parsedSQL.append("DISTINCT ");
2183 } else if (nextToken.equals("*")
2184 && (parsedSQL.toString().equals("SELECT ") || parsedSQL.toString().equals(
2185 "SELECT DISTINCT "))) {
2186 throw new org.onap.portalsdk.analytics.error.ValidationException(
2187 "You cannot use \"SELECT *\". Please specify select columns/expressions.");
2188 } else if (nextToken.toUpperCase().equals("FROM")) {
2189 if (lastToken != null) {
2190 updatedReportCols.add(getParseSQLDataColumn(lastToken, null, parsedSQL,
2191 updatedReportCols, false));
2195 parsedSQL.append(" \n");
2196 while (lastParsePos < sql.length()
2197 && Character.isWhitespace(sql.charAt(lastParsePos)))
2199 parsedSQL.append(sql.substring(lastParsePos));
2202 //System.out.println("Next Token " + nextToken);
2203 if (nextToken.charAt(nextToken.length() - 1) == ',') {
2204 // The token ends with ,
2205 nextToken = nextToken.substring(0, nextToken.length() - 1);
2207 if (nextToken.length() == 0) {
2208 if (lastToken != null) {
2209 updatedReportCols.add(getParseSQLDataColumn(lastToken, null,
2210 parsedSQL, updatedReportCols, false));
2212 } // else just comma => ignore it
2214 //System.out.println("Next Token " + nextToken + " is Here" + " Last Token " + lastToken);
2215 if (lastToken != null) {
2216 updatedReportCols.add(getParseSQLDataColumn(lastToken, nextToken,
2217 parsedSQL, updatedReportCols, false));
2220 updatedReportCols.add(getParseSQLDataColumn(nextToken, null,
2221 parsedSQL, updatedReportCols, false));
2224 // The token doesn't end with ,
2225 if (lastToken == null)
2226 lastToken = nextToken;
2228 String token = getNextSQLParseToken(sql, false);
2229 //System.out.println(" ********** " + token + " " + lastToken);
2230 if (!token.toUpperCase().equals("FROM"))
2231 throw new org.onap.portalsdk.analytics.error.ValidationException(
2232 "|FROM keyword or a comma expected after [" + nextToken
2234 //System.out.println("Next Token " + nextToken);
2235 updatedReportCols.add(getParseSQLDataColumn(lastToken, nextToken,
2236 parsedSQL, updatedReportCols, false));
2242 lastParsePos = curSQLParsePos;
2243 nextToken = getNextSQLParseToken(sql, true);
2245 } else { // if CYMBAL Script
2246 nextToken = getNextCYMBALSQLParseToken(sql, true);
2248 Matcher matcher = null;
2249 String extracted = null;
2250 while (nextToken.length() > 0) {
2251 if (lastToken == null) lastToken = nextToken;
2253 if( lastToken.toUpperCase().equals("DO DISPLAY")) {
2254 re = Pattern.compile("each(.*)\\[.(.*?)\\]"); //\\[(.*?)\\]
2255 matcher = re.matcher(nextToken);
2256 if (matcher.find()) {
2257 extracted = matcher.group();
2258 re = Pattern.compile("\\[(.*?)\\]");
2259 matcher = re.matcher(nextToken);
2260 if(matcher.find()) {
2261 extracted = matcher.group();
2262 extracted = extracted.substring(1,extracted.length()-2);
2263 StringTokenizer sToken = new StringTokenizer(extracted);
2264 while(sToken.hasMoreTokens()) {
2265 updatedReportCols.add(getParseSQLDataColumn("", sToken.nextToken(),
2266 new StringBuffer(""), updatedReportCols, true));
2273 lastToken = nextToken;
2274 nextToken = getNextCYMBALSQLParseToken(sql, true);
2278 if (updatedReportCols.size() == 0)
2279 throw new org.onap.portalsdk.analytics.error.ValidationException(
2280 "The SQL statement must have at least one column in the SELECT clause.");
2283 return parsedSQL.toString();
2287 private String getNextCYMBALSQLParseToken(String sql, boolean updateParsePos) {
2288 int braketCount = 0;
2289 boolean isInsideQuote = false;
2290 StringBuffer nextToken = new StringBuffer();
2291 for (int idxNext = curSQLParsePos; idxNext < sql.length(); idxNext++) {
2292 char ch = sql.charAt(idxNext);
2295 nextToken.append(ch);
2299 return nextToken.toString();
2300 } // getNextSQLParseToken
2302 private String getNextSQLParseToken(String sql, boolean updateParsePos) {
2303 int braketCount = 0;
2304 boolean isInsideQuote = false;
2305 StringBuffer nextToken = new StringBuffer();
2306 for (int idxNext = curSQLParsePos; idxNext < sql.length(); idxNext++) {
2307 char ch = sql.charAt(idxNext);
2309 if (Character.isWhitespace(ch) || ch == ',') {
2311 nextToken.append(ch);
2313 if (nextToken.length() == 0)
2315 else if (braketCount == 0 && (!isInsideQuote)) {
2317 curSQLParsePos = idxNext + ((ch == ',') ? 1 : 0);
2319 } else if (ch != ',' && nextToken.charAt(nextToken.length() - 1) != ' ')
2320 nextToken.append(' ');
2322 nextToken.append(ch);
2324 if (ch == '(' || ch == '[')
2326 else if (ch == ')' || ch == ']')
2328 else if (ch == '\''/* ||ch=='\"' */)
2329 isInsideQuote = (!isInsideQuote);
2333 return nextToken.toString();
2334 } // getNextSQLParseToken
2336 private DataColumnType getParseSQLDataColumn(String sqlExpression, String colId,
2337 StringBuffer parsedSQL, Vector updatedReportCols, boolean isCYMBALScript) throws RaptorException {
2338 DataColumnType dct = null;
2340 if (colId != null) {
2341 if (!isParseSQLColID(colId))
2342 throw new org.onap.portalsdk.analytics.error.ValidationException(
2345 + "] must either be a valid column id consisting only of letters, numbers, and underscores, or there must be a comma in front of it.");
2347 dct = getColumnById(colId);
2349 // Getting unique column id
2352 for (int i = 0; (i < sqlExpression.length()) && (colIdN < 2); i++)
2353 if (Character.isLetter(sqlExpression.charAt(i))) {
2354 colId += sqlExpression.toLowerCase().charAt(i);
2358 colIdN = getAllColumns().size() + updatedReportCols.size();
2359 for (boolean idAlreadyUsed = true; idAlreadyUsed; colIdN++) {
2360 String newColId = colId + colIdN;
2361 idAlreadyUsed = false;
2363 for (Iterator iter = getAllColumns().iterator(); iter.hasNext();)
2364 if (newColId.equals(((DataColumnType) iter.next()).getColId())) {
2365 idAlreadyUsed = true;
2370 for (Iterator iter = updatedReportCols.iterator(); iter.hasNext();)
2371 if (newColId.equals(((DataColumnType) iter.next()).getColId())) {
2372 idAlreadyUsed = true;
2377 colId += (colIdN - 1);
2381 dct = (new ObjectFactory()).createDataColumnType();
2382 dct.setColId(colId);
2383 dct.setDisplayWidth(10);
2384 dct.setDisplayAlignment("Left");
2385 dct.setVisible(true);
2386 dct.setGroupBreak(false); // ???
2388 boolean isValidIdentifier = Character.isLetterOrDigit(sqlExpression.charAt(0));
2389 for (int i = 0; i < sqlExpression.length(); i++)
2390 if (!(Character.isLetterOrDigit(sqlExpression.charAt(i))
2391 || (sqlExpression.charAt(i) == '_') || (sqlExpression.charAt(i) == '$'))) {
2392 isValidIdentifier = false;
2396 if (isValidIdentifier) {
2397 dct.setDisplayName(sqlExpression);
2399 dct.setDisplayName(colId);
2403 sqlExpression = sqlExpression.replaceAll(", '", ",'");
2404 dct.setDbColName(sqlExpression);
2405 dct.setColName(sqlExpression);
2406 dct.setCalculated(true);
2407 dct.setColType(AppConstants.CT_CHAR);
2408 dct.setDbColType(AppConstants.CT_CHAR);
2409 adjustColumnType(dct); // ???
2411 if(!isCYMBALScript) {
2412 if (parsedSQL.toString().equals("SELECT ")
2413 || parsedSQL.toString().equals("SELECT DISTINCT "))
2414 parsedSQL.append("\n\t");
2416 parsedSQL.append(", \n\t");
2417 parsedSQL.append(sqlExpression);
2418 parsedSQL.append(" ");
2419 parsedSQL.append(colId);
2423 } // getParseSQLDataColumn
2425 private boolean isParseSQLColID(String token) {
2426 if (nvl(token).length() == 0)
2429 for (int i = 0; i < token.length(); i++) {
2430 char ch = token.charAt(i);
2432 if (i == 0 && ch == '_')
2435 if (!(Character.isLetterOrDigit(ch) || ch == '_'))
2440 } // isParseSQLColID
2442 /*private*/ public String parseReportSQLForDrillDownParams(String reportSQL, DataColumnType dataColumnRequest, HttpServletRequest request){
2443 String param = nvl(dataColumnRequest.getDrillDownParams());
2444 String sql = reportSQL;
2446 while (param.indexOf('[', pos) >= 0) {
2447 int startIdx = param.indexOf('[',pos);
2448 int endIdx = param.indexOf(']',startIdx+1);
2450 StringBuffer sb = new StringBuffer();
2452 sb.append(param.substring(0, startIdx));
2455 if (param.charAt(startIdx + 1) == '#') {
2456 // Parameter is a form field value
2457 String fieldId = param.substring(startIdx + 2, endIdx);
2458 String fieldValue = request.getParameter(fieldId);
2459 sql = Utils.replaceInString(sql, "[" + fieldId.toUpperCase()+"]", fieldValue );
2465 public List getMapMarkers(ReportData rd, org.onap.portalsdk.analytics.xmlobj.ReportMap xmlmap){
2467 ArrayList markers = new ArrayList();
2469 HashMap colHash = new HashMap();
2471 for(rd.reportDataRows.resetNext(); rd.reportDataRows.hasNext(); rNum++) {
2472 DataRow dr = rd.reportDataRows.getNext();
2473 for(dr.resetNext(); dr.hasNext(); ) {
2474 DataValue dv = dr.getNext();
2475 colHash.put(dv.getColId(), dv.getDisplayValueLinkHtml());
2478 for (int i = 0; i < xmlmap.getMarkers().size(); i ++){
2479 Marker marker = new Marker("", "", "");
2480 org.onap.portalsdk.analytics.xmlobj.Marker m = (org.onap.portalsdk.analytics.xmlobj.Marker) xmlmap.getMarkers().get(i);
2481 String address = (String) colHash.get(m.getAddressColumn());
2482 String data = (String) colHash.get(m.getDataColumn());
2483 marker.setAddress(address);
2484 if (xmlmap.getAddAddressInDataYN() != null && xmlmap.getAddAddressInDataYN().equals("Y")){
2485 marker.setData(address + "<br/>" + data);
2488 marker.setData(data);
2490 marker.setColor(m.getMarkerColor());
2491 markers.add(marker);
2492 System.out.println("%%%%%%%%%%%% marker is : " + address + data);
2502 public ReportParamValues getReportParamValues() {
2503 return reportParamValues;
2506 public String getFormFieldFilled(String title) {
2507 if( getFormFieldList()!=null && reportParamValues!=null && nvl(title).length()>0) {
2508 for (Iterator iter1 = getFormFieldList().getFormField().iterator(); iter1.hasNext();) {
2509 FormFieldType fft = (FormFieldType) iter1.next();
2510 String fieldDisplay = getFormFieldDisplayName(fft);
2511 String fieldId = fft.getFieldId();
2512 if(!fft.getFieldType().equals(FormField.FFT_BLANK) && !fft.getFieldType().equals(FormField.FFT_LIST_MULTI) && !fft.getFieldType().equals(FormField.FFT_TEXTAREA)) {
2513 String paramValue = Utils.oracleSafe(nvl(reportParamValues.getParamValue(fieldId)));
2514 title = Utils.replaceInString(title, fieldDisplay, nvl(
2522 public synchronized Object clone() {
2524 return super.clone();
2525 } catch (CloneNotSupportedException e) {
2526 // this shouldn't happen, since we are Cloneable
2527 throw new InternalError("Cloning throws error.");
2531 public VisualManager getVisualManager() {
2532 return visualManager;
2535 public String getReportSQLWithRowNum(String _orderBy, boolean asc) {
2536 String sql = getWholeSQL();
2537 int closeBracketPos = 0;
2538 // Added reportSQLOnlyFirstPart which has Column information with Rownum
2539 return nvl(getReportSQLOnlyFirstPart()) + " " + sql + ") x ";
2543 public int getDisplayMode() {
2544 return DISPLAY_MODE;
2547 public void setDisplayMode(int mode) {
2548 DISPLAY_MODE = mode;
2551 public int getDateOption() {
2555 public void setDateOption(int dateOption) {
2556 DATE_OPTION = dateOption;
2559 public boolean isDisplayColTotals() {
2560 return displayColTotals;
2563 public void setDisplayColTotals(boolean displayColTotals) {
2564 this.displayColTotals = displayColTotals;
2567 public boolean isDisplayRowTotals() {
2568 return displayRowTotals;
2571 public void setDisplayRowTotals(boolean displayRowTotals) {
2572 this.displayRowTotals = displayRowTotals;
2576 private boolean canPersistLinearReport() {
2577 boolean visibleColExist = false;
2579 if (getDataSourceList().getDataSource().size() > 0) {
2580 for (Iterator iter = getAllColumns().iterator(); iter.hasNext();) {
2581 DataColumnType dct = (DataColumnType) iter.next();
2583 if (dct.isVisible()) {
2584 visibleColExist = true;
2590 return visibleColExist;
2591 } // canPersistLinearReport
2593 public void persistLinearReport(HttpServletRequest request)
2594 throws RaptorException {
2595 if (!canPersistLinearReport())
2598 Connection connection = null;
2600 String userID = AppUtils.getUserID(request);
2601 String reportXML = marshal();
2602 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] Report " + reportID
2603 + " XML marshalled succesfully"));
2606 verifySQLBasedReportAccess(request);
2607 reportSecurity.reportUpdate(request);
2608 connection = DbUtils.startTransaction();
2609 ReportLoader.updateCustomReportRec(connection, this, reportXML);
2610 ReportLoader.createReportLogEntry(connection, reportID, userID,
2611 AppConstants.RLA_UPDATE, "", "");
2612 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] DB update report "
2613 + reportID + " succesfull"));
2614 DbUtils.commitTransaction(connection);
2615 } catch (RaptorException e) {
2616 e.printStackTrace();
2617 DbUtils.rollbackTransaction(connection);
2620 DbUtils.clearConnection(connection);
2622 } // persistLinearReport
2624 public void persistDashboardReport(HttpServletRequest request)
2625 throws RaptorException {
2627 Connection connection = null;
2629 String userID = AppUtils.getUserID(request);
2630 String reportXML = marshal();
2631 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] Report " + reportID
2632 + " XML marshalled succesfully"));
2635 verifySQLBasedReportAccess(request);
2636 reportSecurity.reportUpdate(request);
2637 connection = DbUtils.startTransaction();
2638 ReportLoader.updateCustomReportRec(connection, this, reportXML);
2639 ReportLoader.createReportLogEntry(connection, reportID, userID,
2640 AppConstants.RLA_UPDATE, "", "");
2641 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] DB update report "
2642 + reportID + " succesfull"));
2643 DbUtils.commitTransaction(connection);
2644 } catch (RaptorException e) {
2645 e.printStackTrace();
2646 DbUtils.rollbackTransaction(connection);
2649 DbUtils.clearConnection(connection);
2651 } // persistDashboardReport
2652 public String getTotalSql() {
2656 public void setTotalSql(String totalSql) {
2657 this.totalSql = totalSql;
2660 public void setTriggerFormFieldCheck( ReportFormFields FormFieldList, FormField selectedFormField) {
2662 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
2663 FormField ff = (FormField) iter.next();
2664 if(!ff.getFieldName().equals(selectedFormField.getFieldName())) {
2665 if(nvl(ff.getBaseSQL()).length()>0 && ff.getBaseSQL().indexOf("["+selectedFormField.getFieldDisplayName() +"]")!= -1) {
2666 selectedFormField.setTriggerOtherFormFields(true);
2674 public void setTriggerThisFormFieldCheck( ReportFormFields FormFieldList, FormField selectedFormField) {
2676 String sql = nvl(selectedFormField.getBaseSQL()).length()>0 ? selectedFormField.getBaseSQL():"";
2677 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
2678 FormField ff = (FormField) iter.next();
2679 if(!ff.getFieldName().equals(selectedFormField.getFieldName())) {
2680 if(sql.indexOf("["+ff.getFieldDisplayName() +"]")!= -1) {
2681 selectedFormField.setTriggerThisFormfield(true);
2690 private boolean isAllowEdit(HttpServletRequest request) {
2691 boolean allowEdit = false;
2692 String userId = AppUtils.getUserID(request);
2694 if( AppUtils.isAdminUser(request) || AppUtils.isSuperUser(request) ) {
2697 if(getOwnerID().equals(userId)) allowEdit = true;
2698 else allowEdit = false;
2700 } catch (RaptorException ex) {
2705 public ReportJSONRuntime createReportJSONRuntime(HttpServletRequest request, ReportData rd) {
2706 String userId = AppUtils.getUserID(request);
2707 ObjectMapper mapper = new ObjectMapper();
2708 ReportJSONRuntime reportJSONRuntime = new ReportJSONRuntime();
2709 reportJSONRuntime.setReportTitle(getReportTitle());
2710 //reportJSONRuntime.setReportSubTitle(getReportSubTitle());
2711 reportJSONRuntime.setReportID(getReportID());
2712 reportJSONRuntime.setReportDescr(getReportDescr());
2713 reportJSONRuntime.setReportName(getReportName());
2714 reportJSONRuntime.setReportSubTitle(getReportSubTitle());
2715 reportJSONRuntime.setAllowSchedule(isAllowSchedule());
2716 reportJSONRuntime.setAllowEdit(isAllowEdit(request));
2717 reportJSONRuntime.setColIdxTobeFreezed(getFrozenColumnId());
2718 reportJSONRuntime.setNumFormCols(getNumFormColsAsInt());
2720 reportJSONRuntime.setBackBtnURL("");
2721 String chartType = getChartType();
2722 boolean displayChart = (nvl(chartType).length()>0)&&getDisplayChart();
2723 boolean displayChartWizard = getDisplayChart();
2724 reportJSONRuntime.setChartAvailable(displayChart);
2725 reportJSONRuntime.setChartWizardAvailable(displayChartWizard);
2726 reportJSONRuntime.setDisplayData(!isDisplayOptionHideData());
2727 reportJSONRuntime.setDisplayForm(!isDisplayOptionHideForm());
2728 reportJSONRuntime.setHideFormFieldsAfterRun(isHideFormFieldAfterRun());
2729 reportJSONRuntime.setDisplayExcel(!isDisplayOptionHideExcelIcons());
2730 reportJSONRuntime.setDisplayPDF(!isDisplayOptionHidePDFIcons());
2731 ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
2732 ArrayList<FormFieldJSON> formFieldJSONList = new ArrayList<FormFieldJSON>();
2733 if(getReportFormFields()!=null) {
2734 formFieldJSONList = new ArrayList<FormFieldJSON>(getReportFormFields().size());
2735 for (Iterator iter = getReportFormFields().iterator(); iter.hasNext();) {
2736 formFieldValues = new ArrayList<IdNameValue>();
2737 FormField ff = (FormField) iter.next();
2738 ff.setDbInfo(getDbInfo());
2739 FormFieldJSON ffJSON = new FormFieldJSON();
2740 ffJSON.setFieldId(ff.getFieldName());
2741 ffJSON.setFieldType(ff.getFieldType());
2742 ffJSON.setFieldDisplayName(ff.getFieldDisplayName());
2743 ffJSON.setHelpText(ff.getHelpText());
2744 ffJSON.setValidationType(ff.getValidationType());
2745 ffJSON.setVisible(ff.isVisible());
2746 //ffJSON.setTriggerOtherFormFields(ff.getDependsOn());
2747 IdNameList lookup = null;
2748 lookup = ff.getLookupList();
2749 String selectedValue = "";
2751 IdNameList lookupList = null;
2752 boolean readOnly = false;
2754 if(!ff.hasPredefinedList) {
2755 IdNameSql lu = (IdNameSql) lookup;
2756 String SQL = lu.getSql();
2757 oldSQL = lu.getSql();
2758 setTriggerFormFieldCheck( getReportFormFields(), ff);
2759 ffJSON.setTriggerOtherFormFields(ff.isTriggerOtherFormFields());
2760 SQL = parseAndFillReq_Session_UserValues(request, SQL, userId);
2761 SQL = parseAndFillWithCurrentValues(request, SQL, ff);
2762 String defaultSQL = lu.getDefaultSQL();
2763 defaultSQL = parseAndFillReq_Session_UserValues(request, defaultSQL, userId);
2764 defaultSQL = parseAndFillWithCurrentValues(request, defaultSQL, ff);
2765 lookup = new IdNameSql(-1,SQL,defaultSQL);
2767 lookupList = lookup;
2769 lookup.loadUserData(0, "", ff.getDbInfo(), ff.getUserId());
2770 } catch (Exception e ){ e.printStackTrace(); //throw new RaptorRuntimeException(e);
2773 lookup.trimToSize();
2775 String[] requestValue = request.getParameterValues(ff.getFieldName());
2777 if(lookup != null && lookup.size() > 0) {
2778 for (lookup.resetNext(); lookup.hasNext();) {
2779 IdNameValue value = lookup.getNext();
2780 readOnly = value.isReadOnly();
2781 if(requestValue != null && Arrays.asList(requestValue).contains(value.getId())) {
2782 //if(value.getId().equals(requestValue))
2783 value.setDefaultValue(true);
2784 } else if (AppUtils.nvl(ff.getDefaultValue()).length()>0) {
2785 if(ff.getDefaultValue().equals(value.getId())) {
2786 value.setDefaultValue(true);
2789 if(!(ff.getFieldType().equals(FormField.FFT_CHECK_BOX) || ff.getFieldType().equals(FormField.FFT_COMBO_BOX) || ff.getFieldType().equals(FormField.FFT_LIST_BOX)
2790 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI)) && value.isDefaultValue())
2791 formFieldValues.add(value);
2792 else if(ff.getFieldType().equals(FormField.FFT_CHECK_BOX) || ff.getFieldType().equals(FormField.FFT_COMBO_BOX) || ff.getFieldType().equals(FormField.FFT_LIST_BOX)
2793 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI)) {
2794 formFieldValues.add(value);
2799 if(requestValue!=null && requestValue.length>0) {
2800 IdNameValue value = new IdNameValue(requestValue[0], requestValue[0], true, false);
2801 formFieldValues.add(value);
2806 setTriggerFormFieldCheck( getReportFormFields(), ff);
2807 ffJSON.setTriggerOtherFormFields(ff.isTriggerOtherFormFields());
2808 String[] requestValue = request.getParameterValues(ff.getFieldName());
2809 if(requestValue!=null && requestValue.length>0) {
2810 IdNameValue value = new IdNameValue(requestValue[0], requestValue[0], true, false);
2811 formFieldValues.add(value);
2812 } else if (AppUtils.nvl(ff.getDefaultValue()).length()>0) {
2813 IdNameValue value = new IdNameValue(ff.getDefaultValue(), ff.getDefaultValue(), true, false);
2814 formFieldValues.add(value);
2817 if(!ff.hasPredefinedList) {
2818 if(oldSQL != null && !oldSQL.equals("")) {
2819 ((IdNameSql)lookup).setSQL(oldSQL);
2825 ffJSON.setFormFieldValues(formFieldValues);
2826 formFieldJSONList.add(ffJSON);
2829 reportJSONRuntime.setFormFieldList(formFieldJSONList);
2830 //reportJSONRuntime.setReportDataColumns(get);
2832 Map<String,Object> dvJSON = null;
2835 reportJSONRuntime.setTotalRows(getReportDataSize());
2836 ArrayList<ColumnHeader> colList = new ArrayList<ColumnHeader>();
2837 ArrayList<Map<String,Object>> reportDataRows = new ArrayList<Map<String,Object>>();
2838 for(rd.reportColumnHeaderRows.resetNext(); rd.reportColumnHeaderRows.hasNext(); ) {
2840 ColumnHeaderRow chr = rd.reportColumnHeaderRows.getNext();
2841 for(chr.resetNext(); chr.hasNext(); ) {
2842 colList.add(chr.getNext());
2845 if(getReportDataSize() > 0) {
2847 for(rd.reportDataRows.resetNext(); rd.reportDataRows.hasNext(); count++) {
2848 dvJSON = new HashMap<String,Object>();
2849 DataRow dr = rd.reportDataRows.getNext();
2850 for(dr.resetNext(); dr.hasNext(); ) {
2851 DataValue dv = dr.getNext();
2853 dvJSON.put(dv.getColId(), dv);
2854 } catch (Exception ex) {
2855 ex.printStackTrace();
2859 reportDataRows.add(dvJSON);
2862 reportJSONRuntime.setReportDataColumns(colList);
2863 reportJSONRuntime.setReportDataRows(reportDataRows);
2864 //reportJSONRuntime.setSqlWhole(getWholeSQL());
2865 reportJSONRuntime.setPageSize(getPageSize());
2869 if(getReportDataSize() <= 0) {
2870 reportJSONRuntime.setMessage(getEmptyMessage());
2872 reportJSONRuntime.setSqlWhole(getWholeSQL());
2873 return reportJSONRuntime;
2877 public ReportJSONRuntime createFormFieldJSONRuntime(HttpServletRequest request) {
2878 String userId = AppUtils.getUserID(request);
2879 ObjectMapper mapper = new ObjectMapper();
2880 ReportJSONRuntime reportJSONRuntime = new ReportJSONRuntime();
2881 reportJSONRuntime.setReportTitle(getReportTitle());
2882 reportJSONRuntime.setReportID(getReportID());
2883 reportJSONRuntime.setReportName(getReportName());
2884 reportJSONRuntime.setReportSubTitle(getReportSubTitle());
2885 reportJSONRuntime.setNumFormCols(getNumFormColsAsInt());
2886 ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
2887 ArrayList<FormFieldJSON> formFieldJSONList = new ArrayList<FormFieldJSON>();
2888 if(reportFormFields!=null) {
2889 formFieldJSONList = new ArrayList<FormFieldJSON>(reportFormFields.size());
2890 for (Iterator iter = reportFormFields.iterator(); iter.hasNext();) {
2891 formFieldValues = new ArrayList<IdNameValue>();
2892 FormField ff = (FormField) iter.next();
2893 FormFieldJSON ffJSON = new FormFieldJSON();
2894 ffJSON.setFieldId(ff.getFieldName());
2895 ffJSON.setFieldType(ff.getFieldType());
2896 ffJSON.setFieldDisplayName(ff.getFieldDisplayName());
2897 ffJSON.setHelpText(ff.getHelpText());
2898 ffJSON.setValidationType(ff.getValidationType());
2899 ffJSON.setFormFieldValues(formFieldValues);
2900 ffJSON.setVisible(ff.isVisible());
2901 formFieldJSONList.add(ffJSON);
2903 for (Iterator iter = reportFormFields.iterator(); iter.hasNext();) {
2904 formFieldValues = new ArrayList<IdNameValue>();
2905 FormField ff = (FormField) iter.next();
2906 ff.setDbInfo(getDbInfo());
2907 for (Iterator iter1 = formFieldJSONList.iterator(); iter1.hasNext();) {
2908 FormFieldJSON ffJSON = (FormFieldJSON) iter1.next();
2909 if(ffJSON.getFieldId().equals(ff.getFieldName())) {
2910 IdNameList lookup = null;
2911 lookup = ff.getLookupList();
2912 String selectedValue = "";
2914 IdNameList lookupList = null;
2915 boolean readOnly = false;
2917 if(!ff.hasPredefinedList) {
2918 IdNameSql lu = (IdNameSql) lookup;
2919 String SQL = lu.getSql();
2920 oldSQL = lu.getSql();
2921 setTriggerFormFieldCheck( getReportFormFields(), ff);
2922 ffJSON.setTriggerOtherFormFields(ff.isTriggerOtherFormFields());
2923 setTriggerThisFormFieldCheck(getReportFormFields(), ff);
2924 SQL = parseAndFillReq_Session_UserValues(request, SQL, userId);
2925 SQL = parseAndFillOtherFormfieldValues(request, SQL, userId, formFieldJSONList);
2926 //SQL = parseAndFillWithCurrentValues(formGrid,SQL, ff);
2927 String defaultSQL = lu.getDefaultSQL();
2928 defaultSQL = parseAndFillReq_Session_UserValues(request, defaultSQL, userId);
2929 //defaultSQL = parseAndFillWithCurrentValues(formGrid,defaultSQL, ff);
2930 lookup = new IdNameSql(-1,SQL,defaultSQL);
2932 lookupList = lookup;
2934 lookup.loadUserData(0, "", ff.getDbInfo(), ff.getUserId());
2935 } catch (Exception e ){ e.printStackTrace(); //throw new RaptorRuntimeException(e);
2938 lookup.trimToSize();
2940 String requestValue = request.getParameter(ff.getFieldName());
2941 ArrayList<String> requestValueList = new ArrayList<String>();
2942 requestValueList.add(requestValue);
2944 /*if(ff.isTriggerThisFormfield()) {
2945 refreshFormFieldsWithLatestValue(request, userId, ff, formFieldJSONList);
2949 for (lookup.resetNext(); lookup.hasNext();) {
2950 IdNameValue value = lookup.getNext();
2951 readOnly = value.isReadOnly();
2952 if(nvl(requestValue).length()>0) {
2953 if(value.getId().equals(requestValue))
2954 value.setDefaultValue(true);
2956 formFieldValues.add(value);
2961 setTriggerFormFieldCheck( getReportFormFields(), ff);
2962 ffJSON.setTriggerOtherFormFields(ff.isTriggerOtherFormFields());
2963 String[] requestValue = request.getParameterValues(ff.getFieldName());
2964 if(requestValue!=null && requestValue.length>0) {
2965 IdNameValue value = new IdNameValue(requestValue[0], requestValue[0], true, false);
2966 formFieldValues.add(value);
2967 } else if (AppUtils.nvl(ff.getDefaultValue()).length()>0) {
2968 IdNameValue value = new IdNameValue(ff.getDefaultValue(), ff.getDefaultValue(), true, false);
2969 formFieldValues.add(value);
2972 if(!ff.hasPredefinedList) {
2973 if(oldSQL != null && !oldSQL.equals("")) {
2974 ((IdNameSql)lookup).setSQL(oldSQL);
2979 //if(!ff.isTriggerThisFormfield()) {
2980 ffJSON.setFormFieldValues(formFieldValues);
2990 reportJSONRuntime.setFormFieldList(formFieldJSONList);
2991 //reportJSONRuntime.setReportDataColumns(get);
2993 return reportJSONRuntime;
2998 private String parseAndFillOtherFormfieldValues(HttpServletRequest request, String SQL, String userId, ArrayList<FormFieldJSON> formFieldJSONList) {
2999 ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
3000 String selectedValue = "";
3001 String displayName = "";
3002 for (Iterator iter1 = formFieldJSONList.iterator(); iter1.hasNext();) {
3003 FormFieldJSON ffJSON = (FormFieldJSON) iter1.next();
3004 displayName = ffJSON.getFieldDisplayName();
3005 ArrayList<IdNameValue> formfieldvalues = ffJSON.getFormFieldValues();
3006 for (int i = 0; i< formfieldvalues.size(); i++) {
3007 IdNameValue formfieldItem = formfieldvalues.get(i);
3008 if(formfieldItem.isDefaultValue()) {
3009 selectedValue = formfieldItem.getId();
3012 SQL = Utils.replaceInString(SQL, "["+displayName+"]", selectedValue);
3018 private void refreshFormFieldsWithLatestValue(HttpServletRequest request, String userId, FormField ff_src, ArrayList<FormFieldJSON> formFieldJSONList) {
3019 ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
3020 List<String> requestValueList = null;
3021 IdNameList lookup = null;
3022 lookup = ff_src.getLookupList();
3023 IdNameSql lu = (IdNameSql) lookup;
3026 String oldDefaultSQL = "";
3027 String defaultSQL = "";
3028 IdNameList lookupList = null;
3031 oldSQL = lu.getSql();
3032 oldDefaultSQL = lu.getDefaultSQL();
3033 defaultSQL = lu.getDefaultSQL();
3035 boolean readOnly = false;
3036 for (Iterator iter1 = formFieldJSONList.iterator(); iter1.hasNext();) {
3037 FormFieldJSON ffJSON = (FormFieldJSON) iter1.next();
3038 if((ffJSON.getFieldId().equals(ff_src.getFieldName())) && ffJSON.isVisible()) {
3039 for (Iterator iter = reportFormFields.iterator(); iter.hasNext();) {
3040 formFieldValues = new ArrayList<IdNameValue>();
3041 FormField ff = (FormField) iter.next();
3042 if(!ff.getFieldName().equals(ff_src.getFieldName())) {
3043 //IdNameList lookup = null;
3044 //lookup = ff.getLookupList();
3045 String selectedValue = "";
3049 String [] requestParam = request.getParameterValues(ff.getFieldName());
3050 if(requestParam != null) {
3051 requestValueList = Arrays.asList(request.getParameterValues(ff.getFieldName()));
3054 requestValueList = new ArrayList<String>();
3058 if(nvl(ff_src.getBaseSQL()).length()>0 && ff_src.getBaseSQL().indexOf("["+ff.getFieldDisplayName() +"]")!= -1) {
3061 if(!ff_src.hasPredefinedList) {
3062 String formatSelected = null;
3063 if(ff_src.getFieldType().equals(FormField.FFT_LIST_MULTI) || ff_src.getFieldType().equals(FormField.FFT_CHECK_BOX)) {
3064 formatSelected = formatSelectedItems(requestValueList, ff_src.getFieldType());
3066 formatSelected = requestValueList.size()>0?requestValueList.get(0):"";
3067 SQL = Utils.replaceInString(SQL, "["+ff_src.getFieldDisplayName()+"]", formatSelected);
3068 defaultSQL = Utils.replaceInString(defaultSQL, "["+ff_src.getFieldDisplayName()+"]", formatSelected);
3069 defaultSQL = parseAndFillWithCurrentValues(request, defaultSQL, ff_src);
3070 defaultSQL = parseAndFillReq_Session_UserValues(request, defaultSQL, userId);
3071 SQL = parseAndFillReq_Session_UserValues(request, SQL, userId);
3072 SQL = parseAndFillWithCurrentValues(request, SQL, ff_src);
3075 } catch (Exception ex) {
3076 ex.printStackTrace();
3085 if(nvl(ff_src.getBaseSQL()).length()>0) {
3086 lookup = new IdNameSql(-1,SQL,defaultSQL);
3087 lookupList = lookup;
3089 lookup.loadUserData(0, "", ff_src.getDbInfo(), ff_src.getUserId());
3090 } catch (Exception e ){
3091 e.printStackTrace(); //throw new RaptorRuntimeException(e);
3093 if(!ff_src.hasPredefinedList) {
3094 lookup.trimToSize();
3095 for (lookup.resetNext(); lookup.hasNext();) {
3096 IdNameValue value = lookup.getNext();
3097 readOnly = value.isReadOnly();
3098 formFieldValues.add(value);
3101 ffJSON.setFormFieldValues(formFieldValues);
3103 if(!ff_src.hasPredefinedList) {
3104 if(oldSQL != null && !oldSQL.equals("")) {
3105 ((IdNameSql)lookup).setSQL(oldSQL);
3107 if(oldDefaultSQL != null && !oldDefaultSQL.equals("")) {
3108 ((IdNameSql)lookup).setDefaultSQL(oldDefaultSQL);
3118 private void triggerOtherFormFieldsWithThisValue(HttpServletRequest request, String userId, FormField ff_src, ArrayList<String> requestValueList, ArrayList<FormFieldJSON> formFieldJSONList) {
3119 ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>();
3120 //ArrayList<FormFieldJSON> formFieldJSONList = new ArrayList<FormFieldJSON>();
3121 for (Iterator iter = reportFormFields.iterator(); iter.hasNext();) {
3122 formFieldValues = new ArrayList<IdNameValue>();
3123 FormField ff = (FormField) iter.next();
3124 if(!ff_src.getFieldName().equals(ff.getFieldName())) {
3125 for (Iterator iter1 = formFieldJSONList.iterator(); iter1.hasNext();) {
3126 FormFieldJSON ffJSON = (FormFieldJSON) iter1.next();
3127 if(ffJSON.getFieldId().equals(ff.getFieldName()) && ffJSON.isVisible()) {
3128 if(nvl(ff.getBaseSQL()).length()>0 && ff.getBaseSQL().indexOf("["+ff_src.getFieldDisplayName() +"]")!= -1) {
3129 IdNameList lookup = null;
3130 lookup = ff.getLookupList();
3131 String selectedValue = "";
3133 String oldDefaultSQL = "";
3134 IdNameList lookupList = null;
3135 boolean readOnly = false;
3138 if(!ff.hasPredefinedList) {
3139 IdNameSql lu = (IdNameSql) lookup;
3140 String SQL = lu.getSql();
3141 oldSQL = lu.getSql();
3142 oldDefaultSQL = lu.getDefaultSQL();
3143 String defaultSQL = lu.getDefaultSQL();
3144 String formatSelected = null;
3145 if(ff_src.getFieldType().equals(FormField.FFT_LIST_MULTI) || ff_src.getFieldType().equals(FormField.FFT_CHECK_BOX)) {
3146 formatSelected = formatSelectedItems(requestValueList, ff.getFieldType());
3149 formatSelected = requestValueList.size()>0?requestValueList.get(0):"";
3150 SQL = Utils.replaceInString(SQL, "["+ff_src.getFieldDisplayName()+"]", formatSelected);
3151 defaultSQL = Utils.replaceInString(defaultSQL, "["+ff_src.getFieldDisplayName()+"]", formatSelected);
3152 defaultSQL = parseAndFillWithCurrentValues(request, defaultSQL, ff_src);
3153 defaultSQL = parseAndFillReq_Session_UserValues(request, defaultSQL, userId);
3154 SQL = parseAndFillReq_Session_UserValues(request, SQL, userId);
3155 SQL = parseAndFillWithCurrentValues(request, SQL, ff_src);
3156 lookup = new IdNameSql(-1,SQL,defaultSQL);
3157 lookupList = lookup;
3159 lookup.loadUserData(0, "", ff.getDbInfo(), ff.getUserId());
3160 } catch (Exception e ){
3161 e.printStackTrace(); //throw new RaptorRuntimeException(e);
3164 lookup.trimToSize();
3168 for (lookup.resetNext(); lookup.hasNext();) {
3169 IdNameValue value = lookup.getNext();
3170 readOnly = value.isReadOnly();
3171 // if(nvl(requestValue).length()>0) {
3172 // if(value.getId().equals(requestValue))
3173 // value.setDefaultValue(true);
3175 formFieldValues.add(value);
3179 ffJSON.setFormFieldValues(formFieldValues);
3181 if(!ff.hasPredefinedList) {
3182 if(oldSQL != null && !oldSQL.equals("")) {
3183 ((IdNameSql)lookup).setSQL(oldSQL);
3185 if(oldDefaultSQL != null && !oldDefaultSQL.equals("")) {
3186 ((IdNameSql)lookup).setDefaultSQL(oldDefaultSQL);
3189 } catch (Exception ex) {
3190 ex.printStackTrace();
3202 public String formatSelectedItems(List selectedItems, String type) {
3203 StringBuffer value = new StringBuffer("");
3205 boolean multiple = false;
3206 if(type.equals("LIST_MULTI_SELECT"))
3208 //multiple = (selectedItems.size()>1);
3209 for(Iterator iter = selectedItems.iterator(); iter.hasNext(); ) {
3211 String entry = (String) iter.next();
3212 if(count == 1 && multiple)
3214 //if(type.equals(FormField.FFT_CHECK_BOX))
3215 /*if(type.equals(FormField.FFT_CHECK_BOX))
3216 value.append("'"+Utils.oracleSafe(entry)+"'");
3217 else*/ if (type.equals(FormField.FFT_LIST_MULTI))
3218 value.append("'"+Utils.oracleSafe(entry)+"'");
3219 else if(type.equals(FormField.FFT_LIST_BOX))
3220 value.append(Utils.oracleSafe(entry));
3222 value.append("'"+Utils.oracleSafe(entry)+"'");
3223 if((count < selectedItems.size()) && multiple)
3225 if((count == selectedItems.size()) && multiple)
3229 if(value.length()>0)
3230 return value.toString();
3235 public String parseAndFillWithCurrentValues(HttpServletRequest request, String sql, FormField source_Formfield) {
3237 if (getFormFieldList() != null) {
3238 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
3239 FormFieldType fft = (FormFieldType) iter.next();
3240 String fieldId = fft.getFieldId();
3241 String fieldDisplay = getFormFieldDisplayName(fft);
3242 String formfield_value = "";
3243 List<String> selectedItems = new ArrayList<String>();
3244 //Added so that Combo Box in old RAPTOR definition is translated to List box
3245 if(fft.getFieldType().equals(FormField.FFT_COMBO_BOX)) {
3246 fft.setFieldType(FormField.FFT_LIST_BOX);
3248 if(!fft.getFieldType().equals(FormField.FFT_BLANK)) {
3249 //if(source_Formfield==null || (source_Formfield!=null && !fft.getFieldId().equals(source_Formfield.getFieldName()))) {
3251 // Add param base sql
3252 if(fft.getFieldType().equals(FormField.FFT_LIST_MULTI) || fft.getFieldType().equals(FormField.FFT_CHECK_BOX)) {
3253 if(request.getParameterValues(fieldId)!=null && request.getParameterValues(fieldId).length > 0) {
3255 selectedItems = Arrays.asList(request.getParameterValues(fieldId));
3256 formfield_value = formatSelectedItems(selectedItems, fft.getFieldType());
3258 formfield_value = "";
3260 } else if(fft.getFieldType().equals(FormField.FFT_RADIO_BTN)) {
3261 if(request.getParameter(fieldId)!=null) {
3262 formfield_value = request.getParameter(fieldId);
3264 formfield_value = "";
3266 } else if (fft.getFieldType().equals(FormField.FFT_HIDDEN)) {
3267 if(request.getParameter(fieldId)!=null) {
3268 formfield_value = request.getParameter(fieldId);
3270 formfield_value = "";
3272 } else if((fft.getFieldType().equals(FormField.FFT_TEXT) || fft.getFieldType().equals(FormField.FFT_TEXTAREA)) &&
3273 (!fft.getValidationType().equals(FormField.VT_DATE) && !fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)&&
3274 !fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) && !fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) ) {
3275 if(request.getParameter(fieldId)!=null) {
3276 formfield_value = request.getParameter(fieldId);
3278 formfield_value = "";
3280 } else if (fft.getValidationType().equals(FormField.VT_DATE) || fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)||
3281 fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) || fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
3282 /*if(formGrid.hasFellow(fieldId, true)) {
3283 Datebox tb = (Datebox) formGrid.getFellowIfAny(fieldId, true);
3285 formfield_value = tb.getText();
3286 } catch (WrongValueException ex) {
3287 formfield_value = "";
3289 if(AppUtils.nvl(formfield_value).length() > 0) {
3290 if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)) {
3291 if(formGrid.hasFellow(fieldId+"_Hr", true)) {
3292 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3293 formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3295 } else if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN)) {
3296 if(formGrid.hasFellow(fieldId+"_Min", true)) {
3297 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3298 //formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3299 Label hiddenLbMin = (Label) formGrid.getFellowIfAny(fieldId+"_Min", true);
3300 formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue();
3303 } else if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
3304 if(formGrid.hasFellow(fieldId+"_Sec", true)) {
3305 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3306 //formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3307 Label hiddenLbMin = (Label) formGrid.getFellowIfAny(fieldId+"_Min", true);
3308 //formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue();
3309 Label hiddenLbSec = (Label) formGrid.getFellowIfAny(fieldId+"_Sec", true);
3310 formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue()+ ":" +hiddenLbSec.getValue();
3317 formfield_value = "";
3319 } else if ((fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)||
3320 fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) || fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC))) {
3321 /*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 if(formGrid.hasFellow(fieldId+"_Hr", true)) {
3325 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3326 formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3328 } else if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN)) {
3329 if(formGrid.hasFellow(fieldId+"_Min", true)) {
3330 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3331 //formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3332 Label hiddenLbMin = (Label) formGrid.getFellowIfAny(fieldId+"_Min", true);
3333 formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue();
3336 } else if(fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
3337 if(formGrid.hasFellow(fieldId+"_Sec", true)) {
3338 Label hiddenLbHr = (Label) formGrid.getFellowIfAny(fieldId+"_Hr", true);
3339 //formfield_value = formfield_value + " " + hiddenLbHr.getValue();
3340 Label hiddenLbMin = (Label) formGrid.getFellowIfAny(fieldId+"_Min", true);
3341 //formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue();
3342 Label hiddenLbSec = (Label) formGrid.getFellowIfAny(fieldId+"_Sec", true);
3343 formfield_value = formfield_value + " " + hiddenLbHr.getValue() + ":" +hiddenLbMin.getValue()+ ":" +hiddenLbSec.getValue();
3349 } else if (fft.getFieldType().equals(FormField.FFT_TEXT_W_POPUP)) {
3350 if(request.getParameter(fieldId)!=null) {
3351 formfield_value = request.getParameter(fieldId);
3353 formfield_value = "";
3355 } else if (fft.getFieldType().equals(FormField.FFT_LIST_BOX)) {
3356 if(request.getParameter(fieldId)!=null) {
3357 formfield_value = request.getParameter(fieldId);
3359 formfield_value = "";
3363 if(nvl(formfield_value).length()>0) {
3364 sql = Utils.replaceInString(sql, fieldDisplay, formfield_value);
3366 sql = Utils.replaceInString(sql, "'"+fieldDisplay+"'", "null");
3367 sql = Utils.replaceInString(sql, fieldDisplay, "null");
3368 //sql = Utils.replaceInString(sql, fieldDisplay, "''");
3375 public String parseAndFillReq_Session_UserValues(HttpServletRequest request, String sql, String user_id) {
3376 HttpSession session = request.getSession();
3378 String[] reqParameters = Globals.getRequestParams().split(",");
3379 String[] sessionParameters = Globals.getSessionParams().split(",");
3380 String[] scheduleSessionParameters = Globals.getSessionParamsForScheduling().split(",");
3383 if(AppUtils.nvl(sql).length()>0) {
3384 for (int i = 0; i < reqParameters.length; i++) {
3385 if(!reqParameters[i].startsWith("ff") && (request.getParameter(reqParameters[i].toUpperCase())!=null && request.getParameter(reqParameters[i].toUpperCase()).length() > 0))
3386 sql = Utils.replaceInString(sql, "[" + reqParameters[i].toUpperCase()+"]", request.getParameter(reqParameters[i].toUpperCase()) );
3387 else if (request.getParameter(reqParameters[i])!=null && request.getParameter(reqParameters[i]).length() > 0)
3388 sql = Utils.replaceInString(sql, "[" + reqParameters[i].toUpperCase()+"]", request.getParameter(reqParameters[i]) );
3391 for (int i = 0; i < scheduleSessionParameters.length; i++) {
3392 //debugLogger.debug(" Session " + " scheduleSessionParameters[i] " + scheduleSessionParameters[i].toUpperCase() + " " + request.getParameter(scheduleSessionParameters[i]));
3393 if(request.getParameter(scheduleSessionParameters[i])!=null && request.getParameter(scheduleSessionParameters[i]).trim().length()>0 )
3394 sql = Utils.replaceInString(sql, "[" + scheduleSessionParameters[i].toUpperCase()+"]", request.getParameter(scheduleSessionParameters[i]) );
3395 if(request.getAttribute(scheduleSessionParameters[i])!=null && ((String)request.getAttribute(scheduleSessionParameters[i])).trim().length()>0 )
3396 sql = Utils.replaceInString(sql, "[" + scheduleSessionParameters[i].toUpperCase()+"]", (String) request.getAttribute(scheduleSessionParameters[i]) );
3400 for (int i = 0; i < sessionParameters.length; i++) {
3401 //if(!sessionParameters[i].startsWith("ff"))
3402 //fieldSQL = Utils.replaceInString(fieldSQL, "[" + sessionParameters[i].toUpperCase()+"]", (String)session.getAttribute(sessionParameters[i].toUpperCase()) );
3404 if (session.getAttribute(sessionParameters[i])!=null && ((String)session.getAttribute(sessionParameters[i])).length() > 0) {
3405 //debugLogger.debug(" Session " + " sessionParameters[i] " + sessionParameters[i] + " " + (String)session.getAttribute(sessionParameters[i]));
3406 sql = Utils.replaceInString(sql, "[" + sessionParameters[i].toUpperCase()+"]", (String)session.getAttribute(sessionParameters[i]) );
3410 sql = Utils.replaceInString(sql, "[USERID]", user_id);
3411 sql = Utils.replaceInString(sql, "[USER_ID]", user_id);
3412 sql = Utils.replaceInString(sql, "[LOGGED_USERID]", user_id);