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