Sat, 04 Jun 2022 18:02:25 +0200
simplify listIssues() interface
--- a/src/main/kotlin/de/uapcore/lightpit/dao/DataAccessObject.kt Wed Dec 15 19:56:05 2021 +0100 +++ b/src/main/kotlin/de/uapcore/lightpit/dao/DataAccessObject.kt Sat Jun 04 18:02:25 2022 +0200 @@ -26,12 +26,12 @@ package de.uapcore.lightpit.dao import de.uapcore.lightpit.entities.* -import de.uapcore.lightpit.util.IssueFilter import de.uapcore.lightpit.viewmodel.ComponentSummary import de.uapcore.lightpit.viewmodel.IssueSummary import de.uapcore.lightpit.viewmodel.VersionSummary interface DataAccessObject { + fun listUsers(): List<User> fun findUser(id: Int): User? fun findUserByName(username: String): User? @@ -69,7 +69,7 @@ fun collectIssueSummary(project: Project): IssueSummary - fun listIssues(filter: IssueFilter): List<Issue> + fun listIssues(project: Project, version: Version?, component: Component?): List<Issue> fun findIssue(id: Int): Issue? fun insertIssue(issue: Issue): Int fun updateIssue(issue: Issue)
--- a/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt Wed Dec 15 19:56:05 2021 +0100 +++ b/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt Sat Jun 04 18:02:25 2022 +0200 @@ -28,7 +28,6 @@ import de.uapcore.lightpit.entities.* import de.uapcore.lightpit.types.IssueHistoryType import de.uapcore.lightpit.types.WebColor -import de.uapcore.lightpit.util.* import de.uapcore.lightpit.viewmodel.ComponentSummary import de.uapcore.lightpit.viewmodel.IssueSummary import de.uapcore.lightpit.viewmodel.VersionSummary @@ -509,7 +508,7 @@ return i } - override fun listIssues(filter: IssueFilter): List<Issue> = + override fun listIssues(project: Project, version: Version?, component: Component?): List<Issue> = withStatement( """$issueQuery where (not ? or i.project = ?) and @@ -517,41 +516,21 @@ (not ? or component = ?) and (not ? or component is null) """.trimIndent() ) { - fun <T : Entity> applyFilter(filter: Filter<T>, fflag: Int, nflag: Int, idcol: Int) { - when (filter) { - is AllFilter -> { - setBoolean(fflag, false) - setBoolean(nflag, false) - setInt(idcol, 0) - } - is NoneFilter -> { - setBoolean(fflag, false) - setBoolean(nflag, true) - setInt(idcol, 0) - } - is SpecificFilter -> { - setBoolean(fflag, true) - setBoolean(nflag, false) - setInt(idcol, filter.obj.id) - } - else -> { - TODO("Implement range filter.") - } + fun <T : Entity> applyFilter(search: T?, fflag: Int, nflag: Int, idcol: Int) { + if (search == null) { + setBoolean(fflag, false) + setBoolean(nflag, false) + setInt(idcol, 0) + } else { + setBoolean(fflag, true) + setBoolean(nflag, false) + setInt(idcol, search.id) } } - when (filter.project) { - is AllFilter -> { - setBoolean(1, false) - setInt(2, 0) - } - is SpecificFilter -> { - setBoolean(1, true) - setInt(2, filter.project.obj.id) - } - else -> throw IllegalArgumentException() - } - applyFilter(filter.version, 3, 5, 4) - applyFilter(filter.component, 6, 8, 7) + setBoolean(1, true) + setInt(2, project.id) + applyFilter(version, 3, 5, 4) + applyFilter(component, 6, 8, 7) queryAll { it.extractIssue() } }
--- a/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt Wed Dec 15 19:56:05 2021 +0100 +++ b/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt Sat Jun 04 18:02:25 2022 +0200 @@ -35,10 +35,7 @@ import de.uapcore.lightpit.types.IssueStatus import de.uapcore.lightpit.types.VersionStatus import de.uapcore.lightpit.types.WebColor -import de.uapcore.lightpit.util.AllFilter -import de.uapcore.lightpit.util.IssueFilter import de.uapcore.lightpit.util.IssueSorter.Companion.DEFAULT_ISSUE_SORTER -import de.uapcore.lightpit.util.SpecificFilter import de.uapcore.lightpit.viewmodel.* import java.sql.Date import javax.servlet.annotation.WebServlet @@ -189,11 +186,8 @@ private fun project(http: HttpRequest, dao: DataAccessObject) { withPathInfo(http, dao)?.run { - val issues = dao.listIssues(IssueFilter( - project = SpecificFilter(project), - version = version?.let { SpecificFilter(it) } ?: AllFilter(), - component = component?.let { SpecificFilter(it) } ?: AllFilter() - )).sortedWith(DEFAULT_ISSUE_SORTER) + val issues = dao.listIssues(project, version, component) + .sortedWith(DEFAULT_ISSUE_SORTER) with(http) { pageTitle = project.name
--- a/src/main/kotlin/de/uapcore/lightpit/util/Filter.kt Wed Dec 15 19:56:05 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * Copyright 2021 Mike Becker. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package de.uapcore.lightpit.util - -sealed class Filter<T> -class AllFilter<T> : Filter<T>() -class NoneFilter<T> : Filter<T>() -data class SpecificFilter<T>(val obj: T) : Filter<T>() -data class RangeFilter<T>(val lower: T, val upper: T) : Filter<T>() where T : Comparable<T>
--- a/src/main/kotlin/de/uapcore/lightpit/util/Issues.kt Wed Dec 15 19:56:05 2021 +0100 +++ b/src/main/kotlin/de/uapcore/lightpit/util/Issues.kt Sat Jun 04 18:02:25 2022 +0200 @@ -25,18 +25,9 @@ package de.uapcore.lightpit.util -import de.uapcore.lightpit.entities.Component import de.uapcore.lightpit.entities.Issue -import de.uapcore.lightpit.entities.Project -import de.uapcore.lightpit.entities.Version import de.uapcore.lightpit.types.IssueStatusPhase -data class IssueFilter( - val project: Filter<Project> = AllFilter(), - val version: Filter<Version> = AllFilter(), - val component: Filter<Component> = AllFilter() -) - data class IssueSorter(val criteria: List<Criteria>) : Comparator<Issue> { enum class Field { DONE, ETA, UPDATED