package in.partake.model.dto; import java.util.UUID; import in.partake.base.DateTime; import in.partake.model.dto.auxiliary.MessageDelivery; import in.partake.model.dto.auxiliary.NotificationType; import org.apache.commons.lang.ObjectUtils; import org.codehaus.jackson.node.JsonNodeFactory; import org.codehaus.jackson.node.ObjectNode; /** * @author shinyak * */ public class UserNotification extends PartakeModel<UserNotification> { private String id; private UUID ticketId; private String userId; private NotificationType notificationType; private MessageDelivery delivery; private DateTime createdAt; private DateTime modifiedAt; public UserNotification() { // do nothing } public UserNotification(UserNotification message) { this(message.id, message.ticketId, message.userId, message.notificationType, message.delivery, message.createdAt, message.modifiedAt); } public UserNotification(String id, UUID ticketId, String userId, NotificationType notificationType, MessageDelivery delivery, DateTime createdAt, DateTime modifiedAt) { this.id = id; this.ticketId = ticketId; this.userId = userId; this.notificationType = notificationType; this.delivery = delivery; this.createdAt = createdAt; this.modifiedAt = modifiedAt; } public UserNotification(ObjectNode obj) { this.id = obj.get("id").asText(); this.ticketId = UUID.fromString(obj.get("ticketId").asText()); this.userId = obj.get("userId").asText(); this.notificationType = NotificationType.safeValueOf(obj.get("notificationType").asText()); this.delivery = MessageDelivery.safeValueOf(obj.get("delivery").asText()); this.createdAt = new DateTime(obj.get("createdAt").asLong()); if (obj.has("modifiedAt")) this.modifiedAt = new DateTime(obj.get("modifiedAt").asLong()); } @Override public Object getPrimaryKey() { return id; } @Override public ObjectNode toJSON() { ObjectNode obj = new ObjectNode(JsonNodeFactory.instance); obj.put("id", id); obj.put("ticketId", ticketId.toString()); obj.put("userId", userId); obj.put("notificationType", notificationType.toString()); obj.put("delivery", delivery.toString()); if (createdAt != null) obj.put("createdAt", createdAt.getTime()); if (modifiedAt != null) obj.put("modifiedAt", modifiedAt.getTime()); return obj; } // ---------------------------------------------------------------------- // equals method @Override public boolean equals(Object obj) { if (!(obj instanceof UserNotification)) { return false; } UserNotification lhs = this; UserNotification rhs = (UserNotification) obj; if (!(ObjectUtils.equals(lhs.id, rhs.id))) { return false; } if (!(ObjectUtils.equals(lhs.ticketId, rhs.ticketId))) { return false; } if (!(ObjectUtils.equals(lhs.userId, rhs.userId))) { return false; } if (!(ObjectUtils.equals(lhs.notificationType, rhs.notificationType))) { return false; } if (!(ObjectUtils.equals(lhs.delivery, rhs.delivery))) { return false; } if (!(ObjectUtils.equals(lhs.createdAt, rhs.createdAt))) { return false; } if (!(ObjectUtils.equals(lhs.modifiedAt, rhs.modifiedAt))) { return false; } return true; } @Override public int hashCode() { int code = 0; code = code * 37 + ObjectUtils.hashCode(id); code = code * 37 + ObjectUtils.hashCode(ticketId); code = code * 37 + ObjectUtils.hashCode(userId); code = code * 37 + ObjectUtils.hashCode(notificationType); code = code * 37 + ObjectUtils.hashCode(delivery); code = code * 37 + ObjectUtils.hashCode(createdAt); code = code * 37 + ObjectUtils.hashCode(modifiedAt); return code; } // ---------------------------------------------------------------------- // accessors public String getId() { return id; } public UUID getTicketId() { return ticketId; } public String getUserId() { return userId; } public NotificationType getNotificationType() { return notificationType; } public MessageDelivery getDelivery() { return delivery; } public DateTime getCreatedAt() { return createdAt; } public DateTime getModifiedAt() { return modifiedAt; } public void setId(String id) { checkFrozen(); this.id = id; } public void setTicketId(UUID ticketId) { checkFrozen(); this.ticketId = ticketId; } public void setUserId(String userId) { checkFrozen(); this.userId = userId; } public void setNotificationType(NotificationType notificationType) { checkFrozen(); this.notificationType = notificationType; } public void setDelivery(MessageDelivery delivery) { checkFrozen(); this.delivery = delivery; } public void setCreatedAt(DateTime createdAt) { checkFrozen(); this.createdAt = createdAt; } public void setModifiedAt(DateTime modifiedAt) { checkFrozen(); this.modifiedAt = modifiedAt; } }