/* * PatientView * * Copyright (c) Worth Solutions Limited 2004-2013 * * This file is part of PatientView. * * PatientView is free software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, either version 3 of the License, * or (at your option) any later version. * PatientView is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License along with PatientView in a file * titled COPYING. If not, see <http://www.gnu.org/licenses/>. * * @package PatientView * @link http://www.patientview.org * @author PatientView <info@patientview.org> * @copyright Copyright (c) 2004-2013, Worth Solutions Limited * @license http://www.gnu.org/licenses/gpl-3.0.html The GNU General Public License V3.0 */ package org.patientview.patientview.model; import org.patientview.model.BaseModel; import org.patientview.model.Unit; import org.patientview.patientview.model.enums.GroupEnum; import org.apache.commons.lang.StringUtils; import org.patientview.utils.XssUtils; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Transient; import javax.persistence.EnumType; import javax.persistence.Enumerated; import java.util.Date; @Entity public class Message extends BaseModel { @Column(nullable = false) private boolean deleted; @ManyToOne(optional = false) @JoinColumn(name = "conversation_id") private Conversation conversation; @Column(nullable = false) private Date date; @ManyToOne(optional = false) @JoinColumn(name = "sender_id") private User sender; @ManyToOne(optional = true) @JoinColumn(name = "recipient_id") private User recipient; @Column(nullable = false, columnDefinition = "TEXT") private String content; @Column(nullable = false) private boolean hasRead; // this will be set by manager @Transient private String friendlyDate; @Column(nullable = true) @Enumerated(EnumType.STRING) private GroupEnum groupEnum; @Column(nullable = true) private String type; @ManyToOne(optional = true) @JoinColumn(name = "unit_id") private Unit unit; private static final int SUMMARY_LENGTH = 500; public String getFormattedContent() { return XssUtils.encodeForHTML(content, new String[] {" " }); } public String getSummary() { if (content.length() > SUMMARY_LENGTH) { return StringUtils.substring(content, 0, SUMMARY_LENGTH) + " ..."; } return content; } public boolean isDeleted() { return deleted; } public void setDeleted(boolean deleted) { this.deleted = deleted; } public Conversation getConversation() { return conversation; } public void setConversation(Conversation conversation) { this.conversation = conversation; } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } public User getSender() { return sender; } public void setSender(User sender) { this.sender = sender; } public User getRecipient() { return recipient; } public void setRecipient(User recipient) { this.recipient = recipient; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public boolean isHasRead() { return hasRead; } public void setHasRead(boolean hasRead) { this.hasRead = hasRead; } public String getFriendlyDate() { return friendlyDate; } public void setFriendlyDate(String friendlyDate) { this.friendlyDate = friendlyDate; } public GroupEnum getGroupEnum() { return groupEnum; } public void setGroupEnum(GroupEnum groupEnum) { this.groupEnum = groupEnum; } public String getType() { return type; } public void setType(String type) { this.type = type; } public Unit getUnit() { return unit; } public void setUnit(Unit unit) { this.unit = unit; } }