KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > web > controller > analysis > AnalysisController


1 /*********************************************************************************
2  * The contents of this file are subject to the OpenI Public License Version 1.0
3  * ("License"); You may not use this file except in compliance with the
4  * License. You may obtain a copy of the License at
5  * http://www.openi.org/docs/LICENSE.txt
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is: OpenI Open Source
12  *
13  * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
14  * Portions created by Loyalty Matrix, Inc. are
15  * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
16  *
17  * Contributor(s): ______________________________________.
18  *
19  ********************************************************************************/

20 package org.openi.web.controller.analysis;
21
22 import com.tonbeller.wcf.controller.RequestContext;
23 import com.tonbeller.wcf.table.EditableTableComponent;
24 import org.apache.log4j.Logger;
25 import org.openi.analysis.Analysis;
26 import org.openi.analysis.Datasource;
27 import org.openi.application.Application;
28 import org.openi.chart.EnhancedChartComponent;
29 import org.openi.chart.EnhancedChartTag;
30 import org.openi.project.ProjectContext;
31 import org.openi.xmla.XMLAQueryTag;
32 import org.springframework.web.servlet.ModelAndView;
33 import org.springframework.web.servlet.mvc.AbstractController;
34 import java.util.*;
35 import javax.servlet.http.HttpServletRequest JavaDoc;
36 import javax.servlet.http.HttpServletResponse JavaDoc;
37 import javax.servlet.http.HttpSession JavaDoc;
38 import org.openi.menu.ToolbarState;
39 import org.openi.security.Permission;
40
41 /**
42  * @author Uddhab Pant <br>
43  *
44  * Controller to handle analysis request. It does following tasks:
45  * <ul>
46  * <li> Restores analysis when analysis link is clicked.
47  * <li> Retrieves datasource.
48  * <li> Creates and configures query.
49  * <li> Creates and customizes chart.
50  * </ul>
51  *
52  */

