[9387] | 1 | package fr.mael.jiwigo.service; |
---|
| 2 | |
---|
| 3 | import java.io.IOException; |
---|
| 4 | import java.util.List; |
---|
| 5 | |
---|
| 6 | import fr.mael.jiwigo.dao.TagDao; |
---|
| 7 | import fr.mael.jiwigo.om.Image; |
---|
| 8 | import fr.mael.jiwigo.om.Tag; |
---|
[9430] | 9 | import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; |
---|
[9387] | 10 | import fr.mael.jiwigo.transverse.session.SessionManager; |
---|
| 11 | |
---|
| 12 | /* |
---|
| 13 | Copyright (c) 2010, Mael |
---|
| 14 | All rights reserved. |
---|
| 15 | |
---|
| 16 | Redistribution and use in source and binary forms, with or without |
---|
| 17 | modification, are permitted provided that the following conditions are met: |
---|
| 18 | * Redistributions of source code must retain the above copyright |
---|
| 19 | notice, this list of conditions and the following disclaimer. |
---|
| 20 | * Redistributions in binary form must reproduce the above copyright |
---|
| 21 | notice, this list of conditions and the following disclaimer in the |
---|
| 22 | documentation and/or other materials provided with the distribution. |
---|
| 23 | * Neither the name of jiwigo nor the |
---|
| 24 | names of its contributors may be used to endorse or promote products |
---|
| 25 | derived from this software without specific prior written permission. |
---|
| 26 | |
---|
| 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
---|
| 28 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
---|
| 29 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
---|
| 30 | DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY |
---|
| 31 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
| 32 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
---|
| 33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
---|
| 34 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
| 35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
| 36 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 37 | */ |
---|
| 38 | /** |
---|
| 39 | * |
---|
| 40 | |
---|
| 41 | * @author mael |
---|
| 42 | * |
---|
| 43 | */ |
---|
| 44 | public class TagService { |
---|
| 45 | /** |
---|
| 46 | * Logger |
---|
| 47 | */ |
---|
| 48 | public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory |
---|
| 49 | .getLog(TagService.class); |
---|
| 50 | |
---|
| 51 | /** |
---|
| 52 | * The instance, to use a singleton |
---|
| 53 | */ |
---|
| 54 | private static TagService instance; |
---|
| 55 | |
---|
| 56 | private SessionManager sessionManager; |
---|
| 57 | |
---|
| 58 | /** |
---|
| 59 | * @return the singleton |
---|
| 60 | */ |
---|
| 61 | public static TagService getInstance(SessionManager sessionManager) { |
---|
| 62 | if (instance == null) { |
---|
| 63 | instance = new TagService(sessionManager); |
---|
| 64 | } |
---|
| 65 | return instance; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | /** |
---|
| 69 | * private constructor |
---|
| 70 | */ |
---|
| 71 | private TagService(SessionManager sessionManager) { |
---|
| 72 | this.sessionManager = sessionManager; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | /** |
---|
| 76 | * Lists all tags |
---|
| 77 | * @return le list of tags |
---|
| 78 | * @throws IOException |
---|
[9430] | 79 | * @throws ProxyAuthenticationException |
---|
[9387] | 80 | */ |
---|
[9430] | 81 | public List<Tag> list() throws IOException, ProxyAuthenticationException { |
---|
[9392] | 82 | return TagDao.getInstance(sessionManager).list(); |
---|
[9387] | 83 | } |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | * Creates a tag |
---|
| 87 | * @param nom name of the tag |
---|
| 88 | * @return true if the tag is created |
---|
| 89 | * @throws IOException |
---|
[9430] | 90 | * @throws ProxyAuthenticationException |
---|
[9387] | 91 | */ |
---|
[9430] | 92 | public boolean create(String nom) throws IOException, ProxyAuthenticationException { |
---|
[9387] | 93 | Tag tag = new Tag(); |
---|
[9392] | 94 | tag.setName(nom); |
---|
| 95 | return TagDao.getInstance(sessionManager).create(tag); |
---|
[9387] | 96 | } |
---|
| 97 | |
---|
| 98 | /** |
---|
| 99 | * Returns all the tag for an image |
---|
| 100 | * @param image the image to check |
---|
| 101 | * @return the list of tags |
---|
| 102 | * @throws IOException |
---|
[9430] | 103 | * @throws ProxyAuthenticationException |
---|
[9387] | 104 | */ |
---|
[9430] | 105 | public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException { |
---|
[9387] | 106 | return TagDao.getInstance(sessionManager).tagsForImage(image); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | } |
---|