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@97: // TODO: try to get rid of this shit 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@97: if (issueSelection.get() < 0) { universe@97: issue = null; universe@97: } else { universe@97: final var selectedIssue = dao.getIssueDao().find(issueSelection.get()); universe@97: dao.getIssueDao().joinVersionInformation(selectedIssue); universe@97: selectIssue(selectedIssue); universe@97: } 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@97: private String queryParams(Project p, Version v, Issue i) { universe@97: return String.format("pid=%d&vid=%d&issue=%d", universe@97: p == null ? -1 : p.getId(), universe@97: v == null ? -1 : v.getId(), universe@97: i == null ? -1 : i.getId() universe@97: ); universe@97: } universe@80: universe@71: /** universe@96: * Creates the navigation menu. universe@71: * universe@97: * @param projects the list of projects universe@86: * @param selection the currently selected objects universe@97: * @param projInfo info about the currently selected project or null universe@96: * @return a dynamic navigation menu trying to display as many levels as possible universe@71: */ universe@97: private List getNavMenu(List projects, SessionSelection selection, ProjectInfo projInfo) { universe@97: final var navigation = new ArrayList(); universe@71: universe@97: for (Project proj : projects) { universe@97: final var projEntry = new MenuEntry( universe@97: proj.getName(), universe@97: "projects/view?pid=" + proj.getId() universe@97: ); universe@97: navigation.add(projEntry); universe@97: if (proj.equals(selection.project)) { universe@97: projEntry.setActive(true); universe@71: universe@97: // **************** universe@97: // Versions Section universe@97: // **************** universe@97: { universe@97: final var entry = new MenuEntry(1, universe@97: new ResourceKey("localization.projects", "menu.versions"), universe@97: "projects/view?" + queryParams(proj, null, null) universe@97: ); universe@97: navigation.add(entry); universe@97: } universe@97: universe@97: final var level2 = new ArrayList(); universe@97: { universe@97: final var entry = new MenuEntry( universe@97: new ResourceKey("localization.projects", "filter.all"), universe@97: "projects/view?" + queryParams(proj, null, null) universe@97: ); universe@97: if (selection.version == null) entry.setActive(true); universe@97: level2.add(entry); universe@97: } universe@97: universe@97: for (Version version : projInfo.getVersions()) { universe@97: final var entry = new MenuEntry( universe@97: version.getName(), universe@97: "projects/versions/view?" + queryParams(proj, version, null) universe@97: ); universe@97: if (version.equals(selection.version)) entry.setActive(true); universe@97: level2.add(entry); universe@97: } universe@97: universe@97: level2.forEach(e -> e.setLevel(2)); universe@97: navigation.addAll(level2); universe@75: } universe@75: } universe@75: universe@96: return navigation; 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@97: setNavigationMenu(req, getNavMenu(projectList, sessionSelection, currentProjectInfo(dao, sessionSelection.project))); universe@45: universe@45: return ResponseType.HTML; universe@45: } universe@45: universe@97: private ProjectInfo currentProjectInfo(DataAccessObjects dao, Project project) throws SQLException { universe@97: if (project == null) return null; universe@97: final var projectDao = dao.getProjectDao(); universe@97: final var versionDao = dao.getVersionDao(); universe@97: universe@97: final var info = new ProjectInfo(project); universe@97: info.setVersions(versionDao.list(project)); universe@97: info.setIssueSummary(projectDao.getIssueSummary(project)); universe@97: return info; universe@97: } universe@97: 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@97: setNavigationMenu(req, getNavMenu(dao.getProjectDao().list(), selection, currentProjectInfo(dao, selection.project))); universe@86: setViewModel(req, viewModel); universe@74: setContentPage(req, "project-form"); 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@97: final var projectDao = dao.getProjectDao(); 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@97: // TODO: fix duplicated selection of versions (projectInfo also contains these infos) universe@86: viewModel.setVersions(versionDao.list(selection.project)); universe@86: viewModel.updateVersionInfo(); universe@86: setViewModel(req, viewModel); universe@80: universe@97: setNavigationMenu(req, getNavMenu(projectDao.list(), selection, currentProjectInfo(dao, selection.project))); 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@97: final var projectDao = dao.getProjectDao(); universe@86: final var issueDao = dao.getIssueDao(); universe@97: 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@97: setNavigationMenu(req, getNavMenu(projectDao.list(), selection, currentProjectInfo(dao, selection.project))); 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@97: setNavigationMenu(req, getNavMenu(dao.getProjectDao().list(), selection, currentProjectInfo(dao, selection.project))); 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@96: 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@97: setNavigationMenu(req, getNavMenu(dao.getProjectDao().list(), selection, currentProjectInfo(dao, selection.project))); 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@97: final var projectDao = dao.getProjectDao(); universe@97: final var issueDao = dao.getIssueDao(); universe@97: universe@86: final var viewModel = new IssuesView(); universe@86: viewModel.setProject(selection.project); universe@86: if (selection.version == null) { universe@97: viewModel.setIssues(issueDao.list(selection.project)); universe@86: } else { universe@86: viewModel.setVersion(selection.version); universe@97: viewModel.setIssues(issueDao.list(selection.version)); universe@86: } universe@86: setViewModel(req, viewModel); universe@80: universe@97: setNavigationMenu(req, getNavMenu(projectDao.list(), selection, currentProjectInfo(dao, selection.project))); 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@96: 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@96: // specifying the issue parameter keeps the edited issue as menu item universe@96: 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: }