src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java

changeset 75
33b6843fdf8a
parent 74
91d1fc2a3a14
child 76
82f71fb1758a
equal deleted inserted replaced
74:91d1fc2a3a14 75:33b6843fdf8a
36 import org.slf4j.LoggerFactory; 36 import org.slf4j.LoggerFactory;
37 37
38 import javax.servlet.annotation.WebServlet; 38 import javax.servlet.annotation.WebServlet;
39 import javax.servlet.http.HttpServletRequest; 39 import javax.servlet.http.HttpServletRequest;
40 import javax.servlet.http.HttpServletResponse; 40 import javax.servlet.http.HttpServletResponse;
41 import javax.servlet.http.HttpSession;
41 import java.io.IOException; 42 import java.io.IOException;
43 import java.sql.Date;
42 import java.sql.SQLException; 44 import java.sql.SQLException;
43 import java.util.ArrayList; 45 import java.util.ArrayList;
44 import java.util.List; 46 import java.util.List;
45 import java.util.NoSuchElementException; 47 import java.util.NoSuchElementException;
46 import java.util.Optional; 48 import java.util.Objects;
47 49
48 import static de.uapcore.lightpit.Functions.fqn; 50 import static de.uapcore.lightpit.Functions.fqn;
49 51
50 @LightPITModule( 52 @LightPITModule(
51 bundleBaseName = "localization.projects", 53 bundleBaseName = "localization.projects",
59 public final class ProjectsModule extends AbstractLightPITServlet { 61 public final class ProjectsModule extends AbstractLightPITServlet {
60 62
61 private static final Logger LOG = LoggerFactory.getLogger(ProjectsModule.class); 63 private static final Logger LOG = LoggerFactory.getLogger(ProjectsModule.class);
62 64
63 public static final String SESSION_ATTR_SELECTED_PROJECT = fqn(ProjectsModule.class, "selected-project"); 65 public static final String SESSION_ATTR_SELECTED_PROJECT = fqn(ProjectsModule.class, "selected-project");
64 66 public static final String SESSION_ATTR_SELECTED_ISSUE = fqn(ProjectsModule.class, "selected-issue");
65 private Project getSelectedProject(HttpServletRequest req, DataAccessObjects dao) throws SQLException { 67 public static final String SESSION_ATTR_SELECTED_VERSION = fqn(ProjectsModule.class, "selected-version");
66 final var projectDao = dao.getProjectDao(); 68
67 final var session = req.getSession(); 69 private class SessionSelection {
68 final var projectSelection = getParameter(req, Integer.class, "pid"); 70 final HttpSession session;
69 final Project selectedProject; 71 Project project;
70 if (projectSelection.isPresent()) { 72 Version version;
71 selectedProject = projectDao.find(projectSelection.get()); 73 Issue issue;
72 } else { 74
73 final var sessionProject = (Project) session.getAttribute(SESSION_ATTR_SELECTED_PROJECT); 75 SessionSelection(HttpServletRequest req, Project project) {
74 selectedProject = sessionProject == null ? null : projectDao.find(sessionProject.getId()); 76 this.session = req.getSession();
75 } 77 this.project = project;
76 session.setAttribute(SESSION_ATTR_SELECTED_PROJECT, selectedProject); 78 version = null;
77 return selectedProject; 79 issue = null;
80 updateAttributes();
81 }
82
83 SessionSelection(HttpServletRequest req, DataAccessObjects dao) throws SQLException {
84 this.session = req.getSession();
85 final var issueDao = dao.getIssueDao();
86 final var projectDao = dao.getProjectDao();
87 final var issueSelection = getParameter(req, Integer.class, "issue");
88 if (issueSelection.isPresent()) {
89 issue = issueDao.find(issueSelection.get());
90 } else {
91 final var issue = (Issue) session.getAttribute(SESSION_ATTR_SELECTED_ISSUE);
92 this.issue = issue == null ? null : issueDao.find(issue.getId());
93 }
94 if (issue != null) {
95 version = null; // show the issue globally
96 project = projectDao.find(issue.getProject().getId());
97 }
98
99 final var projectSelection = getParameter(req, Integer.class, "pid");
100 if (projectSelection.isPresent()) {
101 final var selectedProject = projectDao.find(projectSelection.get());
102 if (!Objects.equals(selectedProject, project)) {
103 // reset version and issue if project changed
104 version = null;
105 issue = null;
106 }
107 project = selectedProject;
108 } else {
109 final var sessionProject = (Project) session.getAttribute(SESSION_ATTR_SELECTED_PROJECT);
110 project = sessionProject == null ? null : projectDao.find(sessionProject.getId());
111 }
112 updateAttributes();
113 }
114
115 void selectVersion(Version version) {
116 if (!version.getProject().equals(project)) throw new AssertionError("Nice, you implemented a bug!");
117 this.version = version;
118 this.issue = null;
119 updateAttributes();
120 }
121
122 void selectIssue(Issue issue) {
123 if (!issue.getProject().equals(project)) throw new AssertionError("Nice, you implemented a bug!");
124 this.issue = issue;
125 this.version = null;
126 updateAttributes();
127 }
128
129 void updateAttributes() {
130 session.setAttribute(SESSION_ATTR_SELECTED_PROJECT, project);
131 session.setAttribute(SESSION_ATTR_SELECTED_VERSION, version);
132 session.setAttribute(SESSION_ATTR_SELECTED_ISSUE, issue);
133 }
78 } 134 }
79 135
80 136
81 /** 137 /**
82 * Creates the breadcrumb menu. 138 * Creates the breadcrumb menu.
83 * 139 *
84 * @param level the current active level 140 * @param level the current active level (0: root, 1: project, 2: version, 3: issue)
85 * @param selectedProject the selected project, if any, or null 141 * @param sessionSelection the currently selected objects
86 * @return a dynamic breadcrumb menu trying to display as many levels as possible 142 * @return a dynamic breadcrumb menu trying to display as many levels as possible
87 */ 143 */
88 private List<MenuEntry> getBreadcrumbs(int level, 144 private List<MenuEntry> getBreadcrumbs(int level, SessionSelection sessionSelection) {
89 Project selectedProject) {
90 MenuEntry entry; 145 MenuEntry entry;
91 146
92 final var breadcrumbs = new ArrayList<MenuEntry>(); 147 final var breadcrumbs = new ArrayList<MenuEntry>();
93 entry = new MenuEntry(new ResourceKey("localization.projects", "menuLabel"), 148 entry = new MenuEntry(new ResourceKey("localization.projects", "menuLabel"),
94 "projects/", 0); 149 "projects/", 0);
95 breadcrumbs.add(entry); 150 breadcrumbs.add(entry);
96 if (level == 0) entry.setActive(true); 151 if (level == 0) entry.setActive(true);
97 152
98 if (selectedProject == null) 153 if (sessionSelection.project != null) {
99 return breadcrumbs; 154 if (sessionSelection.project.getId() < 0) {
100 155 entry = new MenuEntry(new ResourceKey("localization.projects", "button.create"),
101 entry = new MenuEntry(selectedProject.getName(), 156 "projects/edit", 1);
102 "projects/view?pid=" + selectedProject.getId(), 1); 157 } else {
103 if (level == 1) entry.setActive(true); 158 entry = new MenuEntry(sessionSelection.project.getName(),
104 159 "projects/view?pid=" + sessionSelection.project.getId(), 1);
105 breadcrumbs.add(entry); 160 }
161 if (level == 1) entry.setActive(true);
162 breadcrumbs.add(entry);
163 }
164
165 if (sessionSelection.version != null) {
166 if (sessionSelection.version.getId() < 0) {
167 entry = new MenuEntry(new ResourceKey("localization.projects", "button.version.create"),
168 "projects/versions/edit", 2);
169 } else {
170 entry = new MenuEntry(sessionSelection.version.getName(),
171 // TODO: change link to issue overview for that version
172 "projects/versions/edit?id=" + sessionSelection.version.getId(), 2);
173 }
174 if (level == 2) entry.setActive(true);
175 breadcrumbs.add(entry);
176 }
177
178 if (sessionSelection.issue != null) {
179 entry = new MenuEntry(new ResourceKey("localization.projects", "menu.issues"),
180 // TODO: change link to a separate issue view (maybe depending on the selected version)
181 "projects/view?pid=" + sessionSelection.issue.getProject().getId(), 3);
182 breadcrumbs.add(entry);
183 if (sessionSelection.issue.getId() < 0) {
184 entry = new MenuEntry(new ResourceKey("localization.projects", "button.issue.create"),
185 "projects/issues/edit", 2);
186 } else {
187 entry = new MenuEntry("#" + sessionSelection.issue.getId(),
188 // TODO: maybe change link to a view rather than directly opening the editor
189 "projects/issues/edit?id=" + sessionSelection.issue.getId(), 4);
190 }
191 if (level == 3) entry.setActive(true);
192 breadcrumbs.add(entry);
193 }
194
106 return breadcrumbs; 195 return breadcrumbs;
107 } 196 }
108 197
109 @RequestMapping(method = HttpMethod.GET) 198 @RequestMapping(method = HttpMethod.GET)
110 public ResponseType index(HttpServletRequest req, DataAccessObjects dao) throws SQLException { 199 public ResponseType index(HttpServletRequest req, DataAccessObjects dao) throws SQLException {
111 200 final var sessionSelection = new SessionSelection(req, dao);
112 final var projectList = dao.getProjectDao().list(); 201 final var projectList = dao.getProjectDao().list();
113 req.setAttribute("projects", projectList); 202 req.setAttribute("projects", projectList);
114 setContentPage(req, "projects"); 203 setContentPage(req, "projects");
115 setStylesheet(req, "projects"); 204 setStylesheet(req, "projects");
116 205
117 final var selectedProject = getSelectedProject(req, dao); 206 setBreadcrumbs(req, getBreadcrumbs(0, sessionSelection));
118 setBreadcrumbs(req, getBreadcrumbs(0, selectedProject)); 207
119 208 return ResponseType.HTML;
120 return ResponseType.HTML; 209 }
121 } 210
122 211 private void configureEditForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException {
123 private void configureEditForm(HttpServletRequest req, DataAccessObjects dao, Optional<Project> project) throws SQLException { 212 req.setAttribute("project", selection.project);
124 if (project.isPresent()) {
125 req.setAttribute("project", project.get());
126 setBreadcrumbs(req, getBreadcrumbs(1, project.get()));
127 } else {
128 req.setAttribute("project", new Project(-1));
129 setBreadcrumbs(req, getBreadcrumbs(0, null));
130 }
131
132 req.setAttribute("users", dao.getUserDao().list()); 213 req.setAttribute("users", dao.getUserDao().list());
133 setContentPage(req, "project-form"); 214 setContentPage(req, "project-form");
215 setBreadcrumbs(req, getBreadcrumbs(1, selection));
134 } 216 }
135 217
136 @RequestMapping(requestPath = "edit", method = HttpMethod.GET) 218 @RequestMapping(requestPath = "edit", method = HttpMethod.GET)
137 public ResponseType edit(HttpServletRequest req, DataAccessObjects dao) throws SQLException { 219 public ResponseType edit(HttpServletRequest req, DataAccessObjects dao) throws SQLException {
138 220 final var selection = new SessionSelection(req, findByParameter(req, Integer.class, "id",
139 Optional<Project> project = findByParameter(req, Integer.class, "id", dao.getProjectDao()::find); 221 dao.getProjectDao()::find).orElse(new Project(-1)));
140 configureEditForm(req, dao, project); 222
141 if (project.isPresent()) { 223 configureEditForm(req, dao, selection);
142 req.getSession().setAttribute(SESSION_ATTR_SELECTED_PROJECT, project.get());
143 }
144 224
145 return ResponseType.HTML; 225 return ResponseType.HTML;
146 } 226 }
147 227
148 @RequestMapping(requestPath = "commit", method = HttpMethod.POST) 228 @RequestMapping(requestPath = "commit", method = HttpMethod.POST)
149 public ResponseType commit(HttpServletRequest req, DataAccessObjects dao) throws SQLException { 229 public ResponseType commit(HttpServletRequest req, DataAccessObjects dao) throws SQLException {
150 230
151 Project project = null; 231 Project project = new Project(-1);
152 try { 232 try {
153 project = new Project(getParameter(req, Integer.class, "id").orElseThrow()); 233 project = new Project(getParameter(req, Integer.class, "id").orElseThrow());
154 project.setName(getParameter(req, String.class, "name").orElseThrow()); 234 project.setName(getParameter(req, String.class, "name").orElseThrow());
155 getParameter(req, String.class, "description").ifPresent(project::setDescription); 235 getParameter(req, String.class, "description").ifPresent(project::setDescription);
156 getParameter(req, String.class, "repoUrl").ifPresent(project::setRepoUrl); 236 getParameter(req, String.class, "repoUrl").ifPresent(project::setRepoUrl);
161 dao.getProjectDao().saveOrUpdate(project); 241 dao.getProjectDao().saveOrUpdate(project);
162 242
163 setRedirectLocation(req, "./projects/"); 243 setRedirectLocation(req, "./projects/");
164 setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); 244 setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL);
165 LOG.debug("Successfully updated project {}", project.getName()); 245 LOG.debug("Successfully updated project {}", project.getName());
166 } catch (NoSuchElementException | NumberFormatException | SQLException ex) { 246 } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) {
167 // TODO: set request attribute with error text 247 // TODO: set request attribute with error text
168 LOG.warn("Form validation failure: {}", ex.getMessage()); 248 LOG.warn("Form validation failure: {}", ex.getMessage());
169 LOG.debug("Details:", ex); 249 LOG.debug("Details:", ex);
170 configureEditForm(req, dao, Optional.ofNullable(project)); 250 configureEditForm(req, dao, new SessionSelection(req, project));
171 } 251 }
172 252
173 return ResponseType.HTML; 253 return ResponseType.HTML;
174 } 254 }
175 255
176 @RequestMapping(requestPath = "view", method = HttpMethod.GET) 256 @RequestMapping(requestPath = "view", method = HttpMethod.GET)
177 public ResponseType view(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { 257 public ResponseType view(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException {
178 final var selectedProject = getSelectedProject(req, dao); 258 final var sessionSelection = new SessionSelection(req, dao);
179 if (selectedProject == null) { 259
260 req.setAttribute("versions", dao.getVersionDao().list(sessionSelection.project));
261 req.setAttribute("issues", dao.getIssueDao().list(sessionSelection.project));
262
263 setBreadcrumbs(req, getBreadcrumbs(1, sessionSelection));
264 setContentPage(req, "project-details");
265
266 return ResponseType.HTML;
267 }
268
269 private void configureEditVersionForm(HttpServletRequest req, SessionSelection selection) {
270 req.setAttribute("version", selection.version);
271 req.setAttribute("versionStatusEnum", VersionStatus.values());
272
273 setContentPage(req, "version-form");
274 setBreadcrumbs(req, getBreadcrumbs(2, selection));
275 }
276
277 @RequestMapping(requestPath = "versions/edit", method = HttpMethod.GET)
278 public ResponseType editVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException {
279 final var sessionSelection = new SessionSelection(req, dao);
280 if (sessionSelection.project == null) {
281 // TODO: remove this bullshit and only retrieve the object from session if we are creating a fresh version
180 resp.sendError(HttpServletResponse.SC_FORBIDDEN); 282 resp.sendError(HttpServletResponse.SC_FORBIDDEN);
181 return ResponseType.NONE; 283 return ResponseType.NONE;
182 } 284 }
183 285
184 req.setAttribute("versions", dao.getVersionDao().list(selectedProject)); 286 sessionSelection.selectVersion(findByParameter(req, Integer.class, "id", dao.getVersionDao()::find)
185 req.setAttribute("issues", dao.getIssueDao().list(selectedProject)); 287 .orElse(new Version(-1, sessionSelection.project)));
186 288 configureEditVersionForm(req, sessionSelection);
187 // TODO: add more levels depending on last visited location 289
188 setBreadcrumbs(req, getBreadcrumbs(1, selectedProject)); 290 return ResponseType.HTML;
189 291 }
190 setContentPage(req, "project-details"); 292
191 293 @RequestMapping(requestPath = "versions/commit", method = HttpMethod.POST)
192 return ResponseType.HTML; 294 public ResponseType commitVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException {
193 } 295 final var sessionSelection = new SessionSelection(req, dao);
194 296 if (sessionSelection.project == null) {
195 private void configureEditVersionForm(HttpServletRequest req, Optional<Version> version, Project selectedProject) { 297 // TODO: remove this bullshit and retrieve project id from hidden field
196 req.setAttribute("version", version.orElse(new Version(-1, selectedProject)));
197 req.setAttribute("versionStatusEnum", VersionStatus.values());
198
199 setContentPage(req, "version-form");
200 }
201
202 @RequestMapping(requestPath = "versions/edit", method = HttpMethod.GET)
203 public ResponseType editVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException {
204 final var selectedProject = getSelectedProject(req, dao);
205 if (selectedProject == null) {
206 resp.sendError(HttpServletResponse.SC_FORBIDDEN); 298 resp.sendError(HttpServletResponse.SC_FORBIDDEN);
207 return ResponseType.NONE; 299 return ResponseType.NONE;
208 } 300 }
209 301
210 configureEditVersionForm(req, 302 var version = new Version(-1, sessionSelection.project);
211 findByParameter(req, Integer.class, "id", dao.getVersionDao()::find),
212 selectedProject);
213
214 return ResponseType.HTML;
215 }
216
217 @RequestMapping(requestPath = "versions/commit", method = HttpMethod.POST)
218 public ResponseType commitVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException {
219 final var selectedProject = getSelectedProject(req, dao);
220 if (selectedProject == null) {
221 resp.sendError(HttpServletResponse.SC_FORBIDDEN);
222 return ResponseType.NONE;
223 }
224
225 Version version = null;
226 try { 303 try {
227 version = new Version(getParameter(req, Integer.class, "id").orElseThrow(), selectedProject); 304 version = new Version(getParameter(req, Integer.class, "id").orElseThrow(), sessionSelection.project);
228 version.setName(getParameter(req, String.class, "name").orElseThrow()); 305 version.setName(getParameter(req, String.class, "name").orElseThrow());
229 getParameter(req, Integer.class, "ordinal").ifPresent(version::setOrdinal); 306 getParameter(req, Integer.class, "ordinal").ifPresent(version::setOrdinal);
230 version.setStatus(VersionStatus.valueOf(getParameter(req, String.class, "status").orElseThrow())); 307 version.setStatus(VersionStatus.valueOf(getParameter(req, String.class, "status").orElseThrow()));
231 dao.getVersionDao().saveOrUpdate(version); 308 dao.getVersionDao().saveOrUpdate(version);
232 309
233 setRedirectLocation(req, "./projects/versions/"); 310 // specifying the pid parameter will purposely reset the session selected version!
311 setRedirectLocation(req, "./projects/view?pid="+sessionSelection.project.getId());
234 setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); 312 setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL);
235 LOG.debug("Successfully updated version {} for project {}", version.getName(), selectedProject.getName()); 313 LOG.debug("Successfully updated version {} for project {}", version.getName(), sessionSelection.project.getName());
236 } catch (NoSuchElementException | NumberFormatException | SQLException ex) { 314 } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) {
237 // TODO: set request attribute with error text 315 // TODO: set request attribute with error text
238 LOG.warn("Form validation failure: {}", ex.getMessage()); 316 LOG.warn("Form validation failure: {}", ex.getMessage());
239 LOG.debug("Details:", ex); 317 LOG.debug("Details:", ex);
240 configureEditVersionForm(req, Optional.ofNullable(version), selectedProject); 318 sessionSelection.selectVersion(version);
241 } 319 configureEditVersionForm(req, sessionSelection);
242 320 }
243 return ResponseType.HTML; 321
244 } 322 return ResponseType.HTML;
245 323 }
246 private void configureEditIssueForm(HttpServletRequest req, DataAccessObjects dao, Optional<Issue> issue, Project selectedProject) throws SQLException { 324
247 325 private void configureEditIssueForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException {
248 req.setAttribute("issue", issue.orElse(new Issue(-1, selectedProject))); 326 req.setAttribute("issue", selection.issue);
249 req.setAttribute("issueStatusEnum", IssueStatus.values()); 327 req.setAttribute("issueStatusEnum", IssueStatus.values());
250 req.setAttribute("issueCategoryEnum", IssueCategory.values()); 328 req.setAttribute("issueCategoryEnum", IssueCategory.values());
251 req.setAttribute("versions", dao.getVersionDao().list(selectedProject)); 329 req.setAttribute("versions", dao.getVersionDao().list(selection.project));
330 req.setAttribute("users", dao.getUserDao().list());
252 331
253 setContentPage(req, "issue-form"); 332 setContentPage(req, "issue-form");
333 setBreadcrumbs(req, getBreadcrumbs(3, selection));
254 } 334 }
255 335
256 @RequestMapping(requestPath = "issues/edit", method = HttpMethod.GET) 336 @RequestMapping(requestPath = "issues/edit", method = HttpMethod.GET)
257 public ResponseType editIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { 337 public ResponseType editIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException {
258 final var selectedProject = getSelectedProject(req, dao); 338 final var sessionSelection = new SessionSelection(req, dao);
259 if (selectedProject == null) { 339 if (sessionSelection.project == null) {
340 // TODO: remove this bullshit and only retrieve the object from session if we are creating a fresh issue
260 resp.sendError(HttpServletResponse.SC_FORBIDDEN); 341 resp.sendError(HttpServletResponse.SC_FORBIDDEN);
261 return ResponseType.NONE; 342 return ResponseType.NONE;
262 } 343 }
263 344
264 configureEditIssueForm(req, dao, 345 sessionSelection.selectIssue(findByParameter(req, Integer.class, "id",
265 findByParameter(req, Integer.class, "id", dao.getIssueDao()::find), 346 dao.getIssueDao()::find).orElse(new Issue(-1, sessionSelection.project)));
266 selectedProject); 347 configureEditIssueForm(req, dao, sessionSelection);
267 348
268 return ResponseType.HTML; 349 return ResponseType.HTML;
269 } 350 }
270 351
271 @RequestMapping(requestPath = "issues/commit", method = HttpMethod.POST) 352 @RequestMapping(requestPath = "issues/commit", method = HttpMethod.POST)
272 public ResponseType commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { 353 public ResponseType commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException {
273 final var selectedProject = getSelectedProject(req, dao); 354 // TODO: remove this bullshit and store the project ID as hidden field
274 if (selectedProject == null) { 355 final var sessionSelection = new SessionSelection(req, dao);
356 if (sessionSelection.project == null) {
275 resp.sendError(HttpServletResponse.SC_FORBIDDEN); 357 resp.sendError(HttpServletResponse.SC_FORBIDDEN);
276 return ResponseType.NONE; 358 return ResponseType.NONE;
277 } 359 }
278 360
279 Issue issue = null; 361 Issue issue = new Issue(-1, sessionSelection.project);
280 try { 362 try {
281 issue = new Issue(getParameter(req, Integer.class, "id").orElseThrow(), selectedProject); 363 issue = new Issue(getParameter(req, Integer.class, "id").orElseThrow(), sessionSelection.project);
282 364 getParameter(req, String.class, "category").map(IssueCategory::valueOf).ifPresent(issue::setCategory);
283 // TODO: implement 365 getParameter(req, String.class, "status").map(IssueStatus::valueOf).ifPresent(issue::setStatus);
284 366 issue.setSubject(getParameter(req, String.class, "subject").orElseThrow());
367 getParameter(req, Integer.class, "assignee").map(
368 userid -> userid >= 0 ? new User(userid) : null
369 ).ifPresent(issue::setAssignee);
370 getParameter(req, String.class, "description").ifPresent(issue::setDescription);
371 getParameter(req, Date.class, "eta").ifPresent(issue::setEta);
285 dao.getIssueDao().saveOrUpdate(issue); 372 dao.getIssueDao().saveOrUpdate(issue);
286 373
287 setRedirectLocation(req, "./projects/issues/"); 374 // TODO: redirect to issue overview
375 // specifying the issue parameter keeps the edited issue as breadcrumb
376 setRedirectLocation(req, "./projects/view?issue="+issue.getId());
288 setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); 377 setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL);
289 LOG.debug("Successfully updated issue {} for project {}", issue.getId(), selectedProject.getName()); 378 LOG.debug("Successfully updated issue {} for project {}", issue.getId(), sessionSelection.project.getName());
290 } catch (NoSuchElementException | NumberFormatException | SQLException ex) { 379 } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) {
291 // TODO: set request attribute with error text 380 // TODO: set request attribute with error text
292 LOG.warn("Form validation failure: {}", ex.getMessage()); 381 LOG.warn("Form validation failure: {}", ex.getMessage());
293 LOG.debug("Details:", ex); 382 LOG.debug("Details:", ex);
294 configureEditIssueForm(req, dao, Optional.ofNullable(issue), selectedProject); 383 sessionSelection.selectIssue(issue);
384 configureEditIssueForm(req, dao, sessionSelection);
295 } 385 }
296 386
297 return ResponseType.HTML; 387 return ResponseType.HTML;
298 } 388 }
299 } 389 }

mercurial