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.extend.modules.comment.service; 35 36 import java.util.Collection; 37 import java.util.List; 38 import java.util.Locale; 39 40 import javax.servlet.http.HttpServletRequest; 41 42 import org.springframework.transaction.annotation.Transactional; 43 44 import fr.paris.lutece.plugins.extend.modules.comment.business.Comment; 45 import fr.paris.lutece.plugins.extend.modules.comment.business.CommentFilter; 46 import fr.paris.lutece.portal.service.plugin.Plugin; 47 import fr.paris.lutece.util.ReferenceList; 48 49 /** 50 * ICommentService. 51 */ 52 public interface ICommentService 53 { 54 /** 55 * Delete. 56 * 57 * @param nIdComment 58 * the n id comment 59 */ 60 @Transactional( CommentPlugin.TRANSACTION_MANAGER ) 61 void remove( int nIdComment ); 62 63 /** 64 * Delete by resource 65 * 66 * @param strIdExtendableResource 67 * the str id extendable resource 68 * @param strExtendableResourceType 69 * the str extendable resource type 70 */ 71 @Transactional( CommentPlugin.TRANSACTION_MANAGER ) 72 void removeByResource( String strIdExtendableResource, String strExtendableResourceType ); 73 74 /** 75 * Insert. 76 * 77 * @param comment 78 * the comment 79 */ 80 @Transactional( CommentPlugin.TRANSACTION_MANAGER ) 81 void create( Comment comment ); 82 83 /** 84 * Insert. 85 * 86 * @param comment 87 * the comment 88 * @param request 89 * the HTTP request 90 */ 91 @Transactional( CommentPlugin.TRANSACTION_MANAGER ) 92 void create( Comment comment, HttpServletRequest request ); 93 94 /** 95 * Store. 96 * 97 * @param comment 98 * the comment 99 */ 100 @Transactional( CommentPlugin.TRANSACTION_MANAGER ) 101 void update( Comment comment ); 102 103 /** 104 * Update comment status. 105 * 106 * @param nIdComment 107 * the n id comment 108 * @param bPublished 109 * the b published 110 */ 111 @Transactional( CommentPlugin.TRANSACTION_MANAGER ) 112 void updateCommentStatus( int nIdComment, boolean bPublished ); 113 114 /** 115 * Update flag important. 116 * 117 * @param nIdComment 118 * the n id comment 119 * @param bImportant 120 * true if the comment is important 121 */ 122 @Transactional( CommentPlugin.TRANSACTION_MANAGER ) 123 void updateFlagImportant( int nIdComment, boolean bImportant ); 124 125 /** 126 * Update flag important. 127 * 128 * @param nIdComment 129 * the n id comment 130 * @param bPinned 131 * true if the comment must be pinned 132 */ 133 @Transactional( CommentPlugin.TRANSACTION_MANAGER ) 134 void updateCommentPinned( int nIdComment, boolean bPinned ); 135 136 /** 137 * Load. 138 * 139 * @param nIdComment 140 * the n id comment 141 * @return the comment 142 */ 143 Comment findByPrimaryKey( int nIdComment ); 144 145 /** 146 * Select ids of comments associated with a given resource 147 * 148 * @param strIdExtendableResource 149 * The id of the extendable resource 150 * @param strExtendableResourceType 151 * The extendable resource type 152 * @param bPublishedOnly 153 * True to consider only published comments, false to consider every comment 154 * @return The list of comment ids, or an empty list if no comment is associated with the given resource 155 */ 156 List<Integer> findIdsByResource( String strIdExtendableResource, String strExtendableResourceType, boolean bPublishedOnly ); 157 158 /** 159 * Select by resource. 160 * 161 * @param strIdExtendableResource 162 * the id of the extendable resource 163 * @param strExtendableResourceType 164 * the extendable resource type 165 * @param bPublishedOnly 166 * Get only published comments 167 * @param bAscSort 168 * True if comments should be sorted ascendantly, false otherwise 169 * @return the list 170 */ 171 List<Comment> findByResource( String strIdExtendableResource, String strExtendableResourceType, boolean bPublishedOnly, boolean bAscSort ); 172 173 /** 174 * Get the number of comment 175 * 176 * @param strIdExtendableResource 177 * the id of the extendable resource 178 * @param strExtendableResourceType 179 * the extendable resource type 180 * @param bParentsOnly 181 * True to consider only comments with no parent, false otherwise 182 * @param bPublishedOnly 183 * True to get only published comments, false to get every comments 184 * @return the number of comments 185 */ 186 int getCommentNb( String strIdExtendableResource, String strExtendableResourceType, boolean bParentsOnly, boolean bPublishedOnly ); 187 188 /** 189 * Load last comments. 190 * 191 * @param strIdExtendableResource 192 * the id of the extendable resource 193 * @param strExtendableResourceType 194 * the extendable resource type 195 * @param nNbComments 196 * the number of comments 197 * @param bPublishedOnly 198 * True to get only published comments, false to get every comments 199 * @param bParentsOnly 200 * True to get only parent comments, false to get every comments. 201 * @param bGetNumberSubComments 202 * True to get the number of sub comments of each comment, false otherwise 203 * @param bDisplaySubComments 204 * True if the mod display sub comments is enable 205 * @param bSortedByDateCreation 206 * true if the list is sorted by date creation 207 * @return the list 208 */ 209 List<Comment> findLastComments( String strIdExtendableResource, String strExtendableResourceType, int nNbComments, boolean bPublishedOnly, 210 boolean bParentsOnly, boolean bGetNumberSubComments, boolean bDisplaySubComments, boolean bSortedByDateCreation ); 211 212 /** 213 * Get comments of a given resource 214 * 215 * @param strIdExtendableResource 216 * The id of the resource 217 * @param strExtendableResourceType 218 * The type of the resource 219 * @param bPublishedOnly 220 * True to consider only published comments 221 * @param strSortedAttributeName 222 * The name of the attribute to sort, or null if no sort should be done 223 * @param bAscSort 224 * True to sort ascendantly, false otherwise 225 * @param nItemsOffset 226 * The offset of the items to get, or 0 to get items from the first one 227 * @param nMaxItemsNumber 228 * The maximum number of items to return, or 0 to get every items 229 * @param bLoadSubComments 230 * True if sub comments should be loaded, false if they should be ignored 231 * @return The list of comments associated with the given resource 232 */ 233 List<Comment> findByResource( String strIdExtendableResource, String strExtendableResourceType, boolean bPublishedOnly, String strSortedAttributeName, 234 boolean bAscSort, int nItemsOffset, int nMaxItemsNumber, boolean bLoadSubComments ); 235 236 /** 237 * Get comments of a given resource 238 * 239 * @param strIdExtendableResource 240 * The id of the resource 241 * @param strExtendableResourceType 242 * The type of the resource 243 * @param commentFilter 244 * The commentFilter Object 245 * @param nItemsOffset 246 * The offset of the items to get, or 0 to get items from the first one 247 * @param nMaxItemsNumber 248 * The maximum number of items to return, or 0 to get every items 249 * @param bLoadSubComments 250 * True if sub comments should be loaded, false if they should be ignored 251 * @return The list of comments associated with the given resource 252 */ 253 List<Comment> findByResource( String strIdExtendableResource, String strExtendableResourceType, CommentFilter commentFilter, int nItemsOffset, 254 int nMaxItemsNumber, boolean bLoadSubComments ); 255 256 /** 257 * Get comments from their parent 258 * 259 * @param nIdParent 260 * The id of the parent of comments to get 261 * @param bPublishedOnly 262 * True to consider only published comments 263 * @return The list of comments associated with the given parent 264 */ 265 List<Comment> findByIdParent( int nIdParent, boolean bPublishedOnly ); 266 267 /** 268 * Get comments from their parent 269 * 270 * @param nIdParent 271 * The id of the parent of comments to get 272 * @param bPublishedOnly 273 * True to consider only published comments 274 * @param strSortedAttributeName 275 * The name of the attribute to sort, or null if no sort should be done 276 * @param bAscSort 277 * True to sort ascendantly, false otherwise 278 * @return The list of comments associated with the given parent 279 */ 280 List<Comment> findByIdParent( int nIdParent, boolean bPublishedOnly, String strSortedAttributeName, boolean bAscSort ); 281 282 /** 283 * Load comments pinned. 284 * 285 * @param strIdExtendableResource 286 * the id of the extendable resource 287 * @param strExtendableResourceType 288 * the extendable resource type 289 * @param nNbComments 290 * the number of comments 291 * @param bPublishedOnly 292 * True to get only published comments, false to get every comments 293 * @param bParentsOnly 294 * True to get only parent comments, false to get every comments. 295 * @param bGetNumberSubComments 296 * True to get the number of sub comments of each comment, false otherwise 297 * @param add 298 * filter on user name strFilterUserName 299 * @return the list of comments pinned 300 */ 301 List<Comment> findCommentsPinned( String strIdExtendableResource, String strExtendableResourceType, int nNbComments, Integer nCommentState, 302 boolean bParentsOnly, boolean bGetNumberSubComments, String strFilterUserName ); 303 304 /** 305 * Get the number of comments associated with a given parent 306 * 307 * @param nIdParent 308 * The id of the parent of comments to count. 309 * @param bPublishedOnly 310 * True to consider only published comments 311 * @return The number of comments associated with the given parent 312 */ 313 int countByIdParent( int nIdParent, boolean bPublishedOnly ); 314 315 /** 316 * Get the ids of resources ordered by their number of comments 317 * 318 * @param strExtendableResourceType 319 * The type of resources to consider 320 * @param bPublishedOnly 321 * True to consider only published comments, false to consider every comments 322 * @param nItemsOffset 323 * The offset of the items to get, or 0 to get items from the first one 324 * @param nMaxItemsNumber 325 * The maximum number of items to return, or 0 to get every items 326 * @return The list of ids of resources ordered by the number of associated comments 327 */ 328 List<Integer> findIdMostCommentedResources( String strExtendableResourceType, boolean bPublishedOnly, int nItemsOffset, int nMaxItemsNumber ); 329 330 /** 331 * Find comment list by resource 332 * @param strIdExtendableResource 333 * the id of the extendable resource 334 * @param strExtendableResourceType 335 * the extendable resource type 336 * @return list of comments 337 */ 338 List<Comment> findByListResource( List<String> listIdExtendableResource, String strExtendableResourceType ); 339 340 /** 341 * return a referenceList of comment states 342 * 343 * @param locale 344 * the locale 345 * @return a referenceList of comment states 346 */ 347 ReferenceList getRefListCommentStates( Locale locale ); 348 349 /** 350 * 351 * return a referenceList containing the filter on the flag important 352 * 353 * @param locale 354 * the locale 355 * @return a referenceList containing the filter on the flag important 356 */ 357 ReferenceList getRefListFilterAsImportant( Locale locale ); 358 359 /** 360 * return a referenceList containing the filter on the flag As Pinned 361 * 362 * @param locale 363 * the locale 364 * @return a referenceList containing the filter on the flag As Pinned 365 */ 366 ReferenceList getRefListFilterAsPinned( Locale locale ); 367 368 /** 369 * return resource type 370 * 371 * @param extendableResourceType 372 * @return 373 */ 374 String getResourceType( String extendableResourceType ); 375 376 /** 377 * Load comments by lutece user name. 378 * 379 * @param strLuteceUserName 380 * the name of the lutece user 381 * @param nItemsOffset 382 * The offset of the items to get, or 0 to get items from the first one 383 * @param nMaxItemsNumber 384 * The maximum number of items to return, or 0 to get every items 385 * @return the list of comments by lutece user name 386 */ 387 List<Comment> findCommentsByLuteceUser( String strLuteceUserName ); 388 389 }