1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.business.user.attribute;
35
36 import fr.paris.lutece.portal.service.user.attribute.AttributeService;
37 import fr.paris.lutece.portal.service.util.AppLogService;
38 import fr.paris.lutece.portal.service.util.AppPropertiesService;
39 import fr.paris.lutece.util.url.UrlItem;
40
41 import org.apache.commons.lang3.StringUtils;
42
43 import java.io.UnsupportedEncodingException;
44
45 import java.net.URLEncoder;
46
47 import java.util.ArrayList;
48 import java.util.List;
49 import java.util.Locale;
50
51 import javax.servlet.http.HttpServletRequest;
52
53
54
55
56
57
58 public class AdminUserFieldFilter
59 {
60
61 private static final String CONSTANT_ESPERLUETTE = "&";
62 private static final String CONSTANT_EQUAL = "=";
63 private static final String CONSTANT_UNDERSCORE = "_";
64 private static final int ALL_INT = -1;
65
66
67 private static final String PARAMETER_SEARCH_IS_SEARCH = "search_is_search";
68 private static final String PARAMETER_ATTRIBUTE = "attribute";
69
70
71 private static final String PROPERTY_ENCODING_URL = "lutece.encoding.url";
72 private List<AdminUserField> _listUserFields;
73 private int _nIdUser = ALL_INT;
74 private int _nIdAttribute = ALL_INT;
75 private int _nIdField = ALL_INT;
76
77
78
79
80
81
82 public List<AdminUserField> getListUserFields( )
83 {
84 return _listUserFields;
85 }
86
87
88
89
90
91
92
93 public void setListUserFields( List<AdminUserField> listUserFields )
94 {
95 _listUserFields = listUserFields;
96 }
97
98
99
100
101
102
103 public int getIdUser( )
104 {
105 return _nIdUser;
106 }
107
108
109
110
111
112
113
114 public void setIdUser( int nIdUser )
115 {
116 _nIdUser = nIdUser;
117 }
118
119
120
121
122
123
124 public int getIdAttribute( )
125 {
126 return _nIdAttribute;
127 }
128
129
130
131
132
133
134
135 public void setIdAttribute( int nIdAttribute )
136 {
137 _nIdAttribute = nIdAttribute;
138 }
139
140
141
142
143
144
145 public int getIdField( )
146 {
147 return _nIdField;
148 }
149
150
151
152
153
154
155
156 public void setIdField( int nIdField )
157 {
158 _nIdField = nIdField;
159 }
160
161
162
163
164
165
166 public boolean containsIdAttribute( )
167 {
168 return ( _nIdAttribute != ALL_INT );
169 }
170
171
172
173
174
175
176 public boolean containsIdUser( )
177 {
178 return ( _nIdUser != ALL_INT );
179 }
180
181
182
183
184
185
186 public boolean containsIdField( )
187 {
188 return ( _nIdField != ALL_INT );
189 }
190
191
192
193
194
195
196
197
198
199 public void setAdminUserFieldFilter( HttpServletRequest request, Locale locale )
200 {
201 _listUserFields = new ArrayList<>( );
202
203 String strIsSearch = request.getParameter( PARAMETER_SEARCH_IS_SEARCH );
204
205 if ( strIsSearch != null )
206 {
207 List<IAttribute> listAttributes = AttributeService.getInstance( ).getAllAttributesWithoutFields( locale );
208
209 for ( IAttribute attribute : listAttributes )
210 {
211 for ( AdminUserField userField : attribute.getUserFieldsData( request, null ) )
212 {
213 if ( ( userField != null ) && StringUtils.isNotBlank( userField.getValue( ) ) )
214 {
215 _listUserFields.add( userField );
216 }
217 }
218 }
219 }
220 }
221
222
223
224
225
226
227
228 public void setUrlAttributes( UrlItem url )
229 {
230 for ( AdminUserField userField : _listUserFields )
231 {
232 try
233 {
234 url.addParameter( PARAMETER_ATTRIBUTE + CONSTANT_UNDERSCORE + userField.getAttribute( ).getIdAttribute( ),
235 URLEncoder.encode( userField.getValue( ), AppPropertiesService.getProperty( PROPERTY_ENCODING_URL ) ) );
236 }
237 catch( UnsupportedEncodingException e )
238 {
239 AppLogService.error( e.getMessage( ), e );
240 }
241 }
242 }
243
244
245
246
247
248
249 public String getUrlAttributes( )
250 {
251 StringBuilder sbUrlAttributes = new StringBuilder( );
252
253 for ( AdminUserField userField : _listUserFields )
254 {
255 try
256 {
257 sbUrlAttributes.append( CONSTANT_ESPERLUETTE + PARAMETER_ATTRIBUTE + CONSTANT_UNDERSCORE + userField.getAttribute( ).getIdAttribute( )
258 + CONSTANT_EQUAL + URLEncoder.encode( userField.getValue( ), AppPropertiesService.getProperty( PROPERTY_ENCODING_URL ) ) );
259 }
260 catch( UnsupportedEncodingException e )
261 {
262 AppLogService.error( e.getMessage( ), e );
263 }
264 }
265
266 return sbUrlAttributes.toString( );
267 }
268 }