001// Generated by delombok at Sun Nov 17 22:54:56 CET 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 static java.util.Collections.unmodifiableList; 026import java.util.ArrayList; 027import java.util.Date; 028import java.util.List; 029import com.restfb.Facebook; 030import com.restfb.JsonMapper.JsonMappingCompleted; 031import com.restfb.json.Json; 032import com.restfb.json.JsonObject; 033 034/** 035 * Represents the <a href="https://developers.facebook.com/docs/graph-api/reference/video/likes/">Video Likes Graph API 036 * type</a> and the <a href="https://developers.facebook.com/docs/graph-api/reference/post/likes/">Post Likes Graph API 037 * type</a> 038 * 039 * @author <a href="http://restfb.com">Mark Allen</a> 040 */ 041public class Likes extends AbstractFacebookType { 042 /** 043 * The number of likes. 044 */ 045 @Facebook 046 private Long totalCount = 0L; 047 /** 048 * returns if the user can like the object 049 */ 050 private Boolean canLike; 051 /** 052 * returns if the user has liked the object 053 */ 054 private Boolean hasLiked; 055 @Facebook("can_like") 056 private Boolean openGraphCanLike; 057 @Facebook("user_likes") 058 private Boolean openGraphUserLikes; 059 @Facebook("count") 060 private Long openGraphCount = 0L; 061 @Facebook 062 private String summary; 063 @Facebook 064 private List<LikeItem> data = new ArrayList<>(); 065 private static final long serialVersionUID = 1L; 066 067 /** 068 * The likes. 069 * 070 * @return The likes. 071 */ 072 public List<LikeItem> getData() { 073 return unmodifiableList(data); 074 } 075 076 public boolean addData(LikeItem like) { 077 return data.add(like); 078 } 079 080 public boolean removeData(LikeItem like) { 081 return data.remove(like); 082 } 083 084 @JsonMappingCompleted 085 private void fillFields() { 086 JsonObject summaryObject = null; 087 if (summary != null) { 088 summaryObject = Json.parse(summary).asObject(); 089 } 090 fillTotalCount(summaryObject); 091 fillHasLiked(summaryObject); 092 fillCanLike(summaryObject); 093 } 094 095 /** 096 * add change count value, if summary is set and count is empty 097 */ 098 private void fillTotalCount(JsonObject summary) { 099 if (totalCount == 0 && summary != null && summary.get("total_count") != null) { 100 totalCount = summary.getLong("total_count", totalCount); 101 } 102 if (openGraphCount != 0) { 103 totalCount = openGraphCount; 104 } 105 } 106 107 /** 108 * fill <code>has_liked</code> from summary, in case of open graph object use user_likes instead 109 */ 110 private void fillHasLiked(JsonObject summary) { 111 if (summary != null && summary.get("has_liked") != null) { 112 hasLiked = summary.get("has_liked").asBoolean(); 113 } 114 if (hasLiked == null && openGraphUserLikes != null) { 115 hasLiked = openGraphUserLikes; 116 } 117 } 118 119 private void fillCanLike(JsonObject summary) { 120 if (summary != null && summary.get("can_like") != null) { 121 canLike = summary.get("can_like").asBoolean(); 122 } 123 if (canLike == null && openGraphCanLike != null) { 124 canLike = openGraphCanLike; 125 } 126 } 127 128 129 public static class LikeItem extends NamedFacebookType { 130 /** 131 * created time is the date the Like was created. 132 * 133 * may be null if Facebook does not provide this information 134 */ 135 @Facebook("created_time") 136 private Date createdTime; 137 138 @java.lang.SuppressWarnings("all") 139 public Date getCreatedTime() { 140 return this.createdTime; 141 } 142 143 @java.lang.SuppressWarnings("all") 144 public void setCreatedTime(final Date createdTime) { 145 this.createdTime = createdTime; 146 } 147 } 148 149 /** 150 * The number of likes. 151 * 152 * @return The number of likes. 153 */ 154 @java.lang.SuppressWarnings("all") 155 public Long getTotalCount() { 156 return this.totalCount; 157 } 158 159 /** 160 * The number of likes. 161 */ 162 @java.lang.SuppressWarnings("all") 163 public void setTotalCount(final Long totalCount) { 164 this.totalCount = totalCount; 165 } 166 167 /** 168 * returns if the user can like the object 169 * 170 * @return if the user can like the object 171 */ 172 @java.lang.SuppressWarnings("all") 173 public Boolean getCanLike() { 174 return this.canLike; 175 } 176 177 /** 178 * returns if the user can like the object 179 */ 180 @java.lang.SuppressWarnings("all") 181 public void setCanLike(final Boolean canLike) { 182 this.canLike = canLike; 183 } 184 185 /** 186 * returns if the user has liked the object 187 * 188 * @return if the user has liked the object 189 */ 190 @java.lang.SuppressWarnings("all") 191 public Boolean getHasLiked() { 192 return this.hasLiked; 193 } 194 195 /** 196 * returns if the user has liked the object 197 */ 198 @java.lang.SuppressWarnings("all") 199 public void setHasLiked(final Boolean hasLiked) { 200 this.hasLiked = hasLiked; 201 } 202}