Add column 'Remote_Id' to the local files db. Create upgrade for 'Permissions' and...
authorjabarros <jabarros@solidgear.es>
Mon, 23 Jun 2014 12:49:52 +0000 (14:49 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Tue, 1 Jul 2014 07:59:28 +0000 (09:59 +0200)
src/com/owncloud/android/datamodel/FileDataStorageManager.java
src/com/owncloud/android/datamodel/OCFile.java
src/com/owncloud/android/db/ProviderMeta.java
src/com/owncloud/android/operations/SynchronizeFolderOperation.java
src/com/owncloud/android/providers/FileContentProvider.java
src/com/owncloud/android/utils/FileStorageUtils.java

index 2f2cf45..c8c0d24 100644 (file)
@@ -187,6 +187,7 @@ public class FileDataStorageManager {
         cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, file.isShareByLink() ? 1 : 0);
         cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
         cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
+        cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
         
         boolean sameRemotePath = fileExists(file.getRemotePath());
         if (sameRemotePath ||
@@ -287,6 +288,7 @@ public class FileDataStorageManager {
             cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, file.isShareByLink() ? 1 : 0);
             cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
             cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
+            cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
 
             boolean existsByPath = fileExists(file.getRemotePath());
             if (existsByPath || fileExists(file.getFileId())) {
@@ -345,6 +347,7 @@ public class FileDataStorageManager {
         cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, folder.isShareByLink() ? 1 : 0);
         cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, folder.getPublicLink());
         cv.put(ProviderTableMeta.FILE_PERMISSIONS, folder.getPermissions());
+        cv.put(ProviderTableMeta.FILE_REMOTE_ID, folder.getRemoteId());
         
         operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
                 withValues(cv).
@@ -754,6 +757,7 @@ public class FileDataStorageManager {
                     c.getColumnIndex(ProviderTableMeta.FILE_SHARE_BY_LINK)) == 1 ? true : false);
             file.setPublicLink(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PUBLIC_LINK)));
             file.setPermissions(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PERMISSIONS)));
+            file.setRemoteId(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID)));
                     
         }
         return file;
@@ -1097,6 +1101,7 @@ public class FileDataStorageManager {
                 cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, file.isShareByLink() ? 1 : 0);
                 cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
                 cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
