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.dila.service.impl;
35
36 import fr.paris.lutece.plugins.dila.business.enums.AudienceCategoryEnum;
37 import fr.paris.lutece.plugins.dila.exception.DilaException;
38 import fr.paris.lutece.plugins.dila.service.IDilaBatchXMLService;
39 import fr.paris.lutece.plugins.dila.service.IDilaIndexationService;
40 import fr.paris.lutece.plugins.dila.utils.constants.DilaConstants;
41 import fr.paris.lutece.plugins.dila.utils.filter.FilenameFilterXml;
42 import fr.paris.lutece.portal.service.util.AppLogService;
43 import fr.paris.lutece.portal.service.util.AppPropertiesService;
44
45 import org.jdom2.JDOMException;
46
47 import java.io.File;
48 import java.io.IOException;
49
50 import javax.inject.Inject;
51 import javax.inject.Named;
52
53
54
55
56
57 public class DilaIndexationService implements IDilaIndexationService
58 {
59 @Inject
60 @Named( "dilaBatchXmlService" )
61 private IDilaBatchXMLService _dilaBatchXMLService;
62
63 @Override
64 public void indexAll( ) throws DilaException
65 {
66 AppLogService.info( "Begin index" );
67
68
69 process( AppPropertiesService.getProperty( DilaConstants.PROPERTY_XML_FINAL_INDIVIDUALS ),
70 DilaConstants.PROCESS_INDIVIDUAL, AudienceCategoryEnum.INDIVIDUALS );
71
72
73 process( AppPropertiesService.getProperty( DilaConstants.PROPERTY_XML_FINAL_ASSO ),
74 DilaConstants.PROCESS_ASSOCIATION, AudienceCategoryEnum.ASSOCIATIONS );
75
76
77 process( AppPropertiesService.getProperty( DilaConstants.PROPERTY_XML_FINAL_PME ),
78 DilaConstants.PROCESS_PROFESSIONAL, AudienceCategoryEnum.PROFESSIONNALS );
79
80 _dilaBatchXMLService.delete( );
81 }
82
83
84
85
86
87
88
89
90
91
92 private void process( String strDirPath, String strProcessName, AudienceCategoryEnum typeXml )
93 throws DilaException
94 {
95 File dirXML = new File( strDirPath );
96
97 if ( dirXML.exists( ) )
98 {
99 File[] listXML = dirXML.listFiles( new FilenameFilterXml( ) );
100
101 if ( listXML != null )
102 {
103 AppLogService.info( "Processing " + strProcessName + " XML files available in directory " + strDirPath );
104
105 for ( File file : listXML )
106 {
107 try
108 {
109 _dilaBatchXMLService.processXMLFile( file, typeXml );
110 }
111 catch ( JDOMException jdom )
112 {
113 throw new DilaException( "Error during file " + file.getName( ) + " parsing.", jdom );
114 }
115 catch ( IOException ioe )
116 {
117 throw new DilaException( "Error during file " + file.getName( ) + " management.", ioe );
118 }
119 catch ( Exception e )
120 {
121 throw new DilaException( "Error during file " + file.getName( ) + " indexation : "+e.getMessage( ), e );
122 }
123 }
124 }
125 else
126 {
127 AppLogService.info( "No " + strProcessName + " XML files in directory " + strDirPath );
128 }
129 }
130 }
131 }