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.plugin.Plugin;
37 import fr.paris.lutece.portal.service.template.AppTemplateService;
38 import fr.paris.lutece.util.html.HtmlTemplate;
39
40 import java.util.ArrayList;
41 import java.util.HashMap;
42 import java.util.List;
43 import java.util.Locale;
44 import java.util.Map;
45
46
47
48
49
50
51
52 public abstract class AbstractAttribute implements IAttribute
53 {
54
55 private static final String MARK_ATTRIBUTE = "attribute";
56 private static final String MARK_DEFAULT_VALUES_LIST = "default_values_list";
57 private static final String MARK_USER_FIELD = "user_field";
58 private int _nIdAttribute;
59 private boolean _bMandatory;
60 private String _strTitle;
61 private String _strHelpMessage;
62 private int _nPosition;
63 private AttributeType _attributeType;
64 private List<AttributeField> _listAttributeFields;
65 private Plugin _plugin;
66 private boolean _bIsShownInSearch;
67 private boolean _bIsFieldInLine;
68 private boolean _bIsAttributeImage;
69 private boolean _bIsShownInResultList;
70 private boolean _bAnonymize;
71
72
73
74
75 public AbstractAttribute( )
76 {
77 }
78
79
80
81
82
83 @Override
84 public int getIdAttribute( )
85 {
86 return _nIdAttribute;
87 }
88
89
90
91
92
93 @Override
94 public void setIdAttribute( int nIdAttribute )
95 {
96 _nIdAttribute = nIdAttribute;
97 }
98
99
100
101
102
103 @Override
104 public boolean isMandatory( )
105 {
106 return _bMandatory;
107 }
108
109
110
111
112
113 @Override
114 public void setMandatory( boolean bMandatory )
115 {
116 _bMandatory = bMandatory;
117 }
118
119
120
121
122
123 @Override
124 public List<AttributeField> getListAttributeFields( )
125 {
126 return _listAttributeFields;
127 }
128
129
130
131
132
133 @Override
134 public void setListAttributeFields( List<AttributeField> listAttributeFields )
135 {
136 _listAttributeFields = listAttributeFields;
137 }
138
139
140
141
142
143 @Override
144 public String getTitle( )
145 {
146 return _strTitle;
147 }
148
149
150
151
152
153 @Override
154 public void setTitle( String strTitle )
155 {
156 _strTitle = strTitle;
157 }
158
159
160
161
162
163 @Override
164 public String getHelpMessage( )
165 {
166 return _strHelpMessage;
167 }
168
169
170
171
172
173 @Override
174 public void setHelpMessage( String strHelpMessage )
175 {
176 _strHelpMessage = strHelpMessage;
177 }
178
179
180
181
182
183 @Override
184 public int getPosition( )
185 {
186 return _nPosition;
187 }
188
189
190
191
192
193 @Override
194 public void setPosition( int nPosition )
195 {
196 _nPosition = nPosition;
197 }
198
199
200
201
202
203 @Override
204 public AttributeType getAttributeType( )
205 {
206 return _attributeType;
207 }
208
209
210
211
212
213 @Override
214 public void setAttributeType( AttributeType attributeType )
215 {
216 _attributeType = attributeType;
217 }
218
219
220
221
222
223 @Override
224 public boolean getAnonymize( )
225 {
226 return _bAnonymize;
227 }
228
229
230
231
232
233
234 @Override
235 public void setAnonymize( boolean bAnonymize )
236 {
237 _bAnonymize = bAnonymize;
238 }
239
240
241
242
243
244
245 public String getHtmlFormAttribute( Locale locale )
246 {
247 Map<String, Object> model = new HashMap<String, Object>( );
248 model.put( MARK_ATTRIBUTE, this );
249
250 HtmlTemplate template = AppTemplateService.getTemplate( getTemplateHtmlFormAttribute( ), locale, model );
251
252 return template.getHtml( );
253 }
254
255
256
257
258
259
260
261 public String getHtmlFormAttribute( Locale locale, Object listDefaultValues )
262 {
263 Map<String, Object> model = new HashMap<String, Object>( );
264 model.put( MARK_ATTRIBUTE, this );
265 model.put( MARK_DEFAULT_VALUES_LIST, listDefaultValues );
266
267 HtmlTemplate template = AppTemplateService.getTemplate( getTemplateHtmlFormAttribute( ), locale, model );
268
269 return template.getHtml( );
270 }
271
272
273
274
275
276
277
278 public String getHtmlFormSearchAttribute( AdminUserFieldFilter auFieldFilter, Locale locale )
279 {
280 Map<String, Object> model = new HashMap<String, Object>( );
281 List<AdminUserField> listUserFields = auFieldFilter.getListUserFields( );
282 List<AdminUserField> selectedUserFields = null;
283
284 if ( ( listUserFields != null ) && ( !listUserFields.isEmpty( ) ) )
285 {
286 selectedUserFields = new ArrayList<AdminUserField>( );
287
288 for ( AdminUserField userField : listUserFields )
289 {
290 if ( userField.getAttribute( ).getIdAttribute( ) == _nIdAttribute )
291 {
292 selectedUserFields.add( userField );
293 }
294 }
295 }
296
297 model.put( MARK_DEFAULT_VALUES_LIST, selectedUserFields );
298 model.put( MARK_ATTRIBUTE, this );
299
300 HtmlTemplate template = AppTemplateService.getTemplate( getTemplateHtmlFormSearchAttribute( ), locale, model );
301
302 return template.getHtml( );
303 }
304
305
306
307
308
309
310
311 public String getHtmlValue( Locale locale, AdminUserField userField )
312 {
313 Map<String, Object> model = new HashMap<String, Object>( );
314
315 model.put( MARK_ATTRIBUTE, this );
316 model.put( MARK_USER_FIELD, userField );
317
318 HtmlTemplate template = AppTemplateService.getTemplate( getTemplateHtmlValue( ), locale, model );
319
320 return template.getHtml( );
321 }
322
323
324
325
326
327 @Override
328 public Plugin getPlugin( )
329 {
330 return _plugin;
331 }
332
333
334
335
336
337 @Override
338 public void setPlugin( Plugin plugin )
339 {
340 _plugin = plugin;
341 }
342
343
344
345
346
347 @Override
348 public boolean isShownInSearch( )
349 {
350 return _bIsShownInSearch;
351 }
352
353
354
355
356
357 @Override
358 public void setShownInSearch( boolean bIsShownInSearch )
359 {
360 _bIsShownInSearch = bIsShownInSearch;
361 }
362
363
364
365
366
367 @Override
368 public boolean isFieldInLine( )
369 {
370 return _bIsFieldInLine;
371 }
372
373
374
375
376
377 @Override
378 public void setFieldInLine( boolean bIsFieldInLine )
379 {
380 _bIsFieldInLine = bIsFieldInLine;
381 }
382
383
384
385
386
387 @Override
388 public boolean isAttributeImage( )
389 {
390 return _bIsAttributeImage;
391 }
392
393
394
395
396
397 @Override
398 public void setAttributeImage( boolean bIsAttributeImage )
399 {
400 _bIsAttributeImage = bIsAttributeImage;
401 }
402
403
404
405
406
407 @Override
408 public boolean isShownInResultList( )
409 {
410 return _bIsShownInResultList;
411 }
412
413
414
415
416
417 @Override
418 public void setShownInResultList( boolean bIsShownInResultList )
419 {
420 _bIsShownInResultList = bIsShownInResultList;
421 }
422 }