Changeset 9893


Ignore:
Timestamp:
Mar 27, 2011, 1:03:05 PM (13 years ago)
Author:
mlg
Message:

Adds a better Exception management
new Exception : FileAlreadyExistsException.

Location:
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo
Files:
1 added
7 edited

Legend:

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

    r9879 r9893  
    1111import fr.mael.jiwigo.transverse.enumeration.CategoryEnum;
    1212import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
     13import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException;
    1314import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    1415import fr.mael.jiwigo.transverse.session.SessionManager;
     
    112113        } catch (IOException e) {
    113114            LOG.error(Tools.getStackTrace(e));
     115        } catch (FileAlreadyExistsException e) {
     116            LOG.error(Tools.getStackTrace(e));
    114117        }
    115118        return false;
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/CommentDao.java

    r9879 r9893  
    1010import fr.mael.jiwigo.om.Comment;
    1111import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
     12import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException;
    1213import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    1314import fr.mael.jiwigo.transverse.session.SessionManager;
     
    113114            e.printStackTrace();
    114115        }
    115         return Tools.checkOk(sessionManager.executeReturnDocument(MethodsEnum.AJOUTER_COMMENTAIRE.getLabel(),
    116                 "image_id", String.valueOf(commentaire.getImageId()), "author", commentaire.getAuthor(), "content",
    117                 commentaire.getContent(), "key", key));
     116        try {
     117            return Tools.checkOk(sessionManager.executeReturnDocument(MethodsEnum.AJOUTER_COMMENTAIRE.getLabel(),
     118                    "image_id", String.valueOf(commentaire.getImageId()), "author", commentaire.getAuthor(), "content",
     119                    commentaire.getContent(), "key", key));
     120        } catch (FileAlreadyExistsException e) {
     121            LOG.error(Tools.getStackTrace(e));
     122            return false;
     123        }
    118124
    119125    }
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/ImageDao.java

    r9879 r9893  
    33import java.io.File;
    44import java.io.IOException;
     5import java.security.NoSuchAlgorithmException;
    56import java.util.ArrayList;
    67import java.util.HashMap;
     
    1314import fr.mael.jiwigo.om.Image;
    1415import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
     16import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException;
    1517import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    1618import fr.mael.jiwigo.transverse.exception.WrongChunkSizeException;
     
    133135     * @param image the image to create
    134136     * @return true if the creation of the image was the successful
     137     * @throws IOException
     138     * @throws NoSuchAlgorithmException
     139     * @throws WrongChunkSizeException
    135140     * @throws Exception
    136141     */
    137142    //TODO ne pas continuer si une des reponses precedentes est negative
    138     public boolean create(Image image, Double chunkSize) throws Exception {
     143    public boolean create(Image image, Double chunkSize) throws FileAlreadyExistsException, IOException,
     144            ProxyAuthenticationException, NoSuchAlgorithmException, WrongChunkSizeException {
    139145        //thumbnail converted to base64
    140146        BASE64Encoder base64 = new BASE64Encoder();
     
    201207        Document doc = sessionManager.executeReturnDocument(MethodsEnum.SET_INFO.getLabel(), "image_id", String
    202208                .valueOf(imageId), "tag_ids", tagId);
    203         return Tools.checkOk(doc);
     209        try {
     210            return Tools.checkOk(doc);
     211        } catch (FileAlreadyExistsException e) {
     212            LOG.error(Tools.getStackTrace(e));
     213            return false;
     214        }
    204215
    205216    }
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/TagDao.java

    r9879 r9893  
    1212import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
    1313import fr.mael.jiwigo.transverse.enumeration.TagEnum;
     14import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException;
    1415import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    1516import fr.mael.jiwigo.transverse.session.SessionManager;
     
    105106        } catch (IOException e) {
    106107            LOG.error(Tools.getStackTrace(e));
     108        } catch (FileAlreadyExistsException e) {
     109            e.printStackTrace();
    107110        }
    108111        return false;
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/ImageService.java

    r9879 r9893  
    33import java.io.File;
    44import java.io.IOException;
     5import java.security.NoSuchAlgorithmException;
    56import java.util.List;
    67
    78import fr.mael.jiwigo.dao.ImageDao;
    89import fr.mael.jiwigo.om.Image;
     10import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException;
    911import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
     12import fr.mael.jiwigo.transverse.exception.WrongChunkSizeException;
    1013import fr.mael.jiwigo.transverse.session.SessionManager;
    1114import fr.mael.jiwigo.transverse.util.ImagesUtil;
     
    8083     * @param originalHeight height for the original image
    8184     * @return true if the image is created
     85     * @throws IOException
     86     * @throws WrongChunkSizeException
     87     * @throws ProxyAuthenticationException
     88     * @throws FileAlreadyExistsException
     89     * @throws NoSuchAlgorithmException
    8290     * @throws Exception
    8391     */
    8492    public boolean create(String filePath, Integer idCategory, Integer originalWidth, Integer originalHeight,
    85             Double chunckSize, Integer privacyLevel) throws Exception {
     93            Double chunckSize, Integer privacyLevel) throws IOException, NoSuchAlgorithmException,
     94            FileAlreadyExistsException, ProxyAuthenticationException, WrongChunkSizeException {
    8695        File originalFile = new File(filePath);
    8796        //get the byte array of the original file, to keep metadata
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/ImagesUtil.java

    r9879 r9893  
    9797     * @param height the height
    9898     * @return true if successful
     99     * @throws IOException
    99100     * @throws Exception
    100101     */
    101     public static boolean scale(String filePath, String tempName, int width, int height) throws Exception {
     102    public static boolean scale(String filePath, String tempName, int width, int height) throws IOException {
    102103        File file = new File(filePath);
    103104        InputStream imageStream = new BufferedInputStream(new FileInputStream(filePath));
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/Tools.java

    r9879 r9893  
    1717import java.net.URLClassLoader;
    1818import java.security.MessageDigest;
     19import java.security.NoSuchAlgorithmException;
    1920import java.util.ArrayList;
    2021
     
    3233import org.jdom.output.XMLOutputter;
    3334
     35import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException;
     36
    3437/*
    3538 *  jiwigo-ws-api Piwigo webservice access Api
     
    123126     * @param filename the path of the file
    124127     * @return the checksum
     128     * @throws IOException
     129     * @throws NoSuchAlgorithmException
    125130     * @throws Exception
    126131     */
    127     public static String getMD5Checksum(String filename) throws Exception {
     132    public static String getMD5Checksum(String filename) throws NoSuchAlgorithmException, IOException {
    128133        byte[] b = createChecksum(filename);
    129134        String result = "";
     
    138143     * @param filename the path of the file
    139144     * @return the checksum as array byte
     145     * @throws NoSuchAlgorithmException
     146     * @throws IOException
    140147     * @throws Exception
    141148     */
    142     private static byte[] createChecksum(String filename) throws Exception {
     149    private static byte[] createChecksum(String filename) throws NoSuchAlgorithmException, IOException {
    143150        InputStream fis = new FileInputStream(filename);
    144151
     
    185192     * @return true if ok
    186193     */
    187     public static boolean checkOk(Document doc) {
     194    public static boolean checkOk(Document doc) throws FileAlreadyExistsException {
    188195        if (doc.getRootElement().getAttributeValue("stat").equals("ok")) {
    189196            return true;
     
    191198            LOG.error("Resultat : " + doc.getRootElement().getAttributeValue("stat") + "\nDocument retourné : \n"
    192199                    + Tools.documentToString(doc));
     200            if (doc.getRootElement().getChild("err").getAttributeValue("msg").equals("file already exists")) {
     201                throw new FileAlreadyExistsException("The file already exists on the server");
     202            }
    193203            return false;
    194204        }
Note: See TracChangeset for help on using the changeset viewer.