View Javadoc
1   /*
2    * Copyright (c) 2002-2020, 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 java.util.List;
37  
38  import fr.paris.lutece.portal.service.plugin.Plugin;
39  import fr.paris.lutece.portal.service.plugin.PluginService;
40  import fr.paris.lutece.portal.service.spring.SpringContextService;
41  import fr.paris.lutece.util.ReferenceList;
42  
43  /**
44   * This class provides instances management methods (create, find, ...) for Blog objects
45   */
46  public final class BlogHome
47  {
48      // Static variable pointed at the DAO instance
49      private static IBlogDAO _dao = SpringContextService.getBean( "blog.blogDAO" );
50      private static Plugin _plugin = PluginService.getPlugin( "blog" );
51  
52      /**
53       * Private constructor - this class need not be instantiated
54       */
55      private BlogHome( )
56      {
57      }
58  
59      /**
60       * Create an instance of the blog class
61       * 
62       * @param blog
63       *            The instance of the blog which contains the informations to store
64       * @return The instance of blog which has been created with its primary key.
65       */
66      public static Blogef="../../../../../../fr/paris/lutece/plugins/blog/business/Blog.html#Blog">Blog create( Blog blog )
67      {
68          _dao.insert( blog, _plugin );
69  
70          return blog;
71      }
72  
73      /**
74       * Create an instance of the blog class
75       * 
76       * @param blog
77       *            The instance of the blog which contains the informations to store
78       * @return The instance of blog which has been created with its primary key.
79       */
80      public static Blog../../../../../fr/paris/lutece/plugins/blog/business/Blog.html#Blog">Blog createVersion( Blog blog )
81      {
82          _dao.insertVersion( blog, _plugin );
83  
84          return blog;
85      }
86  
87      /**
88       * Update of the blog which is specified in parameter
89       * 
90       * @param blog
91       *            The instance of the blog which contains the data to store
92       * @return The instance of the blog which has been updated
93       */
94      public static Blogef="../../../../../../fr/paris/lutece/plugins/blog/business/Blog.html#Blog">Blog update( Blog blog )
95      {
96          _dao.store( blog, _plugin );
97  
98          return blog;
99      }
100 
101     /**
102      * Remove the blog whose identifier is specified in parameter
103      * 
104      * @param nKey
105      *            The blog Id
106      */
107     public static void remove( int nKey )
108     {
109         _dao.delete( nKey, _plugin );
110     }
111 
112     /**
113      * Remove the blog's versions whose identifier is specified in parameter
114      * 
115      * @param nKey
116      *            The blog Id
117      */
118     public static void removeVersions( int nKey )
119     {
120         _dao.deleteVersions( nKey, _plugin );
121     }
122 
123     /**
124      * Returns an instance of a blog whose identifier is specified in parameter
125      * 
126      * @param nKey
127      *            The blog primary key
128      * @return an instance of blog
129      */
130     public static Blog findByPrimaryKey( int nKey )
131     {
132         return _dao.load( nKey, _plugin );
133     }
134 
135     /**
136      * Returns an instance of a blog whose identifier is specified in parameter
137      * 
138      * @param nKey
139      *            The blog primary key
140      * @return an instance of blog
141      */
142     public static Blog findByName( String strName )
143     {
144         return _dao.loadByName( strName, _plugin );
145     }
146 
147     /**
148      * Returns an instance of a blog whose identifier is specified in parameter
149      * 
150      * @param nId
151      *            The blog primary key
152      * @param nVersion
153      * 
154      * @return an instance of blog
155      */
156     public static Blog findVersion( int nId, int nVersion )
157     {
158         return _dao.loadVersion( nId, nVersion, _plugin );
159     }
160 
161     /**
162      * Load the data of all the blog objects and returns them as a list
163      * 
164      * @return the list which contains the data of all the blog objects
165      */
166     public static List<Blog> getBlogsList( )
167     {
168         return _dao.selectBlogsList( _plugin );
169     }
170 
171     /**
172      * Load the data of nLimit last modified Blog objects and returns them as a list
173      * 
174      * @param nLimit
175      *            number of Blogument
176      * @return The list which contains the data of of nLimit last modified Blog objects
177      */
178     public static List<Blog> getLastModifiedBlogsList( int nLimit )
179     {
180         return _dao.selectlastModifiedBlogsList( _plugin, nLimit );
181     }
182 
183     /**
184      * Load the data of all the Blog objects and returns them as a list
185      * 
186      * @return the list which contains the data of all the Blog objects
187      */
188     public static List<Blog> getBlogsVersionsList( int nId )
189     {
190         return _dao.selectBlogsVersionsList( nId, _plugin );
191     }
192 
193     /**
194      * Load the data of all users edited the Blog objects and returns them as a list
195      * 
196      * @param nId
197      *            The Id
198      * @return the list which contains the data of all users edited the Blog objects
199      */
200     public static List<String> getUsersEditedBlogVersions( int nId )
201     {
202         return _dao.selectAllUsersEditedBlog( nId, _plugin );
203     }
204 
205     /**
206      * Load the id of all the Blog objects and returns them as a list
207      * 
208      * @return the list which contains the id of all the Blog objects
209      */
210     public static List<Integer> getIdBlogsList( )
211     {
212         return _dao.selectIdBlogsList( _plugin );
213     }
214 
215     /**
216      * Load the data of all the Blog objects and returns them as a referenceList
217      * 
218      * @return the referenceList which contains the data of all the Blog objects
219      */
220     public static ReferenceList getBlogsReferenceList( )
221     {
222         return _dao.selectBlogsReferenceList( _plugin );
223     }
224 
225     /**
226      * Create an initial version of an Blog
227      *
228      * @param blog
229      *            The instance of the Blog which contains the informations to store
230      * @return The instance of Blog which has been created with its primary key.
231      */
232     public static Blog./../../../fr/paris/lutece/plugins/blog/business/Blog.html#Blog">Blog addInitialVersion( Blog blog )
233     {
234         BlogHome.create( blog );
235         BlogHome.createVersion( blog );
236 
237         return blog;
238     }
239 
240     /**
241      * Adds a new version of an Blog
242      *
243      * @param blog
244      *            The instance of the blog which contains the informations to store
245      * @return The instance of the blog which has been updated
246      */
247     public static Blog../../../../../fr/paris/lutece/plugins/blog/business/Blog.html#Blog">Blog addNewVersion( Blog blog )
248     {
249         BlogHome.update( blog );
250         BlogHome.createVersion( blog );
251 
252         return blog;
253     }
254 
255     /**
256      * Returns a collection of blog objects
257      * 
258      * @return A collection of Blogs
259      * @param filter
260      *            The filter
261      */
262     public static List<Blog> findByFilter( BlogFilter filter )
263     {
264         return _dao.selectByFilter( filter );
265     }
266 
267     /**
268      * Load the data of Blog objects and returns them as a list
269      * 
270      * @param nIdTag
271      *            Tag Id
272      * @return The list which contains the data of Blog objects
273      */
274     public static List<Blog> getBlogByTag( int nIdTag )
275     {
276         return _dao.loadBlogByIdTag( nIdTag, _plugin );
277     }
278 
279     /**
280      * Returns a collection of blog objects
281      * 
282      * @return
283      */
284     public static List<Blog> selectWithoutBinaries( )
285     {
286         return _dao.selectWithoutBinaries( _plugin );
287     }
288 
289 }