package fr.mael.jiwigo.service; import java.io.IOException; import java.util.List; import fr.mael.jiwigo.dao.CommentDao; import fr.mael.jiwigo.om.Comment; import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; import fr.mael.jiwigo.transverse.session.SessionManager; /* * jiwigo-ws-api Piwigo webservice access Api * Copyright (c) 2010-2011 Mael mael@le-guevel.com * All Rights Reserved * * This library is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/wtfpl/COPYING for more details. */ /** * @author mael * */ public class CommentService { /** * Logger */ public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory .getLog(CommentService.class); /** * singleton */ private static CommentService instance; private SessionManager sessionManager; /** * @return the singleton */ public static CommentService getInstance(SessionManager sessionManager) { if (instance == null) { instance = new CommentService(sessionManager); } return instance; } /** * private constructor, to use a singleton */ private CommentService(SessionManager sessionManager) { this.sessionManager = sessionManager; } /** * Lists all comments for an image * @param imageId the id of the image * @return the list of comments * @throws IOException * @throws ProxyAuthenticationException */ public List list(Integer imageId) throws IOException, ProxyAuthenticationException { return CommentDao.getInstance(sessionManager).list(imageId); } /** * Creates a comment for an image * @param content the comment * @param imageId the id of the image * @param auteur the author of the comment * @return true if successful * @throws IOException * @throws ProxyAuthenticationException */ public boolean create(String content, Integer imageId, String auteur) throws IOException, ProxyAuthenticationException { Comment comment = new Comment(); comment.setContent(content); comment.setImageId(imageId); comment.setAuthor(auteur); return CommentDao.getInstance(sessionManager).create(comment); } }