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 StringBLOB_CONVERSION_BLOBprotected static StringBLOB_CONVERSION_KEYprotected static StringBLOB_CONVERSIONS_FACETprotected static StringBLOB_CONVERSIONS_PROPERTYstatic StringCLIENT_ID_PROPstatic StringDEFAULT_EXPORT_MIMETYPEprotected static com.google.api.client.util.ObjectParserJSON_PARSERstatic intPREFERRED_ICON_SIZEstatic StringSERVICE_ACCOUNT_ID_PROPstatic StringSERVICE_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 InputStreamdoGet(LiveConnectFileInfo fileInfo, URI url)Executes a GET request with the user's credentials.protected <T> TexecuteAndCache(String cacheKey, com.google.api.services.drive.DriveRequest<T> request, Class<T> aClass)Executes aDriveRequestand caches the unparsed response.ManagedBlobfreezeVersion(ManagedBlob blob, Document doc)Returns a new managed blob pointing to a fixed version of the original blob.protected StringgetAlternateUrl(ManagedBlob blob)protected com.google.api.services.drive.model.AppgetApp(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 correspondingURIfor a managed blob.protected StringgetCacheName()StringgetClientId()InputStreamgetConvertedStream(ManagedBlob blob, String mimeType, DocumentModel doc)Gets anInputStreamfor a conversion to the given MIME type.protected CredentialFactorygetCredentialFactory()Should be overriden by subclasses needing another credential factory.protected StringgetDownloadUrl(ManagedBlob blob)Gets the URL to which we can redirect to let the user download the file.protected com.google.api.services.drive.model.FilegetDriveFile(LiveConnectFileInfo fileInfo)Retrieves aFileresource and caches the unparsed response.protected StringgetEmbedUrl(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.StringgetPageProviderNameForUpdate()protected com.google.api.services.drive.model.FilegetPartialFile(String user, String fileId, String... fields)Retrieve a partialFileresource.protected com.google.api.services.drive.model.RevisiongetRevision(LiveConnectFileInfo fileInfo)Retrieves aRevisionresource and caches the unparsed response.protected com.google.api.services.drive.model.RevisionListgetRevisionList(LiveConnectFileInfo fileInfo)Retrieves the list ofRevisionresources for a file.protected com.google.api.services.drive.DrivegetService(String user)protected StringgetServiceUser(String username)InputStreamgetStream(ManagedBlob blob)Gets anInputStreamfor the data of a managed blob.protected InputStreamgetStream(ManagedBlob blob, URI uri)protected StringgetStreamUrl(ManagedBlob blob)Gets the URL from which we can stream the content of the file.InputStreamgetThumbnail(ManagedBlob blob)Gets anInputStreamfor a thumbnail of a managed blob.protected StringgetThumbnailUrl(ManagedBlob blob)Gets the URL from which we can stream a thumbnail.URIgetURI(ManagedBlob blob, BlobManager.UsageHint usage, javax.servlet.http.HttpServletRequest servletRequest)Gets anURIfor the content of a managed blob.protected booleanhasChanged(SimpleManagedBlob blob, LiveConnectFile file)Should be overriden by subclasses wanting to rely on a different fields.voidinitialize(String blobProviderId, Map<String,String> properties)Initializes the blob provider.protected BlobretrieveBlobConversion(ManagedBlob blob, String mimeType, DocumentModel doc)Retrieve a stored conversion of the given blobprotected LiveConnectFileretrieveFile(LiveConnectFileInfo fileInfo)Retrieves the file with API.protected voidstoreBlobConversion(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:BlobProviderInitializes the blob provider.- Specified by:
initializein interfaceBlobProvider- Overrides:
initializein classAbstractBlobProvider- Parameters:
blobProviderId- the blob provider id for this binary managerproperties- initialization properties- Throws:
IOException
-
getCacheName
protected String getCacheName()
- Specified by:
getCacheNamein classAbstractLiveConnectBlobProvider<GoogleOAuth2ServiceProvider>
-
getPageProviderNameForUpdate
public String getPageProviderNameForUpdate()
- Specified by:
getPageProviderNameForUpdatein classAbstractLiveConnectBlobProvider<GoogleOAuth2ServiceProvider>
-
getURI
public URI getURI(ManagedBlob blob, BlobManager.UsageHint usage, javax.servlet.http.HttpServletRequest servletRequest) throws IOException
Description copied from interface:BlobProviderGets anURIfor the content of a managed blob.- Parameters:
blob- the managed blobusage-BlobManager.UsageHintservletRequest- the servlet request, ornull- Returns:
- the
URI, ornullif none available - Throws:
IOException
-
getAvailableConversions
public Map<String,URI> getAvailableConversions(ManagedBlob blob, BlobManager.UsageHint hint) throws IOException
Description copied from interface:BlobProviderGets a map of available MIME type conversions and correspondingURIfor 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:BlobProviderGets anInputStreamfor 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
nullif 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:BlobProviderGets anInputStreamfor 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:DocumentBlobProviderGets anInputStreamfor 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
nullif 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:BlobProviderReturns 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:DocumentBlobProviderReturns 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
nullif 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:AbstractLiveConnectBlobProviderShould be overriden by subclasses wanting to rely on a different fields.- Overrides:
hasChangedin classAbstractLiveConnectBlobProvider<GoogleOAuth2ServiceProvider>
-
getCredentialFactory
protected CredentialFactory getCredentialFactory()
Description copied from class:AbstractLiveConnectBlobProviderShould be overriden by subclasses needing another credential factory.- Overrides:
getCredentialFactoryin 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:AbstractLiveConnectBlobProviderRetrieves the file with API.- Specified by:
retrieveFilein 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 partialFileresource.- Throws:
IOException
-
getDriveFile
protected com.google.api.services.drive.model.File getDriveFile(LiveConnectFileInfo fileInfo) throws IOException
Retrieves aFileresource and caches the unparsed response.- Returns:
- a
Fileresource - Throws:
IOException
-
getRevision
protected com.google.api.services.drive.model.Revision getRevision(LiveConnectFileInfo fileInfo) throws IOException
Retrieves aRevisionresource and caches the unparsed response.- Returns:
- a
Revisionresource - Throws:
IOException
-
executeAndCache
protected <T> T executeAndCache(String cacheKey, com.google.api.services.drive.DriveRequest<T> request, Class<T> aClass) throws IOException
Executes aDriveRequestand caches the unparsed response.- Throws:
IOException
-
getRevisionList
protected com.google.api.services.drive.model.RevisionList getRevisionList(LiveConnectFileInfo fileInfo) throws IOException
Retrieves the list ofRevisionresources for a file.- Returns:
- a list of
Revisionresources - 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()
-
-