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