universe@41: /* universe@41: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. universe@41: * universe@41: * Copyright 2018 Mike Becker. All rights reserved. universe@41: * universe@41: * Redistribution and use in source and binary forms, with or without universe@41: * modification, are permitted provided that the following conditions are met: universe@41: * universe@41: * 1. Redistributions of source code must retain the above copyright universe@41: * notice, this list of conditions and the following disclaimer. universe@41: * universe@41: * 2. Redistributions in binary form must reproduce the above copyright universe@41: * notice, this list of conditions and the following disclaimer in the universe@41: * documentation and/or other materials provided with the distribution. universe@41: * universe@41: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" universe@41: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE universe@41: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE universe@41: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE universe@41: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR universe@41: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF universe@41: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS universe@41: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN universe@41: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) universe@41: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE universe@41: * POSSIBILITY OF SUCH DAMAGE. universe@41: * universe@41: */ universe@41: package de.uapcore.lightpit.modules; universe@41: universe@41: universe@41: import de.uapcore.lightpit.*; universe@41: import de.uapcore.lightpit.dao.DataAccessObjects; universe@64: import de.uapcore.lightpit.entities.*; universe@86: import de.uapcore.lightpit.viewmodel.*; universe@59: import org.slf4j.Logger; universe@59: import org.slf4j.LoggerFactory; universe@41: universe@41: import javax.servlet.annotation.WebServlet; universe@41: import javax.servlet.http.HttpServletRequest; universe@59: import javax.servlet.http.HttpServletResponse; universe@75: import javax.servlet.http.HttpSession; universe@59: import java.io.IOException; universe@75: import java.sql.Date; universe@47: import java.sql.SQLException; universe@86: import java.util.ArrayList; universe@86: import java.util.List; universe@86: import java.util.NoSuchElementException; universe@86: import java.util.Objects; universe@83: import java.util.stream.Collectors; universe@83: import java.util.stream.Stream; universe@41: universe@52: import static de.uapcore.lightpit.Functions.fqn; universe@52: universe@41: @WebServlet( universe@41: name = "ProjectsModule", universe@41: urlPatterns = "/projects/*" universe@41: ) universe@41: public final class ProjectsModule extends AbstractLightPITServlet { universe@41: universe@59: private static final Logger LOG = LoggerFactory.getLogger(ProjectsModule.class); universe@59: universe@80: public static final String SESSION_ATTR_SELECTED_PROJECT = fqn(ProjectsModule.class, "selected_project"); universe@80: public static final String SESSION_ATTR_SELECTED_ISSUE = fqn(ProjectsModule.class, "selected_issue"); universe@80: public static final String SESSION_ATTR_SELECTED_VERSION = fqn(ProjectsModule.class, "selected_version"); universe@52: universe@75: private class SessionSelection { universe@75: final HttpSession session; universe@86: final HttpServletRequest req; universe@86: final DataAccessObjects dao; universe@75: Project project; universe@75: Version version; universe@75: Issue issue; universe@75: universe@86: SessionSelection(HttpServletRequest req, DataAccessObjects dao) { universe@86: this.req = req; universe@86: this.dao = dao; universe@86: session = req.getSession(); universe@86: } universe@86: universe@86: void newProject() { universe@86: project = null; universe@75: version = null; universe@75: issue = null; universe@75: updateAttributes(); universe@86: project = new Project(-1); universe@86: updateAttributes(); universe@64: } universe@75: universe@86: void newVersion() throws SQLException { universe@86: project = (Project) session.getAttribute(SESSION_ATTR_SELECTED_PROJECT); universe@86: syncProject(); universe@86: version = null; universe@86: issue = null; universe@86: updateAttributes(); universe@86: version = new Version(-1); universe@86: version.setProject(project); universe@86: updateAttributes(); universe@86: } universe@86: universe@86: void newIssue() throws SQLException { universe@86: project = (Project) session.getAttribute(SESSION_ATTR_SELECTED_PROJECT); universe@86: syncProject(); universe@86: version = null; universe@86: issue = null; universe@86: updateAttributes(); universe@86: issue = new Issue(-1); universe@86: issue.setProject(project); universe@86: updateAttributes(); universe@86: } universe@86: universe@86: void selectVersion(Version selectedVersion) throws SQLException { universe@86: issue = null; universe@86: version = selectedVersion; universe@86: if (!version.getProject().equals(project)) { universe@86: project = dao.getProjectDao().find(version.getProject().getId()); universe@75: } universe@86: // our object contains more details universe@86: version.setProject(project); universe@86: updateAttributes(); universe@86: } universe@86: universe@86: void selectIssue(Issue selectedIssue) throws SQLException { universe@86: issue = selectedIssue; universe@86: if (!issue.getProject().equals(project)) { universe@86: project = dao.getProjectDao().find(issue.getProject().getId()); universe@75: } universe@86: // our object contains more details universe@86: issue.setProject(project); universe@88: if (!issue.getResolvedVersions().contains(version) universe@86: && !issue.getAffectedVersions().contains(version)) { universe@86: version = null; universe@86: } universe@86: updateAttributes(); universe@86: } universe@75: universe@86: void syncProject() throws SQLException { universe@75: final var projectSelection = getParameter(req, Integer.class, "pid"); universe@75: if (projectSelection.isPresent()) { universe@86: final var selectedProject = dao.getProjectDao().find(projectSelection.get()); universe@75: if (!Objects.equals(selectedProject, project)) { universe@75: // reset version and issue if project changed universe@75: version = null; universe@75: issue = null; universe@75: } universe@75: project = selectedProject; universe@75: } else { universe@86: project = project == null ? null : dao.getProjectDao().find(project.getId()); universe@75: } universe@86: } universe@86: universe@86: void syncVersion() throws SQLException { universe@86: final var versionSelection = getParameter(req, Integer.class, "vid"); universe@86: if (versionSelection.isPresent()) { universe@86: if (versionSelection.get() < 0) { universe@86: version = null; universe@86: } else { universe@86: final var selectedVersion = dao.getVersionDao().find(versionSelection.get()); universe@86: if (!Objects.equals(selectedVersion, version)) { universe@86: issue = null; universe@86: } universe@86: selectVersion(selectedVersion); universe@86: } universe@86: } else { universe@86: version = version == null ? null : dao.getVersionDao().find(version.getId()); universe@86: } universe@86: } universe@86: universe@86: void syncIssue() throws SQLException { universe@86: final var issueSelection = getParameter(req, Integer.class, "issue"); universe@86: if (issueSelection.isPresent()) { universe@86: final var selectedIssue = dao.getIssueDao().find(issueSelection.get()); universe@86: dao.getIssueDao().joinVersionInformation(selectedIssue); universe@86: selectIssue(selectedIssue); universe@86: } else { universe@86: issue = issue == null ? null : dao.getIssueDao().find(issue.getId()); universe@86: } universe@86: } universe@86: universe@86: void sync() throws SQLException { universe@86: project = (Project) session.getAttribute(SESSION_ATTR_SELECTED_PROJECT); universe@86: version = (Version) session.getAttribute(SESSION_ATTR_SELECTED_VERSION); universe@86: issue = (Issue) session.getAttribute(SESSION_ATTR_SELECTED_ISSUE); universe@86: universe@86: syncProject(); universe@86: syncVersion(); universe@86: syncIssue(); universe@86: universe@75: updateAttributes(); universe@75: } universe@75: universe@86: private void updateAttributes() { universe@75: session.setAttribute(SESSION_ATTR_SELECTED_PROJECT, project); universe@75: session.setAttribute(SESSION_ATTR_SELECTED_VERSION, version); universe@75: session.setAttribute(SESSION_ATTR_SELECTED_ISSUE, issue); universe@75: } universe@71: } universe@71: universe@78: @Override universe@78: protected String getResourceBundleName() { universe@78: return "localization.projects"; universe@78: } universe@71: universe@80: universe@80: private static final int BREADCRUMB_LEVEL_ROOT = 0; universe@80: private static final int BREADCRUMB_LEVEL_PROJECT = 1; universe@80: private static final int BREADCRUMB_LEVEL_VERSION = 2; universe@80: private static final int BREADCRUMB_LEVEL_ISSUE_LIST = 3; universe@80: private static final int BREADCRUMB_LEVEL_ISSUE = 4; universe@80: universe@71: /** universe@71: * Creates the breadcrumb menu. universe@71: * universe@80: * @param level the current active level (0: root, 1: project, 2: version, 3: issue list, 4: issue) universe@86: * @param selection the currently selected objects universe@71: * @return a dynamic breadcrumb menu trying to display as many levels as possible universe@71: */ universe@86: private List getBreadcrumbs(int level, SessionSelection selection) { universe@71: MenuEntry entry; universe@71: universe@71: final var breadcrumbs = new ArrayList(); universe@79: entry = new MenuEntry(new ResourceKey("localization.lightpit", "menu.projects"), universe@79: "projects/"); universe@71: breadcrumbs.add(entry); universe@80: if (level == BREADCRUMB_LEVEL_ROOT) entry.setActive(true); universe@71: universe@86: if (selection.project != null) { universe@86: if (selection.project.getId() < 0) { universe@75: entry = new MenuEntry(new ResourceKey("localization.projects", "button.create"), universe@79: "projects/edit"); universe@75: } else { universe@86: entry = new MenuEntry(selection.project.getName(), universe@86: "projects/view?pid=" + selection.project.getId()); universe@75: } universe@80: if (level == BREADCRUMB_LEVEL_PROJECT) entry.setActive(true); universe@75: breadcrumbs.add(entry); universe@75: } universe@71: universe@86: if (selection.version != null) { universe@86: if (selection.version.getId() < 0) { universe@75: entry = new MenuEntry(new ResourceKey("localization.projects", "button.version.create"), universe@79: "projects/versions/edit"); universe@75: } else { universe@86: entry = new MenuEntry(selection.version.getName(), universe@86: "projects/versions/view?vid=" + selection.version.getId()); universe@75: } universe@80: if (level == BREADCRUMB_LEVEL_VERSION) entry.setActive(true); universe@80: breadcrumbs.add(entry); universe@80: } universe@80: universe@86: if (selection.project != null) { universe@86: String path = "projects/issues/?pid=" + selection.project.getId(); universe@86: if (selection.version != null) { universe@86: path += "&vid="+selection.version.getId(); universe@86: } universe@80: entry = new MenuEntry(new ResourceKey("localization.projects", "menu.issues"), universe@86: path); universe@80: if (level == BREADCRUMB_LEVEL_ISSUE_LIST) entry.setActive(true); universe@75: breadcrumbs.add(entry); universe@75: } universe@71: universe@86: if (selection.issue != null) { universe@86: if (selection.issue.getId() < 0) { universe@75: entry = new MenuEntry(new ResourceKey("localization.projects", "button.issue.create"), universe@79: "projects/issues/edit"); universe@75: } else { universe@86: entry = new MenuEntry("#" + selection.issue.getId(), universe@75: // TODO: maybe change link to a view rather than directly opening the editor universe@86: "projects/issues/edit?issue=" + selection.issue.getId()); universe@75: } universe@80: if (level == BREADCRUMB_LEVEL_ISSUE) entry.setActive(true); universe@75: breadcrumbs.add(entry); universe@75: } universe@75: universe@71: return breadcrumbs; universe@64: } universe@64: universe@61: @RequestMapping(method = HttpMethod.GET) universe@47: public ResponseType index(HttpServletRequest req, DataAccessObjects dao) throws SQLException { universe@75: final var sessionSelection = new SessionSelection(req, dao); universe@86: sessionSelection.sync(); universe@86: universe@86: final var projectDao = dao.getProjectDao(); universe@86: final var versionDao = dao.getVersionDao(); universe@86: universe@86: final var projectList = projectDao.list(); universe@86: universe@86: final var viewModel = new ProjectIndexView(); universe@86: for (var project : projectList) { universe@86: final var info = new ProjectInfo(project); universe@86: info.setVersions(versionDao.list(project)); universe@86: info.setIssueSummary(projectDao.getIssueSummary(project)); universe@86: viewModel.getProjects().add(info); universe@86: } universe@86: universe@86: setViewModel(req, viewModel); universe@74: setContentPage(req, "projects"); universe@52: setStylesheet(req, "projects"); universe@52: universe@80: setBreadcrumbs(req, getBreadcrumbs(BREADCRUMB_LEVEL_ROOT, sessionSelection)); universe@45: universe@45: return ResponseType.HTML; universe@45: } universe@45: universe@86: private ProjectEditView configureEditForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException { universe@86: final var viewModel = new ProjectEditView(); universe@86: viewModel.setProject(selection.project); universe@86: viewModel.setUsers(dao.getUserDao().list()); universe@86: setViewModel(req, viewModel); universe@74: setContentPage(req, "project-form"); universe@80: setBreadcrumbs(req, getBreadcrumbs(BREADCRUMB_LEVEL_PROJECT, selection)); universe@86: return viewModel; universe@71: } universe@71: universe@47: @RequestMapping(requestPath = "edit", method = HttpMethod.GET) universe@51: public ResponseType edit(HttpServletRequest req, DataAccessObjects dao) throws SQLException { universe@86: final var selection = new SessionSelection(req, dao); universe@86: if (getParameter(req, Integer.class, "pid").isEmpty()) { universe@86: selection.newProject(); universe@86: } else { universe@86: selection.sync(); universe@86: } universe@47: universe@75: configureEditForm(req, dao, selection); universe@47: universe@47: return ResponseType.HTML; universe@47: } universe@47: universe@47: @RequestMapping(requestPath = "commit", method = HttpMethod.POST) universe@68: public ResponseType commit(HttpServletRequest req, DataAccessObjects dao) throws SQLException { universe@47: universe@75: Project project = new Project(-1); universe@47: try { universe@47: project = new Project(getParameter(req, Integer.class, "id").orElseThrow()); universe@47: project.setName(getParameter(req, String.class, "name").orElseThrow()); universe@47: getParameter(req, String.class, "description").ifPresent(project::setDescription); universe@47: getParameter(req, String.class, "repoUrl").ifPresent(project::setRepoUrl); universe@47: getParameter(req, Integer.class, "owner").map( universe@47: ownerId -> ownerId >= 0 ? new User(ownerId) : null universe@47: ).ifPresent(project::setOwner); universe@47: universe@47: dao.getProjectDao().saveOrUpdate(project); universe@47: universe@70: setRedirectLocation(req, "./projects/"); universe@74: setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); universe@59: LOG.debug("Successfully updated project {}", project.getName()); universe@75: } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { universe@59: LOG.warn("Form validation failure: {}", ex.getMessage()); universe@59: LOG.debug("Details:", ex); universe@86: final var selection = new SessionSelection(req, dao); universe@86: selection.project = project; universe@86: final var vm = configureEditForm(req, dao, selection); universe@86: vm.setErrorText(ex.getMessage()); // TODO: error text universe@47: } universe@47: universe@47: return ResponseType.HTML; universe@47: } universe@47: universe@70: @RequestMapping(requestPath = "view", method = HttpMethod.GET) universe@80: public ResponseType view(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, IOException { universe@86: final var selection = new SessionSelection(req, dao); universe@86: selection.sync(); universe@86: universe@86: if (selection.project == null) { universe@80: resp.sendError(HttpServletResponse.SC_NOT_FOUND, "No project selected."); universe@80: return ResponseType.NONE; universe@80: } universe@47: universe@80: final var versionDao = dao.getVersionDao(); universe@86: final var issueDao = dao.getIssueDao(); universe@70: universe@86: final var viewModel = new ProjectView(selection.project); universe@86: final var issues = issueDao.list(selection.project); universe@86: for (var issue : issues) issueDao.joinVersionInformation(issue); universe@86: viewModel.setIssues(issues); universe@86: viewModel.setVersions(versionDao.list(selection.project)); universe@86: viewModel.updateVersionInfo(); universe@86: setViewModel(req, viewModel); universe@80: universe@86: setBreadcrumbs(req, getBreadcrumbs(BREADCRUMB_LEVEL_PROJECT, selection)); universe@74: setContentPage(req, "project-details"); universe@80: setStylesheet(req, "projects"); universe@59: universe@59: return ResponseType.HTML; universe@59: } universe@59: universe@86: @RequestMapping(requestPath = "versions/view", method = HttpMethod.GET) universe@86: public ResponseType viewVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, IOException { universe@86: final var selection = new SessionSelection(req, dao); universe@86: selection.sync(); universe@86: if (selection.version == null) { universe@86: resp.sendError(HttpServletResponse.SC_NOT_FOUND); universe@86: return ResponseType.NONE; universe@86: } universe@71: universe@86: final var issueDao = dao.getIssueDao(); universe@86: final var viewModel = new VersionView(selection.version); universe@86: final var issues = issueDao.list(selection.version); universe@86: for (var issue : issues) issueDao.joinVersionInformation(issue); universe@86: viewModel.setIssues(issues); universe@86: setViewModel(req, viewModel); universe@80: universe@86: setBreadcrumbs(req, getBreadcrumbs(BREADCRUMB_LEVEL_VERSION, selection)); universe@86: setContentPage(req, "version"); universe@86: setStylesheet(req, "projects"); universe@86: universe@86: return ResponseType.HTML; universe@86: } universe@86: universe@86: private VersionEditView configureEditVersionForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException { universe@86: final var viewModel = new VersionEditView(selection.version); universe@86: if (selection.version.getProject() == null) { universe@86: viewModel.setProjects(dao.getProjectDao().list()); universe@86: } universe@86: setViewModel(req, viewModel); universe@74: setContentPage(req, "version-form"); universe@80: setBreadcrumbs(req, getBreadcrumbs(BREADCRUMB_LEVEL_VERSION, selection)); universe@86: return viewModel; universe@71: } universe@71: universe@59: @RequestMapping(requestPath = "versions/edit", method = HttpMethod.GET) universe@86: public ResponseType editVersion(HttpServletRequest req, DataAccessObjects dao) throws SQLException { universe@86: final var selection = new SessionSelection(req, dao); universe@86: if (getParameter(req, Integer.class, "vid").isEmpty()) { universe@86: selection.newVersion(); universe@86: } else { universe@86: selection.sync(); universe@86: } universe@59: universe@86: configureEditVersionForm(req, dao, selection); universe@59: universe@59: return ResponseType.HTML; universe@59: } universe@59: universe@59: @RequestMapping(requestPath = "versions/commit", method = HttpMethod.POST) universe@80: public ResponseType commitVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException { universe@59: universe@86: var version = new Version(-1); universe@59: try { universe@86: version = new Version(getParameter(req, Integer.class, "id").orElseThrow()); universe@86: version.setProject(new Project(getParameter(req, Integer.class, "pid").orElseThrow())); universe@59: version.setName(getParameter(req, String.class, "name").orElseThrow()); universe@59: getParameter(req, Integer.class, "ordinal").ifPresent(version::setOrdinal); universe@59: version.setStatus(VersionStatus.valueOf(getParameter(req, String.class, "status").orElseThrow())); universe@59: dao.getVersionDao().saveOrUpdate(version); universe@59: universe@75: // specifying the pid parameter will purposely reset the session selected version! universe@86: setRedirectLocation(req, "./projects/view?pid="+version.getProject().getId()); universe@74: setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); universe@75: } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { universe@59: LOG.warn("Form validation failure: {}", ex.getMessage()); universe@59: LOG.debug("Details:", ex); universe@86: final var selection = new SessionSelection(req, dao); universe@86: selection.selectVersion(version); universe@86: final var viewModel = configureEditVersionForm(req, dao, selection); universe@86: // TODO: set Error Text universe@59: } universe@41: universe@43: return ResponseType.HTML; universe@41: } universe@64: universe@86: private IssueEditView configureEditIssueForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException { universe@86: final var viewModel = new IssueEditView(selection.issue); universe@83: universe@86: if (selection.issue.getProject() == null) { universe@86: viewModel.setProjects(dao.getProjectDao().list()); universe@83: } else { universe@86: viewModel.setVersions(dao.getVersionDao().list(selection.issue.getProject())); universe@83: } universe@86: viewModel.setUsers(dao.getUserDao().list()); universe@86: setViewModel(req, viewModel); universe@71: universe@74: setContentPage(req, "issue-form"); universe@80: setBreadcrumbs(req, getBreadcrumbs(BREADCRUMB_LEVEL_ISSUE, selection)); universe@86: return viewModel; universe@80: } universe@80: universe@80: @RequestMapping(requestPath = "issues/", method = HttpMethod.GET) universe@80: public ResponseType issues(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, IOException { universe@86: final var selection = new SessionSelection(req, dao); universe@86: selection.sync(); universe@86: if (selection.project == null) { universe@80: resp.sendError(HttpServletResponse.SC_NOT_FOUND, "No project selected."); universe@80: return ResponseType.NONE; universe@80: } universe@80: universe@86: final var viewModel = new IssuesView(); universe@86: viewModel.setProject(selection.project); universe@86: if (selection.version == null) { universe@86: viewModel.setIssues(dao.getIssueDao().list(selection.project)); universe@86: } else { universe@86: viewModel.setVersion(selection.version); universe@86: viewModel.setIssues(dao.getIssueDao().list(selection.version)); universe@86: } universe@86: setViewModel(req, viewModel); universe@80: universe@86: setBreadcrumbs(req, getBreadcrumbs(BREADCRUMB_LEVEL_ISSUE_LIST, selection)); universe@80: setContentPage(req, "issues"); universe@80: setStylesheet(req, "projects"); universe@80: universe@80: return ResponseType.HTML; universe@71: } universe@71: universe@64: @RequestMapping(requestPath = "issues/edit", method = HttpMethod.GET) universe@80: public ResponseType editIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException { universe@86: final var selection = new SessionSelection(req, dao); universe@86: if (getParameter(req, Integer.class, "issue").isEmpty()) { universe@86: selection.newIssue(); universe@86: } else { universe@86: selection.sync(); universe@86: } universe@64: universe@86: configureEditIssueForm(req, dao, selection); universe@64: universe@64: return ResponseType.HTML; universe@64: } universe@64: universe@64: @RequestMapping(requestPath = "issues/commit", method = HttpMethod.POST) universe@80: public ResponseType commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException { universe@64: universe@86: Issue issue = new Issue(-1); universe@64: try { universe@86: issue = new Issue(getParameter(req, Integer.class, "id").orElseThrow()); universe@86: issue.setProject(new Project(getParameter(req, Integer.class, "pid").orElseThrow())); universe@75: getParameter(req, String.class, "category").map(IssueCategory::valueOf).ifPresent(issue::setCategory); universe@75: getParameter(req, String.class, "status").map(IssueStatus::valueOf).ifPresent(issue::setStatus); universe@75: issue.setSubject(getParameter(req, String.class, "subject").orElseThrow()); universe@75: getParameter(req, Integer.class, "assignee").map( universe@75: userid -> userid >= 0 ? new User(userid) : null universe@75: ).ifPresent(issue::setAssignee); universe@75: getParameter(req, String.class, "description").ifPresent(issue::setDescription); universe@75: getParameter(req, Date.class, "eta").ifPresent(issue::setEta); universe@83: universe@83: getParameter(req, Integer[].class, "affected") universe@83: .map(Stream::of) universe@83: .map(stream -> universe@86: stream.map(Version::new).collect(Collectors.toList()) universe@83: ).ifPresent(issue::setAffectedVersions); universe@83: getParameter(req, Integer[].class, "resolved") universe@83: .map(Stream::of) universe@83: .map(stream -> universe@86: stream.map(Version::new).collect(Collectors.toList()) universe@83: ).ifPresent(issue::setResolvedVersions); universe@83: universe@64: dao.getIssueDao().saveOrUpdate(issue); universe@64: universe@75: // specifying the issue parameter keeps the edited issue as breadcrumb universe@81: setRedirectLocation(req, "./projects/issues/?issue="+issue.getId()); universe@74: setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); universe@75: } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { universe@64: // TODO: set request attribute with error text universe@64: LOG.warn("Form validation failure: {}", ex.getMessage()); universe@64: LOG.debug("Details:", ex); universe@86: final var selection = new SessionSelection(req, dao); universe@86: selection.selectIssue(issue); universe@86: final var viewModel = configureEditIssueForm(req, dao, selection); universe@86: // TODO: set Error Text universe@64: } universe@64: universe@64: return ResponseType.HTML; universe@64: } universe@41: }