KickJava   Java API By Example, From Geeks To Geeks.

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


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.RoleManager;
21 import com.blandware.atleap.service.core.GroupManager;
22 import com.blandware.atleap.webapp.action.core.BaseAction;
23 import com.blandware.atleap.webapp.form.core.SelectRolesForm;
24 import com.blandware.atleap.webapp.util.core.WebappConstants;
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 import java.util.ArrayList JavaDoc;
34 import java.util.List JavaDoc;
35
36 /**
37  * <p>Returns page with two lists to reassign roles to group
38  * </p>
39  * <p><a HREF="CallAssignGroupRolesAction.java.htm"><i>View Source</i></a></p>
40  * <p/>
41  *
42  * @author Roman Puchkovskiy <a HREF="mailto:roman.puchkovskiy@blandware.com">
43  * &lt;roman.puchkovskiy@blandware.com&gt;</a>
44  * @version $Revision: 1.3 $ $Date: 2006/03/11 10:08:53 $
45  * @struts.action path="/core/group/callAssignRoles"
46  * name="selectRolesForm"
47  * validate="false"
48  * roles="core-group-assignRoles"
49  * @struts.action-forward name="assignRoles"
50  * path=".core.group.assignRoles"
51  * @struts.action-forward name="listGroups"
52  * path="/core/group/list.do"
53  * redirect="true"
54  */

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

65     public ActionForward execute(ActionMapping mapping, ActionForm form,
66                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
67
68         String JavaDoc groupName = null;
69         if ( request.getParameter("groupName") != null ) {
70             groupName = request.getParameter("groupName");
71         } else if ( request.getAttribute(WebappConstants.GROUP_NAME_KEY) != null ) {
72             groupName = (String JavaDoc) request.getAttribute(WebappConstants.GROUP_NAME_KEY);
73         } else {
74             if ( log.isWarnEnabled() ) {
75                 log.warn("Missing group name. Returning to list...");
76             }
77             return mapping.findForward("listGroups");
78         }
79
80         SelectRolesForm selectRolesForm = (SelectRolesForm) form;
81         GroupManager groupManager = (GroupManager) getBean(Constants.GROUP_MANAGER_BEAN);
82         Group group = groupManager.retrieveGroup(groupName);
83
84         if ( group == null ) {
85             // group not found. it might be deleted by someone else
86
ActionMessages errors = new ActionMessages();
87             errors.add("groupNotFound", new ActionMessage("core.group.errors.notFound"));
88             saveErrors(request, errors);
89             return mapping.findForward("listGroups");
90         }
91
92         selectRolesForm.setVersion(group.getVersion().toString());
93
94         List JavaDoc groupRoles = new ArrayList JavaDoc(group.getRoles());
95
96         RoleManager roleManager = (RoleManager) getBean(Constants.ROLE_MANAGER_BEAN);
97         List JavaDoc availableRoles = new ArrayList JavaDoc(roleManager.listRoles(null));
98         List JavaDoc allRoles = new ArrayList JavaDoc(availableRoles);
99         availableRoles.removeAll(groupRoles);
100
101         selectRolesForm.setAvailableRolesList(availableRoles);
102         selectRolesForm.setSelectedRolesList(groupRoles);
103         request.getSession().setAttribute(WebappConstants.GROUP_NAME_KEY, group.getName());
104
105         request.setAttribute("allRoles", allRoles);
106
107         // save transaction token in request
108
saveToken(request);
109         return mapping.findForward("assignRoles");
110     }
111 }
Popular Tags