Changeset 10716


Ignore:
Timestamp:
May 1, 2011, 12:44:59 PM (9 years ago)
Author:
mlg
Message:

Adds support for pwg.images.delete function
(deletes image).

Location:
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo
Files:
8 edited

Legend:

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

    r10505 r10716  
    8282    public void addSimple(File file, Integer category, String title) throws JiwigoException;
    8383
     84    /**
     85     * Deletes an image
     86     * @param image the image to delete
     87     * @throws JiwigoException
     88     */
     89    public boolean delete(Image image) throws JiwigoException;
     90
    8491}
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/CategoryDaoImpl.java

    r10714 r10716  
    116116    public boolean delete(Category category) throws JiwigoException {
    117117        //this document will allow to get pwg_token. it is necessary to delete a category
    118         Document docStatus = sessionManager.executeReturnDocument(MethodsEnum.SESSION_STATUS.getLabel());
    119         String pwgToken = Tools.getStringValueDom(docStatus.getDocumentElement(), "pwg_token");
    120         if (pwgToken.equals("")) {
    121             throw new JiwigoException("Error getting pwg_token. Returned document was : "
    122                     + Tools.documentToString(docStatus));
     118        String pwgToken = sessionManager.getPwgToken();
     119        if (pwgToken == null) {
     120            throw new JiwigoException("Error : received a null pwg_token");
    123121        }
    124122        if (LOG.isDebugEnabled()) {
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/ImageDaoImpl.java

    r10714 r10716  
    356356    }
    357357
     358    /**
     359     * @see fr.mael.jiwigo.dao.ImageDao#delete(fr.mael.jiwigo.om.Image)
     360     */
     361    public boolean delete(Image image) throws JiwigoException {
     362        //this document will allow to get pwg_token. it is necessary to delete an image
     363        String pwgToken = sessionManager.getPwgToken();
     364        if (pwgToken == null) {
     365            throw new JiwigoException("Error : received a null pwg_token");
     366        }
     367        if (LOG.isDebugEnabled()) {
     368            LOG.debug("Deletes image " + image.getIdentifier() + " with pwg_token = " + pwgToken);
     369        }
     370
     371        Document doc = sessionManager.executeReturnDocument(MethodsEnum.DELETE_IMAGE.getLabel(), "image_id",
     372                String.valueOf(image.getIdentifier()), "pwg_token", pwgToken);
     373
     374        if (LOG.isDebugEnabled()) {
     375            LOG.debug(Tools.documentToString(doc));
     376        }
     377        try {
     378            return Tools.checkOk(doc);
     379        } catch (FileAlreadyExistsException e) {
     380            e.printStackTrace();
     381        }
     382        return false;
     383
     384    }
     385
    358386    public SessionManager getSessionManager() {
    359387        return sessionManager;
     
    363391        this.sessionManager = sessionManager;
    364392    }
     393
    365394}
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/ImageService.java

    r10505 r10716  
    4040    public boolean create(String filePath, Integer idCategory, Integer originalWidth, Integer originalHeight,
    4141            Double chunckSize, Integer privacyLevel) throws IOException, NoSuchAlgorithmException,
    42             FileAlreadyExistsException, ProxyAuthenticationException, WrongChunkSizeException,
    43             JiwigoException;
     42            FileAlreadyExistsException, ProxyAuthenticationException, WrongChunkSizeException, JiwigoException;
    4443
    4544    /**
     
    7473    public void addSimple(File file, Integer category, String title) throws JiwigoException;
    7574
     75    /**
     76     * Deletes an image
     77     * @param image the image to delete
     78     * @throws JiwigoException
     79     */
     80    public boolean delete(Image image) throws JiwigoException;
     81
    7682}
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/ImageServiceImpl.java

    r10505 r10716  
    7373    public boolean create(String filePath, Integer idCategory, Integer originalWidth, Integer originalHeight,
    7474            Double chunckSize, Integer privacyLevel) throws IOException, NoSuchAlgorithmException,
    75             FileAlreadyExistsException, ProxyAuthenticationException, WrongChunkSizeException,
    76             JiwigoException {
     75            FileAlreadyExistsException, ProxyAuthenticationException, WrongChunkSizeException, JiwigoException {
    7776        File originalFile = new File(filePath);
    7877        //get the byte array of the original file, to keep metadata
     
    151150    }
    152151
     152    public boolean delete(Image image) throws JiwigoException {
     153        if (image.getIdentifier() == null) {
     154            throw new JiwigoException("The identifier of the image cannot be null");
     155        } else {
     156            return dao.delete(image);
     157        }
     158
     159    }
     160
    153161    public ImageDao getDao() {
    154162        return dao;
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/enumeration/MethodsEnum.java

    r10714 r10716  
    2828            "pwg.images.setInfo"), SEARCH("pwg.images.search"), SET_PRIVACY_LEVEL("pwg.images.setPrivacyLevel"), ADD_SIMPLE(
    2929            "pwg.images.addSimple"), ADD_IMAGE("pwg.images.add"), ADD_CHUNK("pwg.images.addChunk"), DELETE_CATEGORY(
    30             "pwg.categories.delete"), SESSION_STATUS("pwg.session.getStatus");
     30            "pwg.categories.delete"), DELETE_IMAGE("pwg.images.delete"), SESSION_STATUS("pwg.session.getStatus");
    3131
    3232    protected String label;
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/SessionManager.java

    r10698 r10716  
    127127     */
    128128    public InputStream getInputStreamFromUrl(String url) throws Exception;
     129
     130    /**
     131     * This method allows to get pwg_token. This string is necessary
     132     * to call web service functions like pwg.images.delete and pwg.categories.delete
     133     * @return pwg_token
     134     */
     135    public String getPwgToken() throws JiwigoException;
     136
    129137}
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/impl/SessionManagerImpl.java

    r10714 r10716  
    266266
    267267    /**
     268     * @see fr.mael.jiwigo.transverse.session.SessionManager#getPwgToken()
     269     */
     270    public String getPwgToken() throws JiwigoException {
     271        Document docStatus = executeReturnDocument(MethodsEnum.SESSION_STATUS.getLabel());
     272        String pwgToken = Tools.getStringValueDom(docStatus.getDocumentElement(), "pwg_token");
     273        if ("".equals(pwgToken)) {
     274            throw new JiwigoException("Error getting pwg_token. Returned document was : "
     275                    + Tools.documentToString(docStatus));
     276        }
     277        return pwgToken;
     278    }
     279
     280    /**
    268281     * @return the login
    269282     */
Note: See TracChangeset for help on using the changeset viewer.