diff options
author | desperateCoder <echotodevnull@gmail.com> | 2021-03-26 14:47:33 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2021-03-26 14:47:33 +0300 |
commit | 1d00fcc34ee63e722bc673b580b7b36f5b649e4d (patch) | |
tree | 9f6a9733077e79710b697c55a044416c87794968 /app | |
parent | cc84f119054619d695ec29108b09e08a6072bc42 (diff) |
sync project resource deletion properly
Diffstat (limited to 'app')
3 files changed, 31 insertions, 0 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java index e21d689fe..827fcee39 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java @@ -1447,4 +1447,12 @@ public class DataBaseAdapter { public Integer getBoardColorDirectly(long accountId, long localBoardId) { return db.getBoardDao().getBoardColorByLocalIdDirectly(accountId, localBoardId); } + + public void deleteProjectResourcesByCardIdExceptGivenProjectIdsDirectly(long accountId, Long localCardId, List<Long> remoteProjectIDs) { + db.getJoinCardWithOcsProjectDao().deleteProjectResourcesByCardIdExceptGivenProjectIdsDirectly(accountId, localCardId, remoteProjectIDs); + } + + public void deleteProjectResourcesByCardIdDirectly(Long localCardId) { + db.getJoinCardWithOcsProjectDao().deleteProjectResourcesByCardIdDirectly(localCardId); + } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/projects/JoinCardWithOcsProjectDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/projects/JoinCardWithOcsProjectDao.java index d132796e4..205c84aa0 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/projects/JoinCardWithOcsProjectDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/projects/JoinCardWithOcsProjectDao.java @@ -3,6 +3,8 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.projects; import androidx.room.Dao; import androidx.room.Query; +import java.util.List; + import it.niedermann.nextcloud.deck.model.ocs.projects.JoinCardWithProject; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.GenericDao; @@ -10,4 +12,10 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.GenericDao; public interface JoinCardWithOcsProjectDao extends GenericDao<JoinCardWithProject> { @Query("select * from JoinCardWithProject where projectId = :localProjectId and cardId = :localCardId") JoinCardWithProject getAssignmentByCardIdAndProjectIdDirectly(Long localCardId, Long localProjectId); + + @Query("delete from JoinCardWithProject where cardId = :localCardId and projectId NOT in (select p.localId from OcsProject p where p.accountId = :accountId and p.id in (:remoteProjectIDs))") + void deleteProjectResourcesByCardIdExceptGivenProjectIdsDirectly(long accountId, Long localCardId, List<Long> remoteProjectIDs); + + @Query("delete from JoinCardWithProject where cardId = :localCardId") + void deleteProjectResourcesByCardIdDirectly(Long localCardId); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/OcsProjectDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/OcsProjectDataProvider.java index 5379be6d9..bdf92f409 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/OcsProjectDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/OcsProjectDataProvider.java @@ -3,6 +3,7 @@ package it.niedermann.nextcloud.deck.persistence.sync.helpers.providers; import java.time.Instant; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.api.IResponseCallback; @@ -67,6 +68,20 @@ public class OcsProjectDataProvider extends AbstractSyncDataProvider<OcsProject> } } + @Override + public void handleDeletes(ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter, long accountId, List<OcsProject> entitiesFromServer) { + if (entitiesFromServer.isEmpty()){ + dataBaseAdapter.deleteProjectResourcesByCardIdDirectly(card.getLocalId()); + return; + } + List<Long> remoteProjectIDs = entitiesFromServer.stream() + .map(OcsProject::getId) + .collect(Collectors.toList()); + if (!remoteProjectIDs.isEmpty()) { + dataBaseAdapter.deleteProjectResourcesByCardIdExceptGivenProjectIdsDirectly(accountId, card.getLocalId(), remoteProjectIDs); + } + } + private void updateResources(DataBaseAdapter dataBaseAdapter, Long accountId, OcsProject entity) { if (entity.getResources() != null) { for (OcsProjectResource resource : entity.getResources()) { |