001/* 002 * (C) Copyright 2006-2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Thomas Roger <troger@nuxeo.com> 016 */ 017 018package org.nuxeo.ecm.rating.api; 019 020import java.io.Serializable; 021import java.util.HashMap; 022import java.util.Map; 023 024/** 025 * An object storing the like / dislike status of an activity object. 026 * <p> 027 * It may also contain the like status for a {@code username}: 028 * <ul> 029 * <li>LIKED</li> 030 * <li>DISLIKED</li> 031 * <li>UNKNOWN</li> 032 * </ul> 033 * 034 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 035 * @since 5.6 036 */ 037public class LikeStatus { 038 039 /** 040 * Constant used when the {@code username} liked the {@code activityObject} . 041 */ 042 public static final int LIKED = 1; 043 044 /** 045 * Constant used when the {@code username} disliked the {@code activityObject}. 046 */ 047 public static final int DISLIKED = -1; 048 049 /** 050 * Constant used when the {@code username} didn't like nor dislike the {@code activityObject}. 051 */ 052 public static final int UNKNOWN = 0; 053 054 public final String activityObject; 055 056 public final long likesCount; 057 058 public final long dislikesCount; 059 060 public final String username; 061 062 public final int userLikeStatus; 063 064 /** 065 * Creates a {@code LikeStatus} with the like status for the specified {@code username}. 066 * 067 * @param activityObject the activity object for which this {@code LikeStatus} apply 068 * @param likesCount the likes count for the activity object 069 * @param dislikesCount the dislikes count for the activity object 070 * @param username the username on which the {@code userLikeStatus} apply 071 * @param userLikeStatus the like status for the {@code username} 072 */ 073 public LikeStatus(String activityObject, long likesCount, long dislikesCount, String username, int userLikeStatus) { 074 this.activityObject = activityObject; 075 this.likesCount = likesCount; 076 this.dislikesCount = dislikesCount; 077 this.username = username; 078 this.userLikeStatus = userLikeStatus; 079 } 080 081 /** 082 * Creates a {@code LikeStatus} without the like status for a {@code username}. 083 * 084 * @param activityObject the activity object for which this {@code LikeStatus} apply 085 * @param likesCount the likes count for the activity object 086 * @param dislikesCount the dislikes count for the activity object 087 */ 088 public LikeStatus(String activityObject, long likesCount, long dislikesCount) { 089 this(activityObject, likesCount, dislikesCount, null, UNKNOWN); 090 } 091 092 /** 093 * Returns a {@code Map} of attributes for this {@code LikeStatus}. 094 */ 095 @SuppressWarnings("boxing") 096 public Map<String, Serializable> toMap() { 097 Map<String, Serializable> map = new HashMap<String, Serializable>(); 098 map.put("activityObject", activityObject); 099 map.put("likesCount", likesCount); 100 map.put("dislikesCount", dislikesCount); 101 map.put("username", username); 102 map.put("userLikeStatus", userLikeStatus); 103 return map; 104 } 105 106}