public class GoogleDriveBlobProvider extends AbstractBlobProvider implements BatchUpdateBlobProvider
Modifier and Type | Class and Description |
---|---|
static class |
GoogleDriveBlobProvider.FileInfo
Information about a file stored in Google Drive.
|
Modifier and Type | Field and 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 |
blobProviderId, properties
MAX_RESULT
Constructor and Description |
---|
GoogleDriveBlobProvider() |
Modifier and Type | Method and Description |
---|---|
protected static URI |
asURI(String link)
Parse a
URI . |
List<DocumentModel> |
checkChangesAndUpdateBlob(List<DocumentModel> docs)
Check the given list of document for change and update if needed.
|
void |
close()
Closes this blob provider and releases resources that may be held by it.
|
protected InputStream |
doGet(String user,
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 a
DriveRequest 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 corresponding
URI for a managed blob. |
protected ManagedBlob |
getBlob(GoogleDriveBlobProvider.FileInfo fileInfo)
Gets the blob for a Google Drive file.
|
String |
getBlobProviderId() |
protected Cache |
getCache() |
String |
getClientId() |
InputStream |
getConvertedStream(ManagedBlob blob,
String mimeType,
DocumentModel doc)
Gets an
InputStream for a conversion to the given MIME type. |
protected com.google.api.client.auth.oauth2.Credential |
getCredential(String user) |
protected CredentialFactory |
getCredentialFactory() |
protected String |
getDigest(com.google.api.services.drive.model.File file) |
protected String |
getDownloadUrl(ManagedBlob blob)
Gets the URL to which we can redirect to let the user download the file.
|
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.
|
protected com.google.api.services.drive.model.File |
getFile(GoogleDriveBlobProvider.FileInfo fileInfo)
Retrieves a
File resource and caches the unparsed response. |
protected GoogleDriveBlobProvider.FileInfo |
getFileInfo(ManagedBlob blob)
Removes the prefix from the key.
|
protected String |
getKey(GoogleDriveBlobProvider.FileInfo fileInfo)
Adds the prefix to the key.
|
protected OAuth2ServiceProvider |
getOAuth2Provider() |
String |
getPageProviderNameForUpdate() |
protected com.google.api.services.drive.model.File |
getPartialFile(String user,
String fileId,
String... fields)
Retrieve a partial
File resource. |
protected com.google.api.services.drive.model.Revision |
getRevision(GoogleDriveBlobProvider.FileInfo fileInfo)
Retrieves a
Revision resource and caches the unparsed response. |
protected com.google.api.services.drive.model.RevisionList |
getRevisionList(GoogleDriveBlobProvider.FileInfo fileInfo)
Retrieves the list of
Revision resources for a file. |
protected com.google.api.services.drive.Drive |
getService(String user) |
protected String |
getServiceUser(String username) |
InputStream |
getStream(ManagedBlob blob)
Gets an
InputStream 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 an
InputStream 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 an
URI for the content of a managed blob. |
void |
initialize(String blobProviderId,
Map<String,String> properties)
Initializes the blob provider.
|
protected boolean |
isChanged(Blob blob,
com.google.api.services.drive.model.File file) |
protected boolean |
isDigestChanged(Blob blob,
com.google.api.services.drive.model.File file) |
protected boolean |
isFilenameChanged(Blob blob,
com.google.api.services.drive.model.File file) |
boolean |
isVersion(ManagedBlob blob)
Returns true if version of the blob is a version.
|
Blob |
readBlob(BlobManager.BlobInfo blobInfo)
Reads a
Blob from storage. |
protected Blob |
retrieveBlobConversion(ManagedBlob blob,
String mimeType,
DocumentModel doc)
Retrieve a stored conversion of the given blob
|
protected void |
storeBlobConversion(Document doc,
String blobKey,
Blob blob)
Store a conversion of the given blob
|
boolean |
supportsUserUpdate()
Checks if user update is supported.
|
String |
writeBlob(Blob blob,
Document doc)
Writes a
Blob to storage and returns information about it. |
supportsUserUpdateDefaultFalse, supportsUserUpdateDefaultTrue
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
processDocumentsUpdate
getBinaryManager
public static final int PREFERRED_ICON_SIZE
public static final String SERVICE_ACCOUNT_ID_PROP
public static final String SERVICE_ACCOUNT_P12_PATH_PROP
public static final String CLIENT_ID_PROP
public static final String DEFAULT_EXPORT_MIMETYPE
protected static final String BLOB_CONVERSIONS_FACET
protected static final String BLOB_CONVERSIONS_PROPERTY
protected static final String BLOB_CONVERSION_KEY
protected static final String BLOB_CONVERSION_BLOB
protected static final com.google.api.client.util.ObjectParser JSON_PARSER
public GoogleDriveBlobProvider()
public void initialize(String blobProviderId, Map<String,String> properties) throws IOException
BlobProvider
initialize
in interface BlobProvider
initialize
in class AbstractBlobProvider
blobProviderId
- the blob provider id for this binary managerproperties
- initialization propertiesIOException
public void close()
BlobProvider
close
in interface BlobProvider
public Blob readBlob(BlobManager.BlobInfo blobInfo)
BlobProvider
Blob
from storage.readBlob
in interface BlobProvider
blobInfo
- the blob informationpublic boolean supportsUserUpdate()
BlobProvider
A user update refers to the fact that a blob from this provider may be overwritten with another blob, wherever the original blob may occur (usually in a document property).
supportsUserUpdate
in interface BlobProvider
supportsUserUpdate
in class AbstractBlobProvider
true
if user update is supportedpublic String writeBlob(Blob blob, Document doc)
BlobProvider
Blob
to storage and returns information about it.
Called to store a user-created blob.
writeBlob
in interface BlobProvider
blob
- the blobdoc
- the document to which this blob belongspublic URI getURI(ManagedBlob blob, BlobManager.UsageHint usage, javax.servlet.http.HttpServletRequest servletRequest) throws IOException
BlobProvider
URI
for the content of a managed blob.getURI
in interface BlobProvider
blob
- the managed blobusage
- BlobManager.UsageHint
servletRequest
- the servlet request, or null
URI
, or null
if none availableIOException
public Map<String,URI> getAvailableConversions(ManagedBlob blob, BlobManager.UsageHint hint) throws IOException
BlobProvider
URI
for a managed blob.getAvailableConversions
in interface BlobProvider
blob
- the managed blobhint
- BlobManager.UsageHint
URI
, which may be emptyIOException
public InputStream getThumbnail(ManagedBlob blob) throws IOException
BlobProvider
InputStream
for a thumbnail of a managed blob.
Like all InputStream
, the result must be closed when done with it to avoid resource leaks.
getThumbnail
in interface BlobProvider
blob
- the managed blobIOException
protected String getStreamUrl(ManagedBlob blob) throws IOException
Will return null
if this is a native Google document.
IOException
protected String getDownloadUrl(ManagedBlob blob) throws IOException
IOException
protected String getAlternateUrl(ManagedBlob blob) throws IOException
IOException
protected String getEmbedUrl(ManagedBlob blob) throws IOException
IOException
protected String getThumbnailUrl(ManagedBlob blob) throws IOException
IOException
protected Map<String,String> getExportLinks(ManagedBlob blob) throws IOException
IOException
public InputStream getStream(ManagedBlob blob) throws IOException
BlobProvider
InputStream
for the data of a managed blob.
Like all InputStream
, the result must be closed when done with it to avoid resource leaks.
getStream
in interface BlobProvider
blob
- the managed blobIOException
public InputStream getConvertedStream(ManagedBlob blob, String mimeType, DocumentModel doc) throws IOException
BlobProvider
InputStream
for a conversion to the given MIME type.
Like all InputStream
, the result must be closed when done with it to avoid resource leaks.
getConvertedStream
in interface BlobProvider
blob
- the managed blobmimeType
- the MIME type to convert todoc
- the document that holds the blobnull
if no conversion is available for the given MIME typeIOException
protected InputStream getStream(ManagedBlob blob, URI uri) throws IOException
IOException
public List<AppLink> getAppLinks(String username, ManagedBlob blob) throws IOException
BlobProvider
getAppLinks
in interface BlobProvider
IOException
protected String getServiceUser(String username)
protected com.google.api.services.drive.model.App getApp(String user, String appId) throws IOException
IOException
public ManagedBlob freezeVersion(ManagedBlob blob, Document doc) throws IOException
BlobProvider
freezeVersion
in interface BlobProvider
blob
- the original managed blobdoc
- the document that holds the blobnull
if no change is neededIOException
protected void storeBlobConversion(Document doc, String blobKey, Blob blob)
protected Blob retrieveBlobConversion(ManagedBlob blob, String mimeType, DocumentModel doc)
protected ManagedBlob getBlob(GoogleDriveBlobProvider.FileInfo fileInfo) throws IOException
fileInfo
- the file infoIOException
protected boolean isDigestChanged(Blob blob, com.google.api.services.drive.model.File file)
protected boolean isFilenameChanged(Blob blob, com.google.api.services.drive.model.File file)
protected String getKey(GoogleDriveBlobProvider.FileInfo fileInfo)
protected GoogleDriveBlobProvider.FileInfo getFileInfo(ManagedBlob blob)
protected com.google.api.client.auth.oauth2.Credential getCredential(String user) throws IOException
IOException
protected CredentialFactory getCredentialFactory()
protected com.google.api.services.drive.Drive getService(String user) throws IOException
IOException
protected com.google.api.services.drive.model.File getPartialFile(String user, String fileId, String... fields) throws IOException
File
resource.IOException
protected com.google.api.services.drive.model.File getFile(GoogleDriveBlobProvider.FileInfo fileInfo) throws IOException
File
resource and caches the unparsed response.File
resourceIOException
protected com.google.api.services.drive.model.Revision getRevision(GoogleDriveBlobProvider.FileInfo fileInfo) throws IOException
Revision
resource and caches the unparsed response.Revision
resourceIOException
protected <T> T executeAndCache(String cacheKey, com.google.api.services.drive.DriveRequest<T> request, Class<T> aClass) throws IOException
DriveRequest
and caches the unparsed response.IOException
protected com.google.api.services.drive.model.RevisionList getRevisionList(GoogleDriveBlobProvider.FileInfo fileInfo) throws IOException
Revision
resources for a file.Revision
resourcesIOException
protected InputStream doGet(String user, URI url) throws IOException
IOException
public String getClientId()
protected OAuth2ServiceProvider getOAuth2Provider()
public List<DocumentModel> checkChangesAndUpdateBlob(List<DocumentModel> docs)
BatchUpdateBlobProvider
checkChangesAndUpdateBlob
in interface BatchUpdateBlobProvider
public String getPageProviderNameForUpdate()
getPageProviderNameForUpdate
in interface BatchUpdateBlobProvider
public String getBlobProviderId()
getBlobProviderId
in interface BatchUpdateBlobProvider
public boolean isVersion(ManagedBlob blob)
BlobProvider
isVersion
in interface BlobProvider
blob
- the managed blobCopyright © 2015 Nuxeo SA. All rights reserved.