Skip to content
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

[#289] Add user_segment_id, permission_group_id and other new fields … #290

Merged
merged 1 commit into from
Jun 24, 2019
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
56 changes: 56 additions & 0 deletions src/main/java/org/zendesk/client/v2/model/hc/Article.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.zendesk.client.v2.model.hc;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.zendesk.client.v2.model.SearchResultEntity;

Expand Down Expand Up @@ -41,6 +43,10 @@ public class Article implements SearchResultEntity {
/** Whether the source (default) translation of the article is out of date */
private Boolean outdated;

/** Locales in which the article was marked as outdated */
@JsonProperty("outdated_locales")
private List<String> outdatedLocales;

/** An array of label names associated with this article. By default no label names are used. Only available on certain plans */
@JsonProperty("label_names")
private List<String> labelNames;
Expand All @@ -66,6 +72,16 @@ public class Article implements SearchResultEntity {
@JsonProperty("section_id")
private Long sectionId;

/** The id of the user segment which defines who can see this article. Set to null to make it accessible to everyone. */
@JsonInclude(Include.ALWAYS)
@JsonProperty(value = "user_segment_id", defaultValue = "null")
private Long userSegmentId;

/** The id of the permission group which defines who can edit and publish this article. */
@JsonInclude(Include.ALWAYS)
@JsonProperty(value = "permission_group_id", defaultValue = "null")
private Long permissionGroupId;

/** The time the article was created */
@JsonProperty("created_at")
private Date createdAt;
Expand All @@ -74,6 +90,10 @@ public class Article implements SearchResultEntity {
@JsonProperty("updated_at")
private Date updatedAt;

/** The time the article was last edited in its displayed locale */
@JsonProperty("edited_at")
private Date editedAt;

public Long getId() {
return id;
}
Expand Down Expand Up @@ -154,6 +174,14 @@ public void setOutdated(Boolean outdated) {
this.outdated = outdated;
}

public List<String> getOutdatedLocales() {
return outdatedLocales;
}

public void setOutdatedLocales(List<String> outdatedLocales) {
this.outdatedLocales = outdatedLocales;
}

public List<String> getLabelNames() {
return labelNames;
}
Expand Down Expand Up @@ -210,6 +238,22 @@ public void setSectionId(Long sectionId) {
this.sectionId = sectionId;
}

public Long getUserSegmentId() {
return userSegmentId;
}

public void setUserSegmentId(Long userSegmentId) {
this.userSegmentId = userSegmentId;
}

public Long getPermissionGroupId() {
return permissionGroupId;
}

public void setPermissionGroupId(Long permissionGroupId) {
this.permissionGroupId = permissionGroupId;
}

public Date getCreatedAt() {
return createdAt;
}
Expand All @@ -226,6 +270,14 @@ public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}

public Date getEditedAt() {
return editedAt;
}

public void setEditedAt(Date editedAt) {
this.editedAt = editedAt;
}

@Override
public String toString() {
return "Article{" +
Expand All @@ -239,15 +291,19 @@ public String toString() {
", authorId=" + authorId +
", commentsDisabled=" + commentsDisabled +
", outdated=" + outdated +
", outdatedLocales=" + outdatedLocales +
", labelNames=" + labelNames +
", draft=" + draft +
", promoted=" + promoted +
", position=" + position +
", voteSum=" + voteSum +
", voteCount=" + voteCount +
", sectionId=" + sectionId +
", userSegmentId=" + userSegmentId +
", permissionGroupId=" + permissionGroupId +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", editedAt=" + editedAt +
'}';
}
}
76 changes: 76 additions & 0 deletions src/test/java/org/zendesk/client/v2/model/ArticleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.zendesk.client.v2.model;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.zendesk.client.v2.model.hc.Article;

import java.util.ArrayList;
import java.util.Date;

import static org.junit.Assert.*;

public class ArticleTest {

private Article parseJson(byte[] json) {
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.readValue(json, Article.class);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

@Test
public void testParseArticle() {
String json = "{" +
"\"id\":918273645013," +
"\"url\":\"https://example.zendesk.com/api/v2/help_center/en-us/articles/918273645013-Welcome-to-your-Help-Center-.json\"," +
"\"html_url\":\"https://example.zendesk.com/hc/en-us/articles/918273645013-Welcome-to-your-Help-Center-\"," +
"\"author_id\":2314596780," +
"\"comments_disabled\":false," +
"\"draft\":false," +
"\"promoted\":false," +
"\"position\":0," +
"\"vote_sum\":0," +
"\"vote_count\":0," +
"\"section_id\":123456789," +
"\"created_at\":\"2019-06-10T12:39:23Z\"," +
"\"updated_at\":\"2019-06-10T12:39:23Z\"," +
"\"title\":\"Welcome to your Help Center!\"," +
"\"source_locale\":\"en-us\"," +
"\"locale\":\"en-us\"," +
"\"outdated\":false," +
"\"outdated_locales\":[]," +
"\"edited_at\":\"2019-06-10T12:39:23Z\"," +
"\"user_segment_id\":null," +
"\"permission_group_id\":2739912," +
"\"label_names\":[]," +
"\"body\":\"This is a test\"}";
Article article = parseJson(json.getBytes());
assertNotNull(article);
assertEquals(Article.class, article.getClass());
assertEquals((Long) 918273645013L, article.getId());
assertEquals("https://example.zendesk.com/api/v2/help_center/en-us/articles/918273645013-Welcome-to-your-Help-Center-.json", article.getUrl());
assertEquals("https://example.zendesk.com/hc/en-us/articles/918273645013-Welcome-to-your-Help-Center-", article.getHtmlUrl());
assertEquals((Long) 2314596780L, article.getAuthorId());
assertEquals(false, article.getCommentsDisabled());
assertEquals(false, article.getDraft());
assertEquals(false, article.getPromoted());
assertEquals((Long) 0L, article.getPosition());
assertEquals((Long) 0L, article.getVoteSum());
assertEquals((Long) 0L, article.getVoteCount());
assertEquals(new Date(1560170363000L), article.getCreatedAt());
assertEquals(new Date(1560170363000L), article.getUpdatedAt());
assertEquals("Welcome to your Help Center!", article.getTitle());
assertEquals("en-us", article.getSourceLocale());
assertEquals("en-us", article.getLocale());
assertEquals(false, article.getOutdated());
assertEquals(new ArrayList<>(), article.getOutdatedLocales());
assertEquals(new Date(1560170363000L), article.getEditedAt());
assertNull(article.getUserSegmentId());
assertEquals((Long) 2739912L, article.getPermissionGroupId());
assertEquals(new ArrayList<>(), article.getLabelNames());
assertEquals("This is a test", article.getBody());
}
}