001// Generated by delombok at Wed Nov 11 21:20:25 CET 2020
002/*
003 * Copyright (c) 2010-2020 Mark Allen, Norbert Bartels.
004 *
005 * Permission is hereby granted, free of charge, to any person obtaining a copy
006 * of this software and associated documentation files (the "Software"), to deal
007 * in the Software without restriction, including without limitation the rights
008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
009 * copies of the Software, and to permit persons to whom the Software is
010 * furnished to do so, subject to the following conditions:
011 *
012 * The above copyright notice and this permission notice shall be included in
013 * all copies or substantial portions of the Software.
014 *
015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
021 * THE SOFTWARE.
022 */
023package com.restfb.types;
024
025import static java.util.Collections.unmodifiableList;
026import java.util.ArrayList;
027import java.util.List;
028import com.restfb.Facebook;
029import com.restfb.JsonMapper.JsonMappingCompleted;
030import com.restfb.json.Json;
031import com.restfb.json.JsonObject;
032
033/**
034 * Represents the <a href="https://developers.facebook.com/docs/graph-api/reference/object/comments">Comments Graph API
035 * type</a>.
036 *
037 * <p>
038 * Please request '{id}/comments?summary=true' explicitly if you would like the summary field which contains the count
039 * (now called 'total_count')
040 * </p>
041 *
042 * @author <a href="http://restfb.com">Mark Allen</a>
043 */
044public class Comments extends AbstractFacebookType {
045  /**
046   * The count of comments on this node.
047   * 
048   * <p>
049   * It is important to note that this value is changed depending on the {@code filter} modifier being used (where
050   * comment replies are available):
051   * </p>
052   * <ul>
053   * <li>if filter is {@code stream} then total_count will be a count of all comments (including replies) on the node.
054   * </li>
055   * <li>if filter is {@code toplevel} then total_count will be a count of all top-level comments on the node.</li>
056   * </ul>
057   * <p>
058   * {@code total_count} can be greater than or equal to the actual number of comments returned due to privacy or
059   * deletion
060   * </p>
061   * <p>
062   * Please request '{id}/comments?summary=true' explicitly if you would like the summary field which contains the count
063   * (now called 'total_count')
064   * </p>
065   */
066  @Facebook("total_count")
067  private Long totalCount = 0L;
068  /**
069   * Order in which comments were returned.
070   * 
071   * <p>
072   * <code>ranked</code> indicates the most interesting comments are sorted first.<br>
073   * <code>chronological</code> indicates comments are sorted by the oldest comments first.
074   * </p>
075   */
076  private String order;
077  private Boolean canComment;
078  @Facebook("comment_order")
079  private String openGraphCommentOrder;
080  @Facebook("can_comment")
081  private Boolean openGraphCanComment;
082  @Facebook
083  private Long count = 0L;
084  @Facebook
085  private String summary = null;
086  @Facebook
087  private List<Comment> data = new ArrayList<>();
088  private static final long serialVersionUID = 1L;
089
090  /**
091   * The comments.
092   *
093   * @return The comments.
094   */
095  public List<Comment> getData() {
096    return unmodifiableList(data);
097  }
098
099  public boolean addData(Comment comment) {
100    return data.add(comment);
101  }
102
103  public boolean removeData(Comment comment) {
104    return data.remove(comment);
105  }
106
107  @JsonMappingCompleted
108  private void fillFields() {
109    JsonObject summaryObject = null;
110    if (summary != null) {
111      summaryObject = Json.parse(summary).asObject();
112    }
113    fillTotalCount(summaryObject);
114    fillOrder(summaryObject);
115    fillCanComment(summaryObject);
116  }
117
118  /**
119   * set total count if summary is present
120   */
121  private void fillTotalCount(JsonObject summary) {
122    if (totalCount == 0 && summary != null && summary.get("total_count") != null) {
123      totalCount = summary.getLong("total_count", totalCount);
124    }
125    if (totalCount == 0 && count != 0) {
126      totalCount = count;
127    }
128  }
129
130  /**
131   * set the order the comments are sorted
132   */
133  private void fillOrder(JsonObject summary) {
134    if (summary != null) {
135      order = summary.getString("order", order);
136    }
137    if (order == null && openGraphCommentOrder != null) {
138      order = openGraphCommentOrder;
139    }
140  }
141
142  /**
143   * set the can_comment
144   */
145  private void fillCanComment(JsonObject summary) {
146    if (summary != null && summary.get("can_comment") != null) {
147      canComment = summary.get("can_comment").asBoolean();
148    }
149    if (canComment == null && openGraphCanComment != null) {
150      canComment = openGraphCanComment;
151    }
152  }
153
154  /**
155   * The count of comments on this node.
156   * 
157   * <p>
158   * It is important to note that this value is changed depending on the {@code filter} modifier being used (where
159   * comment replies are available):
160   * </p>
161   * <ul>
162   * <li>if filter is {@code stream} then total_count will be a count of all comments (including replies) on the node.
163   * </li>
164   * <li>if filter is {@code toplevel} then total_count will be a count of all top-level comments on the node.</li>
165   * </ul>
166   * <p>
167   * {@code total_count} can be greater than or equal to the actual number of comments returned due to privacy or
168   * deletion
169   * </p>
170   * <p>
171   * Please request '{id}/comments?summary=true' explicitly if you would like the summary field which contains the count
172   * (now called 'total_count')
173   * </p>
174   *
175   * @return The number of comments.
176   */
177  @java.lang.SuppressWarnings("all")
178  public Long getTotalCount() {
179    return this.totalCount;
180  }
181
182  /**
183   * The count of comments on this node.
184   * 
185   * <p>
186   * It is important to note that this value is changed depending on the {@code filter} modifier being used (where
187   * comment replies are available):
188   * </p>
189   * <ul>
190   * <li>if filter is {@code stream} then total_count will be a count of all comments (including replies) on the node.
191   * </li>
192   * <li>if filter is {@code toplevel} then total_count will be a count of all top-level comments on the node.</li>
193   * </ul>
194   * <p>
195   * {@code total_count} can be greater than or equal to the actual number of comments returned due to privacy or
196   * deletion
197   * </p>
198   * <p>
199   * Please request '{id}/comments?summary=true' explicitly if you would like the summary field which contains the count
200   * (now called 'total_count')
201   * </p>
202   */
203  @java.lang.SuppressWarnings("all")
204  public void setTotalCount(final Long totalCount) {
205    this.totalCount = totalCount;
206  }
207
208  /**
209   * Order in which comments were returned.
210   * 
211   * <p>
212   * <code>ranked</code> indicates the most interesting comments are sorted first.<br>
213   * <code>chronological</code> indicates comments are sorted by the oldest comments first.
214   * </p>
215   *
216   * @return the order of the comments
217   */
218  @java.lang.SuppressWarnings("all")
219  public String getOrder() {
220    return this.order;
221  }
222
223  /**
224   * Order in which comments were returned.
225   * 
226   * <p>
227   * <code>ranked</code> indicates the most interesting comments are sorted first.<br>
228   * <code>chronological</code> indicates comments are sorted by the oldest comments first.
229   * </p>
230   */
231  @java.lang.SuppressWarnings("all")
232  public void setOrder(final String order) {
233    this.order = order;
234  }
235
236  @java.lang.SuppressWarnings("all")
237  public Boolean getCanComment() {
238    return this.canComment;
239  }
240
241  @java.lang.SuppressWarnings("all")
242  public void setCanComment(final Boolean canComment) {
243    this.canComment = canComment;
244  }
245}