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
Fields Modifier and Type Field Description protected static String
BLOB_CONVERSION_BLOB
protected static String
BLOB_CONVERSION_KEY
protected static String
BLOB_CONVERSIONS_FACET
protected static String
BLOB_CONVERSIONS_PROPERTY
static String
CLIENT_ID_PROP
static String
DEFAULT_EXPORT_MIMETYPE
protected static com.google.api.client.util.ObjectParser
JSON_PARSER
static int
PREFERRED_ICON_SIZE
static String
SERVICE_ACCOUNT_ID_PROP
static String
SERVICE_ACCOUNT_P12_PATH_PROP
-
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
Constructors Constructor Description GoogleDriveBlobProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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.ManagedBlob
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
getApp(String user, String appId)
List<AppLink>
getAppLinks(String username, ManagedBlob blob)
Returns a list of application links for the given blob.Map<String,URI>
getAvailableConversions(ManagedBlob blob, BlobManager.UsageHint hint)
Gets a map of available MIME type conversions and correspondingURI
for a managed blob.protected String
getCacheName()
String
getClientId()
InputStream
getConvertedStream(ManagedBlob blob, String mimeType, DocumentModel doc)
Gets anInputStream
for a conversion to the given MIME type.protected CredentialFactory
getCredentialFactory()
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.protected Map<String,String>
getExportLinks(ManagedBlob blob)
Gets the export link.String
getPageProviderNameForUpdate()
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)
InputStream
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.InputStream
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.URI
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 blob-
Methods 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 Detail
-
PREFERRED_ICON_SIZE
public static final int PREFERRED_ICON_SIZE
- See Also:
- Constant Field Values
-
SERVICE_ACCOUNT_ID_PROP
public static final String SERVICE_ACCOUNT_ID_PROP
- See Also:
- Constant Field Values
-
SERVICE_ACCOUNT_P12_PATH_PROP
public static final String SERVICE_ACCOUNT_P12_PATH_PROP
- See Also:
- Constant Field Values
-
CLIENT_ID_PROP
public static final String CLIENT_ID_PROP
- See Also:
- Constant Field Values
-
DEFAULT_EXPORT_MIMETYPE
public static final String DEFAULT_EXPORT_MIMETYPE
- See Also:
- Constant Field Values
-
BLOB_CONVERSIONS_FACET
protected static final String BLOB_CONVERSIONS_FACET
- See Also:
- Constant Field Values
-
BLOB_CONVERSIONS_PROPERTY
protected static final String BLOB_CONVERSIONS_PROPERTY
- See Also:
- Constant Field Values
-
BLOB_CONVERSION_KEY
protected static final String BLOB_CONVERSION_KEY
- See Also:
- Constant Field Values
-
BLOB_CONVERSION_BLOB
protected static final String BLOB_CONVERSION_BLOB
- See Also:
- Constant Field Values
-
JSON_PARSER
protected static final com.google.api.client.util.ObjectParser JSON_PARSER
-
-
Method Detail
-
initialize
public void initialize(String blobProviderId, Map<String,String> properties) throws IOException
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
protected String getCacheName()
- Specified by:
getCacheName
in classAbstractLiveConnectBlobProvider<GoogleOAuth2ServiceProvider>
-
getPageProviderNameForUpdate
public String 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
public InputStream getThumbnail(ManagedBlob blob) throws IOException
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
protected String getStreamUrl(ManagedBlob blob) throws IOException
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
protected String getDownloadUrl(ManagedBlob blob) throws IOException
Gets the URL to which we can redirect to let the user download the file.- Throws:
IOException
-
getAlternateUrl
protected String getAlternateUrl(ManagedBlob blob) throws IOException
- Throws:
IOException
-
getEmbedUrl
protected String getEmbedUrl(ManagedBlob blob) throws IOException
Gets the URL to which we can redirect to let the user see a preview of the file.- Throws:
IOException
-
getThumbnailUrl
protected String getThumbnailUrl(ManagedBlob blob) throws IOException
Gets the URL from which we can stream a thumbnail.- Throws:
IOException
-
getExportLinks
protected Map<String,String> getExportLinks(ManagedBlob blob) throws IOException
Gets the export link.- Throws:
IOException
-
getStream
public InputStream getStream(ManagedBlob blob) throws IOException
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
protected InputStream getStream(ManagedBlob blob, URI uri) throws IOException
- Throws:
IOException
-
getAppLinks
public List<AppLink> getAppLinks(String username, ManagedBlob blob) throws IOException
Description copied from interface:BlobProvider
Returns a list of application links for the given blob.- Throws:
IOException
-
getApp
protected com.google.api.services.drive.model.App getApp(String user, String appId) throws IOException
- Throws:
IOException
-
freezeVersion
public ManagedBlob freezeVersion(ManagedBlob blob, Document doc) throws IOException
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
protected void storeBlobConversion(Document doc, String blobKey, Blob blob)
Store a conversion of the given blob
-
retrieveBlobConversion
protected Blob retrieveBlobConversion(ManagedBlob blob, String mimeType, DocumentModel doc)
Retrieve a stored conversion of the given blob
-
hasChanged
protected boolean hasChanged(SimpleManagedBlob blob, LiveConnectFile file)
Description copied from class:AbstractLiveConnectBlobProvider
Should be overriden by subclasses wanting to rely on a different fields.- Overrides:
hasChanged
in classAbstractLiveConnectBlobProvider<GoogleOAuth2ServiceProvider>
-
getCredentialFactory
protected CredentialFactory getCredentialFactory()
Description copied from class:AbstractLiveConnectBlobProvider
Should be overriden by subclasses needing another credential factory.- Overrides:
getCredentialFactory
in classAbstractLiveConnectBlobProvider<GoogleOAuth2ServiceProvider>
-
getService
protected com.google.api.services.drive.Drive getService(String user) throws IOException
- Throws:
IOException
-
retrieveFile
protected LiveConnectFile retrieveFile(LiveConnectFileInfo fileInfo) throws IOException
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
protected InputStream doGet(LiveConnectFileInfo fileInfo, URI url) throws IOException
Executes a GET request with the user's credentials.- Throws:
IOException
-
getClientId
public String getClientId()
-
-