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.document.service.history;
35
36 import fr.paris.lutece.plugins.document.business.history.HistoryEvent;
37 import fr.paris.lutece.plugins.document.business.history.HistoryEventHome;
38 import fr.paris.lutece.plugins.document.service.DocumentEvent;
39 import fr.paris.lutece.plugins.document.service.DocumentEventListener;
40 import fr.paris.lutece.plugins.document.service.DocumentException;
41 import fr.paris.lutece.portal.service.util.AppLogService;
42
43 import java.sql.Timestamp;
44
45
46
47
48
49 public class DocumentHistoryService implements DocumentEventListener
50 {
51 private static final String PROPERTY_MESSAGE_DOCUMENT_CREATED = "document.history.message.documentCreated";
52 private static final String PROPERTY_MESSAGE_DOCUMENT_STATE_MODIFIED = "document.history.message.documentStateModified";
53 private static final String PROPERTY_MESSAGE_DOCUMENT_MODIFIED = "document.history.message.documentModified";
54 private static final String PROPERTY_MESSAGE_DOCUMENT_MOVED = "document.history.message.documentMoved";
55 private static DocumentHistoryServicee/history/DocumentHistoryService.html#DocumentHistoryService">DocumentHistoryService _singleton = new DocumentHistoryService( );
56
57
58 private DocumentHistoryService( )
59 {
60 }
61
62
63
64
65
66 public static DocumentHistoryService getInstance( )
67 {
68 return _singleton;
69 }
70
71
72
73
74
75
76 public void processDocumentEvent( DocumentEvent event )
77 throws DocumentException
78 {
79 try
80 {
81 HistoryEventt/business/history/HistoryEvent.html#HistoryEvent">HistoryEvent historyEvent = new HistoryEvent( );
82 historyEvent.setDate( new Timestamp( new java.util.Date( ).getTime( ) ) );
83
84 String strUser = ( event.getUser( ) != null ) ? event.getUser( ).getAccessCode( ) : "";
85 historyEvent.setEventUser( strUser );
86 historyEvent.setIdDocument( event.getDocument( ).getId( ) );
87 historyEvent.setDocumentStateKey( event.getDocument( ).getStateKey( ) );
88 historyEvent.setSpace( event.getDocument( ).getSpace( ) );
89
90 String strMessageKey;
91
92 switch ( event.getEventType( ) )
93 {
94 case DocumentEvent.DOCUMENT_CREATED:
95 strMessageKey = PROPERTY_MESSAGE_DOCUMENT_CREATED;
96
97 break;
98
99 case DocumentEvent.DOCUMENT_CONTENT_MODIFIED:
100 strMessageKey = PROPERTY_MESSAGE_DOCUMENT_MODIFIED;
101
102 break;
103
104 case DocumentEvent.DOCUMENT_STATE_CHANGED:
105 strMessageKey = PROPERTY_MESSAGE_DOCUMENT_STATE_MODIFIED;
106
107 break;
108
109 case DocumentEvent.DOCUMENT_MOVED:
110 strMessageKey = PROPERTY_MESSAGE_DOCUMENT_MOVED;
111
112 break;
113
114 default:
115 strMessageKey = PROPERTY_MESSAGE_DOCUMENT_MODIFIED;
116
117 break;
118 }
119
120 historyEvent.setEventMessageKey( strMessageKey );
121 HistoryEventHome.create( historyEvent );
122 }
123 catch ( Exception e )
124 {
125 AppLogService.error( "Error in History even : " + e.getMessage( ), e );
126 }
127 }
128 }