Skip to content

Add basic View support - List the Views; List the tickets in a View #491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/main/java/org/zendesk/client/v2/Zendesk.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.zendesk.client.v2.model.User;
import org.zendesk.client.v2.model.UserField;
import org.zendesk.client.v2.model.UserRelatedInfo;
import org.zendesk.client.v2.model.View;
import org.zendesk.client.v2.model.dynamic.DynamicContentItem;
import org.zendesk.client.v2.model.dynamic.DynamicContentItemVariant;
import org.zendesk.client.v2.model.hc.Article;
Expand Down Expand Up @@ -853,7 +854,18 @@ public void deleteTrigger(long triggerId) {
}


// Automations
// Views
public Iterable<View> getViews() {
return new PagedIterable<>(cnst("/views.json"), handleList(View.class, "views"));

}

public Iterable<Ticket> getView(long id) {
return new PagedIterable<>(tmpl("/views/{id}/tickets.json").set("id", id),
handleList(Ticket.class, "tickets"));
}

// Automations
public Iterable<Automation> getAutomations() {
return new PagedIterable<>(cnst("/automations.json"),
handleList(Automation.class, "automations"));
Expand Down
117 changes: 117 additions & 0 deletions src/main/java/org/zendesk/client/v2/model/View.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package org.zendesk.client.v2.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;

@JsonIgnoreProperties(ignoreUnknown = true)
public class View implements Serializable {

private static final long serialVersionUID = 8162172428393948830L;

private long id;
private String title;
private boolean active;
private String updatedAt;
private String createdAt;
private long position;
private String description;
private Conditions conditions;
private boolean watchable;

public void setId(long id) {
this.id = id;
}

@JsonProperty("id")
public long getId() {
return this.id;
}

public void setTitle(String title) {
this.title = title;
}

@JsonProperty("title")
public String getTitle() {
return this.title;
}

public void setActive(boolean active) {
this.active = active;
}

@JsonProperty("active")
public boolean getActive() {
return this.active;
}

public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}

@JsonProperty("updated_at")
public String getUpdatedAt() {
return this.updatedAt;
}

public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}

@JsonProperty("created_at")
public String getCreatedAt() {
return this.createdAt;
}

public void setPosition(long position) {
this.position = position;
}

@JsonProperty("position")
public long getPosition() {
return this.position;
}

public void setDescription(String description) {
this.description = description;
}

@JsonProperty("description")
public String getDescription() {
return this.description;
}

public void setConditions(Conditions conditions) {
this.conditions = conditions;
}

@JsonProperty("conditions")
public Conditions getConditions() {
return this.conditions;
}

public void setWatchable(boolean watchable) {
this.watchable = watchable;
}

@JsonProperty("watchable")
public boolean getWatchable() {
return this.watchable;
}

public String toString() {
return "View " +
"{id=" + id +
", title=" + title +
", active=" + active +
", updatedAt=" + updatedAt +
", createdAt=" + createdAt +
", position=" + position +
", description=" + description +
", conditions=" + conditions +
", watchable=" + watchable +
"}";
}
}
28 changes: 28 additions & 0 deletions src/test/java/org/zendesk/client/v2/RealSmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.zendesk.client.v2.model.Trigger;
import org.zendesk.client.v2.model.Type;
import org.zendesk.client.v2.model.User;
import org.zendesk.client.v2.model.View;
import org.zendesk.client.v2.model.dynamic.DynamicContentItem;
import org.zendesk.client.v2.model.dynamic.DynamicContentItemVariant;
import org.zendesk.client.v2.model.events.Event;
Expand All @@ -63,6 +64,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.Random;
import java.util.Set;
Expand Down Expand Up @@ -107,6 +109,7 @@ public class RealSmokeTest {
private static final long CLOUDBEES_ORGANIZATION_ID = 360507899132L;
private static final long USER_ID = 381626101132L; // Pierre B
private static final long PUBLIC_FORM_ID = 360000434032L;
private static final long UNRESOLVED_TICKETS_VIEW_ID = 360094600471L;
private static final Random RANDOM = new Random();
private static final String TICKET_COMMENT1 = "Please ignore this ticket";
private static final String TICKET_COMMENT2 = "Yes ignore this ticket";
Expand Down Expand Up @@ -1964,6 +1967,31 @@ public void getTicketsFromSearch() throws Exception {
}
}

@Test
public void getUnresolvedViewReturnsANewlyCreatedTicket() throws Exception {
createClientWithTokenOrPassword();
Ticket ticket = instance.createTicket(newTestTicket());
try {
assertThat(ticket.getId(), notNullValue());

Optional<Ticket> maybeTicket = StreamSupport.stream(instance.getView(UNRESOLVED_TICKETS_VIEW_ID).spliterator(), false)
.filter(t -> Objects.equals(t.getId(), ticket.getId()))
.findFirst();
assertTrue(maybeTicket.isPresent());
} finally {
instance.deleteTicket(ticket.getId());
}
}

@Test
public void getViewReturnsTheUnresolvedView() throws Exception {
createClientWithTokenOrPassword();
Optional<View> maybeView = StreamSupport.stream(instance.getViews().spliterator(),false)
.filter(v -> Objects.equals(v.getId(), UNRESOLVED_TICKETS_VIEW_ID))
.findFirst();
assertTrue(maybeView.isPresent());
}

// UTILITIES

/**
Expand Down