Source code: org/acs/damsel/client/add/AddUserToGroupAction.java
1 package org.acs.damsel.client.add;
2
3 import org.apache.struts.action.*;
4 import javax.servlet.http.*;
5 import java.util.Vector;
6 import org.acs.damsel.srvr.group.GroupMgr;
7 import org.acs.damsel.srvr.user.UserMgr;
8 import org.acs.damsel.client.ClientApp;
9 import java.sql.*;
10
11 public class AddUserToGroupAction
12 extends Action {
13 public ActionForward execute(ActionMapping actionMapping,
14 ActionForm actionForm,
15 HttpServletRequest httpServletRequest,
16 HttpServletResponse httpServletResponse) {
17
18 AddUserToGroupForm addUserToGroupForm = (AddUserToGroupForm) actionForm;
19
20 // If a group has been selected the page is refreshed with information
21 //relevant to the selected group.
22 if (addUserToGroupForm.isChangedGroup()) {
23 addUserToGroupForm.setChangedGroup(false);
24 return actionMapping.findForward("reset");
25 }
26
27 //If a user is added to the group the page is refreshed with the updated
28 //lists (taken from the bean vector) of users in/not in the group.
29 if (addUserToGroupForm.isAddUser()) {
30 addUserToGroupForm.setAddUser(false);
31 Vector beanVec = addUserToGroupForm.getMoveList();
32 beanVec.add(addUserToGroupForm.getUsersNotInGroup());
33 return actionMapping.findForward("reset");
34 }
35
36 //If a user is deleted from the group the page is refreshed with the updated
37 //lists (taken from the bean vector) of users in/not in the group.
38 if (addUserToGroupForm.isDeleteUser()) {
39 addUserToGroupForm.setDeleteUser(false);
40 Vector beanVec = addUserToGroupForm.getMoveList();
41 boolean found = false;
42 int index = 0;
43
44 //If the bean vector is not empty, the deleted user is removed from it.
45 if (beanVec.size() > 0) {
46 while (!found && index < beanVec.size()) {
47 if (beanVec.elementAt(index).equals(addUserToGroupForm.
48 getUsersInGroup())) {
49 beanVec.removeElementAt(index);
50 }
51 else {
52 index++;
53 }
54 }
55 }
56 return actionMapping.findForward("reset");
57 }
58 String grp = addUserToGroupForm.getSelectGroup();
59 UserMgr umgr = ClientApp.instance().getUserMgr();
60 Vector usrs = addUserToGroupForm.getMoveList(); //list of users to be added to group
61 GroupMgr gmgr = ClientApp.instance().getGroupMgr();
62 String userName = new String();
63
64 //All records of users in the current group are removed from the
65 //UsersGroupsTable and replaced with the changes made to the bean vector.
66 gmgr.deleteMultipleUsersFromGroup(grp);
67
68 //adds the users back to the users groups table
69 for (int i = 0; i < usrs.size(); i++) {
70 userName = (String) usrs.elementAt(i);
71 try {
72 gmgr.addUserToGroup(userName, grp);
73 }
74 catch (SQLException ex) {
75 }
76 }
77 //resets the value of isFirstLoad to true
78 addUserToGroupForm.setIsFirstLoad(true);
79 return (actionMapping.findForward("success"));
80
81 }
82 }