View Javadoc
1   /*
2    * Copyright (c) 2002-2022, 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.portal.business.mailinglist;
35  
36  import fr.paris.lutece.portal.service.spring.SpringContextService;
37  
38  import java.util.Collection;
39  import java.util.List;
40  
41  /**
42   * This class provides instances management methods (create, find, ...) for MailingList objects
43   */
44  public final class MailingListHome
45  {
46      // Static variable pointed at the DAO instance
47      private static IMailingListDAO _dao = SpringContextService.getBean( "mailingListDAO" );
48  
49      /**
50       * Private constructor - this class need not be instantiated
51       */
52      private MailingListHome( )
53      {
54      }
55  
56      /**
57       * Creation of an instance of mailingList
58       *
59       * @param mailingList
60       *            The instance of the MailingList which contains the informations to store
61       * @return The instance of mailingList which has been created with its primary key.
62       */
63      public static MailingList../../../../../fr/paris/lutece/portal/business/mailinglist/MailingList.html#MailingList">MailingList create( MailingList mailingList )
64      {
65          _dao.insert( mailingList );
66  
67          return mailingList;
68      }
69  
70      /**
71       * Update of the mailingList which is specified in parameter
72       *
73       * @param mailingList
74       *            The instance of the MailingList which contains the data to store
75       * @return The instance of the mailingList which has been updated
76       */
77      public static MailingList../../../../../fr/paris/lutece/portal/business/mailinglist/MailingList.html#MailingList">MailingList update( MailingList mailingList )
78      {
79          _dao.store( mailingList );
80  
81          return mailingList;
82      }
83  
84      /**
85       * Remove the mailingList whose identifier is specified in parameter
86       *
87       * @param nMailingListId
88       *            The mailingList Id
89       */
90      public static void remove( int nMailingListId )
91      {
92          _dao.delete( nMailingListId );
93      }
94  
95      // /////////////////////////////////////////////////////////////////////////
96      // Finders
97  
98      /**
99       * Returns an instance of a mailingList whose identifier is specified in parameter
100      *
101      * @param nKey
102      *            The mailingList primary key
103      * @return an instance of MailingList
104      */
105     public static MailingList findByPrimaryKey( int nKey )
106     {
107         return _dao.load( nKey );
108     }
109 
110     /**
111      * Loads the data of all the mailingLists and returns them in form of a collection
112      *
113      * @return the collection which contains the data of all the mailingLists
114      */
115     public static Collection<MailingList> findAll( )
116     {
117         return _dao.selectAll( );
118     }
119 
120     /**
121      * Find all mailing lists visible by a workgroup
122      * 
123      * @param strWorkgroup
124      *            The workgroup
125      * @return A mailing list collection
126      */
127     public static Collection<MailingList> findByWorkgroup( String strWorkgroup )
128     {
129         return _dao.selectByWorkgroup( strWorkgroup );
130     }
131 
132     /**
133      * Add an new user filter to a mailing list
134      * 
135      * @param filter
136      *            The filter to add
137      * @param nId
138      *            The Id of the mailing list
139      */
140     public static void addFilterToMailingList( MailingListUsersFilter filter, int nId )
141     {
142         _dao.insertFilter( filter, nId );
143     }
144 
145     /**
146      * Remove an user filter from a mailing list
147      * 
148      * @param filter
149      *            The filter to remove
150      * @param nId
151      *            The Id of the mailing list
152      */
153     public static void deleteFilterToMailingList( MailingListUsersFilter filter, int nId )
154     {
155         _dao.deleteFilter( filter, nId );
156     }
157 
158     /**
159      * Check if the filter already exists or not in a mailing list
160      * 
161      * @param filter
162      *            the filter
163      * @param nId
164      *            the id mailing list
165      * @return true if it already exists, false otherwise
166      */
167     public static boolean checkFilter( MailingListUsersFilter filter, int nId )
168     {
169         return _dao.checkFilter( filter, nId );
170     }
171 
172     /**
173      * Find by filter.
174      *
175      * @param filter
176      *            the filter
177      * @return the list
178      */
179     public static List<MailingList> findsByFilter( MailingListFilter filter )
180     {
181         return _dao.selectByFilter( filter );
182     }
183 }