Class JCRLocalGoogleDrive

  • All Implemented Interfaces:
    org.exoplatform.services.cms.clouddrives.CloudDriveSecurity, org.exoplatform.services.cms.clouddrives.CloudDriveStorage, org.exoplatform.services.cms.clouddrives.oauth2.UserTokenRefreshListener

    public class JCRLocalGoogleDrive
    extends org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive
    implements org.exoplatform.services.cms.clouddrives.oauth2.UserTokenRefreshListener
    JCR local storage for Google Drive. Created by The eXo Platform SAS.
    Version:
    $Id: JCRLocalGoogleDrive.java 00000 Sep 13, 2012 pnedonosko $
    Author:
    Peter Nedonosko
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  JCRLocalGoogleDrive.Connect
      Connect algorithm for Google Drive.
      protected class  JCRLocalGoogleDrive.FileAPI
      The Class FileAPI.
      protected class  JCRLocalGoogleDrive.Sync
      Sync algorithm for Google Drive.
      • Nested classes/interfaces inherited from class org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive

        org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.AbstractCommand, org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.AbstractFileAPI, org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.CommandCallable, org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.ConnectCommand, org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.DriveState, org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.ExoJCREnvironment, org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.ExoJCRSettings, org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.FileChange, org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.JCRListener, org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.NoConnectCommand, org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.NoSyncCommand, org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.SyncCommand, org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.SyncFilesCommand
      • Nested classes/interfaces inherited from class org.exoplatform.services.cms.clouddrives.CloudDrive

        org.exoplatform.services.cms.clouddrives.CloudDrive.Command, org.exoplatform.services.cms.clouddrives.CloudDrive.CommandProgress, org.exoplatform.services.cms.clouddrives.CloudDrive.FilesState, org.exoplatform.services.cms.clouddrives.CloudDrive.ListenerSupport
      • Nested classes/interfaces inherited from interface org.exoplatform.services.cms.clouddrives.CloudDriveStorage

        org.exoplatform.services.cms.clouddrives.CloudDriveStorage.Change<R extends Object>
    • Field Summary

      • Fields inherited from class org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive

        accentsConverter, actionDrive, ALREADY_DONE, COMMAND_CHANGES_CHUNK, commandEnv, CURRENT_LOCALFORMAT, currentChangeId, currentConnect, currentSync, delayedSyncFiles, driveCommands, DUMMY_DATA, ECD_CLOUDDRIVE, ECD_CLOUDFILE, ECD_CLOUDFILERESOURCE, ECD_CLOUDFOLDER, ECD_IGNORED, ECD_LOCALFORMAT, EXO_DATETIME, EXO_MODIFY, EXO_THUMBNAIL, EXO_THUMBNAILS, EXO_TRASHFOLDER, fileAPI, fileChanges, fileChangeSequencer, fileCopies, fileHistory, fileRemovals, fileSynchronizers, fileTrash, finder, HISTORY_EXPIRATION, HISTORY_MAX_LENGTH, jcrListener, mimeTypes, MIX_REFERENCEABLE, MIX_VERSIONABLE, noConnect, noSync, NT_FILE, NT_FOLDER, NT_RESOURCE, NT_UNSTRUCTURED, repository, rootNodeHolder, rootSystemNodeHolder, rootUUID, rootWorkspace, sessionProviders, state, syncFilesMessages, syncLock, updating, user, USER_NODEPATH, USER_SESSIONPROVIDER, USER_WORKSPACE, workerExecutor
      • Fields inherited from class org.exoplatform.services.cms.clouddrives.CloudDrive

        listeners, LOG
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected JCRLocalGoogleDrive​(org.exoplatform.services.cms.clouddrives.gdrive.GoogleDriveConnector.API apiBuilder, GoogleProvider provider, javax.jcr.Node driveNode, org.exoplatform.services.jcr.ext.app.SessionProviderService sessionProviders, org.exoplatform.services.cms.clouddrives.jcr.NodeFinder finder, org.exoplatform.services.cms.clouddrives.utils.ExtendedMimeTypeResolver mimeTypes)
      Create drive by loading it from local JCR node.
      protected JCRLocalGoogleDrive​(GoogleUser user, javax.jcr.Node driveNode, org.exoplatform.services.jcr.ext.app.SessionProviderService sessionProviders, org.exoplatform.services.cms.clouddrives.jcr.NodeFinder finder, org.exoplatform.services.cms.clouddrives.utils.ExtendedMimeTypeResolver mimeTypes)
      Create newly connecting drive.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean checkAccessScope​(org.exoplatform.services.cms.clouddrives.CloudDriveAccessException cause)
      Throw RefreshAccessException if currently coded scope doesn't match the one used by the drive access tokens.
      protected org.exoplatform.services.cms.clouddrives.CloudFileAPI createFileAPI()
      protected String editLink​(String fileLink, String type, javax.jcr.Node fileNode)
      protected long fileSize​(com.google.api.services.drive.model.File gf)
      Google Drive manages consumed size differently for uploaded (stored in content) and native documents.
      protected org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.ConnectCommand getConnectCommand()
      protected org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.SyncCommand getSyncCommand()
      GoogleUser getUser()
      protected void initDrive​(javax.jcr.Node driveNode)
      protected boolean isAccessScopeMatch()
      Check if currently coded scope match the one used by the drive access tokens.
      protected boolean isEditableType​(String mimeType)
      Checks if is editable type of file type.
      protected static GoogleUser loadUser​(org.exoplatform.services.cms.clouddrives.gdrive.GoogleDriveConnector.API apiBuilder, GoogleProvider provider, javax.jcr.Node driveNode)
      Load user from the drive Node.
      protected List<com.google.api.services.drive.model.ParentReference> mergeParents​(String parentId, List<com.google.api.services.drive.model.ParentReference> cloudParents, Collection<String> localParentIds)
      Merge file's local and cloud parents (local changes has precedence).
      void onUserTokenRefresh​(org.exoplatform.services.cms.clouddrives.oauth2.UserToken token)
      void onUserTokenRemove()
      protected Long readChangeId()
      protected void refreshAccess()
      protected void saveChangeId​(Long id)
      protected void updateAccess​(org.exoplatform.services.cms.clouddrives.CloudUser newUser)
      • Methods inherited from class org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive

        addJCRListener, addUpdating, await, checkNotTrashed, cleanName, cleanRemoved, cleanup, cleanUpdated, commitChanges, configure, connect, copyFile, create, currentUserName, disconnect, ensureSame, fileNode, findNode, findNodes, fixNameConflict, getChangeId, getConnectDate, getCurentCommand, getFile, getFileContent, getFilePreview, getId, getInitDate, getLink, getLocalUser, getOrCleanFileNode, getPath, getState, getTitle, getWorkspace, hasChange, hasFile, hasRemoved, hasUpdated, ignore, initCommon, initCopy, initFile, initFolder, initRemove, initUpdating, isConnected, isDrive, isDrive, isIgnored, isInDrive, isInTrash, isLocal, isNew, isNewOrUpdating, isPrivilegedUser, isSameDrive, isSharingSupported, isUpdating, link, listFiles, listFiles, loadHistory, localChange, migrateName, moveFile, nextChangeId, nodeName, openFile, openFolder, parentPath, previewLink, readFile, readNode, readNodes, removeJCRListener, removeLinks, removeLinks, removeNode, removeUpdating, rollback, rollbackAllChanges, rootNode, rootNode, saveChanges, savedChanges, session, setChangeId, shareFile, size, synchronize, systemSession, thumbnailLink, title, unignore, unshareFile
      • Methods inherited from class org.exoplatform.services.cms.clouddrives.CloudDrive

        addListener, initCreated, removeListener, toString
    • Constructor Detail

      • JCRLocalGoogleDrive

        protected JCRLocalGoogleDrive​(GoogleUser user,
                                      javax.jcr.Node driveNode,
                                      org.exoplatform.services.jcr.ext.app.SessionProviderService sessionProviders,
                                      org.exoplatform.services.cms.clouddrives.jcr.NodeFinder finder,
                                      org.exoplatform.services.cms.clouddrives.utils.ExtendedMimeTypeResolver mimeTypes)
                               throws org.exoplatform.services.cms.clouddrives.CloudDriveException,
                                      javax.jcr.RepositoryException
        Create newly connecting drive.
        Parameters:
        user - the user
        driveNode - the drive node
        sessionProviders - the session providers
        finder - the finder
        mimeTypes - the mime types
        Throws:
        org.exoplatform.services.cms.clouddrives.CloudDriveException - the cloud drive exception
        javax.jcr.RepositoryException - the repository exception
      • JCRLocalGoogleDrive

        protected JCRLocalGoogleDrive​(org.exoplatform.services.cms.clouddrives.gdrive.GoogleDriveConnector.API apiBuilder,
                                      GoogleProvider provider,
                                      javax.jcr.Node driveNode,
                                      org.exoplatform.services.jcr.ext.app.SessionProviderService sessionProviders,
                                      org.exoplatform.services.cms.clouddrives.jcr.NodeFinder finder,
                                      org.exoplatform.services.cms.clouddrives.utils.ExtendedMimeTypeResolver mimeTypes)
                               throws javax.jcr.RepositoryException,
                                      GoogleDriveException,
                                      org.exoplatform.services.cms.clouddrives.CloudDriveException
        Create drive by loading it from local JCR node.
        Parameters:
        apiBuilder - GoogleDriveConnector.API API builder
        provider - GoogleProvider
        driveNode - Node root of the drive
        sessionProviders - the session providers
        finder - the finder
        mimeTypes - the mime types
        Throws:
        javax.jcr.RepositoryException - if local storage error
        GoogleDriveException - if error communicating with Google Drive services
        org.exoplatform.services.cms.clouddrives.CloudDriveException - if cannot load tokens stored locally
    • Method Detail

      • loadUser

        protected static GoogleUser loadUser​(org.exoplatform.services.cms.clouddrives.gdrive.GoogleDriveConnector.API apiBuilder,
                                             GoogleProvider provider,
                                             javax.jcr.Node driveNode)
                                      throws javax.jcr.RepositoryException,
                                             GoogleDriveException,
                                             org.exoplatform.services.cms.clouddrives.CloudDriveException
        Load user from the drive Node.
        Parameters:
        apiBuilder - GoogleDriveConnector.API API builder
        provider - GoogleProvider
        driveNode - Node root of the drive
        Returns:
        GoogleUser
        Throws:
        javax.jcr.RepositoryException - the repository exception
        GoogleDriveException - the google drive exception
        org.exoplatform.services.cms.clouddrives.CloudDriveException - the cloud drive exception
      • getUser

        public GoogleUser getUser()
        Specified by:
        getUser in class org.exoplatform.services.cms.clouddrives.CloudDrive
      • onUserTokenRefresh

        public void onUserTokenRefresh​(org.exoplatform.services.cms.clouddrives.oauth2.UserToken token)
                                throws org.exoplatform.services.cms.clouddrives.CloudDriveException
        Specified by:
        onUserTokenRefresh in interface org.exoplatform.services.cms.clouddrives.oauth2.UserTokenRefreshListener
        Throws:
        org.exoplatform.services.cms.clouddrives.CloudDriveException
      • onUserTokenRemove

        public void onUserTokenRemove()
                               throws org.exoplatform.services.cms.clouddrives.CloudDriveException
        Specified by:
        onUserTokenRemove in interface org.exoplatform.services.cms.clouddrives.oauth2.UserTokenRefreshListener
        Throws:
        org.exoplatform.services.cms.clouddrives.CloudDriveException
      • refreshAccess

        protected void refreshAccess()
                              throws GoogleDriveException,
                                     org.exoplatform.services.cms.clouddrives.RefreshAccessException
        Specified by:
        refreshAccess in class org.exoplatform.services.cms.clouddrives.CloudDrive
        Throws:
        GoogleDriveException
        org.exoplatform.services.cms.clouddrives.RefreshAccessException
      • updateAccess

        protected void updateAccess​(org.exoplatform.services.cms.clouddrives.CloudUser newUser)
                             throws org.exoplatform.services.cms.clouddrives.CloudDriveException,
                                    javax.jcr.RepositoryException
        Specified by:
        updateAccess in class org.exoplatform.services.cms.clouddrives.CloudDrive
        Throws:
        org.exoplatform.services.cms.clouddrives.CloudDriveException
        javax.jcr.RepositoryException
      • isAccessScopeMatch

        protected boolean isAccessScopeMatch()
                                      throws javax.jcr.RepositoryException,
                                             org.exoplatform.services.cms.clouddrives.DriveRemovedException
        Check if currently coded scope match the one used by the drive access tokens.
        Returns:
        true, if is access scope match
        Throws:
        javax.jcr.RepositoryException - the repository exception
        org.exoplatform.services.cms.clouddrives.DriveRemovedException - the drive removed exception
      • checkAccessScope

        protected boolean checkAccessScope​(org.exoplatform.services.cms.clouddrives.CloudDriveAccessException cause)
                                    throws javax.jcr.RepositoryException,
                                           org.exoplatform.services.cms.clouddrives.RefreshAccessException,
                                           org.exoplatform.services.cms.clouddrives.DriveRemovedException
        Throw RefreshAccessException if currently coded scope doesn't match the one used by the drive access tokens.
        Parameters:
        cause - CloudDriveAccessException
        Returns:
        false if access coded and currently used access scopes match, otherwise RefreshAccessException will be thrown with given cause CloudDriveAccessException
        Throws:
        javax.jcr.RepositoryException - the repository exception
        org.exoplatform.services.cms.clouddrives.RefreshAccessException - the refresh access exception
        org.exoplatform.services.cms.clouddrives.DriveRemovedException - the drive removed exception
      • readChangeId

        protected Long readChangeId()
                             throws javax.jcr.RepositoryException,
                                    org.exoplatform.services.cms.clouddrives.CloudDriveException
        Specified by:
        readChangeId in class org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive
        Throws:
        javax.jcr.RepositoryException
        org.exoplatform.services.cms.clouddrives.CloudDriveException
      • saveChangeId

        protected void saveChangeId​(Long id)
                             throws org.exoplatform.services.cms.clouddrives.CloudDriveException,
                                    javax.jcr.RepositoryException
        Specified by:
        saveChangeId in class org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive
        Throws:
        org.exoplatform.services.cms.clouddrives.CloudDriveException
        javax.jcr.RepositoryException
      • initDrive

        protected void initDrive​(javax.jcr.Node driveNode)
                          throws org.exoplatform.services.cms.clouddrives.CloudDriveException,
                                 javax.jcr.RepositoryException
        Overrides:
        initDrive in class org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive
        Throws:
        org.exoplatform.services.cms.clouddrives.CloudDriveException
        javax.jcr.RepositoryException
      • getConnectCommand

        protected org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.ConnectCommand getConnectCommand()
                                                                                                            throws org.exoplatform.services.cms.clouddrives.DriveRemovedException,
                                                                                                                   javax.jcr.RepositoryException
        Specified by:
        getConnectCommand in class org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive
        Throws:
        org.exoplatform.services.cms.clouddrives.DriveRemovedException
        javax.jcr.RepositoryException
      • getSyncCommand

        protected org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive.SyncCommand getSyncCommand()
                                                                                                      throws org.exoplatform.services.cms.clouddrives.DriveRemovedException,
                                                                                                             org.exoplatform.services.cms.clouddrives.SyncNotSupportedException,
                                                                                                             javax.jcr.RepositoryException
        Specified by:
        getSyncCommand in class org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive
        Throws:
        org.exoplatform.services.cms.clouddrives.DriveRemovedException
        org.exoplatform.services.cms.clouddrives.SyncNotSupportedException
        javax.jcr.RepositoryException
      • createFileAPI

        protected org.exoplatform.services.cms.clouddrives.CloudFileAPI createFileAPI()
                                                                               throws org.exoplatform.services.cms.clouddrives.DriveRemovedException,
                                                                                      org.exoplatform.services.cms.clouddrives.SyncNotSupportedException,
                                                                                      javax.jcr.RepositoryException
        Specified by:
        createFileAPI in class org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive
        Throws:
        org.exoplatform.services.cms.clouddrives.DriveRemovedException
        org.exoplatform.services.cms.clouddrives.SyncNotSupportedException
        javax.jcr.RepositoryException
      • mergeParents

        protected List<com.google.api.services.drive.model.ParentReference> mergeParents​(String parentId,
                                                                                         List<com.google.api.services.drive.model.ParentReference> cloudParents,
                                                                                         Collection<String> localParentIds)
        Merge file's local and cloud parents (local changes has precedence).
        Parameters:
        parentId - String current local parent id
        cloudParents - List of ParentReference on cloud side
        localParentIds - List of parent ids locally
        Returns:
        the list
      • editLink

        protected String editLink​(String fileLink,
                                  String type,
                                  javax.jcr.Node fileNode)
                           throws javax.jcr.RepositoryException
        Overrides:
        editLink in class org.exoplatform.services.cms.clouddrives.jcr.JCRLocalCloudDrive
        Throws:
        javax.jcr.RepositoryException
      • fileSize

        protected long fileSize​(com.google.api.services.drive.model.File gf)
        Google Drive manages consumed size differently for uploaded (stored in content) and native documents. File stored in content has a size, but native document has usage of quota only.
        Parameters:
        gf - File
        Returns:
        file size or consumed quota if the size not available
      • isEditableType

        protected boolean isEditableType​(String mimeType)
        Checks if is editable type of file type.
        Parameters:
        mimeType - the mime type
        Returns:
        true, if is editable type