Class DriveTemplate
- java.lang.Object
-
- org.springframework.social.google.api.impl.AbstractGoogleApiOperations
-
- org.springframework.social.google.api.drive.impl.DriveTemplate
-
- All Implemented Interfaces:
DriveOperations
public class DriveTemplate extends AbstractGoogleApiOperations implements DriveOperations
DriveOperationsimplementation.- Author:
- Gabriel Axel
-
-
Field Summary
-
Fields inherited from class org.springframework.social.google.api.impl.AbstractGoogleApiOperations
isAuthorized, restTemplate
-
-
Constructor Summary
Constructors Constructor Description DriveTemplate(org.springframework.web.client.RestTemplate restTemplate, boolean isAuthorized)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FileCommentaddComment(String fileId, FileComment comment)Adds a comment to a fileUserPermissionaddPermission(String fileId, UserPermission permission, boolean sendNotificationEmails)Adds a permission to a fileFilePropertyaddProperty(String fileId, FileProperty property)Adds a new property to a fileCommentReplyaddReply(String fileId, String commentId, CommentReply reply)Adds a reply to a file commentDriveFilecopy(String id)Create a copy of a fileDriveFilecopy(String id, String[] parentIds)Create a copy of a fileDriveFilecopy(String id, String[] parentIds, String title)Create a copy of a fileDriveFilecreateFileMetadata(DriveFile metadata)Creates an empty file with metadataDriveFilecreateFolder(String parentId, String name)Creates a foldervoiddelete(String id)Permanently deletes a fileorg.springframework.core.io.ResourcedownloadFile(String id)Downloads a file from Google Drive.org.springframework.core.io.ResourcedownloadFile(DriveFile file)Downloads a file from Google Drive.DriveFileQueryBuilderdriveFileQuery()Creates aDriveFileQueryBuilderFileCommentQueryBuilderfileCommentQueryBuilder(String fileId)Returns aFileCommentQueryBuilderfor listing the comments of a fileDriveAboutgetAbout()Get general Google Drive details for the current userDriveAppgetApp(String id)Returns an application by its IDList<DriveApp>getApps()Returns the applications authorized by the user to access Google Drive APIFileCommentsPagegetComments(String fileId, String pageToken)Returns the first default page of comments on a fileDriveFilegetFile(String id)Retrieves a file by its IDDriveFilesPagegetFiles(String parent, String pageToken)Returns the files and folders under a specified folderList<UserPermission>getPermissions(String fileId)Returns the permissions of a fileList<FileProperty>getProperties(String fileId)Get the custom properties applied to this fileFilePropertygetProperty(String fileId, String propertyKey)Get a specific custom property applied to this fileList<FileRevision>getRevisions(String fileId)Returns the revisions of a fileDriveFilesPagegetRootFiles(String pageToken)Returns files and folders under the root folderDriveFilesPagegetTrashedFiles(String pageToken)Returns trashed files and foldersDriveFilehide(String id)Hides a fileDriveFilemove(String id, String parentId)Move a file into a different foldervoidremoveComment(String fileId, String commentId)Removes a comment from a filevoidremovePermission(String fileId, String permissionId)Removes a permission from a filevoidremoveProperty(String fileId, String propertyKey)Deletes a propertyvoidremoveReply(String fileId, String commentId, String replyId)Removes a reply from a file commentDriveFilestar(String id)Stars a fileDriveFiletrash(String id)Moves a file to trashDriveFileunhide(String id)Unhides a fileDriveFileunstar(String id)Remove the star from a fileDriveFileuntrash(String id)Restores a file from trashFileCommentupdateComment(String fileId, String commentId, FileComment comment)Updates a comment to a fileFilePropertyupdateProperty(String fileId, FileProperty property)Updates a propertyCommentReplyupdateReply(String fileId, String commentId, String replyId, CommentReply reply)Updates a reply to a file commentFileRevisionupdateRevision(String fileId, String revisionId, FileRevision revision)Updates a file revisionUserPermissionupdatesPermission(String fileId, String permissionId, UserPermission permission)Updates a permission to a fileDriveFileupload(org.springframework.core.io.Resource resource, DriveFile metadata, UploadParameters parameters)Uploads a file using multipart-
Methods inherited from class org.springframework.social.google.api.impl.AbstractGoogleApiOperations
deleteEntity, deleteEntity, getEntity, patch, requireAuthorization, saveEntity
-
-
-
-
Method Detail
-
getAbout
public DriveAbout getAbout()
Description copied from interface:DriveOperationsGet general Google Drive details for the current user- Specified by:
getAboutin interfaceDriveOperations- Returns:
DriveAboutwith details for the current user
-
getApps
public List<DriveApp> getApps()
Description copied from interface:DriveOperationsReturns the applications authorized by the user to access Google Drive API- Specified by:
getAppsin interfaceDriveOperations- Returns:
- List of
DriveAppfor the current user
-
getApp
public DriveApp getApp(String id)
Description copied from interface:DriveOperationsReturns an application by its ID- Specified by:
getAppin interfaceDriveOperations- Parameters:
id- The ID of the application- Returns:
DriveAppmatching the ID
-
getFile
public DriveFile getFile(String id)
Description copied from interface:DriveOperationsRetrieves a file by its ID- Specified by:
getFilein interfaceDriveOperations- Parameters:
id- the ID to retrieve by- Returns:
DriveFilematching the ID
-
driveFileQuery
public DriveFileQueryBuilder driveFileQuery()
Description copied from interface:DriveOperationsCreates aDriveFileQueryBuilder- Specified by:
driveFileQueryin interfaceDriveOperations- Returns:
- a new
DriveFileQueryBuilder
-
getRootFiles
public DriveFilesPage getRootFiles(String pageToken)
Description copied from interface:DriveOperationsReturns files and folders under the root folder- Specified by:
getRootFilesin interfaceDriveOperations- Parameters:
pageToken- Page token or null- Returns:
DriveFilesPage
-
getFiles
public DriveFilesPage getFiles(String parent, String pageToken)
Description copied from interface:DriveOperationsReturns the files and folders under a specified folder- Specified by:
getFilesin interfaceDriveOperations- Parameters:
parent- folder ID or "root"pageToken- Page token or null- Returns:
DriveFilesPage
-
getTrashedFiles
public DriveFilesPage getTrashedFiles(String pageToken)
Description copied from interface:DriveOperationsReturns trashed files and folders- Specified by:
getTrashedFilesin interfaceDriveOperations- Parameters:
pageToken- Page token or null- Returns:
DriveFilesPage
-
trash
public DriveFile trash(String id)
Description copied from interface:DriveOperationsMoves a file to trash- Specified by:
trashin interfaceDriveOperations- Parameters:
id- The ID of the file to trash- Returns:
- The updated
DriveFile
-
untrash
public DriveFile untrash(String id)
Description copied from interface:DriveOperationsRestores a file from trash- Specified by:
untrashin interfaceDriveOperations- Parameters:
id- The ID of the file to untrash return The updatedDriveFile- Returns:
- The trashed
DriveFile
-
star
public DriveFile star(String id)
Description copied from interface:DriveOperationsStars a file- Specified by:
starin interfaceDriveOperations- Parameters:
id- The ID of the file to star- Returns:
- The updated
DriveFile
-
unstar
public DriveFile unstar(String id)
Description copied from interface:DriveOperationsRemove the star from a file- Specified by:
unstarin interfaceDriveOperations- Parameters:
id- The ID of the file to unstar- Returns:
- The updated
DriveFile
-
hide
public DriveFile hide(String id)
Description copied from interface:DriveOperationsHides a file- Specified by:
hidein interfaceDriveOperations- Parameters:
id- The ID of the file to hide- Returns:
- The updated
DriveFile
-
unhide
public DriveFile unhide(String id)
Description copied from interface:DriveOperationsUnhides a file- Specified by:
unhidein interfaceDriveOperations- Parameters:
id- The ID of the file to unhide- Returns:
- The updated
DriveFile
-
delete
public void delete(String id)
Description copied from interface:DriveOperationsPermanently deletes a file- Specified by:
deletein interfaceDriveOperations- Parameters:
id- The ID of the file to delete
-
copy
public DriveFile copy(String id)
Description copied from interface:DriveOperationsCreate a copy of a file- Specified by:
copyin interfaceDriveOperations- Parameters:
id- The ID of the source file- Returns:
- The newly-created
DriveFilecopy
-
copy
public DriveFile copy(String id, String[] parentIds)
Description copied from interface:DriveOperationsCreate a copy of a file- Specified by:
copyin interfaceDriveOperations- Parameters:
id- The ID of the source fileparentIds- Array of parent folder ID to place the file into, or "root"- Returns:
- The newly-created
DriveFilecopy
-
copy
public DriveFile copy(String id, String[] parentIds, String title)
Description copied from interface:DriveOperationsCreate a copy of a file- Specified by:
copyin interfaceDriveOperations- Parameters:
id- The ID of the source fileparentIds- Array of parent folder ID to place the file into, or "root"title- The title to apply to the new file- Returns:
- The newly-created
DriveFilecopy
-
move
public DriveFile move(String id, String parentId)
Description copied from interface:DriveOperationsMove a file into a different folder- Specified by:
movein interfaceDriveOperations- Parameters:
id- The ID of the file to moveparentId- The parent folder ID to move the file to, or "root"- Returns:
- The updated
DriveFile
-
upload
public DriveFile upload(org.springframework.core.io.Resource resource, DriveFile metadata, UploadParameters parameters)
Description copied from interface:DriveOperationsUploads a file using multipart- Specified by:
uploadin interfaceDriveOperations- Parameters:
resource- Reference to the file's contentmetadata- The file's metadataparameters- Parameters for uploading and processing the file- Returns:
- The file resource that was created
-
createFileMetadata
public DriveFile createFileMetadata(DriveFile metadata)
Description copied from interface:DriveOperationsCreates an empty file with metadata- Specified by:
createFileMetadatain interfaceDriveOperations- Parameters:
metadata- The file's properties- Returns:
DriveFilerepresenting the created file
-
createFolder
public DriveFile createFolder(String parentId, String name)
Description copied from interface:DriveOperationsCreates a folder- Specified by:
createFolderin interfaceDriveOperations- Parameters:
parentId- The parent folder ID or "root"name- The name of the folder to create- Returns:
DriveFilerepresenting the created folder
-
getPermissions
public List<UserPermission> getPermissions(String fileId)
Description copied from interface:DriveOperationsReturns the permissions of a file- Specified by:
getPermissionsin interfaceDriveOperations- Parameters:
fileId- The ID of the file- Returns:
- List of
UserPermissionfor the file
-
addPermission
public UserPermission addPermission(String fileId, UserPermission permission, boolean sendNotificationEmails)
Description copied from interface:DriveOperationsAdds a permission to a file- Specified by:
addPermissionin interfaceDriveOperations- Parameters:
fileId- The file IDpermission-UserPermissionwith the permission settingssendNotificationEmails- Whether to send notification e-mails- Returns:
- The created
UserPermission
-
updatesPermission
public UserPermission updatesPermission(String fileId, String permissionId, UserPermission permission)
Description copied from interface:DriveOperationsUpdates a permission to a file- Specified by:
updatesPermissionin interfaceDriveOperations- Parameters:
fileId- The file IDpermissionId- the ID of the permissionpermission-UserPermissionwith new role and additionalRoles properties- Returns:
- The updated
UserPermission
-
removePermission
public void removePermission(String fileId, String permissionId)
Description copied from interface:DriveOperationsRemoves a permission from a file- Specified by:
removePermissionin interfaceDriveOperations- Parameters:
fileId- The file IDpermissionId- The ID of the permission
-
getRevisions
public List<FileRevision> getRevisions(String fileId)
Description copied from interface:DriveOperationsReturns the revisions of a file- Specified by:
getRevisionsin interfaceDriveOperations- Parameters:
fileId- The ID of the file- Returns:
- List of
FileRevision
-
updateRevision
public FileRevision updateRevision(String fileId, String revisionId, FileRevision revision)
Description copied from interface:DriveOperationsUpdates a file revision- Specified by:
updateRevisionin interfaceDriveOperations- Parameters:
fileId- The ID of the filerevisionId- The ID of the revisionrevision-FileRevisionwith new pinned, publishAuto, published and publishedOutsideDomain properties- Returns:
- The updated
FileRevision
-
fileCommentQueryBuilder
public FileCommentQueryBuilder fileCommentQueryBuilder(String fileId)
Description copied from interface:DriveOperationsReturns aFileCommentQueryBuilderfor listing the comments of a file- Specified by:
fileCommentQueryBuilderin interfaceDriveOperations- Parameters:
fileId- The ID of the file- Returns:
FileCommentQueryBuilderfor the file
-
getComments
public FileCommentsPage getComments(String fileId, String pageToken)
Description copied from interface:DriveOperationsReturns the first default page of comments on a file- Specified by:
getCommentsin interfaceDriveOperations- Parameters:
fileId- The ID of the filepageToken- Page token or null- Returns:
- Page of comments
-
addComment
public FileComment addComment(String fileId, FileComment comment)
Description copied from interface:DriveOperationsAdds a comment to a file- Specified by:
addCommentin interfaceDriveOperations- Parameters:
fileId- The ID of the filecomment- The new comment- Returns:
- The created
FileComment
-
updateComment
public FileComment updateComment(String fileId, String commentId, FileComment comment)
Description copied from interface:DriveOperationsUpdates a comment to a file- Specified by:
updateCommentin interfaceDriveOperations- Parameters:
fileId- The ID of the filecommentId- The ID of the commentcomment- Comment with the new content- Returns:
- The updated
FileComment
-
removeComment
public void removeComment(String fileId, String commentId)
Description copied from interface:DriveOperationsRemoves a comment from a file- Specified by:
removeCommentin interfaceDriveOperations- Parameters:
fileId- The ID of the filecommentId- The ID of the comment
-
addReply
public CommentReply addReply(String fileId, String commentId, CommentReply reply)
Description copied from interface:DriveOperationsAdds a reply to a file comment- Specified by:
addReplyin interfaceDriveOperations- Parameters:
fileId- The ID of the filecommentId- The ID of the commentreply- The new reply- Returns:
- The created
CommentReply
-
updateReply
public CommentReply updateReply(String fileId, String commentId, String replyId, CommentReply reply)
Description copied from interface:DriveOperationsUpdates a reply to a file comment- Specified by:
updateReplyin interfaceDriveOperations- Parameters:
fileId- The ID of the filecommentId- The ID of the commentreplyId- The ID of the replyreply- Reply with new content- Returns:
- The updated
CommentReply
-
removeReply
public void removeReply(String fileId, String commentId, String replyId)
Description copied from interface:DriveOperationsRemoves a reply from a file comment- Specified by:
removeReplyin interfaceDriveOperations- Parameters:
fileId- The ID of the filecommentId- The ID of the commentreplyId- The ID of the reply
-
downloadFile
public org.springframework.core.io.Resource downloadFile(String id)
Description copied from interface:DriveOperationsDownloads a file from Google Drive. This method first sends a request to get the download URL, and then another request to download the file.- Specified by:
downloadFilein interfaceDriveOperations- Parameters:
id- The file ID- Returns:
- Resource abstraction for the file
-
downloadFile
public org.springframework.core.io.Resource downloadFile(DriveFile file)
Description copied from interface:DriveOperationsDownloads a file from Google Drive. This method usesDriveFile.getDownloadUrl(), which may have expired since the file metadata was fetched.- Specified by:
downloadFilein interfaceDriveOperations- Parameters:
file- The file metadata- Returns:
- Resource abstraction for the file
-
getProperties
public List<FileProperty> getProperties(String fileId)
Description copied from interface:DriveOperationsGet the custom properties applied to this file- Specified by:
getPropertiesin interfaceDriveOperations- Parameters:
fileId- The ID of the file- Returns:
- The list of properties defined
-
getProperty
public FileProperty getProperty(String fileId, String propertyKey)
Description copied from interface:DriveOperationsGet a specific custom property applied to this file- Specified by:
getPropertyin interfaceDriveOperations- Parameters:
fileId- The ID of the filepropertyKey- The key of the property- Returns:
- The the property information
-
addProperty
public FileProperty addProperty(String fileId, FileProperty property)
Description copied from interface:DriveOperationsAdds a new property to a file- Specified by:
addPropertyin interfaceDriveOperations- Parameters:
fileId- The ID of the fileproperty- Property representation- Returns:
- The new
FileProperty
-
updateProperty
public FileProperty updateProperty(String fileId, FileProperty property)
Description copied from interface:DriveOperationsUpdates a property- Specified by:
updatePropertyin interfaceDriveOperations- Parameters:
fileId- The ID of the fileproperty- Property representation- Returns:
- The updated
FileProperty
-
removeProperty
public void removeProperty(String fileId, String propertyKey)
Description copied from interface:DriveOperationsDeletes a property- Specified by:
removePropertyin interfaceDriveOperations- Parameters:
fileId- The ID of the filepropertyKey- The key of the property
-
-