Skip to content

Commit 90875d4

Browse files
authored
Merge pull request cloudbees-oss#491 from rcprcp/view-support
2 parents 373e111 + c519a80 commit 90875d4

File tree

3 files changed

+158
-1
lines changed

3 files changed

+158
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.zendesk.client.v2.model.User;
5858
import org.zendesk.client.v2.model.UserField;
5959
import org.zendesk.client.v2.model.UserRelatedInfo;
60+
import org.zendesk.client.v2.model.View;
6061
import org.zendesk.client.v2.model.dynamic.DynamicContentItem;
6162
import org.zendesk.client.v2.model.dynamic.DynamicContentItemVariant;
6263
import org.zendesk.client.v2.model.hc.Article;
@@ -853,7 +854,18 @@ public void deleteTrigger(long triggerId) {
853854
}
854855

855856

856-
// Automations
857+
// Views
858+
public Iterable<View> getViews() {
859+
return new PagedIterable<>(cnst("/views.json"), handleList(View.class, "views"));
860+
861+
}
862+
863+
public Iterable<Ticket> getView(long id) {
864+
return new PagedIterable<>(tmpl("/views/{id}/tickets.json").set("id", id),
865+
handleList(Ticket.class, "tickets"));
866+
}
867+
868+
// Automations
857869
public Iterable<Automation> getAutomations() {
858870
return new PagedIterable<>(cnst("/automations.json"),
859871
handleList(Automation.class, "automations"));
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package org.zendesk.client.v2.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
import java.io.Serializable;
7+
8+
@JsonIgnoreProperties(ignoreUnknown = true)
9+
public class View implements Serializable {
10+
11+
private static final long serialVersionUID = 8162172428393948830L;
12+
13+
private long id;
14+
private String title;
15+
private boolean active;
16+
private String updatedAt;
17+
private String createdAt;
18+
private long position;
19+
private String description;
20+
private Conditions conditions;
21+
private boolean watchable;
22+
23+
public void setId(long id) {
24+
this.id = id;
25+
}
26+
27+
@JsonProperty("id")
28+
public long getId() {
29+
return this.id;
30+
}
31+
32+
public void setTitle(String title) {
33+
this.title = title;
34+
}
35+
36+
@JsonProperty("title")
37+
public String getTitle() {
38+
return this.title;
39+
}
40+
41+
public void setActive(boolean active) {
42+
this.active = active;
43+
}
44+
45+
@JsonProperty("active")
46+
public boolean getActive() {
47+
return this.active;
48+
}
49+
50+
public void setUpdatedAt(String updatedAt) {
51+
this.updatedAt = updatedAt;
52+
}
53+
54+
@JsonProperty("updated_at")
55+
public String getUpdatedAt() {
56+
return this.updatedAt;
57+
}
58+
59+
public void setCreatedAt(String createdAt) {
60+
this.createdAt = createdAt;
61+
}
62+
63+
@JsonProperty("created_at")
64+
public String getCreatedAt() {
65+
return this.createdAt;
66+
}
67+
68+
public void setPosition(long position) {
69+
this.position = position;
70+
}
71+
72+
@JsonProperty("position")
73+
public long getPosition() {
74+
return this.position;
75+
}
76+
77+
public void setDescription(String description) {
78+
this.description = description;
79+
}
80+
81+
@JsonProperty("description")
82+
public String getDescription() {
83+
return this.description;
84+
}
85+
86+
public void setConditions(Conditions conditions) {
87+
this.conditions = conditions;
88+
}
89+
90+
@JsonProperty("conditions")
91+
public Conditions getConditions() {
92+
return this.conditions;
93+
}
94+
95+
public void setWatchable(boolean watchable) {
96+
this.watchable = watchable;
97+
}
98+
99+
@JsonProperty("watchable")
100+
public boolean getWatchable() {
101+
return this.watchable;
102+
}
103+
104+
public String toString() {
105+
return "View " +
106+
"{id=" + id +
107+
", title=" + title +
108+
", active=" + active +
109+
", updatedAt=" + updatedAt +
110+
", createdAt=" + createdAt +
111+
", position=" + position +
112+
", description=" + description +
113+
", conditions=" + conditions +
114+
", watchable=" + watchable +
115+
"}";
116+
}
117+
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.zendesk.client.v2.model.Trigger;
4242
import org.zendesk.client.v2.model.Type;
4343
import org.zendesk.client.v2.model.User;
44+
import org.zendesk.client.v2.model.View;
4445
import org.zendesk.client.v2.model.dynamic.DynamicContentItem;
4546
import org.zendesk.client.v2.model.dynamic.DynamicContentItemVariant;
4647
import org.zendesk.client.v2.model.events.Event;
@@ -63,6 +64,7 @@
6364
import java.util.HashSet;
6465
import java.util.List;
6566
import java.util.Objects;
67+
import java.util.Optional;
6668
import java.util.Properties;
6769
import java.util.Random;
6870
import java.util.Set;
@@ -107,6 +109,7 @@ public class RealSmokeTest {
107109
private static final long CLOUDBEES_ORGANIZATION_ID = 360507899132L;
108110
private static final long USER_ID = 381626101132L; // Pierre B
109111
private static final long PUBLIC_FORM_ID = 360000434032L;
112+
private static final long UNRESOLVED_TICKETS_VIEW_ID = 360094600471L;
110113
private static final Random RANDOM = new Random();
111114
private static final String TICKET_COMMENT1 = "Please ignore this ticket";
112115
private static final String TICKET_COMMENT2 = "Yes ignore this ticket";
@@ -1964,6 +1967,31 @@ public void getTicketsFromSearch() throws Exception {
19641967
}
19651968
}
19661969

1970+
@Test
1971+
public void getUnresolvedViewReturnsANewlyCreatedTicket() throws Exception {
1972+
createClientWithTokenOrPassword();
1973+
Ticket ticket = instance.createTicket(newTestTicket());
1974+
try {
1975+
assertThat(ticket.getId(), notNullValue());
1976+
1977+
Optional<Ticket> maybeTicket = StreamSupport.stream(instance.getView(UNRESOLVED_TICKETS_VIEW_ID).spliterator(), false)
1978+
.filter(t -> Objects.equals(t.getId(), ticket.getId()))
1979+
.findFirst();
1980+
assertTrue(maybeTicket.isPresent());
1981+
} finally {
1982+
instance.deleteTicket(ticket.getId());
1983+
}
1984+
}
1985+
1986+
@Test
1987+
public void getViewReturnsTheUnresolvedView() throws Exception {
1988+
createClientWithTokenOrPassword();
1989+
Optional<View> maybeView = StreamSupport.stream(instance.getViews().spliterator(),false)
1990+
.filter(v -> Objects.equals(v.getId(), UNRESOLVED_TICKETS_VIEW_ID))
1991+
.findFirst();
1992+
assertTrue(maybeView.isPresent());
1993+
}
1994+
19671995
// UTILITIES
19681996

19691997
/**

0 commit comments

Comments
 (0)