View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.tuigwaa.controller;
17  
18  
19  import java.util.Map;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpServletResponse;
23  
24  import org.apache.struts.action.ActionForm;
25  import org.apache.struts.action.ActionForward;
26  import org.apache.struts.action.ActionMapping;
27  import org.seasar.tuigwaa.database.function.CriteriaExeFunction;
28  import org.seasar.tuigwaa.model.DAOService;
29  import org.seasar.tuigwaa.model.DataService;
30  import org.seasar.tuigwaa.model.core.TgwEntity;
31  import org.seasar.tuigwaa.system.Constants;
32  import org.seasar.tuigwaa.util.TgwUtils;
33  import org.seasar.tuigwaa.util.ajax.AbstractRowSetAction;
34  import org.seasar.tuigwaa.util.ajax.RowSetForm;
35  
36  
37  public class AggregationAction extends AbstractRowSetAction {
38  
39  	private DAOService daoService_;
40  			
41  	public AggregationAction(DAOService daoService) {
42  		this.daoService_ = daoService;
43  	}
44  
45  	public String getFormName() {
46  		return "aggregationForm";
47  	}
48  
49  	public String getEditPath() {
50  		return "tiles.sitemanage.createAggregation";
51  	}
52  
53  	public String getBasePath() {
54  		return "/listRecord.do";
55  	}
56  
57  	public RowSetForm getNewRowSet(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
58  		TgwEntity entity = TgwUtils.getEntity(request, getServlet());	
59  		Map map = daoService_.getDataFilterFunctionMap(entity);
60  	
61  		String valueStr = request.getParameter(Constants.PARAM_VALUE);
62  		boolean valueFlag = "true".equals(valueStr);
63  		AggregationForm aggForm = new AggregationForm(entity, map);
64  		aggForm.setValueFlag(valueFlag);
65  		return aggForm;
66  	}
67  
68  	public RowSetForm getRowSet(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
69  		// TODO Auto-generated method stub
70  		return null;
71  	}
72  
73  	public ActionForward doSave(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
74  		AggregationForm aggForm = (AggregationForm)form;
75  		
76  		CriteriaExeFunction function = aggForm.getAggregatoinExeFunction();
77  		TgwEntity entity  = aggForm.getEntity();
78  		
79  		daoService_.registerDaoMethod(entity, function);
80  		daoService_.saveFunction(entity);
81  		
82  		String daoType = (aggForm.isValueFlag())?DataService.DAOTYPE_VALUE:DataService.DAOTYPE_AGGREGATION;
83  		
84  		return TgwUtils.dialoggCloseAndListRecordForward(mapping, request, entity.getName(),
85  				aggForm.getName(), daoType);
86  	}
87  }