1 /*
2 * Copyright (c) 2002-2017, Mairie de 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.greetingscard.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 import java.util.Date;
41 import java.util.List;
42 import java.util.Map;
43
44
45 /**
46 * This class provides instances management methods (create, find, ...) for GreetingsCard objects
47 */
48 public final class GreetingsCardHome
49 {
50 // Static variable pointed at the DAO instance
51 private static IGreetingsCardDAO _dao = SpringContextService.getBean( "greetingscardDAO" );
52
53 /**
54 * Private constructor - this class need not be instantiated.
55 */
56 private GreetingsCardHome( )
57 {
58 }
59
60 /**
61 * Creates a greetings card in the database
62 * @param greetingsCard An instance of the GreetingsCard which contains the informations to insert
63 * @param plugin The plugin
64 * @return The instance of the GreetingsCard which has been created.
65 */
66 public static GreetingsCard/../../../../fr/paris/lutece/plugins/greetingscard/business/GreetingsCard.html#GreetingsCard">GreetingsCard create( GreetingsCard greetingsCard, Plugin plugin )
67 {
68 _dao.insert( greetingsCard, plugin );
69
70 return greetingsCard;
71 }
72
73 /**
74 *
75 * @param greetingsCard An instance of the GreetingsCard which contains the informations to store
76 * @param plugin The plugin
77 * @return The instance of the GreetingsCard which has been updated.
78 */
79 public static GreetingsCard/../../../../fr/paris/lutece/plugins/greetingscard/business/GreetingsCard.html#GreetingsCard">GreetingsCard update( GreetingsCard greetingsCard, Plugin plugin )
80 {
81 _dao.store( greetingsCard, plugin );
82
83 return greetingsCard;
84 }
85
86 /**
87 *
88 * @param strIdGC The Id of the deleted greeting card
89 * @param plugin The plugin
90 */
91 public static void remove( String strIdGC, Plugin plugin )
92 {
93 _dao.delete( strIdGC, plugin );
94 }
95
96 /**
97 * Remove a list of greetings card
98 * @param strIdGC The comma separated list of greetings cards ids
99 * @param plugin The plugin
100 */
101 public static void removeList( String strIdGC, Plugin plugin )
102 {
103 _dao.deleteList( strIdGC, plugin );
104 }
105
106 // /////////////////////////////////////////////////////////////////////////
107 // Finders
108
109 /**
110 * Returns an instance of the article GreetingsCard whose identifier is specified in parameter
111 *
112 * @param strKey The primary key of the article to find in the database
113 * @param plugin The plugin
114 * @return An instance of the GreetingsCard which corresponds to the key
115 */
116 public static GreetingsCard findByPrimaryKey( String strKey, Plugin plugin )
117 {
118 return _dao.load( strKey, plugin );
119 }
120
121 /**
122 * Returns GreetingsCard list
123 *
124 * @param plugin The plugin
125 * @return the list of the GreetingsCard of the database in form of a GreetingsCard Collection object
126 */
127 public static Collection<GreetingsCard> findAll( Plugin plugin )
128 {
129 return _dao.findAll( plugin );
130 }
131
132 /**
133 * Returns the list of greetings cards of a greetings card template
134 * @param nIdGreetingsCardTemplate The greetings card template identifier
135 * @param plugin The plugin
136 * @return A Collection of greetings cards
137 */
138 public static Collection<GreetingsCard> findByGreetingsCardTemplateId( int nIdGreetingsCardTemplate, Plugin plugin )
139 {
140 return _dao.findByGreetingsCardTemplateId( nIdGreetingsCardTemplate, plugin );
141 }
142
143 /**
144 * Returns the list of domain name of mail sent
145 * @param greetingsCardFilter The greetings card filter
146 * @param plugin The plugin
147 * @return A Collection of greetings cards
148 */
149 public static List<String> findDomainNameOfMailSent( GreetingsCardFilter greetingsCardFilter, Plugin plugin )
150 {
151 return _dao.findDomainNameOfMailSent( greetingsCardFilter, plugin );
152 }
153
154 /**
155 * Return the number of mail sent for each domains
156 * @param greetingsCardFilter The greetings card filter
157 * @param plugin The plugin
158 * @return A map containing associations of domain names and numbers of email sent. Only cards matching the filter are considered.
159 */
160 public static Map<String, Integer> findNumberOfMailSentByDomain( GreetingsCardFilter greetingsCardFilter, Plugin plugin )
161 {
162 return _dao.findNumberOfMailSentByDomain( greetingsCardFilter, plugin );
163 }
164
165 /**
166 * Get the total number of cards sent without archives. Copies are ignored
167 * @param plugin The plugin
168 * @return The number of cards sent without copies and archives.
169 */
170 public static int findNumberTotalOfMailSentWithoutCopy( Plugin plugin )
171 {
172 return _dao.findNumberTotalOfMailSentWithoutCopy( plugin );
173 }
174
175 /**
176 * Return the number of mail red for each domains
177 * @param greetingsCardFilter The greetings card filter
178 * @param plugin The plugin
179 * @return A map containing associations of domain names and numbers of email red. Only cards matching the filter are considered.
180 */
181 public static Map<String, Integer> findNumberOfMailReadByDomain( GreetingsCardFilter greetingsCardFilter, Plugin plugin )
182 {
183 return _dao.findNumberOfMailReadByDomain( greetingsCardFilter, plugin );
184 }
185
186 /**
187 * Get the collection of greetings cards that has been red and that has the notify sender flag set.
188 * @param nStatus Status
189 * @param plugin The plugin
190 * @return The collection of greetings cards that has been red and that has the notify sender flag set. The collection may be empty.
191 */
192 public static Collection<GreetingsCard> findCardsToSendNotification( Plugin plugin )
193 {
194 return _dao.findCardsToSendNotification( plugin );
195 }
196
197 /**
198 * Get greetings card with a given template and sent between two given dates
199 * @param nIdGreetingsCardTemplate Id of the template of greetings cards
200 * @param dateMin Minimum sent date. If the date is null, then it is ignored
201 * @param dateMax Maximum sent date. If the date is null, then it is ignored
202 * @param nResultsLimit Maximum number of results returned. If the number is 0, then every object is considered
203 * @param plugin The plugin
204 * @return The collection of greetings cards. Messages and messages 2 of greetings cards are not loaded.
205 */
206 public static Collection<GreetingsCard> findByTemplateAndDate( int nIdGreetingsCardTemplate, Date dateMin, Date dateMax, int nResultsLimit, Plugin plugin )
207 {
208 return _dao.findByTemplateAndDate( nIdGreetingsCardTemplate, dateMin, dateMax, nResultsLimit, plugin );
209 }
210 }