001: /*********************************************************************************
002: * The contents of this file are subject to the OpenI Public License Version 1.0
003: * ("License"); You may not use this file except in compliance with the
004: * License. You may obtain a copy of the License at
005: * http://www.openi.org/docs/LICENSE.txt
006: *
007: * Software distributed under the License is distributed on an "AS IS" basis,
008: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009: * the specific language governing rights and limitations under the License.
010: *
011: * The Original Code is: OpenI Open Source
012: *
013: * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
014: * Portions created by Loyalty Matrix, Inc. are
015: * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
016: *
017: * Contributor(s): i18n : Pedro Casals Fradera (2006/05/16)
018: *
019: ********************************************************************************/package org.openi.web.controller.analysis;
020:
021: import java.util.HashMap;
022: import java.util.List;
023: import java.util.Map;
024:
025: import javax.servlet.http.HttpServletRequest;
026: import javax.servlet.http.HttpServletResponse;
027:
028: import org.apache.log4j.Logger;
029: import org.openi.analysis.Datasource;
030: import org.openi.project.ProjectContext;
031: import org.openi.xmla.XmlaConnector;
032: import org.springframework.validation.BindException;
033: import org.springframework.web.servlet.ModelAndView;
034: import org.springframework.web.servlet.mvc.SimpleFormController;
035:
036: import com.tonbeller.jpivot.olap.model.OlapException;
037:
038: /**
039: * Controller to configure dashboard
040: */
041: public class AutoAnalysisFormController extends SimpleFormController {
042: private static Logger logger = Logger
043: .getLogger(AutoAnalysisFormController.class);
044: // private ProjectContext projectContext = null;
045:
046: private String selectOverviewFormView;
047: private String configureOverviewFormView;
048:
049: /**
050: * This method will create the command object and set it in its initial state.
051: * This method is called before the user is directed to the first page of the wizard
052: *
053: * @param request HttpServletRequest
054: * @return Object
055: * @throws Exception
056: *
057: */
058: protected Object formBackingObject(HttpServletRequest request)
059: throws Exception {
060: logger.debug("handling formBackingObject, request: "
061: + request.getParameterMap());
062: ProjectContext projectContext = (ProjectContext) request
063: .getSession().getAttribute("projectContext");
064: if (!projectContext.checkPermission("/autogenerate.htm")) {
065: throw new SecurityException(
066: "User does not have appropriate permission");
067: }
068:
069: //not just using the projectContext as a command object b/c it does not handle
070: // state (and shouldn't), should extend the AbstractWizardFormController?
071: Map model = new HashMap();
072: // model.put("overviews", projectContext.getProject().getOverviews());
073: // projectContext.getProject().setOverviews(this.getMockOverviewMap());
074: // model.put("overviews", this.getMockOverviewMap());
075: model.put("datasources", projectContext.getProject()
076: .getDataSourceMap());
077:
078: String targetDatasource = request
079: .getParameter("targetDatasource");
080: if (targetDatasource != null && targetDatasource.length() > 0) {
081: model.put("cubes", discoverCubes(projectContext
082: .getDatasource(targetDatasource)));
083: model.remove("targetCube");//reset the target cube
084: model.put("targetDatasource", targetDatasource);
085: }
086: return model;
087: }
088:
089: /**
090: * @param datasource
091: * @return
092: * @throws OlapException
093: */
094: private List discoverCubes(Datasource datasource)
095: throws OlapException {
096: return new XmlaConnector().getCubeList(datasource);
097: }
098:
099: /**
100: * Submit callback with all parameters. Called in case of submit without
101: * errors reported by the registered validator, or on every submit if no validator.
102: * @param request HttpServletRequest
103: * @param response HttpServletResponse
104: * @param command Object
105: * @param errors BindException
106: * @return ModelAndView
107: * @throws Exception
108: */
109: protected ModelAndView onSubmit(HttpServletRequest request,
110: HttpServletResponse response, Object command,
111: BindException errors) throws Exception {
112:
113: logger.debug("onSubmit: " + request.getParameterMap());
114: ProjectContext projectContext = (ProjectContext) request
115: .getSession().getAttribute("projectContext");
116:
117: Map model = (Map) command;
118: logger.debug("command map: " + model);
119: String targetDatasource = (String) model
120: .get("targetDatasource");
121: String targetCube = request.getParameter("targetCube");
122:
123: logger.debug("targetDatasource=" + targetDatasource);
124: logger.debug("targetCube=" + targetCube);
125:
126: projectContext.autogenerate(targetDatasource, targetCube,
127: "Auto_Generated/" + targetCube.replaceAll(" ", "_"),
128: null);
129:
130: //message, you have just created blah, to view all go here, or look in the navigation
131: // for a specific report
132:
133: return super.onSubmit(request, response, command, errors);
134: }
135:
136: }
|