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.workgroup;
35  
36  import fr.paris.lutece.portal.business.user.AdminUser;
37  import fr.paris.lutece.portal.service.spring.SpringContextService;
38  import fr.paris.lutece.util.ReferenceList;
39  
40  import java.util.Collection;
41  
42  /**
43   * This class provides instances management methods (create, find, ...) for AdminWorkgroup objects
44   */
45  public final class AdminWorkgroupHome
46  {
47      // Static variable pointed at the DAO instance
48      private static IAdminWorkgroupDAO _dao = SpringContextService.getBean( "adminWorkgroupDAO" );
49  
50      /**
51       * Private constructor - this class need not be instantiated
52       */
53      private AdminWorkgroupHome( )
54      {
55      }
56  
57      /**
58       * Creation of an instance of workgroup
59       *
60       * @param workgroup
61       *            The instance of the workgroup which contains the informations to store
62       * @return The instance of workgroup which has been created with its primary key.
63       */
64      public static AdminWorkgroup../../../../fr/paris/lutece/portal/business/workgroup/AdminWorkgroup.html#AdminWorkgroup">AdminWorkgroup create( AdminWorkgroup workgroup )
65      {
66          _dao.insert( workgroup );
67  
68          return workgroup;
69      }
70  
71      /**
72       * Update of the workgroup which is specified in parameter
73       * 
74       * @param workgroup
75       *            The instance of the workgroup which contains the new data to store
76       * @return The instance of the workgroup which has been updated
77       */
78      public static AdminWorkgroup../../../../fr/paris/lutece/portal/business/workgroup/AdminWorkgroup.html#AdminWorkgroup">AdminWorkgroup update( AdminWorkgroup workgroup )
79      {
80          _dao.store( workgroup );
81  
82          return workgroup;
83      }
84  
85      /**
86       * Remove the AdminWorkgroup whose identifier is specified in parameter
87       *
88       * @param strWorkgroupKey
89       *            The AdminWorkgroup object to remove
90       */
91      public static void remove( String strWorkgroupKey )
92      {
93          _dao.delete( strWorkgroupKey );
94      }
95  
96      // /////////////////////////////////////////////////////////////////////////
97      // Finders
98  
99      /**
100      * Returns an instance of a workgroup whose identifier is specified in parameter
101      *
102      * @param strWorkgroupKey
103      *            The key of the workgroup
104      * @return An instance of workgroup
105      */
106     public static AdminWorkgroup findByPrimaryKey( String strWorkgroupKey )
107     {
108         return _dao.load( strWorkgroupKey );
109     }
110 
111     /**
112      * Returns a collection of workgroups objects
113      * 
114      * @return A collection of workgroups
115      */
116     public static Collection<AdminWorkgroup> findAll( )
117     {
118         return _dao.selectWorkgroupList( );
119     }
120 
121     /**
122      * Check that the given key points to an existing workgroup
123      * 
124      * @param strWorkgroupKey
125      *            The workgroup key
126      * @return true if the workgroup exists, false otherwise
127      */
128     public static boolean checkExistWorkgroup( String strWorkgroupKey )
129     {
130         return _dao.checkExistWorkgroup( strWorkgroupKey );
131     }
132 
133     /**
134      * Is the user member of the workgroup
135      * 
136      * @param user
137      *            The user
138      * @param strWorkgroup
139      *            The workgroup key
140      * @return True if the user is in the workgroup, otherwise false
141      */
142     public static boolean isUserInWorkgroup( AdminUser user, String strWorkgroup )
143     {
144         return _dao.isUserInWorkgroup( user.getUserId( ), strWorkgroup );
145     }
146 
147     /**
148      * Is the user member of the workgroup
149      * 
150      * @param nIdUser
151      *            The user identifier
152      * @return True if the user is in a workgroup, otherwise false
153      */
154     public static boolean checkUserHasWorkgroup( int nIdUser )
155     {
156         return _dao.checkUserHasWorkgroup( nIdUser );
157     }
158 
159     /**
160      * Returns the list of all workgroups the user is member
161      * 
162      * @param user
163      *            The user
164      * @return A reference list of all user's workgroups
165      */
166     public static ReferenceList getUserWorkgroups( AdminUser user )
167     {
168         return _dao.getUserWorkgroups( user.getUserId( ) );
169     }
170 
171     /**
172      * Returns the list of all users for a workgroup
173      * 
174      * @param strWorkgroupKey
175      *            The workgroup key
176      * @return A list of all users of the workgroup
177      */
178     public static Collection<AdminUser> getUserListForWorkgroup( String strWorkgroupKey )
179     {
180         return _dao.getUsersListForWorkgroup( strWorkgroupKey );
181     }
182 
183     /**
184      * Add user to the workgroup
185      * 
186      * @param user
187      *            The user
188      * @param strWorkgroupKey
189      *            The workgroup key
190      */
191     public static void addUserForWorkgroup( AdminUser user, String strWorkgroupKey )
192     {
193         _dao.insertUserForWorkgroup( user, strWorkgroupKey );
194     }
195 
196     /**
197      * Remove all users of a workgroup
198      * 
199      * @param strWorkgroupKey
200      *            The workgroup key
201      */
202     public static void removeAllUsersForWorkgroup( String strWorkgroupKey )
203     {
204         _dao.deleteAllUsersForWorkgroup( strWorkgroupKey );
205     }
206 
207     /**
208      * Remove an user from a workgroup
209      * 
210      * @param user
211      *            The user
212      * @param strWorkgroupKey
213      *            The workgroup key
214      */
215     public static void removeUserFromWorkgroup( AdminUser user, String strWorkgroupKey )
216     {
217         _dao.deleteUserFromWorkgroup( user.getUserId( ), strWorkgroupKey );
218     }
219 
220     /**
221      * Find workgroups from a filter
222      * 
223      * @param awFilter
224      *            the filter
225      * @return the list of workgroups
226      */
227     public static Collection<AdminWorkgroup> findByFilter( AdminWorkgroupFilter awFilter )
228     {
229         return _dao.selectWorkgroupsByFilter( awFilter );
230     }
231 }