Ignore:
Timestamp:
May 3, 2011, 8:25:38 PM (13 years ago)
Author:
mlg
Message:

Adds support for changing level on addSimple.

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

Legend:

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

    r10716 r10749  
    7070    public List<Image> search(String searchString) throws JiwigoException;
    7171
     72    //    /**
     73    //     * Uses the pwg.images.addsimple web API to add a new picture
     74    //     * http://piwigo.org/doc/doku.php?id=en:dev:webapi:pwg.images.addsimple
     75    //     *
     76    //     * @param file
     77    //     * @param category
     78    //     * @param title
     79    //     * @throws IOException
     80    //     * @throws JiwigoException
     81    //     */
     82    //    public void addSimple(File file, Integer category, String title) throws JiwigoException;
     83
    7284    /**
    7385     * Uses the pwg.images.addsimple web API to add a new picture
     
    7789     * @param category
    7890     * @param title
     91     * @param level
    7992     * @throws IOException
    8093     * @throws JiwigoException
    8194     */
    82     public void addSimple(File file, Integer category, String title) throws JiwigoException;
     95    public void addSimple(File file, Integer category, String title, Integer level) throws JiwigoException;
    8396
    8497    /**
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/ImageDaoImpl.java

    r10719 r10749  
    141141    public boolean create(Image image, Double chunkSize) throws FileAlreadyExistsException, IOException,
    142142            ProxyAuthenticationException, NoSuchAlgorithmException, WrongChunkSizeException, JiwigoException {
     143        if (exists(image)) {
     144            throw new FileAlreadyExistsException("Photo already exists");
     145        }
    143146        //thumbnail converted to base64
    144147        BASE64Encoder base64 = new BASE64Encoder();
     
    196199        return reussite;
    197200
     201    }
     202
     203    /**
     204     * Function to test if a photo already exists
     205     * @param image the image to test
     206     * @return true if the photo exists
     207     * @throws JiwigoException
     208     */
     209    private boolean exists(Image image) throws JiwigoException {
     210        try {
     211            String imageMD5 = Tools.getMD5Checksum(image.getOriginale().getAbsolutePath());
     212            Document docResult = sessionManager.executeReturnDocument(MethodsEnum.IMAGE_EXIST.getLabel(),
     213                    "md5sum_list", imageMD5);
     214            String result = Tools.getStringValueDom(docResult.getDocumentElement(), imageMD5);
     215
     216            if (result != null && !"".equals(result)) {
     217                return true;
     218            } else {
     219                return false;
     220            }
     221        } catch (NoSuchAlgorithmException e) {
     222            throw new JiwigoException(e);
     223        } catch (IOException e) {
     224            throw new JiwigoException(e);
     225        }
    198226    }
    199227
     
    279307    }
    280308
    281     public void addSimple(File file, Integer category, String title) throws JiwigoException {
     309    public void addSimple(File file, Integer category, String title, Integer level) throws JiwigoException {
    282310        HttpPost httpMethod = new HttpPost(((SessionManagerImpl) sessionManager).getUrl());
    283311
     
    299327                multipartEntity.addPart("category", new StringBody(category.toString()));
    300328                multipartEntity.addPart("name", new StringBody(title));
     329                if (level != null) {
     330                    multipartEntity.addPart("level", new StringBody(level.toString()));
     331                }
    301332            } catch (UnsupportedEncodingException e) {
    302333                throw new JiwigoException(e);
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/ImageService.java

    r10716 r10749  
    7474
    7575    /**
     76     * Uses the pwg.images.addsimple web API to add a new picture
     77     * http://piwigo.org/doc/doku.php?id=en:dev:webapi:pwg.images.addsimple
     78     *
     79     * @param file
     80     * @param category
     81     * @param title
     82     * @param level
     83     * @throws IOException
     84     * @throws JiwigoException
     85     */
     86    public void addSimple(File file, Integer category, String title, Integer level) throws JiwigoException;
     87
     88    /**
    7689     * Deletes an image
    7790     * @param image the image to delete
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/ImageServiceImpl.java

    r10716 r10749  
    146146
    147147    public void addSimple(File file, Integer category, String title) throws JiwigoException {
    148         dao.addSimple(file, category, title);
     148        dao.addSimple(file, category, title, null);
    149149
    150150    }
     
    167167    }
    168168
     169    @Override
     170    public void addSimple(File file, Integer category, String title, Integer level) throws JiwigoException {
     171        dao.addSimple(file, category, title, level);
     172    }
     173
    169174}
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/enumeration/MethodsEnum.java

    r10716 r10749  
    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"), DELETE_IMAGE("pwg.images.delete"), SESSION_STATUS("pwg.session.getStatus");
     30            "pwg.categories.delete"), DELETE_IMAGE("pwg.images.delete"), SESSION_STATUS("pwg.session.getStatus"), IMAGE_EXIST(
     31            "pwg.images.exist");
    3132
    3233    protected String label;
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/exception/JiwigoException.java

    r10505 r10749  
    1313    }
    1414
     15    public JiwigoException(String msg, Throwable t) {
     16        super(msg, t);
     17    }
     18
    1519}
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/Tools.java

    r10714 r10749  
    366366    public static void setStringValueDom(Element element, String tagName, String value) {
    367367        Element el = (Element) element.getElementsByTagName(tagName).item(0);
    368         el.setNodeValue(value);
     368        el.setTextContent(value);
    369369    }
    370370
     
    387387        }
    388388    }
     389    //
     390    //    /**
     391    //     * Function used to get the md5 sum of a file
     392    //     * @param fileToTest the file
     393    //     * @return the md5 sum
     394    //     * @throws NoSuchAlgorithmException
     395    //     * @throws FileNotFoundException
     396    //     * @throws JiwigoException
     397    //     */
     398    //    public static String getMD5Sum(File file) throws NoSuchAlgorithmException, JiwigoException, FileNotFoundException {
     399    //  MessageDigest digest = MessageDigest.getInstance("MD5");
     400    //  InputStream is = new FileInputStream(file);
     401    //  byte[] buffer = new byte[8192];
     402    //  int read = 0;
     403    //  try {
     404    //      while ((read = is.read(buffer)) > 0) {
     405    //          digest.update(buffer, 0, read);
     406    //      }
     407    //      byte[] md5sum = digest.digest();
     408    //      BigInteger bigInt = new BigInteger(1, md5sum);
     409    //      String output = bigInt.toString(16);
     410    //      return output;
     411    //  } catch (IOException e) {
     412    //      throw new JiwigoException("Unable to process file for MD5", e);
     413    //  } finally {
     414    //      try {
     415    //          is.close();
     416    //      } catch (IOException e) {
     417    //          throw new JiwigoException("Unable to close input stream for MD5 calculation", e);
     418    //      }
     419    //  }
     420    //    }
     421
    389422}
Note: See TracChangeset for help on using the changeset viewer.