View Javadoc
1   /*
2    * Copyright (c) 2002-2020, 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.announce.business;
35  
36  import fr.paris.lutece.portal.service.plugin.Plugin;
37  
38  import java.sql.Timestamp;
39  
40  import java.util.List;
41  
42  /**
43   * IAnnounceDAO Interface
44   */
45  public interface IAnnounceDAO
46  {
47      /**
48       * Insert a new record in the table.
49       * 
50       * @param announce
51       *            instance of the Announce object to insert
52       * @param plugin
53       *            the Plugin
54       */
55      void insert( Announce announce, Plugin plugin );
56  
57      /**
58       * Update the record in the table
59       * 
60       * @param announce
61       *            the reference of the Announce
62       * @param plugin
63       *            the Plugin
64       */
65      void store( Announce announce, Plugin plugin );
66  
67      /**
68       * Delete a record from the table
69       * 
70       * @param nIdAnnounce
71       *            int identifier of the Announce to delete
72       * @param plugin
73       *            the Plugin
74       */
75      void delete( int nIdAnnounce, Plugin plugin );
76  
77      // /////////////////////////////////////////////////////////////////////////
78      // Finders
79  
80      /**
81       * Load the data from the table
82       * 
83       * @return The instance of the announce
84       * @param nKey
85       *            the primary key
86       * @param plugin
87       *            the Plugin
88       */
89      Announce load( int nKey, Plugin plugin );
90  
91      /**
92       * Load the data of all the announce objects and returns them as a List
93       * 
94       * @param announceSort
95       *            the sort to use
96       * @param plugin
97       *            the Plugin
98       * @return The List which contains the data of all the announce objects
99       */
100     List<Integer> selectAll( AnnounceSort announceSort, Plugin plugin );
101 
102     /**
103      * selects id of published announces
104      * 
105      * @param announceSort
106      *            the sort to use
107      * @param plugin
108      *            the plugin
109      * @return id of published announces
110      */
111     List<Integer> selectAllPublishedId( AnnounceSort announceSort, Plugin plugin );
112 
113     /**
114      * selects all the published announces
115      * 
116      * @param announceSort
117      *            the sort to use
118      * @param plugin
119      *            the plugin
120      * @return announces list
121      */
122     List<Announce> selectAllPublished( AnnounceSort announceSort, Plugin plugin );
123 
124     /**
125      * Get the list of announces from a list of ids
126      * 
127      * @param announceSort
128      *            the sort to use
129      * @param listIdAnnounces
130      *            The list of ids of announces to get
131      * @param plugin
132      *            The plugin
133      * @return The list of announces
134      */
135     List<Announce> findByListId( List<Integer> listIdAnnounces, AnnounceSort announceSort, Plugin plugin );
136 
137     /**
138      * selects all published announces for a given category
139      * 
140      * @param announceSort
141      *            the sort to use
142      * @param category
143      *            announces list
144      * @param plugin
145      *            the plugin
146      * @return announces list
147      */
148     List<Integer> selectAllPublishedForCategory( Category category, AnnounceSort announceSort, Plugin plugin );
149 
150     /**
151      * selects all announces for a given user
152      * 
153      * @param announceSort
154      *            the sort to use
155      * @param strUsername
156      *            the username
157      * @param plugin
158      *            the plugin
159      * @return all announces for a given user
160      */
161     List<Announce> selectAllForUser( String strUsername, AnnounceSort announceSort, Plugin plugin );
162 
163     /**
164      * publish or unpublish an announce
165      * 
166      * @param announce
167      *            the announce
168      * @param plugin
169      *            the plugin
170      */
171     void setPublished( Announce announce, Plugin plugin );
172 
173     void setHasNotifed( Announce announce, Plugin plugin );
174 
175     /**
176      * suspend or enable an announce
177      * 
178      * @param announce
179      *            the announce
180      * @param plugin
181      *            the plugin
182      */
183     void setSuspended( Announce announce, Plugin plugin );
184 
185     /**
186      * suspend or enable an announce
187      * 
188      * @param announce
189      *            the announce
190      * @param plugin
191      *            the plugin
192      */
193     void setSuspendedByUser( Announce announce, Plugin plugin );
194 
195     /**
196      * Get the list of ids of announces that was created before the given date
197      * 
198      * @param timestamp
199      *            The timestamp
200      * @param plugin
201      *            The plugin
202      * @return The list of ids
203      */
204     List<Integer> findIdAnnouncesByDateCreation( Timestamp timestamp, Plugin plugin );
205 
206     // ----------------------------------------
207     // Announce response management
208     // ----------------------------------------
209 
210     /**
211      * Associates a response to an Announce
212      * 
213      * @param nIdAnnounce
214      *            The id of the Announce
215      * @param nIdResponse
216      *            The id of the response
217      * @param bIsImage
218      *            True if the response is an image, false otherwise
219      * @param plugin
220      *            The plugin
221      */
222     void insertAnnounceResponse( int nIdAnnounce, int nIdResponse, boolean bIsImage, Plugin plugin );
223 
224     /**
225      * Get the list of id of responses associated with an announce
226      * 
227      * @param nIdAnnounce
228      *            the id of the announce
229      * @param plugin
230      *            the plugin
231      * @return the list of responses, or an empty list if no response was found
232      */
233     List<Integer> findListIdResponse( int nIdAnnounce, Plugin plugin );
234 
235     /**
236      * Get the list of id of image responses associated with an announce
237      * 
238      * @param nIdAnnounce
239      *            the id of the announce
240      * @param plugin
241      *            the plugin
242      * @return the list of responses, or an empty list if no response was found
243      */
244     List<Integer> findListIdImageResponse( int nIdAnnounce, Plugin plugin );
245 
246     /**
247      * Remove the association between an announce and responses
248      * 
249      * @param nIdAnnounce
250      *            The id of the announce
251      * @param plugin
252      *            The plugin
253      */
254     void deleteAnnounceResponse( int nIdAnnounce, Plugin plugin );
255 
256     /**
257      * Get the list of ids of announces that were created after a given time
258      * 
259      * @param lMinPublicationTime
260      *            The minimum publication time of announces to get
261      * @param plugin
262      *            The plugin
263      * @return The list of ids of announces
264      */
265     List<Integer> findIdAnnouncesByDatePublication( long lMinPublicationTime, Plugin plugin );
266 
267     /**
268      * Get the announce id from its image response id
269      * 
270      * @param nIdResponse
271      *            the id of the response
272      * @param plugin
273      *            the plugin
274      * @return The announce id, or null if there no anncounce has this response as an image
275      */
276     Integer findIdByImageResponse( int nIdResponse, Plugin plugin );
277 
278 }