Skip to content

Instantly share code, notes, and snippets.

Created November 16, 2011 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1371479 to your computer and use it in GitHub Desktop.
Save anonymous/1371479 to your computer and use it in GitHub Desktop.
content builder for thread
XContentBuilder cb = null;
try {
cb = XContentFactory.jsonBuilder().startObject();
cb.field("postID", thread.getPostID())
.field("threadID", thread.getThreadID())
.field("subject", thread.getSubject())
.field("message", thread.getMessage())
.field("dateCreated", thread.getDateCreated())
.field("postGUID", thread.getPostGUID())
.field("category.categoryID", thread.getCategory().getCategoryID())
.field("category.categoryName", thread.getCategory().getCategoryName())
.field("category.categoryTypeID", thread.getCategory().getCategoryTypeID())
.field("author.accountID", thread.getAuthor().getAccountID())
.field("author.username", thread.getAuthor().getUserName())
.field("author.companyID", thread.getAuthor().getCompanyBrandingID())
.field("author.companyName", thread.getAuthor().getCompanyName())
.field("author.userAccessTypeBit", thread.getAuthor().getUserAccessTypeBit())
.field("owner.accountID", thread.getOwner().getAccountID())
.field("owner.username", thread.getOwner().getUserName())
.field("owner.companyID", thread.getOwner().getCompanyBrandingID())
.field("owner.companyName", thread.getOwner().getCompanyName())
.field("owner.userAccessTypeBit", thread.getOwner().getUserAccessTypeBit())
.field("owner.accountNotesStatusID", thread.getOwner().getAccountNotesStatusID())
.field("statusBit", thread.getStatusBit())
.field("lastUpdatedBy.accountID", thread.getLastUpdatedBy().getAccountID())
.field("lastUpdatedBy.username", thread.getLastUpdatedBy().getUserName())
.field("lastPostDate", thread.getLastPostDate())
.field("replies", thread.getReplyCount())
.field("tags", thread.getTagIDs());
cb.array("postDates", thread.getPostDates().toArray());
if (thread.getStatus() != null) {
cb.field("status.tagID", thread.getStatus().tagID)
.field("status.tagName", thread.getStatus().tagName)
.field("status.number", thread.getStatus().tagDescription);
}
if (thread.getInternalPriority() != null) {
cb.field("priority.internal.tagID", thread.getInternalPriority().tagID)
.field("priority.internal.tagName", thread.getInternalPriority().tagName)
.field("priority.internal.number", thread.getInternalPriority().tagDescription);
}
if (thread.getExternalPriority() != null) {
cb.field("priority.external.tagID", thread.getExternalPriority().tagID)
.field("priority.external.tagName", thread.getExternalPriority().tagName)
.field("priority.external.number", thread.getExternalPriority().tagDescription);
}
if (thread.getResolutionOwner() != null) {
cb.field("resolutionOwner.tagID", thread.getResolutionOwner().tagID)
.field("resolutionOwner.tagName", thread.getResolutionOwner().tagName)
.field("resolutionOwner.accountID", thread.getResolutionOwner().tagAccountID);
}
cb.field("meta.readAccessAccountID", thread.getReadAccessAccountID());
cb.field("meta.readAccessGroupAccessBit", thread.getReadAccessGroupAccessBit());
cb.endObject();
} catch (IOException e) {
log.error("error building json for thread", e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment