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.exception.ProxyAuthenticationException; |
---|
10 | import fr.mael.jiwigo.transverse.session.SessionManager; |
---|
11 | |
---|
12 | /* |
---|
13 | * jiwigo-ws-api Piwigo webservice access Api |
---|
14 | * Copyright (c) 2010-2011 Mael mael@le-guevel.com |
---|
15 | * All Rights Reserved |
---|
16 | * |
---|
17 | * This library is free software. It comes without any warranty, to |
---|
18 | * the extent permitted by applicable law. You can redistribute it |
---|
19 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
20 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
21 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
22 | */ |
---|
23 | /** |
---|
24 | * |
---|
25 | |
---|
26 | * @author mael |
---|
27 | * |
---|
28 | */ |
---|
29 | public class TagService { |
---|
30 | /** |
---|
31 | * Logger |
---|
32 | */ |
---|
33 | public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory |
---|
34 | .getLog(TagService.class); |
---|
35 | |
---|
36 | /** |
---|
37 | * The instance, to use a singleton |
---|
38 | */ |
---|
39 | private static TagService instance; |
---|
40 | |
---|
41 | private SessionManager sessionManager; |
---|
42 | |
---|
43 | /** |
---|
44 | * @return the singleton |
---|
45 | */ |
---|
46 | public static TagService getInstance(SessionManager sessionManager) { |
---|
47 | if (instance == null) { |
---|
48 | instance = new TagService(sessionManager); |
---|
49 | } |
---|
50 | return instance; |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * private constructor |
---|
55 | */ |
---|
56 | private TagService(SessionManager sessionManager) { |
---|
57 | this.sessionManager = sessionManager; |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * Lists all tags |
---|
62 | * @return le list of tags |
---|
63 | * @throws IOException |
---|
64 | * @throws ProxyAuthenticationException |
---|
65 | */ |
---|
66 | public List<Tag> list() throws IOException, ProxyAuthenticationException { |
---|
67 | return TagDao.getInstance(sessionManager).list(); |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * Creates a tag |
---|
72 | * @param nom name of the tag |
---|
73 | * @return true if the tag is created |
---|
74 | * @throws IOException |
---|
75 | * @throws ProxyAuthenticationException |
---|
76 | */ |
---|
77 | public boolean create(String nom) throws IOException, ProxyAuthenticationException { |
---|
78 | Tag tag = new Tag(); |
---|
79 | tag.setName(nom); |
---|
80 | return TagDao.getInstance(sessionManager).create(tag); |
---|
81 | } |
---|
82 | |
---|
83 | /** |
---|
84 | * Returns all the tag for an image |
---|
85 | * @param image the image to check |
---|
86 | * @return the list of tags |
---|
87 | * @throws IOException |
---|
88 | * @throws ProxyAuthenticationException |
---|
89 | */ |
---|
90 | public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException { |
---|
91 | return TagDao.getInstance(sessionManager).tagsForImage(image); |
---|
92 | } |
---|
93 | |
---|
94 | } |
---|