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