1 | package fr.mael.jiwigo.service; |
---|
2 | |
---|
3 | import java.io.IOException; |
---|
4 | import java.util.List; |
---|
5 | |
---|
6 | import fr.mael.jiwigo.dao.CommentDao; |
---|
7 | import fr.mael.jiwigo.om.Comment; |
---|
8 | import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; |
---|
9 | import fr.mael.jiwigo.transverse.session.SessionManager; |
---|
10 | |
---|
11 | /* |
---|
12 | Copyright (c) 2010, Mael |
---|
13 | All rights reserved. |
---|
14 | |
---|
15 | Redistribution and use in source and binary forms, with or without |
---|
16 | modification, are permitted provided that the following conditions are met: |
---|
17 | * Redistributions of source code must retain the above copyright |
---|
18 | notice, this list of conditions and the following disclaimer. |
---|
19 | * Redistributions in binary form must reproduce the above copyright |
---|
20 | notice, this list of conditions and the following disclaimer in the |
---|
21 | documentation and/or other materials provided with the distribution. |
---|
22 | * Neither the name of jiwigo nor the |
---|
23 | names of its contributors may be used to endorse or promote products |
---|
24 | derived from this software without specific prior written permission. |
---|
25 | |
---|
26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
---|
27 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
---|
28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
---|
29 | DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY |
---|
30 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
---|
32 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
---|
33 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
35 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
36 | */ |
---|
37 | /** |
---|
38 | |
---|
39 | * @author mael |
---|
40 | * |
---|
41 | */ |
---|
42 | public class CommentService { |
---|
43 | /** |
---|
44 | * Logger |
---|
45 | */ |
---|
46 | public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory |
---|
47 | .getLog(CommentService.class); |
---|
48 | |
---|
49 | /** |
---|
50 | * singleton |
---|
51 | */ |
---|
52 | private static CommentService instance; |
---|
53 | |
---|
54 | private SessionManager sessionManager; |
---|
55 | |
---|
56 | /** |
---|
57 | * @return the singleton |
---|
58 | */ |
---|
59 | public static CommentService getInstance(SessionManager sessionManager) { |
---|
60 | if (instance == null) { |
---|
61 | instance = new CommentService(sessionManager); |
---|
62 | } |
---|
63 | return instance; |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * private constructor, to use a singleton |
---|
68 | */ |
---|
69 | private CommentService(SessionManager sessionManager) { |
---|
70 | this.sessionManager = sessionManager; |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | * Lists all comments for an image |
---|
75 | * @param imageId the id of the image |
---|
76 | * @return the list of comments |
---|
77 | * @throws IOException |
---|
78 | * @throws ProxyAuthenticationException |
---|
79 | */ |
---|
80 | public List<Comment> list(Integer imageId) throws IOException, ProxyAuthenticationException { |
---|
81 | return CommentDao.getInstance(sessionManager).list(imageId); |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | * Creates a comment for an image |
---|
86 | * @param content the comment |
---|
87 | * @param imageId the id of the image |
---|
88 | * @param auteur the author of the comment |
---|
89 | * @return true if successful |
---|
90 | * @throws IOException |
---|
91 | * @throws ProxyAuthenticationException |
---|
92 | */ |
---|
93 | public boolean create(String content, Integer imageId, String auteur) throws IOException, |
---|
94 | ProxyAuthenticationException { |
---|
95 | Comment comment = new Comment(); |
---|
96 | comment.setContent(content); |
---|
97 | comment.setImageId(imageId); |
---|
98 | comment.setAuthor(auteur); |
---|
99 | return CommentDao.getInstance(sessionManager).create(comment); |
---|
100 | } |
---|
101 | |
---|
102 | } |
---|