// Copyright (c) 2011, Chute Corporation. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Chute Corporation nor the names
// of its contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
//
package com.chute.sdk.v2.model;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import com.chute.sdk.v2.utils.JsonUtil;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
/**
* Comments offer the ability for users to interact and comment on assets inside
* an album.
* <p>
* Each comment holds links, time and date of creation and update, comment text,
* user name and user e-mail.
*
*/
public class CommentModel implements Parcelable {
public static final String TAG = CommentModel.class.getSimpleName();
/**
* Unique identifier.
*/
@JsonProperty("id")
private String id;
/**
* Comment links.
*/
@JsonProperty("links")
private LinkModel links;
/**
* The user the comment belongs to.
*/
@JsonProperty("user")
private UserModel user;
/**
* Date and time of creation.
*/
@JsonProperty("created_at")
private String createdAt;
/**
* Date and time of update.
*/
@JsonProperty("updated_at")
private String updatedAt;
/**
* Comment text.
*/
@JsonProperty("comment_text")
private String commentText;
/**
* Name of the user posting the comment.
*/
@JsonProperty("name")
private String name;
/**
* E-mail of the user posting the comment.
*/
@JsonProperty("email")
private String email;
/**
* Default non-args constructor.
*/
public CommentModel() {
}
/**
* Getters and setters.
*/
public String getId() {
return id;
}
public UserModel getUser() {
return user;
}
public void setUser(UserModel user) {
this.user = user;
}
public void setId(String id) {
this.id = id;
}
public LinkModel getLinks() {
return links;
}
public void setLinks(LinkModel links) {
this.links = links;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public String getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}
public String getCommentText() {
return commentText;
}
public void setCommentText(String commentText) {
this.commentText = commentText;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public CommentModel(Parcel in) {
this();
id = in.readString();
links = in.readParcelable(LinkModel.class.getClassLoader());
createdAt = in.readString();
updatedAt = in.readString();
commentText = in.readString();
name = in.readString();
email = in.readString();
user = in.readParcelable(UserModel.class.getClassLoader());
}
/*
* (non-Javadoc)
*
* @see android.os.Parcelable#describeContents()
*/
@Override
public int describeContents() {
return 0;
}
/*
* (non-Javadoc)
*
* @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
*/
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(id);
dest.writeParcelable(links, flags);
dest.writeString(createdAt);
dest.writeString(updatedAt);
dest.writeString(commentText);
dest.writeString(name);
dest.writeString(email);
dest.writeParcelable(user, flags);
}
public static final Creator<CommentModel> CREATOR = new Creator<CommentModel>() {
@Override
public CommentModel createFromParcel(Parcel in) {
return new CommentModel(in);
}
@Override
public CommentModel[] newArray(int size) {
return new CommentModel[size];
}
};
/**
* Method used for serializing Comment object as a String
*/
public String serializeComment() {
FilterProvider filters = new SimpleFilterProvider().addFilter(
"commentModelFilter", SimpleBeanPropertyFilter
.filterOutAllExcept("comment_text", "name", "email"));
String result = null;
try {
result = JsonUtil.getMapper().writer(filters)
.writeValueAsString(this);
} catch (JsonProcessingException e) {
Log.d(TAG,"", e);
}
return result;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((commentText == null) ? 0 : commentText.hashCode());
result = prime * result
+ ((createdAt == null) ? 0 : createdAt.hashCode());
result = prime * result + ((email == null) ? 0 : email.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((links == null) ? 0 : links.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result
+ ((updatedAt == null) ? 0 : updatedAt.hashCode());
result = prime * result + ((user == null) ? 0 : user.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CommentModel other = (CommentModel) obj;
if (commentText == null) {
if (other.commentText != null)
return false;
} else if (!commentText.equals(other.commentText))
return false;
if (createdAt == null) {
if (other.createdAt != null)
return false;
} else if (!createdAt.equals(other.createdAt))
return false;
if (email == null) {
if (other.email != null)
return false;
} else if (!email.equals(other.email))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (links == null) {
if (other.links != null)
return false;
} else if (!links.equals(other.links))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (updatedAt == null) {
if (other.updatedAt != null)
return false;
} else if (!updatedAt.equals(other.updatedAt))
return false;
if (user == null) {
if (other.user != null)
return false;
} else if (!user.equals(other.user))
return false;
return true;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("CommentModel [id=");
builder.append(id);
builder.append(", links=");
builder.append(links);
builder.append(", user=");
builder.append(user);
builder.append(", createdAt=");
builder.append(createdAt);
builder.append(", updatedAt=");
builder.append(updatedAt);
builder.append(", commentText=");
builder.append(commentText);
builder.append(", name=");
builder.append(name);
builder.append(", email=");
builder.append(email);
builder.append("]");
return builder.toString();
}
}