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.newsletter.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.ArrayList;
40 import java.util.List;
41
42 /**
43 * This class provides instances management methods (create, find, ...) for SendingNewsLetter objects
44 */
45 public final class SendingNewsLetterHome
46 {
47 // Static variable pointed at the DAO instance
48 private static ISendingNewsLetterDAO _dao = SpringContextService.getBean( "newsletter.sendingNewsLetterDAO" );
49
50 /**
51 * Private constructor - this class need not be instantiated
52 */
53 private SendingNewsLetterHome( )
54 {
55 }
56
57 /**
58 * Create an instance of a newsletter sending
59 *
60 * @param sending
61 * The object to insert in the database
62 * @param plugin
63 * the plugin
64 * @return the instance created
65 */
66 public static SendingNewsLetter../../../fr/paris/lutece/plugins/newsletter/business/SendingNewsLetter.html#SendingNewsLetter">SendingNewsLetter create( SendingNewsLetter sending, Plugin plugin )
67 {
68 _dao.insert( sending, plugin );
69
70 return sending;
71 }
72
73 /**
74 * remove an entry of a newsletter sending
75 *
76 * @param nId
77 * the primary key of the sending newsletter
78 * @param plugin
79 * the plugin
80 */
81 public static void remove( int nId, Plugin plugin )
82 {
83 _dao.delete( nId, plugin );
84 }
85
86 /**
87 * Update of the sendingNewsLetter which is specified in parameter
88 *
89 * @param sending
90 * the object which contains the data to store
91 * @param plugin
92 * the plugin
93 * @return the new instance updated
94 */
95 public static SendingNewsLetter../../../fr/paris/lutece/plugins/newsletter/business/SendingNewsLetter.html#SendingNewsLetter">SendingNewsLetter update( SendingNewsLetter sending, Plugin plugin )
96 {
97 _dao.store( sending, plugin );
98
99 return sending;
100 }
101
102 ///////////////////////////////////////////////////////////////////////////
103 // Finders
104
105 /**
106 * Returns an object SendingNewsLetter from its identifier
107 *
108 * @param nKey
109 * the primary key of the sending newsletter
110 * @param plugin
111 * the plugin
112 * @return an instance of the class
113 */
114 public static SendingNewsLetter findByPrimaryKey( int nKey, Plugin plugin )
115 {
116 return _dao.load( nKey, plugin );
117 }
118
119 /**
120 * Returns the last sending performed for the newsletter of given id
121 *
122 * @param newsletterId
123 * the newsletter id for wich we need the last sending
124 * @param plugin
125 * the plugin
126 * @return the last sending for the given newsletter id - null if no sending found
127 */
128 public static SendingNewsLetter findLastSendingForNewsletterId( int newsletterId, Plugin plugin )
129 {
130 return _dao.selectLastSendingForNewsletterId( newsletterId, plugin );
131 }
132
133 /**
134 * Returns all the last sending performed for the newsletter of given id
135 *
136 * @param newsletterId
137 * the newsletter id for wich we need the last sending
138 * @param plugin
139 * the plugin
140 * @return the last sending for the given newsletter id - null if no sending found
141 */
142 public static List<SendingNewsLetter> findAllLastSendingForNewsletterId( int newsletterId, Plugin plugin )
143 {
144 return _dao.selectAllLastSendingForNewsletterId( newsletterId, plugin );
145 }
146
147 /**
148 * Returns all the sendings in the database.
149 *
150 * @param plugin
151 * the plugin
152 * @return a list of SendingNewsLetter objects.
153 */
154 public static List<SendingNewsLetter> findAllSendings( Plugin plugin )
155 {
156 return _dao.findAllSendings( plugin );
157 }
158
159 /**
160 * Returns all the sendings in the database.
161 *
162 * @return a list of SendingNewsLetter objects.
163 * @param listId
164 * A list of sent newsletters
165 * @param plugin
166 * the plugin
167 */
168 public static ArrayList<SendingNewsLetter> findSendingsByIds( ArrayList<Integer> listId, Plugin plugin )
169 {
170 return _dao.findSendingsByIds( listId, plugin );
171 }
172 }