27 * |
27 * |
28 */ |
28 */ |
29 package de.uapcore.lightpit.dao.postgres; |
29 package de.uapcore.lightpit.dao.postgres; |
30 |
30 |
31 import de.uapcore.lightpit.dao.ProjectDao; |
31 import de.uapcore.lightpit.dao.ProjectDao; |
|
32 import de.uapcore.lightpit.entities.IssueSummary; |
32 import de.uapcore.lightpit.entities.Project; |
33 import de.uapcore.lightpit.entities.Project; |
33 import de.uapcore.lightpit.entities.User; |
34 import de.uapcore.lightpit.entities.User; |
34 |
35 |
35 import java.sql.Connection; |
36 import java.sql.Connection; |
36 import java.sql.PreparedStatement; |
37 import java.sql.PreparedStatement; |
96 } |
97 } |
97 |
98 |
98 return proj; |
99 return proj; |
99 } |
100 } |
100 |
101 |
101 private void mapIssueSummary(Project proj) throws SQLException { |
102 public IssueSummary getIssueSummary(Project project) throws SQLException { |
102 issue_summary.setInt(1, proj.getId()); |
103 issue_summary.setInt(1, project.getId()); |
103 final var result = issue_summary.executeQuery(); |
104 final var result = issue_summary.executeQuery(); |
|
105 final var summary = new IssueSummary(); |
104 while (result.next()) { |
106 while (result.next()) { |
105 final var phase = result.getInt("phase"); |
107 final var phase = result.getInt("phase"); |
106 final var total = result.getInt("total"); |
108 final var total = result.getInt("total"); |
107 switch(phase) { |
109 switch(phase) { |
108 case 0: |
110 case 0: |
109 proj.setOpenIssues(total); |
111 summary.setOpen(total); |
110 break; |
112 break; |
111 case 1: |
113 case 1: |
112 proj.setActiveIssues(total); |
114 summary.setActive(total); |
113 break; |
115 break; |
114 case 2: |
116 case 2: |
115 proj.setDoneIssues(total); |
117 summary.setDone(total); |
116 break; |
118 break; |
117 } |
119 } |
118 } |
120 } |
|
121 return summary; |
119 } |
122 } |
120 |
123 |
121 @Override |
124 @Override |
122 public void save(Project instance) throws SQLException { |
125 public void save(Project instance) throws SQLException { |
123 Objects.requireNonNull(instance.getName()); |
126 Objects.requireNonNull(instance.getName()); |
144 public List<Project> list() throws SQLException { |
147 public List<Project> list() throws SQLException { |
145 List<Project> projects = new ArrayList<>(); |
148 List<Project> projects = new ArrayList<>(); |
146 try (var result = list.executeQuery()) { |
149 try (var result = list.executeQuery()) { |
147 while (result.next()) { |
150 while (result.next()) { |
148 final var project = mapColumns(result); |
151 final var project = mapColumns(result); |
149 mapIssueSummary(project); |
|
150 projects.add(project); |
152 projects.add(project); |
151 } |
153 } |
152 } |
154 } |
153 return projects; |
155 return projects; |
154 } |
156 } |