fixes #138 - ResultSet processing for summaries

Tue, 11 May 2021 17:30:36 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 11 May 2021 17:30:36 +0200
changeset 190
a83f1ab56898
parent 189
f7de8158b41c
child 191
193ee4828767

fixes #138 - ResultSet processing for summaries

build.gradle.kts file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt file | annotate | diff | comparison | revisions
     1.1 --- a/build.gradle.kts	Tue May 11 16:00:28 2021 +0200
     1.2 +++ b/build.gradle.kts	Tue May 11 17:30:36 2021 +0200
     1.3 @@ -5,7 +5,7 @@
     1.4      war
     1.5  }
     1.6  group = "de.uapcore"
     1.7 -version = "0.5-SNAPSHOT"
     1.8 +version = "0.6-SNAPSHOT"
     1.9  
    1.10  val log4jVersion = "2.13.1"
    1.11  val slf4jVersion = "1.7.30"
     2.1 --- a/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt	Tue May 11 16:00:28 2021 +0200
     2.2 +++ b/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt	Tue May 11 17:30:36 2021 +0200
     2.3 @@ -129,7 +129,7 @@
     2.4              executeUpdate()
     2.5          }
     2.6      }
     2.7 -    //</editor-fold>
     2.8 +//</editor-fold>
     2.9  
    2.10      //<editor-fold desc="Version">
    2.11      //language=SQL
    2.12 @@ -153,10 +153,10 @@
    2.13          withStatement(
    2.14              """
    2.15              with version_map(issueid, versionid, isresolved) as (
    2.16 -                select issueid, versionid, 1
    2.17 +                select issueid, versionid, true
    2.18                  from lpit_issue_resolved_version
    2.19                  union
    2.20 -                select issueid, versionid, 0
    2.21 +                select issueid, versionid, false
    2.22                  from lpit_issue_affected_version
    2.23              ),
    2.24              issues as (
    2.25 @@ -170,30 +170,31 @@
    2.26                  select versionid, phase, isresolved, total
    2.27                  from lpit_version v
    2.28                  left join issues using (versionid)
    2.29 -                where v.project = ?
    2.30              )
    2.31 -            select versionid, project, name, node, ordinal, status, phase, isresolved, total
    2.32 -            from lpit_version
    2.33 -            join summary using (versionid)
    2.34 +            select v.versionid, project, name, node, ordinal, status,
    2.35 +                ro.total as resolved_open, ra.total as resolved_active, rd.total as resolved_done,
    2.36 +                ao.total as affected_open, aa.total as affected_active, ad.total as affected_done
    2.37 +            from lpit_version v
    2.38 +            left join summary ro on ro.versionid = v.versionid and ro.phase = 0 and ro.isresolved
    2.39 +            left join summary ra on ra.versionid = v.versionid and ra.phase = 1 and ra.isresolved
    2.40 +            left join summary rd on rd.versionid = v.versionid and rd.phase = 2 and rd.isresolved
    2.41 +            left join summary ao on ao.versionid = v.versionid and ao.phase = 0 and not ao.isresolved
    2.42 +            left join summary aa on aa.versionid = v.versionid and aa.phase = 1 and not aa.isresolved
    2.43 +            left join summary ad on ad.versionid = v.versionid and ad.phase = 2 and not ad.isresolved
    2.44 +            where v.project = ?
    2.45              order by ordinal, name
    2.46              """.trimIndent()
    2.47          ) {
    2.48              setInt(1, project.id)
    2.49 -            executeQuery().use { rs ->
    2.50 -                sequence {
    2.51 -                    // TODO: fix bug: this extractor is not grouping the results
    2.52 -                    val versionSummary = VersionSummary(rs.extractVersion())
    2.53 -                    val phase = rs.getInt("phase")
    2.54 -                    val total = rs.getInt("total")
    2.55 -                    val issueSummary =
    2.56 -                        if (rs.getBoolean("isresolved")) versionSummary.resolvedTotal else versionSummary.reportedTotal
    2.57 -                    when (phase) {
    2.58 -                        0 -> issueSummary.open = total
    2.59 -                        1 -> issueSummary.active = total
    2.60 -                        2 -> issueSummary.done = total
    2.61 -                    }
    2.62 -                    yield(versionSummary)
    2.63 -                }.toList()
    2.64 +            queryAll { rs ->
    2.65 +                VersionSummary(rs.extractVersion()).apply {
    2.66 +                    reportedTotal.open = rs.getInt("affected_open")
    2.67 +                    reportedTotal.active = rs.getInt("affected_active")
    2.68 +                    reportedTotal.done = rs.getInt("affected_done")
    2.69 +                    resolvedTotal.open = rs.getInt("resolved_open")
    2.70 +                    resolvedTotal.active = rs.getInt("resolved_active")
    2.71 +                    resolvedTotal.done = rs.getInt("resolved_done")
    2.72 +                }
    2.73              }
    2.74          }
    2.75  
    2.76 @@ -236,7 +237,7 @@
    2.77              executeUpdate()
    2.78          }
    2.79      }
    2.80 -    //</editor-fold>
    2.81 +//</editor-fold>
    2.82  
    2.83      //<editor-fold desc="Component">
    2.84      //language=SQL
    2.85 @@ -294,31 +295,26 @@
    2.86                  select c.id, phase, total
    2.87                  from lpit_component c
    2.88                  left join issues i on c.id = i.component 
    2.89 -                where c.project = ?
    2.90              )
    2.91              select c.id, project, name, node, color, ordinal, description,
    2.92 -                userid, username, givenname, lastname, mail, phase, total
    2.93 +                userid, username, givenname, lastname, mail,
    2.94 +                open.total as open, active.total as active, done.total as done
    2.95              from lpit_component c
    2.96              left join lpit_user on lead = userid
    2.97 -            join summary s on c.id = s.id
    2.98 +            left join summary open on c.id = open.id and open.phase = 0
    2.99 +            left join summary active on c.id = active.id and active.phase = 1
   2.100 +            left join summary done on c.id = done.id and done.phase = 2
   2.101 +            where c.project = ?
   2.102              order by ordinal, name
   2.103              """.trimIndent()
   2.104          ) {
   2.105              setInt(1, project.id)
   2.106 -            executeQuery().use { rs ->
   2.107 -                // TODO: fix bug: this extractor is not grouping the results
   2.108 -                sequence {
   2.109 -                    val componentSummary = ComponentSummary(rs.extractComponent()).also {
   2.110 -                        val phase = rs.getInt("phase")
   2.111 -                        val total = rs.getInt("total")
   2.112 -                        when (phase) {
   2.113 -                            0 -> it.issueSummary.open = total
   2.114 -                            1 -> it.issueSummary.active = total
   2.115 -                            2 -> it.issueSummary.done = total
   2.116 -                        }
   2.117 -                    }
   2.118 -                    yield(componentSummary)
   2.119 -                }.toList()
   2.120 +            queryAll { rs ->
   2.121 +                ComponentSummary(rs.extractComponent()).apply {
   2.122 +                    issueSummary.open = rs.getInt("open")
   2.123 +                    issueSummary.active = rs.getInt("active")
   2.124 +                    issueSummary.done = rs.getInt("done")
   2.125 +                }
   2.126              }
   2.127          }
   2.128  

mercurial