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.portal.service.file;
35
36 import fr.paris.lutece.portal.service.spring.SpringContextService;
37 import fr.paris.lutece.portal.service.util.AppException;
38 import java.util.List;
39
40
41
42
43
44 public class FileService
45 {
46
47
48 public static final String PARAMETER_FILE_ID = "file_id";
49 public static final String PARAMETER_RESOURCE_ID = "resource_id";
50 public static final String PARAMETER_RESOURCE_TYPE = "resource_type";
51 public static final String PARAMETER_VALIDITY_TIME = "validity_time";
52 public static final String PARAMETER_DATA = "data";
53 public static final String PARAMETER_BO = "is_bo";
54 public static final String PARAMETER_PROVIDER = "provider";
55
56
57 public static final String PERMISSION_VIEW = "VIEW";
58
59
60 private static final String MSG_NO_FILE_SERVICE = "No file service Available";
61
62 private IFileStoreServiceProvider _currentFileStoreServiceProvider;
63 private static FileService/file/FileService.html#FileService">FileService _instance = new FileService( );
64
65
66
67
68 private FileService( )
69 {
70 _currentFileStoreServiceProvider = getDefaultServiceProvider( );
71 }
72
73
74
75
76
77
78 public static FileService getInstance( )
79 {
80 return _instance;
81 }
82
83
84
85
86
87
88
89 public boolean healthCheck( )
90 {
91 return _currentFileStoreServiceProvider.healthCheck( );
92 }
93
94
95
96
97
98
99
100 public IFileStoreServiceProvider getFileStoreServiceProvider( )
101 {
102 return _currentFileStoreServiceProvider;
103 }
104
105
106
107
108
109
110
111 public IFileStoreServiceProvider getFileStoreServiceProvider( String strFileStoreServiceProviderName )
112 {
113 List<IFileStoreServiceProvider> fileStoreServiceProviderList = SpringContextService.getBeansOfType( IFileStoreServiceProvider.class );
114
115
116 if ( !fileStoreServiceProviderList.isEmpty( ) )
117 {
118 for ( IFileStoreServiceProvider fss : fileStoreServiceProviderList )
119 {
120 if ( strFileStoreServiceProviderName.equals( fss.getName( ) ) )
121 {
122 return fss;
123 }
124 }
125 }
126
127
128 throw new AppException( MSG_NO_FILE_SERVICE );
129 }
130
131
132
133
134
135
136 public void setFileStoreServiceProvider( String strFileStoreServiceProviderName )
137 {
138 List<IFileStoreServiceProvider> fileStoreServiceProviderList = SpringContextService.getBeansOfType( IFileStoreServiceProvider.class );
139
140
141 if ( !fileStoreServiceProviderList.isEmpty( ) )
142 {
143 for ( IFileStoreServiceProvider fss : fileStoreServiceProviderList )
144 {
145 if ( strFileStoreServiceProviderName.equals( fss.getName( ) ) )
146 {
147 _currentFileStoreServiceProvider = fss;
148 return;
149 }
150 }
151 }
152
153
154 throw new AppException( MSG_NO_FILE_SERVICE );
155 }
156
157
158
159
160
161
162 private IFileStoreServiceProvider getDefaultServiceProvider( )
163 {
164 List<IFileStoreServiceProvider> fileStoreServiceProviderList = SpringContextService.getBeansOfType( IFileStoreServiceProvider.class );
165
166
167 if ( !fileStoreServiceProviderList.isEmpty( ) )
168 {
169 for ( IFileStoreServiceProvider fss : fileStoreServiceProviderList )
170 {
171 if ( fss.isDefault( ) )
172 {
173 return fss;
174 }
175 }
176
177
178 return fileStoreServiceProviderList.get( 0 ) ;
179 }
180
181
182 throw new AppException( MSG_NO_FILE_SERVICE );
183 }
184 }