# HG changeset patch # User Mike Becker # Date 1620747036 -7200 # Node ID a83f1ab568980b24d638e07b4066729ffc4ac4fa # Parent f7de8158b41c7ded644be543fcaba7c410960bd4 fixes #138 - ResultSet processing for summaries diff -r f7de8158b41c -r a83f1ab56898 build.gradle.kts --- a/build.gradle.kts Tue May 11 16:00:28 2021 +0200 +++ b/build.gradle.kts Tue May 11 17:30:36 2021 +0200 @@ -5,7 +5,7 @@ war } group = "de.uapcore" -version = "0.5-SNAPSHOT" +version = "0.6-SNAPSHOT" val log4jVersion = "2.13.1" val slf4jVersion = "1.7.30" diff -r f7de8158b41c -r a83f1ab56898 src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt --- a/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt Tue May 11 16:00:28 2021 +0200 +++ b/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt Tue May 11 17:30:36 2021 +0200 @@ -129,7 +129,7 @@ executeUpdate() } } - // +// // //language=SQL @@ -153,10 +153,10 @@ withStatement( """ with version_map(issueid, versionid, isresolved) as ( - select issueid, versionid, 1 + select issueid, versionid, true from lpit_issue_resolved_version union - select issueid, versionid, 0 + select issueid, versionid, false from lpit_issue_affected_version ), issues as ( @@ -170,30 +170,31 @@ select versionid, phase, isresolved, total from lpit_version v left join issues using (versionid) - where v.project = ? ) - select versionid, project, name, node, ordinal, status, phase, isresolved, total - from lpit_version - join summary using (versionid) + select v.versionid, project, name, node, ordinal, status, + ro.total as resolved_open, ra.total as resolved_active, rd.total as resolved_done, + ao.total as affected_open, aa.total as affected_active, ad.total as affected_done + from lpit_version v + left join summary ro on ro.versionid = v.versionid and ro.phase = 0 and ro.isresolved + left join summary ra on ra.versionid = v.versionid and ra.phase = 1 and ra.isresolved + left join summary rd on rd.versionid = v.versionid and rd.phase = 2 and rd.isresolved + left join summary ao on ao.versionid = v.versionid and ao.phase = 0 and not ao.isresolved + left join summary aa on aa.versionid = v.versionid and aa.phase = 1 and not aa.isresolved + left join summary ad on ad.versionid = v.versionid and ad.phase = 2 and not ad.isresolved + where v.project = ? order by ordinal, name """.trimIndent() ) { setInt(1, project.id) - executeQuery().use { rs -> - sequence { - // TODO: fix bug: this extractor is not grouping the results - val versionSummary = VersionSummary(rs.extractVersion()) - val phase = rs.getInt("phase") - val total = rs.getInt("total") - val issueSummary = - if (rs.getBoolean("isresolved")) versionSummary.resolvedTotal else versionSummary.reportedTotal - when (phase) { - 0 -> issueSummary.open = total - 1 -> issueSummary.active = total - 2 -> issueSummary.done = total - } - yield(versionSummary) - }.toList() + queryAll { rs -> + VersionSummary(rs.extractVersion()).apply { + reportedTotal.open = rs.getInt("affected_open") + reportedTotal.active = rs.getInt("affected_active") + reportedTotal.done = rs.getInt("affected_done") + resolvedTotal.open = rs.getInt("resolved_open") + resolvedTotal.active = rs.getInt("resolved_active") + resolvedTotal.done = rs.getInt("resolved_done") + } } } @@ -236,7 +237,7 @@ executeUpdate() } } - // +// // //language=SQL @@ -294,31 +295,26 @@ select c.id, phase, total from lpit_component c left join issues i on c.id = i.component - where c.project = ? ) select c.id, project, name, node, color, ordinal, description, - userid, username, givenname, lastname, mail, phase, total + userid, username, givenname, lastname, mail, + open.total as open, active.total as active, done.total as done from lpit_component c left join lpit_user on lead = userid - join summary s on c.id = s.id + left join summary open on c.id = open.id and open.phase = 0 + left join summary active on c.id = active.id and active.phase = 1 + left join summary done on c.id = done.id and done.phase = 2 + where c.project = ? order by ordinal, name """.trimIndent() ) { setInt(1, project.id) - executeQuery().use { rs -> - // TODO: fix bug: this extractor is not grouping the results - sequence { - val componentSummary = ComponentSummary(rs.extractComponent()).also { - val phase = rs.getInt("phase") - val total = rs.getInt("total") - when (phase) { - 0 -> it.issueSummary.open = total - 1 -> it.issueSummary.active = total - 2 -> it.issueSummary.done = total - } - } - yield(componentSummary) - }.toList() + queryAll { rs -> + ComponentSummary(rs.extractComponent()).apply { + issueSummary.open = rs.getInt("open") + issueSummary.active = rs.getInt("active") + issueSummary.done = rs.getInt("done") + } } }