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 import fr.paris.lutece.util.ReferenceList;
39
40 import java.util.Collection;
41 import java.util.List;
42
43 /**
44 * This class provides instances management methods (create, find, ...) for NewsLetterTemplate objects
45 */
46 public final class NewsLetterTemplateHome
47 {
48 /**
49 * The data access object initialised by Spring mechanism
50 */
51 private static INewsLetterTemplateDAO _dao = SpringContextService.getBean( "newsletter.newsLetterTemplateDAO" );
52
53 /**
54 * Private constructor - this class need not be instantiated
55 */
56 private NewsLetterTemplateHome( )
57 {
58 }
59
60 /**
61 * Returns the list of every templates
62 *
63 * @param plugin
64 * The Plugin
65 * @return a collection object
66 */
67 public static Collection<NewsLetterTemplate> getTemplatesList( Plugin plugin )
68 {
69 return _dao.selectTemplatesList( plugin );
70 }
71
72 /**
73 * Returns a list of templates depending on the given type
74 *
75 * @param strTopicType
76 * the topic type of templates to retrieve
77 * @param plugin
78 * The Plugin
79 * @return a Referencelist object
80 */
81 public static ReferenceList getTemplatesListByType( String strTopicType, Plugin plugin )
82 {
83 return _dao.selectTemplatesListByType( strTopicType, plugin );
84 }
85
86 /**
87 * Returns a list of templates depending on the given topic type
88 *
89 * @param strTopicType
90 * the topic type of templates to retrieve
91 * @param plugin
92 * The Plugin
93 * @return a Collection object
94 */
95 public static List<NewsLetterTemplate> getTemplatesCollectionByType( String strTopicType, Plugin plugin )
96 {
97 return _dao.selectTemplatesCollectionByType( strTopicType, plugin );
98 }
99
100 /**
101 * Creation of an instance of a newsletter template
102 *
103 * @param newsletterTemplate
104 * template An instance of a newsletter template which contains the informations to store
105 * @param plugin
106 * The Plugin
107 * @return The instance of a newsletter template which has been created with its primary key.
108 */
109 public static NewsLetterTemplate./../../fr/paris/lutece/plugins/newsletter/business/NewsLetterTemplate.html#NewsLetterTemplate">NewsLetterTemplate create( NewsLetterTemplate newsletterTemplate, Plugin plugin )
110 {
111 _dao.insert( newsletterTemplate, plugin );
112
113 return newsletterTemplate;
114 }
115
116 /**
117 * Returns an object NewsLetter's template from its identifier
118 *
119 * @param nKey
120 * the primary key of the newsletter's template
121 * @param plugin
122 * The Plugin
123 * @return an instance of the class
124 */
125 public static NewsLetterTemplate findByPrimaryKey( int nKey, Plugin plugin )
126 {
127 return _dao.load( nKey, plugin );
128 }
129
130 /**
131 * Update of an instance of a newsletter template
132 *
133 * @param newsletterTemplate
134 * template An instance of a newsletter template which contains the informations to store
135 * @param plugin
136 * The Plugin
137 * @return The instance of a newsletter template which has been updated with its primary key.
138 */
139 public static NewsLetterTemplate./../../fr/paris/lutece/plugins/newsletter/business/NewsLetterTemplate.html#NewsLetterTemplate">NewsLetterTemplate update( NewsLetterTemplate newsletterTemplate, Plugin plugin )
140 {
141 _dao.store( newsletterTemplate, plugin );
142
143 return newsletterTemplate;
144 }
145
146 /**
147 * Remove the record from the template identifier
148 *
149 * @param nNewsLetterTemplateId
150 * the template identifier
151 * @param plugin
152 * the Plugin
153 */
154 public static void remove( int nNewsLetterTemplateId, Plugin plugin )
155 {
156 _dao.delete( nNewsLetterTemplateId, plugin );
157 }
158
159 /**
160 * Fetches a template list
161 *
162 * @param plugin
163 * The plugin
164 * @return A reference list
165 */
166 public static ReferenceList getTemplateListByRef( Plugin plugin )
167 {
168 return _dao.selectTemplatesByRef( plugin );
169 }
170
171 /**
172 * Returns the list of templates associated with a given workgroup
173 *
174 * @param strWorkgroupKey
175 * The workgoup key
176 * @param plugin
177 * The Plugin
178 * @return a collection object
179 */
180 public static Collection<NewsLetterTemplate> getTemplatesListByWorkgoup( String strWorkgroupKey, Plugin plugin )
181 {
182 return _dao.selectTemplatesListByWorkgoup( strWorkgroupKey, plugin );
183 }
184 }