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 fr.paris.lutece.plugins.grubusiness.business.notification.INotificationEventDAO;
37 import fr.paris.lutece.plugins.grubusiness.business.notification.NotificationEvent;
38 import fr.paris.lutece.plugins.grubusiness.business.notification.NotificationFilter;
39
40 import java.util.ArrayList;
41 import java.util.List;
42 import java.util.Optional;
43
44
45
46
47 public final class MockNotificationEventDAO implements INotificationEventDAO
48 {
49 List<NotificationEvent> _eventList = new ArrayList<>( );
50
51
52
53
54 @Override
55 public NotificationEvent insert( NotificationEvent notificationEvent )
56 {
57 _eventList.add( notificationEvent );
58
59 return notificationEvent;
60 }
61
62
63
64
65 @Override
66 public Optional<NotificationEvent> loadById( int nKey )
67 {
68 for ( NotificationEvent event : _eventList )
69 {
70 if ( event.getId( ) == nKey )
71 return Optional.of( event );
72 }
73
74 return Optional.empty( );
75 }
76
77
78
79
80 @Override
81 public void delete( int nKey )
82 {
83 for ( NotificationEvent event : _eventList )
84 {
85 if ( event.getId( ) == nKey )
86 {
87 _eventList.remove( event );
88 return;
89 }
90 }
91 }
92
93
94
95
96 @Override
97 public List<NotificationEvent> loadByDemand( String strDemandId, String strDemandTypeId )
98 {
99 List<NotificationEvent> eventDemandList = new ArrayList<>( );
100
101 for ( NotificationEvent event : _eventList )
102 {
103 if ( event.getDemand( ).getId( ).equals( strDemandId ) && event.getDemand( ).getTypeId( ).equals( strDemandTypeId ) )
104 {
105 eventDemandList.add( event );
106 }
107 }
108
109 return eventDemandList;
110 }
111
112
113
114
115 @Override
116 public List<NotificationEvent> loadByFilter( NotificationFilter filter )
117 {
118 List<NotificationEvent> eventDemandList = new ArrayList<>( );
119
120 for ( NotificationEvent event : _eventList )
121 {
122 if ( filter.containsDemandTypeId( ) && event.getDemand( ).getTypeId( ).equals( filter.getDemandTypeId( ) ) )
123 {
124 eventDemandList.add( event );
125 }
126 }
127
128 return eventDemandList;
129 }
130
131
132
133
134 @Override
135 public List<Integer> loadIdsByFilter( NotificationFilter filter )
136 {
137 List<Integer> eventDemandList = new ArrayList<>( );
138
139 for ( NotificationEvent event : _eventList )
140 {
141 if ( filter.containsDemandTypeId( ) && event.getDemand( ).getTypeId( ).equals( filter.getDemandTypeId( ) ) )
142 {
143 eventDemandList.add( event.getId( ) );
144 }
145 }
146
147 return eventDemandList;
148 }
149
150 @Override
151 public List<NotificationEvent> loadByNotification( String strDemandId, String strDemandTypeId, long lNotificationDate )
152 {
153 List<NotificationEvent> eventList = new ArrayList<>( );
154
155 for ( NotificationEvent event : _eventList )
156 {
157 if ( event.getDemand( ).getId( ).equals( strDemandId ) && event.getDemand( ).getTypeId( ).equals( strDemandTypeId )
158 && event.getNotificationDate( ) == lNotificationDate )
159 {
160 eventList.add( event );
161 }
162 }
163
164 return eventList;
165 }
166
167 @Override
168 public List<NotificationEvent> loadByIds( List<Integer> listIds )
169 {
170 List<NotificationEvent> eventList = new ArrayList<>( );
171
172 for ( NotificationEvent event : _eventList )
173 {
174 if ( listIds.contains( event.getId( ) ) )
175 {
176 eventList.add( event );
177 }
178 }
179
180 return eventList;
181 }
182
183 @Override
184 public String deleteBeforeDate( long lDate )
185 {
186
187 return "MOCK (no need to purge)";
188 }
189
190 }