Ignore:
Timestamp:
Mar 29, 2011, 8:21:25 PM (13 years ago)
Author:
mlg
Message:

Complete rewriting of the api
The api now uses interfaces everywhere (for the dao, services and session manager). This allows the developer to use his own implementations if he wants.
Deletion of the singletons. There are now getters and setters. It allows to make dependency injection.
Use of sl4j in the api, instead of using log4j.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CommentService.java

    r9879 r9919  
    44import java.util.List;
    55
    6 import fr.mael.jiwigo.dao.CommentDao;
    76import fr.mael.jiwigo.om.Comment;
    87import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    9 import fr.mael.jiwigo.transverse.session.SessionManager;
    108
    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  */
    27 public 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 
     9public interface CommentService {
    5810    /**
    5911     * Lists all comments for an image
     
    6315     * @throws ProxyAuthenticationException
    6416     */
    65     public List<Comment> list(Integer imageId) throws IOException, ProxyAuthenticationException {
    66         return CommentDao.getInstance(sessionManager).list(imageId);
    67     }
     17    public List<Comment> list(Integer imageId) throws IOException, ProxyAuthenticationException;
    6818
    6919    /**
     
    7727     */
    7828    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     }
     29            ProxyAuthenticationException;
    8630
    8731}
Note: See TracChangeset for help on using the changeset viewer.