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.plugins.directory.business;
35
36 import fr.paris.lutece.plugins.directory.service.DirectoryService;
37 import fr.paris.lutece.plugins.directory.service.FileImgService;
38 import fr.paris.lutece.plugins.directory.utils.DirectoryUtils;
39 import fr.paris.lutece.plugins.workflowcore.business.state.State;
40 import fr.paris.lutece.portal.service.plugin.Plugin;
41 import fr.paris.lutece.portal.service.resource.IExtendableResource;
42 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupResource;
43 import fr.paris.lutece.util.date.DateUtil;
44 import fr.paris.lutece.util.xml.XmlUtil;
45
46 import org.apache.commons.lang.StringEscapeUtils;
47 import org.apache.commons.lang.StringUtils;
48
49 import java.sql.Timestamp;
50
51 import java.util.HashMap;
52 import java.util.List;
53 import java.util.Locale;
54 import java.util.Map;
55
56
57
58
59
60
61 public class Record implements AdminWorkgroupResource, IExtendableResource
62 {
63 public static final String WORKFLOW_RESOURCE_TYPE = "DIRECTORY_RECORD";
64 public static final String EXTENDABLE_RESOURCE_TYPE = WORKFLOW_RESOURCE_TYPE;
65 public static final String ATTRIBUTE_TITLE = "title";
66 public static final String TAG_LIST_RECORD_FIELD = "list-record-field";
67 public static final String TAG_RECORD_FIELD = "record-field";
68 public static final String TAG_RECORD_FIELD_VALUE = "record-field-value";
69 public static final String TAG_CREATION_DATE = "creation-date";
70 public static final String TAG_MODIFICATION_DATE = "modification-date";
71 public static final String TAG_STATUS = "status";
72 public static final String ATTRIBUTE_ICON = "icon";
73 private static final String TAG_RECORD = "record";
74 private static final String ATTRIBUTE_RECORD_ID = "id";
75 private static final String ATTRIBUTE_TYPE_ENTRY = "type-entry";
76 private static final String ATTRIBUTE_SHOW_IN_RECORD = "isShownInRecord";
77 private static final String ATTRIBUTE_SHOW_IN_LIST = "isShownInList";
78 private int _nIdRecord;
79 private Timestamp _tDateCreation;
80 private Timestamp _tDateModification;
81 private Directory _directory;
82 private List<RecordField> _listRecordField;
83 private List<DirectoryAction> _listAction;
84 private boolean _bIsEnabled;
85 private String _strRoleKey;
86 private String _strWorkgroupKey;
87
88
89
90
91
92 public Directory getDirectory( )
93 {
94 return _directory;
95 }
96
97
98
99
100
101
102
103
104 public void setDirectory( Directory directory )
105 {
106 this._directory = directory;
107 }
108
109
110
111
112
113
114 public int getIdRecord( )
115 {
116 return _nIdRecord;
117 }
118
119
120
121
122
123
124
125 public void setIdRecord( int idRecord )
126 {
127 _nIdRecord = idRecord;
128 }
129
130
131
132
133
134
135 public Timestamp getDateCreation( )
136 {
137 return _tDateCreation;
138 }
139
140
141
142
143
144
145
146 public void setDateCreation( Timestamp dateCreation )
147 {
148 _tDateCreation = dateCreation;
149 }
150
151
152
153
154
155
156 public Timestamp getDateModification( )
157 {
158 return _tDateModification;
159 }
160
161
162
163
164
165
166
167 public void setDateModification( Timestamp dateModification )
168 {
169 _tDateModification = dateModification;
170 }
171
172
173
174
175
176 public List<RecordField> getListRecordField( )
177 {
178 return _listRecordField;
179 }
180
181
182
183
184
185
186
187 public void setActions( List<DirectoryAction> listAction )
188 {
189 _listAction = listAction;
190 }
191
192
193
194
195
196 public List<DirectoryAction> getActions( )
197 {
198 return _listAction;
199 }
200
201
202
203
204
205
206
207 public void setListRecordField( List<RecordField> listRecordField )
208 {
209 _listRecordField = listRecordField;
210 }
211
212
213
214
215
216 public boolean isEnabled( )
217 {
218 return _bIsEnabled;
219 }
220
221
222
223
224
225
226
227 public void setEnabled( boolean enable )
228 {
229 _bIsEnabled = enable;
230 }
231
232
233
234
235
236
237
238 public String getRoleKey( )
239 {
240 return _strRoleKey;
241 }
242
243
244
245
246
247
248
249
250 public void setRoleKey( String strRole )
251 {
252 _strRoleKey = strRole;
253 }
254
255
256
257
258 @Override
259 public String getWorkgroup( )
260 {
261 return _strWorkgroupKey;
262 }
263
264
265
266
267
268
269
270 public void setWorkgroup( String workGroup )
271 {
272 _strWorkgroupKey = workGroup;
273 }
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300 public StringBuffer getXml( Plugin plugin, Locale locale, boolean bWithHtmlCode, State state, List<IEntry> listEntryResultSearch,
301 boolean bDisplayTitleEntryTypeSelect, boolean bDisplayFront, boolean bDisplayExport, boolean bDisplayDateCreation, Map<Integer, Field> mapFieldEntry )
302 {
303 return getXml( plugin, locale, bWithHtmlCode, state, listEntryResultSearch, bDisplayTitleEntryTypeSelect, bDisplayFront, bDisplayExport,
304 bDisplayDateCreation, false, mapFieldEntry );
305 }
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334 public StringBuffer getXml( Plugin plugin, Locale locale, boolean bWithHtmlCode, State state, List<IEntry> listEntryResultSearch,
335 boolean bDisplayTitleEntryTypeSelect, boolean bDisplayFront, boolean bDisplayExport, boolean bDisplayDateCreation,
336 boolean bDisplayDateModification, Map<Integer, Field> mapFieldEntry )
337 {
338 StringBuffer strXml = new StringBuffer( );
339 Map<String, String> model = new HashMap<String, String>( );
340 model.put( ATTRIBUTE_RECORD_ID, String.valueOf( this.getIdRecord( ) ) );
341 XmlUtil.beginElement( strXml, TAG_RECORD, model );
342
343 if ( bDisplayDateCreation )
344 {
345 XmlUtil.addElement( strXml, TAG_CREATION_DATE, DateUtil.getDateString( this.getDateCreation( ), locale ) );
346 }
347
348 if ( bDisplayDateModification )
349 {
350 XmlUtil.addElement( strXml, TAG_MODIFICATION_DATE, DateUtil.getDateString( this.getDateModification( ), locale ) );
351 }
352
353 if ( state != null )
354 {
355 Map<String, String> stateAttributes = new HashMap<String, String>( );
356 stateAttributes.put( ATTRIBUTE_ICON, Integer.toString( state.getIcon( ).getId( ) ) );
357 XmlUtil.addElement( strXml, TAG_STATUS, state.getName( ), stateAttributes );
358 }
359
360 XmlUtil.beginElement( strXml, Entry.TAG_LIST_ENTRY );
361
362 Map<String, List<RecordField>> mapEntryRecordFields = DirectoryUtils.getSpecificMapIdEntryListRecordField( listEntryResultSearch, this.getIdRecord( ),
363 plugin, mapFieldEntry );
364
365 for ( IEntry entry : listEntryResultSearch )
366 {
367 if ( entry.getEntryType( ).getGroup( ) && ( entry.getChildren( ) != null ) )
368 {
369 for ( IEntry entryChildren : entry.getChildren( ) )
370 {
371 if ( !entryChildren.getEntryType( ).getComment( ) )
372 {
373 getXmlListRecordField( entryChildren, strXml, plugin, locale, bWithHtmlCode,
374 mapEntryRecordFields.get( Integer.toString( entryChildren.getIdEntry( ) ) ), bDisplayTitleEntryTypeSelect, bDisplayFront,
375 bDisplayExport );
376 }
377 }
378 }
379 else
380 if ( !entry.getEntryType( ).getComment( ) )
381 {
382 getXmlListRecordField( entry, strXml, plugin, locale, bWithHtmlCode, mapEntryRecordFields.get( Integer.toString( entry.getIdEntry( ) ) ),
383 bDisplayTitleEntryTypeSelect, bDisplayFront, bDisplayExport );
384 }
385 }
386
387 XmlUtil.endElement( strXml, Entry.TAG_LIST_ENTRY );
388 XmlUtil.endElement( strXml, TAG_RECORD );
389
390 return strXml;
391 }
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412 private void getXmlListRecordField( IEntry entry, StringBuffer strXml, Plugin plugin, Locale locale, boolean bWithHtmlCode,
413 List<RecordField> listRecordField, boolean bDisplayTitleEntryTypeSelect, boolean bDisplayFront, boolean bDisplayExport )
414 {
415 Map<String, String> model = DirectoryService.getInstance( ).getModelForEntryForXml( entry );
416 XmlUtil.beginElement( strXml, Entry.TAG_ENTRY, model );
417
418 Map<String, String> modelListRecordField = new HashMap<String, String>( );
419 boolean bIsEntryTypeGeolocation = ( entry instanceof EntryTypeGeolocation ) ? true : false;
420 boolean bIsEntryTypeNumbering = ( entry instanceof EntryTypeNumbering ) ? true : false;
421 modelListRecordField.put( RecordField.ATTRIBUTE_GEOLOCATION, Boolean.toString( bIsEntryTypeGeolocation ) );
422 XmlUtil.beginElement( strXml, TAG_LIST_RECORD_FIELD, modelListRecordField );
423
424 if ( listRecordField != null )
425 {
426 for ( RecordField recordField : listRecordField )
427 {
428 Map<String, String> modelRecordField = new HashMap<String, String>( );
429 Field field = recordField.getField( );
430
431 if ( ( field != null ) && StringUtils.isNotBlank( field.getTitle( ) ) )
432 {
433 modelRecordField.put( Record.ATTRIBUTE_TITLE, StringEscapeUtils.escapeXml( field.getTitle( ) ) );
434 }
435
436 if ( entry.getEntryType( ) != null )
437 {
438 modelRecordField.put( ATTRIBUTE_TYPE_ENTRY, String.valueOf( entry.getEntryType( ).getIdType( ) ) );
439 }
440
441 if ( field != null )
442 {
443 modelRecordField.put( ATTRIBUTE_SHOW_IN_RECORD, String.valueOf( field.isShownInResultRecord( ) ) );
444 modelRecordField.put( ATTRIBUTE_SHOW_IN_LIST, String.valueOf( field.isShownInResultList( ) ) );
445 }
446
447 XmlUtil.beginElement( strXml, TAG_RECORD_FIELD, modelRecordField );
448
449 if ( bWithHtmlCode )
450 {
451 Map<String, String> modelRecordFieldValue = new HashMap<String, String>( );
452
453 if ( field != null )
454 {
455 modelRecordFieldValue.put( Field.ATTRIBUTE_FIELD_ID, Integer.toString( field.getIdField( ) ) );
456
457 if ( StringUtils.isNotBlank( field.getTitle( ) ) )
458 {
459 modelRecordFieldValue.put( Field.ATTRIBUTE_FIELD_TITLE, StringEscapeUtils.escapeXml( recordField.getField( ).getTitle( ) ) );
460 }
461 }
462
463 XmlUtil.addElementHtml( strXml, TAG_RECORD_FIELD_VALUE, recordField.getEntry( )
464 .getHtmlRecordFieldValue( locale, recordField, bDisplayFront ), modelRecordFieldValue );
465 }
466 else
467 {
468 if ( recordField.getFile( ) != null )
469 {
470 IEntry entryFile = EntryHome.findByPrimaryKey( recordField.getEntry( ).getIdEntry( ), plugin );
471
472 XmlUtil.addElementHtml( strXml, TAG_RECORD_FIELD_VALUE,
473 entry.convertRecordFieldValueToString( recordField, locale, bDisplayFront, bDisplayExport ) );
474 strXml.append( recordField.getFile( ).getXml( plugin, locale, entry.getEntryType( ).getIdType( ), entryFile.getDisplayWidth( ),
475 entryFile.getDisplayHeight( ) ) );
476 }
477 else
478 {
479 if ( bDisplayTitleEntryTypeSelect && !bIsEntryTypeNumbering )
480 {
481 XmlUtil.addElementHtml(
482 strXml,
483 TAG_RECORD_FIELD_VALUE,
484 DirectoryUtils.substituteSpecialCaractersForExport( recordField.getEntry( ).convertRecordFieldTitleToString( recordField,
485 locale, bDisplayFront ) ) );
486 }
487 else
488 {
489 Map<String, String> modelRecordFieldValue = new HashMap<String, String>( );
490
491 if ( recordField.getField( ) != null )
492 {
493 modelRecordFieldValue.put( Field.ATTRIBUTE_FIELD_ID, Integer.toString( recordField.getField( ).getIdField( ) ) );
494
495 if ( StringUtils.isNotBlank( recordField.getField( ).getTitle( ) ) )
496 {
497 modelRecordFieldValue.put( Field.ATTRIBUTE_FIELD_TITLE, StringEscapeUtils.escapeXml( recordField.getField( ).getTitle( ) ) );
498 }
499 }
500
501 XmlUtil.addElementHtml(
502 strXml,
503 TAG_RECORD_FIELD_VALUE,
504 DirectoryUtils.substituteSpecialCaractersForExport( recordField.getEntry( ).convertRecordFieldValueToString( recordField,
505 locale, bDisplayFront, bDisplayExport ) ), modelRecordFieldValue );
506 }
507
508 XmlUtil.addEmptyElement( strXml, File.TAG_FILE, null );
509 }
510 }
511
512 XmlUtil.endElement( strXml, TAG_RECORD_FIELD );
513 }
514 }
515
516 XmlUtil.endElement( strXml, TAG_LIST_RECORD_FIELD );
517 XmlUtil.endElement( strXml, Entry.TAG_ENTRY );
518 }
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545 public StringBuffer getXmlForCsvExport( Plugin plugin, Locale locale, boolean bWithHtmlCode, State state, List<IEntry> listEntryResultSearch,
546 boolean bDisplayTitleEntryTypeSelect, boolean bDisplayFront, boolean bDisplayExport, boolean bDisplayDateCreation, Map<Integer, Field> mapFieldEntry )
547 {
548 return getXmlForCsvExport( plugin, locale, bWithHtmlCode, state, listEntryResultSearch, bDisplayTitleEntryTypeSelect, bDisplayFront, bDisplayExport,
549 bDisplayDateCreation, false, mapFieldEntry );
550 }
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579 public StringBuffer getXmlForCsvExport( Plugin plugin, Locale locale, boolean bWithHtmlCode, State state, List<IEntry> listEntryResultSearch,
580 boolean bDisplayTitleEntryTypeSelect, boolean bDisplayFront, boolean bDisplayExport, boolean bDisplayDateCreation,
581 boolean bDisplayDateModification, Map<Integer, Field> mapFieldEntry )
582 {
583 StringBuffer strXml = new StringBuffer( );
584 Map<String, String> model = new HashMap<String, String>( );
585 model.put( ATTRIBUTE_RECORD_ID, String.valueOf( this.getIdRecord( ) ) );
586 XmlUtil.beginElement( strXml, TAG_RECORD, model );
587
588 if ( state != null )
589 {
590 Map<String, String> stateAttributes = new HashMap<String, String>( );
591 stateAttributes.put( ATTRIBUTE_ICON, Integer.toString( state.getIcon( ).getId( ) ) );
592 XmlUtil.addElement( strXml, TAG_STATUS, state.getName( ), stateAttributes );
593 }
594
595 XmlUtil.beginElement( strXml, Entry.TAG_LIST_ENTRY );
596
597 Map<String, List<RecordField>> mapEntryRecordFields = DirectoryUtils.getSpecificMapIdEntryListRecordField( listEntryResultSearch, this.getIdRecord( ),
598 plugin, mapFieldEntry );
599
600 if ( bDisplayDateCreation )
601 {
602 HashMap<String, String> modelCreationDate = new HashMap<String, String>( );
603 modelCreationDate.put( Entry.ATTRIBUTE_ENTRY_ID, "0" );
604 XmlUtil.beginElement( strXml, Entry.TAG_ENTRY, modelCreationDate );
605 XmlUtil.beginElement( strXml, TAG_LIST_RECORD_FIELD );
606 XmlUtil.beginElement( strXml, TAG_RECORD_FIELD );
607 XmlUtil.addElementHtml( strXml, TAG_RECORD_FIELD_VALUE, DateUtil.getDateString( this.getDateCreation( ), locale ) );
608 XmlUtil.endElement( strXml, TAG_RECORD_FIELD );
609 XmlUtil.endElement( strXml, TAG_LIST_RECORD_FIELD );
610 XmlUtil.endElement( strXml, Entry.TAG_ENTRY );
611 }
612
613 if ( bDisplayDateModification )
614 {
615 HashMap<String, String> modelModificationDate = new HashMap<String, String>( );
616 modelModificationDate.put( Entry.ATTRIBUTE_ENTRY_ID, "0" );
617 XmlUtil.beginElement( strXml, Entry.TAG_ENTRY, modelModificationDate );
618 XmlUtil.beginElement( strXml, TAG_LIST_RECORD_FIELD );
619 XmlUtil.beginElement( strXml, TAG_RECORD_FIELD );
620 XmlUtil.addElementHtml( strXml, TAG_RECORD_FIELD_VALUE, DateUtil.getDateString( this.getDateModification( ), locale ) );
621 XmlUtil.endElement( strXml, TAG_RECORD_FIELD );
622 XmlUtil.endElement( strXml, TAG_LIST_RECORD_FIELD );
623 XmlUtil.endElement( strXml, Entry.TAG_ENTRY );
624 }
625
626 for ( IEntry entry : listEntryResultSearch )
627 {
628 if ( entry.getEntryType( ).getGroup( ) && ( entry.getChildren( ) != null ) )
629 {
630 for ( IEntry entryChildren : entry.getChildren( ) )
631 {
632 if ( !entryChildren.getEntryType( ).getComment( ) )
633 {
634 getXmlListRecordField( entryChildren, strXml, plugin, locale, bWithHtmlCode,
635 mapEntryRecordFields.get( Integer.toString( entryChildren.getIdEntry( ) ) ), bDisplayTitleEntryTypeSelect, bDisplayFront,
636 bDisplayExport );
637 }
638 }
639 }
640 else
641 if ( !entry.getEntryType( ).getComment( ) )
642 {
643 getXmlListRecordField( entry, strXml, plugin, locale, bWithHtmlCode, mapEntryRecordFields.get( Integer.toString( entry.getIdEntry( ) ) ),
644 bDisplayTitleEntryTypeSelect, bDisplayFront, bDisplayExport );
645 }
646 }
647
648 XmlUtil.endElement( strXml, Entry.TAG_LIST_ENTRY );
649 XmlUtil.endElement( strXml, TAG_RECORD );
650
651 return strXml;
652 }
653
654
655
656
657 @Override
658 public String getIdExtendableResource( )
659 {
660 return Integer.toString( getIdRecord( ) );
661 }
662
663
664
665
666 @Override
667 public String getExtendableResourceType( )
668 {
669 return EXTENDABLE_RESOURCE_TYPE;
670 }
671
672
673
674
675 @Override
676 public String getExtendableResourceName( )
677 {
678 return Integer.toString( getIdRecord( ) );
679 }
680
681
682
683
684 @Override
685 public String getExtendableResourceDescription( )
686 {
687 return Integer.toString( getIdRecord( ) );
688 }
689
690
691
692
693 @Override
694 public String getExtendableResourceImageUrl( )
695 {
696 if ( ( _listRecordField != null ) && ( _listRecordField.size( ) > 0 ) )
697 {
698 RecordField recordFieldImage = null;
699
700 for ( RecordField recordField : _listRecordField )
701 {
702 if ( recordField.isBigThumbnail( ) )
703 {
704
705 recordFieldImage = recordField;
706
707 break;
708 }
709 else
710 if ( recordField.isLittleThumbnail( ) )
711 {
712
713 recordFieldImage = recordField;
714 }
715 }
716
717 if ( recordFieldImage != null )
718 {
719 return FileImgService.getResourceImageEntryUrlWhitoutEntities( recordFieldImage.getFile( ).getIdFile( ) );
720 }
721 }
722
723 return null;
724 }
725 }