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.user.attribute;
35  
36  import fr.paris.lutece.portal.business.file.FileHome;
37  import fr.paris.lutece.portal.business.user.AdminUser;
38  import fr.paris.lutece.portal.service.spring.SpringContextService;
39  
40  import java.util.List;
41  
42  
43  /**
44   *
45   * AdminUserFieldHome
46   *
47   */
48  public final class AdminUserFieldHome
49  {
50      private static IAdminUserFieldDAO _dao = (IAdminUserFieldDAO) SpringContextService.getBean( "adminUserFieldDAO" );
51  
52      /**
53       * Private constructor
54       */
55      private AdminUserFieldHome(  )
56      {
57      }
58  
59      /**
60       * Load the user field
61       * @param nIdUserField ID
62       * @return AdminUserField
63       */
64      public static AdminUserField findByPrimaryKey( int nIdUserField )
65      {
66          return _dao.load( nIdUserField );
67      }
68  
69      /**
70       * Insert a new user field
71       * @param userField the user field
72       */
73      public static void create( AdminUserField userField )
74      {
75          if ( userField.getFile(  ) != null )
76          {
77              userField.getFile(  ).setIdFile( FileHome.create( userField.getFile(  ) ) );
78          }
79  
80          _dao.insert( userField );
81      }
82  
83      /**
84       * Update an user field
85       * @param userField the user field
86       */
87      public static void update( AdminUserField userField )
88      {
89          if ( userField.getFile(  ) != null )
90          {
91              FileHome.update( userField.getFile(  ) );
92          }
93  
94          _dao.store( userField );
95      }
96  
97      /**
98       * Delete an attribute.
99       *
100      * @param userField the user field
101      */
102     public static void remove( AdminUserField userField )
103     {
104         if ( userField != null )
105         {
106             if ( userField.getFile(  ) != null )
107             {
108                 FileHome.remove( userField.getFile(  ).getIdFile(  ) );
109             }
110 
111             _dao.delete( userField.getIdUserField(  ) );
112         }
113     }
114 
115     /**
116      * Delete all user fields from given id field
117      * @param nIdField id field
118      */
119     public static void removeUserFieldsFromIdField( int nIdField )
120     {
121         _dao.deleteUserFieldsFromIdField( nIdField );
122     }
123 
124     /**
125      * Delete all user fields from given id user
126      * @param nIdUser id user
127      */
128     public static void removeUserFieldsFromIdUser( int nIdUser )
129     {
130         _dao.deleteUserFieldsFromIdUser( nIdUser );
131     }
132 
133     /**
134      * Delete all user fields from given id attribute
135      * @param nIdAttribute id attribute
136      */
137     public static void removeUserFieldsFromIdAttribute( int nIdAttribute )
138     {
139         _dao.deleteUserFieldsFromIdAttribute( nIdAttribute );
140     }
141 
142     /**
143      * Load all the user field by a given ID user and a given ID attribute
144      * @param nIdUser the ID user
145      * @param nIdAttribute the attribute identifier
146      * @return a list of adminuserfield
147      */
148     public static List<AdminUserField> selectUserFieldsByIdUserIdAttribute( int nIdUser, int nIdAttribute )
149     {
150         return _dao.selectUserFieldsByIdUserIdAttribute( nIdUser, nIdAttribute );
151     }
152 
153     /**
154      * Load users by a given filter
155      * @param auFieldFilter the filter
156      * @return a list of users
157      */
158     public static List<AdminUser> findUsersByFilter( AdminUserFieldFilter auFieldFilter )
159     {
160         return _dao.selectUsersByFilter( auFieldFilter );
161     }
162 
163     /**
164      * Select by filter
165      * @param auFieldFilter the filter
166      * @return a list of admin user field
167      */
168     public static List<AdminUserField> findByFilter( AdminUserFieldFilter auFieldFilter )
169     {
170         return _dao.selectByFilter( auFieldFilter );
171     }
172 
173     /**
174      * Remove by filter
175      * @param auFieldFilter the filter
176      */
177     public static void removeByFilter( AdminUserFieldFilter auFieldFilter )
178     {
179         List<AdminUserField> listUserFields = findByFilter( auFieldFilter );
180 
181         for ( AdminUserField userField : listUserFields )
182         {
183             remove( userField );
184         }
185     }
186 }