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

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

Modifications to handle proxy error.
Two types of error are handled : proxy address error and proxy authentication error.
Connecting to jiwigo via a proxy seems to work (tried with my own server... gonna have to try with an external server).
version is 0.13.1.1

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