Class GoogleDriveBlobProvider
java.lang.Object
org.nuxeo.ecm.core.blob.AbstractBlobProvider
org.nuxeo.ecm.liveconnect.core.AbstractLiveConnectBlobProvider<GoogleOAuth2ServiceProvider>
org.nuxeo.ecm.liveconnect.google.drive.GoogleDriveBlobProvider
- All Implemented Interfaces:
BlobProvider
,DocumentBlobProvider
,LiveConnectBlobProvider<GoogleOAuth2ServiceProvider>
,BatchUpdateBlobProvider
public class GoogleDriveBlobProvider
extends AbstractLiveConnectBlobProvider<GoogleOAuth2ServiceProvider>
Provider for blobs getting information from Google Drive.
- Since:
- 7.3
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
protected static final String
protected static final String
protected static final String
static final String
static final String
protected static final com.google.api.client.util.ObjectParser
static final int
static final String
static final String
Fields inherited from class org.nuxeo.ecm.core.blob.AbstractBlobProvider
blobProviderId, properties
Fields inherited from interface org.nuxeo.ecm.liveconnect.update.BatchUpdateBlobProvider
MAX_RESULT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected InputStream
doGet
(LiveConnectFileInfo fileInfo, URI url) Executes a GET request with the user's credentials.protected <T> T
executeAndCache
(String cacheKey, com.google.api.services.drive.DriveRequest<T> request, Class<T> aClass) Executes aDriveRequest
and caches the unparsed response.freezeVersion
(ManagedBlob blob, Document doc) Returns a new managed blob pointing to a fixed version of the original blob.protected String
getAlternateUrl
(ManagedBlob blob) protected com.google.api.services.drive.model.App
getAppLinks
(String username, ManagedBlob blob) Returns a list of application links for the given blob.getAvailableConversions
(ManagedBlob blob, BlobManager.UsageHint hint) Gets a map of available MIME type conversions and correspondingURI
for a managed blob.protected String
getConvertedStream
(ManagedBlob blob, String mimeType, DocumentModel doc) Gets anInputStream
for a conversion to the given MIME type.protected CredentialFactory
Should be overriden by subclasses needing another credential factory.protected String
getDownloadUrl
(ManagedBlob blob) Gets the URL to which we can redirect to let the user download the file.protected com.google.api.services.drive.model.File
getDriveFile
(LiveConnectFileInfo fileInfo) Retrieves aFile
resource and caches the unparsed response.protected String
getEmbedUrl
(ManagedBlob blob) Gets the URL to which we can redirect to let the user see a preview of the file.getExportLinks
(ManagedBlob blob) Gets the export link.protected com.google.api.services.drive.model.File
getPartialFile
(String user, String fileId, String... fields) Retrieve a partialFile
resource.protected com.google.api.services.drive.model.Revision
getRevision
(LiveConnectFileInfo fileInfo) Retrieves aRevision
resource and caches the unparsed response.protected com.google.api.services.drive.model.RevisionList
getRevisionList
(LiveConnectFileInfo fileInfo) Retrieves the list ofRevision
resources for a file.protected com.google.api.services.drive.Drive
getService
(String user) protected String
getServiceUser
(String username) getStream
(ManagedBlob blob) Gets anInputStream
for the data of a managed blob.protected InputStream
getStream
(ManagedBlob blob, URI uri) protected String
getStreamUrl
(ManagedBlob blob) Gets the URL from which we can stream the content of the file.getThumbnail
(ManagedBlob blob) Gets anInputStream
for a thumbnail of a managed blob.protected String
getThumbnailUrl
(ManagedBlob blob) Gets the URL from which we can stream a thumbnail.getURI
(ManagedBlob blob, BlobManager.UsageHint usage, javax.servlet.http.HttpServletRequest servletRequest) Gets anURI
for the content of a managed blob.protected boolean
hasChanged
(SimpleManagedBlob blob, LiveConnectFile file) Should be overriden by subclasses wanting to rely on a different fields.void
initialize
(String blobProviderId, Map<String, String> properties) Initializes the blob provider.protected Blob
retrieveBlobConversion
(ManagedBlob blob, String mimeType, DocumentModel doc) Retrieve a stored conversion of the given blobprotected LiveConnectFile
retrieveFile
(LiveConnectFileInfo fileInfo) Retrieves the file with API.protected void
storeBlobConversion
(Document doc, String blobKey, Blob blob) Store a conversion of the given blobMethods inherited from class org.nuxeo.ecm.liveconnect.core.AbstractLiveConnectBlobProvider
asURI, buildBlobKey, checkChangesAndUpdateBlob, close, getCredential, getCredential, getCredential, getFile, getFileFromCache, getFromCache, getOAuth2Provider, invalidateInCache, isVersion, performsExternalAccessControl, processDocumentsUpdate, putFileInCache, putInCache, readBlob, supportsSync, toBlob, toBlob, toFileInfo, toFileInfo, writeBlob
Methods inherited from class org.nuxeo.ecm.core.blob.AbstractBlobProvider
allowByteRange, getProperties, hasCreateFromKeyPermission, isColdStorageMode, isRecordMode, isTransactional, isTransient, supportsUserUpdate, supportsUserUpdateDefaultFalse, supportsUserUpdateDefaultTrue
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.nuxeo.ecm.core.blob.BlobProvider
allowByteRange, allowDirectDownload, canConvert, deleteBlob, getBinaryGarbageCollector, getBinaryManager, getFile, getProperties, getStatus, getStream, hasCreateFromKeyPermission, isColdStorageMode, isRecordMode, isTransactional, isTransient, readBlob, supportsUserUpdate, updateBlob, writeBlob
-
Field Details
-
PREFERRED_ICON_SIZE
public static final int PREFERRED_ICON_SIZE- See Also:
-
SERVICE_ACCOUNT_ID_PROP
- See Also:
-
SERVICE_ACCOUNT_P12_PATH_PROP
- See Also:
-
CLIENT_ID_PROP
- See Also:
-
DEFAULT_EXPORT_MIMETYPE
- See Also:
-
BLOB_CONVERSIONS_FACET
- See Also:
-
BLOB_CONVERSIONS_PROPERTY
- See Also:
-
BLOB_CONVERSION_KEY
- See Also:
-
BLOB_CONVERSION_BLOB
- See Also:
-
JSON_PARSER
protected static final com.google.api.client.util.ObjectParser JSON_PARSER
-
-
Constructor Details
-
GoogleDriveBlobProvider
public GoogleDriveBlobProvider()
-
-
Method Details
-
initialize
Description copied from interface:BlobProvider
Initializes the blob provider.- Specified by:
initialize
in interfaceBlobProvider
- Overrides:
initialize
in classAbstractBlobProvider
- Parameters:
blobProviderId
- the blob provider id for this binary managerproperties
- initialization properties- Throws:
IOException
-
getCacheName
- Specified by:
getCacheName
in classAbstractLiveConnectBlobProvider<GoogleOAuth2ServiceProvider>
-
getPageProviderNameForUpdate
- Specified by:
getPageProviderNameForUpdate
in classAbstractLiveConnectBlobProvider<GoogleOAuth2ServiceProvider>
-
getURI
public URI getURI(ManagedBlob blob, BlobManager.UsageHint usage, javax.servlet.http.HttpServletRequest servletRequest) throws IOException Description copied from interface:BlobProvider
Gets anURI
for the content of a managed blob.- Parameters:
blob
- the managed blobusage
-BlobManager.UsageHint
servletRequest
- the servlet request, ornull
- Returns:
- the
URI
, ornull
if none available - Throws:
IOException
-
getAvailableConversions
public Map<String,URI> getAvailableConversions(ManagedBlob blob, BlobManager.UsageHint hint) throws IOException Description copied from interface:BlobProvider
Gets a map of available MIME type conversions and correspondingURI
for a managed blob.- Parameters:
blob
- the managed blobhint
-BlobManager.UsageHint
- Returns:
- a map of MIME types and
URI
, which may be empty - Throws:
IOException
-
getThumbnail
Description copied from interface:BlobProvider
Gets anInputStream
for a thumbnail of a managed blob.Like all
InputStream
, the result must be closed when done with it to avoid resource leaks.- Parameters:
blob
- the managed blob- Returns:
- the stream
- Throws:
IOException
-
getStreamUrl
Gets the URL from which we can stream the content of the file.Will return
null
if this is a native Google document.- Throws:
IOException
-
getDownloadUrl
Gets the URL to which we can redirect to let the user download the file.- Throws:
IOException
-
getAlternateUrl
- Throws:
IOException
-
getEmbedUrl
Gets the URL to which we can redirect to let the user see a preview of the file.- Throws:
IOException
-
getThumbnailUrl
Gets the URL from which we can stream a thumbnail.- Throws:
IOException
-
getExportLinks
Gets the export link.- Throws:
IOException
-
getStream
Description copied from interface:BlobProvider
Gets anInputStream
for the data of a managed blob.Like all
InputStream
, the result must be closed when done with it to avoid resource leaks.- Parameters:
blob
- the managed blob- Returns:
- the stream
- Throws:
IOException
-
getConvertedStream
public InputStream getConvertedStream(ManagedBlob blob, String mimeType, DocumentModel doc) throws IOException Description copied from interface:DocumentBlobProvider
Gets anInputStream
for a conversion to the given MIME type.Like all
InputStream
, the result must be closed when done with it to avoid resource leaks.- Parameters:
blob
- the managed blobmimeType
- the MIME type to convert todoc
- the document that holds the blob- Returns:
- the stream, or
null
if no conversion is available for the given MIME type - Throws:
IOException
-
getStream
- Throws:
IOException
-
getAppLinks
Description copied from interface:BlobProvider
Returns a list of application links for the given blob.- Throws:
IOException
-
getServiceUser
-
getApp
protected com.google.api.services.drive.model.App getApp(String user, String appId) throws IOException - Throws:
IOException
-
freezeVersion
Description copied from interface:DocumentBlobProvider
Returns a new managed blob pointing to a fixed version of the original blob.- Parameters:
blob
- the original managed blobdoc
- the document that holds the blob- Returns:
- a managed blob with fixed version, or
null
if no change is needed - Throws:
IOException
-
storeBlobConversion
Store a conversion of the given blob -
retrieveBlobConversion
Retrieve a stored conversion of the given blob -
hasChanged
Description copied from class:AbstractLiveConnectBlobProvider
Should be overriden by subclasses wanting to rely on a different fields.- Overrides:
hasChanged
in classAbstractLiveConnectBlobProvider<GoogleOAuth2ServiceProvider>
-
getCredentialFactory
Description copied from class:AbstractLiveConnectBlobProvider
Should be overriden by subclasses needing another credential factory.- Overrides:
getCredentialFactory
in classAbstractLiveConnectBlobProvider<GoogleOAuth2ServiceProvider>
-
getService
- Throws:
IOException
-
retrieveFile
Description copied from class:AbstractLiveConnectBlobProvider
Retrieves the file with API.- Specified by:
retrieveFile
in classAbstractLiveConnectBlobProvider<GoogleOAuth2ServiceProvider>
- Parameters:
fileInfo
- the file info- Returns:
- the file retrieved from API
- Throws:
IOException
-
getPartialFile
protected com.google.api.services.drive.model.File getPartialFile(String user, String fileId, String... fields) throws IOException Retrieve a partialFile
resource.- Throws:
IOException
-
getDriveFile
protected com.google.api.services.drive.model.File getDriveFile(LiveConnectFileInfo fileInfo) throws IOException Retrieves aFile
resource and caches the unparsed response.- Returns:
- a
File
resource - Throws:
IOException
-
getRevision
protected com.google.api.services.drive.model.Revision getRevision(LiveConnectFileInfo fileInfo) throws IOException Retrieves aRevision
resource and caches the unparsed response.- Returns:
- a
Revision
resource - Throws:
IOException
-
executeAndCache
protected <T> T executeAndCache(String cacheKey, com.google.api.services.drive.DriveRequest<T> request, Class<T> aClass) throws IOException Executes aDriveRequest
and caches the unparsed response.- Throws:
IOException
-
getRevisionList
protected com.google.api.services.drive.model.RevisionList getRevisionList(LiveConnectFileInfo fileInfo) throws IOException Retrieves the list ofRevision
resources for a file.- Returns:
- a list of
Revision
resources - Throws:
IOException
-
doGet
Executes a GET request with the user's credentials.- Throws:
IOException
-
getClientId
-