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.contact.business; 35 36 import fr.paris.lutece.portal.service.plugin.Plugin; 37 import fr.paris.lutece.portal.service.spring.SpringContextService; 38 39 import java.util.Collection; 40 41 /** 42 * This class provides instances management methods (create, find, ...) for Contact objects 43 */ 44 public final class ContactListHome 45 { 46 // Static variable pointed at the DAO instance 47 private static IContactListDAO./../../../fr/paris/lutece/plugins/contact/business/IContactListDAO.html#IContactListDAO">IContactListDAO _dao = (IContactListDAO) SpringContextService.getPluginBean( "contact", "contactListDAO" ); 48 49 /** 50 * Private constructor - this class need not be instantiated 51 */ 52 private ContactListHome( ) 53 { 54 } 55 56 /** 57 * Creation of an instance of List 58 * 59 * @param contactList 60 * The instance of the contact which contains the informations to store 61 * @param plugin 62 * The Plugin object 63 * @return The instance of contactList which has been created with its primary key. 64 */ 65 public static ContactList../../../../../fr/paris/lutece/plugins/contact/business/ContactList.html#ContactList">ContactList create( ContactList contactList, Plugin plugin ) 66 { 67 _dao.insert( contactList, plugin ); 68 69 return contactList; 70 } 71 72 /** 73 * Update of the contactList which is specified in parameter 74 * 75 * @return The instance of the contact which has been updated 76 * @param contactList 77 * the contactList object with updated parameters 78 * @param plugin 79 * The Plugin object 80 */ 81 public static ContactList../../../../../fr/paris/lutece/plugins/contact/business/ContactList.html#ContactList">ContactList update( ContactList contactList, Plugin plugin ) 82 { 83 _dao.store( contactList, plugin ); 84 85 return contactList; 86 } 87 88 /** 89 * Remove the Contact whose identifier is specified in parameter 90 * 91 * @param nIdContactList 92 * the Id of the contact list to remove 93 * @param plugin 94 * The Plugin object 95 */ 96 public static void remove( int nIdContactList, Plugin plugin ) 97 { 98 _dao.delete( nIdContactList, plugin ); 99 } 100 101 /////////////////////////////////////////////////////////////////////////// 102 // Finders 103 104 /** 105 * Returns an instance of a contact whose identifier is specified in parameter 106 * 107 * @param nKey 108 * The Primary key of the contact 109 * @param plugin 110 * The Plugin object 111 * @return An instance of contact 112 */ 113 public static ContactList findByPrimaryKey( int nKey, Plugin plugin ) 114 { 115 return _dao.load( nKey, plugin ); 116 } 117 118 /** 119 * Returns a collection of contacts objects 120 * 121 * @param plugin 122 * The Plugin object 123 * @return A collection of contacts 124 */ 125 public static Collection<ContactList> findAll( Plugin plugin ) 126 { 127 return _dao.selectAll( plugin ); 128 } 129 130 /** 131 * Returns a collection of contacts objects 132 * 133 * @param strRoleKey 134 * The role key 135 * @param plugin 136 * The Plugin object 137 * @return A collection of ContactList 138 */ 139 public static Collection<ContactList> findByRoleKey( String strRoleKey, Plugin plugin ) 140 { 141 return _dao.selectByRoleKey( strRoleKey, plugin ); 142 } 143 144 /** 145 * Counts how many contacts are associated to the list 146 * 147 * @param nIdContactList 148 * the id of the contactList 149 * @param plugin 150 * The plugin contact 151 * @return the number of contacts 152 */ 153 public static int countContactsForList( int nIdContactList, Plugin plugin ) 154 { 155 return _dao.countContactsForList( nIdContactList, plugin ); 156 } 157 158 /** 159 * counts all lists for one contact 160 * 161 * @param nIdContact 162 * the Id of the contact 163 * @param plugin 164 * The plugin contact 165 * @return the number of lists 166 */ 167 public static int countListsForContact( int nIdContact, Plugin plugin ) 168 { 169 return _dao.countListsForContact( nIdContact, plugin ); 170 } 171 172 /** 173 * selects the list of assigned contacts for one list 174 * 175 * @param nIdContactList 176 * the id of contactList 177 * @param plugin 178 * The plugin contact 179 * @return the collection of contacts assigned to the list 180 */ 181 public static Collection<Contact> getAssignedContactsFor( int nIdContactList, Plugin plugin ) 182 { 183 return _dao.selectContactsForList( nIdContactList, plugin ); 184 } 185 186 /** 187 * get all contacts that are not assigned to one specific list 188 * 189 * @param nIdContactList 190 * th id of the contactList 191 * @param plugin 192 * The plugin contact 193 * @return the collection of not assigned contacts 194 */ 195 public static Collection<Contact> getNotAssignedContactsFor( int nIdContactList, Plugin plugin ) 196 { 197 return _dao.selectNotAssignedContactsFor( nIdContactList, plugin ); 198 } 199 200 /** 201 * returns true if the count of couples is positive 202 * 203 * @param nIdContact 204 * the id of the contact 205 * @param nIdContactList 206 * the id of contact List 207 * @param plugin 208 * The plugin contact 209 * @return true or false 210 */ 211 public static boolean isAssigned( int nIdContact, int nIdContactList, Plugin plugin ) 212 { 213 return _dao.isAssigned( nIdContact, nIdContactList, plugin ); 214 } 215 216 /** 217 * selects the list of Lists assigned to one contact 218 * 219 * @param nIdContact 220 * the Id of the contact 221 * @param plugin 222 * The plugin contact 223 * @return collection of assigned lists 224 */ 225 public static Collection<ContactList> getAssignedListsFor( int nIdContact, Plugin plugin ) 226 { 227 return _dao.selectAssignedListsFor( nIdContact, plugin ); 228 } 229 230 /** 231 * selects the list of Lists not assigned to one contact 232 * 233 * @param nIdContact 234 * the id of the contact 235 * @param plugin 236 * The plugin Contact 237 * @return collection of not assigned lists 238 */ 239 public static Collection<ContactList> getNotAssignedListsFor( int nIdContact, Plugin plugin ) 240 { 241 return _dao.selectNotAssignedListsFor( nIdContact, plugin ); 242 } 243 244 /** 245 * assigns a contact to a list or a list to a contact 246 * 247 * @param nIdContact 248 * the id of the contact 249 * @param nIdContactList 250 * the id of the contact list 251 * @param plugin 252 * The plugin Contact 253 */ 254 public static void assign( int nIdContact, int nIdContactList, Plugin plugin ) 255 { 256 _dao.assign( nIdContact, nIdContactList, plugin ); 257 } 258 259 /** 260 * Unassigns a list and a contact 261 * 262 * @param nIdContact 263 * the id of the contact 264 * @param nIdContactList 265 * the id of contact List 266 * @param plugin 267 * The plugin Contact 268 */ 269 public static void unAssign( int nIdContact, int nIdContactList, Plugin plugin ) 270 { 271 _dao.unAssign( nIdContact, nIdContactList, plugin ); 272 } 273 274 /** 275 * unassigns all contacts for one specific list 276 * 277 * @param nIdContactList 278 * the id of concerned ContactList 279 * @param plugin 280 * The plugin Contact 281 */ 282 public static void unassignContactsForList( int nIdContactList, Plugin plugin ) 283 { 284 _dao.unassignContactsForList( nIdContactList, plugin ); 285 } 286 287 //////////////////////////////////////////////////////////////////////////// 288 // Contact Order management 289 290 /** 291 * Search the max order number of contacts for one list 292 * 293 * @return int the max order 294 * @param plugin 295 * The Plugin object 296 */ 297 public static int getMaxOrderContactList( Plugin plugin ) 298 { 299 return _dao.maxOrderContactList( plugin ); 300 } 301 302 /** 303 * Search the max order number of contacts for one list 304 * 305 * @param nIdContactList 306 * the id contact list 307 * @param plugin 308 * The Plugin object 309 * @return int the max order 310 */ 311 public static int getMaxOrderContact( int nIdContactList, Plugin plugin ) 312 { 313 return _dao.maxOrderContact( nIdContactList, plugin ); 314 } 315 316 /** 317 * Search the order number of contactLists 318 * 319 * @param nContactListOrder 320 * the order of contact 321 * @param plugin 322 * The Plugin object 323 * @return int the id by a given order 324 */ 325 public static int getContactListIdByOrder( int nContactListOrder, Plugin plugin ) 326 { 327 return _dao.selectContactListIdByOrder( nContactListOrder, plugin ); 328 } 329 330 /** 331 * returns the order of a contact in a list using its Id 332 * 333 * @return int the id by a given order 334 * @param nIdContactList 335 * the id of the contactList 336 * @param plugin 337 * The Plugin object 338 */ 339 public static int getContactListOrderById( int nIdContactList, Plugin plugin ) 340 { 341 return _dao.selectContactListOrderById( nIdContactList, plugin ); 342 } 343 344 /** 345 * Update the number order of contact 346 * 347 * @param nIdContactList 348 * the id of the contactList 349 * @param nNewOrder 350 * the new number of order 351 * @param plugin 352 * The Plugin object 353 */ 354 public static void updateContactListOrder( int nNewOrder, int nIdContactList, Plugin plugin ) 355 { 356 _dao.storeContactListOrder( nNewOrder, nIdContactList, plugin ); 357 } 358 359 /** 360 * Returns true if the contactList exists 361 * 362 * @return boolean the existance of the list 363 * @param nIdContactList 364 * The if of contactList 365 * @param plugin 366 * The Plugin object 367 */ 368 public static boolean listExists( int nIdContactList, Plugin plugin ) 369 { 370 return _dao.listExists( nIdContactList, plugin ); 371 } 372 373 //////////////////////////////////////////////////////////////////////////// 374 // References List management 375 376 /** 377 * unassigns all lists for one specific contact 378 * 379 * @param nIdContact 380 * The if of contact 381 * @param plugin 382 * The Plugin object 383 */ 384 public static void unassignListsForContact( int nIdContact, Plugin plugin ) 385 { 386 _dao.unassignListsForContact( nIdContact, plugin ); 387 } 388 }