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.

Location:
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl
Files:
1 added
1 copied

Legend:

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

    r9893 r9919  
    1 package fr.mael.jiwigo.service;
     1package fr.mael.jiwigo.service.impl;
    22
    33import java.io.File;
     
    66import java.util.List;
    77
     8import org.slf4j.Logger;
     9import org.slf4j.LoggerFactory;
     10
    811import fr.mael.jiwigo.dao.ImageDao;
    912import fr.mael.jiwigo.om.Image;
     13import fr.mael.jiwigo.service.ImageService;
    1014import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException;
    1115import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    1216import fr.mael.jiwigo.transverse.exception.WrongChunkSizeException;
    13 import fr.mael.jiwigo.transverse.session.SessionManager;
    1417import fr.mael.jiwigo.transverse.util.ImagesUtil;
    1518import fr.mael.jiwigo.transverse.util.Tools;
     
    3235 *
    3336 */
    34 public class ImageService {
     37public class ImageServiceImpl implements ImageService {
    3538
    3639    /**
    3740     * Logger
    3841     */
    39     public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
    40             .getLog(ImageService.class);
     42    private final Logger LOG = LoggerFactory.getLogger(ImageServiceImpl.class);
    4143
    42     /**
    43      * Singleton
    44      */
    45     private static ImageService instance;
    46 
    47     private SessionManager sessionManager;
    48 
    49     /**
    50      * @return the singleton
    51      */
    52     public static ImageService getInstance(SessionManager sessionManager) {
    53         if (instance == null) {
    54             instance = new ImageService(sessionManager);
    55         }
    56         return instance;
    57     }
    58 
    59     /**
    60      * private constructor to use a singleton
    61      */
    62     private ImageService(SessionManager sessionManager) {
    63         this.sessionManager = sessionManager;
    64     }
     44    private ImageDao dao;
    6545
    6646    /**
     
    7353    public List<Image> listByCategory(Integer categoryId, boolean rafraichir) throws IOException,
    7454            ProxyAuthenticationException {
    75         return ImageDao.getInstance(sessionManager).listByCategory(categoryId, rafraichir);
     55        return dao.listByCategory(categoryId, rafraichir);
    7656    }
    7757
     
    127107        image.setPrivacyLevel(String.valueOf(privacyLevel));
    128108        //now we call the dao to send the image to the webservice
    129         return ImageDao.getInstance(sessionManager).create(image, chunckSize * 1000000);
     109        return dao.create(image, chunckSize * 1000000);
    130110    }
    131111
     
    139119     */
    140120    public boolean addTags(Image image, String tagId) throws IOException, ProxyAuthenticationException {
    141         return ImageDao.getInstance(sessionManager).addTags(image.getIdentifier(), tagId);
     121        return dao.addTags(image.getIdentifier(), tagId);
    142122    }
    143123
     
    150130     */
    151131    public List<Image> search(String queryString) throws IOException, ProxyAuthenticationException {
    152         return ImageDao.getInstance(sessionManager).search(queryString);
     132        return dao.search(queryString);
    153133    }
    154134
     
    165145    }
    166146
     147    public ImageDao getDao() {
     148        return dao;
     149    }
     150
     151    public void setDao(ImageDao dao) {
     152        this.dao = dao;
     153    }
     154
    167155}
Note: See TracChangeset for help on using the changeset viewer.