001// Generated by delombok at Fri Oct 04 16:05:59 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 java.util.Date;
026import com.restfb.Facebook;
027import com.restfb.JsonMapper;
028import com.restfb.JsonMapper.JsonMappingCompleted;
029import com.restfb.json.Json;
030import com.restfb.json.JsonObject;
031import com.restfb.types.features.HasComments;
032import com.restfb.types.features.HasFrom;
033import com.restfb.types.features.HasMessage;
034
035/**
036 * Represents the <a href="https://developers.facebook.com/docs/graph-api/reference/v1.0/page/ratings">Cover Graph API
037 * type</a>.
038 * 
039 * @author Anand Hemmige
040 * @author Venil Noronha
041 * @since 1.6.16
042 */
043public class PageRating extends FacebookType implements HasComments, HasFrom, HasMessage {
044  private static final long serialVersionUID = 1L;
045  /**
046   * Time the rating took place
047   * 
048   */
049  @Facebook("start_time")
050  private Date startTime;
051  /**
052   * Time the rating took place
053   */
054  @Facebook("publish_time")
055  private Date publishTime;
056  /**
057   * Person who rated the page
058   * 
059   */
060  @Facebook
061  private NamedFacebookType from;
062  @Facebook
063  private String message;
064  @Facebook
065  private Application application;
066  @Facebook("no_feed_story")
067  private Boolean noFeedStory;
068  @Facebook
069  private Comments comments;
070  @Facebook
071  private Likes likes;
072  @Facebook
073  private String data;
074  private Double ratingValue;
075  private Long ratingScale;
076  private String reviewText;
077  private Boolean isDraft;
078  private String language;
079  private Place place;
080  private RecommendationType recommendationType;
081
082  public boolean isRecommendation() {
083    return ratingValue == null;
084  }
085
086  @JsonMappingCompleted
087  void fillAdditionalValues(JsonMapper mapper) {
088    if (this.data != null) {
089      JsonObject dataObject = Json.parse(this.data).asObject();
090      if (dataObject.get("rating") != null) {
091        JsonObject rating = dataObject.get("rating").asObject();
092        if (rating != null) {
093          ratingValue = rating.get("value").asDouble();
094          ratingScale = rating.get("scale").asLong();
095        }
096      }
097      if (dataObject.get("language") != null) {
098        language = dataObject.get("language").asString();
099      }
100      if (dataObject.get("is_draft") != null) {
101        isDraft = dataObject.get("is_draft").asBoolean();
102      }
103      if (dataObject.get("review_text") != null) {
104        reviewText = dataObject.get("review_text").asString();
105      }
106      if (dataObject.get("generic_place") != null) {
107        place = mapper.toJavaObject(dataObject.get("generic_place").toString(), Place.class);
108      } else if (dataObject.get("seller") != null) {
109        place = mapper.toJavaObject(dataObject.get("seller").toString(), Place.class);
110      }
111      if (dataObject.get("recommendation_type") != null) {
112        try {
113          String typeString = dataObject.get("recommendation_type").asString();
114          recommendationType = RecommendationType.valueOf(typeString.toUpperCase());
115        } catch (IllegalArgumentException iae) {
116        }
117      }
118    }
119    // no enum value found ignore this
120  }
121
122  /**
123   * Time the rating took place
124   * 
125   * @return Time the rating took place
126   */
127  @java.lang.SuppressWarnings("all")
128  public Date getStartTime() {
129    return this.startTime;
130  }
131
132  /**
133   * Time the rating took place
134   * 
135   */
136  @java.lang.SuppressWarnings("all")
137  public void setStartTime(final Date startTime) {
138    this.startTime = startTime;
139  }
140
141  /**
142   * Time the rating took place
143   *
144   * @return Time the rating took place
145   */
146  @java.lang.SuppressWarnings("all")
147  public Date getPublishTime() {
148    return this.publishTime;
149  }
150
151  /**
152   * Time the rating took place
153   */
154  @java.lang.SuppressWarnings("all")
155  public void setPublishTime(final Date publishTime) {
156    this.publishTime = publishTime;
157  }
158
159  /**
160   * Person who rated the page
161   * 
162   * @return Person who rated the page
163   */
164  @Override
165  @java.lang.SuppressWarnings("all")
166  public NamedFacebookType getFrom() {
167    return this.from;
168  }
169
170  /**
171   * Person who rated the page
172   * 
173   */
174  @java.lang.SuppressWarnings("all")
175  public void setFrom(final NamedFacebookType from) {
176    this.from = from;
177  }
178
179  @Override
180  @java.lang.SuppressWarnings("all")
181  public String getMessage() {
182    return this.message;
183  }
184
185  @java.lang.SuppressWarnings("all")
186  public void setMessage(final String message) {
187    this.message = message;
188  }
189
190  @java.lang.SuppressWarnings("all")
191  public Application getApplication() {
192    return this.application;
193  }
194
195  @java.lang.SuppressWarnings("all")
196  public void setApplication(final Application application) {
197    this.application = application;
198  }
199
200  @java.lang.SuppressWarnings("all")
201  public Boolean getNoFeedStory() {
202    return this.noFeedStory;
203  }
204
205  @java.lang.SuppressWarnings("all")
206  public void setNoFeedStory(final Boolean noFeedStory) {
207    this.noFeedStory = noFeedStory;
208  }
209
210  @Override
211  @java.lang.SuppressWarnings("all")
212  public Comments getComments() {
213    return this.comments;
214  }
215
216  @java.lang.SuppressWarnings("all")
217  public void setComments(final Comments comments) {
218    this.comments = comments;
219  }
220
221  @java.lang.SuppressWarnings("all")
222  public Likes getLikes() {
223    return this.likes;
224  }
225
226  @java.lang.SuppressWarnings("all")
227  public void setLikes(final Likes likes) {
228    this.likes = likes;
229  }
230
231  @java.lang.SuppressWarnings("all")
232  public Double getRatingValue() {
233    return this.ratingValue;
234  }
235
236  @java.lang.SuppressWarnings("all")
237  public void setRatingValue(final Double ratingValue) {
238    this.ratingValue = ratingValue;
239  }
240
241  @java.lang.SuppressWarnings("all")
242  public Long getRatingScale() {
243    return this.ratingScale;
244  }
245
246  @java.lang.SuppressWarnings("all")
247  public void setRatingScale(final Long ratingScale) {
248    this.ratingScale = ratingScale;
249  }
250
251  @java.lang.SuppressWarnings("all")
252  public String getReviewText() {
253    return this.reviewText;
254  }
255
256  @java.lang.SuppressWarnings("all")
257  public void setReviewText(final String reviewText) {
258    this.reviewText = reviewText;
259  }
260
261  @java.lang.SuppressWarnings("all")
262  public Boolean getIsDraft() {
263    return this.isDraft;
264  }
265
266  @java.lang.SuppressWarnings("all")
267  public void setIsDraft(final Boolean isDraft) {
268    this.isDraft = isDraft;
269  }
270
271  @java.lang.SuppressWarnings("all")
272  public String getLanguage() {
273    return this.language;
274  }
275
276  @java.lang.SuppressWarnings("all")
277  public void setLanguage(final String language) {
278    this.language = language;
279  }
280
281  @java.lang.SuppressWarnings("all")
282  public Place getPlace() {
283    return this.place;
284  }
285
286  @java.lang.SuppressWarnings("all")
287  public void setPlace(final Place place) {
288    this.place = place;
289  }
290
291  @java.lang.SuppressWarnings("all")
292  public RecommendationType getRecommendationType() {
293    return this.recommendationType;
294  }
295
296  @java.lang.SuppressWarnings("all")
297  public void setRecommendationType(final RecommendationType recommendationType) {
298    this.recommendationType = recommendationType;
299  }
300}