Skip to content

Commit 2465fb7

Browse files
committed
Merge pull request cloudbees-oss#61 from tandrup/improve-collaborators
Improve collaborators handling
2 parents b4d2b1a + 5ecc958 commit 2465fb7

File tree

5 files changed

+68
-27
lines changed

5 files changed

+68
-27
lines changed

src/main/java/org/zendesk/client/v2/Zendesk.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ public List<Ticket> getTicketIncidents(long id) {
214214
handleList(Ticket.class, "tickets")));
215215
}
216216

217+
public List<User> getTicketCollaborators(long id) {
218+
return complete(submit(req("GET", tmpl("/tickets/{id}/collaborators.json").set("id", id)),
219+
handleList(User.class, "users")));
220+
}
221+
217222
public void deleteTicket(Ticket ticket) {
218223
checkHasId(ticket);
219224
deleteTicket(ticket.getId());
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.zendesk.client.v2.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
5+
@JsonIgnoreProperties(ignoreUnknown = true)
6+
public class Collaborator {
7+
private String name;
8+
private String email;
9+
10+
public Collaborator() {
11+
}
12+
13+
protected Collaborator(String name) {
14+
this.name = name;
15+
this.email = email;
16+
}
17+
18+
public Collaborator(String name, String email) {
19+
this.name = name;
20+
this.email = email;
21+
}
22+
23+
public String getName() {
24+
return name;
25+
}
26+
27+
public void setName(String name) {
28+
this.name = name;
29+
}
30+
31+
public String getEmail() {
32+
return email;
33+
}
34+
35+
public void setEmail(String email) {
36+
this.email = email;
37+
}
38+
}

src/main/java/org/zendesk/client/v2/model/Ticket.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class Ticket extends Request implements SearchResultEntity {
2020
private Long assigneeId;
2121
private Long groupId;
2222
private List<Long> collaboratorIds;
23+
private List<Collaborator> collaborators;
2324
private Long forumTopicId;
2425
private Long problemId;
2526
private boolean hasIncidents;
@@ -65,6 +66,15 @@ public void setCollaboratorIds(List<Long> collaboratorIds) {
6566
this.collaboratorIds = collaboratorIds;
6667
}
6768

69+
@JsonProperty("collaborators")
70+
private List<Collaborator> getCollaborators() {
71+
return collaborators;
72+
}
73+
74+
public void setCollaborators(List<Collaborator> collaborators) {
75+
this.collaborators = collaborators;
76+
}
77+
6878
@JsonProperty("custom_fields")
6979
public List<CustomFieldValue> getCustomFields() {
7080
return customFields;

src/main/java/org/zendesk/client/v2/model/User.java

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
* @author stephenc
1313
* @since 05/04/2013 15:32
1414
*/
15-
public class User implements SearchResultEntity {
15+
public class User extends Collaborator implements SearchResultEntity {
1616
private Long id;
1717
private String url;
18-
private String name;
1918
private String externalId;
2019
private String alias;
2120
private Date createdAt;
@@ -26,7 +25,6 @@ public class User implements SearchResultEntity {
2625
private Long localeId;
2726
private String timeZone;
2827
private Date lastLoginAt;
29-
private String email;
3028
private String phone;
3129
private String signature;
3230
private String details;
@@ -48,35 +46,33 @@ public User() {
4846
}
4947

5048
public User(Boolean verified, String name, String email) {
51-
this.name = name;
52-
this.email = email;
49+
super(name, email);
5350
this.verified = verified;
5451
}
5552

5653
public User(Boolean verified, String name, List<Identity> identities) {
54+
super(name);
5755
this.verified = verified;
58-
this.name = name;
5956
this.identities = identities;
6057
}
6158

6259
public User(Boolean verified, String name, Identity... identities) {
60+
super(name);
6361
this.verified = verified;
64-
this.name = name;
6562
this.identities = new ArrayList<Identity>(Arrays.asList(identities));
6663
}
6764

6865
public User(String name, String email) {
69-
this.name = name;
70-
this.email = email;
66+
super(name, email);
7167
}
7268

7369
public User(String name, List<Identity> identities) {
74-
this.name = name;
70+
super(name);
7571
this.identities = identities;
7672
}
7773

7874
public User(String name, Identity... identities) {
79-
this.name = name;
75+
super(name);
8076
this.identities = new ArrayList<Identity>(Arrays.asList(identities));
8177
}
8278

@@ -130,14 +126,6 @@ public void setDetails(String details) {
130126
this.details = details;
131127
}
132128

133-
public String getEmail() {
134-
return email;
135-
}
136-
137-
public void setEmail(String email) {
138-
this.email = email;
139-
}
140-
141129
@JsonProperty("external_id")
142130
public String getExternalId() {
143131
return externalId;
@@ -181,14 +169,6 @@ public void setModerator(Boolean moderator) {
181169
this.moderator = moderator;
182170
}
183171

184-
public String getName() {
185-
return name;
186-
}
187-
188-
public void setName(String name) {
189-
this.name = name;
190-
}
191-
192172
public String getNotes() {
193173
return notes;
194174
}

src/test/java/org/zendesk/client/v2/RealSmokeTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.junit.Ignore;
66
import org.junit.Test;
77
import org.zendesk.client.v2.model.Audit;
8+
import org.zendesk.client.v2.model.Collaborator;
89
import org.zendesk.client.v2.model.Comment;
910
import org.zendesk.client.v2.model.Field;
1011
import org.zendesk.client.v2.model.Group;
@@ -27,6 +28,7 @@
2728
import java.util.Properties;
2829
import java.util.UUID;
2930

31+
import static org.hamcrest.CoreMatchers.anyOf;
3032
import static org.hamcrest.CoreMatchers.is;
3133
import static org.hamcrest.CoreMatchers.not;
3234
import static org.hamcrest.CoreMatchers.notNullValue;
@@ -242,20 +244,26 @@ public void createDeleteTicket() throws Exception {
242244
Ticket t = new Ticket(
243245
new Ticket.Requester(config.getProperty("requester.name"), config.getProperty("requester.email")),
244246
"This is a test", new Comment("Please ignore this ticket"));
247+
t.setCollaborators(Arrays.asList(new Collaborator("Bob Example", "[email protected]"), new Collaborator("Alice Example", "[email protected]")));
245248
Ticket ticket = instance.createTicket(t);
246249
System.out.println(ticket.getId() + " -> " + ticket.getUrl());
247250
assertThat(ticket.getId(), notNullValue());
248251
try {
249252
Ticket t2 = instance.getTicket(ticket.getId());
250253
assertThat(t2, notNullValue());
251254
assertThat(t2.getId(), is(ticket.getId()));
255+
256+
List<User> ticketCollaborators = instance.getTicketCollaborators(ticket.getId());
257+
assertThat("Collaborators", ticketCollaborators.size(), is(2));
258+
assertThat("First Collaborator", ticketCollaborators.get(0).getEmail(), anyOf(is("[email protected]"), is("[email protected]")));
252259
} finally {
253260
instance.deleteTicket(ticket.getId());
254261
}
255262
assertThat(ticket.getSubject(), is(t.getSubject()));
256263
assertThat(ticket.getRequester(), nullValue());
257264
assertThat(ticket.getRequesterId(), notNullValue());
258265
assertThat(ticket.getDescription(), is(t.getComment().getBody()));
266+
assertThat("Collaborators", ticket.getCollaboratorIds().size(), is(2));
259267
assertThat(instance.getTicket(ticket.getId()), nullValue());
260268
}
261269

0 commit comments

Comments
 (0)