diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/Astrid44SyncMigrator.java b/astrid/plugin-src/com/todoroo/astrid/tags/Astrid44SyncMigrator.java index 201bba580..0f563a55c 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/Astrid44SyncMigrator.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/Astrid44SyncMigrator.java @@ -137,12 +137,14 @@ public class Astrid44SyncMigrator { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { instance.readPropertiesFromCursor(cursor); if (!instance.containsNonNullValue(RemoteModel.REMOTE_ID_PROPERTY)) { - Pair uuidPair = UUIDHelper.newUUID(); - instance.setValue(RemoteModel.REMOTE_ID_PROPERTY, uuidPair.getLeft()); + // No remote id exists, just create a UUID + Pair uuidPair = UUIDHelper.newUUID(); + instance.setValue(RemoteModel.UUID_PROPERTY, uuidPair.getLeft()); instance.setValue(RemoteModel.PROOF_TEXT_PROPERTY, uuidPair.getRight()); + } else { + // Migrate remote id to uuid field + instance.setValue(RemoteModel.UUID_PROPERTY, BigInteger.valueOf(instance.getValue(RemoteModel.REMOTE_ID_PROPERTY))); } - // Migrate remote id to uuid field - instance.setValue(RemoteModel.UUID_PROPERTY, BigInteger.valueOf(instance.getValue(RemoteModel.REMOTE_ID_PROPERTY))); dao.saveExisting(instance); } } finally { diff --git a/astrid/src/com/todoroo/astrid/dao/RemoteModelDao.java b/astrid/src/com/todoroo/astrid/dao/RemoteModelDao.java index 1724e4f50..ee40c1f5a 100644 --- a/astrid/src/com/todoroo/astrid/dao/RemoteModelDao.java +++ b/astrid/src/com/todoroo/astrid/dao/RemoteModelDao.java @@ -1,5 +1,7 @@ package com.todoroo.astrid.dao; +import java.math.BigInteger; + import com.todoroo.andlib.data.DatabaseDao; import com.todoroo.andlib.utility.Pair; import com.todoroo.astrid.data.RemoteModel; @@ -22,9 +24,9 @@ public class RemoteModelDao extends DatabaseDao uuidPair = UUIDHelper.newUUID(); - item.setValue(RemoteModel.REMOTE_ID_PROPERTY, uuidPair.getLeft()); + if (!item.containsValue(RemoteModel.UUID_PROPERTY)) { + Pair uuidPair = UUIDHelper.newUUID(); + item.setValue(RemoteModel.UUID_PROPERTY, uuidPair.getLeft()); item.setValue(RemoteModel.PROOF_TEXT_PROPERTY, uuidPair.getRight()); } return super.createNew(item); diff --git a/astrid/src/com/todoroo/astrid/dao/TagDataDao.java b/astrid/src/com/todoroo/astrid/dao/TagDataDao.java index 494c423fc..c2daab28b 100644 --- a/astrid/src/com/todoroo/astrid/dao/TagDataDao.java +++ b/astrid/src/com/todoroo/astrid/dao/TagDataDao.java @@ -30,7 +30,7 @@ public class TagDataDao extends RemoteModelDao { private static final String[] IGNORE_OUTSTANDING_COLUMNS = new String[] { TagData.MODIFICATION_DATE.name, - TagData.REMOTE_ID.name, + TagData.UUID.name, }; @Override diff --git a/astrid/src/com/todoroo/astrid/dao/TaskDao.java b/astrid/src/com/todoroo/astrid/dao/TaskDao.java index 0f575cb9e..feab58e9d 100644 --- a/astrid/src/com/todoroo/astrid/dao/TaskDao.java +++ b/astrid/src/com/todoroo/astrid/dao/TaskDao.java @@ -320,7 +320,7 @@ public class TaskDao extends RemoteModelDao { Task.DETAILS.name, Task.DETAILS_DATE.name, Task.CALENDAR_URI.name, - Task.REMOTE_ID.name, + Task.UUID.name, Task.PUSHED_AT.name, Task.LAST_SYNC.name, Task.ESTIMATED_SECONDS.name, diff --git a/astrid/src/com/todoroo/astrid/helper/UUIDHelper.java b/astrid/src/com/todoroo/astrid/helper/UUIDHelper.java index 4a2af2ca1..6f8c53299 100644 --- a/astrid/src/com/todoroo/astrid/helper/UUIDHelper.java +++ b/astrid/src/com/todoroo/astrid/helper/UUIDHelper.java @@ -1,5 +1,6 @@ package com.todoroo.astrid.helper; +import java.math.BigInteger; import java.security.SecureRandom; import java.util.UUID; @@ -39,7 +40,7 @@ public class UUIDHelper { * @return a pair consisting of the newly * generated uuid and the corresponding proof text */ - public static Pair newUUID() { + public static Pair newUUID() { long uuid = 0; String proofText = ""; //$NON-NLS-1$ do { @@ -54,7 +55,7 @@ public class UUIDHelper { proofText = d + "," + s; //$NON-NLS-1$ uuid = bcryptToLong(proofText); } while (uuid < MIN_UUID); - return Pair.create(uuid, proofText); + return Pair.create(BigInteger.valueOf(uuid), proofText); } private static final String SALT = "$2a$10$2RHhxhKaPb4VXlQUJyBU/O"; //$NON-NLS-1$