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.grubusiness.business.mock;
35
36 import java.util.ArrayList;
37 import java.util.List;
38
39 import fr.paris.lutece.plugins.grubusiness.business.notification.INotificationListener;
40 import fr.paris.lutece.plugins.grubusiness.business.notification.Notification;
41
42
43
44
45 public class MockNotificationListener implements INotificationListener
46 {
47 private final List<String> _listLogAction = new ArrayList<String>( );
48
49
50
51
52 @Override
53 public void onCreateNotification( Notification notification )
54 {
55 _listLogAction.add( MockActionListenerEnum.CREATE.name( ) + "|" + notification.getId( ) );
56 }
57
58
59
60
61 @Override
62 public void onUpdateNotification( Notification notification )
63 {
64 _listLogAction.add( MockActionListenerEnum.UPDATE.name( ) + "|" + notification.getId( ) );
65 }
66
67
68
69
70 @Override
71 public void onDeleteDemand( String strDemandId, String strDemandTypeId )
72 {
73 _listLogAction.add( MockActionListenerEnum.DELETE.name( ) + "|" + strDemandTypeId + "|" + strDemandId );
74 }
75
76
77
78
79
80
81
82
83
84
85 public synchronized boolean listenAndConsume( MockActionListenerEnum actionListener, Notification notification )
86 {
87 StringBuilder sbCompareLog = new StringBuilder( actionListener.name( ) ).append( '|' );
88
89 if ( actionListener == MockActionListenerEnum.DELETE )
90 {
91 if ( notification.getDemand( ) != null )
92 {
93 sbCompareLog.append( notification.getDemand( ).getTypeId( ) ).append( '|' ).append( notification.getDemand( ).getId( ) );
94 }
95 }
96 else
97 {
98 sbCompareLog.append( notification.getId( ) );
99 }
100
101 int nIndexConsume = -1;
102 for ( int nIndex = 0; nIndex < _listLogAction.size( ); nIndex++ )
103 {
104
105 if ( _listLogAction.get( nIndex ).equals( sbCompareLog.toString( ) ) )
106 {
107 nIndexConsume = nIndex;
108 break;
109 }
110 }
111 if ( nIndexConsume > -1 )
112 {
113 _listLogAction.remove( nIndexConsume );
114 return true;
115 }
116 else
117 {
118 return false;
119 }
120 }
121 }