Source code: org/acs/damsel/client/cb/CbGroupInfoAction.java
1 package org.acs.damsel.client.cb;
2
3 import org.apache.struts.action.*;
4 import javax.servlet.http.*;
5 import java.util.Vector;
6 import org.acs.damsel.srvr.user.*;
7 import org.acs.damsel.client.ClientApp;
8 import org.acs.damsel.srvr.group.*;
9 import java.sql.*;
10 import org.acs.damsel.srvr.group.GroupMgr;
11
12 public class CbGroupInfoAction
13 extends Action {
14 public ActionForward execute(ActionMapping actionMapping,
15 ActionForm actionForm,
16 HttpServletRequest httpServletRequest,
17 HttpServletResponse httpServletResponse) {
18
19 CbGroupInfoForm cbGroupInfoForm = (CbGroupInfoForm) actionForm;
20 ActionErrors errors;
21
22 // If a group has been selected the page is refreshed with information
23 //relevant to the selected group.
24 if (cbGroupInfoForm.isChangedGroup()) {
25 cbGroupInfoForm.setChangedGroup(false);
26 cbGroupInfoForm.setNewGroupName("");
27 return actionMapping.findForward("reset");
28 }
29
30 //If a user is added to the group the page is refreshed with the updated
31 //lists (taken from the bean vector) of users in/not in the group.
32 if (cbGroupInfoForm.isAddUser()) {
33 cbGroupInfoForm.setAddUser(false);
34 cbGroupInfoForm.setIsFirstLoad(false);
35 Vector beanVec = cbGroupInfoForm.getMoveList();
36 beanVec.add(cbGroupInfoForm.getUsersNotInGroup()); //gets the selected user to move and adds to beanVec
37 cbGroupInfoForm.setMoveList(beanVec);
38 return actionMapping.findForward("reset");
39 }
40
41 //If a user is deleted from the group the page is refreshed with the updated
42 //lists (taken from the bean vector) of users in/not in the group.
43 if (cbGroupInfoForm.isDeleteUser()) {
44 cbGroupInfoForm.setDeleteUser(false);
45 Vector beanVec = cbGroupInfoForm.getMoveList();
46 boolean found = false;
47 int index = 0;
48
49 //If the bean vector is not empty, the deleted user is removed from it.
50 if (beanVec.size() > 0) {
51 while (!found && index < beanVec.size()) {
52 if (beanVec.elementAt(index).equals(cbGroupInfoForm.
53 getUsersInGroup())) {
54 beanVec.removeElementAt(index);
55 }
56 else {
57 index++;
58 }
59 }
60 }
61 cbGroupInfoForm.setMoveList(beanVec);
62 return actionMapping.findForward("reset");
63 }
64
65 // goes back to the cbCollectionInfo page if the user clicks the back button
66 if (cbGroupInfoForm.isBack()) {
67 cbGroupInfoForm.setBack(false);
68 return actionMapping.findForward("back");
69 }
70
71 if (cbGroupInfoForm.isNext()) {
72 //resets the value of isFirstLoad to true
73 cbGroupInfoForm.setIsFirstLoad(true);
74 cbGroupInfoForm.setNext(false);
75 return (actionMapping.findForward("next"));
76 }
77
78 /*We will only get here if the New button is pressed or the user presses
79 enter in the New group input box */
80 cbGroupInfoForm.setNewGroupAdded(false);
81 cbGroupInfoForm.setIsFirstLoad(false);
82 cbGroupInfoForm.setDisplayButtons(true);
83 if (!cbGroupInfoForm.getNewGroupName().trim().equals(""))
84 cbGroupInfoForm.setSelectGroup("");
85 GroupMgr gMgr = ClientApp.instance().getGroupMgr();
86 Vector groupNames = gMgr.groupNames();
87 if (groupNames.contains(cbGroupInfoForm.getNewGroupName())) {
88 errors = new ActionErrors();
89 errors.add("cb", new ActionError("group.name.already.exists"));
90 this.saveErrors(httpServletRequest, errors);
91 }
92 else {
93 Vector newVec = new Vector();
94 cbGroupInfoForm.setMoveList(newVec);
95 cbGroupInfoForm.setDescription("");
96 }
97
98 return actionMapping.findForward("reset");
99 }
100
101
102 }