1 | /** |
---|
2 | * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. |
---|
3 | * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior |
---|
4 | * |
---|
5 | * This program is free software: you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU Affero General Public License as |
---|
7 | * published by the Free Software Foundation, either version 3 of the |
---|
8 | * License, or (at your option) any later version. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU Affero General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU Affero General Public License |
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | */ |
---|
18 | |
---|
19 | /******************************************************************************\ |
---|
20 | * |
---|
21 | * This product was developed by |
---|
22 | * |
---|
23 | * SERVIÃO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), |
---|
24 | * |
---|
25 | * a government company established under Brazilian law (5.615/70), |
---|
26 | * at Department of Development of Porto Alegre. |
---|
27 | * |
---|
28 | \******************************************************************************/ |
---|
29 | |
---|
30 | package serpro.mailarchiver.service.web; |
---|
31 | |
---|
32 | import javax.jdo.annotations.PersistenceAware; |
---|
33 | import javax.jws.WebService; |
---|
34 | |
---|
35 | import org.springframework.beans.factory.annotation.Autowired; |
---|
36 | |
---|
37 | import static com.google.common.base.Strings.*; |
---|
38 | |
---|
39 | import serpro.mailarchiver.service.BaseService; |
---|
40 | import serpro.mailarchiver.service.dto.TAttachment; |
---|
41 | import serpro.mailarchiver.service.dto.TFault; |
---|
42 | import serpro.mailarchiver.service.dto.TFolder; |
---|
43 | import serpro.mailarchiver.service.dto.TMessage; |
---|
44 | import serpro.mailarchiver.service.dto.TSession; |
---|
45 | import serpro.mailarchiver.session.Session; |
---|
46 | import serpro.mailarchiver.session.SessionMap; |
---|
47 | import serpro.mailarchiver.util.Logger; |
---|
48 | |
---|
49 | @WebService( |
---|
50 | endpointInterface = "serpro.mailarchiver.service.web.ArchiveServices", |
---|
51 | serviceName = "ArchiveServices") |
---|
52 | @PersistenceAware |
---|
53 | public class DefaultArchiveServices |
---|
54 | extends BaseService |
---|
55 | implements ArchiveServices |
---|
56 | { |
---|
57 | private static final Logger log = Logger.getLocalLogger(); |
---|
58 | |
---|
59 | private static final String[] EMPTY_MESSAGES_ID = new String[0]; |
---|
60 | |
---|
61 | public DefaultArchiveServices() { |
---|
62 | log.debug("Instanciando bean DefaultArchiveServices"); |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | //<editor-fold defaultstate="collapsed" desc=" getFaultInfo "> |
---|
67 | //========================================================================== |
---|
68 | @Autowired |
---|
69 | private GetFaultInfoOperation getFaultInfo; |
---|
70 | |
---|
71 | @Override |
---|
72 | public TFault getFaultInfo(String sessionId) { |
---|
73 | sessionId = nullToEmpty(sessionId).trim(); |
---|
74 | |
---|
75 | Session session = SessionMap.get(sessionId); |
---|
76 | if(session == null) { |
---|
77 | return null; |
---|
78 | } |
---|
79 | |
---|
80 | Session.setThreadSession(session); |
---|
81 | |
---|
82 | return getFaultInfo.apply(); |
---|
83 | } |
---|
84 | //</editor-fold> |
---|
85 | |
---|
86 | |
---|
87 | //<editor-fold defaultstate="collapsed" desc=" login "> |
---|
88 | //========================================================================== |
---|
89 | @Autowired |
---|
90 | private LoginOperation login; |
---|
91 | |
---|
92 | @Override |
---|
93 | public TSession login(String userId, String password, String phpSessId, String balanceId) throws ServiceFault { |
---|
94 | userId = nullToEmpty(userId).trim(); |
---|
95 | password = nullToEmpty(password).trim(); |
---|
96 | phpSessId = nullToEmpty(phpSessId).trim(); |
---|
97 | balanceId = nullToEmpty(balanceId).trim(); |
---|
98 | |
---|
99 | try { |
---|
100 | TSession ret = login.apply(userId, password, phpSessId, balanceId); |
---|
101 | return ret; |
---|
102 | } |
---|
103 | catch(Throwable t) { |
---|
104 | ServiceFault e; |
---|
105 | if(t instanceof ServiceFault) { |
---|
106 | e = (ServiceFault) t; |
---|
107 | } |
---|
108 | else { |
---|
109 | e = ServiceFault.runtimeException() |
---|
110 | .setActor("login") |
---|
111 | .setCause(t) |
---|
112 | .create(); |
---|
113 | } |
---|
114 | TFault faultInfo = e.getFaultInfo(); |
---|
115 | if(faultInfo != null) { |
---|
116 | log.error(faultInfo); |
---|
117 | } |
---|
118 | log.error(e, "login\n\tuserId: %s", userId); |
---|
119 | throw e; |
---|
120 | } |
---|
121 | } |
---|
122 | //</editor-fold> |
---|
123 | |
---|
124 | |
---|
125 | //<editor-fold defaultstate="collapsed" desc=" logout "> |
---|
126 | //========================================================================== |
---|
127 | @Autowired |
---|
128 | private LogoutOperation logout; |
---|
129 | |
---|
130 | @Override |
---|
131 | public Integer logout(String sessionId) throws ServiceFault { |
---|
132 | long time1 = System.currentTimeMillis(); |
---|
133 | sessionId = nullToEmpty(sessionId).trim(); |
---|
134 | |
---|
135 | Session session = SessionMap.get(sessionId); |
---|
136 | if(session == null) { |
---|
137 | return null; |
---|
138 | } |
---|
139 | |
---|
140 | Session.setThreadSession(session); |
---|
141 | |
---|
142 | long time2 = System.currentTimeMillis(); |
---|
143 | session.enroll(); |
---|
144 | long time3 = System.currentTimeMillis(); |
---|
145 | |
---|
146 | try { |
---|
147 | session.incStatistics("logout-Total"); |
---|
148 | Integer ret = logout.apply(); |
---|
149 | session.incStatistics("logout-Success"); |
---|
150 | return ret; |
---|
151 | } |
---|
152 | catch(Throwable t) { |
---|
153 | session.incStatistics("logout-Failure"); |
---|
154 | ServiceFault e; |
---|
155 | if(t instanceof ServiceFault) { |
---|
156 | e = (ServiceFault) t; |
---|
157 | } |
---|
158 | else { |
---|
159 | e = ServiceFault.runtimeException() |
---|
160 | .setActor("logout") |
---|
161 | .setCause(t) |
---|
162 | .create(); |
---|
163 | } |
---|
164 | TFault faultInfo = e.getFaultInfo(); |
---|
165 | if(faultInfo != null) { |
---|
166 | log.error(faultInfo); |
---|
167 | } |
---|
168 | log.error(e, "logout\n\tsessionId: %s", sessionId); |
---|
169 | session.setLastFault(faultInfo); |
---|
170 | throw e; |
---|
171 | } |
---|
172 | finally { |
---|
173 | long time4 = System.currentTimeMillis(); |
---|
174 | session.depart(); |
---|
175 | long time5 = System.currentTimeMillis(); |
---|
176 | log.info("Execution time profile logout: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
177 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
178 | } |
---|
179 | } |
---|
180 | //</editor-fold> |
---|
181 | |
---|
182 | |
---|
183 | //<editor-fold defaultstate="collapsed" desc=" listFolders "> |
---|
184 | //========================================================================== |
---|
185 | @Autowired |
---|
186 | private ListFoldersOperation listFolders; |
---|
187 | |
---|
188 | @Override |
---|
189 | public TFolder[] listFolders(String sessionId, String folderId) throws ServiceFault { |
---|
190 | long time1 = System.currentTimeMillis(); |
---|
191 | sessionId = nullToEmpty(sessionId).trim(); |
---|
192 | folderId = nullToEmpty(folderId).trim(); |
---|
193 | |
---|
194 | Session session = SessionMap.get(sessionId); |
---|
195 | if(session == null) { |
---|
196 | return null; |
---|
197 | } |
---|
198 | |
---|
199 | Session.setThreadSession(session); |
---|
200 | |
---|
201 | long time2 = System.currentTimeMillis(); |
---|
202 | session.enroll(); |
---|
203 | long time3 = System.currentTimeMillis(); |
---|
204 | |
---|
205 | try { |
---|
206 | session.incStatistics("listFolders-Total"); |
---|
207 | TFolder[] ret = listFolders.apply(folderId); |
---|
208 | session.incStatistics("listFolders-Success"); |
---|
209 | return ret; |
---|
210 | } |
---|
211 | catch(Throwable t) { |
---|
212 | session.incStatistics("listFolders-Failure"); |
---|
213 | ServiceFault e; |
---|
214 | if(t instanceof ServiceFault) { |
---|
215 | e = (ServiceFault) t; |
---|
216 | } |
---|
217 | else { |
---|
218 | e = ServiceFault.runtimeException() |
---|
219 | .setActor("listFolders") |
---|
220 | .setCause(t) |
---|
221 | .create(); |
---|
222 | } |
---|
223 | TFault faultInfo = e.getFaultInfo(); |
---|
224 | if(faultInfo != null) { |
---|
225 | log.error(faultInfo); |
---|
226 | } |
---|
227 | log.error(e, "listFolders\n\tsessionId: %s\n\tfolderId: %s", sessionId, folderId); |
---|
228 | session.setLastFault(faultInfo); |
---|
229 | throw e; |
---|
230 | } |
---|
231 | finally { |
---|
232 | long time4 = System.currentTimeMillis(); |
---|
233 | session.depart(); |
---|
234 | long time5 = System.currentTimeMillis(); |
---|
235 | log.info("Execution time profile listFolders: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
236 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
237 | } |
---|
238 | } |
---|
239 | //</editor-fold> |
---|
240 | |
---|
241 | |
---|
242 | //<editor-fold defaultstate="collapsed" desc=" listMessages "> |
---|
243 | //========================================================================== |
---|
244 | @Autowired |
---|
245 | private ListMessagesOperation listMessages; |
---|
246 | |
---|
247 | @Override |
---|
248 | public TMessage[] listMessages(String sessionId, String queryConfig) throws ServiceFault { |
---|
249 | long time1 = System.currentTimeMillis(); |
---|
250 | sessionId = nullToEmpty(sessionId).trim(); |
---|
251 | queryConfig = nullToEmpty(queryConfig).trim(); |
---|
252 | |
---|
253 | Session session = SessionMap.get(sessionId); |
---|
254 | if(session == null) { |
---|
255 | return null; |
---|
256 | } |
---|
257 | |
---|
258 | Session.setThreadSession(session); |
---|
259 | |
---|
260 | long time2 = System.currentTimeMillis(); |
---|
261 | session.enroll(); |
---|
262 | long time3 = System.currentTimeMillis(); |
---|
263 | |
---|
264 | try { |
---|
265 | session.incStatistics("listMessages-Total"); |
---|
266 | TMessage[] ret = listMessages.apply(queryConfig); |
---|
267 | session.incStatistics("listMessages-Success"); |
---|
268 | return ret; |
---|
269 | } |
---|
270 | catch(Throwable t) { |
---|
271 | session.incStatistics("listMessages-Failure"); |
---|
272 | ServiceFault e; |
---|
273 | if(t instanceof ServiceFault) { |
---|
274 | e = (ServiceFault) t; |
---|
275 | } |
---|
276 | else { |
---|
277 | e = ServiceFault.runtimeException() |
---|
278 | .setActor("listMessages") |
---|
279 | .setCause(t) |
---|
280 | .create(); |
---|
281 | } |
---|
282 | TFault faultInfo = e.getFaultInfo(); |
---|
283 | if(faultInfo != null) { |
---|
284 | log.error(faultInfo); |
---|
285 | } |
---|
286 | log.error(e, "listMessages\n\tsessionId: %s\n\tqueryConfig: %s", sessionId, queryConfig); |
---|
287 | session.setLastFault(faultInfo); |
---|
288 | throw e; |
---|
289 | } |
---|
290 | finally { |
---|
291 | long time4 = System.currentTimeMillis(); |
---|
292 | session.depart(); |
---|
293 | long time5 = System.currentTimeMillis(); |
---|
294 | log.info("Execution time profile listMessages: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
295 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
296 | } |
---|
297 | } |
---|
298 | //</editor-fold> |
---|
299 | |
---|
300 | |
---|
301 | //<editor-fold defaultstate="collapsed" desc=" listAttachments "> |
---|
302 | //========================================================================== |
---|
303 | //TODO: avaliar necessidade |
---|
304 | |
---|
305 | @Autowired |
---|
306 | private ListAttachmentsOperation listAttachments; |
---|
307 | |
---|
308 | @Override |
---|
309 | public TAttachment[] listAttachments(String sessionId, String messageId) throws ServiceFault { |
---|
310 | long time1 = System.currentTimeMillis(); |
---|
311 | sessionId = nullToEmpty(sessionId).trim(); |
---|
312 | messageId = nullToEmpty(messageId).trim(); |
---|
313 | |
---|
314 | Session session = SessionMap.get(sessionId); |
---|
315 | if(session == null) { |
---|
316 | return null; |
---|
317 | } |
---|
318 | |
---|
319 | Session.setThreadSession(session); |
---|
320 | |
---|
321 | long time2 = System.currentTimeMillis(); |
---|
322 | session.enroll(); |
---|
323 | long time3 = System.currentTimeMillis(); |
---|
324 | |
---|
325 | try { |
---|
326 | session.incStatistics("listAttachments-Total"); |
---|
327 | TAttachment[] ret = listAttachments.apply(messageId); |
---|
328 | session.incStatistics("listAttachments-Success"); |
---|
329 | return ret; |
---|
330 | } |
---|
331 | catch(Throwable t) { |
---|
332 | session.incStatistics("listAttachments-Failure"); |
---|
333 | ServiceFault e; |
---|
334 | if(t instanceof ServiceFault) { |
---|
335 | e = (ServiceFault) t; |
---|
336 | } |
---|
337 | else { |
---|
338 | e = ServiceFault.runtimeException() |
---|
339 | .setActor("listAttachments") |
---|
340 | .setCause(t) |
---|
341 | .create(); |
---|
342 | } |
---|
343 | TFault faultInfo = e.getFaultInfo(); |
---|
344 | if(faultInfo != null) { |
---|
345 | log.error(faultInfo); |
---|
346 | } |
---|
347 | log.error(e, "listAttachments\n\tsessionId: %s\n\tmessageId: %s", sessionId, messageId); |
---|
348 | session.setLastFault(faultInfo); |
---|
349 | throw e; |
---|
350 | } |
---|
351 | finally { |
---|
352 | long time4 = System.currentTimeMillis(); |
---|
353 | session.depart(); |
---|
354 | long time5 = System.currentTimeMillis(); |
---|
355 | log.info("Execution time profile listAttachments: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
356 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
357 | } |
---|
358 | } |
---|
359 | //</editor-fold> |
---|
360 | |
---|
361 | |
---|
362 | //<editor-fold defaultstate="collapsed" desc=" getMessageBody "> |
---|
363 | //========================================================================== |
---|
364 | @Autowired |
---|
365 | private GetMessageBodyOperation getMessageBody; |
---|
366 | |
---|
367 | @Override |
---|
368 | public String getMessageBody(String sessionId, String messageId) throws ServiceFault { |
---|
369 | long time1 = System.currentTimeMillis(); |
---|
370 | sessionId = nullToEmpty(sessionId).trim(); |
---|
371 | messageId = nullToEmpty(messageId).trim(); |
---|
372 | |
---|
373 | Session session = SessionMap.get(sessionId); |
---|
374 | if(session == null) { |
---|
375 | return null; |
---|
376 | } |
---|
377 | |
---|
378 | Session.setThreadSession(session); |
---|
379 | |
---|
380 | long time2 = System.currentTimeMillis(); |
---|
381 | session.enroll(); |
---|
382 | long time3 = System.currentTimeMillis(); |
---|
383 | |
---|
384 | try { |
---|
385 | session.incStatistics("getMessageBody-Total"); |
---|
386 | String ret = getMessageBody.apply(messageId); |
---|
387 | session.incStatistics("getMessageBody-Success"); |
---|
388 | return ret; |
---|
389 | } |
---|
390 | catch(Throwable t) { |
---|
391 | session.incStatistics("getMessageBody-Failure"); |
---|
392 | ServiceFault e; |
---|
393 | if(t instanceof ServiceFault) { |
---|
394 | e = (ServiceFault) t; |
---|
395 | } |
---|
396 | else { |
---|
397 | e = ServiceFault.runtimeException() |
---|
398 | .setActor("getMessageBody") |
---|
399 | .setCause(t) |
---|
400 | .create(); |
---|
401 | } |
---|
402 | TFault faultInfo = e.getFaultInfo(); |
---|
403 | if(faultInfo != null) { |
---|
404 | log.error(faultInfo); |
---|
405 | } |
---|
406 | log.error(e, "getMessageBody\n\tsessionId: %s\n\tmessageId: %s", sessionId, messageId); |
---|
407 | session.setLastFault(faultInfo); |
---|
408 | throw e; |
---|
409 | } |
---|
410 | finally { |
---|
411 | long time4 = System.currentTimeMillis(); |
---|
412 | session.depart(); |
---|
413 | long time5 = System.currentTimeMillis(); |
---|
414 | log.info("Execution time profile getMessageBody: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
415 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
416 | } |
---|
417 | } |
---|
418 | //</editor-fold> |
---|
419 | |
---|
420 | |
---|
421 | //<editor-fold defaultstate="collapsed" desc=" getRawBinaryBody "> |
---|
422 | //========================================================================== |
---|
423 | @Autowired |
---|
424 | private GetRawBinaryBodyOperation getRawBinaryBody; |
---|
425 | |
---|
426 | @Override |
---|
427 | public String getRawBinaryBody(String sessionId, String bodyId) throws ServiceFault { |
---|
428 | long time1 = System.currentTimeMillis(); |
---|
429 | sessionId = nullToEmpty(sessionId).trim(); |
---|
430 | bodyId = nullToEmpty(bodyId).trim(); |
---|
431 | |
---|
432 | Session session = SessionMap.get(sessionId); |
---|
433 | if(session == null) { |
---|
434 | return null; |
---|
435 | } |
---|
436 | |
---|
437 | Session.setThreadSession(session); |
---|
438 | |
---|
439 | long time2 = System.currentTimeMillis(); |
---|
440 | session.enroll(); |
---|
441 | long time3 = System.currentTimeMillis(); |
---|
442 | |
---|
443 | try { |
---|
444 | session.incStatistics("getRawBinaryBody-Total"); |
---|
445 | String ret = getRawBinaryBody.apply(bodyId); |
---|
446 | session.incStatistics("getRawBinaryBody-Success"); |
---|
447 | return ret; |
---|
448 | } |
---|
449 | catch(Throwable t) { |
---|
450 | session.incStatistics("getRawBinaryBody-Failure"); |
---|
451 | ServiceFault e; |
---|
452 | if(t instanceof ServiceFault) { |
---|
453 | e = (ServiceFault) t; |
---|
454 | } |
---|
455 | else { |
---|
456 | e = ServiceFault.runtimeException() |
---|
457 | .setActor("getRawBinaryBody") |
---|
458 | .setCause(t) |
---|
459 | .create(); |
---|
460 | } |
---|
461 | TFault faultInfo = e.getFaultInfo(); |
---|
462 | if(faultInfo != null) { |
---|
463 | log.error(faultInfo); |
---|
464 | } |
---|
465 | log.error(e, "getRawBinaryBody\n\tsessionId: %s\n\tbodyId: %s", sessionId, bodyId); |
---|
466 | session.setLastFault(faultInfo); |
---|
467 | throw e; |
---|
468 | } |
---|
469 | finally { |
---|
470 | long time4 = System.currentTimeMillis(); |
---|
471 | session.depart(); |
---|
472 | long time5 = System.currentTimeMillis(); |
---|
473 | log.info("Execution time profile getRawBinaryBody: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
474 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
475 | } |
---|
476 | } |
---|
477 | //</editor-fold> |
---|
478 | |
---|
479 | |
---|
480 | //<editor-fold defaultstate="collapsed" desc=" copyMessages "> |
---|
481 | //========================================================================== |
---|
482 | @Autowired |
---|
483 | private CopyMessagesOperation copyMessages; |
---|
484 | |
---|
485 | @Override |
---|
486 | public Integer copyMessages(String sessionId, String folderId, String... messagesId) throws ServiceFault { |
---|
487 | long time1 = System.currentTimeMillis(); |
---|
488 | sessionId = nullToEmpty(sessionId).trim(); |
---|
489 | folderId = nullToEmpty(folderId).trim(); |
---|
490 | if(messagesId == null) { |
---|
491 | messagesId = EMPTY_MESSAGES_ID; |
---|
492 | } |
---|
493 | |
---|
494 | Session session = SessionMap.get(sessionId); |
---|
495 | if(session == null) { |
---|
496 | return null; |
---|
497 | } |
---|
498 | |
---|
499 | Session.setThreadSession(session); |
---|
500 | |
---|
501 | long time2 = System.currentTimeMillis(); |
---|
502 | session.enroll(); |
---|
503 | long time3 = System.currentTimeMillis(); |
---|
504 | |
---|
505 | try { |
---|
506 | session.incStatistics("copyMessages-Total"); |
---|
507 | Integer ret = copyMessages.apply(folderId, messagesId); |
---|
508 | session.incStatistics("copyMessages-Success"); |
---|
509 | return ret; |
---|
510 | } |
---|
511 | catch(Throwable t) { |
---|
512 | session.incStatistics("copyMessages-Failure"); |
---|
513 | ServiceFault e; |
---|
514 | if(t instanceof ServiceFault) { |
---|
515 | e = (ServiceFault) t; |
---|
516 | } |
---|
517 | else { |
---|
518 | e = ServiceFault.runtimeException() |
---|
519 | .setActor("copyMessages") |
---|
520 | .setCause(t) |
---|
521 | .create(); |
---|
522 | } |
---|
523 | TFault faultInfo = e.getFaultInfo(); |
---|
524 | if(faultInfo != null) { |
---|
525 | log.error(faultInfo); |
---|
526 | } |
---|
527 | StringBuilder sb = new StringBuilder(); |
---|
528 | sb.append("copyMessages\n\tsessionId: ").append(sessionId).append("\n\tfolderId: ").append(folderId); |
---|
529 | for(int i = 0; i < messagesId.length; i++) { |
---|
530 | sb.append("\n\tmessagesId[").append(i).append("]: ").append(messagesId[i]); |
---|
531 | } |
---|
532 | log.error(e, sb.toString()); |
---|
533 | session.setLastFault(faultInfo); |
---|
534 | throw e; |
---|
535 | } |
---|
536 | finally { |
---|
537 | long time4 = System.currentTimeMillis(); |
---|
538 | session.depart(); |
---|
539 | long time5 = System.currentTimeMillis(); |
---|
540 | log.info("Execution time profile copyMessages: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
541 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
542 | } |
---|
543 | } |
---|
544 | //</editor-fold> |
---|
545 | |
---|
546 | |
---|
547 | //<editor-fold defaultstate="collapsed" desc=" moveMessages "> |
---|
548 | //========================================================================== |
---|
549 | @Autowired |
---|
550 | private MoveMessagesOperation moveMessages; |
---|
551 | |
---|
552 | @Override |
---|
553 | public Integer moveMessages(String sessionId, String folderId, String... messagesId) throws ServiceFault { |
---|
554 | long time1 = System.currentTimeMillis(); |
---|
555 | sessionId = nullToEmpty(sessionId).trim(); |
---|
556 | folderId = nullToEmpty(folderId).trim(); |
---|
557 | if(messagesId == null) { |
---|
558 | messagesId = EMPTY_MESSAGES_ID; |
---|
559 | } |
---|
560 | |
---|
561 | Session session = SessionMap.get(sessionId); |
---|
562 | if(session == null) { |
---|
563 | return null; |
---|
564 | } |
---|
565 | |
---|
566 | Session.setThreadSession(session); |
---|
567 | |
---|
568 | long time2 = System.currentTimeMillis(); |
---|
569 | session.enroll(); |
---|
570 | long time3 = System.currentTimeMillis(); |
---|
571 | |
---|
572 | try { |
---|
573 | session.incStatistics("moveMessages-Total"); |
---|
574 | Integer ret = moveMessages.apply(folderId, messagesId); |
---|
575 | session.incStatistics("moveMessages-Failure"); |
---|
576 | return ret; |
---|
577 | } |
---|
578 | catch(Throwable t) { |
---|
579 | session.incStatistics("moveMessages-Failure"); |
---|
580 | ServiceFault e; |
---|
581 | if(t instanceof ServiceFault) { |
---|
582 | e = (ServiceFault) t; |
---|
583 | } |
---|
584 | else { |
---|
585 | e = ServiceFault.runtimeException() |
---|
586 | .setActor("moveMessages") |
---|
587 | .setCause(t) |
---|
588 | .create(); |
---|
589 | } |
---|
590 | TFault faultInfo = e.getFaultInfo(); |
---|
591 | if(faultInfo != null) { |
---|
592 | log.error(faultInfo); |
---|
593 | } |
---|
594 | StringBuilder sb = new StringBuilder(); |
---|
595 | sb.append("moveMessages\n\tsessionId: ").append(sessionId).append("\n\tfolderId: ").append(folderId); |
---|
596 | for(int i = 0; i < messagesId.length; i++) { |
---|
597 | sb.append("\n\tmessagesId[").append(i).append("]: ").append(messagesId[i]); |
---|
598 | } |
---|
599 | log.error(e, sb.toString()); |
---|
600 | session.setLastFault(faultInfo); |
---|
601 | throw e; |
---|
602 | } |
---|
603 | finally { |
---|
604 | long time4 = System.currentTimeMillis(); |
---|
605 | session.depart(); |
---|
606 | long time5 = System.currentTimeMillis(); |
---|
607 | log.info("Execution time profile moveMessages: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
608 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
609 | } |
---|
610 | } |
---|
611 | //</editor-fold> |
---|
612 | |
---|
613 | |
---|
614 | //<editor-fold defaultstate="collapsed" desc=" deleteMessages "> |
---|
615 | //========================================================================== |
---|
616 | @Autowired |
---|
617 | private DeleteMessagesOperation deleteMessages; |
---|
618 | |
---|
619 | @Override |
---|
620 | public Integer deleteMessages(String sessionId, String... messagesId) throws ServiceFault { |
---|
621 | long time1 = System.currentTimeMillis(); |
---|
622 | sessionId = nullToEmpty(sessionId).trim(); |
---|
623 | if(messagesId == null) { |
---|
624 | messagesId = EMPTY_MESSAGES_ID; |
---|
625 | } |
---|
626 | |
---|
627 | Session session = SessionMap.get(sessionId); |
---|
628 | if(session == null) { |
---|
629 | return null; |
---|
630 | } |
---|
631 | |
---|
632 | Session.setThreadSession(session); |
---|
633 | |
---|
634 | long time2 = System.currentTimeMillis(); |
---|
635 | session.enroll(); |
---|
636 | long time3 = System.currentTimeMillis(); |
---|
637 | |
---|
638 | try { |
---|
639 | session.incStatistics("deleteMessages-Total"); |
---|
640 | Integer ret = deleteMessages.apply(messagesId); |
---|
641 | session.incStatistics("deleteMessages-Success"); |
---|
642 | return ret; |
---|
643 | } |
---|
644 | catch(Throwable t) { |
---|
645 | session.incStatistics("deleteMessages-Failure"); |
---|
646 | ServiceFault e; |
---|
647 | if(t instanceof ServiceFault) { |
---|
648 | e = (ServiceFault) t; |
---|
649 | } |
---|
650 | else { |
---|
651 | e = ServiceFault.runtimeException() |
---|
652 | .setActor("deleteMessages") |
---|
653 | .setCause(t) |
---|
654 | .create(); |
---|
655 | } |
---|
656 | TFault faultInfo = e.getFaultInfo(); |
---|
657 | if(faultInfo != null) { |
---|
658 | log.error(faultInfo); |
---|
659 | } |
---|
660 | StringBuilder sb = new StringBuilder(); |
---|
661 | sb.append("deleteMessages\n\tsessionId: ").append(sessionId); |
---|
662 | for(int i = 0; i < messagesId.length; i++) { |
---|
663 | sb.append("\n\tmessagesId[").append(i).append("]: ").append(messagesId[i]); |
---|
664 | } |
---|
665 | log.error(e, sb.toString()); |
---|
666 | session.setLastFault(faultInfo); |
---|
667 | throw e; |
---|
668 | } |
---|
669 | finally { |
---|
670 | long time4 = System.currentTimeMillis(); |
---|
671 | session.depart(); |
---|
672 | long time5 = System.currentTimeMillis(); |
---|
673 | log.info("Execution time profile deleteMessages: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
674 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
675 | } |
---|
676 | } |
---|
677 | //</editor-fold> |
---|
678 | |
---|
679 | |
---|
680 | //<editor-fold defaultstate="collapsed" desc=" tagMessages "> |
---|
681 | //========================================================================== |
---|
682 | @Autowired |
---|
683 | private TagMessagesOperation tagMessages; |
---|
684 | |
---|
685 | @Override |
---|
686 | public Integer tagMessages(String sessionId, String tagConfig) throws ServiceFault { |
---|
687 | long time1 = System.currentTimeMillis(); |
---|
688 | sessionId = nullToEmpty(sessionId).trim(); |
---|
689 | tagConfig = nullToEmpty(tagConfig).trim(); |
---|
690 | |
---|
691 | Session session = SessionMap.get(sessionId); |
---|
692 | if(session == null) { |
---|
693 | return null; |
---|
694 | } |
---|
695 | |
---|
696 | Session.setThreadSession(session); |
---|
697 | |
---|
698 | long time2 = System.currentTimeMillis(); |
---|
699 | session.enroll(); |
---|
700 | long time3 = System.currentTimeMillis(); |
---|
701 | |
---|
702 | try { |
---|
703 | session.incStatistics("tagMessages-Total"); |
---|
704 | Integer ret = tagMessages.apply(tagConfig); |
---|
705 | session.incStatistics("tagMessages-Success"); |
---|
706 | return ret; |
---|
707 | } |
---|
708 | catch(Throwable t) { |
---|
709 | session.incStatistics("tagMessages-Failure"); |
---|
710 | ServiceFault e; |
---|
711 | if(t instanceof ServiceFault) { |
---|
712 | e = (ServiceFault) t; |
---|
713 | } |
---|
714 | else { |
---|
715 | e = ServiceFault.runtimeException() |
---|
716 | .setActor("tagMessages") |
---|
717 | .setCause(t) |
---|
718 | .create(); |
---|
719 | } |
---|
720 | TFault faultInfo = e.getFaultInfo(); |
---|
721 | if(faultInfo != null) { |
---|
722 | log.error(faultInfo); |
---|
723 | } |
---|
724 | log.error(e, "tagMessages\n\tsessionId: %s\n\ttagConfig: %s", sessionId, tagConfig); |
---|
725 | session.setLastFault(faultInfo); |
---|
726 | throw e; |
---|
727 | } |
---|
728 | finally { |
---|
729 | long time4 = System.currentTimeMillis(); |
---|
730 | session.depart(); |
---|
731 | long time5 = System.currentTimeMillis(); |
---|
732 | log.info("Execution time profile tagMessages: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
733 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
734 | } |
---|
735 | } |
---|
736 | //</editor-fold> |
---|
737 | |
---|
738 | |
---|
739 | //<editor-fold defaultstate="collapsed" desc=" zipMessages "> |
---|
740 | //========================================================================== |
---|
741 | @Autowired |
---|
742 | private ZipMessagesOperation zipMessages; |
---|
743 | |
---|
744 | @Override |
---|
745 | public String zipMessages(String sessionId, String zipConfig) throws ServiceFault { |
---|
746 | long time1 = System.currentTimeMillis(); |
---|
747 | sessionId = nullToEmpty(sessionId).trim(); |
---|
748 | zipConfig = nullToEmpty(zipConfig).trim(); |
---|
749 | |
---|
750 | Session session = SessionMap.get(sessionId); |
---|
751 | if(session == null) { |
---|
752 | return null; |
---|
753 | } |
---|
754 | |
---|
755 | Session.setThreadSession(session); |
---|
756 | |
---|
757 | long time2 = System.currentTimeMillis(); |
---|
758 | session.enroll(); |
---|
759 | long time3 = System.currentTimeMillis(); |
---|
760 | |
---|
761 | try { |
---|
762 | session.incStatistics("zipMessages-Total"); |
---|
763 | String ret = zipMessages.apply(zipConfig); |
---|
764 | session.incStatistics("zipMessages-Success"); |
---|
765 | return ret; |
---|
766 | } |
---|
767 | catch(Throwable t) { |
---|
768 | session.incStatistics("zipMessages-Failure"); |
---|
769 | ServiceFault e; |
---|
770 | if(t instanceof ServiceFault) { |
---|
771 | e = (ServiceFault) t; |
---|
772 | } |
---|
773 | else { |
---|
774 | e = ServiceFault.runtimeException() |
---|
775 | .setActor("zipMessages") |
---|
776 | .setCause(t) |
---|
777 | .create(); |
---|
778 | } |
---|
779 | TFault faultInfo = e.getFaultInfo(); |
---|
780 | if(faultInfo != null) { |
---|
781 | log.error(faultInfo); |
---|
782 | } |
---|
783 | log.error(e, "zipMessages\n\tsessionId: %s\n\tzipConfig: %s", sessionId, zipConfig); |
---|
784 | session.setLastFault(faultInfo); |
---|
785 | throw e; |
---|
786 | } |
---|
787 | finally { |
---|
788 | long time4 = System.currentTimeMillis(); |
---|
789 | session.depart(); |
---|
790 | long time5 = System.currentTimeMillis(); |
---|
791 | log.info("Execution time profile zipMessages: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
792 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
793 | } |
---|
794 | } |
---|
795 | //</editor-fold> |
---|
796 | |
---|
797 | |
---|
798 | //<editor-fold defaultstate="collapsed" desc=" createFolder "> |
---|
799 | //========================================================================== |
---|
800 | @Autowired |
---|
801 | private CreateFolderOperation createFolder; |
---|
802 | |
---|
803 | @Override |
---|
804 | public TFolder createFolder(String sessionId, String parentFolderId, String name) throws ServiceFault { |
---|
805 | long time1 = System.currentTimeMillis(); |
---|
806 | sessionId = nullToEmpty(sessionId).trim(); |
---|
807 | parentFolderId = nullToEmpty(parentFolderId).trim(); |
---|
808 | name = nullToEmpty(name).trim(); |
---|
809 | |
---|
810 | Session session = SessionMap.get(sessionId); |
---|
811 | if(session == null) { |
---|
812 | return null; |
---|
813 | } |
---|
814 | |
---|
815 | Session.setThreadSession(session); |
---|
816 | |
---|
817 | long time2 = System.currentTimeMillis(); |
---|
818 | session.enroll(); |
---|
819 | long time3 = System.currentTimeMillis(); |
---|
820 | |
---|
821 | try { |
---|
822 | session.incStatistics("createFolder-Total"); |
---|
823 | TFolder ret = createFolder.apply(parentFolderId, name); |
---|
824 | session.incStatistics("createFolder-Success"); |
---|
825 | return ret; |
---|
826 | } |
---|
827 | catch(Throwable t) { |
---|
828 | session.incStatistics("createFolder-Failure"); |
---|
829 | ServiceFault e; |
---|
830 | if(t instanceof ServiceFault) { |
---|
831 | e = (ServiceFault) t; |
---|
832 | } |
---|
833 | else { |
---|
834 | e = ServiceFault.runtimeException() |
---|
835 | .setActor("createFolder") |
---|
836 | .setCause(t) |
---|
837 | .create(); |
---|
838 | } |
---|
839 | TFault faultInfo = e.getFaultInfo(); |
---|
840 | if(faultInfo != null) { |
---|
841 | log.error(faultInfo); |
---|
842 | } |
---|
843 | log.error(e, "createFolder\n\tsessionId: %s\n\tparentFolderId: %s\n\tname: %s", sessionId, parentFolderId, name); |
---|
844 | session.setLastFault(faultInfo); |
---|
845 | throw e; |
---|
846 | } |
---|
847 | finally { |
---|
848 | long time4 = System.currentTimeMillis(); |
---|
849 | session.depart(); |
---|
850 | long time5 = System.currentTimeMillis(); |
---|
851 | log.info("Execution time profile createFolder: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
852 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
853 | } |
---|
854 | } |
---|
855 | //</editor-fold> |
---|
856 | |
---|
857 | |
---|
858 | //<editor-fold defaultstate="collapsed" desc=" createAbsoluteFolder "> |
---|
859 | //========================================================================== |
---|
860 | @Autowired |
---|
861 | private CreateAbsoluteFolderOperation createAbsoluteFolder; |
---|
862 | |
---|
863 | @Override |
---|
864 | public TFolder createAbsoluteFolder(String sessionId, String path) throws ServiceFault { |
---|
865 | long time1 = System.currentTimeMillis(); |
---|
866 | sessionId = nullToEmpty(sessionId).trim(); |
---|
867 | path = nullToEmpty(path).trim(); |
---|
868 | |
---|
869 | Session session = SessionMap.get(sessionId); |
---|
870 | if(session == null) { |
---|
871 | return null; |
---|
872 | } |
---|
873 | |
---|
874 | Session.setThreadSession(session); |
---|
875 | |
---|
876 | long time2 = System.currentTimeMillis(); |
---|
877 | session.enroll(); |
---|
878 | long time3 = System.currentTimeMillis(); |
---|
879 | |
---|
880 | try { |
---|
881 | session.incStatistics("createAbsoluteFolder-Total"); |
---|
882 | TFolder ret = createAbsoluteFolder.apply(path); |
---|
883 | session.incStatistics("createAbsoluteFolder-Success"); |
---|
884 | return ret; |
---|
885 | } |
---|
886 | catch(Throwable t) { |
---|
887 | session.incStatistics("createAbsoluteFolder-Failure"); |
---|
888 | ServiceFault e; |
---|
889 | if(t instanceof ServiceFault) { |
---|
890 | e = (ServiceFault) t; |
---|
891 | } |
---|
892 | else { |
---|
893 | e = ServiceFault.runtimeException() |
---|
894 | .setActor("createAbsoluteFolder") |
---|
895 | .setCause(t) |
---|
896 | .create(); |
---|
897 | } |
---|
898 | TFault faultInfo = e.getFaultInfo(); |
---|
899 | if(faultInfo != null) { |
---|
900 | log.error(faultInfo); |
---|
901 | } |
---|
902 | log.error(e, "createAbsoluteFolder\n\tsessionId: %s\n\tpath: %s", sessionId, path); |
---|
903 | session.setLastFault(faultInfo); |
---|
904 | throw e; |
---|
905 | } |
---|
906 | finally { |
---|
907 | long time4 = System.currentTimeMillis(); |
---|
908 | session.depart(); |
---|
909 | long time5 = System.currentTimeMillis(); |
---|
910 | log.info("Execution time profile createAbsoluteFolder: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
911 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
912 | } |
---|
913 | } |
---|
914 | //</editor-fold> |
---|
915 | |
---|
916 | |
---|
917 | //<editor-fold defaultstate="collapsed" desc=" renameFolder "> |
---|
918 | //========================================================================== |
---|
919 | @Autowired |
---|
920 | private RenameFolderOperation renameFolder; |
---|
921 | |
---|
922 | @Override |
---|
923 | public TFolder renameFolder(String sessionId, String folderId, String newName) throws ServiceFault { |
---|
924 | long time1 = System.currentTimeMillis(); |
---|
925 | sessionId = nullToEmpty(sessionId).trim(); |
---|
926 | folderId = nullToEmpty(folderId).trim(); |
---|
927 | newName = nullToEmpty(newName).trim(); |
---|
928 | |
---|
929 | Session session = SessionMap.get(sessionId); |
---|
930 | if(session == null) { |
---|
931 | return null; |
---|
932 | } |
---|
933 | |
---|
934 | Session.setThreadSession(session); |
---|
935 | |
---|
936 | long time2 = System.currentTimeMillis(); |
---|
937 | session.enroll(); |
---|
938 | long time3 = System.currentTimeMillis(); |
---|
939 | |
---|
940 | try { |
---|
941 | session.incStatistics("renameFolder-Total"); |
---|
942 | TFolder ret = renameFolder.apply(folderId, newName); |
---|
943 | session.incStatistics("renameFolder-Success"); |
---|
944 | return ret; |
---|
945 | } |
---|
946 | catch(Throwable t) { |
---|
947 | session.incStatistics("renameFolder-Failure"); |
---|
948 | ServiceFault e; |
---|
949 | if(t instanceof ServiceFault) { |
---|
950 | e = (ServiceFault) t; |
---|
951 | } |
---|
952 | else { |
---|
953 | e = ServiceFault.runtimeException() |
---|
954 | .setActor("renameFolder") |
---|
955 | .setCause(t) |
---|
956 | .create(); |
---|
957 | } |
---|
958 | TFault faultInfo = e.getFaultInfo(); |
---|
959 | if(faultInfo != null) { |
---|
960 | log.error(faultInfo); |
---|
961 | } |
---|
962 | log.error(e, "renameFolder\n\tsessionId: %s\n\tfolderId: %s\n\tnewName: %s", sessionId, folderId, newName); |
---|
963 | session.setLastFault(faultInfo); |
---|
964 | throw e; |
---|
965 | } |
---|
966 | finally { |
---|
967 | long time4 = System.currentTimeMillis(); |
---|
968 | session.depart(); |
---|
969 | long time5 = System.currentTimeMillis(); |
---|
970 | log.info("Execution time profile renameFolder: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
971 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
972 | } |
---|
973 | } |
---|
974 | //</editor-fold> |
---|
975 | |
---|
976 | |
---|
977 | //<editor-fold defaultstate="collapsed" desc=" moveFolder "> |
---|
978 | //========================================================================== |
---|
979 | @Autowired |
---|
980 | private MoveFolderOperation moveFolder; |
---|
981 | |
---|
982 | @Override |
---|
983 | public TFolder moveFolder(String sessionId, String newParentFolderId, String folderId) throws ServiceFault { |
---|
984 | long time1 = System.currentTimeMillis(); |
---|
985 | sessionId = nullToEmpty(sessionId).trim(); |
---|
986 | newParentFolderId = nullToEmpty(newParentFolderId).trim(); |
---|
987 | folderId = nullToEmpty(folderId).trim(); |
---|
988 | |
---|
989 | Session session = SessionMap.get(sessionId); |
---|
990 | if(session == null) { |
---|
991 | return null; |
---|
992 | } |
---|
993 | |
---|
994 | Session.setThreadSession(session); |
---|
995 | |
---|
996 | long time2 = System.currentTimeMillis(); |
---|
997 | session.enroll(); |
---|
998 | long time3 = System.currentTimeMillis(); |
---|
999 | |
---|
1000 | try { |
---|
1001 | session.incStatistics("moveFolder-Total"); |
---|
1002 | TFolder ret = moveFolder.apply(newParentFolderId, folderId); |
---|
1003 | session.incStatistics("moveFolder-Success"); |
---|
1004 | return ret; |
---|
1005 | } |
---|
1006 | catch(Throwable t) { |
---|
1007 | session.incStatistics("moveFolder-Failure"); |
---|
1008 | ServiceFault e; |
---|
1009 | if(t instanceof ServiceFault) { |
---|
1010 | e = (ServiceFault) t; |
---|
1011 | } |
---|
1012 | else { |
---|
1013 | e = ServiceFault.runtimeException() |
---|
1014 | .setActor("moveFolder") |
---|
1015 | .setCause(t) |
---|
1016 | .create(); |
---|
1017 | } |
---|
1018 | TFault faultInfo = e.getFaultInfo(); |
---|
1019 | if(faultInfo != null) { |
---|
1020 | log.error(faultInfo); |
---|
1021 | } |
---|
1022 | log.error(e, "moveFolder\n\tsessionId: %s\n\tfolderId: %s\n\tnewParentFolderId: %s", sessionId, folderId, newParentFolderId); |
---|
1023 | session.setLastFault(faultInfo); |
---|
1024 | throw e; |
---|
1025 | } |
---|
1026 | finally { |
---|
1027 | long time4 = System.currentTimeMillis(); |
---|
1028 | session.depart(); |
---|
1029 | long time5 = System.currentTimeMillis(); |
---|
1030 | log.info("Execution time profile moveFolder: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
1031 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
1032 | } |
---|
1033 | } |
---|
1034 | //</editor-fold> |
---|
1035 | |
---|
1036 | |
---|
1037 | //<editor-fold defaultstate="collapsed" desc=" deleteFolder "> |
---|
1038 | //========================================================================== |
---|
1039 | @Autowired |
---|
1040 | private DeleteFolderOperation deleteFolder; |
---|
1041 | |
---|
1042 | @Override |
---|
1043 | public Integer deleteFolder(String sessionId, String folderId, boolean recursive) throws ServiceFault { |
---|
1044 | long time1 = System.currentTimeMillis(); |
---|
1045 | sessionId = nullToEmpty(sessionId).trim(); |
---|
1046 | folderId = nullToEmpty(folderId).trim(); |
---|
1047 | |
---|
1048 | Session session = SessionMap.get(sessionId); |
---|
1049 | if(session == null) { |
---|
1050 | return null; |
---|
1051 | } |
---|
1052 | |
---|
1053 | Session.setThreadSession(session); |
---|
1054 | |
---|
1055 | long time2 = System.currentTimeMillis(); |
---|
1056 | session.enroll(); |
---|
1057 | long time3 = System.currentTimeMillis(); |
---|
1058 | |
---|
1059 | try { |
---|
1060 | session.incStatistics("deleteFolder-Total"); |
---|
1061 | Integer ret = deleteFolder.apply(folderId, recursive); |
---|
1062 | session.incStatistics("deleteFolder-Success"); |
---|
1063 | return ret; |
---|
1064 | } |
---|
1065 | catch(Throwable t) { |
---|
1066 | session.incStatistics("deleteFolder-Failure"); |
---|
1067 | ServiceFault e; |
---|
1068 | if(t instanceof ServiceFault) { |
---|
1069 | e = (ServiceFault) t; |
---|
1070 | } |
---|
1071 | else { |
---|
1072 | e = ServiceFault.runtimeException() |
---|
1073 | .setActor("deleteFolder") |
---|
1074 | .setCause(t) |
---|
1075 | .create(); |
---|
1076 | } |
---|
1077 | TFault faultInfo = e.getFaultInfo(); |
---|
1078 | if(faultInfo != null) { |
---|
1079 | log.error(faultInfo); |
---|
1080 | } |
---|
1081 | log.error(e, "deleteFolder\n\tsessionId: %s\n\tfolderId: %s\n\trecursive: %b", sessionId, folderId, recursive); |
---|
1082 | session.setLastFault(faultInfo); |
---|
1083 | throw e; |
---|
1084 | } |
---|
1085 | finally { |
---|
1086 | long time4 = System.currentTimeMillis(); |
---|
1087 | session.depart(); |
---|
1088 | long time5 = System.currentTimeMillis(); |
---|
1089 | log.info("Execution time profile deleteFolder: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
1090 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
1091 | } |
---|
1092 | } |
---|
1093 | //</editor-fold> |
---|
1094 | |
---|
1095 | |
---|
1096 | //<editor-fold defaultstate="collapsed" desc=" archive "> |
---|
1097 | //========================================================================== |
---|
1098 | @Autowired |
---|
1099 | private ArchiveOperation archive; |
---|
1100 | |
---|
1101 | @Override |
---|
1102 | public TMessage archive(String sessionId, String folderId, String message) throws ServiceFault { |
---|
1103 | long time1 = System.currentTimeMillis(); |
---|
1104 | sessionId = nullToEmpty(sessionId).trim(); |
---|
1105 | folderId = nullToEmpty(folderId).trim(); |
---|
1106 | message = nullToEmpty(message); |
---|
1107 | |
---|
1108 | Session session = SessionMap.get(sessionId); |
---|
1109 | if(session == null) { |
---|
1110 | return null; |
---|
1111 | } |
---|
1112 | |
---|
1113 | Session.setThreadSession(session); |
---|
1114 | |
---|
1115 | long time2 = System.currentTimeMillis(); |
---|
1116 | session.enroll(); |
---|
1117 | long time3 = System.currentTimeMillis(); |
---|
1118 | |
---|
1119 | try { |
---|
1120 | session.incStatistics("archive-Total"); |
---|
1121 | TMessage ret = archive.apply(folderId, message); |
---|
1122 | session.incStatistics("archive-Success"); |
---|
1123 | return ret; |
---|
1124 | } |
---|
1125 | catch(Throwable t) { |
---|
1126 | session.incStatistics("archive-Failure"); |
---|
1127 | ServiceFault e; |
---|
1128 | if(t instanceof ServiceFault) { |
---|
1129 | e = (ServiceFault) t; |
---|
1130 | } |
---|
1131 | else { |
---|
1132 | e = ServiceFault.runtimeException() |
---|
1133 | .setActor("archive") |
---|
1134 | .setCause(t) |
---|
1135 | .create(); |
---|
1136 | } |
---|
1137 | TFault faultInfo = e.getFaultInfo(); |
---|
1138 | if(faultInfo != null) { |
---|
1139 | log.error(faultInfo); |
---|
1140 | } |
---|
1141 | log.error(e, "archive\n\tsessionId: %s\n\tfolderId: %s\n\tmessage:\n%s", sessionId, folderId, message); |
---|
1142 | session.setLastFault(faultInfo); |
---|
1143 | throw e; |
---|
1144 | } |
---|
1145 | finally { |
---|
1146 | long time4 = System.currentTimeMillis(); |
---|
1147 | session.depart(); |
---|
1148 | long time5 = System.currentTimeMillis(); |
---|
1149 | log.info("Execution time profile archive: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
1150 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
1151 | } |
---|
1152 | } |
---|
1153 | //</editor-fold> |
---|
1154 | |
---|
1155 | |
---|
1156 | //<editor-fold defaultstate="collapsed" desc=" getFolderInfo "> |
---|
1157 | //========================================================================== |
---|
1158 | @Autowired |
---|
1159 | private GetFolderInfoOperation getFolderInfo; |
---|
1160 | |
---|
1161 | @Override |
---|
1162 | public TFolder getFolderInfo(String sessionId, String folderId) throws ServiceFault { |
---|
1163 | long time1 = System.currentTimeMillis(); |
---|
1164 | sessionId = nullToEmpty(sessionId).trim(); |
---|
1165 | folderId = nullToEmpty(folderId).trim(); |
---|
1166 | |
---|
1167 | Session session = SessionMap.get(sessionId); |
---|
1168 | if(session == null) { |
---|
1169 | return null; |
---|
1170 | } |
---|
1171 | |
---|
1172 | Session.setThreadSession(session); |
---|
1173 | |
---|
1174 | long time2 = System.currentTimeMillis(); |
---|
1175 | session.enroll(); |
---|
1176 | long time3 = System.currentTimeMillis(); |
---|
1177 | |
---|
1178 | try { |
---|
1179 | session.incStatistics("getFolderInfo-Total"); |
---|
1180 | TFolder ret = getFolderInfo.apply(folderId); |
---|
1181 | session.incStatistics("getFolderInfo-Success"); |
---|
1182 | return ret; |
---|
1183 | } |
---|
1184 | catch(Throwable t) { |
---|
1185 | session.incStatistics("getFolderInfo-Failure"); |
---|
1186 | ServiceFault e; |
---|
1187 | if(t instanceof ServiceFault) { |
---|
1188 | e = (ServiceFault) t; |
---|
1189 | } |
---|
1190 | else { |
---|
1191 | e = ServiceFault.runtimeException() |
---|
1192 | .setActor("getFolderInfo") |
---|
1193 | .setCause(t) |
---|
1194 | .create(); |
---|
1195 | } |
---|
1196 | TFault faultInfo = e.getFaultInfo(); |
---|
1197 | if(faultInfo != null) { |
---|
1198 | log.error(faultInfo); |
---|
1199 | } |
---|
1200 | log.error(e, "getFolderInfo\n\tsessionId: %s\n\tfolderId: %s", sessionId, folderId); |
---|
1201 | session.setLastFault(faultInfo); |
---|
1202 | throw e; |
---|
1203 | } |
---|
1204 | finally { |
---|
1205 | long time4 = System.currentTimeMillis(); |
---|
1206 | session.depart(); |
---|
1207 | long time5 = System.currentTimeMillis(); |
---|
1208 | log.info("Execution time profile getFolderInfo: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
1209 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
1210 | } |
---|
1211 | } |
---|
1212 | //</editor-fold> |
---|
1213 | |
---|
1214 | |
---|
1215 | //<editor-fold defaultstate="collapsed" desc=" getMessageInfo "> |
---|
1216 | //========================================================================== |
---|
1217 | @Autowired |
---|
1218 | private GetMessageInfoOperation getMessageInfo; |
---|
1219 | |
---|
1220 | @Override |
---|
1221 | public TMessage getMessageInfo(String sessionId, String messageId) throws ServiceFault { |
---|
1222 | long time1 = System.currentTimeMillis(); |
---|
1223 | sessionId = nullToEmpty(sessionId).trim(); |
---|
1224 | messageId = nullToEmpty(messageId).trim(); |
---|
1225 | |
---|
1226 | Session session = SessionMap.get(sessionId); |
---|
1227 | if(session == null) { |
---|
1228 | return null; |
---|
1229 | } |
---|
1230 | |
---|
1231 | Session.setThreadSession(session); |
---|
1232 | |
---|
1233 | long time2 = System.currentTimeMillis(); |
---|
1234 | session.enroll(); |
---|
1235 | long time3 = System.currentTimeMillis(); |
---|
1236 | |
---|
1237 | try { |
---|
1238 | session.incStatistics("getMessageInfo-Total"); |
---|
1239 | TMessage ret = getMessageInfo.apply(messageId); |
---|
1240 | session.incStatistics("getMessageInfo-Success"); |
---|
1241 | return ret; |
---|
1242 | } |
---|
1243 | catch(Throwable t) { |
---|
1244 | session.incStatistics("getMessageInfo-Failure"); |
---|
1245 | ServiceFault e; |
---|
1246 | if(t instanceof ServiceFault) { |
---|
1247 | e = (ServiceFault) t; |
---|
1248 | } |
---|
1249 | else { |
---|
1250 | e = ServiceFault.runtimeException() |
---|
1251 | .setActor("getMessageInfo") |
---|
1252 | .setCause(t) |
---|
1253 | .create(); |
---|
1254 | } |
---|
1255 | TFault faultInfo = e.getFaultInfo(); |
---|
1256 | if(faultInfo != null) { |
---|
1257 | log.error(faultInfo); |
---|
1258 | } |
---|
1259 | log.error(e, "getMessageInfo\n\tsessionId: %s\n\tmessageId: %s", sessionId, messageId); |
---|
1260 | session.setLastFault(faultInfo); |
---|
1261 | throw e; |
---|
1262 | } |
---|
1263 | finally { |
---|
1264 | long time4 = System.currentTimeMillis(); |
---|
1265 | session.depart(); |
---|
1266 | long time5 = System.currentTimeMillis(); |
---|
1267 | log.info("Execution time profile getMessageInfo: [i12=%1$d] [i23=%2$d] [i34=%3$d] [i45=%4$d]", |
---|
1268 | time2-time1, time3-time2, time4-time3, time5-time4); |
---|
1269 | } |
---|
1270 | } |
---|
1271 | //</editor-fold> |
---|
1272 | |
---|
1273 | |
---|
1274 | //<editor-fold defaultstate="collapsed" desc=" getState "> |
---|
1275 | //========================================================================== |
---|
1276 | @Autowired |
---|
1277 | private GetStateOperation getState; |
---|
1278 | |
---|
1279 | @Override |
---|
1280 | public String getState() throws ServiceFault { |
---|
1281 | return getState.apply(); |
---|
1282 | } |
---|
1283 | //</editor-fold> |
---|
1284 | |
---|
1285 | } |
---|