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.service.user.attribute;
35  
36  import fr.paris.lutece.portal.business.user.AdminUser;
37  import fr.paris.lutece.portal.business.user.attribute.AdminUserField;
38  import fr.paris.lutece.portal.business.user.attribute.AdminUserFieldListener;
39  import fr.paris.lutece.portal.business.user.attribute.SimpleAdminUserFieldListener;
40  
41  import java.util.ArrayList;
42  import java.util.List;
43  import java.util.Locale;
44  
45  import javax.servlet.http.HttpServletRequest;
46  
47  /**
48   *
49   * AdminUserFieldListenerService
50   *
51   */
52  public class AdminUserFieldListenerService
53  {
54      private List<AdminUserFieldListener> _listRegisteredListeners = new ArrayList<>( );
55  
56      /**
57       * Register a new Removal listener
58       * 
59       * @param listener
60       *            The listener to register
61       */
62      public void registerListener( AdminUserFieldListener listener )
63      {
64          _listRegisteredListeners.add( listener );
65      }
66  
67      /**
68       * Create user fields
69       * 
70       * @param user
71       *            AdminUser
72       * @param request
73       *            HttpServletRequest
74       * @param locale
75       *            locale
76       */
77      public void doCreateUserFields( AdminUser user, HttpServletRequest request, Locale locale )
78      {
79          for ( AdminUserFieldListener listener : _listRegisteredListeners )
80          {
81              listener.doCreateUserFields( user, request, locale );
82          }
83      }
84  
85      /**
86       * Modify user fields
87       * 
88       * @param user
89       *            AdminUser
90       * @param request
91       *            HttpServletRequest
92       * @param locale
93       *            locale
94       * @param currentUser
95       *            current user
96       */
97      public void doModifyUserFields( AdminUserl/business/user/AdminUser.html#AdminUser">AdminUser user, HttpServletRequest request, Locale locale, AdminUser currentUser )
98      {
99          for ( AdminUserFieldListener listener : _listRegisteredListeners )
100         {
101             listener.doModifyUserFields( user, request, locale, currentUser );
102         }
103     }
104 
105     /**
106      * Remove user fields
107      * 
108      * @param user
109      *            Adminuser
110      * @param request
111      *            HttpServletRequest
112      * @param locale
113      *            locale
114      */
115     public void doRemoveUserFields( AdminUser user, HttpServletRequest request, Locale locale )
116     {
117         for ( AdminUserFieldListener listener : _listRegisteredListeners )
118         {
119             listener.doRemoveUserFields( user, request, locale );
120         }
121     }
122 
123     /**
124      * Create user fields
125      * 
126      * @param user
127      *            AdminUser
128      * @param listUserFields
129      *            The list of user fields to create
130      * @param locale
131      *            locale
132      */
133     public void doCreateUserFields( AdminUser user, List<AdminUserField> listUserFields, Locale locale )
134     {
135         for ( AdminUserFieldListener listener : _listRegisteredListeners )
136         {
137             if ( listener instanceof SimpleAdminUserFieldListener )
138             {
139                 ( (SimpleAdminUserFieldListener) listener ).doCreateUserFields( user, listUserFields, locale );
140             }
141         }
142     }
143 
144     /**
145      * Modify user fields
146      * 
147      * @param user
148      *            AdminUser
149      * @param listUserFields
150      *            The list of user fields to modify
151      * @param locale
152      *            locale
153      * @param currentUser
154      *            current user
155      */
156     public void doModifyUserFields( AdminUser/AdminUser.html#AdminUser">AdminUser user, List<AdminUserField> listUserFields, Locale locale, AdminUser currentUser )
157     {
158         for ( AdminUserFieldListener listener : _listRegisteredListeners )
159         {
160             if ( listener instanceof SimpleAdminUserFieldListener )
161             {
162                 ( (SimpleAdminUserFieldListener) listener ).doModifyUserFields( user, listUserFields, locale, currentUser );
163             }
164         }
165     }
166 
167     /**
168      * Remove user fields
169      * 
170      * @param user
171      *            Adminuser
172      * @param locale
173      *            locale
174      */
175     public void doRemoveUserFields( AdminUser user, Locale locale )
176     {
177         for ( AdminUserFieldListener listener : _listRegisteredListeners )
178         {
179             if ( listener instanceof SimpleAdminUserFieldListener )
180             {
181                 ( (SimpleAdminUserFieldListener) listener ).doRemoveUserFields( user, locale );
182             }
183         }
184     }
185 }