src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt

changeset 190
a83f1ab56898
parent 189
f7de8158b41c
child 203
7d5b16379768
     1.1 --- a/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt	Tue May 11 16:00:28 2021 +0200
     1.2 +++ b/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt	Tue May 11 17:30:36 2021 +0200
     1.3 @@ -129,7 +129,7 @@
     1.4              executeUpdate()
     1.5          }
     1.6      }
     1.7 -    //</editor-fold>
     1.8 +//</editor-fold>
     1.9  
    1.10      //<editor-fold desc="Version">
    1.11      //language=SQL
    1.12 @@ -153,10 +153,10 @@
    1.13          withStatement(
    1.14              """
    1.15              with version_map(issueid, versionid, isresolved) as (
    1.16 -                select issueid, versionid, 1
    1.17 +                select issueid, versionid, true
    1.18                  from lpit_issue_resolved_version
    1.19                  union
    1.20 -                select issueid, versionid, 0
    1.21 +                select issueid, versionid, false
    1.22                  from lpit_issue_affected_version
    1.23              ),
    1.24              issues as (
    1.25 @@ -170,30 +170,31 @@
    1.26                  select versionid, phase, isresolved, total
    1.27                  from lpit_version v
    1.28                  left join issues using (versionid)
    1.29 -                where v.project = ?
    1.30              )
    1.31 -            select versionid, project, name, node, ordinal, status, phase, isresolved, total
    1.32 -            from lpit_version
    1.33 -            join summary using (versionid)
    1.34 +            select v.versionid, project, name, node, ordinal, status,
    1.35 +                ro.total as resolved_open, ra.total as resolved_active, rd.total as resolved_done,
    1.36 +                ao.total as affected_open, aa.total as affected_active, ad.total as affected_done
    1.37 +            from lpit_version v
    1.38 +            left join summary ro on ro.versionid = v.versionid and ro.phase = 0 and ro.isresolved
    1.39 +            left join summary ra on ra.versionid = v.versionid and ra.phase = 1 and ra.isresolved
    1.40 +            left join summary rd on rd.versionid = v.versionid and rd.phase = 2 and rd.isresolved
    1.41 +            left join summary ao on ao.versionid = v.versionid and ao.phase = 0 and not ao.isresolved
    1.42 +            left join summary aa on aa.versionid = v.versionid and aa.phase = 1 and not aa.isresolved
    1.43 +            left join summary ad on ad.versionid = v.versionid and ad.phase = 2 and not ad.isresolved
    1.44 +            where v.project = ?
    1.45              order by ordinal, name
    1.46              """.trimIndent()
    1.47          ) {
    1.48              setInt(1, project.id)
    1.49 -            executeQuery().use { rs ->
    1.50 -                sequence {
    1.51 -                    // TODO: fix bug: this extractor is not grouping the results
    1.52 -                    val versionSummary = VersionSummary(rs.extractVersion())
    1.53 -                    val phase = rs.getInt("phase")
    1.54 -                    val total = rs.getInt("total")
    1.55 -                    val issueSummary =
    1.56 -                        if (rs.getBoolean("isresolved")) versionSummary.resolvedTotal else versionSummary.reportedTotal
    1.57 -                    when (phase) {
    1.58 -                        0 -> issueSummary.open = total
    1.59 -                        1 -> issueSummary.active = total
    1.60 -                        2 -> issueSummary.done = total
    1.61 -                    }
    1.62 -                    yield(versionSummary)
    1.63 -                }.toList()
    1.64 +            queryAll { rs ->
    1.65 +                VersionSummary(rs.extractVersion()).apply {
    1.66 +                    reportedTotal.open = rs.getInt("affected_open")
    1.67 +                    reportedTotal.active = rs.getInt("affected_active")
    1.68 +                    reportedTotal.done = rs.getInt("affected_done")
    1.69 +                    resolvedTotal.open = rs.getInt("resolved_open")
    1.70 +                    resolvedTotal.active = rs.getInt("resolved_active")
    1.71 +                    resolvedTotal.done = rs.getInt("resolved_done")
    1.72 +                }
    1.73              }
    1.74          }
    1.75  
    1.76 @@ -236,7 +237,7 @@
    1.77              executeUpdate()
    1.78          }
    1.79      }
    1.80 -    //</editor-fold>
    1.81 +//</editor-fold>
    1.82  
    1.83      //<editor-fold desc="Component">
    1.84      //language=SQL
    1.85 @@ -294,31 +295,26 @@
    1.86                  select c.id, phase, total
    1.87                  from lpit_component c
    1.88                  left join issues i on c.id = i.component 
    1.89 -                where c.project = ?
    1.90              )
    1.91              select c.id, project, name, node, color, ordinal, description,
    1.92 -                userid, username, givenname, lastname, mail, phase, total
    1.93 +                userid, username, givenname, lastname, mail,
    1.94 +                open.total as open, active.total as active, done.total as done
    1.95              from lpit_component c
    1.96              left join lpit_user on lead = userid
    1.97 -            join summary s on c.id = s.id
    1.98 +            left join summary open on c.id = open.id and open.phase = 0
    1.99 +            left join summary active on c.id = active.id and active.phase = 1
   1.100 +            left join summary done on c.id = done.id and done.phase = 2
   1.101 +            where c.project = ?
   1.102              order by ordinal, name
   1.103              """.trimIndent()
   1.104          ) {
   1.105              setInt(1, project.id)
   1.106 -            executeQuery().use { rs ->
   1.107 -                // TODO: fix bug: this extractor is not grouping the results
   1.108 -                sequence {
   1.109 -                    val componentSummary = ComponentSummary(rs.extractComponent()).also {
   1.110 -                        val phase = rs.getInt("phase")
   1.111 -                        val total = rs.getInt("total")
   1.112 -                        when (phase) {
   1.113 -                            0 -> it.issueSummary.open = total
   1.114 -                            1 -> it.issueSummary.active = total
   1.115 -                            2 -> it.issueSummary.done = total
   1.116 -                        }
   1.117 -                    }
   1.118 -                    yield(componentSummary)
   1.119 -                }.toList()
   1.120 +            queryAll { rs ->
   1.121 +                ComponentSummary(rs.extractComponent()).apply {
   1.122 +                    issueSummary.open = rs.getInt("open")
   1.123 +                    issueSummary.active = rs.getInt("active")
   1.124 +                    issueSummary.done = rs.getInt("done")
   1.125 +                }
   1.126              }
   1.127          }
   1.128  

mercurial