KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > group > CallUpdateGroupAction


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.webapp.action.core.group;
17
18 import com.blandware.atleap.common.Constants;
19 import com.blandware.atleap.model.core.Group;
20 import com.blandware.atleap.service.core.GroupManager;
21 import com.blandware.atleap.webapp.action.core.BaseAction;
22 import com.blandware.atleap.webapp.form.GroupForm;
23 import com.blandware.atleap.webapp.util.core.WebappConstants;
24 import com.blandware.atleap.webapp.util.core.WebappUtil;
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.action.ActionMessage;
29 import org.apache.struts.action.ActionMessages;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
33
34 /**
35  * <p>Prepares form bean to update group's data
36  * </p>
37  * <p><a HREF="CallUpdateGroupAction.java.htm"><i>View Source</i></a></p>
38  * <p/>
39  *
40  * @author Roman Puchkovskiy <a HREF="mailto:roman.puchkovskiy@blandware.com">
41  * &lt;roman.puchkovskiy@blandware.com&gt;</a>
42  * @version $Revision: 1.4 $ $Date: 2006/03/11 10:41:28 $
43  * @struts.action path="/core/group/callUpdate"
44  * name="groupForm"
45  * scope="request"
46  * validate="false"
47  * roles="core-group-update, core-group-view"
48  * @struts.action-forward name="updateGroup"
49  * path=".core.group.update"
50  * @struts.action-forward name="listGroups"
51  * path="/core/group/list.do"
52  * redirect="true"
53  */

54 public final class CallUpdateGroupAction extends BaseAction {
55     /**
56      * @param mapping The ActionMapping used to select this instance
57      * @param form The optional ActionForm bean for this request (if any)
58      * @param request The HTTP request we are proceeding
59      * @param response The HTTP response we are creating
60      * @return an ActionForward instance describing where and how
61      * control should be forwarded, or null if response
62      * has already been completed
63      */

64     public ActionForward execute(ActionMapping mapping, ActionForm form,
65                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
66
67         if ( isCancelled(request) ) {
68             return mapping.findForward("listGroups");
69         }
70
71         if (!request.isUserInRole("core-group-update")) {
72             response.sendError(HttpServletResponse.SC_FORBIDDEN);
73             return null;
74         }
75
76         GroupForm groupForm = (GroupForm) form;
77         String JavaDoc groupName = null;
78         if ( groupForm.getName() != null ) {
79             groupName = groupForm.getName();
80         } else if ( request.getSession().getAttribute(WebappConstants.GROUP_NAME_KEY) != null ) {
81             groupName = (String JavaDoc) request.getSession().getAttribute(WebappConstants.GROUP_NAME_KEY);
82         } else {
83             if ( log.isWarnEnabled() ) {
84                 log.warn("Missing group name. Returning to list...");
85             }
86             return mapping.findForward("listGroups");
87         }
88
89         GroupManager groupManager = (GroupManager) getBean(Constants.GROUP_MANAGER_BEAN);
90         Group group = groupManager.retrieveGroup(groupName);
91         if ( group == null ) {
92             // group not found. it might be deleted by someone else
93
ActionMessages errors = new ActionMessages();
94             errors.add("groupNotFound", new ActionMessage("core.group.errors.notFound"));
95             saveErrors(request, errors);
96             return mapping.findForward("listGroups");
97         }
98
99         WebappUtil.copyProperties(groupForm, group, request);
100
101         // save transaction token in request
102
saveToken(request);
103         return mapping.findForward("updateGroup");
104     }
105
106 }
Popular Tags