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 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 * Remove a specific version from a blog 125 * 126 * @param nIdBlog 127 * The id of the blog to modify 128 * @param nIdVersion 129 * The value of the version to remove 130 */ 131 public static void removeSpecificVersion( int nIdBlog, int nVersion ) 132 { 133 _dao.deleteSpecificVersion( nIdBlog, nVersion, _plugin ); 134 } 135 136 /** 137 * Returns an instance of a blog whose identifier is specified in parameter 138 * 139 * @param nKey 140 * The blog primary key 141 * @return an instance of blog 142 */ 143 public static Blog findByPrimaryKey( int nKey ) 144 { 145 return _dao.load( nKey, _plugin ); 146 } 147 148 /** 149 * Returns an instance of a blog whose identifier is specified in parameter 150 * 151 * @param nKey 152 * The blog primary key 153 * @return an instance of blog 154 */ 155 public static Blog findByName( String strName ) 156 { 157 return _dao.loadByName( strName, _plugin ); 158 } 159 160 /** 161 * Returns an instance of a blog whose identifier is specified in parameter 162 * 163 * @param nId 164 * The blog primary key 165 * @param nVersion 166 * 167 * @return an instance of blog 168 */ 169 public static Blog findVersion( int nId, int nVersion ) 170 { 171 return _dao.loadVersion( nId, nVersion, _plugin ); 172 } 173 174 /** 175 * Load the data of all the blog objects and returns them as a list 176 * 177 * @return the list which contains the data of all the blog objects 178 */ 179 public static List<Blog> getBlogsList( ) 180 { 181 return _dao.selectBlogsList( _plugin ); 182 } 183 184 /** 185 * Load the data of nLimit last modified Blog objects and returns them as a list 186 * 187 * @param nLimit 188 * number of Blogument 189 * @return The list which contains the data of of nLimit last modified Blog objects 190 */ 191 public static List<Blog> getLastModifiedBlogsList( int nLimit ) 192 { 193 return _dao.selectlastModifiedBlogsList( _plugin, nLimit ); 194 } 195 196 /** 197 * Load the data of nLimit last versions of a specific blog and returns them as a list 198 * 199 * @param nId 200 * The blog's primary key 201 * @param nLimit 202 * Maximum amount of Blog Object versions to return 203 * @return The list which contains the data of nLimit last versions of the blog 204 */ 205 public static List<Blog> getLastBlogVersionsList( int nId, int nLimit ) 206 { 207 return _dao.selectLastBlogVersionsList( nId, nLimit, _plugin ); 208 } 209 210 /** 211 * Load the data of all the Blog objects and returns them as a list 212 * 213 * @return the list which contains the data of all the Blog objects 214 */ 215 public static List<Blog> getBlogsVersionsList( int nId ) 216 { 217 return _dao.selectBlogsVersionsList( nId, _plugin ); 218 } 219 220 /** 221 * Load the data of all users edited the Blog objects and returns them as a list 222 * 223 * @param nId 224 * The Id 225 * @return the list which contains the data of all users edited the Blog objects 226 */ 227 public static List<String> getUsersEditedBlogVersions( int nId ) 228 { 229 return _dao.selectAllUsersEditedBlog( nId, _plugin ); 230 } 231 232 /** 233 * Load the id of all the Blog objects and returns them as a list 234 * 235 * @return the list which contains the id of all the Blog objects 236 */ 237 public static List<Integer> getIdBlogsList( ) 238 { 239 return _dao.selectIdBlogsList( _plugin ); 240 } 241 242 /** 243 * Load the data of all the Blog objects and returns them as a referenceList 244 * 245 * @return the referenceList which contains the data of all the Blog objects 246 */ 247 public static ReferenceList getBlogsReferenceList( ) 248 { 249 return _dao.selectBlogsReferenceList( _plugin ); 250 } 251 252 /** 253 * Create an initial version of an Blog 254 * 255 * @param blog 256 * The instance of the Blog which contains the informations to store 257 * @return The instance of Blog which has been created with its primary key. 258 */ 259 public static Blog./../../../fr/paris/lutece/plugins/blog/business/Blog.html#Blog">Blog addInitialVersion( Blog blog ) 260 { 261 BlogHome.create( blog ); 262 BlogHome.createVersion( blog ); 263 264 return blog; 265 } 266 267 /** 268 * Adds a new version of an Blog 269 * 270 * @param blog 271 * The instance of the blog which contains the informations to store 272 * @return The instance of the blog which has been updated 273 */ 274 public static Blog../../../../../fr/paris/lutece/plugins/blog/business/Blog.html#Blog">Blog addNewVersion( Blog blog ) 275 { 276 BlogHome.update( blog ); 277 BlogHome.createVersion( blog ); 278 279 return blog; 280 } 281 282 /** 283 * Returns a collection of blog objects 284 * 285 * @return A collection of Blogs 286 * @param filter 287 * The filter 288 */ 289 public static List<Blog> findByFilter( BlogFilter filter ) 290 { 291 return _dao.selectByFilter( filter ); 292 } 293 294 /** 295 * Load the data of Blog objects and returns them as a list 296 * 297 * @param nIdTag 298 * Tag Id 299 * @return The list which contains the data of Blog objects 300 */ 301 public static List<Blog> getBlogByTag( int nIdTag ) 302 { 303 return _dao.loadBlogByIdTag( nIdTag, _plugin ); 304 } 305 306 /** 307 * Returns a collection of blog objects 308 * 309 * @return 310 */ 311 public static List<Blog> selectWithoutBinaries( ) 312 { 313 return _dao.selectWithoutBinaries( _plugin ); 314 } 315 316 }