diff --git a/src/main/java/org/zendesk/client/v2/model/hc/Article.java b/src/main/java/org/zendesk/client/v2/model/hc/Article.java index 42cf56ea..6743d707 100644 --- a/src/main/java/org/zendesk/client/v2/model/hc/Article.java +++ b/src/main/java/org/zendesk/client/v2/model/hc/Article.java @@ -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; @@ -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 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 labelNames; @@ -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; @@ -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; } @@ -154,6 +174,14 @@ public void setOutdated(Boolean outdated) { this.outdated = outdated; } + public List getOutdatedLocales() { + return outdatedLocales; + } + + public void setOutdatedLocales(List outdatedLocales) { + this.outdatedLocales = outdatedLocales; + } + public List getLabelNames() { return labelNames; } @@ -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; } @@ -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{" + @@ -239,6 +291,7 @@ public String toString() { ", authorId=" + authorId + ", commentsDisabled=" + commentsDisabled + ", outdated=" + outdated + + ", outdatedLocales=" + outdatedLocales + ", labelNames=" + labelNames + ", draft=" + draft + ", promoted=" + promoted + @@ -246,8 +299,11 @@ public String toString() { ", voteSum=" + voteSum + ", voteCount=" + voteCount + ", sectionId=" + sectionId + + ", userSegmentId=" + userSegmentId + + ", permissionGroupId=" + permissionGroupId + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + + ", editedAt=" + editedAt + '}'; } } diff --git a/src/test/java/org/zendesk/client/v2/model/ArticleTest.java b/src/test/java/org/zendesk/client/v2/model/ArticleTest.java new file mode 100644 index 00000000..ff85d1c6 --- /dev/null +++ b/src/test/java/org/zendesk/client/v2/model/ArticleTest.java @@ -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()); + } +}