1 /***
2 Copyright (C) 2005 The Java Community
3
4 This program is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free Software
6 Foundation; either version 2 of the License, or (at your option) any later
7 version.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 Place, Suite 330, Boston, MA 02111-1307 USA.
16
17 */
18
19 package org.bejug.javacareers.jobs.view.jsf.action;
20
21 import java.util.List;
22
23 import net.sf.acegisecurity.UserDetails;
24 import net.sf.acegisecurity.context.security.SecureContextUtils;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.bejug.javacareers.common.service.ItemService;
29 import org.bejug.javacareers.jobs.model.Comment;
30 import org.bejug.javacareers.jobs.model.Item;
31 import org.bejug.javacareers.jobs.service.CommentService;
32 import org.bejug.javacareers.jobs.service.MailService;
33 import org.bejug.javacareers.jobs.view.jsf.model.UserTracker;
34
35 /***
36 * @author Peter Symoens (Last modified by $Author: shally $)
37 * @version $Revision: 1.8 $ - $Date: 2005/12/08 14:53:46 $
38 */
39 public class CommentActionImpl extends BaseAction implements CommentAction {
40
41
42 /***
43 * The logger.
44 */
45 private static final Log LOG = LogFactory.getLog(CommentActionImpl.class);
46
47
48 /***
49 * The user tracker, injected.
50 */
51 private UserTracker userTracker;
52
53 /***
54 * The CommentService
55 */
56 private CommentService commentService;
57
58 /***
59 * The JobService
60 */
61 private ItemService itemService;
62
63 /***
64 * the mailService
65 */
66 private MailService mailService;
67
68
69
70
71 /***
72 * {@inheritDoc}
73 */
74 public void processPostAction(Item offer, String content) {
75 LOG.info("Debug: processPostAction action called");
76
77
78 Comment comment = new Comment(offer, userTracker.getCurrentUser(), "", content);
79 Item dbOffer = itemService.getItem(offer.getId());
80 if (dbOffer != null) {
81 commentService.storeComment(comment);
82 }
83 else {
84 LOG.error("Could not save comment, offer with id " + offer.getId() + " is null");
85 }
86
87 }
88
89 /***
90 * {@inheritDoc}
91 */
92 public void processPostResponse(Item offer, Integer commentId, String content) {
93
94 Comment parentComment = commentService.getComment(commentId);
95 Comment comment = new Comment();
96 comment.setOffer(offer);
97 comment.setUser(userTracker.getCurrentUser());
98 comment.setParentComment(parentComment);
99 comment.setContent(content);
100 commentService.storeComment(comment);
101
102 }
103
104
105 /***
106 * {@inheritDoc}
107 */
108 public int getCommentCount(Item offer) {
109 return commentService.getCommentCount(offer);
110 }
111
112 /***
113 * {@inheritDoc}
114 */
115 public boolean isUserAuthenticated() {
116 Object principal = SecureContextUtils.getSecureContext()
117 .getAuthentication().getPrincipal();
118 if (principal instanceof UserDetails) {
119 return true;
120 }
121 return false;
122 }
123
124
125 /***
126 * {@inheritDoc}
127 */
128 public int getChildCommentCount(Comment comment) {
129 return commentService.getChildCommentCount(comment);
130 }
131
132 /***
133 * {@inheritDoc}
134 */
135 public List getComments(Item offer) {
136 return commentService.getComments(offer.getId(), true);
137 }
138
139 /***
140 * {@inheritDoc}
141 */
142 public List getChildComments(Comment comment) {
143 return commentService.getChildComments(comment);
144 }
145
146 /***
147 * @param commentService The commentService to set.
148 */
149 public void setCommentService(CommentService commentService) {
150 this.commentService = commentService;
151 }
152
153 /***
154 * @return commentService The commentService to return.
155 */
156 public CommentService getCommentService() {
157 return commentService;
158 }
159
160
161
162 /***
163 * @param userTracker The userTracker to set.
164 */
165 public void setUserTracker(UserTracker userTracker) {
166 this.userTracker = userTracker;
167 }
168
169 /***
170 * gets the jobservice.
171 * @return the wanted jobservice.
172 */
173 public ItemService getJobService() {
174 return itemService;
175 }
176
177 /***
178 * sets the jobservice.
179 * @param jobService the jobservice to set.
180 */
181 public void setItemService(ItemService jobService) {
182 this.itemService = jobService;
183 }
184
185 /***
186 *
187 * @return the wanted mailService
188 */
189 public MailService getMailService() {
190 return mailService;
191 }
192
193 /***
194 *
195 * @param mailService set the mailService
196 */
197 public void setMailService(MailService mailService) {
198 this.mailService = mailService;
199 }
200
201
202 }
203
204 /***
205 * $Log: CommentActionImpl.java,v $
206 * Revision 1.8 2005/12/08 14:53:46 shally
207 * Opkuis voor checkstyle.
208 *
209 * Revision 1.7 2005/09/30 14:38:07 bavo_jcs
210 * Fixed URL
211 *
212 * Revision 1.6 2005/09/19 14:16:51 bavo_jcs
213 * Refactored comments to use Items
214 *
215 * Revision 1.5 2005/09/13 08:11:06 schauwvliege
216 * organize imports
217 *
218 * Revision 1.4 2005/08/30 13:07:47 psong09
219 * renamed author: psong09
220 *
221 * Revision 1.3 2005/08/24 13:04:47 psong09
222 * moved isAuthenticated method to CommentAction
223 *
224 * Revision 1.2 2005/08/24 12:34:27 psong09
225 * removed some comments
226 *
227 * Revision 1.1 2005/08/24 12:32:12 psong09
228 * Added spinner component and renamed commentAction
229 *
230 * Revision 1.27 2005/08/22 13:38:34 psong09
231 * Added error page for synchronisation error
232 *
233 * Revision 1.26 2005/08/19 14:13:15 bme_jcs
234 * checkstyle errors resolved
235 *
236 * Revision 1.25 2005/08/19 13:13:53 psong09
237 * introduced synchroniser token
238 *
239 * Revision 1.24 2005/08/17 16:39:33 psong09
240 * Moved redirectToLogin method to Utils class
241 *
242 * Revision 1.23 2005/08/10 09:04:49 bavo_jcs
243 * Optimized imports according to checkstyle
244 *
245 * Revision 1.22 2005/08/09 12:59:56 bavo_jcs
246 * Optimized imports
247 *
248 * Revision 1.21 2005/08/08 14:12:29 bme_jcs
249 * mailService added again
250 *
251 * Revision 1.20 2005/08/08 12:08:01 bme_jcs
252 * resolved checkstyle errors
253 *
254 * Revision 1.19 2005/08/08 09:38:21 bme_jcs
255 * resolved checkstyle errors
256 *
257 * Revision 1.18 2005/08/04 10:07:18 bavo_jcs
258 * Fixed orphaned comments
259 *
260 * Revision 1.17 2005/07/12 16:12:48 psong09
261 * update comment component
262 *
263 * Revision 1.16 2005/07/08 15:47:26 psong09
264 * modified comment component, removed subject field
265 *
266 * Revision 1.15 2005/07/05 15:26:54 psong09
267 * cleanup
268 *
269 * Revision 1.13 2005/07/04 07:54:01 psong09
270 * update comment component: added count(*) query, user login check, javascript
271 *
272 * Revision 1.12 2005/06/30 15:27:33 bavo_jcs
273 * Tag fix in login
274 *
275 * Revision 1.11 2005/06/30 12:23:46 psong09
276 * update comment component
277 *
278 * Revision 1.10 2005/06/29 09:00:25 psong09
279 * comment component updated
280 *
281 * Revision 1.9 2005/06/28 07:38:29 psong09
282 * comment component updated
283 *
284 * Revision 1.8 2005/06/24 16:28:57 psong09
285 * comment component updated
286 *
287 * Revision 1.7 2005/06/17 12:01:17 schauwvliege
288 * CheckStyle/ PMD
289 *
290 * Revision 1.6 2005/06/17 11:42:46 schauwvliege
291 * CheckStyle/ PMD
292 *
293 * Revision 1.5 2005/06/17 07:50:16 bavo_jcs
294 * temp commnted out non-compiling code
295 *
296 * Revision 1.4 2005/06/16 14:43:50 psong09
297 * added subject to comments
298 *
299 * Revision 1.3 2005/06/14 12:05:53 schauwvliege
300 * CheckStyle and fixing tests
301 *
302 * Revision 1.2 2005/06/09 08:18:52 bejug_cc
303 * Fix initial import
304 *
305 * Revision 1.1 2005/05/25 15:50:31 PSONG09
306 * file added
307 *
308 **/
309