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