View Javadoc
1   /*
2    * Copyright (c) 2002-2022, 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       * Stores a file Lutece File
69       * 
70       * @param file
71       *            the file
72       * @return The key of the stored file
73       */
74      String storeFile( File file );
75  
76      /**
77       * Stores a org.apache.commons.fileupload.FileItem
78       * 
79       * @param fileItem
80       *            the fileItem
81       * @return The key of the blob
82       */
83      String storeFileItem( FileItem fileItem );
84  
85      /**
86       * Stores an input stream
87       * 
88       * @param inputStream
89       *            the input stream
90       * @return The key of the blob
91       */
92      String storeInputStream( InputStream inputStream );
93  
94      /**
95       * Store a blob from a bytes array
96       * 
97       * @param blob
98       *            The blob
99       * @return The key of the blob
100      */
101     String storeBytes( byte [ ] blob );
102 
103     /**
104      * Get a file
105      * 
106      * @param strKey
107      *            The key of the file
108      * @return The file
109      */
110     File getFile( String strKey );
111 
112     /**
113      * Get a file object only filled with the meta data (name, size ...) 
114      * without the physical file content
115      * 
116      * @param strKey
117      *            The key of the file
118      * @return The file
119      */
120     File getFileMetaData( String strKey );
121 
122     /**
123      * Gets a blob as {@link InputStream}
124      * 
125      * @param strKey
126      *            the key
127      * @return the {@link InputStream}
128      */
129     InputStream getInputStream( String strKey );
130 
131     /**
132      * Delete a blob
133      * 
134      * @param strKey
135      *            The key of the blob
136      */
137     void delete( String strKey );
138 
139     /**
140      * Gets the file download url for Front Office Lutece users
141      * 
142      * @param strKey
143      *            the
144      * @return the download link
145      */
146     String getFileDownloadUrlFO( String strKey );
147 
148     /**
149      * Gets the file download url for Front Office Lutece users
150      * 
151      * @param strKey
152      *            the
153      * @param additionnalData
154      * @return the download link
155      */
156     String getFileDownloadUrlFO( String strKey, Map<String, String> additionnalData );
157 
158     /**
159      * Gets the file download url for Back Office admin Lutece users
160      * 
161      * @param strKey
162      *            the
163      * @return the download link
164      */
165     String getFileDownloadUrlBO( String strKey );
166 
167     /**
168      * Gets the file download url for Back Office admin Lutece users
169      * 
170      * @param strKey
171      *            the
172      * @param additionnalData
173      * @return the download link
174      */
175     String getFileDownloadUrlBO( String strKey, Map<String, String> additionnalData );
176 
177     /**
178      * get requested file from BO
179      * 
180      * @param request
181      * @return the file
182      * @throws fr.paris.lutece.portal.service.admin.AccessDeniedException
183      * @throws fr.paris.lutece.portal.service.file.ExpiredLinkException
184      * @throws fr.paris.lutece.portal.service.security.UserNotSignedException
185      */
186     File getFileFromRequestBO( HttpServletRequest request ) throws AccessDeniedException, ExpiredLinkException, UserNotSignedException;
187 
188     /**
189      * get requested file from FO
190      * 
191      * @param request
192      * @return the file
193      * @throws fr.paris.lutece.portal.service.admin.AccessDeniedException
194      * @throws fr.paris.lutece.portal.service.file.ExpiredLinkException
195      * @throws fr.paris.lutece.portal.service.security.UserNotSignedException
196      */
197     File getFileFromRequestFO( HttpServletRequest request ) throws AccessDeniedException, ExpiredLinkException, UserNotSignedException;
198 
199     /**
200      * check if current user can access the file
201      * 
202      * @param fileData
203      * @param user
204      *            the current user
205      * @throws fr.paris.lutece.portal.service.admin.AccessDeniedException
206      * @throws fr.paris.lutece.portal.service.security.UserNotSignedException
207      */
208     void checkAccessRights( Map<String, String> fileData, User user ) throws AccessDeniedException, UserNotSignedException;
209 
210     /**
211      * check if link is valid
212      * 
213      * @param fileData
214      * @throws ExpiredLinkException
215      */
216     void checkLinkValidity( Map<String, String> fileData ) throws ExpiredLinkException;
217 }