View Javadoc
1   package fr.paris.lutece.plugins.ctv.service;
2   
3   import java.io.File;
4   import java.io.FileWriter;
5   import java.io.IOException;
6   import java.text.DateFormat;
7   import java.text.SimpleDateFormat;
8   import java.util.Date;
9   
10  import fr.paris.lutece.plugins.ctv.business.IFluxService;
11  import fr.paris.lutece.portal.service.daemon.Daemon;
12  import fr.paris.lutece.portal.service.datastore.DatastoreService;
13  import fr.paris.lutece.portal.service.spring.SpringContextService;
14  import fr.paris.lutece.portal.service.util.AppPropertiesService;
15  
16  public class FluxDonneesEmprisesTaxationSavoi2 extends Daemon
17  {
18      private IFluxService      fluxService = SpringContextService.getBean( "fluxService" );
19      private FileWriter file;
20      private static final String uploadBaseDirectory = AppPropertiesService.getProperty( "ctv.directory.savoi" );
21  
22      @Override
23      public void run( )
24      {
25  
26          setLastRunLogs( generateFlux( ) );
27      }
28  
29      public String generateFlux( )
30      {
31  
32          DateFormat df = new SimpleDateFormat( "yyyyMMdd_HHmmss" );
33          File fileFlux = new File( uploadBaseDirectory+"/logFlux/LogFluxDonneesEmprisesTaxationSavoi2_" + df.format( new Date( ) ) + ".log" );
34  
35          StringBuilder rapport = new StringBuilder( );
36          if ( DatastoreService.getDataValue( "parametre.envoi.savoi", "" ).equalsIgnoreCase( "OUI" ) )
37          {
38              fluxService.generateFlow( rapport );
39          }
40          else {
41              fluxService.generateFlowNon( rapport );
42          }
43          try
44          {
45              file = new FileWriter( fileFlux );
46              file.write( rapport.toString( ) );
47          } catch ( IOException e )
48          {
49              rapport.append( e.getMessage( )+" "+"Log non générée statut : 10" );
50              fileFlux.delete();
51          } finally
52          {
53              try
54              {
55                  file.flush( );
56                  file.close( );
57                  rapport.append( "Log générée statut : 0 \n" );
58  
59              } catch ( IOException e1 )
60              {
61                  e1.printStackTrace( );
62                  rapport.append( e1.getMessage( )+" "+"fin de la génération du fichier statut : 10 \n" );
63  
64              }
65          }
66          return rapport.toString( );
67  
68      }
69  
70  }