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  /*
17   * Created on 2005/01/15
18   */
19  package org.seasar.tuigwaa.controller;
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.database.function.criteria.UnaryCriteriaFunction;
29  import org.seasar.tuigwaa.model.DAOService;
30  import org.seasar.tuigwaa.model.ModelService;
31  import org.seasar.tuigwaa.model.core.TgwEntity;
32  import org.seasar.tuigwaa.system.Constants;
33  import org.seasar.tuigwaa.util.TgwUtils;
34  import org.seasar.tuigwaa.util.ajax.AbstractRowSetAction;
35  import org.seasar.tuigwaa.util.ajax.RowSetForm;
36  
37  import com.isenshi.util.extlib.StrutsUtil;
38  
39  /***
40   * @author nishioka
41   */
42  public class DataFilterAction extends AbstractRowSetAction {
43  
44  	private ModelService entityService_;
45  
46  	private DAOService daoService_;
47  
48  	public DataFilterAction(ModelService entityService, DAOService daoService) {
49  		this.entityService_ = entityService;
50  		this.daoService_ = daoService;
51  	}
52  
53  	public String getFormName() {
54  		return "filterForm";
55  	}
56  
57  	public String getEditPath() {
58  		return "tiles.sitemanage.createFilter";
59  	}
60  
61  	public String getBasePath() {
62  		return "/listRecord.do";
63  	}
64  
65  	public ActionForward deleteFilter(ActionMapping mapping, ActionForm form,
66  			HttpServletRequest request, HttpServletResponse response)
67  			throws Exception {
68  
69  		TgwEntity entity = TgwUtils.getEntity(request, getServlet());
70  		String fileter = StrutsUtil.getURLDecodedParameter(request,
71  				Constants.PARAM_ENTITY_DELETEFILTER);
72  		daoService_.deregisterDaoMethod(entity, fileter);
73  		daoService_.saveFunction(entity);
74  		return TgwUtils.listRecordForward(mapping, request, entity.getName());
75  	}
76  
77  	public RowSetForm getNewRowSet(ActionMapping mapping, ActionForm form,
78  			HttpServletRequest request, HttpServletResponse response)
79  			throws Exception {
80  
81  		TgwEntity entity = TgwUtils.getEntity(request, getServlet());
82  
83  		String aggName = StrutsUtil.getURLDecodedParameter(request,
84  				Constants.PARAM_ENTITY_AGGREGATION);
85  
86  		if (aggName == null) {
87  			return new DataFilterForm(entity);
88  		} else {
89  			TgwEntity projectedEntity = daoService_.createProjectionEntity(
90  					entity, aggName);
91  			return new DataFilterForm(projectedEntity, aggName);
92  		}
93  	}
94  
95  	public RowSetForm getRowSet(ActionMapping mapping, ActionForm form,
96  			HttpServletRequest request, HttpServletResponse response)
97  			throws Exception {
98  		TgwEntity entity = TgwUtils.getEntity(request, getServlet());
99  		String filterName = StrutsUtil.getURLDecodedParameter(request,
100 				Constants.PARAM_ENTITY_FILTER);
101 
102 		CriteriaExeFunction function = (CriteriaExeFunction) daoService_
103 				.getDataFilterFunctionMap(entity).get(filterName);
104 
105 		return new DataFilterForm(entity, function);
106 	}
107 
108 	public ActionForward doSave(ActionMapping mapping, ActionForm form,
109 			HttpServletRequest request, HttpServletResponse response)
110 			throws Exception {
111 		
112 		DataFilterForm filterForm = (DataFilterForm) form;
113 		TgwEntity entity = filterForm.getEntity();
114 		String aggName = filterForm.getAggregationName();
115 
116 		CriteriaExeFunction filter = null;
117 		if (aggName == null) {
118 			filter = filterForm.getDataFilterFunction();
119 		} else {
120 			entity = entityService_.getEntity(entity.getDomainName(), entity
121 					.getName());
122 			UnaryCriteriaFunction dataFilter = filterForm
123 					.getUnaryCriteriaFunction();
124 			filter = daoService_.injectDataFilter(entity, aggName, dataFilter);
125 			filter.setName(filterForm.getName());
126 		}
127 		daoService_.registerDaoMethod(entity, filter);
128 		daoService_.saveFunction(entity);
129 
130 		return TgwUtils.dialoggCloseAndListRecordForward(mapping, request,
131 				entity.getName(), filterForm.getName());
132 	}
133 }