Skip to content

Commit 9b6f090

Browse files
committed
Adding support for user and status descriptive data
1 parent e236444 commit 9b6f090

3 files changed

Lines changed: 139 additions & 0 deletions

File tree

src/main/java/javiergs/tulip/taiga/TaigaClient.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import java.net.http.*;
88
import java.nio.charset.StandardCharsets;
99
import java.util.ArrayList;
10+
import java.util.HashMap;
1011
import java.util.List;
12+
import java.util.Map;
1113

1214
public class TaigaClient {
1315

@@ -131,6 +133,52 @@ public List<TaigaUserStory> getStoriesBySprint(long sprintId) throws Exception {
131133
}
132134

133135

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+
134182
// ---------------------------
135183
// INTERNALS
136184
// ---------------------------
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package javiergs.tulip.taiga;
2+
3+
public class TaigaStatus {
4+
5+
private final long id;
6+
private final String name;
7+
private final String slug;
8+
private final String color;
9+
private final int order;
10+
11+
public TaigaStatus(long id, String name, String slug, String color, int order) {
12+
this.id = id;
13+
this.name = name;
14+
this.slug = slug;
15+
this.color = color;
16+
this.order = order;
17+
}
18+
19+
public long getId() {
20+
return id;
21+
}
22+
23+
public String getName() {
24+
return name;
25+
}
26+
27+
public String getSlug() {
28+
return slug;
29+
}
30+
31+
public String getColor() {
32+
return color;
33+
}
34+
35+
public int getOrder() {
36+
return order;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return "TaigaStatus{" +
42+
"id=" + id +
43+
", name='" + name + '\'' +
44+
", slug='" + slug + '\'' +
45+
", color='" + color + '\'' +
46+
", order=" + order +
47+
'}';
48+
}
49+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package javiergs.tulip.taiga;
2+
3+
public class TaigaUser {
4+
5+
private final long id;
6+
private final String username;
7+
private final String fullName;
8+
private final String email;
9+
10+
public TaigaUser(long id, String username, String fullName, String email) {
11+
this.id = id;
12+
this.username = username;
13+
this.fullName = fullName;
14+
this.email = email;
15+
}
16+
17+
public long getId() {
18+
return id;
19+
}
20+
21+
public String getUsername() {
22+
return username;
23+
}
24+
25+
public String getFullName() {
26+
return fullName;
27+
}
28+
29+
public String getEmail() {
30+
return email;
31+
}
32+
33+
@Override
34+
public String toString() {
35+
return "TaigaUser{" +
36+
"id=" + id +
37+
", username='" + username + '\'' +
38+
", fullName='" + fullName + '\'' +
39+
", email='" + email + '\'' +
40+
'}';
41+
}
42+
}

0 commit comments

Comments
 (0)