source: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/TagService.java @ 9430

Last change on this file since 9430 was 9430, checked in by mlg, 13 years ago

Modifications to handle proxy error.
Two types of error are handled : proxy address error and proxy authentication error.
Connecting to jiwigo via a proxy seems to work (tried with my own server... gonna have to try with an external server).
version is 0.13.1.1

File size: 3.4 KB
Line 
1package fr.mael.jiwigo.service;
2
3import java.io.IOException;
4import java.util.List;
5
6import fr.mael.jiwigo.dao.TagDao;
7import fr.mael.jiwigo.om.Image;
8import fr.mael.jiwigo.om.Tag;
9import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
10import fr.mael.jiwigo.transverse.session.SessionManager;
11
12/*
13Copyright (c) 2010, Mael
14All rights reserved.
15
16Redistribution and use in source and binary forms, with or without
17modification, 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
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
28ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY
31DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
34ON 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
36SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37*/
38/**
39 *
40
41 * @author mael
42 *
43 */
44public 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
79     * @throws ProxyAuthenticationException
80     */
81    public List<Tag> list() throws IOException, ProxyAuthenticationException {
82        return TagDao.getInstance(sessionManager).list();
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
90     * @throws ProxyAuthenticationException
91     */
92    public boolean create(String nom) throws IOException, ProxyAuthenticationException {
93        Tag tag = new Tag();
94        tag.setName(nom);
95        return TagDao.getInstance(sessionManager).create(tag);
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
103     * @throws ProxyAuthenticationException
104     */
105    public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException {
106        return TagDao.getInstance(sessionManager).tagsForImage(image);
107    }
108
109}
Note: See TracBrowser for help on using the repository browser.