001: /*
002: * (C) Copyright 2000 - 2006 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019: package com.nabhinc.portlet.report;
020:
021: import java.io.IOException;
022:
023: import javax.portlet.PortletException;
024: import javax.portlet.RenderRequest;
025: import javax.portlet.RenderResponse;
026:
027: import com.nabhinc.core.Defaults;
028: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
029: import com.nabhinc.portlet.mvcportlet.core.RenderConfig;
030: import com.nabhinc.portlet.mvcportlet.core.RenderProcessor;
031: import com.nabhinc.util.StringUtil;
032:
033: /**
034: * Helper class for Report creation.
035: *
036: * @author Padmanabh Dabke
037: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
038: */
039: public class ReportCreator extends BaseRequestProcessor implements
040: RenderProcessor {
041:
042: /* (non-Javadoc)
043: * @see com.nabhinc.portlet.mvcportlet.core.RenderProcessor#process(javax.portlet.RenderRequest, javax.portlet.RenderResponse, com.nabhinc.portlet.mvcportlet.core.RenderConfig)
044: */
045: public String process(RenderRequest request,
046: RenderResponse response, RenderConfig renderConfig)
047: throws PortletException, IOException {
048:
049: String tableName = request.getParameter("table_name");
050: if (tableName != null) {
051: String fieldsStr = request.getParameter("report_columns");
052: String[] reportFields = StringUtil.split(fieldsStr, ",");
053: String orderFields = request.getParameter("order_columns");
054: String groupBy = request.getParameter("group_column");
055: String where = request.getParameter("where_clause");
056: String reportSQL = null;
057: String dataSource = request.getParameter("datasource");
058: if (groupBy != null && groupBy.length() > 0) {
059: reportSQL = "SELECT " + fieldsStr + "," + groupBy
060: + " FROM " + tableName;
061: } else {
062: reportSQL = "SELECT " + fieldsStr + " FROM "
063: + tableName;
064: }
065:
066: if (where != null && where.length() > 0) {
067: reportSQL = reportSQL + " WHERE " + where;
068: }
069:
070: if (groupBy != null && groupBy.length() > 0) {
071: reportSQL = reportSQL + " ORDER BY " + groupBy;
072: if (orderFields != null && orderFields.length() > 0) {
073: reportSQL = reportSQL + "," + orderFields;
074: }
075: } else {
076: if (orderFields != null && orderFields.length() > 0) {
077: reportSQL = reportSQL + " ORDER BY " + orderFields;
078: }
079: }
080:
081: ReportPortlet reportPortlet = new ReportPortlet();
082: reportPortlet.setReportSQL(reportSQL);
083: if (dataSource != null && dataSource.length() > 0) {
084: reportPortlet.setDataSourceName(dataSource);
085: } else {
086: reportPortlet.setDataSourceName(Defaults
087: .getDataSourceName());
088: }
089: String[] columnHeaders = StringUtil.split(request
090: .getParameter("column_headers"), ",");
091: if (columnHeaders != null)
092: reportPortlet.setColumnHeaders(columnHeaders);
093:
094: String groupColumn = request.getParameter("group_column");
095: if (groupColumn != null && groupColumn.length() > 0) {
096: reportPortlet
097: .setGroupExpressions(new String[] { groupColumn });
098: reportPortlet.setGroupNames(new String[] { groupColumn
099: + "Group" });
100: }
101: String groupHeader = request.getParameter("group_header");
102: if (groupHeader != null && groupHeader.length() > 0) {
103: reportPortlet
104: .setGroupHeaders(new String[] { groupHeader });
105: }
106: String groupFooter = request.getParameter("group_footer");
107: if (groupFooter != null && groupFooter.length() > 0) {
108: reportPortlet
109: .setGroupFooters(new String[] { groupFooter });
110: }
111:
112: String[] report = reportPortlet.generateContent("0", 5);
113: request.getPortletSession().setAttribute(
114: "mvcportlet.report", report);
115: }
116: //rcReportPortlet.setColumnHeaders(columnHeaders);
117: return "success";
118: }
119:
120: }
|