1 package org.flowfuse.base.model;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5
6 import java.util.Date;
7
8 /***
9 * <p>A <code>Comment</code> instance holds a user comment associated
10 * to a particular workflow. Instances of this class are persisted using
11 * Hibernate.<p>
12 *
13 * @author <a href="stefan@flowfuse.org">Stefan Kleineikenscheidt</a>,
14 * Flowfuse.org
15 * @since 1.0
16 * @version $Id: Comment.java,v 1.1 2005/11/20 15:02:13 skleinei Exp $
17 *
18 * @hibernate.class table="FF_COMMENT"
19 */
20 public class Comment extends BaseObject {
21
22 /***
23 * RCS ID
24 */
25 public final static String rcsid = "$Id: Comment.java,v 1.1 2005/11/20 15:02:13 skleinei Exp $";
26
27 /***
28 * Logger
29 */
30 protected final Log logger = LogFactory.getLog(this.getClass());
31
32 /***
33 * The comments unique id.
34 */
35 private Long id;
36
37 /***
38 * The workflowInstance the comment is associated to.
39 */
40 private WorkItem workItem;
41
42 /***
43 * The author's user-id.
44 */
45 private String author = "";
46
47 /***
48 * The comments creation date.
49 */
50 private Date creationDate = null;
51
52 /***
53 * The comments text.
54 */
55 String text = new String();
56
57 /***
58 * Return id (used by Hibernate).
59 *
60 * @return Returns this comments id.
61 * @since 1.0
62 *
63 * @hibernate.id generator-class="native" column="COMMENT_ID"
64 * unsaved-value="null" type="long"
65 */
66 public Long getId() {
67 return id;
68 }
69
70 public void setId(Long id) {
71 this.id = id;
72 }
73
74 /***
75 * Returns the work item this comments associated to.
76 *
77 * @return The WorkflowItem the comment is associated to.
78 * @since 1.0
79 *
80 * @hibernate.many-to-one column="WORKFLOWINSTANCE_ID" cascade="all" not-null="true"
81 */
82 public WorkItem getWorkflowInstance() {
83 return this.workItem;
84 }
85
86 public void setWorkflowInstance(WorkItem workItem) {
87 this.workItem = workItem;
88 }
89
90 /***
91 * Returns the author of this comment.
92 *
93 * <code>
94 * TODO This methods needs to return an object of type user.
95 * </code>
96 *
97 * @return The comment's text.
98 * @since 1.0
99 *
100 * @hibernate.property column="COMMENT_AUTHOR" length="255"
101 */
102 public String getAuthor() {
103 return author;
104 }
105
106 public void setAuthor(String author) {
107 this.author = author;
108 }
109
110 /***
111 * Return the creation date of this comment.
112 *
113 * @return The comment's creation date.
114 *
115 * @hibernate.property column="COMMENT_CREATIONDATE" length="255"
116 */
117 public Date getCreationDate() {
118 return creationDate;
119 }
120
121 public void setCreationDate(Date creationDate) {
122 this.creationDate = creationDate;
123 }
124
125 /***
126 * Return the text of this comment.
127 *
128 * @return The comment's text.
129 *
130 * @hibernate.property column="COMMENT_TEXT" length="255"
131 */
132 public String getText() {
133 return text;
134 }
135
136 public void setText(String text) {
137 this.text = text;
138 }
139
140 /***
141 * Overrides <code>equals()</code> in <code>{@link BaseObject}</code>
142 * in order to support Hibernate.
143 *
144 * @param o
145 * @return
146 */
147 public boolean equals(Object o) {
148 if (this == o) {
149 return true;
150 }
151 if (!(o instanceof Comment)) {
152 return false;
153 }
154
155 final Comment comment = (Comment) o;
156
157 if (author != null ? !author.equals(comment.author) : comment.author != null) {
158 return false;
159 }
160 if (creationDate != null ? !creationDate.equals(comment.creationDate) : comment.creationDate != null) {
161 return false;
162 }
163 if (text != null ? !text.equals(comment.text) : comment.text != null) {
164 return false;
165 }
166 if (!workItem.equals(comment.workItem)) {
167 return false;
168 }
169
170 return true;
171 }
172
173 /***
174 * Overrides <code>hashCode()</code> in <code>{@link BaseObject}</code>
175 * in order to support Hibernate.
176 *
177 * @return
178 */
179 public int hashCode() {
180 int result;
181 result = workItem.hashCode();
182 result = 29 * result + (author != null ? author.hashCode() : 0);
183 result = 29 * result + (creationDate != null ? creationDate.hashCode() : 0);
184 result = 29 * result + (text != null ? text.hashCode() : 0);
185 return result;
186 }
187
188 /***
189 * Overrides <code>toString()</code> in <code>{@link BaseObject}</code>
190 * in order to support Hibernate.
191 *
192 * @return
193 */
194 public String toString() {
195 return "Comment{" +
196 "id=" + id +
197 ", workflowInstance=" + workItem +
198 ", author='" + author + "'" +
199 ", creationDate=" + creationDate +
200 ", text='" + text + "'" +
201 "}";
202 }
203 }
204
205