source: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CommentService.java @ 9387

Last change on this file since 9387 was 9387, checked in by mlg, 13 years ago

First commit for jiwigo-ws-api

File size: 3.2 KB
Line 
1package fr.mael.jiwigo.service;
2
3import java.io.IOException;
4import java.util.List;
5
6import fr.mael.jiwigo.dao.CommentDao;
7import fr.mael.jiwigo.om.Comment;
8import fr.mael.jiwigo.transverse.session.SessionManager;
9
10/*
11Copyright (c) 2010, Mael
12All rights reserved.
13
14Redistribution and use in source and binary forms, with or without
15modification, 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
25THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY
29DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32ON 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
34SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35*/
36/**
37
38 * @author mael
39 *
40 */
41public 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}
Note: See TracBrowser for help on using the repository browser.