1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.controller;
17
18 import java.util.Collection;
19 import java.util.Iterator;
20 import java.util.Map;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionForward;
27 import org.apache.struts.action.ActionMapping;
28 import org.apache.struts.actions.MappingDispatchAction;
29 import org.seasar.tuigwaa.database.function.UpdateExeFunction;
30 import org.seasar.tuigwaa.model.DAOService;
31 import org.seasar.tuigwaa.model.ModelService;
32 import org.seasar.tuigwaa.model.common.EntityInfo;
33 import org.seasar.tuigwaa.model.core.TgwEntity;
34 import org.seasar.tuigwaa.system.Constants;
35 import org.seasar.tuigwaa.util.TgwUtils;
36
37 import com.isenshi.util.extlib.StrutsUtil;
38
39 public class UpdateRuleAction extends MappingDispatchAction {
40
41 public DAOService daoService;
42
43 public ModelService modelservice;
44
45 public UpdateRuleAction(DAOService daoService, ModelService modelService) {
46 this.daoService = daoService;
47 this.modelservice = modelService;
48 }
49
50 public ActionForward create(ActionMapping mapping, ActionForm form,
51 HttpServletRequest request, HttpServletResponse response)
52 throws Exception {
53 TgwEntity entity = TgwUtils.getEntity(request, getServlet());
54 UpdateRuleForm updateRuleForm = new UpdateRuleForm(entity);
55 request.getSession().setAttribute(Constants.SATTR_FORM_UPDATERULE,
56 updateRuleForm);
57 return mapping.findForward("success");
58 }
59
60 public ActionForward edit(ActionMapping mapping, ActionForm form,
61 HttpServletRequest request, HttpServletResponse response)
62 throws Exception {
63 TgwEntity entity = TgwUtils.getEntity(request, getServlet());
64
65 String filterName = StrutsUtil.getURLDecodedParameter(request,
66 Constants.PARAM_ENTITY_FILTER);
67
68 EntityInfo info = modelservice.createEntityInfo(entity.getDomainName(),
69 entity.getName());
70
71 UpdateExeFunction function = null;
72
73 Collection collection = info.getUpdateRuleList();
74 Iterator itr = collection.iterator();
75 while (itr.hasNext()) {
76 UpdateExeFunction func = (UpdateExeFunction) itr.next();
77 if (filterName != null && filterName.equals(func.getName())) {
78 function = func;
79 }
80 }
81 UpdateRuleForm updateRuleForm = new UpdateRuleForm(entity, function);
82 request.getSession().setAttribute(Constants.SATTR_FORM_UPDATERULE,
83 updateRuleForm);
84 return mapping.findForward("success");
85 }
86
87 public ActionForward save(ActionMapping mapping, ActionForm form,
88 HttpServletRequest request, HttpServletResponse response)
89 throws Exception {
90 UpdateRuleForm ruleForm = (UpdateRuleForm) form;
91 UpdateExeFunction updateExe = ruleForm.getUpdateExeFunction();
92 TgwEntity entity = ruleForm.getEntity();
93 daoService.registerDaoMethod(entity, updateExe);
94 daoService.saveFunction(entity);
95
96 return TgwUtils.dialoggCloseAndListRecordForward(mapping, request,
97 entity.getName(), null);
98 }
99
100 public ActionForward delete(ActionMapping mapping, ActionForm form,
101 HttpServletRequest request, HttpServletResponse response)
102 throws Exception {
103 TgwEntity entity = TgwUtils.getEntity(request, getServlet());
104 String filterName = StrutsUtil.getURLDecodedParameter(request,
105 Constants.PARAM_ENTITY_DELETEFILTER);
106 daoService.deregisterDaoMethod(entity, filterName);
107 daoService.saveFunction(entity);
108
109 return mapping.findForward("listRecord");
110 }
111 }