diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-07-25 14:54:20 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-07-25 15:40:50 +0300 |
commit | 53dc1ff8ae71fcb649efa6cfe6fd08187c7de0ab (patch) | |
tree | 18022623add355b0e3a174f6916d8abacc5eb0aa /app | |
parent | 6d5b071c2424da307c992137dffd0f4d5015cbd1 (diff) |
#619 string-ID support for OcsProjectResources
Diffstat (limited to 'app')
3 files changed, 34 insertions, 3 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java index fc3dbc834..524bd2a07 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java @@ -129,7 +129,16 @@ public class JsonToEntityParser { DeckLog.verbose(obj.toString()); OcsProjectResource resource = new OcsProjectResource(); makeTraceableIfFails(() -> { - resource.setId(Long.parseLong(getNullAsEmptyString(obj.get("id")))); + if (obj.has("id")) { + String idString = obj.get("id").getAsString(); + if (idString != null && idString.trim().length() > 0) { + if (idString.matches("[0-9]+")){ + resource.setId(Long.parseLong(idString.trim())); + } else { + resource.setIdString(idString); + } + } + } if (obj.has("type")) { resource.setType(getNullAsEmptyString(obj.get("type"))); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/OcsProjectResource.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/OcsProjectResource.java index 07cd367f4..cd63ccde4 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/OcsProjectResource.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/OcsProjectResource.java @@ -16,7 +16,7 @@ import it.niedermann.nextcloud.deck.model.interfaces.AbstractRemoteEntity; indices = { @Index(value = "id", name = "index_OcsProjectResource_id"), @Index(value = "lastModifiedLocal", name = "index_OcsProjectResource_lastModifiedLocal"), - @Index(value = {"accountId", "id", "projectId"}, name = "index_OcsProjectResource_accountId_id", unique = true), + @Index(value = {"accountId", "id", "idString", "projectId"}, name = "index_OcsProjectResource_accountId_id", unique = true), @Index(value = "accountId", name = "index_projectResource_accID"), @Index(value = "projectId", name = "index_projectResource_projectId"), }, @@ -43,6 +43,9 @@ public class OcsProjectResource extends AbstractRemoteEntity implements Serializ private String mimetype; @Nullable private Boolean previewAvailable; + @Nullable + private String idString; + @NonNull private Long projectId; @@ -120,4 +123,13 @@ public class OcsProjectResource extends AbstractRemoteEntity implements Serializ public void setPreviewAvailable(@Nullable Boolean previewAvailable) { this.previewAvailable = previewAvailable; } + + @Nullable + public String getIdString() { + return idString; + } + + public void setIdString(@Nullable String idString) { + this.idString = idString; + } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java index b8af9ffed..df2d9a604 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java @@ -87,7 +87,7 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.Sta JoinCardWithProject.class, }, exportSchema = false, - version = 18 + version = 19 ) @TypeConverters({DateTypeConverter.class}) public abstract class DeckDatabase extends RoomDatabase { @@ -227,6 +227,15 @@ public abstract class DeckDatabase extends RoomDatabase { database.execSQL("ALTER TABLE `Account` ADD `etag` TEXT"); } }; + private static final Migration MIGRATION_18_19 = new Migration(18, 19) { + @Override + public void migrate(SupportSQLiteDatabase database) { + // https://github.com/stefan-niedermann/nextcloud-deck/issues/619 + database.execSQL("DROP INDEX `index_OcsProjectResource_accountId_id`"); + database.execSQL("ALTER TABLE `OcsProjectResource` ADD `idString` TEXT"); + database.execSQL("CREATE UNIQUE INDEX `index_OcsProjectResource_accountId_id` ON `OcsProjectResource` (`accountId`, `id`, `idString`, `projectId`)"); + } + }; public static final RoomDatabase.Callback ON_CREATE_CALLBACK = new RoomDatabase.Callback() { @Override @@ -271,6 +280,7 @@ public abstract class DeckDatabase extends RoomDatabase { .addMigrations(MIGRATION_15_16) .addMigrations(MIGRATION_16_17) .addMigrations(MIGRATION_17_18) + .addMigrations(MIGRATION_18_19) .fallbackToDestructiveMigration() .addCallback(ON_CREATE_CALLBACK) .build(); |