Changeset 10749 for extensions/jiwigo-ws-api/src
- Timestamp:
- May 3, 2011, 8:25:38 PM (14 years ago)
- 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 70 70 public List<Image> search(String searchString) throws JiwigoException; 71 71 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 72 84 /** 73 85 * Uses the pwg.images.addsimple web API to add a new picture … … 77 89 * @param category 78 90 * @param title 91 * @param level 79 92 * @throws IOException 80 93 * @throws JiwigoException 81 94 */ 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; 83 96 84 97 /** -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/ImageDaoImpl.java
r10719 r10749 141 141 public boolean create(Image image, Double chunkSize) throws FileAlreadyExistsException, IOException, 142 142 ProxyAuthenticationException, NoSuchAlgorithmException, WrongChunkSizeException, JiwigoException { 143 if (exists(image)) { 144 throw new FileAlreadyExistsException("Photo already exists"); 145 } 143 146 //thumbnail converted to base64 144 147 BASE64Encoder base64 = new BASE64Encoder(); … … 196 199 return reussite; 197 200 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 } 198 226 } 199 227 … … 279 307 } 280 308 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 { 282 310 HttpPost httpMethod = new HttpPost(((SessionManagerImpl) sessionManager).getUrl()); 283 311 … … 299 327 multipartEntity.addPart("category", new StringBody(category.toString())); 300 328 multipartEntity.addPart("name", new StringBody(title)); 329 if (level != null) { 330 multipartEntity.addPart("level", new StringBody(level.toString())); 331 } 301 332 } catch (UnsupportedEncodingException e) { 302 333 throw new JiwigoException(e); -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/ImageService.java
r10716 r10749 74 74 75 75 /** 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 /** 76 89 * Deletes an image 77 90 * @param image the image to delete -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/ImageServiceImpl.java
r10716 r10749 146 146 147 147 public void addSimple(File file, Integer category, String title) throws JiwigoException { 148 dao.addSimple(file, category, title );148 dao.addSimple(file, category, title, null); 149 149 150 150 } … … 167 167 } 168 168 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 169 174 } -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/enumeration/MethodsEnum.java
r10716 r10749 28 28 "pwg.images.setInfo"), SEARCH("pwg.images.search"), SET_PRIVACY_LEVEL("pwg.images.setPrivacyLevel"), ADD_SIMPLE( 29 29 "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"); 31 32 32 33 protected String label; -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/exception/JiwigoException.java
r10505 r10749 13 13 } 14 14 15 public JiwigoException(String msg, Throwable t) { 16 super(msg, t); 17 } 18 15 19 } -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/Tools.java
r10714 r10749 366 366 public static void setStringValueDom(Element element, String tagName, String value) { 367 367 Element el = (Element) element.getElementsByTagName(tagName).item(0); 368 el.set NodeValue(value);368 el.setTextContent(value); 369 369 } 370 370 … … 387 387 } 388 388 } 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 389 422 }
Note: See TracChangeset
for help on using the changeset viewer.