View Javadoc
1   /*
2    * Copyright (c) 2002-2014, 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.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  /**
44   * This class provides instances management methods (create, find, ...) for AdminWorkgroup objects
45   */
46  public final class AdminWorkgroupHome
47  {
48      // Static variable pointed at the DAO instance
49      private static IAdminWorkgroupDAO _dao = (IAdminWorkgroupDAO) SpringContextService.getBean( "adminWorkgroupDAO" );
50  
51      /**
52       * Private constructor - this class need not be instantiated
53       */
54      private AdminWorkgroupHome(  )
55      {
56      }
57  
58      /**
59       * Creation of an instance of workgroup
60       *
61       * @param workgroup 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 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       * @param workgroup The instance of the workgroup which contains the new data to store
74       * @return The instance of the  workgroup which has been updated
75       */
76      public static AdminWorkgroup update( AdminWorkgroup workgroup )
77      {
78          _dao.store( workgroup );
79  
80          return workgroup;
81      }
82  
83      /**
84       * Remove the AdminWorkgroup whose identifier is specified in parameter
85       *
86       * @param strWorkgroupKey The AdminWorkgroup object to remove
87       */
88      public static void remove( String strWorkgroupKey )
89      {
90          _dao.delete( strWorkgroupKey );
91      }
92  
93      ///////////////////////////////////////////////////////////////////////////
94      // Finders
95  
96      /**
97       * Returns an instance of a workgroup whose identifier is specified in parameter
98       *
99       * @param strWorkgroupKey The key of the workgroup
100      * @return An instance of workgroup
101      */
102     public static AdminWorkgroup findByPrimaryKey( String strWorkgroupKey )
103     {
104         return _dao.load( strWorkgroupKey );
105     }
106 
107     /**
108      * Returns a collection of workgroups objects
109      * @return A collection of workgroups
110      */
111     public static Collection<AdminWorkgroup> findAll(  )
112     {
113         return _dao.selectWorkgroupList(  );
114     }
115 
116     /**
117      * Check that the given key points to an existing workgroup
118      * @param strWorkgroupKey The workgroup key
119      * @return true if the workgroup exists, false otherwise
120      */
121     public static boolean checkExistWorkgroup( String strWorkgroupKey )
122     {
123         return _dao.checkExistWorkgroup( strWorkgroupKey );
124     }
125 
126     /**
127      * Is the user member of the workgroup
128      * @param user The user
129      * @param strWorkgroup The workgroup key
130      * @return True if the user is in the workgroup, otherwise false
131      */
132     public static boolean isUserInWorkgroup( AdminUser user, String strWorkgroup )
133     {
134         return _dao.isUserInWorkgroup( user.getUserId(  ), strWorkgroup );
135     }
136 
137     /**
138      * Is the user member of the workgroup
139      * @param nIdUser The user identifier
140      * @return True if the user is in a workgroup, otherwise false
141      */
142     public static boolean checkUserHasWorkgroup( int nIdUser )
143     {
144         return _dao.checkUserHasWorkgroup( nIdUser );
145     }
146 
147     /**
148      * Returns the list of all workgroups the user is member
149      * @param user The user
150      * @return A reference list of all user's workgroups
151      */
152     public static ReferenceList getUserWorkgroups( AdminUser user )
153     {
154         return _dao.getUserWorkgroups( user.getUserId(  ) );
155     }
156 
157     /**
158       * Returns the list of all users for a workgroup
159       * @param strWorkgroupKey The workgroup key
160       * @return A list of all users of the workgroup
161       */
162     public static Collection<AdminUser> getUserListForWorkgroup( String strWorkgroupKey )
163     {
164         return _dao.getUsersListForWorkgroup( strWorkgroupKey );
165     }
166 
167     /**
168      * Add user to the workgroup
169      * @param user The user
170      * @param strWorkgroupKey The workgroup key
171      */
172     public static void addUserForWorkgroup( AdminUser user, String strWorkgroupKey )
173     {
174         _dao.insertUserForWorkgroup( user, strWorkgroupKey );
175     }
176 
177     /**
178      * Remove all users of a workgroup
179      * @param strWorkgroupKey The workgroup key
180      */
181     public static void removeAllUsersForWorkgroup( String strWorkgroupKey )
182     {
183         _dao.deleteAllUsersForWorkgroup( strWorkgroupKey );
184     }
185 
186     /**
187      * Remove an user from a workgroup
188      * @param user The user
189      * @param strWorkgroupKey The workgroup key
190      */
191     public static void removeUserFromWorkgroup( AdminUser user, String strWorkgroupKey )
192     {
193         _dao.deleteUserFromWorkgroup( user.getUserId(  ), strWorkgroupKey );
194     }
195 
196     /**
197      * Find workgroups from a filter
198      * @param awFilter the filter
199      * @return the list of workgroups
200      */
201     public static Collection<AdminWorkgroup> findByFilter( AdminWorkgroupFilter awFilter )
202     {
203         return _dao.selectWorkgroupsByFilter( awFilter );
204     }
205 }