Sat, 04 Jun 2022 18:29:58 +0200
move IssueSorter to viewmodel package
1.1 --- a/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt Sat Jun 04 18:02:25 2022 +0200 1.2 +++ b/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt Sat Jun 04 18:29:58 2022 +0200 1.3 @@ -35,7 +35,6 @@ 1.4 import de.uapcore.lightpit.types.IssueStatus 1.5 import de.uapcore.lightpit.types.VersionStatus 1.6 import de.uapcore.lightpit.types.WebColor 1.7 -import de.uapcore.lightpit.util.IssueSorter.Companion.DEFAULT_ISSUE_SORTER 1.8 import de.uapcore.lightpit.viewmodel.* 1.9 import java.sql.Date 1.10 import javax.servlet.annotation.WebServlet 1.11 @@ -187,7 +186,13 @@ 1.12 withPathInfo(http, dao)?.run { 1.13 1.14 val issues = dao.listIssues(project, version, component) 1.15 - .sortedWith(DEFAULT_ISSUE_SORTER) 1.16 + .sortedWith( 1.17 + IssueSorter( 1.18 + IssueSorter.Criteria(IssueSorter.Field.DONE), 1.19 + IssueSorter.Criteria(IssueSorter.Field.ETA), 1.20 + IssueSorter.Criteria(IssueSorter.Field.UPDATED, false) 1.21 + ) 1.22 + ) 1.23 1.24 with(http) { 1.25 pageTitle = project.name 1.26 @@ -304,7 +309,7 @@ 1.27 } 1.28 } 1.29 1.30 - private fun obtainIdAndProject(http: HttpRequest, dao:DataAccessObject): Pair<Int, Project>? { 1.31 + private fun obtainIdAndProject(http: HttpRequest, dao: DataAccessObject): Pair<Int, Project>? { 1.32 val id = http.param("id")?.toIntOrNull() 1.33 val projectid = http.param("projectid")?.toIntOrNull() ?: -1 1.34 val project = dao.findProject(projectid) 1.35 @@ -326,8 +331,8 @@ 1.36 ordinal = http.param("ordinal")?.toIntOrNull() ?: 0 1.37 status = http.param("status")?.let(VersionStatus::valueOf) ?: VersionStatus.Future 1.38 // TODO: process error messages 1.39 - eol = http.param("eol", ::dateOptValidator, null, mutableListOf()) 1.40 - release = http.param("release", ::dateOptValidator, null, mutableListOf()) 1.41 + eol = http.param("eol", ::dateOptValidator, null, mutableListOf()) 1.42 + release = http.param("release", ::dateOptValidator, null, mutableListOf()) 1.43 // intentional defaults 1.44 if (node.isBlank()) node = name 1.45 // sanitizing
2.1 --- a/src/main/kotlin/de/uapcore/lightpit/util/Issues.kt Sat Jun 04 18:02:25 2022 +0200 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,70 +0,0 @@ 2.4 -/* 2.5 - * Copyright 2021 Mike Becker. All rights reserved. 2.6 - * 2.7 - * Redistribution and use in source and binary forms, with or without 2.8 - * modification, are permitted provided that the following conditions are met: 2.9 - * 2.10 - * 1. Redistributions of source code must retain the above copyright 2.11 - * notice, this list of conditions and the following disclaimer. 2.12 - * 2.13 - * 2. Redistributions in binary form must reproduce the above copyright 2.14 - * notice, this list of conditions and the following disclaimer in the 2.15 - * documentation and/or other materials provided with the distribution. 2.16 - * 2.17 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2.18 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2.19 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 2.20 - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 2.21 - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2.22 - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 2.23 - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 2.24 - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2.25 - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2.26 - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2.27 - */ 2.28 - 2.29 -package de.uapcore.lightpit.util 2.30 - 2.31 -import de.uapcore.lightpit.entities.Issue 2.32 -import de.uapcore.lightpit.types.IssueStatusPhase 2.33 - 2.34 -data class IssueSorter(val criteria: List<Criteria>) : Comparator<Issue> { 2.35 - enum class Field { 2.36 - DONE, ETA, UPDATED 2.37 - } 2.38 - 2.39 - data class Criteria(val field: Field, val asc: Boolean = true) 2.40 - 2.41 - companion object { 2.42 - val DEFAULT_ISSUE_SORTER = IssueSorter(listOf( 2.43 - Criteria(Field.DONE), 2.44 - Criteria(Field.ETA), 2.45 - Criteria(Field.UPDATED, false) 2.46 - )) 2.47 - } 2.48 - 2.49 - override fun compare(left: Issue, right: Issue): Int { 2.50 - if (left == right) { 2.51 - return 0; 2.52 - } 2.53 - for (c in criteria) { 2.54 - val result = when (c.field) { 2.55 - Field.DONE -> (left.status.phase == IssueStatusPhase.Done).compareTo(right.status.phase == IssueStatusPhase.Done) 2.56 - Field.ETA -> { 2.57 - val l = left.eta 2.58 - val r = right.eta 2.59 - if (l == null && r == null) 0 2.60 - else if (l == null) 1 2.61 - else if (r == null) -1 2.62 - else l.compareTo(r) 2.63 - } 2.64 - Field.UPDATED -> left.updated.compareTo(right.updated) 2.65 - } 2.66 - if (result != 0) { 2.67 - return if (c.asc) result else -result 2.68 - } 2.69 - } 2.70 - return 0 2.71 - } 2.72 -} 2.73 -
3.1 --- a/src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt Sat Jun 04 18:02:25 2022 +0200 3.2 +++ b/src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt Sat Jun 04 18:29:58 2022 +0200 3.3 @@ -38,6 +38,38 @@ 3.4 import de.uapcore.lightpit.types.VersionStatus 3.5 import kotlin.math.roundToInt 3.6 3.7 +class IssueSorter(private vararg val criteria: Criteria) : Comparator<Issue> { 3.8 + enum class Field { 3.9 + DONE, ETA, UPDATED 3.10 + } 3.11 + 3.12 + data class Criteria(val field: Field, val asc: Boolean = true) 3.13 + 3.14 + override fun compare(left: Issue, right: Issue): Int { 3.15 + if (left == right) { 3.16 + return 0; 3.17 + } 3.18 + for (c in criteria) { 3.19 + val result = when (c.field) { 3.20 + Field.DONE -> (left.status.phase == IssueStatusPhase.Done).compareTo(right.status.phase == IssueStatusPhase.Done) 3.21 + Field.ETA -> { 3.22 + val l = left.eta 3.23 + val r = right.eta 3.24 + if (l == null && r == null) 0 3.25 + else if (l == null) 1 3.26 + else if (r == null) -1 3.27 + else l.compareTo(r) 3.28 + } 3.29 + Field.UPDATED -> left.updated.compareTo(right.updated) 3.30 + } 3.31 + if (result != 0) { 3.32 + return if (c.asc) result else -result 3.33 + } 3.34 + } 3.35 + return 0 3.36 + } 3.37 +} 3.38 + 3.39 class IssueSummary { 3.40 var open = 0 3.41 var active = 0