1 package org.unitedfront2.domain.communication;
2
3 import java.io.Serializable;
4 import java.util.Date;
5 import java.util.List;
6
7 import org.apache.commons.lang.builder.EqualsBuilder;
8 import org.apache.commons.lang.builder.HashCodeBuilder;
9 import org.apache.commons.lang.builder.ToStringBuilder;
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import org.unitedfront2.dao.BlogDao;
13 import org.unitedfront2.domain.Deletable;
14 import org.unitedfront2.domain.Domain;
15 import org.unitedfront2.domain.Identifiable;
16 import org.unitedfront2.domain.Storable;
17 import org.unitedfront2.domain.User;
18 import org.unitedfront2.domain.accesscontrol.AccessControl;
19 import org.unitedfront2.domain.accesscontrol.AccessDeniedException;
20
21
22
23
24
25
26
27 public class BlogEntry implements Serializable, Identifiable<BlogEntry>,
28 Storable, Deletable, Domain {
29
30
31 protected final transient Log logger = LogFactory.getLog(getClass());
32
33
34 private static final long serialVersionUID = 8962368517170431378L;
35
36
37 private Message entry;
38
39
40 private transient List<Comment> comments;
41
42
43 private transient Integer commentCount;
44
45
46 private transient BlogDao blogDao;
47
48 public BlogEntry() {
49 super();
50 }
51
52 public BlogEntry(Message entry) {
53 super();
54 this.entry = entry;
55 }
56
57 @Override
58 public boolean equals(final Object other) {
59 if (!(other instanceof BlogEntry)) {
60 return false;
61 }
62 BlogEntry castOther = (BlogEntry) other;
63 return new EqualsBuilder()
64 .append(entry, castOther.entry).isEquals();
65 }
66
67 @Override
68 public int hashCode() {
69 return new HashCodeBuilder().append(entry).toHashCode();
70 }
71
72 @Override
73 public String toString() {
74 return new ToStringBuilder(this).append("entry", entry).toString();
75 }
76
77 @Override
78 public boolean identify(BlogEntry other) {
79 if (entry == null) {
80 return false;
81 }
82 return entry.identify(other.entry);
83 }
84
85
86
87
88 @Override
89 public void store() {
90 try {
91 entry.store();
92 } catch (MessageCodeUsedByOtherException e) {
93
94 logger.error(e.getMessage(), e);
95 throw new IllegalStateException(e);
96 }
97 }
98
99
100
101
102 @Override
103 public void delete() {
104 entry.delete();
105 }
106
107 /
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207 public void post(Comment comment) {
208 comment.store();
209 blogDao.registerComment(getId(), comment.getId());
210 }
211
212
213
214
215
216
217
218 public Comment findComment(int id) {
219 for (Comment c : getComments()) {
220 if (c.getId() == id) {
221 return c;
222 }
223 }
224 return null;
225 }
226
227 public Message getEntry() {
228 return entry;
229 }
230
231 public void setEntry(Message entry) {
232 this.entry = entry;
233 }
234
235 public List<Comment> getComments() {
236 if (comments == null && blogDao != null && getId() != null) {
237 comments = blogDao.findComments(getId());
238 }
239 return comments;
240 }
241
242 public Integer getCommentCount() {
243 if (commentCount == null && blogDao != null && getId() != null) {
244 commentCount = blogDao.countComment(getId());
245 }
246 return commentCount;
247 }
248
249 public void setBlogDao(BlogDao blogDao) {
250 this.blogDao = blogDao;
251 }
252 }