KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > war > action > ViewOlapModelAction


1 package com.jaspersoft.jasperserver.war.action;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7 import javax.servlet.http.HttpSession JavaDoc;
8
9 import org.apache.log4j.Logger;
10 import org.springframework.webflow.Event;
11 import org.springframework.webflow.RequestContext;
12 import org.springframework.webflow.context.servlet.ServletExternalContext;
13
14 import com.jaspersoft.jasperserver.api.JSException;
15 import com.jaspersoft.jasperserver.api.common.domain.impl.ExecutionContextImpl;
16 import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService;
17 import com.jaspersoft.jasperserver.api.metadata.olap.domain.OlapUnit;
18 import com.jaspersoft.jasperserver.api.metadata.olap.service.OlapConnectionService;
19 import com.tonbeller.jpivot.olap.model.OlapModel;
20 import com.tonbeller.jpivot.tags.OlapModelProxy;
21
22 /**
23  *
24  * ViewOlapModelAction provides actions to display JPivot olap view
25  *
26  * @author jshih
27  */

28 public class ViewOlapModelAction extends RepositoryAction {
29     protected final Logger logger = Logger.getLogger(getClass());
30     public static final String JavaDoc OLAPUNIT_ATTR = "olapUnit";
31     private OlapConnectionService olapConnectionService;
32     private RepositoryService repository;
33     private RequestContext requestContext;
34     private OlapConnectionService olapConnection;
35     private String JavaDoc olapUnitName;
36     private OlapUnit olapUnit;
37     private OlapModel olapModel;
38     
39     /**
40      * initAction performs the initialization for the olap model controller
41      *
42      * @param context
43      * @return
44      */

45     public Event initOlapModel(RequestContext context)
46     {
47         String JavaDoc viewUri = (String JavaDoc) context.getFlowScope().get("name");
48         ServletExternalContext sec = (ServletExternalContext) context.getExternalContext();
49         HttpServletRequest JavaDoc req = sec.getRequest();
50         init(viewUri, req);
51         return success();
52     }
53
54     /**
55      * From OlapModelController
56      *
57      * @param req
58      */

59     private void init(String JavaDoc viewUri, HttpServletRequest JavaDoc req) {
60         if (viewUri == null || viewUri.length() == 0) {
61             throw new JSException("No OLAP Model name");
62         }
63         logger.debug("Viewing OLAP Model: " + viewUri);
64         
65         req.setAttribute("name", viewUri);
66         
67         HttpSession JavaDoc sess = req.getSession();
68         Map JavaDoc olapModels = (Map JavaDoc) sess.getAttribute("olapModels");
69         if (olapModels == null) {
70             olapModels = new HashMap JavaDoc();
71             sess.setAttribute("olapModels", olapModels);
72         }
73         
74         OlapSessionState sessionState = (OlapSessionState) olapModels.get(viewUri);
75         if (sessionState == null) {
76             sessionState = getOlapSession(viewUri, sess);
77             olapModels.put(viewUri, sessionState);
78         }
79         req.setAttribute("olapModel", sessionState.getOlapModel());
80         req.setAttribute("olapSession", sessionState);
81         
82         // Because WCF is so behind the times, we have to also set the
83
// session attribute by name
84

85         sess.setAttribute("olapModel", sessionState.getOlapModel());
86     }
87
88     /**
89      * From OlapModelController
90      *
91      * @param viewUri
92      * @param sess
93      * @return
94      */

95     protected OlapSessionState getOlapSession(String JavaDoc viewUri, HttpSession JavaDoc sess) {
96         
97         logger.debug("Setting OlapModel for " + viewUri);
98         
99         com.tonbeller.wcf.controller.RequestContext context = com.tonbeller.wcf.controller.RequestContext.instance();
100         ExecutionContextImpl executionContext = new ExecutionContextImpl();
101         
102         OlapUnit olapUnit = (OlapUnit) getRepository().getResource(executionContext,
103                 viewUri);
104         
105         if (olapUnit == null) {
106             throw new JSException("No OLAP Model retrieved");
107         }
108         
109         OlapModel model = getOlapConnectionService().createOlapModel(executionContext, olapUnit);
110         
111         if (model == null) {
112             throw new JSException("No OLAP Model created for: " + viewUri);
113         }
114             
115         model = (OlapModel) model.getTopDecorator();
116         model.setLocale(context.getLocale());
117         model.setServletContext(context.getSession().getServletContext());
118         model.setID(viewUri);
119
120         model.setServletContext(sess.getServletContext());
121 /*
122         ClickableExtension ext = (ClickableExtension) model.getExtension(ClickableExtension.ID);
123         if (ext == null) {
124             ext = new ClickableExtensionImpl();
125             model.addExtension(ext);
126         }
127         ext.setClickables(clickables);
128 */

129         // stackMode
130

131         OlapModelProxy omp = OlapModelProxy.instance(viewUri, sess, false);
132 /* if (queryName != null)
133             omp.initializeAndShow(queryName, model);
134         else
135 */

136         try {
137             omp.initializeAndShow(viewUri, model);
138         } catch (Exception JavaDoc e) {
139             throw new JSException(e);
140         }
141
142         return new OlapSessionState(omp, olapUnit);
143     }
144     
145     /**
146      * From OlapModelController
147      *
148      * @author jshih
149      *
150      */

151     public class OlapSessionState {
152         private OlapModel olapModel;
153         private OlapUnit olapUnit;
154         
155         public OlapSessionState(OlapModel olapModel, OlapUnit olapUnit) {
156             this.olapModel = olapModel;
157             this.olapUnit = olapUnit;
158         }
159         
160         /**
161          * @return Returns the olapModel.
162          */

163         public OlapModel getOlapModel() {
164             return olapModel;
165         }
166         /**
167          * @param olapModel The olapModel to set.
168          */

169         public void setOlapModel(OlapModel olapModel) {
170             this.olapModel = olapModel;
171         }
172         /**
173          * @return Returns the olapUnit.
174          */

175         public OlapUnit getOlapUnit() {
176             return olapUnit;
177         }
178         /**
179          * @param olapUnit The olapUnit to set.
180          */

181         public void setOlapUnit(OlapUnit olapUnit) {
182             this.olapUnit = olapUnit;
183         }
184     }
185     
186     /**
187      * getOlapUnit retrieves the uri of specified olap unit
188      *
189      * @param requestContext
190      * @return success or error
191      */

192     public Event getOlapUnit(RequestContext requestContext) {
193         Event result = success();
194         ExecutionContextImpl executionContext = new ExecutionContextImpl();
195         this.requestContext = requestContext;
196         if ((olapUnitName = (String JavaDoc) requestContext.getFlowScope().get(
197                 OLAPUNIT_ATTR)) == null) {
198             result = error();
199         } else if ((olapUnit = (OlapUnit) repository.getResource(
200                 executionContext, olapUnitName)) == null) {
201             result = error();
202         }
203
204         return result;
205     }
206     
207     /**
208      * createOlapModel action
209      *
210      * @param requestContext
211      * @return success or error
212      */

213     public Event createOlapModel(RequestContext requestContext)
214     {
215         Event result = success();
216         ExecutionContextImpl executionContext = new ExecutionContextImpl();
217         olapModel = olapConnection.createOlapModel(executionContext, olapUnit);
218         if (olapModel == null) {
219             result = error();
220         }
221         return result;
222     }
223
224     /**
225      * displayOlapModel action
226      *
227      * @param requestContext
228      * @return
229      */

230     public Event displayOlapModel(RequestContext requestContext) {
231         Event result = success();
232
233         requestContext.getRequestScope().put("olapUnitName", olapUnitName);
234
235         return result;
236     }
237
238     /**
239      * @return Returns the olapConnectionService.
240      */

241     public OlapConnectionService getOlapConnectionService() {
242         return olapConnectionService;
243     }
244
245     /**
246      * @param olapConnectionService The olapConnectionService to set.
247      */

248     public void setOlapConnectionService(OlapConnectionService olapConnectionService) {
249         this.olapConnectionService = olapConnectionService;
250     }
251     
252     public RepositoryService getRepository() {
253         return repository;
254     }
255
256     public void setRepository(RepositoryService repository) {
257         this.repository = repository;
258     }
259
260     public OlapConnectionService getOlapConnection() {
261         return olapConnection;
262     }
263                 
264     public void setOlapConnection(OlapConnectionService olapConnection) {
265         this.olapConnection = olapConnection;
266     }
267     
268     public OlapModel getOlapModel() {
269         return olapModel;
270     }
271                 
272     public void setOlapModel(OlapModel olapModel) {
273         this.olapModel = olapModel;
274     }
275
276 }
277
Popular Tags