View Javadoc
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  import fr.paris.lutece.util.ReferenceList;
39  
40  import java.util.Collection;
41  
42  /**
43   * This class provides instances management methods (create, find, ...) for Contact objects
44   */
45  public final class ContactHome
46  {
47      // Static variable pointed at the DAO instance
48      private static IContactDAO../../../../../fr/paris/lutece/plugins/contact/business/IContactDAO.html#IContactDAO">IContactDAO _dao = (IContactDAO) SpringContextService.getPluginBean( "contact", "contactDAO" );
49  
50      /**
51       * Private constructor - this class need not be instantiated
52       */
53      private ContactHome( )
54      {
55      }
56  
57      /**
58       * Creation of an instance of contact
59       *
60       * @param contact
61       *            The instance of the contact which contains the informations to store
62       * @param plugin
63       *            The Plugin object
64       * @return The instance of contact which has been created with its primary key.
65       */
66      public static Contact"../../../../../../fr/paris/lutece/plugins/contact/business/Contact.html#Contact">Contact create( Contact contact, Plugin plugin )
67      {
68          _dao.insert( contact, plugin );
69  
70          return contact;
71      }
72  
73      /**
74       * Update of the contact which is specified in parameter
75       *
76       * @param contact
77       *            The instance of the contact which contains the data to store
78       * @param plugin
79       *            The Plugin object
80       * @return The instance of the contact which has been updated
81       */
82      public static Contact"../../../../../../fr/paris/lutece/plugins/contact/business/Contact.html#Contact">Contact update( Contact contact, Plugin plugin )
83      {
84          _dao.store( contact, plugin );
85  
86          return contact;
87      }
88  
89      /**
90       * Remove the Contact whose identifier is specified in parameter
91       *
92       * @param contact
93       *            The Contact object to remove
94       * @param plugin
95       *            The Plugin object
96       */
97      public static void remove( Contact contact, Plugin plugin )
98      {
99          _dao.delete( contact, plugin );
100     }
101 
102     ///////////////////////////////////////////////////////////////////////////
103     // Finders
104 
105     /**
106      * Returns an instance of a contact whose identifier is specified in parameter
107      *
108      * @param nKey
109      *            The Primary key of the contact
110      * @param plugin
111      *            The Plugin object
112      * @return An instance of contact
113      */
114     public static Contact findByPrimaryKey( int nKey, Plugin plugin )
115     {
116         return _dao.load( nKey, plugin );
117     }
118 
119     /**
120      * Returns a collection of contacts objects
121      * 
122      * @param plugin
123      *            The Plugin object
124      * @return A collection of contacts
125      */
126     public static Collection<Contact> findAll( Plugin plugin )
127     {
128         return _dao.selectAll( plugin );
129     }
130 
131     ////////////////////////////////////////////////////////////////////////////
132     // References List management
133 
134     /**
135      * Returns a reference list which contains all the contacts and the string "choose your contact", for the xpage
136      * 
137      * @return a reference list
138      * @param nIdContactList
139      *            The id of contactList
140      * @param strComboItem
141      *            The string to display at the top of combo
142      * @param plugin
143      *            The Plugin object
144      */
145     public static ReferenceList getContactsByListWithString( int nIdContactList, String strComboItem, Plugin plugin )
146     {
147         return _dao.selectContactsByListWithString( nIdContactList, strComboItem, plugin );
148     }
149 
150     /**
151      * Increments hits in contact and contact_list_contact tables
152      * 
153      * @param nIdContactList
154      *            id of the contactList
155      * @param nIdContact
156      *            id of the contact
157      * @param plugin
158      *            the plugin Contact
159      */
160     public static void updateHits( int nIdContactList, int nIdContact, Plugin plugin )
161     {
162         _dao.updateHits( nIdContactList, nIdContact, plugin );
163     }
164 
165     // Contact order Management
166 
167     /**
168      * Search the order number of contacts for one list
169      * 
170      * @return int the id by a given order
171      * @param nIdContactList
172      *            the id of the contactList
173      * @param nContactOrder
174      *            the number of order of the contact
175      * @param plugin
176      *            The Plugin object
177      */
178     public static int getContactIdByOrder( int nContactOrder, int nIdContactList, Plugin plugin )
179     {
180         return _dao.selectContactIdByOrder( nContactOrder, nIdContactList, plugin );
181     }
182 
183     /**
184      * returns the order of a contact in a list using its Id
185      * 
186      * @return int the id by a given order
187      * @param nIdContact
188      *            the id of the contact
189      * @param nIdContactList
190      *            the id of the contactList
191      * @param plugin
192      *            The Plugin object
193      */
194     public static int getContactOrderById( int nIdContact, int nIdContactList, Plugin plugin )
195     {
196         return _dao.selectContactOrderById( nIdContact, nIdContactList, plugin );
197     }
198 
199     /**
200      * Update the number order of contact
201      * 
202      * @param nIdContactList
203      *            the id of the contactList
204      * @param nNewOrder
205      *            the new number of order
206      * @param nId
207      *            the Identifier of contact
208      * @param plugin
209      *            The Plugin object
210      */
211     public static void updateContactOrder( int nNewOrder, int nId, int nIdContactList, Plugin plugin )
212     {
213         _dao.storeContactOrder( nNewOrder, nId, nIdContactList, plugin );
214     }
215 }