KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.log4j.Logger;
23 import org.openi.analysis.Datasource;
24 import org.openi.menu.AnalysisCollectionMenuVisitor;
25 import org.openi.project.DirectoryLister;
26 import org.openi.project.Overview;
27 import org.openi.project.ProjectContext;
28 import org.openi.security.Permission;
29 import org.openi.util.*;
30 import org.openi.xml.*;
31 import org.openi.xmla.XmlaConnector;
32 import org.springframework.validation.BindException;
33 import org.springframework.validation.Errors;
34 import org.springframework.validation.ObjectError;
35 import org.springframework.web.servlet.ModelAndView;
36 import org.springframework.web.servlet.mvc.SimpleFormController;
37 import org.springframework.web.servlet.view.RedirectView;
38
39 import com.tonbeller.jpivot.olap.model.OlapException;
40
41 import java.io.*;
42 import java.util.*;
43 import javax.servlet.http.HttpServletRequest JavaDoc;
44 import javax.servlet.http.HttpServletResponse JavaDoc;
45 import javax.servlet.http.HttpSession JavaDoc;
46
47
48 /**
49  * Controller to configure dashboard
50  */

51 public class AutoAnalysisFormController extends SimpleFormController {
52     private static Logger logger = Logger.getLogger(AutoAnalysisFormController.class);
53     // private ProjectContext projectContext = null;
54

55
56     private String JavaDoc selectOverviewFormView;
57     private String JavaDoc configureOverviewFormView;
58     
59
60     /**
61      * This method will create the command object and set it in its initial state.
62      * This method is called before the user is directed to the first page of the wizard
63      *
64      * @param request HttpServletRequest
65      * @return Object
66      * @throws Exception
67      *
68      */

69     protected Object JavaDoc formBackingObject(HttpServletRequest JavaDoc request)
70         throws Exception JavaDoc {
71         logger.debug("handling formBackingObject, request: " + request.getParameterMap());
72         ProjectContext projectContext = (ProjectContext) request.getSession()
73                                           .getAttribute("projectContext");
74             if(!projectContext.hasPermission(Permission.AUTOGENERATE)){
75                 throw new SecurityException JavaDoc("User does not have appropriate permission");
76         }
77                 
78         //not just using the projectContext as a command object b/c it does not handle
79
// state (and shouldn't), should extend the AbstractWizardFormController?
80
Map model = new HashMap();
81         // model.put("overviews", projectContext.getProject().getOverviews());
82
// projectContext.getProject().setOverviews(this.getMockOverviewMap());
83
// model.put("overviews", this.getMockOverviewMap());
84
model.put("datasources", projectContext.getProject().getDataSourceMap());
85         
86         String JavaDoc targetDatasource = request.getParameter("targetDatasource");
87         if(targetDatasource!=null && targetDatasource.length()>0){
88             model.put("cubes", discoverCubes(projectContext.getDatasource(targetDatasource)));
89             model.remove("targetCube");//reset the target cube
90
model.put("targetDatasource", targetDatasource);
91         }
92         return model;
93     }
94
95     
96     /**
97      * @param datasource
98      * @return
99      * @throws OlapException
100      */

101     private List discoverCubes(Datasource datasource) throws OlapException {
102         return new XmlaConnector().getCubeList(datasource.getServer(), datasource.getCatalog(), datasource.getUsername(), datasource.getPassword());
103     }
104
105
106     /**
107      * Submit callback with all parameters. Called in case of submit without
108      * errors reported by the registered validator, or on every submit if no validator.
109      * @param request HttpServletRequest
110      * @param response HttpServletResponse
111      * @param command Object
112      * @param errors BindException
113      * @return ModelAndView
114      * @throws Exception
115      */

116     protected ModelAndView onSubmit(HttpServletRequest JavaDoc request,
117         HttpServletResponse JavaDoc response, Object JavaDoc command, BindException errors)
118     throws Exception JavaDoc
119         {
120         
121             logger.debug("onSubmit: " + request.getParameterMap());
122             ProjectContext projectContext = (ProjectContext)request.getSession().getAttribute("projectContext");
123             
124             if(!projectContext.hasPermission(Permission.AUTOGENERATE)){
125                 throw new SecurityException JavaDoc("User does not have appropriate permission");
126         }
127             
128             Map model = (Map)command;
129             logger.debug("command map: " + model);
130             String JavaDoc targetDatasource = (String JavaDoc)model.get("targetDatasource");
131             String JavaDoc targetCube = request.getParameter("targetCube");
132     
133             logger.debug("targetDatasource=" + targetDatasource);
134             logger.debug("targetCube=" + targetCube);
135             
136             projectContext.autogenerate(targetDatasource,
137                     targetCube,
138                     "Auto_Generated/" + targetCube.replaceAll(" ", "_"));
139             
140             //message, you have just created blah, to view all go here, or look in the navigation
141
// for a specific report
142

143             return super.onSubmit(request, response, command, errors);
144     }
145
146
147
148 }
149
Popular Tags