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.crm.service.notification;
35
36 import fr.paris.lutece.plugins.crm.business.notification.MokeNotification;
37 import fr.paris.lutece.plugins.crm.business.notification.Notification;
38 import fr.paris.lutece.plugins.crm.business.notification.NotificationFilter;
39 import fr.paris.lutece.plugins.crm.business.notification.NotificationHome;
40
41 import java.sql.Timestamp;
42
43 import java.util.ArrayList;
44 import java.util.Date;
45 import java.util.List;
46
47
48
49
50
51
52 public class MokeNotificationService extends NotificationService
53 {
54 private static final int ID_NOTIFICATION1 = 1;
55 private static final int ID_NOTIFICATION2 = 2;
56
57
58
59
60 public Notification findByPrimaryKey( int strIdNotification )
61 {
62 Notification notification = new MokeNotification( ID_NOTIFICATION1 );
63 System.out.println( trace( notification ) );
64
65 return notification;
66 }
67
68
69
70
71 public int create( Notification notification )
72 {
73 notification.setIdNotification( ID_NOTIFICATION1 );
74 notification.setIsRead( false );
75 notification.setDateCreation( new Timestamp( new Date( ).getTime( ) ) );
76
77 System.out.println( trace( notification ) );
78
79 return notification.getIdNotification( );
80 }
81
82
83
84
85 public void update( Notification notification )
86 {
87 if ( notification != null )
88 {
89 notification.setDateCreation( new Timestamp( new Date( ).getTime( ) ) );
90 }
91
92 System.out.println( trace( notification ) );
93 }
94
95
96
97
98 public void remove( int nIdNotification )
99 {
100 System.out.println( trace( ) );
101 }
102
103
104
105
106 public void removeByIdDemand( int nIdDemand )
107 {
108 System.out.println( trace( ) );
109 }
110
111
112
113
114 public List<Notification> findAll( )
115 {
116 List<Notification> listNotifications = new ArrayList<Notification>( );
117 listNotifications.add( new MokeNotification( ID_NOTIFICATION1 ) );
118 listNotifications.add( new MokeNotification( ID_NOTIFICATION2 ) );
119
120 System.out.println( trace( listNotifications ) );
121
122 return listNotifications;
123 }
124
125
126
127
128 public List<Notification> findByFilter( NotificationFilter nFilter )
129 {
130 List<Notification> listNotifications = new ArrayList<Notification>( );
131 listNotifications.add( new MokeNotification( ID_NOTIFICATION1 ) );
132 listNotifications.add( new MokeNotification( ID_NOTIFICATION2 ) );
133
134 System.out.println( trace( listNotifications, nFilter ) );
135
136 return listNotifications;
137 }
138
139
140
141
142 public int getNumberUnreadNotifications( int nIdDemand )
143 {
144 NotificationFilter nFilter = new NotificationFilter( );
145 nFilter.setIdDemand( nIdDemand );
146 nFilter.setIsRead( false );
147
148 List<Notification> listNotifications = NotificationHome.findByFilter( nFilter );
149
150 System.out.println( trace( listNotifications ) );
151
152 return listNotifications.size( );
153 }
154
155
156
157
158 public int getNumberNotifications( int nIdDemand )
159 {
160 NotificationFilter nFilter = new NotificationFilter( );
161 nFilter.setIdDemand( nIdDemand );
162
163 List<Notification> listNotifications = NotificationHome.findByFilter( nFilter );
164
165 System.out.println( trace( listNotifications ) );
166
167 return listNotifications.size( );
168 }
169
170
171
172
173
174
175 private String trace( )
176 {
177 return trace( null, null );
178 }
179
180
181
182
183
184
185
186
187 private String trace( Notification notification )
188 {
189 List<Notification> listNotifications = new ArrayList<Notification>( );
190 listNotifications.add( notification );
191
192 return trace( listNotifications, null );
193 }
194
195
196
197
198
199
200
201
202 private String trace( List<Notification> listNotifications )
203 {
204 return trace( listNotifications, null );
205 }
206
207
208
209
210
211
212
213
214 private String trace( List<Notification> listNotifications, NotificationFilter nFilter )
215 {
216 StringBuilder sbTrace = new StringBuilder( );
217 sbTrace.append( "\n ---------------------- Notification Service -------------------" );
218 sbTrace.append( "\nMethod name : " + Thread.currentThread( ).getStackTrace( ) [2].getMethodName( ) );
219
220 if ( ( listNotifications != null ) && ( listNotifications.size( ) > 0 ) )
221 {
222 for ( Notification notification : listNotifications )
223 {
224 sbTrace.append( "\n-- Notification --" );
225 sbTrace.append( "\nid_notification : " + notification.getIdNotification( ) );
226 sbTrace.append( "\ndate_creation : " + notification.getDateCreation( ) );
227 sbTrace.append( "\nid_demand : " + notification.getIdDemand( ) );
228 sbTrace.append( "\nis_read : " + notification.isRead( ) );
229 sbTrace.append( "\nmessage : " + notification.getMessage( ) );
230 sbTrace.append( "\nobject : " + notification.getObject( ) );
231 sbTrace.append( "\nsender : " + notification.getSender( ) );
232 }
233 }
234
235 if ( nFilter != null )
236 {
237 sbTrace.append( "\n-- Notification Filter --" );
238 sbTrace.append( "\nid_demand : " + nFilter.getIdDemand( ) );
239 sbTrace.append( "\nis_wide_search : " + nFilter.getIsWideSearch( ) );
240 }
241
242 sbTrace.append( "\n --------------------------------------------------------------------" );
243
244 return sbTrace.toString( );
245 }
246 }