class IssueMapper implements EntityMapper<Issue> {

    @Override
    public XContentBuilder map(final EntityContainer<Issue> container) {
        Issue issue = container.getEntity();
        try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
            jsonBuilder.startObject();
            jsonBuilder
                    .field(DOC_TYPE_FIELD, SearchDocumentType.ISSUE.name())
                    .field("id", issue.getId())
                    .field("name", issue.getName())
                    .field("text", issue.getText())
                    .field("status", issue.getStatus())
                    .field("createdDate", parseDataToString(issue.getCreatedDate()))
                    .field("updatedDate", parseDataToString(issue.getUpdatedDate()));

            buildLabels(issue.getLabels(), jsonBuilder);
            buildAttachments(issue.getAttachments(), jsonBuilder);
            buildEntityVO(issue.getEntity(), jsonBuilder);
            buildComments(issue.getComments(), jsonBuilder);
            buildPermissions(container.getPermissions(), jsonBuilder);
            buildUserContent(container.getOwner(), jsonBuilder);

            jsonBuilder.endObject();
            return jsonBuilder;
        } catch (IOException e) {
            throw new IllegalArgumentException("Failed to create elasticsearch document for issue: ", e);
        }
    }

}