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.lang.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
59 public class AdminUserFieldFilter
60 {
61
62 private static final String CONSTANT_ESPERLUETTE = "&";
63 private static final String CONSTANT_EQUAL = "=";
64 private static final String CONSTANT_UNDERSCORE = "_";
65 private static final int ALL_INT = -1;
66
67
68 private static final String PARAMETER_SEARCH_IS_SEARCH = "search_is_search";
69 private static final String PARAMETER_ATTRIBUTE = "attribute";
70
71
72 private static final String PROPERTY_ENCODING_URL = "lutece.encoding.url";
73 private List<AdminUserField> _listUserFields;
74 private int _nIdUser = ALL_INT;
75 private int _nIdAttribute = ALL_INT;
76 private int _nIdField = ALL_INT;
77
78
79
80
81
82 public List<AdminUserField> getListUserFields( )
83 {
84 return _listUserFields;
85 }
86
87
88
89
90
91 public void setListUserFields( List<AdminUserField> listUserFields )
92 {
93 _listUserFields = listUserFields;
94 }
95
96
97
98
99
100 public int getIdUser( )
101 {
102 return _nIdUser;
103 }
104
105
106
107
108
109 public void setIdUser( int nIdUser )
110 {
111 _nIdUser = nIdUser;
112 }
113
114
115
116
117
118 public int getIdAttribute( )
119 {
120 return _nIdAttribute;
121 }
122
123
124
125
126
127 public void setIdAttribute( int nIdAttribute )
128 {
129 _nIdAttribute = nIdAttribute;
130 }
131
132
133
134
135
136 public int getIdField( )
137 {
138 return _nIdField;
139 }
140
141
142
143
144
145 public void setIdField( int nIdField )
146 {
147 _nIdField = nIdField;
148 }
149
150
151
152
153
154 public boolean containsIdAttribute( )
155 {
156 return ( _nIdAttribute != ALL_INT );
157 }
158
159
160
161
162
163 public boolean containsIdUser( )
164 {
165 return ( _nIdUser != ALL_INT );
166 }
167
168
169
170
171
172 public boolean containsIdField( )
173 {
174 return ( _nIdField != ALL_INT );
175 }
176
177
178
179
180
181
182 public void setAdminUserFieldFilter( HttpServletRequest request, Locale locale )
183 {
184 _listUserFields = new ArrayList<AdminUserField>( );
185
186 String strIsSearch = request.getParameter( PARAMETER_SEARCH_IS_SEARCH );
187
188 if ( strIsSearch != null )
189 {
190 List<IAttribute> listAttributes = AttributeService.getInstance( ).getAllAttributesWithoutFields( locale );
191
192 for ( IAttribute attribute : listAttributes )
193 {
194 for ( AdminUserField userField : attribute.getUserFieldsData( request, null ) )
195 {
196 if ( ( userField != null ) && StringUtils.isNotBlank( userField.getValue( ) ) )
197 {
198 _listUserFields.add( userField );
199 }
200 }
201 }
202 }
203 }
204
205
206
207
208
209 public void setUrlAttributes( UrlItem url )
210 {
211 for ( AdminUserField userField : _listUserFields )
212 {
213 try
214 {
215 url.addParameter( PARAMETER_ATTRIBUTE + CONSTANT_UNDERSCORE +
216 userField.getAttribute( ).getIdAttribute( ),
217 URLEncoder.encode( userField.getValue( ), AppPropertiesService.getProperty( PROPERTY_ENCODING_URL ) ) );
218 }
219 catch ( UnsupportedEncodingException e )
220 {
221 AppLogService.error( e.getMessage( ), e );
222 }
223 }
224 }
225
226
227
228
229
230 public String getUrlAttributes( )
231 {
232 StringBuilder sbUrlAttributes = new StringBuilder( );
233
234 for ( AdminUserField userField : _listUserFields )
235 {
236 try
237 {
238 sbUrlAttributes.append( CONSTANT_ESPERLUETTE + PARAMETER_ATTRIBUTE + CONSTANT_UNDERSCORE +
239 userField.getAttribute( ).getIdAttribute( ) + CONSTANT_EQUAL +
240 URLEncoder.encode( userField.getValue( ), AppPropertiesService.getProperty( PROPERTY_ENCODING_URL ) ) );
241 }
242 catch ( UnsupportedEncodingException e )
243 {
244 AppLogService.error( e.getMessage( ), e );
245 }
246 }
247
248 return sbUrlAttributes.toString( );
249 }
250 }