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 38 import java.util.Collection; 39 40 /** 41 * IContactDAO Interface 42 */ 43 public interface IContactListDAO 44 { 45 /** 46 * Insert a new record in the table. 47 * 48 * @param contactList 49 * the instance of contactList to insert into DB 50 * @param plugin 51 * the plugin contact 52 */ 53 void insert( ContactList contactList, Plugin plugin ); 54 55 /** 56 * Load the data of Contact from the table 57 * 58 * @param nContactListId 59 * the Id of the contactList to load 60 * @param plugin 61 * the plugin contact 62 * @return the instance of contactList object loaded 63 */ 64 ContactList load( int nContactListId, Plugin plugin ); 65 66 /** 67 * Delete a record from the table 68 * 69 * @param nIdContactList 70 * the id of contactlist to delete 71 * @param plugin 72 * The plugin 73 */ 74 void delete( int nIdContactList, Plugin plugin ); 75 76 /** 77 * Update the record in the table 78 * 79 * @param contactList 80 * The reference of contactList 81 * @param plugin 82 * The plugin 83 */ 84 void store( ContactList contactList, Plugin plugin ); 85 86 /** 87 * Load the list of contactsList 88 * 89 * @param plugin 90 * The plugin 91 * @return The Collection of the Contacts 92 */ 93 Collection<ContactList> selectAll( Plugin plugin ); 94 95 /** 96 * counts how many contacts are associated to the specified list 97 * 98 * @param nIdContactList 99 * the Id of contactList 100 * @param plugin 101 * the plugin contact 102 * @return the number of contacts for the list 103 */ 104 int countContactsForList( int nIdContactList, Plugin plugin ); 105 106 /** 107 * Selects all contacts associated to a specified list 108 * 109 * @param nIdContactList 110 * the id of contactList 111 * @param plugin 112 * the plugin contact 113 * @return list of contacts 114 */ 115 Collection<Contact> selectContactsForList( int nIdContactList, Plugin plugin ); 116 117 /** 118 * returns true if a contact is assigned to a list 119 * 120 * @param nIdContact 121 * The id of the contact 122 * @param nIdContactList 123 * The id of the contactList 124 * @param plugin 125 * the plugin contact 126 * @return boolean: true if is assigned, false if not 127 */ 128 boolean isAssigned( int nIdContact, int nIdContactList, Plugin plugin ); 129 130 /** 131 * Inserts 2 keys in association table 132 * 133 * @param nIdContact 134 * The id of the contact 135 * @param nIdContactList 136 * The contact List that will be associated 137 * @param plugin 138 * The plugin 139 */ 140 void assign( int nIdContact, int nIdContactList, Plugin plugin ); 141 142 /** 143 * Unassigns a contact of a list, or a list of a contact 144 * 145 * @param nIdContact 146 * the id of the contact 147 * @param nIdContactList 148 * the id of the contactList 149 * @param plugin 150 * The plugin 151 */ 152 void unAssign( int nIdContact, int nIdContactList, Plugin plugin ); 153 154 /** 155 * Selects the list of all contacts that are not assigned to the specified list 156 * 157 * @param nIdContactList 158 * the id of the contact List 159 * @param plugin 160 * the plugin contact 161 * @return list of not assigned contacts 162 */ 163 Collection<Contact> selectNotAssignedContactsFor( int nIdContactList, Plugin plugin ); 164 165 /** 166 * Selects assigned lists for a contact 167 * 168 * @param nIdContact 169 * the id of the contact 170 * @param plugin 171 * the plugin contact 172 * @return collection of lists, the contact is associated to 173 */ 174 Collection<ContactList> selectAssignedListsFor( int nIdContact, Plugin plugin ); 175 176 /** 177 * Selects lists for a role key 178 * 179 * @param strRoleKey 180 * The role key 181 * @param plugin 182 * the plugin contact 183 * @return collection of lists 184 */ 185 Collection<ContactList> selectByRoleKey( String strRoleKey, Plugin plugin ); 186 187 /** 188 * selects all lists, the contact is not associated to 189 * 190 * @param nIdContact 191 * the id of the contact 192 * @param plugin 193 * the plugin contact 194 * @return collection of contactLists 195 */ 196 Collection<ContactList> selectNotAssignedListsFor( int nIdContact, Plugin plugin ); 197 198 /** 199 * Unassigns all contacts for a specified list 200 * 201 * @param nIdContactList 202 * the id of contactlist 203 * @param plugin 204 * the plugin contact 205 */ 206 void unassignContactsForList( int nIdContactList, Plugin plugin ); 207 208 ////////////////////////////////////////// ORDER MANAGEMENT //////////////////////////////// 209 210 /** 211 * Calculate the new max order 212 * 213 * @return the max order of contactList 214 * @param plugin 215 * The plugin 216 */ 217 int maxOrderContactList( Plugin plugin ); 218 219 /** 220 * Calculate the new max order in a list 221 * 222 * @return the max order of contact 223 * @param nIdContactList 224 * the id of the contact list 225 * @param plugin 226 * The plugin 227 */ 228 int maxOrderContact( int nIdContactList, Plugin plugin ); 229 230 /** 231 * Modify the order of a contact 232 * 233 * @param nNewOrder 234 * The order number 235 * @param nId 236 * The contactList identifier 237 * @param plugin 238 * The plugin 239 */ 240 void storeContactListOrder( int nNewOrder, int nId, Plugin plugin ); 241 242 /** 243 * Returns a contact identifier in a distinct order 244 * 245 * @return The order of the ContactList 246 * @param nContactListOrder 247 * The order number 248 * @param plugin 249 * The plugin 250 */ 251 int selectContactListIdByOrder( int nContactListOrder, Plugin plugin ); 252 253 /** 254 * Returns the order of a contactList 255 * 256 * @param nIdContactList 257 * the id of contactList 258 * @param plugin 259 * the plugin contact 260 * @return the order of the contactList 261 */ 262 int selectContactListOrderById( int nIdContactList, Plugin plugin ); 263 264 // ASSIGNMENT 265 266 /** 267 * Unassigns all contacts for a specified list 268 * 269 * @param nIdContact 270 * the id of contact 271 * @param plugin 272 * the plugin contact 273 */ 274 void unassignListsForContact( int nIdContact, Plugin plugin ); 275 276 /** 277 * counts how many lists the contact is associated to 278 * 279 * @param nIdContact 280 * the Id of concerned contact 281 * @param plugin 282 * the plugin contact 283 * @return the number of counted lists 284 */ 285 int countListsForContact( int nIdContact, Plugin plugin ); 286 287 /** 288 * Returns true if the contactList exists 289 * 290 * @return boolean the existance of the list 291 * @param nIdContactList 292 * The if of contactList 293 * @param plugin 294 * The Plugin object 295 */ 296 boolean listExists( int nIdContactList, Plugin plugin ); 297 }