issue and version form now also work if no project is selected in the session

Sat, 23 May 2020 13:24:49 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 23 May 2020 13:24:49 +0200
changeset 76
82f71fb1758a
parent 75
33b6843fdf8a
child 77
192298f8161f

issue and version form now also work if no project is selected in the session

src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java file | annotate | diff | comparison | revisions
src/main/resources/localization/projects.properties file | annotate | diff | comparison | revisions
src/main/resources/localization/projects_de.properties file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/jsp/issue-form.jsp file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/jsp/version-form.jsp file | annotate | diff | comparison | revisions
     1.1 --- a/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java	Fri May 22 21:23:57 2020 +0200
     1.2 +++ b/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java	Sat May 23 13:24:49 2020 +0200
     1.3 @@ -113,14 +113,14 @@
     1.4          }
     1.5  
     1.6          void selectVersion(Version version) {
     1.7 -            if (!version.getProject().equals(project)) throw new AssertionError("Nice, you implemented a bug!");
     1.8 +            if (!Objects.equals(project, version.getProject())) throw new AssertionError("Nice, you implemented a bug!");
     1.9              this.version = version;
    1.10              this.issue = null;
    1.11              updateAttributes();
    1.12          }
    1.13  
    1.14          void selectIssue(Issue issue) {
    1.15 -            if (!issue.getProject().equals(project)) throw new AssertionError("Nice, you implemented a bug!");
    1.16 +            if (!Objects.equals(issue.getProject(), project)) throw new AssertionError("Nice, you implemented a bug!");
    1.17              this.issue = issue;
    1.18              this.version = null;
    1.19              updateAttributes();
    1.20 @@ -266,7 +266,8 @@
    1.21          return ResponseType.HTML;
    1.22      }
    1.23  
    1.24 -    private void configureEditVersionForm(HttpServletRequest req, SessionSelection selection) {
    1.25 +    private void configureEditVersionForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException {
    1.26 +        req.setAttribute("projects", dao.getProjectDao().list());
    1.27          req.setAttribute("version", selection.version);
    1.28          req.setAttribute("versionStatusEnum", VersionStatus.values());
    1.29  
    1.30 @@ -277,15 +278,10 @@
    1.31      @RequestMapping(requestPath = "versions/edit", method = HttpMethod.GET)
    1.32      public ResponseType editVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException {
    1.33          final var sessionSelection = new SessionSelection(req, dao);
    1.34 -        if (sessionSelection.project == null) {
    1.35 -            // TODO: remove this bullshit and only retrieve the object from session if we are creating a fresh version
    1.36 -            resp.sendError(HttpServletResponse.SC_FORBIDDEN);
    1.37 -            return ResponseType.NONE;
    1.38 -        }
    1.39  
    1.40          sessionSelection.selectVersion(findByParameter(req, Integer.class, "id", dao.getVersionDao()::find)
    1.41                  .orElse(new Version(-1, sessionSelection.project)));
    1.42 -        configureEditVersionForm(req, sessionSelection);
    1.43 +        configureEditVersionForm(req, dao, sessionSelection);
    1.44  
    1.45          return ResponseType.HTML;
    1.46      }
    1.47 @@ -293,11 +289,6 @@
    1.48      @RequestMapping(requestPath = "versions/commit", method = HttpMethod.POST)
    1.49      public ResponseType commitVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException {
    1.50          final var sessionSelection = new SessionSelection(req, dao);
    1.51 -        if (sessionSelection.project == null) {
    1.52 -            // TODO: remove this bullshit and retrieve project id from hidden field
    1.53 -            resp.sendError(HttpServletResponse.SC_FORBIDDEN);
    1.54 -            return ResponseType.NONE;
    1.55 -        }
    1.56  
    1.57          var version = new Version(-1, sessionSelection.project);
    1.58          try {
    1.59 @@ -316,17 +307,17 @@
    1.60              LOG.warn("Form validation failure: {}", ex.getMessage());
    1.61              LOG.debug("Details:", ex);
    1.62              sessionSelection.selectVersion(version);
    1.63 -            configureEditVersionForm(req, sessionSelection);
    1.64 +            configureEditVersionForm(req, dao, sessionSelection);
    1.65          }
    1.66  
    1.67          return ResponseType.HTML;
    1.68      }
    1.69  
    1.70      private void configureEditIssueForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException {
    1.71 +        req.setAttribute("projects", dao.getProjectDao().list());
    1.72          req.setAttribute("issue", selection.issue);
    1.73          req.setAttribute("issueStatusEnum", IssueStatus.values());
    1.74          req.setAttribute("issueCategoryEnum", IssueCategory.values());
    1.75 -        req.setAttribute("versions", dao.getVersionDao().list(selection.project));
    1.76          req.setAttribute("users", dao.getUserDao().list());
    1.77  
    1.78          setContentPage(req, "issue-form");
    1.79 @@ -336,11 +327,6 @@
    1.80      @RequestMapping(requestPath = "issues/edit", method = HttpMethod.GET)
    1.81      public ResponseType editIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException {
    1.82          final var sessionSelection = new SessionSelection(req, dao);
    1.83 -        if (sessionSelection.project == null) {
    1.84 -            // TODO: remove this bullshit and only retrieve the object from session if we are creating a fresh issue
    1.85 -            resp.sendError(HttpServletResponse.SC_FORBIDDEN);
    1.86 -            return ResponseType.NONE;
    1.87 -        }
    1.88  
    1.89          sessionSelection.selectIssue(findByParameter(req, Integer.class, "id",
    1.90                  dao.getIssueDao()::find).orElse(new Issue(-1, sessionSelection.project)));
    1.91 @@ -351,12 +337,7 @@
    1.92  
    1.93      @RequestMapping(requestPath = "issues/commit", method = HttpMethod.POST)
    1.94      public ResponseType commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException {
    1.95 -        // TODO: remove this bullshit and store the project ID as hidden field
    1.96          final var sessionSelection = new SessionSelection(req, dao);
    1.97 -        if (sessionSelection.project == null) {
    1.98 -            resp.sendError(HttpServletResponse.SC_FORBIDDEN);
    1.99 -            return ResponseType.NONE;
   1.100 -        }
   1.101  
   1.102          Issue issue = new Issue(-1, sessionSelection.project);
   1.103          try {
     2.1 --- a/src/main/resources/localization/projects.properties	Fri May 22 21:23:57 2020 +0200
     2.2 +++ b/src/main/resources/localization/projects.properties	Sat May 23 13:24:49 2020 +0200
     2.3 @@ -36,6 +36,7 @@
     2.4  thead.repoUrl=Repository
     2.5  thead.owner=Project Lead
     2.6  
     2.7 +thead.version.project=Project
     2.8  thead.version.name=Version
     2.9  thead.version.status=Status
    2.10  thead.version.ordinal=Custom Ordering
    2.11 @@ -50,6 +51,7 @@
    2.12  version.status.LTS=LTS
    2.13  version.status.Deprecated=Deprecated
    2.14  
    2.15 +thead.issue.project=Project
    2.16  thead.issue.subject=Subject
    2.17  thead.issue.description=Description
    2.18  thead.issue.assignee=Assignee
     3.1 --- a/src/main/resources/localization/projects_de.properties	Fri May 22 21:23:57 2020 +0200
     3.2 +++ b/src/main/resources/localization/projects_de.properties	Sat May 23 13:24:49 2020 +0200
     3.3 @@ -36,6 +36,7 @@
     3.4  thead.repoUrl=Repository
     3.5  thead.owner=Projektleitung
     3.6  
     3.7 +thead.version.project=Projekt
     3.8  thead.version.name=Version
     3.9  thead.version.status=Status
    3.10  thead.version.ordinal=Sequenznummer
    3.11 @@ -50,6 +51,7 @@
    3.12  version.status.LTS=Langzeitsupport
    3.13  version.status.Deprecated=Veraltet
    3.14  
    3.15 +thead.issue.project=Projekt
    3.16  thead.issue.subject=Thema
    3.17  thead.issue.description=Beschreibung
    3.18  thead.issue.assignee=Zugewiesen
     4.1 --- a/src/main/webapp/WEB-INF/jsp/issue-form.jsp	Fri May 22 21:23:57 2020 +0200
     4.2 +++ b/src/main/webapp/WEB-INF/jsp/issue-form.jsp	Sat May 23 13:24:49 2020 +0200
     4.3 @@ -31,10 +31,10 @@
     4.4  
     4.5  <c:set scope="page" var="moduleInfo" value="${requestScope[Constants.REQ_ATTR_MODULE_INFO]}"/>
     4.6  
     4.7 +<jsp:useBean id="projects" type="java.util.List<de.uapcore.lightpit.entities.Project>" scope="request" />
     4.8  <jsp:useBean id="issue" type="de.uapcore.lightpit.entities.Issue" scope="request"/>
     4.9  <jsp:useBean id="issueStatusEnum" type="de.uapcore.lightpit.entities.IssueStatus[]" scope="request"/>
    4.10  <jsp:useBean id="issueCategoryEnum" type="de.uapcore.lightpit.entities.IssueCategory[]" scope="request"/>
    4.11 -<jsp:useBean id="versions" type="java.util.List<de.uapcore.lightpit.entities.Version>" scope="request"/>
    4.12  <jsp:useBean id="users" type="java.util.List<de.uapcore.lightpit.entities.User>" scope="request"/>
    4.13  
    4.14  <form action="./${moduleInfo.modulePath}/issues/commit" method="post">
    4.15 @@ -45,6 +45,18 @@
    4.16          </colgroup>
    4.17          <tbody>
    4.18          <tr>
    4.19 +            <th><fmt:message key="thead.issue.project"/></th>
    4.20 +            <td>
    4.21 +                <select name="pid" required>
    4.22 +                    <c:forEach var="project" items="${projects}">
    4.23 +                        <option value="${project.id}" <c:if test="${project eq issue.project}">selected</c:if> >
    4.24 +                            <c:out value="${project.name}" />
    4.25 +                        </option>
    4.26 +                    </c:forEach>
    4.27 +                </select>
    4.28 +            </td>
    4.29 +        </tr>
    4.30 +        <tr>
    4.31              <th><fmt:message key="thead.issue.category"/></th>
    4.32              <td>
    4.33                  <select name="category">
    4.34 @@ -151,7 +163,15 @@
    4.35          <tr>
    4.36              <td colspan="2">
    4.37                  <input type="hidden" name="id" value="${issue.id}"/>
    4.38 -                <a href="./${moduleInfo.modulePath}/view?pid=${issue.project.id}" class="button">
    4.39 +                <c:choose>
    4.40 +                    <c:when test="${not empty issue.project and issue.project.id ge 0}">
    4.41 +                        <c:set var="cancelUrl">./${moduleInfo.modulePath}/view?pid=${issue.project.id}</c:set>
    4.42 +                    </c:when>
    4.43 +                    <c:otherwise>
    4.44 +                        <c:set var="cancelUrl">./${moduleInfo.modulePath}/</c:set>
    4.45 +                    </c:otherwise>
    4.46 +                </c:choose>
    4.47 +                <a href="${cancelUrl}" class="button">
    4.48                      <fmt:message bundle="${lightpit_bundle}" key="button.cancel"/>
    4.49                  </a>
    4.50                  <button type="submit"><fmt:message bundle="${lightpit_bundle}" key="button.okay"/></button>
     5.1 --- a/src/main/webapp/WEB-INF/jsp/version-form.jsp	Fri May 22 21:23:57 2020 +0200
     5.2 +++ b/src/main/webapp/WEB-INF/jsp/version-form.jsp	Sat May 23 13:24:49 2020 +0200
     5.3 @@ -30,8 +30,8 @@
     5.4  <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
     5.5  
     5.6  <c:set scope="page" var="moduleInfo" value="${requestScope[Constants.REQ_ATTR_MODULE_INFO]}"/>
     5.7 -<c:set scope="page" var="selectedProject" value="${sessionScope[ProjectsModule.SESSION_ATTR_SELECTED_PROJECT]}"/>
     5.8  
     5.9 +<jsp:useBean id="projects" type="java.util.List<de.uapcore.lightpit.entities.Project>" scope="request" />
    5.10  <jsp:useBean id="version" type="de.uapcore.lightpit.entities.Version" scope="request"/>
    5.11  <jsp:useBean id="versionStatusEnum" type="de.uapcore.lightpit.entities.VersionStatus[]" scope="request"/>
    5.12  
    5.13 @@ -43,6 +43,18 @@
    5.14          </colgroup>
    5.15          <tbody>
    5.16          <tr>
    5.17 +            <th><fmt:message key="thead.version.project"/></th>
    5.18 +            <td>
    5.19 +                <select name="pid" required>
    5.20 +                    <c:forEach var="project" items="${projects}">
    5.21 +                        <option value="${project.id}" <c:if test="${project eq version.project}">selected</c:if> >
    5.22 +                            <c:out value="${project.name}" />
    5.23 +                        </option>
    5.24 +                    </c:forEach>
    5.25 +                </select>
    5.26 +            </td>
    5.27 +        </tr>
    5.28 +        <tr>
    5.29              <th><fmt:message key="thead.version.name"/></th>
    5.30              <td><input name="name" type="text" maxlength="20" required value="<c:out value="${version.name}"/>" /></td>
    5.31          </tr>
    5.32 @@ -69,7 +81,15 @@
    5.33          <tr>
    5.34              <td colspan="2">
    5.35                  <input type="hidden" name="id" value="${version.id}"/>
    5.36 -                <a href="./${moduleInfo.modulePath}/view?pid=${version.project.id}" class="button">
    5.37 +                <c:choose>
    5.38 +                    <c:when test="${not empty version.project and version.project.id ge 0}">
    5.39 +                        <c:set var="cancelUrl">./${moduleInfo.modulePath}/view?pid=${version.project.id}</c:set>
    5.40 +                    </c:when>
    5.41 +                    <c:otherwise>
    5.42 +                        <c:set var="cancelUrl">./${moduleInfo.modulePath}/</c:set>
    5.43 +                    </c:otherwise>
    5.44 +                </c:choose>
    5.45 +                <a href="${cancelUrl}" class="button">
    5.46                      <fmt:message bundle="${lightpit_bundle}" key="button.cancel"/>
    5.47                  </a>
    5.48                  <button type="submit"><fmt:message bundle="${lightpit_bundle}" key="button.okay"/></button>

mercurial