+                cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
 
                 boolean existsByPath = fileExists(file.getRemotePath());
                 if (existsByPath || fileExists(file.getFileId())) {
index ae2376d..92168ff 100644 (file)
@@ -66,6 +66,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     private String mPublicLink;
 
     private String mPermissions;
+    private String mRemoteId;
 
 
     /**
@@ -107,6 +108,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         mShareByLink = source.readInt() == 1;
         mPublicLink = source.readString();
         mPermissions = source.readString();
+        mRemoteId = source.readString();
     }
 
     @Override
@@ -128,6 +130,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         dest.writeInt(mShareByLink ? 1 : 0);
         dest.writeString(mPublicLink);
         dest.writeString(mPermissions);
+        dest.writeString(mRemoteId);
     }
     
     /**
@@ -339,6 +342,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         mShareByLink = false;
         mPublicLink = null;
         mPermissions = null;
+        mRemoteId = null;
     }
 
     /**
@@ -531,4 +535,12 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         this.mPermissions = permissions;
     }
 
+    public String getRemoteId() {
+        return mRemoteId;
+    }
+
+    public void setRemoteId(String remoteId) {
+        this.mRemoteId = remoteId;
+    }
+
 }
index 6f9683c..f99734c 100644 (file)
@@ -69,6 +69,7 @@ public class ProviderMeta {
         public static final String FILE_SHARE_BY_LINK = "share_by_link";\r
         public static final String FILE_PUBLIC_LINK = "public_link";\r
         public static final String FILE_PERMISSIONS = "permissions";\r
+        public static final String FILE_REMOTE_ID = "remote_id";\r
 \r
         public static final String FILE_DEFAULT_SORT_ORDER = FILE_NAME\r
                 + " collate nocase asc";\r
index a665d57..fc4a74e 100644 (file)
@@ -417,6 +417,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
         file.setModificationTimestamp(remote.getModifiedTimestamp());
         file.setEtag(remote.getEtag());
         file.setPermissions(remote.getPermissions());
+        file.setRemoteId(remote.getRemoteId());
         return file;
     }
     
index 22bcc1e..8ef44e3 100644 (file)
@@ -95,6 +95,8 @@ public class FileContentProvider extends ContentProvider {
                 ProviderTableMeta.FILE_PUBLIC_LINK);
         mFileProjectionMap.put(ProviderTableMeta.FILE_PERMISSIONS,
                 ProviderTableMeta.FILE_PERMISSIONS);
+        mFileProjectionMap.put(ProviderTableMeta.FILE_REMOTE_ID,
+                ProviderTableMeta.FILE_REMOTE_ID);
     }
 
     private static final int SINGLE_FILE = 1;
@@ -557,7 +559,8 @@ public class FileContentProvider extends ContentProvider {
                     + ProviderTableMeta.FILE_ETAG + " TEXT, " 
                     + ProviderTableMeta.FILE_SHARE_BY_LINK + " INTEGER, "
                     + ProviderTableMeta.FILE_PUBLIC_LINK  + " TEXT, "
-                    + ProviderTableMeta.FILE_PERMISSIONS  + " TEXT null);"
+                    + ProviderTableMeta.FILE_PERMISSIONS  + " TEXT null,"
+                    + ProviderTableMeta.FILE_REMOTE_ID  + " TEXT null);"
                     );
             
             // Create table ocshares
@@ -646,7 +649,7 @@ public class FileContentProvider extends ContentProvider {
             }
             if (!upgraded)
                 Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
-            
+
             if (oldVersion < 6 && newVersion >= 6) {
                 Log_OC.i("SQL", "Entering in the #5 ADD in onUpgrade");
                 db.beginTransaction();
@@ -658,10 +661,6 @@ public class FileContentProvider extends ContentProvider {
                     db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
                             " ADD COLUMN " + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT " +
                             " DEFAULT NULL");
-                    
-                    db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
-                            " ADD COLUMN " + ProviderTableMeta.FILE_PERMISSIONS + " TEXT " +
-                            " DEFAULT NULL");
 
                     // Create table ocshares
                     db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "("
@@ -680,6 +679,27 @@ public class FileContentProvider extends ContentProvider {
                             + ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, "
                             + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER," 
                             + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );" );
+
+                    upgraded = true;
+                    db.setTransactionSuccessful();
+                } finally {
+                    db.endTransaction();
+                }
+            }
+            if (!upgraded)
+                Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
+
+            if (oldVersion < 7 && newVersion >= 7) {
+                Log_OC.i("SQL", "Entering in the #6 ADD in onUpgrade");
+                db.beginTransaction();
+                try {
+                    db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
+                            " ADD COLUMN " + ProviderTableMeta.FILE_PERMISSIONS + " TEXT " +
+                            " DEFAULT NULL");
+
+                    db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_REMOTE_ID +
+                            " ADD COLUMN " + ProviderTableMeta.FILE_REMOTE_ID + " TEXT " +
+                            " DEFAULT NULL");
                     
                     upgraded = true;
                     db.setTransactionSuccessful();
index 2bf0554..58dda0d 100644 (file)
@@ -98,6 +98,7 @@ public class FileStorageUtils {
         file.setModificationTimestamp(remote.getModifiedTimestamp());
         file.setEtag(remote.getEtag());
         file.setPermissions(remote.getPermissions());
+        file.setRemoteId(remote.getRemoteId());
         return file;
     }
     
@@ -115,6 +116,7 @@ public class FileStorageUtils {
         file.setModifiedTimestamp(ocFile.getModificationTimestamp());
         file.setEtag(ocFile.getEtag());
         file.setPermissions(ocFile.getPermissions());
+        file.setRemoteId(ocFile.getRemoteId());
         return file;
     }