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.demand;
35
36 import fr.paris.lutece.plugins.crm.business.demand.Demand;
37 import fr.paris.lutece.plugins.crm.business.demand.DemandFilter;
38 import fr.paris.lutece.plugins.crm.business.demand.MokeDemand;
39
40 import java.sql.Timestamp;
41
42 import java.util.ArrayList;
43 import java.util.Date;
44 import java.util.HashMap;
45 import java.util.List;
46 import java.util.Locale;
47 import java.util.Map;
48
49 public class MokeDemandService extends DemandService
50 {
51 private static final int ID_DEMAND1 = 1;
52 private static final int ID_DEMAND2 = 2;
53 private static final int ID_DEMAND3 = 3;
54 private static final int ID_DEMAND4 = 4;
55 private static final String ID_STATUS_CRM1 = "1";
56 private static final String ID_STATUS_CRM2 = "2";
57
58
59
60
61
62
63
64
65 public Demand findByPrimaryKey( int nIdDemand )
66 {
67 Demand demand = new MokeDemand( nIdDemand );
68 System.out.println( trace( demand ) );
69
70 return demand;
71 }
72
73
74
75
76
77
78
79
80 public int create( Demand demand )
81 {
82 if ( demand != null )
83 {
84 demand.setDateModification( new Timestamp( new Date( ).getTime( ) ) );
85 demand.setIdDemand( ID_DEMAND1 );
86 }
87
88 System.out.println( trace( demand ) );
89
90 return demand.getIdDemand( );
91 }
92
93
94
95
96
97
98
99 public void update( Demand demand )
100 {
101 if ( demand != null )
102 {
103 demand.setDateModification( new Timestamp( new Date( ).getTime( ) ) );
104 }
105
106 System.out.println( trace( demand ) );
107 }
108
109
110
111
112
113
114
115 public void remove( int nIdDemand )
116 {
117 System.out.println( trace( ) );
118 }
119
120
121
122
123
124
125
126 public void removeWithItsResource( int nIdDemand )
127 {
128 System.out.println( trace( ) );
129 }
130
131
132
133
134
135
136
137 public void removeByIdDemandType( int nIdDemandType )
138 {
139 System.out.println( trace( ) );
140 }
141
142
143
144
145
146
147 public List<Demand> findAll( )
148 {
149 List<Demand> listDemands = new ArrayList<Demand>( );
150 listDemands.add( new MokeDemand( ID_DEMAND1 ) );
151 listDemands.add( new MokeDemand( ID_DEMAND2 ) );
152 System.out.println( trace( listDemands ) );
153
154 return listDemands;
155 }
156
157
158
159
160
161
162
163
164 public List<Demand> findByFilter( DemandFilter dFilter )
165 {
166 List<Demand> listDemands = new ArrayList<Demand>( );
167 listDemands.add( new MokeDemand( ID_DEMAND1 ) );
168 listDemands.add( new MokeDemand( ID_DEMAND2 ) );
169 System.out.println( trace( listDemands, dFilter ) );
170
171 return listDemands;
172 }
173
174
175
176
177
178
179
180
181
182
183 public Map<String, List<Demand>> findByIdCRMUser( int nIdCRMUser, Locale locale )
184 {
185 Map<String, List<Demand>> map = new HashMap<String, List<Demand>>( );
186
187 List<Demand> listDemands = new ArrayList<Demand>( );
188 listDemands.add( new MokeDemand( ID_DEMAND1 ) );
189 listDemands.add( new MokeDemand( ID_DEMAND2 ) );
190 map.put( ID_STATUS_CRM1, listDemands );
191 System.out.println( trace( listDemands ) );
192
193 listDemands = new ArrayList<Demand>( );
194 listDemands.add( new MokeDemand( ID_DEMAND3 ) );
195 listDemands.add( new MokeDemand( ID_DEMAND4 ) );
196 map.put( ID_STATUS_CRM2, listDemands );
197 System.out.println( trace( listDemands ) );
198
199 return map;
200 }
201
202
203
204
205
206
207 private String trace( )
208 {
209 return trace( null, null );
210 }
211
212
213
214
215
216
217
218
219 private String trace( Demand demand )
220 {
221 List<Demand> listDemands = new ArrayList<Demand>( );
222 listDemands.add( demand );
223
224 return trace( listDemands, null );
225 }
226
227
228
229
230
231
232
233
234 private String trace( List<Demand> listDemands )
235 {
236 return trace( listDemands, null );
237 }
238
239
240
241
242
243
244
245
246 private String trace( List<Demand> listDemands, DemandFilter dFilter )
247 {
248 StringBuilder sbTrace = new StringBuilder( );
249 sbTrace.append( "\n ---------------------- Demand Service -------------------" );
250 sbTrace.append( "\nMethod name : " + Thread.currentThread( ).getStackTrace( ) [2].getMethodName( ) );
251
252 if ( ( listDemands != null ) && ( listDemands.size( ) > 0 ) )
253 {
254 for ( Demand demand : listDemands )
255 {
256 sbTrace.append( "\n-- Demand --" );
257 sbTrace.append( "\nid_demand : " + demand.getIdDemand( ) );
258 sbTrace.append( "\ndata : " + demand.getData( ) );
259 sbTrace.append( "\nid_crm_user : " + demand.getIdCRMUser( ) );
260 sbTrace.append( "\nid_demand_type : " + demand.getIdDemandType( ) );
261 sbTrace.append( "\nid_status_crm : " + demand.getIdStatusCRM( ) );
262 sbTrace.append( "\nstatus_text : " + demand.getStatusText( ) );
263 sbTrace.append( "\ndate_modifiaction : " + demand.getDateModification( ) );
264 }
265 }
266
267 if ( dFilter != null )
268 {
269 sbTrace.append( "\n-- Demand Filter --" );
270 sbTrace.append( "\nid_crm_user : " + dFilter.getIdCRMUser( ) );
271 sbTrace.append( "\nid_demand_type : " + dFilter.getIdDemandType( ) );
272 sbTrace.append( "\nid_status_crm : " + dFilter.getIdStatusCRM( ) );
273 sbTrace.append( "\ndate_modification : " + dFilter.getDateModification( ) );
274 sbTrace.append( "\nis_wide_search : " + dFilter.getIsWideSearch( ) );
275 sbTrace.append( "\noperator_date_modification : " + dFilter.getOperatorDateModification( ) );
276 }
277
278 sbTrace.append( "\n --------------------------------------------------------------------" );
279
280 return sbTrace.toString( );
281 }
282 }