001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.web.controllers.bugtracker;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.bugtracker.BugTrackerConstants;
038: import org.libresource.bugtracker.ejb.model.IssueResourceValue;
039: import org.libresource.bugtracker.interfaces.LibresourceBugTrackerService;
040:
041: import org.libresource.kernel.KernelConstants;
042: import org.libresource.kernel.LibresourceSecurityException;
043: import org.libresource.kernel.interfaces.KernelService;
044:
045: import org.libresource.web.Controller;
046:
047: import java.net.URI;
048:
049: import java.util.Vector;
050:
051: import javax.servlet.http.HttpServletRequest;
052: import javax.servlet.http.HttpServletResponse;
053:
054: public class EditIssueController implements Controller {
055: public Object process(URI uri, HttpServletRequest request,
056: HttpServletResponse response) throws Exception {
057: if (request.getParameter("cancel") != null) {
058: return uri;
059: }
060:
061: KernelService kernelService = (KernelService) Libresource
062: .getService(KernelConstants.SERVICE);
063:
064: if (!kernelService.checkSecurity(uri,
065: KernelConstants.SECURITY_UPDATE)) {
066: throw new LibresourceSecurityException(uri,
067: KernelConstants.SECURITY_UPDATE);
068: }
069:
070: LibresourceBugTrackerService libresourceBugTrackerService = (LibresourceBugTrackerService) Libresource
071: .getService(BugTrackerConstants.SERVICE);
072: IssueResourceValue issue = libresourceBugTrackerService
073: .getIssue(uri);
074:
075: if (request.getParameter("summary") == null) {
076: request.setAttribute("issueId", String.valueOf(issue
077: .getIssueId()));
078: request.setAttribute("summary", issue.getSummary());
079: request.setAttribute("body", issue.getBody());
080: request.setAttribute("type", issue.getType());
081: request.setAttribute("priority", issue.getPriority());
082: request.setAttribute("author", issue.getAuthorName());
083: request.setAttribute("assignee", issue.getAssignee());
084: request.setAttribute("resolution", issue.getResolution());
085:
086: Vector resolutions = libresourceBugTrackerService
087: .getListOfResolution();
088: request.setAttribute("resolutions", resolutions);
089:
090: Vector types = libresourceBugTrackerService.getListOfType();
091: request.setAttribute("types", types);
092:
093: Vector priorities = libresourceBugTrackerService
094: .getListOfPriority();
095: request.setAttribute("priorities", priorities);
096:
097: return "/pages/modules/bugtracker/editIssue.jsp";
098: }
099:
100: if (request.getParameter("issueId").trim().length() == 0) {
101: request.setAttribute("summary", request
102: .getParameter("summary"));
103: request.setAttribute("body", request.getParameter("body"));
104: request.setAttribute("type", request.getParameter("type"));
105: request.setAttribute("priority", request
106: .getParameter("priority"));
107: request.setAttribute("author", issue.getAuthorName());
108: request.setAttribute("assignee", request
109: .getParameter("assignee"));
110: request.setAttribute("resolution", request
111: .getParameter("resolution"));
112:
113: Vector resolutions = libresourceBugTrackerService
114: .getListOfResolution();
115: request.setAttribute("resolutions", resolutions);
116:
117: Vector types = libresourceBugTrackerService.getListOfType();
118: request.setAttribute("types", types);
119:
120: Vector priorities = libresourceBugTrackerService
121: .getListOfPriority();
122: request.setAttribute("priorities", priorities);
123:
124: request.setAttribute("error_id",
125: "The id of the issue is required");
126:
127: return "/pages/modules/bugtracker/editIssue.jsp";
128: }
129:
130: if (request.getParameter("summary").trim().length() == 0) {
131: request.setAttribute("issueId", request
132: .getParameter("issueId"));
133: request.setAttribute("body", request.getParameter("body"));
134: request.setAttribute("type", request.getParameter("type"));
135: request.setAttribute("priority", request
136: .getParameter("priority"));
137: request.setAttribute("author", issue.getAuthorName());
138: request.setAttribute("assignee", request
139: .getParameter("assignee"));
140: request.setAttribute("resolution", request
141: .getParameter("resolution"));
142:
143: Vector resolutions = libresourceBugTrackerService
144: .getListOfResolution();
145: request.setAttribute("resolutions", resolutions);
146:
147: Vector types = libresourceBugTrackerService.getListOfType();
148: request.setAttribute("types", types);
149:
150: Vector priorities = libresourceBugTrackerService
151: .getListOfPriority();
152: request.setAttribute("priorities", priorities);
153:
154: request.setAttribute("error_summary",
155: "The summary of the issue is required");
156:
157: return "/pages/modules/bugtracker/editIssue.jsp";
158: }
159:
160: boolean validAssignee = kernelService.exist(new URI(request
161: .getParameter("assignee")));
162:
163: if (!validAssignee) {
164: request.setAttribute("issueId", request
165: .getParameter("issueId"));
166: request.setAttribute("summary", request
167: .getParameter("summary"));
168: request.setAttribute("body", request.getParameter("body"));
169: request.setAttribute("type", request.getParameter("type"));
170: request.setAttribute("priority", request
171: .getParameter("priority"));
172: request.setAttribute("author", issue.getAuthorName());
173: request.setAttribute("assignee", request
174: .getParameter("assignee"));
175: request.setAttribute("resolution", request
176: .getParameter("resolution"));
177:
178: Vector resolutions = libresourceBugTrackerService
179: .getListOfResolution();
180: request.setAttribute("resolutions", resolutions);
181:
182: Vector types = libresourceBugTrackerService.getListOfType();
183: request.setAttribute("types", types);
184:
185: Vector priorities = libresourceBugTrackerService
186: .getListOfPriority();
187: request.setAttribute("priorities", priorities);
188:
189: request.setAttribute("error_assignee",
190: "This user uri is not a valid user uri");
191:
192: return "/pages/modules/bugtracker/editIssue.jsp";
193: }
194:
195: int id = -1;
196:
197: try {
198: id = Integer.parseInt(request.getParameter("issueId"));
199: } catch (NumberFormatException e) {
200: //
201: }
202:
203: libresourceBugTrackerService.editIssue(uri, id, request
204: .getParameter("summary"), request.getParameter("body"),
205: request.getParameter("type"), request
206: .getParameter("priority"), request
207: .getParameter("resolution"), request
208: .getParameter("assignee"));
209:
210: return uri;
211: }
212: }
|