Class GoogleCloudStorageService

  • All Implemented Interfaces:
    com.totvs.tjf.storage.StorageService

    @Component
    public class GoogleCloudStorageService
    extends Object
    implements com.totvs.tjf.storage.StorageService
    This class gives supports to the Google Cloud Storage
    • Constructor Detail

      • GoogleCloudStorageService

        public GoogleCloudStorageService​(GoogleCloudStorageProperties applicationProperties,
                                         Optional<com.totvs.tjf.storage.PropertiesProvider> propertiesProvider)
        Creates an instance of GoogleCloudStorageService
        Parameters:
        applicationProperties - static application properties
        propertiesProvider - application properties provider
    • Method Detail

      • createBucket

        public void createBucket​(String bucketName,
                                 com.totvs.tjf.storage.Property... properties)
                          throws IOException
        Creates a Bucket
        Specified by:
        createBucket in interface com.totvs.tjf.storage.StorageService
        Parameters:
        bucketName - the bucket's name
        properties - specific connection properties
        Throws:
        IOException - an IO exception of this operation
      • hasBucket

        public boolean hasBucket​(String bucketName,
                                 com.totvs.tjf.storage.Property... properties)
                          throws IOException
        Checks if the Bucket exists
        Specified by:
        hasBucket in interface com.totvs.tjf.storage.StorageService
        Parameters:
        bucketName - the bucket's name
        properties - specific connection properties
        Returns:
        boolean true if buckets exists or false if not
        Throws:
        IOException - an IO exception of this operation
      • deleteBucket

        public void deleteBucket​(String bucketName,
                                 com.totvs.tjf.storage.Property... properties)
                          throws IOException,
                                 com.totvs.tjf.storage.ObjectNotFoundException
        Deletes a Bucket
        Specified by:
        deleteBucket in interface com.totvs.tjf.storage.StorageService
        Parameters:
        bucketName - the bucket's name
        properties - specific connection properties
        Throws:
        IOException - an IO exception of this operation
        com.totvs.tjf.storage.ObjectNotFoundException - an object not found exception
      • saveObject

        public void saveObject​(String bucketName,
                               String name,
                               String type,
                               byte[] content,
                               com.totvs.tjf.storage.Property... properties)
                        throws IOException,
                               com.totvs.tjf.storage.ObjectNotFoundException
        Saves an object
        Specified by:
        saveObject in interface com.totvs.tjf.storage.StorageService
        Parameters:
        bucketName - the bucket's name
        name - the object's name
        type - the object's mime type
        content - the object's content
        properties - specific connection properties
        Throws:
        IOException - an IO exception of this operation
        com.totvs.tjf.storage.ObjectNotFoundException - an object not found exception
      • loadObject

        public byte[] loadObject​(String bucketName,
                                 String name,
                                 com.totvs.tjf.storage.Property... properties)
                          throws IOException,
                                 com.totvs.tjf.storage.ObjectNotFoundException
        Loads the object's content
        Specified by:
        loadObject in interface com.totvs.tjf.storage.StorageService
        Parameters:
        bucketName - the bucket's name
        name - the object's name
        properties - specific connection properties
        Returns:
        byte[] the object's content
        Throws:
        IOException - an IO exception of this operation
        com.totvs.tjf.storage.ObjectNotFoundException - an object not found exception
      • loadObjectsByIds

        public List<com.google.cloud.storage.Blob> loadObjectsByIds​(String bucketName,
                                                                    List<String> blobIds,
                                                                    com.totvs.tjf.storage.Property... properties)
                                                             throws IOException
        Loads the content of all ids informed
        Specified by:
        loadObjectsByIds in interface com.totvs.tjf.storage.StorageService
        Parameters:
        bucketName - bucket name
        blobIds - list of strings
        properties - specific connection properties
        Returns:
        multitype:Blob a list of all the objects content
        Throws:
        IOException - an IO exception of this operation
      • loadObjectsByIds

        public List<com.google.cloud.storage.Blob> loadObjectsByIds​(List<com.google.cloud.storage.BlobId> blobIds,
                                                                    com.totvs.tjf.storage.Property... properties)
                                                             throws IOException
        Loads the content of all ids informed
        Specified by:
        loadObjectsByIds in interface com.totvs.tjf.storage.StorageService
        Parameters:
        blobIds - list of BlobId
        properties - specific connection properties
        Returns:
        multitype:Blob a list of all the objects content
        Throws:
        IOException - an IO exception of this operation
        See Also:
        BlobId
      • deleteObject

        public void deleteObject​(String bucketName,
                                 String name,
                                 com.totvs.tjf.storage.Property... properties)
                          throws IOException,
                                 com.totvs.tjf.storage.ObjectNotFoundException
        Deletes an object
        Specified by:
        deleteObject in interface com.totvs.tjf.storage.StorageService
        Parameters:
        bucketName - the bucket's name
        name - the object's name
        properties - specific connection properties
        Throws:
        IOException - an IO exception of this operation
        com.totvs.tjf.storage.ObjectNotFoundException - an object not found exception
      • listObjects

        public String[] listObjects​(String bucketName,
                                    String startsWith,
                                    com.totvs.tjf.storage.Property... properties)
                             throws IOException,
                                    com.totvs.tjf.storage.ObjectNotFoundException
        List object's names based on an optional prefix string
        Specified by:
        listObjects in interface com.totvs.tjf.storage.StorageService
        Parameters:
        bucketName - the bucket's name
        startsWith - a prefix string
        properties - specific connection properties
        Returns:
        string[] a list of object's names
        Throws:
        IOException - an IO exception of this operation
        com.totvs.tjf.storage.ObjectNotFoundException - an object not found exception
      • createDownloadSignedUrl

        public String createDownloadSignedUrl​(String bucketName,
                                              String blobName,
                                              String expiresIn,
                                              com.totvs.tjf.storage.Property... properties)
                                       throws IOException,
                                              com.totvs.tjf.storage.ObjectNotFoundException
        Creates a download signed url
        Specified by:
        createDownloadSignedUrl in interface com.totvs.tjf.storage.StorageService
        Parameters:
        bucketName - the bucket's name
        blobName - the object's name
        properties - specific connection properties
        Returns:
        the signed url
        Throws:
        IOException - an IO exception of this operation
        com.totvs.tjf.storage.ObjectNotFoundException - an object not found exception
      • createDeleteSignedUrl

        public String createDeleteSignedUrl​(String bucketName,
                                            String blobName,
                                            String expiresIn,
                                            com.totvs.tjf.storage.Property... properties)
                                     throws IOException,
                                            com.totvs.tjf.storage.ObjectNotFoundException
        Creates a delete signed url
        Specified by:
        createDeleteSignedUrl in interface com.totvs.tjf.storage.StorageService
        Parameters:
        bucketName - the bucket's name
        blobName - the object's name
        properties - specific connection properties
        Returns:
        string the signed url
        Throws:
        IOException - an IO exception of this operation
        com.totvs.tjf.storage.ObjectNotFoundException - an object not found exception
      • createUploadSignedUrl

        public String createUploadSignedUrl​(String bucketName,
                                            String blobName,
                                            String type,
                                            String expiresIn,
                                            com.totvs.tjf.storage.Property... properties)
                                     throws IOException,
                                            com.totvs.tjf.storage.ObjectNotFoundException
        Creates a upload signed url
        Specified by:
        createUploadSignedUrl in interface com.totvs.tjf.storage.StorageService
        Parameters:
        bucketName - the bucket's name
        blobName - the object's name
        type - the object's mimetype
        properties - specific connection properties
        Returns:
        string the signed url
        Throws:
        IOException - an IO exception of this operation
        com.totvs.tjf.storage.ObjectNotFoundException - an object not found exception