1 /*
2 * Copyright (c) 2002-2021, City of Paris
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice
10 * and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice
13 * and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
32 * License 1.0
33 */
34 package fr.paris.lutece.plugins.blog.business;
35
36 import fr.paris.lutece.plugins.blog.service.BlogPlugin;
37 import fr.paris.lutece.portal.service.plugin.Plugin;
38 import fr.paris.lutece.portal.service.plugin.PluginService;
39 import fr.paris.lutece.portal.service.spring.SpringContextService;
40 import fr.paris.lutece.util.ReferenceList;
41
42 import java.util.List;
43
44 /**
45 * This class provides instances management methods (create, find, ...) for Tag objects
46 */
47 public final class TagHome
48 {
49 // Static variable pointed at the DAO instance
50 private static ITagDAO _dao = SpringContextService.getBean( "blog.tagDAO" );
51 private static Plugin _plugin = PluginService.getPlugin( BlogPlugin.PLUGIN_NAME );
52
53 /**
54 * Private constructor - this class need not be instantiated
55 */
56 private TagHome( )
57 {
58 }
59
60 /**
61 * Create an instance of the tag class
62 *
63 * @param tag
64 * The instance of the tag which contains the informations to store
65 * @return The instance of tag which has been created with its primary key.
66 */
67 public static Tagref="../../../../../../fr/paris/lutece/plugins/blog/business/Tag.html#Tag">Tag create( Tag tag )
68 {
69 _dao.insert( tag, _plugin );
70
71 return tag;
72 }
73
74 /**
75 * Update of the tag which is specified in parameter
76 *
77 * @param tag
78 * The instance of the tag which contains the data to store
79 * @return The instance of the tag which has been updated
80 */
81 public static Tagref="../../../../../../fr/paris/lutece/plugins/blog/business/Tag.html#Tag">Tag update( Tag tag )
82 {
83 _dao.store( tag, _plugin );
84
85 return tag;
86 }
87
88 /**
89 * Remove the tag whose identifier is specified in parameter
90 *
91 * @param nKey
92 * The tag Id
93 */
94 public static void remove( int nKey )
95 {
96 _dao.delete( nKey, _plugin );
97 }
98
99 /**
100 * Returns an instance of a tag whose identifier is specified in parameter
101 *
102 * @param nKey
103 * The tag primary key
104 * @return an instance of Tag
105 */
106 public static Tag findByPrimaryKey( int nKey )
107 {
108 return _dao.load( nKey, _plugin );
109 }
110
111 /**
112 * Returns an instance of a tag whose name is specified in parameter
113 *
114 * @param strName
115 * The tag name
116 * @return an instance of Tag
117 */
118 public static Tag findByName( String strName )
119 {
120 return _dao.loadByName( strName, _plugin );
121 }
122
123 /**
124 * Load the data of all the tag objects and returns them as a list
125 *
126 * @return the list which contains the data of all the tag objects
127 */
128 public static List<Tag> getTagList( )
129 {
130 return _dao.loadAllTag( _plugin );
131 }
132
133 /**
134 * Load the data of all the tag objects and returns them as a list
135 *
136 * @return the list which contains the data of all the tag objects
137 */
138 public static ReferenceList getTagsReferenceList( )
139 {
140 return _dao.selectTagsReferenceList( _plugin );
141 }
142
143 /**
144 * Load the data of the tag objects whose identifier is specified in parameter and returns them as a list
145 *
146 * @param nIdDco
147 * The document identifiant
148 * @return returns them as a list of the tag objects
149 */
150 public static List<Tag> loadByDoc( int nIdDco )
151 {
152 return _dao.loadByDoc( nIdDco, _plugin );
153 }
154
155 /**
156 * Associating a tag with a document
157 *
158 * @param nIdTag
159 * the Tag id
160 * @param nIdocument
161 * The document identifiant
162 * @param nPriority
163 * The priority of the document
164 */
165 public static void create( int nIdTag, int nIdocument, int nPriority )
166 {
167 _dao.insert( nIdTag, nIdocument, nPriority, _plugin );
168
169 }
170
171 /**
172 * Delete Association a tag with a document whose identifier is specified in parameter
173 *
174 * @param nIdDoc
175 * The Id Document
176 */
177 public static void removeTagDoc( int nIdDoc )
178 {
179 _dao.deleteByDoc( nIdDoc, _plugin );
180 }
181
182 /**
183 * Load the Tags associated with the document whose identifier is specified in parameter
184 *
185 * @param idDoc
186 * Id Document
187 * @return list of Tag
188 */
189 public static List<Tag> getTagListByDoc( int idDoc )
190 {
191 return _dao.loadListTagByIdDoc( idDoc, _plugin );
192 }
193 }