|
7 | 7 | import java.net.http.*; |
8 | 8 | import java.nio.charset.StandardCharsets; |
9 | 9 | import java.util.ArrayList; |
| 10 | +import java.util.HashMap; |
10 | 11 | import java.util.List; |
| 12 | +import java.util.Map; |
11 | 13 |
|
12 | 14 | public class TaigaClient { |
13 | 15 |
|
@@ -131,6 +133,52 @@ public List<TaigaUserStory> getStoriesBySprint(long sprintId) throws Exception { |
131 | 133 | } |
132 | 134 |
|
133 | 135 |
|
| 136 | + |
| 137 | + public TaigaUser getUserById(long userId) throws Exception { |
| 138 | + JsonNode u = getJson("/api/v1/users/" + userId); |
| 139 | + |
| 140 | + String fullName = |
| 141 | + !u.path("full_name_display").asText("").isBlank() |
| 142 | + ? u.path("full_name_display").asText("") |
| 143 | + : u.path("full_name").asText(""); |
| 144 | + |
| 145 | + return new TaigaUser( |
| 146 | + u.path("id").asLong(), |
| 147 | + u.path("username").asText(""), |
| 148 | + fullName, |
| 149 | + u.path("email").asText("") |
| 150 | + ); |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * Retrieve task statuses for a project. |
| 155 | + * These ids are project-specific, so use this mapping to convert status ids to names. |
| 156 | + */ |
| 157 | + public List<TaigaStatus> getTaskStatuses(long projectId) throws Exception { |
| 158 | + JsonNode arr = getJson("/api/v1/task-statuses?project=" + projectId); |
| 159 | + |
| 160 | + List<TaigaStatus> out = new ArrayList<>(); |
| 161 | + for (JsonNode s : arr) { |
| 162 | + out.add(new TaigaStatus( |
| 163 | + s.path("id").asLong(), |
| 164 | + s.path("name").asText(""), |
| 165 | + s.path("slug").asText(""), |
| 166 | + s.path("color").asText(""), |
| 167 | + s.path("order").asInt() |
| 168 | + )); |
| 169 | + } |
| 170 | + return out; |
| 171 | + } |
| 172 | + |
| 173 | + public Map<Long, String> getTaskStatusMap(long projectId) throws Exception { |
| 174 | + Map<Long, String> map = new HashMap<>(); |
| 175 | + for (TaigaStatus s : getTaskStatuses(projectId)) { |
| 176 | + map.put(s.getId(), s.getName()); |
| 177 | + } |
| 178 | + return map; |
| 179 | + } |
| 180 | + |
| 181 | + |
134 | 182 | // --------------------------- |
135 | 183 | // INTERNALS |
136 | 184 | // --------------------------- |
|
0 commit comments