Changeset 10505 for extensions/jiwigo-ws-api
- Timestamp:
- Apr 20, 2011, 5:17:02 AM (13 years ago)
- Location:
- extensions/jiwigo-ws-api/src
- Files:
-
- 1 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/CategoryDao.java
r9919 r10505 5 5 6 6 import fr.mael.jiwigo.om.Category; 7 import fr.mael.jiwigo.transverse.exception.JiwigoException; 7 8 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 8 9 … … 15 16 * @throws IOException 16 17 * @throws ProxyAuthenticationException 18 * @throws JiwigoException 17 19 */ 18 public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException;20 public List<Category> list(boolean recursive) throws JiwigoException; 19 21 20 22 /** … … 23 25 * @return true if the category is successfully created 24 26 * @throws ProxyAuthenticationException 27 * @throws JiwigoException 25 28 */ 26 public boolean create(Category category) throws ProxyAuthenticationException;29 public boolean create(Category category) throws JiwigoException; 27 30 } -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/CommentDao.java
r9919 r10505 5 5 6 6 import fr.mael.jiwigo.om.Comment; 7 import fr.mael.jiwigo.transverse.exception.JiwigoException; 7 8 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 8 9 … … 15 16 * @throws ProxyAuthenticationException 16 17 */ 17 public List<Comment> list(Integer idImage) throws IOException, ProxyAuthenticationException;18 public List<Comment> list(Integer idImage) throws JiwigoException; 18 19 19 20 /** … … 24 25 * @throws ProxyAuthenticationException 25 26 */ 26 public String getKey(Integer idImage) throws IOException, ProxyAuthenticationException;27 public String getKey(Integer idImage) throws JiwigoException; 27 28 28 29 /** … … 33 34 * @throws ProxyAuthenticationException 34 35 */ 35 public boolean create(Comment commentaire) throws IOException, ProxyAuthenticationException;36 public boolean create(Comment commentaire) throws JiwigoException; 36 37 } -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/ImageDao.java
r10494 r10505 8 8 import fr.mael.jiwigo.om.Image; 9 9 import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException; 10 import fr.mael.jiwigo.transverse.exception.JiwigoException; 10 11 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 11 12 import fr.mael.jiwigo.transverse.exception.WrongChunkSizeException; … … 18 19 * @throws ProxyAuthenticationException 19 20 */ 20 public List<Image> list(boolean refresh) throws IOException, ProxyAuthenticationException;21 public List<Image> list(boolean refresh) throws JiwigoException; 21 22 22 23 /** … … 27 28 * @throws ProxyAuthenticationException 28 29 */ 29 public List<Image> listByCategory(Integer categoryId, boolean refresh) throws IOException, 30 ProxyAuthenticationException; 30 public List<Image> listByCategory(Integer categoryId, boolean refresh) throws JiwigoException; 31 31 32 32 /** … … 45 45 * @throws NoSuchAlgorithmException 46 46 * @throws WrongChunkSizeException 47 * @throws JiwigoException 47 48 * @throws Exception 48 49 */ 49 50 //TODO ne pas continuer si une des reponses precedentes est negative 50 51 public boolean create(Image image, Double chunkSize) throws FileAlreadyExistsException, IOException, 51 ProxyAuthenticationException, NoSuchAlgorithmException, WrongChunkSizeException ;52 ProxyAuthenticationException, NoSuchAlgorithmException, WrongChunkSizeException, JiwigoException; 52 53 53 54 /** … … 58 59 * @throws ProxyAuthenticationException 59 60 */ 60 public boolean addTags(Integer imageId, String tagId) throws IOException, ProxyAuthenticationException;61 public boolean addTags(Integer imageId, String tagId) throws JiwigoException; 61 62 62 63 /** … … 67 68 * @throws ProxyAuthenticationException 68 69 */ 69 public List<Image> search(String searchString) throws IOException, ProxyAuthenticationException;70 public List<Image> search(String searchString) throws JiwigoException; 70 71 71 72 /** … … 77 78 * @param title 78 79 * @throws IOException 80 * @throws JiwigoException 79 81 */ 80 public void addSimple(File file, Integer category, String title) throws IOException;82 public void addSimple(File file, Integer category, String title) throws JiwigoException; 81 83 82 84 } -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/TagDao.java
r9919 r10505 1 1 package fr.mael.jiwigo.dao; 2 2 3 import java.io.IOException;4 3 import java.util.List; 5 4 6 5 import fr.mael.jiwigo.om.Image; 7 6 import fr.mael.jiwigo.om.Tag; 8 import fr.mael.jiwigo.transverse.exception. ProxyAuthenticationException;7 import fr.mael.jiwigo.transverse.exception.JiwigoException; 9 8 10 9 public interface TagDao { … … 12 11 * lists the tags 13 12 * @return the list of tags 14 * @throws IOException 15 * @throws ProxyAuthenticationException 13 * @throws JiwigoException 16 14 */ 17 public List<Tag> list() throws IOException, ProxyAuthenticationException;15 public List<Tag> list() throws JiwigoException; 18 16 19 17 /** … … 21 19 * @param tag the tag to create 22 20 * @return true if the tag as been successfully created 23 * @throws ProxyAuthenticationException21 * @throws JiwigoException 24 22 */ 25 public boolean create(Tag tag) throws ProxyAuthenticationException;23 public boolean create(Tag tag) throws JiwigoException; 26 24 27 25 /** … … 29 27 * @param image the image 30 28 * @return the tags list 31 * @throws IOException 32 * @throws ProxyAuthenticationException 29 * @throws JiwigoException 33 30 */ 34 public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException;31 public List<Tag> tagsForImage(Image image) throws JiwigoException; 35 32 } -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/CategoryDaoImpl.java
r9919 r10505 17 17 import fr.mael.jiwigo.transverse.enumeration.MethodsEnum; 18 18 import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException; 19 import fr.mael.jiwigo.transverse.exception.JiwigoException; 19 20 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 20 21 import fr.mael.jiwigo.transverse.session.SessionManager; … … 53 54 * @param recursive true : recursive listing of the categories 54 55 * @return the list of categories 56 * @throws JiwigoException 55 57 * @throws IOException 56 58 * @throws ProxyAuthenticationException 57 59 */ 58 public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException {60 public List<Category> list(boolean recursive) throws JiwigoException { 59 61 Document doc = sessionManager.executeReturnDocument(MethodsEnum.LISTER_CATEGORIES.getLabel(), "recursive", 60 62 String.valueOf(recursive)); … … 92 94 * @return true if the category is successfully created 93 95 * @throws ProxyAuthenticationException 96 * @throws JiwigoException 94 97 */ 95 public boolean create(Category category) throws ProxyAuthenticationException {98 public boolean create(Category category) throws JiwigoException { 96 99 try { 97 100 if (category.getDirectParent() != null) { … … 102 105 "name", category.getName())); 103 106 } 104 } catch (IOException e) {105 LOG.error(Tools.getStackTrace(e));106 107 } catch (FileAlreadyExistsException e) { 107 108 LOG.error(Tools.getStackTrace(e)); 109 throw new JiwigoException(e); 108 110 } 109 return false;110 111 } 111 112 -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/CommentDaoImpl.java
r9919 r10505 16 16 import fr.mael.jiwigo.transverse.enumeration.MethodsEnum; 17 17 import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException; 18 import fr.mael.jiwigo.transverse.exception.JiwigoException; 18 19 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 19 20 import fr.mael.jiwigo.transverse.session.SessionManager; … … 52 53 * @throws ProxyAuthenticationException 53 54 */ 54 public List<Comment> list(Integer idImage) throws IOException, ProxyAuthenticationException {55 Document doc = (sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String56 .valueOf(idImage), "comments_per_page", "100"));55 public List<Comment> list(Integer idImage) throws JiwigoException { 56 Document doc = (sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", 57 String.valueOf(idImage), "comments_per_page", "100")); 57 58 Element elementImage = (Element) doc.getDocumentElement().getElementsByTagName("image").item(0); 58 59 Element elementComments = (Element) elementImage.getElementsByTagName("comments").item(0); … … 81 82 * @throws ProxyAuthenticationException 82 83 */ 83 public String getKey(Integer idImage) throws IOException, ProxyAuthenticationException {84 Document doc = (sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String85 .valueOf(idImage)));84 public String getKey(Integer idImage) throws JiwigoException { 85 Document doc = (sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", 86 String.valueOf(idImage))); 86 87 // String key = doc.getRootElement().getChild("image").getChild("comment_post").getAttributeValue("key"); 87 88 Element elementImage = (Element) doc.getDocumentElement().getElementsByTagName("image").item(0); … … 97 98 * @throws ProxyAuthenticationException 98 99 */ 99 public boolean create(Comment commentaire) throws IOException, ProxyAuthenticationException {100 public boolean create(Comment commentaire) throws JiwigoException { 100 101 String key = getKey(commentaire.getImageId()); 101 102 try { -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/ImageDaoImpl.java
r10494 r10505 5 5 import java.io.IOException; 6 6 import java.io.InputStreamReader; 7 import java.io.UnsupportedEncodingException; 7 8 import java.net.HttpURLConnection; 8 9 import java.security.NoSuchAlgorithmException; … … 13 14 import org.apache.http.HttpEntity; 14 15 import org.apache.http.HttpResponse; 16 import org.apache.http.client.ClientProtocolException; 15 17 import org.apache.http.client.methods.HttpPost; 16 18 import org.apache.http.entity.BufferedHttpEntity; … … 30 32 import fr.mael.jiwigo.transverse.enumeration.MethodsEnum; 31 33 import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException; 34 import fr.mael.jiwigo.transverse.exception.JiwigoException; 32 35 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 33 36 import fr.mael.jiwigo.transverse.exception.WrongChunkSizeException; … … 84 87 * @throws ProxyAuthenticationException 85 88 */ 86 public List<Image> list(boolean refresh) throws IOException, ProxyAuthenticationException {89 public List<Image> list(boolean refresh) throws JiwigoException { 87 90 return listByCategory(null, refresh); 88 91 } … … 95 98 * @throws ProxyAuthenticationException 96 99 */ 97 public List<Image> listByCategory(Integer categoryId, boolean refresh) throws IOException, 98 ProxyAuthenticationException { 100 public List<Image> listByCategory(Integer categoryId, boolean refresh) throws JiwigoException { 99 101 if (refresh || cache.get(categoryId) == null) { 100 102 Document doc = null; … … 133 135 * @throws NoSuchAlgorithmException 134 136 * @throws WrongChunkSizeException 137 * @throws JiwigoException 135 138 * @throws Exception 136 139 */ 137 140 //TODO ne pas continuer si une des reponses precedentes est negative 138 141 public boolean create(Image image, Double chunkSize) throws FileAlreadyExistsException, IOException, 139 ProxyAuthenticationException, NoSuchAlgorithmException, WrongChunkSizeException {142 ProxyAuthenticationException, NoSuchAlgorithmException, WrongChunkSizeException, JiwigoException { 140 143 //thumbnail converted to base64 141 144 BASE64Encoder base64 = new BASE64Encoder(); … … 200 203 * @throws ProxyAuthenticationException 201 204 */ 202 public boolean addTags(Integer imageId, String tagId) throws IOException, ProxyAuthenticationException {205 public boolean addTags(Integer imageId, String tagId) throws JiwigoException { 203 206 Document doc = sessionManager.executeReturnDocument(MethodsEnum.SET_INFO.getLabel(), "image_id", 204 207 String.valueOf(imageId), "tag_ids", tagId); … … 253 256 * @throws ProxyAuthenticationException 254 257 */ 255 public List<Image> search(String searchString) throws IOException, ProxyAuthenticationException {258 public List<Image> search(String searchString) throws JiwigoException { 256 259 Document doc = sessionManager.executeReturnDocument(MethodsEnum.SEARCH.getLabel(), "query", searchString); 257 260 LOG.debug(Tools.documentToString(doc)); … … 272 275 } 273 276 274 public void addSimple(File file, Integer category, String title) throws IOException {277 public void addSimple(File file, Integer category, String title) throws JiwigoException { 275 278 HttpPost httpMethod = new HttpPost(((SessionManagerImpl) sessionManager).getUrl()); 276 279 … … 288 291 // String substring = string.substring(string.indexOf("{"), 289 292 // string.lastIndexOf("}") + 1); 290 multipartEntity.addPart("method", new StringBody("pwg.images.addSimple")); 291 multipartEntity.addPart("category", new StringBody(category.toString())); 292 multipartEntity.addPart("name", new StringBody(title)); 293 try { 294 multipartEntity.addPart("method", new StringBody("pwg.images.addSimple")); 295 multipartEntity.addPart("category", new StringBody(category.toString())); 296 multipartEntity.addPart("name", new StringBody(title)); 297 } catch (UnsupportedEncodingException e) { 298 throw new JiwigoException(e); 299 } 293 300 294 301 // StringBody contentBody = new StringBody(substring, … … 300 307 } 301 308 302 // httpMethod.setHeader(X_GALLERY_REQUEST_METHOD, requestMethod); 303 HttpResponse response = ((SessionManagerImpl) sessionManager).getClient().execute(httpMethod); 304 int responseStatusCode = response.getStatusLine().getStatusCode(); 305 306 switch (responseStatusCode) { 307 case HttpURLConnection.HTTP_CREATED: 308 break; 309 case HttpURLConnection.HTTP_OK: 310 break; 311 case HttpURLConnection.HTTP_BAD_REQUEST: 312 throw new IOException("status code was : " + responseStatusCode); 313 case HttpURLConnection.HTTP_FORBIDDEN: 314 throw new IOException("status code was : " + responseStatusCode); 315 case HttpURLConnection.HTTP_NOT_FOUND: 316 throw new IOException("status code was : " + responseStatusCode); 317 default: 318 throw new IOException("status code was : " + responseStatusCode); 319 } 320 321 HttpEntity resultEntity = response.getEntity(); 322 BufferedHttpEntity responseEntity = new BufferedHttpEntity(resultEntity); 323 324 BufferedReader reader = new BufferedReader(new InputStreamReader(responseEntity.getContent())); 325 String line; 309 HttpResponse response; 326 310 StringBuilder sb = new StringBuilder(); 327 311 try { 328 while ((line = reader.readLine()) != null) { 329 sb.append(line); 330 sb.append("\n"); 331 } 332 } finally { 333 reader.close(); 312 response = ((SessionManagerImpl) sessionManager).getClient().execute(httpMethod); 313 314 int responseStatusCode = response.getStatusLine().getStatusCode(); 315 316 switch (responseStatusCode) { 317 case HttpURLConnection.HTTP_CREATED: 318 break; 319 case HttpURLConnection.HTTP_OK: 320 break; 321 case HttpURLConnection.HTTP_BAD_REQUEST: 322 throw new JiwigoException("status code was : " + responseStatusCode); 323 case HttpURLConnection.HTTP_FORBIDDEN: 324 throw new JiwigoException("status code was : " + responseStatusCode); 325 case HttpURLConnection.HTTP_NOT_FOUND: 326 throw new JiwigoException("status code was : " + responseStatusCode); 327 default: 328 throw new JiwigoException("status code was : " + responseStatusCode); 329 } 330 331 HttpEntity resultEntity = response.getEntity(); 332 BufferedHttpEntity responseEntity = new BufferedHttpEntity(resultEntity); 333 334 BufferedReader reader = new BufferedReader(new InputStreamReader(responseEntity.getContent())); 335 String line; 336 337 try { 338 while ((line = reader.readLine()) != null) { 339 sb.append(line); 340 sb.append("\n"); 341 } 342 } finally { 343 reader.close(); 344 } 345 } catch (ClientProtocolException e) { 346 throw new JiwigoException(e); 347 } catch (IOException e) { 348 throw new JiwigoException(e); 334 349 } 335 350 String stringResult = sb.toString(); -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/TagDaoImpl.java
r9919 r10505 18 18 import fr.mael.jiwigo.transverse.enumeration.TagEnum; 19 19 import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException; 20 import fr.mael.jiwigo.transverse.exception.JiwigoException; 20 21 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 21 22 import fr.mael.jiwigo.transverse.session.SessionManager; … … 52 53 * @throws ProxyAuthenticationException 53 54 */ 54 public List<Tag> list() throws IOException, ProxyAuthenticationException {55 public List<Tag> list() throws JiwigoException { 55 56 Document doc = sessionManager.executeReturnDocument(MethodsEnum.TAGS_ADMIN_LIST.getLabel()); 56 57 // System.out.println(Outil.documentToString(doc)); … … 90 91 * @throws ProxyAuthenticationException 91 92 */ 92 public boolean create(Tag tag) throws ProxyAuthenticationException {93 public boolean create(Tag tag) throws JiwigoException { 93 94 try { 94 return Tools.checkOk(sessionManager.executeReturnDocument(MethodsEnum.ADD_TAG.getLabel(), "name", tag95 .getName()));96 } catch ( IOException e) {95 return Tools.checkOk(sessionManager.executeReturnDocument(MethodsEnum.ADD_TAG.getLabel(), "name", 96 tag.getName())); 97 } catch (FileAlreadyExistsException e) { 97 98 LOG.error(Tools.getStackTrace(e)); 98 } catch (FileAlreadyExistsException e) { 99 e.printStackTrace(); 99 throw new JiwigoException(e); 100 100 } 101 return false;102 101 } 103 102 … … 107 106 * @return the tags list 108 107 * @throws IOException 109 * @throws ProxyAuthenticationException108 * @throws JiwigoException 110 109 */ 111 public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException {112 Document doc = sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String113 .valueOf(image.getIdentifier()));110 public List<Tag> tagsForImage(Image image) throws JiwigoException { 111 Document doc = sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", 112 String.valueOf(image.getIdentifier())); 114 113 Element elementImage = (Element) doc.getDocumentElement().getElementsByTagName("image").item(0); 115 114 Element elementTag = (Element) elementImage.getElementsByTagName("tags").item(0); -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CategoryService.java
r9919 r10505 5 5 6 6 import fr.mael.jiwigo.om.Category; 7 import fr.mael.jiwigo.transverse.exception.JiwigoException; 7 8 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 8 9 … … 15 16 * @throws ProxyAuthenticationException 16 17 */ 17 public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException;18 public List<Category> list(boolean recursive) throws JiwigoException; 18 19 19 20 /** … … 23 24 * @throws ProxyAuthenticationException 24 25 */ 25 public List<Category> makeTree() throws IOException, ProxyAuthenticationException;26 public List<Category> makeTree() throws JiwigoException; 26 27 27 28 /** … … 32 33 * @throws ProxyAuthenticationException 33 34 */ 34 public boolean create(String nom, Integer parent) throws ProxyAuthenticationException;35 public boolean create(String nom, Integer parent) throws JiwigoException; 35 36 36 37 /** … … 40 41 * @throws ProxyAuthenticationException 41 42 */ 42 public boolean create(String nom) throws ProxyAuthenticationException;43 public boolean create(String nom) throws JiwigoException; 43 44 } -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CommentService.java
r9919 r10505 5 5 6 6 import fr.mael.jiwigo.om.Comment; 7 import fr.mael.jiwigo.transverse.exception.JiwigoException; 7 8 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 8 9 … … 15 16 * @throws ProxyAuthenticationException 16 17 */ 17 public List<Comment> list(Integer imageId) throws IOException, ProxyAuthenticationException;18 public List<Comment> list(Integer imageId) throws JiwigoException; 18 19 19 20 /** … … 26 27 * @throws ProxyAuthenticationException 27 28 */ 28 public boolean create(String content, Integer imageId, String auteur) throws IOException, 29 ProxyAuthenticationException; 29 public boolean create(String content, Integer imageId, String auteur) throws JiwigoException; 30 30 31 31 } -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/ImageService.java
r10494 r10505 8 8 import fr.mael.jiwigo.om.Image; 9 9 import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException; 10 import fr.mael.jiwigo.transverse.exception.JiwigoException; 10 11 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 11 12 import fr.mael.jiwigo.transverse.exception.WrongChunkSizeException; … … 20 21 * @throws ProxyAuthenticationException 21 22 */ 22 public List<Image> listByCategory(Integer categoryId, boolean rafraichir) throws IOException, 23 ProxyAuthenticationException; 23 public List<Image> listByCategory(Integer categoryId, boolean rafraichir) throws JiwigoException; 24 24 25 25 /** … … 35 35 * @throws FileAlreadyExistsException 36 36 * @throws NoSuchAlgorithmException 37 * @throws JiwigoException 37 38 * @throws Exception 38 39 */ 39 40 public boolean create(String filePath, Integer idCategory, Integer originalWidth, Integer originalHeight, 40 41 Double chunckSize, Integer privacyLevel) throws IOException, NoSuchAlgorithmException, 41 FileAlreadyExistsException, ProxyAuthenticationException, WrongChunkSizeException; 42 FileAlreadyExistsException, ProxyAuthenticationException, WrongChunkSizeException, 43 JiwigoException; 42 44 43 45 /** … … 49 51 * @throws ProxyAuthenticationException 50 52 */ 51 public boolean addTags(Image image, String tagId) throws IOException, ProxyAuthenticationException;53 public boolean addTags(Image image, String tagId) throws JiwigoException; 52 54 53 55 /** … … 58 60 * @throws ProxyAuthenticationException 59 61 */ 60 public List<Image> search(String queryString) throws IOException, ProxyAuthenticationException;62 public List<Image> search(String queryString) throws JiwigoException; 61 63 62 64 /** … … 68 70 * @param title 69 71 * @throws IOException 72 * @throws JiwigoException 70 73 */ 71 public void addSimple(File file, Integer category, String title) throws IOException;74 public void addSimple(File file, Integer category, String title) throws JiwigoException; 72 75 73 76 } -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/TagService.java
r9919 r10505 1 1 package fr.mael.jiwigo.service; 2 2 3 import java.io.IOException;4 3 import java.util.List; 5 4 6 5 import fr.mael.jiwigo.om.Image; 7 6 import fr.mael.jiwigo.om.Tag; 8 import fr.mael.jiwigo.transverse.exception. ProxyAuthenticationException;7 import fr.mael.jiwigo.transverse.exception.JiwigoException; 9 8 10 9 public interface TagService { … … 13 12 * Lists all tags 14 13 * @return le list of tags 15 * @throws IOException 16 * @throws ProxyAuthenticationException 14 * @throws JiwigoException 17 15 */ 18 public List<Tag> list() throws IOException, ProxyAuthenticationException;16 public List<Tag> list() throws JiwigoException; 19 17 20 18 /** … … 22 20 * @param nom name of the tag 23 21 * @return true if the tag is created 24 * @throws IOException 25 * @throws ProxyAuthenticationException 22 * @throws JiwigoException 26 23 */ 27 public boolean create(String nom) throws IOException, ProxyAuthenticationException;24 public boolean create(String nom) throws JiwigoException; 28 25 29 26 /** … … 31 28 * @param image the image to check 32 29 * @return the list of tags 33 * @throws IOException 34 * @throws ProxyAuthenticationException 30 * @throws JiwigoException 35 31 */ 36 public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException;32 public List<Tag> tagsForImage(Image image) throws JiwigoException; 37 33 } -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/CategoryServiceImpl.java
r9919 r10505 10 10 import fr.mael.jiwigo.om.Category; 11 11 import fr.mael.jiwigo.service.CategoryService; 12 import fr.mael.jiwigo.transverse.exception.JiwigoException; 12 13 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 13 14 … … 43 44 * @throws ProxyAuthenticationException 44 45 */ 45 public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException {46 public List<Category> list(boolean recursive) throws JiwigoException { 46 47 return dao.list(recursive); 47 48 } … … 52 53 * @throws IOException 53 54 * @throws ProxyAuthenticationException 55 * @throws JiwigoException 54 56 */ 55 public List<Category> makeTree() throws IOException, ProxyAuthenticationException {57 public List<Category> makeTree() throws JiwigoException { 56 58 List<Category> list = dao.list(true); 57 59 for (Category category : list) { … … 78 80 * @throws ProxyAuthenticationException 79 81 */ 80 public boolean create(String nom, Integer parent) throws ProxyAuthenticationException {82 public boolean create(String nom, Integer parent) throws JiwigoException { 81 83 Category category = new Category(); 82 84 category.setDirectParent(parent); … … 91 93 * @throws ProxyAuthenticationException 92 94 */ 93 public boolean create(String nom) throws ProxyAuthenticationException {95 public boolean create(String nom) throws JiwigoException { 94 96 Category category = new Category(); 95 97 category.setName(nom); -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/CommentServiceImpl.java
r9919 r10505 10 10 import fr.mael.jiwigo.om.Comment; 11 11 import fr.mael.jiwigo.service.CommentService; 12 import fr.mael.jiwigo.transverse.exception.JiwigoException; 12 13 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 13 14 … … 43 44 * @throws ProxyAuthenticationException 44 45 */ 45 public List<Comment> list(Integer imageId) throws IOException, ProxyAuthenticationException {46 public List<Comment> list(Integer imageId) throws JiwigoException { 46 47 return dao.list(imageId); 47 48 } … … 56 57 * @throws ProxyAuthenticationException 57 58 */ 58 public boolean create(String content, Integer imageId, String auteur) throws IOException, 59 ProxyAuthenticationException { 59 public boolean create(String content, Integer imageId, String auteur) throws JiwigoException { 60 60 Comment comment = new Comment(); 61 61 comment.setContent(content); -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/ImageServiceImpl.java
r10494 r10505 13 13 import fr.mael.jiwigo.service.ImageService; 14 14 import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException; 15 import fr.mael.jiwigo.transverse.exception.JiwigoException; 15 16 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 16 17 import fr.mael.jiwigo.transverse.exception.WrongChunkSizeException; … … 51 52 * @throws ProxyAuthenticationException 52 53 */ 53 public List<Image> listByCategory(Integer categoryId, boolean rafraichir) throws IOException, 54 ProxyAuthenticationException { 54 public List<Image> listByCategory(Integer categoryId, boolean rafraichir) throws JiwigoException { 55 55 return dao.listByCategory(categoryId, rafraichir); 56 56 } … … 68 68 * @throws FileAlreadyExistsException 69 69 * @throws NoSuchAlgorithmException 70 * @throws JiwigoException 70 71 * @throws Exception 71 72 */ 72 73 public boolean create(String filePath, Integer idCategory, Integer originalWidth, Integer originalHeight, 73 74 Double chunckSize, Integer privacyLevel) throws IOException, NoSuchAlgorithmException, 74 FileAlreadyExistsException, ProxyAuthenticationException, WrongChunkSizeException { 75 FileAlreadyExistsException, ProxyAuthenticationException, WrongChunkSizeException, 76 JiwigoException { 75 77 File originalFile = new File(filePath); 76 78 //get the byte array of the original file, to keep metadata … … 117 119 * @throws ProxyAuthenticationException 118 120 */ 119 public boolean addTags(Image image, String tagId) throws IOException, ProxyAuthenticationException {121 public boolean addTags(Image image, String tagId) throws JiwigoException { 120 122 return dao.addTags(image.getIdentifier(), tagId); 121 123 } … … 128 130 * @throws ProxyAuthenticationException 129 131 */ 130 public List<Image> search(String queryString) throws IOException, ProxyAuthenticationException {132 public List<Image> search(String queryString) throws JiwigoException { 131 133 return dao.search(queryString); 132 134 } … … 144 146 } 145 147 146 public void addSimple(File file, Integer category, String title) throws IOException {148 public void addSimple(File file, Integer category, String title) throws JiwigoException { 147 149 dao.addSimple(file, category, title); 148 150 -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/TagServiceImpl.java
r9919 r10505 11 11 import fr.mael.jiwigo.om.Tag; 12 12 import fr.mael.jiwigo.service.TagService; 13 import fr.mael.jiwigo.transverse.exception.JiwigoException; 13 14 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 14 15 … … 43 44 * @throws IOException 44 45 * @throws ProxyAuthenticationException 46 * @throws JiwigoException 45 47 */ 46 public List<Tag> list() throws IOException, ProxyAuthenticationException {48 public List<Tag> list() throws JiwigoException { 47 49 return dao.list(); 48 50 } … … 54 56 * @throws IOException 55 57 * @throws ProxyAuthenticationException 58 * @throws JiwigoException 56 59 */ 57 public boolean create(String nom) throws IOException, ProxyAuthenticationException {60 public boolean create(String nom) throws JiwigoException { 58 61 Tag tag = new Tag(); 59 62 tag.setName(nom); … … 67 70 * @throws IOException 68 71 * @throws ProxyAuthenticationException 72 * @throws JiwigoException 69 73 */ 70 public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException {74 public List<Tag> tagsForImage(Image image) throws JiwigoException { 71 75 return dao.tagsForImage(image); 72 76 } -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/SessionManager.java
r9919 r10505 4 4 import java.io.UnsupportedEncodingException; 5 5 6 import org.apache.http.client.ClientProtocolException; 6 7 import org.w3c.dom.Document; 7 8 9 import fr.mael.jiwigo.transverse.exception.JiwigoException; 8 10 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 9 11 … … 13 15 * 14 16 * @return 0 if Ok, 1 if not Ok (reason not specified), 2 if proxy error 17 * @throws JiwigoException 15 18 * 16 19 * 17 20 */ 18 public int processLogin() ;21 public int processLogin() throws JiwigoException; 19 22 20 23 /** … … 25 28 * @throws UnsupportedEncodingException 26 29 * @throws ProxyAuthenticationException 30 * @throws JiwigoException 31 * @throws IOException 32 * @throws ClientProtocolException 27 33 */ 28 34 public String executeReturnString(String methode, String... parametres) throws UnsupportedEncodingException, 29 ProxyAuthenticationException ;35 ProxyAuthenticationException, JiwigoException, ClientProtocolException, IOException; 30 36 31 37 /** … … 36 42 * @throws IOException 37 43 * @throws ProxyAuthenticationException 44 * @throws JiwigoException 38 45 */ 39 public Document executeReturnDocument(String methode, String... parametres) throws IOException, 40 ProxyAuthenticationException; 46 public Document executeReturnDocument(String methode, String... parametres) throws JiwigoException; 41 47 42 48 /** … … 46 52 * @throws ProxyAuthenticationException 47 53 */ 48 public Document executeReturnDocument(String methode) throws ProxyAuthenticationException;54 public Document executeReturnDocument(String methode) throws JiwigoException; 49 55 50 56 /** -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/impl/SessionManagerImpl.java
r10494 r10505 6 6 import java.util.ArrayList; 7 7 import java.util.List; 8 9 import javax.xml.parsers.ParserConfigurationException; 8 10 9 11 import org.apache.commons.lang.StringUtils; … … 13 15 import org.apache.http.auth.AuthScope; 14 16 import org.apache.http.auth.UsernamePasswordCredentials; 17 import org.apache.http.client.ClientProtocolException; 15 18 import org.apache.http.client.entity.UrlEncodedFormEntity; 16 19 import org.apache.http.client.methods.HttpPost; … … 21 24 import org.slf4j.LoggerFactory; 22 25 import org.w3c.dom.Document; 26 import org.xml.sax.SAXException; 23 27 24 28 import fr.mael.jiwigo.transverse.enumeration.MethodsEnum; 29 import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException; 30 import fr.mael.jiwigo.transverse.exception.JiwigoException; 25 31 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 26 32 import fr.mael.jiwigo.transverse.session.SessionManager; … … 132 138 * 133 139 * @return 0 if Ok, 1 if not Ok (reason not specified), 2 if proxy error 140 * @throws JiwigoException 134 141 * 135 142 * 136 143 */ 137 public int processLogin() {144 public int processLogin() throws JiwigoException { 138 145 Document doc; 139 146 //configures the proxy … … 152 159 } 153 160 } 154 // try {161 doc = executeReturnDocument(MethodsEnum.LOGIN.getLabel(), "username", login, "password", password); 155 162 try { 156 doc = executeReturnDocument(MethodsEnum.LOGIN.getLabel(), "username", login, "password", password);157 163 return (Tools.checkOk(doc) ? 0 : 1); 158 } catch (IOException e) { 159 LOG.debug(Tools.getStackTrace(e)); 160 return 1; 161 } catch (ProxyAuthenticationException e) { 162 LOG.debug(Tools.getStackTrace(e)); 163 return 2; 164 } catch (Exception e) { 165 LOG.debug(Tools.getStackTrace(e)); 166 return 1; 164 } catch (FileAlreadyExistsException e) { 165 LOG.error(Tools.getStackTrace(e)); 166 throw new JiwigoException(e); 167 167 } 168 168 … … 174 174 * @param parametres the parameters of the method. Must be even : the name of the parameter followed by its value 175 175 * @return the result 176 * @throws UnsupportedEncodingException177 176 * @throws ProxyAuthenticationException 178 */ 179 public String executeReturnString(String methode, String... parametres) throws UnsupportedEncodingException, 180 ProxyAuthenticationException { 177 * @throws JiwigoException 178 * @throws IOException 179 * @throws ClientProtocolException 180 */ 181 public String executeReturnString(String methode, String... parametres) throws ProxyAuthenticationException, 182 JiwigoException, ClientProtocolException, IOException { 181 183 if (parametres.length % 2 != 0 && !(parametres == null)) { 182 try { 183 throw new Exception("Le nombre de parametres doit etre pair"); 184 } catch (Exception e) { 185 LOG.error(Tools.getStackTrace(e)); 186 return null; 187 } 184 LOG.error("parameters number should be even"); 185 throw new IllegalArgumentException("parameters number should be even"); 188 186 } 189 187 HttpPost method = new HttpPost(url); … … 195 193 method.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 196 194 method.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); 197 try { 198 HttpResponse response = client.execute(method); 199 if (response.getStatusLine().getStatusCode() == 407) { 200 throw new ProxyAuthenticationException("Error while trying to auth on the proxy"); 201 } 202 InputStream inputStream = response.getEntity().getContent(); 203 String toReturn = Tools.readInputStreamAsString(inputStream); 204 return toReturn; 205 } catch (IOException e) { 206 207 } 208 return null; 195 HttpResponse response = client.execute(method); 196 int statusCode = response.getStatusLine().getStatusCode(); 197 InputStream inputStream = response.getEntity().getContent(); 198 String toReturn = Tools.readInputStreamAsString(inputStream); 199 if (statusCode == 407) { 200 throw new ProxyAuthenticationException("Error while trying to auth on the proxy"); 201 } else if (statusCode >= 400) { 202 throw new JiwigoException("Piwigo server returned an error code " + toReturn); 203 } 204 205 return toReturn; 209 206 210 207 } … … 217 214 * @throws IOException 218 215 * @throws ProxyAuthenticationException 219 * /220 public Document executeReturnDocument(String methode, String... parametres) throws IOException,221 ProxyAuthenticationException {216 * @throws JiwigoException 217 */ 218 public Document executeReturnDocument(String methode, String... parametres) throws JiwigoException { 222 219 try { 223 220 String returnedString = executeReturnString(methode, parametres); 224 221 return Tools.stringToDocument(returnedString); 225 } catch (Exception e) { 226 // TODO Auto-generated catch block 227 LOG.error(Tools.getStackTrace(e)); 228 } 229 return null; 230 222 } catch (ProxyAuthenticationException e) { 223 LOG.error(Tools.getStackTrace(e)); 224 throw new JiwigoException(e); 225 } catch (SAXException e) { 226 LOG.error(Tools.getStackTrace(e)); 227 throw new JiwigoException(e); 228 } catch (ParserConfigurationException e) { 229 LOG.error(Tools.getStackTrace(e)); 230 throw new JiwigoException(e); 231 } catch (UnsupportedEncodingException e) { 232 LOG.error(Tools.getStackTrace(e)); 233 throw new JiwigoException(e); 234 } catch (IOException e) { 235 LOG.error(Tools.getStackTrace(e)); 236 throw new JiwigoException(e); 237 } 231 238 } 232 239 … … 235 242 * @param methode the method to execute 236 243 * @return the result 237 * @throws ProxyAuthenticationException238 */ 239 public Document executeReturnDocument(String methode) throws ProxyAuthenticationException {244 * @throws JiwigoException 245 */ 246 public Document executeReturnDocument(String methode) throws JiwigoException { 240 247 try { 241 248 return Tools.stringToDocument(executeReturnString(methode)); 242 249 } catch (Exception e) { 243 // TODO Auto-generated catch block 244 LOG.error(Tools.getStackTrace(e)); 245 } 246 return null; 247 250 LOG.error(Tools.getStackTrace(e)); 251 throw new JiwigoException(e); 252 } 248 253 } 249 254 -
extensions/jiwigo-ws-api/src/test/java/fr/mael/jiwigo/service/CategoryServiceTest.java
r10089 r10505 1 1 package fr.mael.jiwigo.service; 2 2 3 import java.io.IOException;4 3 import java.util.Date; 5 4 … … 11 10 import fr.mael.jiwigo.dao.impl.CategoryDaoImpl; 12 11 import fr.mael.jiwigo.service.impl.CategoryServiceImpl; 12 import fr.mael.jiwigo.transverse.exception.JiwigoException; 13 13 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 14 14 import fr.mael.jiwigo.transverse.session.SessionManager; … … 16 16 17 17 public class CategoryServiceTest { 18 18 private SessionManager sessionManager; 19 19 20 21 public void setUp(){22 23 24 20 @Before 21 public void setUp() throws JiwigoException { 22 sessionManager = new SessionManagerImpl("mael", "motdepasse", "http://mael.piwigo.com", "Unit Test"); 23 sessionManager.processLogin(); 24 } 25 25 26 /** 27 * Test of the list method 28 * 29 * @throws ProxyAuthenticationException 30 */ 31 @Test 32 public void ListerTest() throws ProxyAuthenticationException { 33 try { 34 CategoryDaoImpl categaryDao = new CategoryDaoImpl(); 35 categaryDao.setSessionManager(sessionManager); 36 categaryDao.list(true); 37 categaryDao.list(false); 38 } catch (IOException e) { 39 e.printStackTrace(); 40 } 41 } 26 /** 27 * Test of the list method 28 * 29 * @throws ProxyAuthenticationException 30 */ 31 @Test 32 public void ListerTest() throws JiwigoException { 33 CategoryDaoImpl categaryDao = new CategoryDaoImpl(); 34 categaryDao.setSessionManager(sessionManager); 35 categaryDao.list(true); 36 categaryDao.list(false); 37 } 42 38 43 44 45 46 47 48 49 public void creerTest() throws ProxyAuthenticationException {50 51 52 53 54 55 56 39 /** 40 * Test of the creation method 41 * 42 * @throws ProxyAuthenticationException 43 */ 44 @Test 45 public void creerTest() throws JiwigoException { 46 Date date = new Date(); 47 CategoryServiceImpl categoryService = new CategoryServiceImpl(); 48 CategoryDaoImpl dao = new CategoryDaoImpl(); 49 dao.setSessionManager(sessionManager); 50 categoryService.setDao(dao); 51 Assert.assertSame(true, categoryService.create("Category" + date.getTime())); 52 } 57 53 58 54 } -
extensions/jiwigo-ws-api/src/test/java/fr/mael/jiwigo/service/ServicesTest.java
r10494 r10505 2 2 3 3 import java.io.File; 4 import java.io.IOException;5 4 import java.util.List; 6 5 … … 16 15 import fr.mael.jiwigo.service.impl.CategoryServiceImpl; 17 16 import fr.mael.jiwigo.service.impl.ImageServiceImpl; 17 import fr.mael.jiwigo.transverse.exception.JiwigoException; 18 18 import fr.mael.jiwigo.transverse.session.SessionManager; 19 19 import fr.mael.jiwigo.transverse.session.impl.SessionManagerImpl; … … 24 24 25 25 @Before 26 public void setUp() {26 public void setUp() throws JiwigoException { 27 27 sessionManager = new SessionManagerImpl("mael", "motdepasse", "http://mael.piwigo.com", "Unit Test"); 28 28 sessionManager.processLogin(); … … 71 71 try { 72 72 imageService.addSimple(imageFile, categoryTest, title); 73 } catch ( IOException e) {73 } catch (JiwigoException e) { 74 74 Assert.fail("An exception was thrown while trying to send the pictures" + e.getMessage()); 75 75 } -
extensions/jiwigo-ws-api/src/test/java/fr/mael/jiwigo/service/TagServiceTest.java
r10089 r10505 12 12 import fr.mael.jiwigo.dao.impl.TagDaoImpl; 13 13 import fr.mael.jiwigo.service.impl.TagServiceImpl; 14 import fr.mael.jiwigo.transverse.exception.JiwigoException; 14 15 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 15 16 import fr.mael.jiwigo.transverse.session.SessionManager; … … 18 19 public class TagServiceTest { 19 20 20 21 private SessionManager sessionManager; 21 22 22 23 public void setUp(){24 25 26 23 @Before 24 public void setUp() throws JiwigoException { 25 sessionManager = new SessionManagerImpl("mael", "motdepasse", "http://mael.piwigo.com", "Unit Test"); 26 sessionManager.processLogin(); 27 } 27 28 28 /** 29 * Test of the listing method 30 * 31 * @throws ProxyAuthenticationException 32 */ 33 @Test 34 @Ignore 35 public void listTest() throws ProxyAuthenticationException { 36 try { 37 TagDaoImpl tagDao = new TagDaoImpl(); 38 tagDao.setSessionManager(sessionManager); 39 // TODO something weird happens here, 40 // java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DeepNodeListImpl cannot be cast to 41 // org.w3c.dom.Element 42 // at fr.mael.jiwigo.dao.impl.TagDaoImpl.list(TagDaoImpl.java:58) 43 tagDao.list(); 44 } catch (IOException e) { 45 e.printStackTrace(); 46 } 47 } 29 /** 30 * Test of the listing method 31 * @throws JiwigoException 32 * 33 * @throws ProxyAuthenticationException 34 */ 35 @Test 36 @Ignore 37 public void listTest() throws JiwigoException { 38 TagDaoImpl tagDao = new TagDaoImpl(); 39 tagDao.setSessionManager(sessionManager); 40 // TODO something weird happens here, 41 // java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DeepNodeListImpl cannot be cast to 42 // org.w3c.dom.Element 43 // at fr.mael.jiwigo.dao.impl.TagDaoImpl.list(TagDaoImpl.java:58) 44 tagDao.list(); 45 } 48 46 49 /** 50 * Test of the creation method 51 * 52 * @throws ProxyAuthenticationException 53 * @throws IOException 54 */ 55 @Test 56 public void createTest() throws ProxyAuthenticationException, IOException { 57 Date date = new Date(); 58 TagServiceImpl tagService = new TagServiceImpl(); 59 TagDaoImpl tagDao = new TagDaoImpl(); 60 tagDao.setSessionManager(sessionManager); 61 tagService.setDao(tagDao); 62 Assert.assertSame(true, tagService.create("Tag" + date.getTime())); 63 } 47 /** 48 * Test of the creation method 49 * @throws JiwigoException 50 * 51 * @throws ProxyAuthenticationException 52 * @throws IOException 53 */ 54 @Test 55 public void createTest() throws JiwigoException { 56 Date date = new Date(); 57 TagServiceImpl tagService = new TagServiceImpl(); 58 TagDaoImpl tagDao = new TagDaoImpl(); 59 tagDao.setSessionManager(sessionManager); 60 tagService.setDao(tagDao); 61 Assert.assertSame(true, tagService.create("Tag" + date.getTime())); 62 } 64 63 65 64 }
Note: See TracChangeset
for help on using the changeset viewer.