KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
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.acegi.UserManagerDaoImpl;
24 import com.blandware.atleap.webapp.util.core.CacheUtil;
25 import org.apache.commons.validator.GenericValidator;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.action.ActionMessage;
30 import org.apache.struts.action.ActionMessages;
31
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34 import java.util.List JavaDoc;
35 import java.util.ArrayList JavaDoc;
36
37 /**
38  * <p>Deletes group
39  * </p>
40  * <p><a HREF="DeleteGroupAction.java.htm"><i>View Source</i></a></p>
41  * <p/>
42  *
43  * @author Roman Puchkovskiy <a HREF="mailto:roman.puchkovskiy@blandware.com">
44  * &lt;roman.puchkovskiy@blandware.com&gt;</a>
45  * @version $Revision: 1.4 $ $Date: 2006/03/25 11:27:52 $
46  * @struts.action path="/core/group/delete"
47  * name="groupForm"
48  * scope="request"
49  * validate="false"
50  * roles="core-group-delete"
51  * @struts.action-forward name="listGroups"
52  * path="/core/group/list.do"
53  * redirect="true"
54  * @struts.action-forward name="unsatisfiable"
55  * path="/core/group/list.do"
56  */

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

67     public ActionForward execute(ActionMapping mapping, ActionForm form,
68                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
69
70         GroupForm groupForm = (GroupForm) form;
71         String JavaDoc groupName = null;
72         if ( !GenericValidator.isBlankOrNull(groupForm.getName()) ) {
73             groupName = groupForm.getName();
74         } else {
75             if ( log.isWarnEnabled() ) {
76                 log.warn("Missing group name. Returning to list...");
77             }
78             return mapping.findForward("listGroups");
79         }
80
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         if ( group.getFixed().booleanValue() ) {
93             ActionMessages errors = new ActionMessages();
94             errors.add("groupIsFixed", new ActionMessage("core.group.errors.isFixed"));
95             saveErrors(request, errors);
96             return mapping.findForward("listGroups");
97         }
98
99         List JavaDoc users = new ArrayList JavaDoc(group.getUsers());
100         UserManagerDaoImpl userManagerDaoImpl = (UserManagerDaoImpl) getBean(Constants.USER_DETAILS_SERVICE_BEAN);
101
102         groupManager.deleteGroup(groupName);
103
104         for (int i = 0; i < users.size(); i++) {
105             User user = (User) users.get(i);
106             if (user.getName().equals(request.getRemoteUser())) {
107                 userManagerDaoImpl.updateUser(user);
108             }
109         }
110
111         // flush CP cache to avoid a situation when user permissions for
112
// CP menu items are changed but he/she still obtains cached version
113
// of page
114
CacheUtil cacheUtil = CacheUtil.getInstance(request);
115         cacheUtil.flushContentPageCache();
116
117         return mapping.findForward("listGroups");
118     }
119 }
120
Popular Tags