Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4147628a authored by vince-bourgmayer's avatar vince-bourgmayer
Browse files

add rootFolderId into SyncedFileStateDB. Change ObserverService to load...

add rootFolderId into SyncedFileStateDB. Change ObserverService to load SyncedFileState with rootFolder and change SyncedFileStateDAO to be able to get list of syncedFileState filtered on rootFolderIds
parent 18007bf5
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import io.eelo.drive.models.SyncedFileState;

public final class DbHelper extends SQLiteOpenHelper {
    final public static String TAG = DbHelper.class.getSimpleName(); //Tag for log
    public static final int DATABASE_VERSION = 10;
    public static final int DATABASE_VERSION = 13;
    public static final String DATABASE_NAME = "eelo_drive.db";

    /**
@@ -117,11 +117,11 @@ public final class DbHelper extends SQLiteOpenHelper {
    /**
     * get many synced file filtered on remote or local path
     * @param context calling context to get DAO
     * @param paths List<String> path of folder on which to filter syncedFileStates. Use parent path of the file
     * @param useLocalPath True if path is a local path, if it's false use remote path
     * @param ids List<String> id of root folders

     * @return null if DB opening failed, either return thelist of SyncedFileState
     */
    public static List<SyncedFileState> getSyncedFileStatesByFolders(Context context, List<String> paths, boolean useLocalPath) {//Connect to DB
    public static List<SyncedFileState> getSyncedFileStatesByFolders(Context context, List<Long> ids) {//Connect to DB
        SyncedFileStateDAO dao = new SyncedFileStateDAO( context );
        try{
            dao.open( false );
@@ -130,7 +130,7 @@ public final class DbHelper extends SQLiteOpenHelper {
            return null;
        }

        List<SyncedFileState> result = dao.getByParentPath(paths, useLocalPath);
        List<SyncedFileState> result = dao.getFilteredByRootFolderID(ids);

        dao.close();
        return result;
+3 −8
Original line number Diff line number Diff line
@@ -27,18 +27,13 @@ public final class RootFolderContract implements BaseColumns{
            .append("CREATE TABLE ").append(TABLE_NAME).append(" ( ")
            .append(_ID).append(" INTEGER PRIMARY KEY, ")
            .append(CATEGORIE_LABEL).append(" TEXT, ")
            .append(LOCAL_PATH).append(" TEXT, ")
            .append(REMOTE_PATH).append(" TEXT, ")
            .append(LOCAL_PATH).append(" TEXT unique, ")
            .append(REMOTE_PATH).append(" TEXT unique, ")
            .append(LAST_ETAG).append(" TEXT, ")
            .append(LOCAL_LAST_MODIFIED).append(" INTEGER, ")
            .append(SCANLOCAL).append(" BOOLEAN, ")
            .append(SCANREMOTE).append(" BOOLEAN, ")
            .append(ENABLED).append(" BOOLEAN, ")
            .append("CONSTRAINT roots_unicity_constraint UNIQUE (")
            //.append(CATEGORIE_LABEL).append(", ")
            .append(LOCAL_PATH).append(", ")
            .append(REMOTE_PATH)
            .append("))")
            .append(ENABLED).append(" BOOLEAN ) ")
            .toString();


+3 −1
Original line number Diff line number Diff line
@@ -14,9 +14,10 @@ public class SyncedFileStateContract implements BaseColumns{
    public static final String TABLE_NAME ="synced_file_state";
    public static final String FILE_NAME ="file_name";
    public static final String LOCAL_PATH ="local_path";
    public static final String REMOTE_PATH = "remote_paths";
    public static final String REMOTE_PATH = "remote_path";
    public static final String LAST_ETAG = "last_etag";
    public static final String LOCAL_LAST_MODIFIED = "local_last_modified";
    public static final String ROOTFOLDER_ID = "rootfolder_id";

    
    
@@ -29,6 +30,7 @@ public class SyncedFileStateContract implements BaseColumns{
            .append(REMOTE_PATH).append(" TEXT, ")
            .append(LAST_ETAG).append(" TEXT, ")
            .append(LOCAL_LAST_MODIFIED).append(" INTEGER, ")
            .append(ROOTFOLDER_ID).append(" INTEGER, ")
            .append("CONSTRAINT synced_unicity_constraint UNIQUE (")
            .append(FILE_NAME).append(", ")
            .append(LOCAL_PATH).append(", ")
+23 −18
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@ public class SyncedFileStateDAO {
            SyncedFileStateContract.LOCAL_PATH,
            SyncedFileStateContract.REMOTE_PATH,
            SyncedFileStateContract.LAST_ETAG,
            SyncedFileStateContract.LOCAL_LAST_MODIFIED
            SyncedFileStateContract.LOCAL_LAST_MODIFIED,
            SyncedFileStateContract.ROOTFOLDER_ID
    };

    public SyncedFileStateDAO(Context context){
@@ -64,6 +65,7 @@ public class SyncedFileStateDAO {
        values.put( SyncedFileStateContract.REMOTE_PATH, syncedFileState.getRemotePath() );
        values.put( SyncedFileStateContract.LAST_ETAG, syncedFileState.getLastETAG() );
        values.put( SyncedFileStateContract.LOCAL_LAST_MODIFIED, syncedFileState.getLocalLastModified() );
        values.put( SyncedFileStateContract.ROOTFOLDER_ID, syncedFileState.getRootFolderId() );
        long id = mDB.insertWithOnConflict(SyncedFileStateContract.TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        return id;
    }
@@ -97,6 +99,7 @@ public class SyncedFileStateDAO {
        values.put(SyncedFileStateContract.REMOTE_PATH, syncedFileState.getRemotePath());
        values.put(SyncedFileStateContract.LAST_ETAG, syncedFileState.getLastETAG());
        values.put( SyncedFileStateContract.LOCAL_LAST_MODIFIED, syncedFileState.getLocalLastModified() );
        values.put( SyncedFileStateContract.ROOTFOLDER_ID, syncedFileState.getRootFolderId() );
        int result = 0;

        try{
@@ -110,10 +113,10 @@ public class SyncedFileStateDAO {

    /**
     * Fetch many SyncedFileState by its localPath
     * @param paths List<String> of path to filter. Need to be directory path
     * @return
     * @param rootFolderids List<String> of path to filter. Need to be directory path
     * @return List<SyncedFileState> List of SyncedFileState filtered on RootFolder ID.
     */
    public List<SyncedFileState> getByParentPath(List<String> paths, boolean isLocalPath){
    public List<SyncedFileState> getFilteredByRootFolderID(List<Long> rootFolderids){
        StringBuilder queryBuilder = new StringBuilder().append("Select ")
            .append(SyncedFileStateContract._ID)
            .append(", ")
@@ -126,28 +129,25 @@ public class SyncedFileStateDAO {
            .append(SyncedFileStateContract.LAST_ETAG)
            .append(", ")
            .append(SyncedFileStateContract.LOCAL_LAST_MODIFIED)
            .append(", ")
            .append(SyncedFileStateContract.ROOTFOLDER_ID)
            .append(" FROM ")
            .append(SyncedFileStateContract.TABLE_NAME)
            .append(" WHERE ");
        String field;
        if(isLocalPath)
            field = SyncedFileStateContract.LOCAL_PATH ;
        else
            field = SyncedFileStateContract.REMOTE_PATH ;

        int pathSize = paths.size();
        for(int i =0; i <pathSize; ++i){
            queryBuilder.append(field);
            queryBuilder.append(" LIKE \"")
                    .append(paths.get(i))
                    .append("%\"");
        int idsSize = rootFolderids.size();
        for(int i =0; i <idsSize; ++i){
            queryBuilder.append(SyncedFileStateContract.ROOTFOLDER_ID);
            queryBuilder.append(" = ")
                    .append(rootFolderids.get(i));

            if(i < pathSize-1 ){
            if(i < idsSize-1 ){
                queryBuilder.append(" OR ");
            }
        }
        String query = queryBuilder.toString();

        Log.d(TAG+"_getFilteredByRootFolderID()", query);
        Cursor cursor = mDB.rawQuery(query, null);
        cursor.moveToFirst();
        List<SyncedFileState> result = new ArrayList<>();
@@ -182,6 +182,8 @@ public class SyncedFileStateDAO {
                .append(SyncedFileStateContract.LAST_ETAG)
                .append(", ")
                .append(SyncedFileStateContract.LOCAL_LAST_MODIFIED)
                .append(", ")
                .append(SyncedFileStateContract.ROOTFOLDER_ID)
                .append(" FROM ")
                .append(SyncedFileStateContract.TABLE_NAME)
                .append(" WHERE ");
@@ -222,6 +224,8 @@ public class SyncedFileStateDAO {
                .append(SyncedFileStateContract.LAST_ETAG)
                .append(", ")
                .append(SyncedFileStateContract.LOCAL_LAST_MODIFIED)
                .append(", ")
                .append(SyncedFileStateContract.ROOTFOLDER_ID)
                .append(" FROM ")
                .append(SyncedFileStateContract.TABLE_NAME).toString();
        Cursor cursor = mDB.rawQuery(query, null);
@@ -242,7 +246,7 @@ public class SyncedFileStateDAO {
    /**
     * Create SyncedFileState from cursor
     * @param cursor
     * @return
     * @return SyncedFileState instance
     */
    private SyncedFileState cursorToSyncedFileState(Cursor cursor) {
        SyncedFileState file = new SyncedFileState()
@@ -251,7 +255,8 @@ public class SyncedFileStateDAO {
                    .setLocalPath( cursor.getString(2 ) ) //local path
                    .setRemotePath( cursor.getString(3 ) ) //remote path
                    .setLastETAG( cursor.getString(4 ) )// last Etag
                    .setLocalLastModified( cursor.getLong(5 ) ); //Local last modified
                    .setLocalLastModified( cursor.getLong(5 ) ) //Local last modified
                    .setRootFolderId( cursor.getLong(6 ) ); //Local last modified
        return file;
    }
}
+25 −1
Original line number Diff line number Diff line
@@ -13,12 +13,16 @@ public class SyncedFileState {
    private String remotePath;
    private String lastETAG;
    private Long localLastModified;
    private Long rootFolderId;

    /**
     * Default constructor
     * Set Id and rootFolderId to -1 and localLastModified to 0L.
     */
    public SyncedFileState(){
        this.id = -1;
        localLastModified = 0L;
        this.rootFolderId = -1L;
    }

    /**
@@ -71,7 +75,7 @@ public class SyncedFileState {
     * @param etag last known etag of the file
     * @param lastModified Last modified time where local file has changed
     */
    public SyncedFileState(int id, String name, String localPath, String remotePath, String etag, Long lastModified){
    public SyncedFileState(int id, String name, String localPath, String remotePath, String etag, Long lastModified, long rootFolderId){
        this(id, name, localPath, remotePath, etag);
        this.localLastModified = lastModified;
    }
@@ -143,4 +147,24 @@ public class SyncedFileState {
    public boolean isLastEtagStored(){
        return (this.lastETAG != null && !this.lastETAG.isEmpty() );
    }


    /**
     * Get the rootFolder _id
     * @return long
     */
    public Long getRootFolderId() {
        return rootFolderId;
    }

    /**
     * Set the root folder _id
     * @param rootFolderId long RootFolder _id
     * @return calling instance
     */
    public SyncedFileState setRootFolderId(long rootFolderId) {
        this.rootFolderId = rootFolderId;
        return this;
    }

}
Loading