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