IFileStoreServiceProvider.java

  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. import fr.paris.lutece.api.user.User;
  36. import fr.paris.lutece.portal.business.file.File;
  37. import fr.paris.lutece.portal.service.admin.AccessDeniedException;
  38. import fr.paris.lutece.portal.service.security.UserNotSignedException;

  39. import java.io.InputStream;
  40. import java.io.Serializable;
  41. import java.util.Map;
  42. import javax.servlet.http.HttpServletRequest;
  43. import org.apache.commons.fileupload.FileItem;

  44. /**
  45.  * File Store Service Provider Interface. InputStream methods should be used for very large blobs
  46.  */
  47. public interface IFileStoreServiceProvider extends Serializable
  48. {

  49.     /**
  50.      * get the service name
  51.      *
  52.      * @return the service name
  53.      */
  54.     public String getName( );

  55.     /**
  56.      * get the default
  57.      *
  58.      * @return true if default
  59.      */
  60.     public boolean isDefault( );
  61.    
  62.     /**
  63.      * health check
  64.      *
  65.      * @return true if available
  66.      */
  67.     public default boolean healthCheck( )
  68.     {
  69.         // default
  70.         return true;
  71.     }


  72.     /**
  73.      * Stores a file Lutece File
  74.      *
  75.      * @param file
  76.      *            the file
  77.      * @return The key of the stored file
  78.      */
  79.     String storeFile( File file ) throws FileServiceException;

  80.     /**
  81.      * Stores a org.apache.commons.fileupload.FileItem
  82.      *
  83.      * @param fileItem
  84.      *            the fileItem
  85.      * @return The key of the blob
  86.      */
  87.     String storeFileItem( FileItem fileItem ) throws FileServiceException;

  88.     /**
  89.      * Stores an input stream
  90.      *
  91.      * @param inputStream
  92.      *            the input stream
  93.      * @return The key of the blob
  94.      */
  95.     String storeInputStream( InputStream inputStream ) throws FileServiceException;

  96.     /**
  97.      * Store a blob from a bytes array
  98.      *
  99.      * @param blob
  100.      *            The blob
  101.      * @return The key of the blob
  102.      */
  103.     String storeBytes( byte [ ] blob ) throws FileServiceException;

  104.     /**
  105.      * Get a file
  106.      *
  107.      * @param strKey
  108.      *            The key of the file
  109.      * @return The file
  110.      */
  111.     File getFile( String strKey ) throws FileServiceException;

  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 ) throws FileServiceException;

  121.     /**
  122.      * Gets a blob as {@link InputStream}
  123.      *
  124.      * @param strKey
  125.      *            the key
  126.      * @return the {@link InputStream}
  127.      */
  128.     InputStream getInputStream( String strKey ) throws FileServiceException;

  129.     /**
  130.      * Delete a blob
  131.      *
  132.      * @param strKey
  133.      *            The key of the blob
  134.      */
  135.     void delete( String strKey ) throws FileServiceException;

  136.     /**
  137.      * Gets the file download url for Front Office Lutece users
  138.      *
  139.      * @param strKey
  140.      *            the
  141.      * @return the download link
  142.      */
  143.     String getFileDownloadUrlFO( String strKey );

  144.     /**
  145.      * Gets the file download url for Front Office Lutece users
  146.      *
  147.      * @param strKey
  148.      *            the
  149.      * @param additionnalData
  150.      * @return the download link
  151.      */
  152.     String getFileDownloadUrlFO( String strKey, Map<String, String> additionnalData );

  153.     /**
  154.      * Gets the file download url for Back Office admin Lutece users
  155.      *
  156.      * @param strKey
  157.      *            the
  158.      * @return the download link
  159.      */
  160.     String getFileDownloadUrlBO( String strKey );

  161.     /**
  162.      * Gets the file download url for Back Office admin Lutece users
  163.      *
  164.      * @param strKey
  165.      *            the
  166.      * @param additionnalData
  167.      * @return the download link
  168.      */
  169.     String getFileDownloadUrlBO( String strKey, Map<String, String> additionnalData );

  170.     /**
  171.      * get requested file from BO
  172.      *
  173.      * @param request
  174.      * @return the file
  175.      * @throws fr.paris.lutece.portal.service.admin.AccessDeniedException
  176.      * @throws fr.paris.lutece.portal.service.file.ExpiredLinkException
  177.      * @throws fr.paris.lutece.portal.service.security.UserNotSignedException
  178.      */
  179.     File getFileFromRequestBO( HttpServletRequest request ) throws AccessDeniedException, ExpiredLinkException, UserNotSignedException, FileServiceException;

  180.     /**
  181.      * get requested file from FO
  182.      *
  183.      * @param request
  184.      * @return the file
  185.      * @throws fr.paris.lutece.portal.service.admin.AccessDeniedException
  186.      * @throws fr.paris.lutece.portal.service.file.ExpiredLinkException
  187.      * @throws fr.paris.lutece.portal.service.security.UserNotSignedException
  188.      */
  189.     File getFileFromRequestFO( HttpServletRequest request ) throws AccessDeniedException, ExpiredLinkException, UserNotSignedException, FileServiceException;

  190.     /**
  191.      * check if current user can access the file
  192.      *
  193.      * @param fileData
  194.      * @param user
  195.      *            the current user
  196.      * @throws fr.paris.lutece.portal.service.admin.AccessDeniedException
  197.      * @throws fr.paris.lutece.portal.service.security.UserNotSignedException
  198.      */
  199.     void checkAccessRights( Map<String, String> fileData, User user ) throws AccessDeniedException, UserNotSignedException;

  200.     /**
  201.      * check if link is valid
  202.      *
  203.      * @param fileData
  204.      * @throws ExpiredLinkException
  205.      */
  206.     void checkLinkValidity( Map<String, String> fileData ) throws ExpiredLinkException;
  207. }