KickJava   Java API By Example, From Geeks To Geeks.

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


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.service.exception.BeanAlreadyExistsException;
22 import com.blandware.atleap.webapp.action.core.BaseAction;
23 import com.blandware.atleap.webapp.form.GroupForm;
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>Creates new group
36  * </p>
37  * <p><a HREF="CreateGroupAction.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.3 $ $Date: 2006/03/10 17:10:25 $
43  * @struts.action path="/core/group/create"
44  * name="groupForm"
45  * scope="request"
46  * input="inputForward"
47  * validate="true"
48  * roles="core-group-create"
49  * @struts.action-forward name="inputForward"
50  * path=".core.group.create"
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 CreateGroupAction 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         if ( !isCancelled(request) ) {
71
72             GroupForm groupForm = (GroupForm) form;
73             Group group = new Group();
74             WebappUtil.copyProperties(group, groupForm, request);
75             group.setFixed(Boolean.FALSE);
76             GroupManager groupManager = (GroupManager) getBean(Constants.GROUP_MANAGER_BEAN);
77             try {
78                 groupManager.createGroup(group);
79             } catch ( BeanAlreadyExistsException e ) {
80                 // group already exists
81
ActionMessages errors = new ActionMessages();
82                 errors.add("groupAlreadyExists", new ActionMessage("core.group.errors.alreadyExists"));
83                 saveErrors(request, errors);
84                 saveToken(request);
85                 return mapping.getInputForward();
86             }
87         }
88         return mapping.findForward("listGroups");
89     }
90 }
Popular Tags