001: /*
002: ====================================================================
003: Project Name: bugtracker
004: File Name: /src/com/espada/bugtracker/servlets/OpenProject.java
005: Author: Kishan Peiris <kishan@espadanet.com>
006: Description: Opening a project to view list of bugs available and other details such as Status, Severity, etc.
007: CVS Repository: goliath:/projects/repository/cvsroot/
008: CVS Module: bugtracker
009: Version: CVS $Id: $
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 OpenProject extends BTServlet {
034:
035: protected void doAction(HttpServletRequest request,
036: HttpServletResponse response, WebContext c) {
037: projectDetails(request, response, c);
038: };
039:
040: public String getInitialTemplate() {
041: return ("openProject.wm");
042: }
043:
044: /**************************** Start Of Method projectDetails ********************************************/
045: /** Opening a project for bugs...*/
046:
047: private void projectDetails(HttpServletRequest request,
048: HttpServletResponse response, WebContext c) {
049:
050: HttpSession session = request.getSession();
051:
052: String SuccessLoggedIn = (String) session
053: .getAttribute("loggedIn");
054:
055: String pageLocation = new String();
056:
057: boolean loggedIn = false;
058:
059: if (SuccessLoggedIn != null) {
060: if (SuccessLoggedIn.equals("true")) {
061: defaultTemplate = "openProject.wm";
062:
063: loggedIn = true;
064:
065: int UID = ((Integer) session.getAttribute("UID"))
066: .intValue();
067:
068: c.put("USER", session.getAttribute("USER"));
069:
070: /*******************************************************************************************/
071: /*******************
072: Required parameters from WebMacro file
073: *******************/
074:
075: String sortBy = (request.getParameter("sort") == null) ? "bid"
076: : request.getParameter("sort");
077: int pid = Integer.parseInt(request
078: .getParameter("projID"));
079: int trancheSize = Integer.parseInt(request
080: .getParameter("trancheSize"));
081: int pageNumber = Integer.parseInt(request
082: .getParameter("pageNumber"));
083: int limitStatus = (request.getParameter("limitStatus") == null) ? 0
084: : Integer.parseInt(request
085: .getParameter("limitStatus"));
086: int limitSeverity = (request
087: .getParameter("limitSeverity") == null) ? 0
088: : Integer.parseInt(request
089: .getParameter("limitSeverity"));
090: Project myProject = new Project(pid);
091: String myRole = myProject.getRoleID(UID);
092: session.setAttribute("PUR", (myRole == null) ? "0"
093: : myRole);
094: c.put("RoleID", (String) session.getAttribute("PUR"));
095:
096: /*Seeting up a session on current project*/
097:
098: session.setAttribute("currentProject", myProject);
099:
100: Vector bugs = new Vector();
101:
102: if (limitStatus == 0) {
103: if (limitSeverity == 0) {
104:
105: bugs = Bug.getAllBugs(myProject, sortBy,
106: pageNumber, trancheSize);
107:
108: } else {
109:
110: bugs = Bug.getAllBugs(myProject, sortBy,
111: new Severity(limitSeverity),
112: pageNumber, trancheSize);
113:
114: }
115: } else {
116: if (limitSeverity == 0) {
117:
118: bugs = Bug.getAllBugs(myProject, sortBy,
119: new Status(limitStatus), pageNumber,
120: trancheSize);
121:
122: } else {
123:
124: bugs = Bug.getAllBugs(myProject, sortBy,
125: new Status(limitStatus), new Severity(
126: limitSeverity), pageNumber,
127: trancheSize);
128:
129: }
130: }
131:
132: /*******************************************************************************************/
133: /*******************
134: Creating bug severity array of objects
135: ********************/
136:
137: Severity server = new Severity(); //object of severity
138: Vector sev = Severity.getSeverities(); //vector of severity
139: Vector s = new Vector(); //to copy as an array of object severity
140: int i;
141:
142: for (i = 0; i < sev.size(); i++) //number of selected items
143: {
144: server = ((Severity) sev.get(i)); //assigning lements
145: s.addElement(server); //adding all objects
146: }
147:
148: Severity pros[] = new Severity[s.size()];//severity type array
149: s.copyInto(pros); //cope all into new array object pros
150:
151: /*******************************************************************************************/
152: /*******************
153: Creating bug status array of objects
154: ********************/
155:
156: Vector stv = Status.getStatusList();
157: Vector ss = new Vector();
158: Status bstat = new Status();
159:
160: for (i = 0; i < stv.size(); i++) {
161: bstat = ((Status) stv.get(i));
162: ss.addElement(bstat);
163: }
164:
165: Status statObj[] = new Status[ss.size()];
166: ss.copyInto(statObj);
167:
168: /*******************************************************************************************/
169: /*******************
170: Selected bugs, array of objects
171: ********************/
172:
173: Vector bb = new Vector();
174: Bug b = new Bug();
175:
176: for (i = 0; i < bugs.size(); i++) {
177: b = (Bug) bugs.get(i);
178: bb.addElement(b);
179: }
180:
181: Bug bugObj[] = new Bug[bb.size()];
182: bb.copyInto(bugObj);
183:
184: /*******************************************************************************************/
185: /*******************
186: Passing parameter to WebMacro file
187: ********************/
188:
189: c.put("currentProject", myProject);
190:
191: c.put("trancheSize", String.valueOf(trancheSize));
192:
193: c.put("limitSeverity", String.valueOf(limitSeverity));
194:
195: c.put("limitStatus", String.valueOf(limitStatus));
196:
197: c.put("sortBy", sortBy);
198:
199: c.put("pros", pros);
200:
201: c.put("statObj", statObj);
202:
203: c.put("bugObjs", bugObj);
204:
205: /*******************************************************************************************/
206: /*******************
207: Page "next" or "previous"
208: ********************/
209:
210: boolean hasMore = (bugs.size() == trancheSize);
211:
212: int backPage = pageNumber;
213: session.setAttribute("page", new Integer(pageNumber));
214:
215: if (hasMore) {
216: pageNumber = pageNumber + 1;
217: }
218:
219: if (backPage > 0) {
220: c.put("back", "yes");
221: backPage = backPage - 1;
222: } else if ((!hasMore) && (backPage > 0)) {
223: backPage = backPage - 1;
224: c.put("back", "yes");
225: } else {
226: c.put("back", "no");
227: }
228: c.put("waite", String.valueOf(session
229: .getAttribute("page")));
230:
231: c.put("hasMore", String.valueOf(hasMore));
232:
233: c.put("pageNumber", String.valueOf(pageNumber));
234:
235: c.put("backPage", String.valueOf(backPage));
236:
237: } else {
238:
239: loggedIn = false;
240:
241: defaultTemplate = "errorMesg.wm";
242:
243: c.put("errorId", "9");
244:
245: }
246: } else {
247:
248: loggedIn = false;
249:
250: defaultTemplate = "errorMesg.wm";
251:
252: c.put("errorId", "9");
253:
254: }
255:
256: c.put("loggedIn", String.valueOf(loggedIn));
257: c.put("myRoleId", session.getAttribute("USERROLE"));
258:
259: } //end of method
260:
261: /**************************** End Of Method projectDetails ********************************************/
262:
263: } //end of class
|