001// Generated by delombok at Sun Apr 14 14:59:49 CEST 2024
002/*
003 * Copyright (c) 2010-2024 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  /**
100   * Adds a comment
101   *
102   * @param comment
103   *          the comment that should be added
104   * @return true if the comment was added, false otherwise
105   */
106  public boolean addData(Comment comment) {
107    return data.add(comment);
108  }
109
110  /**
111   * remove a comment
112   *
113   * @param comment
114   *          the comment that should be removed
115   * @return true if the comment was removed, false otherwise
116   */
117  public boolean removeData(Comment comment) {
118    return data.remove(comment);
119  }
120
121  @JsonMappingCompleted
122  private void fillFields() {
123    JsonObject summaryObject = null;
124    if (summary != null) {
125      summaryObject = Json.parse(summary).asObject();
126    }
127    fillTotalCount(summaryObject);
128    fillOrder(summaryObject);
129    fillCanComment(summaryObject);
130  }
131
132  /**
133   * set total count if summary is present
134   */
135  private void fillTotalCount(JsonObject summary) {
136    if (totalCount == 0 && summary != null && summary.get("total_count") != null) {
137      totalCount = summary.getLong("total_count", totalCount);
138    }
139    if (totalCount == 0 && count != 0) {
140      totalCount = count;
141    }
142  }
143
144  /**
145   * set the order the comments are sorted
146   */
147  private void fillOrder(JsonObject summary) {
148    if (summary != null) {
149      order = summary.getString("order", order);
150    }
151    if (order == null && openGraphCommentOrder != null) {
152      order = openGraphCommentOrder;
153    }
154  }
155
156  /**
157   * set the can_comment
158   */
159  private void fillCanComment(JsonObject summary) {
160    if (summary != null && summary.get("can_comment") != null) {
161      canComment = summary.get("can_comment").asBoolean();
162    }
163    if (canComment == null && openGraphCanComment != null) {
164      canComment = openGraphCanComment;
165    }
166  }
167
168  /**
169   * The count of comments on this node.
170   * 
171   * <p>
172   * It is important to note that this value is changed depending on the {@code filter} modifier being used (where
173   * comment replies are available):
174   * </p>
175   * <ul>
176   * <li>if filter is {@code stream} then total_count will be a count of all comments (including replies) on the node.
177   * </li>
178   * <li>if filter is {@code toplevel} then total_count will be a count of all top-level comments on the node.</li>
179   * </ul>
180   * <p>
181   * {@code total_count} can be greater than or equal to the actual number of comments returned due to privacy or
182   * deletion
183   * </p>
184   * <p>
185   * Please request '{id}/comments?summary=true' explicitly if you would like the summary field which contains the count
186   * (now called 'total_count')
187   * </p>
188   *
189   * @return The number of comments.
190   */
191  @java.lang.SuppressWarnings("all")
192  public Long getTotalCount() {
193    return this.totalCount;
194  }
195
196  /**
197   * The count of comments on this node.
198   * 
199   * <p>
200   * It is important to note that this value is changed depending on the {@code filter} modifier being used (where
201   * comment replies are available):
202   * </p>
203   * <ul>
204   * <li>if filter is {@code stream} then total_count will be a count of all comments (including replies) on the node.
205   * </li>
206   * <li>if filter is {@code toplevel} then total_count will be a count of all top-level comments on the node.</li>
207   * </ul>
208   * <p>
209   * {@code total_count} can be greater than or equal to the actual number of comments returned due to privacy or
210   * deletion
211   * </p>
212   * <p>
213   * Please request '{id}/comments?summary=true' explicitly if you would like the summary field which contains the count
214   * (now called 'total_count')
215   * </p>
216   */
217  @java.lang.SuppressWarnings("all")
218  public void setTotalCount(final Long totalCount) {
219    this.totalCount = totalCount;
220  }
221
222  /**
223   * Order in which comments were returned.
224   * 
225   * <p>
226   * <code>ranked</code> indicates the most interesting comments are sorted first.<br>
227   * <code>chronological</code> indicates comments are sorted by the oldest comments first.
228   * </p>
229   *
230   * @return the order of the comments
231   */
232  @java.lang.SuppressWarnings("all")
233  public String getOrder() {
234    return this.order;
235  }
236
237  /**
238   * Order in which comments were returned.
239   * 
240   * <p>
241   * <code>ranked</code> indicates the most interesting comments are sorted first.<br>
242   * <code>chronological</code> indicates comments are sorted by the oldest comments first.
243   * </p>
244   */
245  @java.lang.SuppressWarnings("all")
246  public void setOrder(final String order) {
247    this.order = order;
248  }
249
250  @java.lang.SuppressWarnings("all")
251  public Boolean getCanComment() {
252    return this.canComment;
253  }
254
255  @java.lang.SuppressWarnings("all")
256  public void setCanComment(final Boolean canComment) {
257    this.canComment = canComment;
258  }
259}