net.netheos.pcsapi.providers.googledrive
Class GoogleDrive

java.lang.Object
  extended by net.netheos.pcsapi.storage.StorageProvider<OAuth2SessionManager>
      extended by net.netheos.pcsapi.providers.googledrive.GoogleDrive
All Implemented Interfaces:
IStorageProvider

public class GoogleDrive
extends StorageProvider<OAuth2SessionManager>

Implements Google Drive storage provider. Note that OAuth2 refresh token is returned by oauth endpoint only if user approves an offline access. This is the purpose of query parameters "access_type=offline&approval_prompt=force" in authorizeUrl. Beware that old refresh tokens may be invalidated by such requests though : see https://developers.google.com/accounts/docs/OAuth2


Field Summary
static String PROVIDER_NAME
           
 
Fields inherited from class net.netheos.pcsapi.storage.StorageProvider
retryStrategy, sessionManager
 
Constructor Summary
GoogleDrive(StorageBuilder builder)
           
 
Method Summary
 boolean createFolder(CPath path)
          Create a folder at given path, with intermediate folders if needed.
 boolean delete(CPath path)
          Deletes blob, or recursively delete folder at given path.
 void download(CDownloadRequest downloadRequest)
          Downloads a blob from provider to a byte sink, as defined by the download_request object.
 CFile getFile(CPath path)
          Return detailed file information at given path, or None if no object exists at this path
 CQuota getQuota()
          Returns a CQuota object
 String getUserId()
          Return user identifier (login in case of login/password, or email in case of OAuth
 CFolderContent listFolder(CFolder folder)
          Return a map of files present in given CFolder. keys of map are CPath objects, values are CFile objects (CFolder or CBlob).
 CFolderContent listFolder(CPath path)
          Return a map of files present in given CPath. keys of map are CPath objects, values are CFile objects (CFolder or CBlob).
 CFolderContent listRootFolder()
          Equivalent to IStorageProvider.listFolder(net.netheos.pcsapi.models.CPath) with "/"
 void upload(CUploadRequest uploadRequest)
          Uploads a byte source to provider, as defined by upload_request object.
 
Methods inherited from class net.netheos.pcsapi.storage.StorageProvider
close, getProviderName, getSessionManager, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROVIDER_NAME

public static final String PROVIDER_NAME
See Also:
Constant Field Values
Constructor Detail

GoogleDrive

public GoogleDrive(StorageBuilder builder)
Method Detail

getUserId

public String getUserId()
                 throws CStorageException
Description copied from interface: IStorageProvider
Return user identifier (login in case of login/password, or email in case of OAuth

Returns:
user identifier (login in case of login/password, or email in case of OAuth
Throws:
CStorageException - Error getting the user identifier

getQuota

public CQuota getQuota()
                throws CStorageException
Description copied from interface: IStorageProvider
Returns a CQuota object

Returns:
a tuple: used bytes, allowed bytes.
Throws:
CStorageException - Error getting the quota

listRootFolder

public CFolderContent listRootFolder()
                              throws CInvalidFileTypeException
Description copied from interface: IStorageProvider
Equivalent to IStorageProvider.listFolder(net.netheos.pcsapi.models.CPath) with "/"

Returns:
TODO
Throws:
CInvalidFileTypeException

listFolder

public CFolderContent listFolder(CPath path)
                          throws CStorageException
Description copied from interface: IStorageProvider
Return a map of files present in given CPath. keys of map are CPath objects, values are CFile objects (CFolder or CBlob). Return None if no folder exists at given path. Raise CInvalidFileTypeError if given path is a blob. Note : objects in returned map may have incomplete information

Parameters:
path - The folder path
Returns:
a map of files present at given CPath. keys of map are CPath objects, values are CFile objects (CFolder or CBlob). Return null if no folder exists at given path. Throws CInvalidFileTypeError if given path is a blob.
Throws:
CStorageException - Error getting the files in the folder

listFolder

public CFolderContent listFolder(CFolder folder)
                          throws CStorageException
Description copied from interface: IStorageProvider
Return a map of files present in given CFolder. keys of map are CPath objects, values are CFile objects (CFolder or CBlob). Return None if no folder exists at given path. Raise CInvalidFileTypeError if given path is a blob. Note : objects in returned map may have incomplete information

Parameters:
folder - The folder to get the files in
Returns:
a map of files present in given CFolder keys of map are CPath objects, values are CFile objects (CFolder or CBlob). Return null if no folder exists at given path. Note : objects in returned map may have incomplete information.
Throws:
CStorageException - Error getting the files in the folder

createFolder

public boolean createFolder(CPath path)
                     throws CStorageException
Description copied from interface: IStorageProvider
Create a folder at given path, with intermediate folders if needed. Throws CInvalidFileType error if a blob exists at this path.

Parameters:
path - The folder path to create
Returns:
true if folder has been created, false if it was already existing.
Throws:
CStorageException - Error creating the folder

delete

public boolean delete(CPath path)
               throws CStorageException
Description copied from interface: IStorageProvider
Deletes blob, or recursively delete folder at given path.

Parameters:
path - The file path to delete
Returns:
true if at least one file was deleted, false if no object was existing at this path.
Throws:
CStorageException - Error deleting the file

getFile

public CFile getFile(CPath path)
              throws CStorageException
Description copied from interface: IStorageProvider
Return detailed file information at given path, or None if no object exists at this path

Parameters:
path - The file path
Returns:
detailed file information at given path, or null if no object exists at this path
Throws:
CStorageException - Error getting the file

download

public void download(CDownloadRequest downloadRequest)
              throws CStorageException
Description copied from interface: IStorageProvider
Downloads a blob from provider to a byte sink, as defined by the download_request object. Throws CFileNotFoundError if no blob exists at this path. Throws CInvalidFileTypeError if a folder exists at specified path.

Parameters:
downloadRequest - The download request object
Throws:
CStorageException - Download error

upload

public void upload(CUploadRequest uploadRequest)
            throws CStorageException
Description copied from interface: IStorageProvider
Uploads a byte source to provider, as defined by upload_request object. If a blob already exists it is replaced. Throws CInvalidFileTypeError if a folder already exists at specified path.

Parameters:
uploadRequest - The upload resuest object
Throws:
CStorageException - Upload error


Copyright © 2014. All Rights Reserved.