001: /*
002: ====================================================================
003: Project Name: bugtracker
004: File Name: /src/com/espada/bugtracker/servlets/UpdateRoles.java
005: Author: Kishan Peiris <kishan@espadanet.com>
006: Description: Update user/roles on a selected project
007: CVS Repository: goliath:/projects/repository/cvsroot/
008: CVS Module: bugtracker
009: Version: CVS $Id: UpdateRoles.java,v 1.4 2001/04/16 06:45:47 manik Exp $
010: ====================================================================
011:
012: ====================================================================
013: Copyright (C) 2001, Silk Road (Pvt.) Ltd.
014: ====================================================================
015: */
016:
017: package com.espada.bugtracker.servlets;
018:
019: import com.sr.espada.se.util.config.*;
020: import com.sr.espada.se.util.logwriter.*;
021: import java.util.*;
022:
023: // webmacro resources
024: import org.webmacro.*;
025: import org.webmacro.broker.*;
026: import org.webmacro.resource.*;
027: import org.webmacro.servlet.WebContext;
028:
029: // servlet libraries
030: import javax.servlet.http.*;
031: import javax.servlet.*;
032:
033: // bugtracker java apps
034: import com.espada.bugtracker.app.*;
035:
036: public class UpdateRoles extends BTServlet {
037:
038: /** the default template to use **/
039: public String getInitialTemplate() {
040: return ("assignProjects.wm");
041: }
042:
043: /**************************** Start Of Method updateRoles ********************************************/
044: /** List all available projects...*/
045:
046: private void updateRoles(HttpServletRequest request,
047: HttpServletResponse response, WebContext c) {
048: HttpSession session = request.getSession();
049: boolean loggedIn = false;
050: LogWriter.write("The value of loggedIn is " + loggedIn);
051: try {
052: loggedIn = ((String) session.getAttribute("loggedIn"))
053: .equalsIgnoreCase("true");
054:
055: LogWriter.write("The value of loggedIn is " + loggedIn);
056:
057: } catch (NullPointerException npexLI) {
058: LogWriter
059: .write("session attrib loggedIn seems to be a Knull.");
060: // do nothing! It measn the user is not logged in for some odd reason.
061: }
062: LogWriter.write("The value of loggedIn is " + loggedIn);
063:
064: int proId = 0;
065: if (loggedIn) {
066: defaultTemplate = "assignProjects.wm";
067: int UID = ((Integer) session.getAttribute("UID"))
068: .intValue();
069: proId = Integer.parseInt(request.getParameter("proId"));
070: c.put("USER", session.getAttribute("USER"));
071:
072: int uId, rId;
073: Roles role = new Roles();
074:
075: for (int i = 0; i < Integer.parseInt(request
076: .getParameter("numUsers")); i++) {
077: try {
078: if (request.getParameter("roleId" + i) != request
079: .getParameter("origRole" + i)) // why waste time with this user if nothing has changed?
080:
081: {
082: rId = Integer.parseInt(request
083: .getParameter("roleId" + i));
084: uId = Integer.parseInt(request
085: .getParameter("userId" + i));
086: if (rId == 1) {
087: new User(uId).makeAdmin();
088: } else {
089: role.update(uId, proId, rId);
090: }
091:
092: }
093: } catch (NullPointerException npex) {
094: // do nothing. This means that the user didnt have the auth to change any values here. :-)
095: // continue on with next user in loop. - Manik (Apr, 2001)
096: }
097:
098: }
099:
100: defaultTemplate = "errorMesg.wm"; // NOT really an error!! Just an alert that user roles were updated.
101: c.put("errorId", "18");
102: c.put("proId", String.valueOf(proId));
103:
104: } else {
105:
106: defaultTemplate = "errorMesg.wm";
107: c.put("errorId", "9");
108:
109: }
110:
111: c.put("loggedIn", String.valueOf(loggedIn));
112: c.put("USER", session.getAttribute("USER"));
113: c.put("myRoleId", session.getAttribute("USERROLE"));
114:
115: } //end of method
116:
117: protected void doAction(HttpServletRequest req,
118: HttpServletResponse resp, WebContext c) {
119:
120: if (req.getParameter("actionType").equals("Delete")) {
121: new User(Integer.parseInt(req.getParameter("userToDel")))
122: .delUserProject(Integer.parseInt(req
123: .getParameter("proId")));
124:
125: HttpSession session = req.getSession();
126:
127: c.put("loggedIn", session.getAttribute("loggedIn"));
128: c.put("USER", session.getAttribute("USER"));
129: c.put("myRoleId", session.getAttribute("USERROLE"));
130: c.put("errorId", "21");
131: c.put("proId", req.getParameter("proId"));
132:
133: defaultTemplate = "errorMesg.wm";
134:
135: } else {
136: updateRoles(req, resp, c);
137: }
138:
139: }
140: } //end of class
|