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/CategoryService.java

    r9879 r9919  
    44import java.util.List;
    55
    6 import fr.mael.jiwigo.dao.CategoryDao;
    76import fr.mael.jiwigo.om.Category;
    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 CategoryService {
    28     /**
    29      * Logger
    30      */
    31     public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
    32             .getLog(CategoryService.class);
    33 
    34     /**
    35      * singleton
    36      */
    37     private static CategoryService instance;
    38 
    39     private SessionManager sessionManager;
    40 
    41     /**
    42      * @return the singleton
    43      */
    44     public static CategoryService getInstance(SessionManager sessionManager) {
    45         if (instance == null) {
    46             instance = new CategoryService(sessionManager);
    47         }
    48         return instance;
    49     }
    50 
    51     /**
    52      * private constructor to use a singleton
    53      */
    54     private CategoryService(SessionManager sessionManager) {
    55         this.sessionManager = sessionManager;
    56 
    57     }
    58 
     9public interface CategoryService {
    5910    /**
    6011     * Lists all categories
     
    6415     * @throws ProxyAuthenticationException
    6516     */
    66     public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException {
    67         return CategoryDao.getInstance(sessionManager).list(recursive);
    68     }
     17    public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException;
    6918
    7019    /**
     
    7423     * @throws ProxyAuthenticationException
    7524     */
    76     public List<Category> makeTree() throws IOException, ProxyAuthenticationException {
    77         List<Category> list = CategoryDao.getInstance(sessionManager).list(true);
    78         for (Category category : list) {
    79             for (Category category2 : list) {
    80                 if (category2.getIdParentCategories().size() != 1
    81                         && category.getIdentifier().equals(
    82                                 category2.getIdParentCategories().get(category2.getIdParentCategories().size() - 2))) {
    83                     category.getChildCategories().add(category2);
    84                     category2.getParentCategories().add(category);
    85                 }
    86 
    87             }
    88         }
    89 
    90         return list;
    91 
    92     }
     25    public List<Category> makeTree() throws IOException, ProxyAuthenticationException;
    9326
    9427    /**
     
    9932     * @throws ProxyAuthenticationException
    10033     */
    101     public boolean create(String nom, Integer parent) throws ProxyAuthenticationException {
    102         Category category = new Category();
    103         category.setDirectParent(parent);
    104         category.setName(nom);
    105         return CategoryDao.getInstance(sessionManager).create(category);
    106     }
     34    public boolean create(String nom, Integer parent) throws ProxyAuthenticationException;
    10735
    10836    /**
     
    11240     * @throws ProxyAuthenticationException
    11341     */
    114     public boolean create(String nom) throws ProxyAuthenticationException {
    115         Category category = new Category();
    116         category.setName(nom);
    117         return CategoryDao.getInstance(sessionManager).create(category);
    118     }
     42    public boolean create(String nom) throws ProxyAuthenticationException;
    11943}
Note: See TracChangeset for help on using the changeset viewer.