diff options
Diffstat (limited to 'app/src/main/java/it/niedermann')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardDataProvider.java | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardDataProvider.java index 05aafb681..4aa6cb452 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardDataProvider.java @@ -5,6 +5,7 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.api.IResponseCallback; import it.niedermann.nextcloud.deck.exceptions.OfflineException; import it.niedermann.nextcloud.deck.model.Account; @@ -18,6 +19,8 @@ import it.niedermann.nextcloud.deck.model.User; import it.niedermann.nextcloud.deck.model.enums.DBStatus; import it.niedermann.nextcloud.deck.model.full.FullCard; import it.niedermann.nextcloud.deck.model.full.FullStack; +import it.niedermann.nextcloud.deck.model.ocs.Capabilities; +import it.niedermann.nextcloud.deck.model.ocs.Version; import it.niedermann.nextcloud.deck.model.propagation.CardUpdate; import it.niedermann.nextcloud.deck.persistence.sync.adapters.ServerAdapter; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.DataBaseAdapter; @@ -38,7 +41,7 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<FullCard>> responder, Date lastSync) { List<FullCard> result = new ArrayList<>(); - if (stack.getCards() == null || stack.getCards().isEmpty()){ + if (stack.getCards() == null || stack.getCards().isEmpty()) { responder.onResponse(result); } for (Card card : stack.getCards()) { @@ -70,7 +73,7 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { return dataBaseAdapter.createCard(accountId, entity.getCard()); } - protected CardUpdate toCardUpdate(FullCard card){ + protected CardUpdate toCardUpdate(FullCard card) { CardUpdate c = new CardUpdate(card); c.setOwner(card.getOwner().get(0)); return c; @@ -78,10 +81,10 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { protected void fixRelations(DataBaseAdapter dataBaseAdapter, long accountId, FullCard entity) { entity.getCard().setStackId(stack.getLocalId()); - if (entity.getOwner() != null && !entity.getOwner().isEmpty()){ + if (entity.getOwner() != null && !entity.getOwner().isEmpty()) { User user = entity.getOwner().get(0); User u = dataBaseAdapter.getUserByUidDirectly(accountId, user.getUid()); - if (u == null){ + if (u == null) { dataBaseAdapter.createUser(accountId, user); } else { user.setLocalId(u.getLocalId()); @@ -97,7 +100,7 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { @Override public FullCard applyUpdatesFromRemote(FullCard localEntity, FullCard remoteEntity, Long accountId) { - if (localEntity.getCard().getUserId()!=null){ + if (localEntity.getCard().getUserId() != null) { remoteEntity.getCard().setUserId(localEntity.getCard().getUserId()); } return remoteEntity; @@ -124,17 +127,24 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { existingEntity.setAttachments(attachments); syncHelper.fixRelations(new CardLabelRelationshipProvider(existingEntity.getCard(), existingEntity.getLabels())); - if(assignedUsers != null && !assignedUsers.isEmpty()){ + if (assignedUsers != null && !assignedUsers.isEmpty()) { syncHelper.doSyncFor(new UserDataProvider(this, board, stack, existingEntity, existingEntity.getAssignedUsers())); } syncHelper.fixRelations(new CardUserRelationshipProvider(existingEntity.getCard(), existingEntity.getAssignedUsers())); - if(attachments == null){ + if (attachments == null) { attachments = new ArrayList<>(); } syncHelper.doSyncFor(new AttachmentDataProvider(this, board, stack.getStack(), existingEntity, attachments)); - syncHelper.doSyncFor(new DeckCommentsDataProvider(this, existingEntity.getCard())); + // TODO comments min version - can be removed when app min version == 1.0.0 + Capabilities capabilities = Capabilities.CACHE.get(callback.getAccount().getId()); + if (capabilities != null && capabilities.getDeckVersion().isGreaterOrEqualTo(new Version("1.0.0", 1, 0, 0))) { + DeckLog.verbose("Comments - Version is OK, SYNC"); + syncHelper.doSyncFor(new DeckCommentsDataProvider(this, existingEntity.getCard())); + } else { + DeckLog.verbose("Comments - Version is too low, DONT SYNC"); + } } @Override @@ -162,7 +172,7 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { @Override public List<FullCard> getAllChangedFromDB(DataBaseAdapter dataBaseAdapter, long accountId, Date lastSync) { - if (board == null || stack == null){ + if (board == null || stack == null) { // no cards changed! // (see call from StackDataProvider: goDeeperForUpSync called with null for board.) // so we can just skip this one and proceed with anything else (users, labels). @@ -180,7 +190,7 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { Account account = callback.getAccount(); for (JoinCardWithLabel deletedLabelLocal : deletedLabels) { Card card = dataBaseAdapter.getCardByLocalIdDirectly(account.getId(), deletedLabelLocal.getCardId()); - if (this.stack == null){ + if (this.stack == null) { stack = dataBaseAdapter.getFullStackByLocalIdDirectly(card.getStackId()); } else { stack = this.stack; @@ -193,7 +203,7 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { } JoinCardWithLabel deletedLabel = dataBaseAdapter.getRemoteIdsForJoin(deletedLabelLocal.getCardId(), deletedLabelLocal.getLabelId()); - if (deletedLabel.getStatusEnum() == DBStatus.LOCAL_DELETED){ + if (deletedLabel.getStatusEnum() == DBStatus.LOCAL_DELETED) { if (deletedLabel.getLabelId() == null || deletedLabel.getCardId() == null) { dataBaseAdapter.deleteJoinedLabelForCardPhysicallyByRemoteIDs(account.getId(), deletedLabel.getCardId(), deletedLabel.getLabelId()); } else { @@ -204,7 +214,7 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { } }); } - } else if (deletedLabel.getStatusEnum() == DBStatus.LOCAL_EDITED){ + } else if (deletedLabel.getStatusEnum() == DBStatus.LOCAL_EDITED) { if (deletedLabel.getLabelId() == null || deletedLabel.getCardId() == null) { // Sync next time, the card should be available on server then. continue; @@ -223,7 +233,7 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { List<JoinCardWithUser> deletedUsers = dataBaseAdapter.getAllDeletedUserJoinsWithRemoteIDs(); for (JoinCardWithUser deletedUser : deletedUsers) { Card card = dataBaseAdapter.getCardByRemoteIdDirectly(account.getId(), deletedUser.getCardId()); - if (this.stack == null){ + if (this.stack == null) { stack = dataBaseAdapter.getFullStackByLocalIdDirectly(card.getLocalId()); } else { stack = this.stack; @@ -235,14 +245,14 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { board = this.board; } User user = dataBaseAdapter.getUserByLocalIdDirectly(deletedUser.getUserId()); - if (deletedUser.getStatusEnum() == DBStatus.LOCAL_DELETED){ + if (deletedUser.getStatusEnum() == DBStatus.LOCAL_DELETED) { serverAdapter.unassignUserFromCard(board.getId(), stack.getId(), deletedUser.getCardId(), user.getUid(), new IResponseCallback<Void>(account) { @Override public void onResponse(Void response) { dataBaseAdapter.deleteJoinedUserForCardPhysicallyByRemoteIDs(account.getId(), deletedUser.getCardId(), user.getUid()); } }); - } else if (deletedUser.getStatusEnum() == DBStatus.LOCAL_EDITED){ + } else if (deletedUser.getStatusEnum() == DBStatus.LOCAL_EDITED) { serverAdapter.assignUserToCard(board.getId(), stack.getId(), deletedUser.getCardId(), user.getUid(), new IResponseCallback<Void>(account) { @Override public void onResponse(Void response) { @@ -257,7 +267,7 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { FullCard card = dataBaseAdapter.getFullCardByLocalIdDirectly(account.getId(), attachment.getCardId()); stack = dataBaseAdapter.getFullStackByLocalIdDirectly(card.getCard().getStackId()); board = dataBaseAdapter.getBoardByLocalIdDirectly(stack.getStack().getBoardId()); - syncHelper.doUpSyncFor(new AttachmentDataProvider(this, board, stack.getStack(), card, Collections.singletonList(attachment)) ); + syncHelper.doUpSyncFor(new AttachmentDataProvider(this, board, stack.getStack(), card, Collections.singletonList(attachment))); } List<Card> cardsWithChangedComments = dataBaseAdapter.getCardsWithLocallyChangedCommentsDirectly(account.getId()); @@ -273,26 +283,26 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { List<FullCard> localCards = dataBaseAdapter.getFullCardsForStackDirectly(accountId, stack.getLocalId()); List<FullCard> delta = findDelta(entitiesFromServer, localCards); for (FullCard cardToDelete : delta) { - if (cardToDelete.getId() == null){ + if (cardToDelete.getId() == null) { // not pushed up yet so: continue; } - if (cardToDelete.getStatus() == DBStatus.LOCAL_MOVED.getId()){ - //only delete, if the card isn't availible on server anymore. - serverAdapter.getCard(board.getId(), stack.getId(), cardToDelete.getId(), new IResponseCallback<FullCard>(new Account(accountId)){ - @Override - public void onResponse(FullCard response) { - // do not delete, it's still there and was just moved! - } + if (cardToDelete.getStatus() == DBStatus.LOCAL_MOVED.getId()) { + //only delete, if the card isn't availible on server anymore. + serverAdapter.getCard(board.getId(), stack.getId(), cardToDelete.getId(), new IResponseCallback<FullCard>(new Account(accountId)) { + @Override + public void onResponse(FullCard response) { + // do not delete, it's still there and was just moved! + } - @Override - public void onError(Throwable throwable) { - if (!(throwable instanceof OfflineException)) { - // most likely permission denied, therefore deleted - dataBaseAdapter.deleteCardPhysically(cardToDelete.getCard()); - } + @Override + public void onError(Throwable throwable) { + if (!(throwable instanceof OfflineException)) { + // most likely permission denied, therefore deleted + dataBaseAdapter.deleteCardPhysically(cardToDelete.getCard()); } - }); + } + }); continue; } |