001: /*
002: ====================================================================
003: Project Name: bugtracker
004: File Name: /src/com/espada/bugtracker/servlets/AddProjectRoles.java
005: Author: Kishan Peiris <kishan@espadanet.com>
006: Description: Add users to a project and a role
007: CVS Repository: goliath:/projects/repository/cvsroot/
008: CVS Module: bugtracker
009: Version: CVS $Id: AddProjectRoles.java,v 1.4 2001/04/16 09:26:58 manik Exp $
010: ====================================================================
011:
012: */
013:
014: package com.espada.bugtracker.servlets;
015:
016: import com.sr.espada.se.util.config.*;
017: import com.sr.espada.se.util.logwriter.*;
018: import java.util.*;
019:
020: // webmacro resources
021: import org.webmacro.*;
022: import org.webmacro.broker.*;
023: import org.webmacro.resource.*;
024: import org.webmacro.servlet.WebContext;
025:
026: // servlet libraries
027: import javax.servlet.http.*;
028: import javax.servlet.*;
029:
030: // bugtracker java apps
031: import com.espada.bugtracker.app.*;
032:
033: public class AddProjectRoles extends BTServlet {
034:
035: /**
036: * This is the core WebMacro interface which we use to create Contexts,
037: * load Templates, and begin other WebMacro operations.
038: */
039:
040: /**************************** Start Of Method updateRoles ********************************************/
041: /** List all available projects...*/
042:
043: private void listUsersToAdd(HttpServletRequest request,
044: HttpServletResponse response, WebContext c) {
045: defaultTemplate = "addUsers.wm";
046:
047: HttpSession session = request.getSession();
048:
049: String SuccessLoggedIn = (String) session
050: .getAttribute("loggedIn");
051:
052: boolean loggedIn = false;
053:
054: int userId;
055:
056: int proId = 0;
057:
058: Vector v = new Vector();
059:
060: Vector ProjRoles = new Vector();
061:
062: String roleId = new String();
063:
064: if (SuccessLoggedIn != null) {
065: if (SuccessLoggedIn.equals("true")) {
066: defaultTemplate = "addUsers.wm";
067: int UID = ((Integer) session.getAttribute("UID"))
068: .intValue();
069: if (request.getParameter("create") != null) {
070:
071: ProjRoles = Project.getProjectsByUserRole(UID, 1);
072: session.setAttribute("PROJROLES", ProjRoles);
073: } else {
074: ProjRoles = (Vector) session
075: .getAttribute("PROJROLES");
076: }
077:
078: roleId = (String) session.getAttribute("USERROLE");
079:
080: if (ProjRoles.size() > 0) {
081: /***************** List all the UserRoles *************/
082: Vector allRoles = Roles.getAllRoles(Integer
083: .parseInt(roleId));
084:
085: if (request.getParameter("Go") != null) {
086: proId = Integer.parseInt(request
087: .getParameter("proId"));
088: }
089:
090: /***************** set of user on this project *************/
091: Vector byProject = User
092: .getUserRolesByProject(proId); // This has User objects in project
093:
094: /***************** Users who are not in this project *************/
095: Vector notInProject = User
096: .getUsersNotInProject(proId); // This has User objects NOT in project
097:
098: c.put("projects", ProjRoles);
099: c.put("users", notInProject);
100: c.put("Uroles", allRoles);
101: c.put("AllUsers", String.valueOf(notInProject
102: .size()));
103:
104: }
105:
106: loggedIn = true;
107: c.put("USER", session.getAttribute("USER"));
108: c.put("proId", String.valueOf(proId));
109:
110: } else {
111:
112: loggedIn = false;
113:
114: defaultTemplate = "errorMesg.wm";
115:
116: c.put("errorId", "9");
117:
118: }
119:
120: } else {
121:
122: loggedIn = false;
123:
124: defaultTemplate = "errorMesg.wm";
125:
126: c.put("errorId", "9");
127:
128: }
129:
130: c.put("loggedIn", String.valueOf(loggedIn));
131: c.put("USER", session.getAttribute("USER"));
132: c.put("myRoleId", roleId);
133:
134: } //end of method
135:
136: /**************************** End Of Method updateRoles ********************************************/
137:
138: private void addUsers(HttpServletRequest request,
139: HttpServletResponse response, WebContext c) {
140: defaultTemplate = "addUsers.wm";
141: HttpSession session = request.getSession();
142: String SuccessLoggedIn = (String) session
143: .getAttribute("loggedIn");
144: boolean loggedIn = false;
145: int proId = 0;
146: if (SuccessLoggedIn != null) {
147: if (SuccessLoggedIn.equals("true")) {
148: defaultTemplate = "addUsers.wm";
149: int UID = ((Integer) session.getAttribute("UID"))
150: .intValue();
151: proId = Integer.parseInt(request.getParameter("proId"));
152: int numUsers = Integer.parseInt(request
153: .getParameter("numUsers"));
154: int rId = 0, uId = 0;
155: for (int ctr = 0; ctr < numUsers; ctr++) {
156: if (Integer.parseInt(request.getParameter("roleId"
157: + ctr)) != 0)
158: User.addUsersToProjectsRoles(proId, Integer
159: .parseInt(request.getParameter("userId"
160: + ctr)), Integer
161: .parseInt(request.getParameter("roleId"
162: + ctr)));
163: }
164:
165: defaultTemplate = "errorMesg.wm";
166: // This is NOT an error!! Just an alert saying the operation was successful.
167: c.put("errorId", "20");
168:
169: loggedIn = true;
170: c.put("USER", session.getAttribute("USER"));
171: c.put("proId", String.valueOf(proId));
172:
173: } else {
174:
175: loggedIn = false;
176:
177: defaultTemplate = "errorMesg.wm";
178:
179: c.put("errorId", "9");
180:
181: }
182:
183: } else {
184:
185: loggedIn = false;
186:
187: defaultTemplate = "errorMesg.wm";
188:
189: c.put("errorId", "9");
190:
191: }
192:
193: c.put("loggedIn", String.valueOf(loggedIn));
194: c.put("USER", session.getAttribute("USER"));
195: c.put("myRoleId", session.getAttribute("USERROLE"));
196:
197: } //end of method
198:
199: protected void doAction(HttpServletRequest req,
200: HttpServletResponse resp, WebContext c) {
201: if (req.getParameter("New") != null) {
202: addUsers(req, resp, c);
203: } else {
204: listUsersToAdd(req, resp, c);
205: }
206: }
207:
208: } //end of class
|