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