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
35
36
37 package fr.paris.lutece.plugins.tipi.business;
38
39 import java.rmi.RemoteException;
40 import java.text.MessageFormat;
41 import java.text.SimpleDateFormat;
42 import java.util.Date;
43 import java.util.List;
44
45 import javax.xml.rpc.ServiceException;
46
47 import fr.paris.lutece.plugins.tipi.util.Constants;
48 import fr.paris.lutece.plugins.tipi.business.Tipi;
49 import fr.paris.lutece.plugins.tipi.business.TipiProcessor;
50 import fr.paris.lutece.portal.service.daemon.Daemon;
51 import fr.paris.lutece.portal.service.spring.SpringContextService;
52 import fr.paris.lutece.portal.service.util.AppLogService;
53
54
55
56
57 public class TipiTask extends Daemon
58 {
59 private TipiProcessor processor = SpringContextService.getBean( "tipiProcessor" );
60
61 private static final String LOG_MESSAGE = "{0}: Traitement de {1} transactions [{2} succes, {3} refus, {4} annulation]\r\n";
62
63 @Override
64 public synchronized void run( )
65 {
66
67 List<String> idOps = processor.getPendingTransactions( );
68
69 if ( idOps == null || idOps.isEmpty( ) )
70 {
71 return;
72 }
73
74 int success = 0;
75 int denied = 0;
76 int cancelled = 0;
77
78 for ( String idOp : idOps )
79 {
80 try
81 {
82 final Tipi tipi = Tipi.read( idOp ).process( );
83
84 if ( tipi.isPaymentSuccess( ) )
85 {
86 success++;
87 }
88 if ( tipi.isPaymentDenied( ) )
89 {
90 denied++;
91 }
92 if ( tipi.isPaymentCancelled( ) )
93 {
94 cancelled++;
95 }
96 } catch ( RemoteException | ServiceException e )
97 {
98 AppLogService.error( "Erreur a la recuperation des informations de paiement pour l'ID: " + idOp, e );
99 }
100 }
101
102 SimpleDateFormat dateFormat = new SimpleDateFormat( Constants.DATE_FORMAT );
103
104 String message = MessageFormat.format( LOG_MESSAGE, dateFormat.format( new Date( ) ), success + denied + cancelled, success, denied, cancelled );
105
106 if ( getLastRunLogs( ) != null )
107 {
108 setLastRunLogs( getLastRunLogs( ) + message );
109 } else
110 {
111 setLastRunLogs( message );
112 }
113 }
114
115 }