1 /*
2 * Copyright (c) 2002-2025, City of Paris
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice
10 * and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice
13 * and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
32 * License 1.0
33 */
34 package fr.paris.lutece.portal.service.file;
35
36 import fr.paris.lutece.api.user.User;
37 import fr.paris.lutece.portal.business.file.File;
38 import fr.paris.lutece.portal.service.admin.AccessDeniedException;
39 import fr.paris.lutece.portal.service.security.UserNotSignedException;
40
41 import java.io.InputStream;
42 import java.io.Serializable;
43 import java.util.Map;
44 import javax.servlet.http.HttpServletRequest;
45 import org.apache.commons.fileupload.FileItem;
46
47 /**
48 * File Store Service Provider Interface. InputStream methods should be used for very large blobs
49 */
50 public interface IFileStoreServiceProvider extends Serializable
51 {
52
53 /**
54 * get the service name
55 *
56 * @return the service name
57 */
58 public String getName( );
59
60 /**
61 * get the default
62 *
63 * @return true if default
64 */
65 public boolean isDefault( );
66
67 /**
68 * health check
69 *
70 * @return true if available
71 */
72 public default boolean healthCheck( )
73 {
74 // default
75 return true;
76 }
77
78
79 /**
80 * Stores a file Lutece File
81 *
82 * @param file
83 * the file
84 * @return The key of the stored file
85 */
86 String storeFile( File file ) throws FileServiceException;
87
88 /**
89 * Stores a org.apache.commons.fileupload.FileItem
90 *
91 * @param fileItem
92 * the fileItem
93 * @return The key of the blob
94 */
95 String storeFileItem( FileItem fileItem ) throws FileServiceException;
96
97 /**
98 * Stores an input stream
99 *
100 * @param inputStream
101 * the input stream
102 * @return The key of the blob
103 */
104 String storeInputStream( InputStream inputStream ) throws FileServiceException;
105
106 /**
107 * Store a blob from a bytes array
108 *
109 * @param blob
110 * The blob
111 * @return The key of the blob
112 */
113 String storeBytes( byte [ ] blob ) throws FileServiceException;
114
115 /**
116 * Get a file
117 *
118 * @param strKey
119 * The key of the file
120 * @return The file
121 */
122 File getFile( String strKey ) throws FileServiceException;
123
124 /**
125 * Get a file object only filled with the meta data (name, size ...)
126 * without the physical file content
127 *
128 * @param strKey
129 * The key of the file
130 * @return The file
131 */
132 File getFileMetaData( String strKey ) throws FileServiceException;
133
134 /**
135 * Gets a blob as {@link InputStream}
136 *
137 * @param strKey
138 * the key
139 * @return the {@link InputStream}
140 */
141 InputStream getInputStream( String strKey ) throws FileServiceException;
142
143 /**
144 * Delete a blob
145 *
146 * @param strKey
147 * The key of the blob
148 */
149 void delete( String strKey ) throws FileServiceException;
150
151 /**
152 * Gets the file download url for Front Office Lutece users
153 *
154 * @param strKey
155 * the
156 * @return the download link
157 */
158 String getFileDownloadUrlFO( String strKey );
159
160 /**
161 * Gets the file download url for Front Office Lutece users
162 *
163 * @param strKey
164 * the
165 * @param additionnalData
166 * @return the download link
167 */
168 String getFileDownloadUrlFO( String strKey, Map<String, String> additionnalData );
169
170 /**
171 * Gets the file download url for Back Office admin Lutece users
172 *
173 * @param strKey
174 * the
175 * @return the download link
176 */
177 String getFileDownloadUrlBO( String strKey );
178
179 /**
180 * Gets the file download url for Back Office admin Lutece users
181 *
182 * @param strKey
183 * the
184 * @param additionnalData
185 * @return the download link
186 */
187 String getFileDownloadUrlBO( String strKey, Map<String, String> additionnalData );
188
189 /**
190 * get requested file from BO
191 *
192 * @param request
193 * @return the file
194 * @throws fr.paris.lutece.portal.service.admin.AccessDeniedException
195 * @throws fr.paris.lutece.portal.service.file.ExpiredLinkException
196 * @throws fr.paris.lutece.portal.service.security.UserNotSignedException
197 */
198 File getFileFromRequestBO( HttpServletRequest request ) throws AccessDeniedException, ExpiredLinkException, UserNotSignedException, FileServiceException;
199
200 /**
201 * get requested file from FO
202 *
203 * @param request
204 * @return the file
205 * @throws fr.paris.lutece.portal.service.admin.AccessDeniedException
206 * @throws fr.paris.lutece.portal.service.file.ExpiredLinkException
207 * @throws fr.paris.lutece.portal.service.security.UserNotSignedException
208 */
209 File getFileFromRequestFO( HttpServletRequest request ) throws AccessDeniedException, ExpiredLinkException, UserNotSignedException, FileServiceException;
210
211 /**
212 * check if current user can access the file
213 *
214 * @param fileData
215 * @param user
216 * the current user
217 * @throws fr.paris.lutece.portal.service.admin.AccessDeniedException
218 * @throws fr.paris.lutece.portal.service.security.UserNotSignedException
219 */
220 void checkAccessRights( Map<String, String> fileData, User user ) throws AccessDeniedException, UserNotSignedException;
221
222 /**
223 * check if link is valid
224 *
225 * @param fileData
226 * @throws ExpiredLinkException
227 */
228 void checkLinkValidity( Map<String, String> fileData ) throws ExpiredLinkException;
229 }