53 public class AnalysisController extends AbstractController {
54     private static Logger logger = Logger.getLogger(AnalysisController.class);
55     private HttpSession JavaDoc session = null;
56     private Analysis analysis = null;
57     private ProjectContext projectContext = null;
58
59     /**
60      *
61      * @param request HttpServletRequest
62      * @param response HttpServletResponse
63      * @return ModelAndView
64      * @throws Exception
65      */

66     protected ModelAndView handleRequestInternal(HttpServletRequest JavaDoc request,
67             HttpServletResponse JavaDoc response) throws Exception JavaDoc {
68         Map model;
69         String JavaDoc analysisConfigName = null;
70         Datasource datasource = null;
71         
72         session = request.getSession();
73         // get project context from session
74
projectContext = (ProjectContext) session.getAttribute("projectContext");
75         
76         //wcf toolbar requires reference bean in session
77
ToolbarState newButtonState = new ToolbarState();
78         newButtonState.setVisible( projectContext.hasPermission(Permission.CREATE_NEW));
79         session.setAttribute("newButtonState", newButtonState);
80         ////
81
try {
82             // setting attribute to request. This attribute is used to check whether
83
// current view is analysis page or not.
84
request.setAttribute("analysisPage", "true");
85             
86             // analysis name
87
analysisConfigName = request.getParameter("config");
88             
89             model = new HashMap();
90             
91             
92             
93             // when clicked on analyses link
94
if (request.getParameter("config") != null) {
95                 // store analysis config in session
96
session.setAttribute("analysisConfigName", analysisConfigName);
97                 
98                 // remove jPivot and wcf objects from session
99
removeSessionObjects();
100                 
101                 // restore analysis from file
102
if (!"newanalysis".equalsIgnoreCase(analysisConfigName)) {
103                     analysis = projectContext.restoreAnalysis(analysisConfigName);
104                     session.setAttribute("analysis01", analysis);
105                 } else {
106                     analysis = (Analysis) session.getAttribute("analysis01");
107                 }
108                 
109                 // get datasource of the analysis.
110
datasource = projectContext.getDatasource(analysis
111                         .getDataSourceName());
112                 
113                 // Query object
114
XMLAQueryTag query = new XMLAQueryTag();
115                 
116                 // set query properties
117
query.setCatalog(datasource.getCatalog());
118                 query.setMdxQuery(analysis.getMdxQuery());
119                 query.setUri(datasource.getServer());
120                 query.setId("query01");
121                 
122                 // if basic authentication is enabled, set username and password to query.
123
if (Application.getInstance().isBasicAuthentication()) {
124                     query.setUser(request.getUserPrincipal().getName());
125                     query.setPassword((String JavaDoc) session.getAttribute(
126                     "user.credentials"));
127                 } else {
128                     query.setUser("");
129                     query.setPassword("");
130                 }
131                 
132                 // initialize query object. this also store query object in session.
133
query.init(RequestContext.instance());
134                 
135                 // create object of enhanced chart tag/
136
EnhancedChartTag chartTag = new EnhancedChartTag();
137                 
138                 // set query to chart tag.
139
chartTag.setQuery("query01");
140                 
141                 // create enhanced chart component from chart tag object
142
EnhancedChartComponent chart = (EnhancedChartComponent) chartTag
143                 .createComponent(RequestContext.instance());
144                 chart.initialize(RequestContext.instance());
145                 
146                 this.setChartSize(chart);
147                 this.translateChart(chart);// translate chart to wcf chart component
148

149                 session.setAttribute("chart01", chart);
150                 
151                 //session.removeAttribute("drillthrough");
152
} else {
153                 //session.removeAttribute("config");
154
//model.put("config", null);
155
}
156             
157             if (request.getParameter("toolbar02.drillThrough01.x") != null) {
158                 request.setAttribute("drillButtonClicked", "true");
159             }
160             model.put("readOnly", projectContext.hasPermission(Permission.READ_ONLY)?Boolean.TRUE:Boolean.FALSE);
161             return new ModelAndView("analysisView", "model", model);
162         } catch (Exception JavaDoc e) {
163             logger.error("Exception:", e);
164             throw e;
165         }
166     }
167     
168     private void setChartSize(EnhancedChartComponent chart){
169         if (analysis.isUseChartSize()) {
170             chart.setChartHeight(analysis.getChartHeight());
171             chart.setChartWidth(analysis.getChartWidth());
172
173             // otherwise set chart size based on screen size.
174
} else {
175             // set chart height and width as per client window height and width.
176
if (session.getAttribute("clientWindowWidth") != null) {
177                 chart.setChartWidth(Integer.parseInt(
178                         session.getAttribute("clientWindowWidth").toString())
179                     - 250);
180             }
181
182             if (session.getAttribute("clientWindowHeight") != null) {
183                 chart.setChartHeight((Integer.parseInt(
184                         session.getAttribute("clientWindowHeight").toString()) / 2)
185                     + 150);
186             }
187         }
188     }
189
190     private void translateChart(EnhancedChartComponent chart) {
191         // use persisted chart size is set to true, set chart size from restored values.
192

193         
194         // set color palette
195
List palette = (List) projectContext.getProject()
196         .getColorPalette(projectContext.getProject()
197                 .getDefaultPaletteName());
198         chart.setColorPalette(palette);
199         
200         chart.setShowPareto(analysis.getShowPareto());
201         chart.setForegroundAlpha(analysis.getForegroundAlpha());
202         
203         chart.setChartTitle(analysis.getChartTitle());
204         chart.setChartType(analysis.getChartType());
205         chart.setFontName(analysis.getFontName());
206         chart.setFontStyle(analysis.getFontStyle());
207         chart.setFontSize(analysis.getFontSize());
208         
209         //legend
210
chart.setShowLegend(analysis.isShowLegend());
211         
212         //if legend is visible, set properties
213
if (analysis.isShowLegend() == true) {
214             chart.setLegendFontName(analysis.getLegendFontName());
215             chart.setLegendFontStyle(analysis.getLegendFontStyle());
216             chart.setLegendFontSize(analysis.getLegendFontSize());
217             chart.setLegendPosition(analysis.getLegendPosition());
218         }
219         
220         //slicer
221
chart.setShowSlicer(analysis.isShowSlicer());
222         
223         //if slicer is visible, set properties
224
if (analysis.isShowSlicer() == true) {
225             chart.setSlicerPosition(analysis.getSlicerPosition());
226             chart.setSlicerAlignment(analysis.getSlicerAlignment());
227             chart.setSlicerFontName(analysis.getSlicerFontName());
228             chart.setSlicerFontStyle(analysis.getSlicerFontStyle());
229             chart.setSlicerFontSize(analysis.getSlicerFontSize());
230         }
231         
232         //axes
233
chart.setAxisFontName(analysis.getAxisFontName());
234         chart.setAxisFontStyle(analysis.getAxisFontStyle());
235         chart.setAxisFontSize(analysis.getAxisFontSize());
236         chart.setHorizAxisLabel(analysis.getHorizAxisLabel());
237         chart.setVertAxisLabel(analysis.getVertAxisLabel());
238         chart.setAxisTickFontName(analysis.getAxisTickFontName());
239         chart.setAxisTickFontStyle(analysis.getAxisTickFontStyle());
240         chart.setAxisTickFontSize(analysis.getAxisTickFontSize());
241         
242         chart.setDrillThroughEnabled(analysis.isDrillThroughEnabled());
243         chart.setTickLabelRotate(analysis.getTickLabelRotate());
244         
245         chart.setUseChartSize(analysis.isUseChartSize());
246         
247         //set chart visible status
248
chart.setVisible(analysis.isShowChart());
249         
250         // background color
251
chart.setBgColorB(analysis.getBgColorB());
252         chart.setBgColorG(analysis.getBgColorG());
253         chart.setBgColorR(analysis.getBgColorR());
254         
255         chart.setWriteImageMap(projectContext.getProject().getWriteImageMap());
256     }
257     
258     /**
259      * Removes jPovt and WCF objects from session
260      *
261      */

262     private void removeSessionObjects() {
263         //remove following objects from session.
264
if (session.getAttribute("query01") != null) {
265             session.removeAttribute("query01");
266         }
267         
268         if (session.getAttribute("table01") != null) {
269             session.removeAttribute("table01");
270         }
271         
272         if (session.getAttribute("minichartform01") != null) {
273             session.removeAttribute("minichartform01");
274         }
275         
276         if (session.getAttribute("mdxedit01") != null) {
277             session.removeAttribute("mdxedit01");
278         }
279         
280         if (session.getAttribute("navi01") != null) {
281             session.removeAttribute("navi01");
282         }
283         
284         if (session.getAttribute("print01") != null) {
285             session.removeAttribute("print01");
286         }
287         
288         if (session.getAttribute("sortform01") != null) {
289             session.removeAttribute("sortform01");
290         }
291         
292         if (session.getAttribute("printform01") != null) {
293             session.removeAttribute("printform01");
294         }
295         
296         if (session.getAttribute("chartform01") != null) {
297             session.removeAttribute("chartform01");
298         }
299         
300         if (session.getAttribute("query01.drillthroughtable") != null) {
301             session.removeAttribute("query01.drillthroughtable");
302         }
303     }
304 }
305
Popular Tags