Sat, 30 May 2020 15:26:15 +0200
adds issue summaries
universe@41 | 1 | /* |
universe@41 | 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
universe@41 | 3 | * |
universe@41 | 4 | * Copyright 2018 Mike Becker. All rights reserved. |
universe@41 | 5 | * |
universe@41 | 6 | * Redistribution and use in source and binary forms, with or without |
universe@41 | 7 | * modification, are permitted provided that the following conditions are met: |
universe@41 | 8 | * |
universe@41 | 9 | * 1. Redistributions of source code must retain the above copyright |
universe@41 | 10 | * notice, this list of conditions and the following disclaimer. |
universe@41 | 11 | * |
universe@41 | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
universe@41 | 13 | * notice, this list of conditions and the following disclaimer in the |
universe@41 | 14 | * documentation and/or other materials provided with the distribution. |
universe@41 | 15 | * |
universe@41 | 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
universe@41 | 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
universe@41 | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
universe@41 | 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
universe@41 | 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
universe@41 | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
universe@41 | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
universe@41 | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
universe@41 | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
universe@41 | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
universe@41 | 26 | * POSSIBILITY OF SUCH DAMAGE. |
universe@41 | 27 | * |
universe@41 | 28 | */ |
universe@41 | 29 | package de.uapcore.lightpit.modules; |
universe@41 | 30 | |
universe@41 | 31 | |
universe@41 | 32 | import de.uapcore.lightpit.*; |
universe@41 | 33 | import de.uapcore.lightpit.dao.DataAccessObjects; |
universe@64 | 34 | import de.uapcore.lightpit.entities.*; |
universe@59 | 35 | import org.slf4j.Logger; |
universe@59 | 36 | import org.slf4j.LoggerFactory; |
universe@41 | 37 | |
universe@41 | 38 | import javax.servlet.annotation.WebServlet; |
universe@41 | 39 | import javax.servlet.http.HttpServletRequest; |
universe@59 | 40 | import javax.servlet.http.HttpServletResponse; |
universe@75 | 41 | import javax.servlet.http.HttpSession; |
universe@59 | 42 | import java.io.IOException; |
universe@75 | 43 | import java.sql.Date; |
universe@47 | 44 | import java.sql.SQLException; |
universe@71 | 45 | import java.util.ArrayList; |
universe@71 | 46 | import java.util.List; |
universe@59 | 47 | import java.util.NoSuchElementException; |
universe@75 | 48 | import java.util.Objects; |
universe@41 | 49 | |
universe@52 | 50 | import static de.uapcore.lightpit.Functions.fqn; |
universe@52 | 51 | |
universe@41 | 52 | @WebServlet( |
universe@41 | 53 | name = "ProjectsModule", |
universe@41 | 54 | urlPatterns = "/projects/*" |
universe@41 | 55 | ) |
universe@41 | 56 | public final class ProjectsModule extends AbstractLightPITServlet { |
universe@41 | 57 | |
universe@59 | 58 | private static final Logger LOG = LoggerFactory.getLogger(ProjectsModule.class); |
universe@59 | 59 | |
universe@80 | 60 | public static final String SESSION_ATTR_SELECTED_PROJECT = fqn(ProjectsModule.class, "selected_project"); |
universe@80 | 61 | public static final String SESSION_ATTR_SELECTED_ISSUE = fqn(ProjectsModule.class, "selected_issue"); |
universe@80 | 62 | public static final String SESSION_ATTR_SELECTED_VERSION = fqn(ProjectsModule.class, "selected_version"); |
universe@80 | 63 | public static final String SESSION_ATTR_HIDE_ZEROS = fqn(ProjectsModule.class, "stats_hide_zeros"); |
universe@52 | 64 | |
universe@75 | 65 | private class SessionSelection { |
universe@75 | 66 | final HttpSession session; |
universe@75 | 67 | Project project; |
universe@75 | 68 | Version version; |
universe@75 | 69 | Issue issue; |
universe@75 | 70 | |
universe@75 | 71 | SessionSelection(HttpServletRequest req, Project project) { |
universe@75 | 72 | this.session = req.getSession(); |
universe@75 | 73 | this.project = project; |
universe@75 | 74 | version = null; |
universe@75 | 75 | issue = null; |
universe@75 | 76 | updateAttributes(); |
universe@64 | 77 | } |
universe@75 | 78 | |
universe@75 | 79 | SessionSelection(HttpServletRequest req, DataAccessObjects dao) throws SQLException { |
universe@75 | 80 | this.session = req.getSession(); |
universe@75 | 81 | final var issueDao = dao.getIssueDao(); |
universe@75 | 82 | final var projectDao = dao.getProjectDao(); |
universe@75 | 83 | final var issueSelection = getParameter(req, Integer.class, "issue"); |
universe@75 | 84 | if (issueSelection.isPresent()) { |
universe@75 | 85 | issue = issueDao.find(issueSelection.get()); |
universe@75 | 86 | } else { |
universe@75 | 87 | final var issue = (Issue) session.getAttribute(SESSION_ATTR_SELECTED_ISSUE); |
universe@75 | 88 | this.issue = issue == null ? null : issueDao.find(issue.getId()); |
universe@75 | 89 | } |
universe@75 | 90 | if (issue != null) { |
universe@75 | 91 | version = null; // show the issue globally |
universe@75 | 92 | project = projectDao.find(issue.getProject().getId()); |
universe@75 | 93 | } |
universe@75 | 94 | |
universe@75 | 95 | final var projectSelection = getParameter(req, Integer.class, "pid"); |
universe@75 | 96 | if (projectSelection.isPresent()) { |
universe@75 | 97 | final var selectedProject = projectDao.find(projectSelection.get()); |
universe@75 | 98 | if (!Objects.equals(selectedProject, project)) { |
universe@75 | 99 | // reset version and issue if project changed |
universe@75 | 100 | version = null; |
universe@75 | 101 | issue = null; |
universe@75 | 102 | } |
universe@75 | 103 | project = selectedProject; |
universe@75 | 104 | } else { |
universe@75 | 105 | final var sessionProject = (Project) session.getAttribute(SESSION_ATTR_SELECTED_PROJECT); |
universe@75 | 106 | project = sessionProject == null ? null : projectDao.find(sessionProject.getId()); |
universe@75 | 107 | } |
universe@75 | 108 | updateAttributes(); |
universe@75 | 109 | } |
universe@75 | 110 | |
universe@75 | 111 | void selectVersion(Version version) { |
universe@76 | 112 | if (!Objects.equals(project, version.getProject())) throw new AssertionError("Nice, you implemented a bug!"); |
universe@75 | 113 | this.version = version; |
universe@75 | 114 | this.issue = null; |
universe@75 | 115 | updateAttributes(); |
universe@75 | 116 | } |
universe@75 | 117 | |
universe@75 | 118 | void selectIssue(Issue issue) { |
universe@76 | 119 | if (!Objects.equals(issue.getProject(), project)) throw new AssertionError("Nice, you implemented a bug!"); |
universe@75 | 120 | this.issue = issue; |
universe@75 | 121 | this.version = null; |
universe@75 | 122 | updateAttributes(); |
universe@75 | 123 | } |
universe@75 | 124 | |
universe@75 | 125 | void updateAttributes() { |
universe@75 | 126 | session.setAttribute(SESSION_ATTR_SELECTED_PROJECT, project); |
universe@75 | 127 | session.setAttribute(SESSION_ATTR_SELECTED_VERSION, version); |
universe@75 | 128 | session.setAttribute(SESSION_ATTR_SELECTED_ISSUE, issue); |
universe@75 | 129 | } |
universe@71 | 130 | } |
universe@71 | 131 | |
universe@80 | 132 | private void setAttributeHideZeros(HttpServletRequest req) { |
universe@80 | 133 | final Boolean value; |
universe@80 | 134 | final var param = getParameter(req, Boolean.class, "reduced"); |
universe@80 | 135 | if (param.isPresent()) { |
universe@80 | 136 | value = param.get(); |
universe@80 | 137 | req.getSession().setAttribute(SESSION_ATTR_HIDE_ZEROS, value); |
universe@80 | 138 | } else { |
universe@80 | 139 | final var sessionValue = req.getSession().getAttribute(SESSION_ATTR_HIDE_ZEROS); |
universe@80 | 140 | if (sessionValue != null) { |
universe@80 | 141 | value = (Boolean) sessionValue; |
universe@80 | 142 | } else { |
universe@80 | 143 | value = false; |
universe@80 | 144 | req.getSession().setAttribute(SESSION_ATTR_HIDE_ZEROS, value); |
universe@80 | 145 | } |
universe@80 | 146 | } |
universe@80 | 147 | req.setAttribute("statsHideZeros", value); |
universe@80 | 148 | } |
universe@80 | 149 | |
universe@78 | 150 | @Override |
universe@78 | 151 | protected String getResourceBundleName() { |
universe@78 | 152 | return "localization.projects"; |
universe@78 | 153 | } |
universe@71 | 154 | |
universe@80 | 155 | |
universe@80 | 156 | private static final int BREADCRUMB_LEVEL_ROOT = 0; |
universe@80 | 157 | private static final int BREADCRUMB_LEVEL_PROJECT = 1; |
universe@80 | 158 | private static final int BREADCRUMB_LEVEL_VERSION = 2; |
universe@80 | 159 | private static final int BREADCRUMB_LEVEL_ISSUE_LIST = 3; |
universe@80 | 160 | private static final int BREADCRUMB_LEVEL_ISSUE = 4; |
universe@80 | 161 | |
universe@71 | 162 | /** |
universe@71 | 163 | * Creates the breadcrumb menu. |
universe@71 | 164 | * |
universe@80 | 165 | * @param level the current active level (0: root, 1: project, 2: version, 3: issue list, 4: issue) |
universe@75 | 166 | * @param sessionSelection the currently selected objects |
universe@71 | 167 | * @return a dynamic breadcrumb menu trying to display as many levels as possible |
universe@71 | 168 | */ |
universe@75 | 169 | private List<MenuEntry> getBreadcrumbs(int level, SessionSelection sessionSelection) { |
universe@71 | 170 | MenuEntry entry; |
universe@71 | 171 | |
universe@71 | 172 | final var breadcrumbs = new ArrayList<MenuEntry>(); |
universe@79 | 173 | entry = new MenuEntry(new ResourceKey("localization.lightpit", "menu.projects"), |
universe@79 | 174 | "projects/"); |
universe@71 | 175 | breadcrumbs.add(entry); |
universe@80 | 176 | if (level == BREADCRUMB_LEVEL_ROOT) entry.setActive(true); |
universe@71 | 177 | |
universe@75 | 178 | if (sessionSelection.project != null) { |
universe@75 | 179 | if (sessionSelection.project.getId() < 0) { |
universe@75 | 180 | entry = new MenuEntry(new ResourceKey("localization.projects", "button.create"), |
universe@79 | 181 | "projects/edit"); |
universe@75 | 182 | } else { |
universe@75 | 183 | entry = new MenuEntry(sessionSelection.project.getName(), |
universe@79 | 184 | "projects/view?pid=" + sessionSelection.project.getId()); |
universe@75 | 185 | } |
universe@80 | 186 | if (level == BREADCRUMB_LEVEL_PROJECT) entry.setActive(true); |
universe@75 | 187 | breadcrumbs.add(entry); |
universe@75 | 188 | } |
universe@71 | 189 | |
universe@75 | 190 | if (sessionSelection.version != null) { |
universe@75 | 191 | if (sessionSelection.version.getId() < 0) { |
universe@75 | 192 | entry = new MenuEntry(new ResourceKey("localization.projects", "button.version.create"), |
universe@79 | 193 | "projects/versions/edit"); |
universe@75 | 194 | } else { |
universe@75 | 195 | entry = new MenuEntry(sessionSelection.version.getName(), |
universe@75 | 196 | // TODO: change link to issue overview for that version |
universe@79 | 197 | "projects/versions/edit?id=" + sessionSelection.version.getId()); |
universe@75 | 198 | } |
universe@80 | 199 | if (level == BREADCRUMB_LEVEL_VERSION) entry.setActive(true); |
universe@80 | 200 | breadcrumbs.add(entry); |
universe@80 | 201 | } |
universe@80 | 202 | |
universe@80 | 203 | if (sessionSelection.project != null) { |
universe@80 | 204 | entry = new MenuEntry(new ResourceKey("localization.projects", "menu.issues"), |
universe@80 | 205 | // TODO: maybe also add selected version |
universe@80 | 206 | "projects/issues/?pid=" + sessionSelection.project.getId()); |
universe@80 | 207 | if (level == BREADCRUMB_LEVEL_ISSUE_LIST) entry.setActive(true); |
universe@75 | 208 | breadcrumbs.add(entry); |
universe@75 | 209 | } |
universe@71 | 210 | |
universe@75 | 211 | if (sessionSelection.issue != null) { |
universe@75 | 212 | if (sessionSelection.issue.getId() < 0) { |
universe@75 | 213 | entry = new MenuEntry(new ResourceKey("localization.projects", "button.issue.create"), |
universe@79 | 214 | "projects/issues/edit"); |
universe@75 | 215 | } else { |
universe@75 | 216 | entry = new MenuEntry("#" + sessionSelection.issue.getId(), |
universe@75 | 217 | // TODO: maybe change link to a view rather than directly opening the editor |
universe@79 | 218 | "projects/issues/edit?id=" + sessionSelection.issue.getId()); |
universe@75 | 219 | } |
universe@80 | 220 | if (level == BREADCRUMB_LEVEL_ISSUE) entry.setActive(true); |
universe@75 | 221 | breadcrumbs.add(entry); |
universe@75 | 222 | } |
universe@75 | 223 | |
universe@71 | 224 | return breadcrumbs; |
universe@64 | 225 | } |
universe@64 | 226 | |
universe@61 | 227 | @RequestMapping(method = HttpMethod.GET) |
universe@47 | 228 | public ResponseType index(HttpServletRequest req, DataAccessObjects dao) throws SQLException { |
universe@75 | 229 | final var sessionSelection = new SessionSelection(req, dao); |
universe@52 | 230 | final var projectList = dao.getProjectDao().list(); |
universe@52 | 231 | req.setAttribute("projects", projectList); |
universe@74 | 232 | setContentPage(req, "projects"); |
universe@52 | 233 | setStylesheet(req, "projects"); |
universe@52 | 234 | |
universe@80 | 235 | setBreadcrumbs(req, getBreadcrumbs(BREADCRUMB_LEVEL_ROOT, sessionSelection)); |
universe@45 | 236 | |
universe@45 | 237 | return ResponseType.HTML; |
universe@45 | 238 | } |
universe@45 | 239 | |
universe@75 | 240 | private void configureEditForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException { |
universe@75 | 241 | req.setAttribute("project", selection.project); |
universe@71 | 242 | req.setAttribute("users", dao.getUserDao().list()); |
universe@74 | 243 | setContentPage(req, "project-form"); |
universe@80 | 244 | setBreadcrumbs(req, getBreadcrumbs(BREADCRUMB_LEVEL_PROJECT, selection)); |
universe@71 | 245 | } |
universe@71 | 246 | |
universe@47 | 247 | @RequestMapping(requestPath = "edit", method = HttpMethod.GET) |
universe@51 | 248 | public ResponseType edit(HttpServletRequest req, DataAccessObjects dao) throws SQLException { |
universe@75 | 249 | final var selection = new SessionSelection(req, findByParameter(req, Integer.class, "id", |
universe@75 | 250 | dao.getProjectDao()::find).orElse(new Project(-1))); |
universe@47 | 251 | |
universe@75 | 252 | configureEditForm(req, dao, selection); |
universe@47 | 253 | |
universe@47 | 254 | return ResponseType.HTML; |
universe@47 | 255 | } |
universe@47 | 256 | |
universe@47 | 257 | @RequestMapping(requestPath = "commit", method = HttpMethod.POST) |
universe@68 | 258 | public ResponseType commit(HttpServletRequest req, DataAccessObjects dao) throws SQLException { |
universe@47 | 259 | |
universe@75 | 260 | Project project = new Project(-1); |
universe@47 | 261 | try { |
universe@47 | 262 | project = new Project(getParameter(req, Integer.class, "id").orElseThrow()); |
universe@47 | 263 | project.setName(getParameter(req, String.class, "name").orElseThrow()); |
universe@47 | 264 | getParameter(req, String.class, "description").ifPresent(project::setDescription); |
universe@47 | 265 | getParameter(req, String.class, "repoUrl").ifPresent(project::setRepoUrl); |
universe@47 | 266 | getParameter(req, Integer.class, "owner").map( |
universe@47 | 267 | ownerId -> ownerId >= 0 ? new User(ownerId) : null |
universe@47 | 268 | ).ifPresent(project::setOwner); |
universe@47 | 269 | |
universe@47 | 270 | dao.getProjectDao().saveOrUpdate(project); |
universe@47 | 271 | |
universe@70 | 272 | setRedirectLocation(req, "./projects/"); |
universe@74 | 273 | setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); |
universe@59 | 274 | LOG.debug("Successfully updated project {}", project.getName()); |
universe@75 | 275 | } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { |
universe@47 | 276 | // TODO: set request attribute with error text |
universe@59 | 277 | LOG.warn("Form validation failure: {}", ex.getMessage()); |
universe@59 | 278 | LOG.debug("Details:", ex); |
universe@75 | 279 | configureEditForm(req, dao, new SessionSelection(req, project)); |
universe@47 | 280 | } |
universe@47 | 281 | |
universe@47 | 282 | return ResponseType.HTML; |
universe@47 | 283 | } |
universe@47 | 284 | |
universe@70 | 285 | @RequestMapping(requestPath = "view", method = HttpMethod.GET) |
universe@80 | 286 | public ResponseType view(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, IOException { |
universe@75 | 287 | final var sessionSelection = new SessionSelection(req, dao); |
universe@80 | 288 | if (sessionSelection.project == null) { |
universe@80 | 289 | resp.sendError(HttpServletResponse.SC_NOT_FOUND, "No project selected."); |
universe@80 | 290 | return ResponseType.NONE; |
universe@80 | 291 | } |
universe@47 | 292 | |
universe@80 | 293 | final var versionDao = dao.getVersionDao(); |
universe@80 | 294 | final var versions = versionDao.list(sessionSelection.project); |
universe@80 | 295 | final var statsAffected = new ArrayList<VersionStatistics>(); |
universe@80 | 296 | final var statsScheduled = new ArrayList<VersionStatistics>(); |
universe@80 | 297 | final var statsResolved = new ArrayList<VersionStatistics>(); |
universe@80 | 298 | for (Version version : versions) { |
universe@80 | 299 | statsAffected.add(versionDao.statsOpenedIssues(version)); |
universe@80 | 300 | statsScheduled.add(versionDao.statsScheduledIssues(version)); |
universe@80 | 301 | statsResolved.add(versionDao.statsResolvedIssues(version)); |
universe@80 | 302 | } |
universe@70 | 303 | |
universe@80 | 304 | setAttributeHideZeros(req); |
universe@80 | 305 | |
universe@81 | 306 | req.setAttribute("project", sessionSelection.project); |
universe@80 | 307 | req.setAttribute("versions", versions); |
universe@80 | 308 | req.setAttribute("statsAffected", statsAffected); |
universe@80 | 309 | req.setAttribute("statsScheduled", statsScheduled); |
universe@80 | 310 | req.setAttribute("statsResolved", statsResolved); |
universe@80 | 311 | |
universe@80 | 312 | req.setAttribute("issueStatusEnum", IssueStatus.values()); |
universe@80 | 313 | req.setAttribute("issueCategoryEnum", IssueCategory.values()); |
universe@80 | 314 | |
universe@80 | 315 | setBreadcrumbs(req, getBreadcrumbs(BREADCRUMB_LEVEL_PROJECT, sessionSelection)); |
universe@74 | 316 | setContentPage(req, "project-details"); |
universe@80 | 317 | setStylesheet(req, "projects"); |
universe@59 | 318 | |
universe@59 | 319 | return ResponseType.HTML; |
universe@59 | 320 | } |
universe@59 | 321 | |
universe@76 | 322 | private void configureEditVersionForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException { |
universe@80 | 323 | final var versionDao = dao.getVersionDao(); |
universe@76 | 324 | req.setAttribute("projects", dao.getProjectDao().list()); |
universe@75 | 325 | req.setAttribute("version", selection.version); |
universe@71 | 326 | req.setAttribute("versionStatusEnum", VersionStatus.values()); |
universe@71 | 327 | |
universe@80 | 328 | req.setAttribute("issueStatusEnum", IssueStatus.values()); |
universe@80 | 329 | req.setAttribute("issueCategoryEnum", IssueCategory.values()); |
universe@80 | 330 | req.setAttribute("statsAffected", versionDao.statsOpenedIssues(selection.version)); |
universe@80 | 331 | req.setAttribute("statsScheduled", versionDao.statsScheduledIssues(selection.version)); |
universe@80 | 332 | req.setAttribute("statsResolved", versionDao.statsResolvedIssues(selection.version)); |
universe@80 | 333 | setAttributeHideZeros(req); |
universe@80 | 334 | |
universe@74 | 335 | setContentPage(req, "version-form"); |
universe@80 | 336 | setBreadcrumbs(req, getBreadcrumbs(BREADCRUMB_LEVEL_VERSION, selection)); |
universe@71 | 337 | } |
universe@71 | 338 | |
universe@59 | 339 | @RequestMapping(requestPath = "versions/edit", method = HttpMethod.GET) |
universe@80 | 340 | public ResponseType editVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException { |
universe@75 | 341 | final var sessionSelection = new SessionSelection(req, dao); |
universe@59 | 342 | |
universe@75 | 343 | sessionSelection.selectVersion(findByParameter(req, Integer.class, "id", dao.getVersionDao()::find) |
universe@75 | 344 | .orElse(new Version(-1, sessionSelection.project))); |
universe@76 | 345 | configureEditVersionForm(req, dao, sessionSelection); |
universe@59 | 346 | |
universe@59 | 347 | return ResponseType.HTML; |
universe@59 | 348 | } |
universe@59 | 349 | |
universe@59 | 350 | @RequestMapping(requestPath = "versions/commit", method = HttpMethod.POST) |
universe@80 | 351 | public ResponseType commitVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException { |
universe@75 | 352 | final var sessionSelection = new SessionSelection(req, dao); |
universe@59 | 353 | |
universe@75 | 354 | var version = new Version(-1, sessionSelection.project); |
universe@59 | 355 | try { |
universe@75 | 356 | version = new Version(getParameter(req, Integer.class, "id").orElseThrow(), sessionSelection.project); |
universe@59 | 357 | version.setName(getParameter(req, String.class, "name").orElseThrow()); |
universe@59 | 358 | getParameter(req, Integer.class, "ordinal").ifPresent(version::setOrdinal); |
universe@59 | 359 | version.setStatus(VersionStatus.valueOf(getParameter(req, String.class, "status").orElseThrow())); |
universe@59 | 360 | dao.getVersionDao().saveOrUpdate(version); |
universe@59 | 361 | |
universe@75 | 362 | // specifying the pid parameter will purposely reset the session selected version! |
universe@75 | 363 | setRedirectLocation(req, "./projects/view?pid="+sessionSelection.project.getId()); |
universe@74 | 364 | setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); |
universe@75 | 365 | LOG.debug("Successfully updated version {} for project {}", version.getName(), sessionSelection.project.getName()); |
universe@75 | 366 | } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { |
universe@59 | 367 | // TODO: set request attribute with error text |
universe@59 | 368 | LOG.warn("Form validation failure: {}", ex.getMessage()); |
universe@59 | 369 | LOG.debug("Details:", ex); |
universe@75 | 370 | sessionSelection.selectVersion(version); |
universe@76 | 371 | configureEditVersionForm(req, dao, sessionSelection); |
universe@59 | 372 | } |
universe@41 | 373 | |
universe@43 | 374 | return ResponseType.HTML; |
universe@41 | 375 | } |
universe@64 | 376 | |
universe@75 | 377 | private void configureEditIssueForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException { |
universe@76 | 378 | req.setAttribute("projects", dao.getProjectDao().list()); |
universe@75 | 379 | req.setAttribute("issue", selection.issue); |
universe@71 | 380 | req.setAttribute("issueStatusEnum", IssueStatus.values()); |
universe@71 | 381 | req.setAttribute("issueCategoryEnum", IssueCategory.values()); |
universe@75 | 382 | req.setAttribute("users", dao.getUserDao().list()); |
universe@71 | 383 | |
universe@74 | 384 | setContentPage(req, "issue-form"); |
universe@80 | 385 | setBreadcrumbs(req, getBreadcrumbs(BREADCRUMB_LEVEL_ISSUE, selection)); |
universe@80 | 386 | } |
universe@80 | 387 | |
universe@80 | 388 | @RequestMapping(requestPath = "issues/", method = HttpMethod.GET) |
universe@80 | 389 | public ResponseType issues(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, IOException { |
universe@80 | 390 | final var sessionSelection = new SessionSelection(req, dao); |
universe@80 | 391 | if (sessionSelection.project == null) { |
universe@80 | 392 | resp.sendError(HttpServletResponse.SC_NOT_FOUND, "No project selected."); |
universe@80 | 393 | return ResponseType.NONE; |
universe@80 | 394 | } |
universe@80 | 395 | |
universe@80 | 396 | req.setAttribute("issues", dao.getIssueDao().list(sessionSelection.project)); |
universe@80 | 397 | |
universe@80 | 398 | setBreadcrumbs(req, getBreadcrumbs(BREADCRUMB_LEVEL_ISSUE_LIST, sessionSelection)); |
universe@80 | 399 | setContentPage(req, "issues"); |
universe@80 | 400 | setStylesheet(req, "projects"); |
universe@80 | 401 | |
universe@80 | 402 | return ResponseType.HTML; |
universe@71 | 403 | } |
universe@71 | 404 | |
universe@64 | 405 | @RequestMapping(requestPath = "issues/edit", method = HttpMethod.GET) |
universe@80 | 406 | public ResponseType editIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException { |
universe@75 | 407 | final var sessionSelection = new SessionSelection(req, dao); |
universe@64 | 408 | |
universe@75 | 409 | sessionSelection.selectIssue(findByParameter(req, Integer.class, "id", |
universe@75 | 410 | dao.getIssueDao()::find).orElse(new Issue(-1, sessionSelection.project))); |
universe@75 | 411 | configureEditIssueForm(req, dao, sessionSelection); |
universe@64 | 412 | |
universe@64 | 413 | return ResponseType.HTML; |
universe@64 | 414 | } |
universe@64 | 415 | |
universe@64 | 416 | @RequestMapping(requestPath = "issues/commit", method = HttpMethod.POST) |
universe@80 | 417 | public ResponseType commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException { |
universe@75 | 418 | final var sessionSelection = new SessionSelection(req, dao); |
universe@64 | 419 | |
universe@75 | 420 | Issue issue = new Issue(-1, sessionSelection.project); |
universe@64 | 421 | try { |
universe@75 | 422 | issue = new Issue(getParameter(req, Integer.class, "id").orElseThrow(), sessionSelection.project); |
universe@75 | 423 | getParameter(req, String.class, "category").map(IssueCategory::valueOf).ifPresent(issue::setCategory); |
universe@75 | 424 | getParameter(req, String.class, "status").map(IssueStatus::valueOf).ifPresent(issue::setStatus); |
universe@75 | 425 | issue.setSubject(getParameter(req, String.class, "subject").orElseThrow()); |
universe@75 | 426 | getParameter(req, Integer.class, "assignee").map( |
universe@75 | 427 | userid -> userid >= 0 ? new User(userid) : null |
universe@75 | 428 | ).ifPresent(issue::setAssignee); |
universe@75 | 429 | getParameter(req, String.class, "description").ifPresent(issue::setDescription); |
universe@75 | 430 | getParameter(req, Date.class, "eta").ifPresent(issue::setEta); |
universe@64 | 431 | dao.getIssueDao().saveOrUpdate(issue); |
universe@64 | 432 | |
universe@75 | 433 | // specifying the issue parameter keeps the edited issue as breadcrumb |
universe@81 | 434 | setRedirectLocation(req, "./projects/issues/?issue="+issue.getId()); |
universe@74 | 435 | setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); |
universe@75 | 436 | LOG.debug("Successfully updated issue {} for project {}", issue.getId(), sessionSelection.project.getName()); |
universe@75 | 437 | } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { |
universe@64 | 438 | // TODO: set request attribute with error text |
universe@64 | 439 | LOG.warn("Form validation failure: {}", ex.getMessage()); |
universe@64 | 440 | LOG.debug("Details:", ex); |
universe@75 | 441 | sessionSelection.selectIssue(issue); |
universe@75 | 442 | configureEditIssueForm(req, dao, sessionSelection); |
universe@64 | 443 | } |
universe@64 | 444 | |
universe@64 | 445 | return ResponseType.HTML; |
universe@64 | 446 | } |
universe@41 | 447 | } |