automatic assignment of component lead (if available) - fixes #28

Thu, 22 Oct 2020 11:06:15 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 22 Oct 2020 11:06:15 +0200
changeset 136
7281bdf43c60
parent 135
bafc315294fd
child 137
a7e543ab0c5f

automatic assignment of component lead (if available) - fixes #28

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
--- a/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java	Sat Oct 17 20:06:14 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java	Thu Oct 22 11:06:15 2020 +0200
@@ -46,6 +46,7 @@
 import java.sql.SQLException;
 import java.util.List;
 import java.util.NoSuchElementException;
+import java.util.Optional;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -453,16 +454,28 @@
     public ResponseType commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException {
         try {
             final var issue = new Issue(getParameter(req, Integer.class, "id").orElseThrow());
+            final var componentId = getParameter(req, Integer.class, "component");
+            final Component component;
+            if (componentId.isPresent()) {
+                component = dao.getComponentDao().find(componentId.get());
+            } else {
+                component = null;
+            }
             issue.setProject(new Project(getParameter(req, Integer.class, "pid").orElseThrow()));
             getParameter(req, String.class, "category").map(IssueCategory::valueOf).ifPresent(issue::setCategory);
             getParameter(req, String.class, "status").map(IssueStatus::valueOf).ifPresent(issue::setStatus);
             issue.setSubject(getParameter(req, String.class, "subject").orElseThrow());
-            getParameter(req, Integer.class, "assignee").map(
-                    userid -> userid >= 0 ? new User(userid) : null
+            issue.setComponent(component);
+            getParameter(req, Integer.class, "assignee").map(userid -> {
+                if (userid >= 0) {
+                    return new User(userid);
+                } else if (userid == -2) {
+                    return Optional.ofNullable(component).map(Component::getLead).orElse(null);
+                } else {
+                    return null;
+                }
+            }
             ).ifPresent(issue::setAssignee);
-            getParameter(req, Integer.class, "component").map(
-                    cid -> cid >= 0 ? new Component(cid) : null
-            ).ifPresent(issue::setComponent);
             getParameter(req, String.class, "description").ifPresent(issue::setDescription);
             getParameter(req, Date.class, "eta").ifPresent(issue::setEta);
 
--- a/src/main/resources/localization/projects.properties	Sat Oct 17 20:06:14 2020 +0200
+++ b/src/main/resources/localization/projects.properties	Thu Oct 22 11:06:15 2020 +0200
@@ -73,6 +73,8 @@
 placeholder.null-owner=Unassigned
 placeholder.null-lead=Unassigned
 placeholder.null-assignee=Unassigned
+placeholder.auto-assignee=Automatic
+placeholder.auto-assignee.tooltip=Assigns the component lead, if available.
 placeholder.null-component=Unassigned
 
 version.status.Future=Future
--- a/src/main/resources/localization/projects_de.properties	Sat Oct 17 20:06:14 2020 +0200
+++ b/src/main/resources/localization/projects_de.properties	Thu Oct 22 11:06:15 2020 +0200
@@ -73,6 +73,8 @@
 placeholder.null-owner=Nicht Zugewiesen
 placeholder.null-lead=Niemand
 placeholder.null-assignee=Niemandem
+placeholder.auto-assignee=Automatisch
+placeholder.auto-assignee.tooltip=Weist, wenn m\u00f6glich, den Vorgang dem Leiter der Komponente.
 placeholder.null-component=Keine
 
 version.status.Future=Geplant
--- a/src/main/webapp/WEB-INF/jsp/issue-form.jsp	Sat Oct 17 20:06:14 2020 +0200
+++ b/src/main/webapp/WEB-INF/jsp/issue-form.jsp	Thu Oct 22 11:06:15 2020 +0200
@@ -128,7 +128,10 @@
             <th><fmt:message key="issue.assignee"/></th>
             <td>
                 <select name="assignee">
-                    <option value="-1"><fmt:message key="placeholder.null-assignee"/></option>
+                    <option value="-2" title="<fmt:message key="placeholder.auto-assignee.tooltip"/>"><fmt:message key="placeholder.auto-assignee"/></option>
+                    <option value="-1"
+                            <c:if test="${issue.id ge 0 and empty issue.assignee}">selected</c:if>
+                    ><fmt:message key="placeholder.null-assignee"/></option>
                     <c:forEach var="user" items="${viewmodel.users}">
                         <option
                                 <c:if test="${not empty issue.assignee and user eq issue.assignee}">selected</c:if>

mercurial