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

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

Changed the licence
to a funniest one.

File size: 2.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/*
12 *  jiwigo-ws-api Piwigo webservice access Api
13 *  Copyright (c) 2010-2011 Mael mael@le-guevel.com
14 *                All Rights Reserved
15 *
16 *  This library is free software. It comes without any warranty, to
17 *  the extent permitted by applicable law. You can redistribute it
18 *  and/or modify it under the terms of the Do What The Fuck You Want
19 *  To Public License, Version 2, as published by Sam Hocevar. See
20 *  http://sam.zoy.org/wtfpl/COPYING for more details.
21 */
22/**
23
24 * @author mael
25 *
26 */
27public class CommentService {
28    /**
29     * Logger
30     */
31    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
32            .getLog(CommentService.class);
33
34    /**
35     * singleton
36     */
37    private static CommentService instance;
38
39    private SessionManager sessionManager;
40
41    /**
42     * @return the singleton
43     */
44    public static CommentService getInstance(SessionManager sessionManager) {
45        if (instance == null) {
46            instance = new CommentService(sessionManager);
47        }
48        return instance;
49    }
50
51    /**
52     * private constructor, to use a singleton
53     */
54    private CommentService(SessionManager sessionManager) {
55        this.sessionManager = sessionManager;
56    }
57
58    /**
59     * Lists all comments for an image
60     * @param imageId the id of the image
61     * @return the list of comments
62     * @throws IOException
63     * @throws ProxyAuthenticationException
64     */
65    public List<Comment> list(Integer imageId) throws IOException, ProxyAuthenticationException {
66        return CommentDao.getInstance(sessionManager).list(imageId);
67    }
68
69    /**
70     * Creates a comment for an image
71     * @param content the comment
72     * @param imageId the id of the image
73     * @param auteur the author of the comment
74     * @return true if successful
75     * @throws IOException
76     * @throws ProxyAuthenticationException
77     */
78    public boolean create(String content, Integer imageId, String auteur) throws IOException,
79            ProxyAuthenticationException {
80        Comment comment = new Comment();
81        comment.setContent(content);
82        comment.setImageId(imageId);
83        comment.setAuthor(auteur);
84        return CommentDao.getInstance(sessionManager).create(comment);
85    }
86
87}
Note: See TracBrowser for help on using the repository browser.