diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-11-22 21:02:12 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-11-22 21:02:36 +0300 |
commit | 2fabfcc0c295917b041ad1f881fde4ded28ffe3d (patch) | |
tree | 85369bb28c49208fa831454a49a50364192dfcbf /app/src/main/java/it/niedermann | |
parent | 0ec28927d9a3560782fad60db1fdee364dc80bcf (diff) |
Improve logging and annotate Nullability
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/main/java/it/niedermann')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/SyncHelper.java | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/SyncHelper.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/SyncHelper.java index 7a88128e0..17c0de2cf 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/SyncHelper.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/SyncHelper.java @@ -1,5 +1,8 @@ package it.niedermann.nextcloud.deck.persistence.sync.helpers; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException; import java.net.HttpURLConnection; @@ -32,7 +35,7 @@ public class SyncHelper { } // Sync Server -> App - public <T extends IRemoteEntity> void doSyncFor(final AbstractSyncDataProvider<T> provider) { + public <T extends IRemoteEntity> void doSyncFor(@NonNull final AbstractSyncDataProvider<T> provider) { provider.registerChildInParent(provider); provider.getAllFromServer(serverAdapter, dataBaseAdapter, accountId, new IResponseCallback<List<T>>(account) { @Override @@ -53,11 +56,11 @@ public class SyncHelper { } else { //TODO: how to handle deletes? what about archived? if (existingEntity.getStatus() != DBStatus.UP_TO_DATE.getId()) { - DeckLog.log("Conflicting changes on entity: " + existingEntity); + DeckLog.warn("Conflicting changes on entity: " + existingEntity); // TODO: what to do? } else { if (entityFromServer.getEtag() != null && entityFromServer.getEtag().equals(existingEntity.getEtag())) { - DeckLog.info("["+provider.getClass().getSimpleName()+"] ETags do match! skipping Entitiy with localId: "+existingEntity.getLocalId()); + DeckLog.log("[" + provider.getClass().getSimpleName() + "] ETags do match! skipping " + existingEntity.getClass().getSimpleName() + " with localId: " + existingEntity.getLocalId()); continue; } provider.updateInDB(dataBaseAdapter, accountId, applyUpdatesFromRemote(provider, existingEntity, entityFromServer, accountId), false); @@ -81,7 +84,7 @@ public class SyncHelper { if (throwable.getClass() == NextcloudHttpRequestFailedException.class) { NextcloudHttpRequestFailedException requestFailedException = (NextcloudHttpRequestFailedException) throwable; if (HttpURLConnection.HTTP_NOT_MODIFIED == requestFailedException.getStatusCode()){ - DeckLog.info("["+provider.getClass().getSimpleName()+"] ETags do match! skipping this one."); + DeckLog.log("[" + provider.getClass().getSimpleName() + "] ETags do match! skipping this one."); // well, etags say we're fine here. no need to go deeper. provider.childDone(provider, responseCallback, false); return; @@ -94,12 +97,12 @@ public class SyncHelper { } // Sync App -> Server - public <T extends IRemoteEntity> void doUpSyncFor(AbstractSyncDataProvider<T> provider) { + public <T extends IRemoteEntity> void doUpSyncFor(@NonNull AbstractSyncDataProvider<T> provider) { doUpSyncFor(provider, null); } - public <T extends IRemoteEntity> void doUpSyncFor(AbstractSyncDataProvider<T> provider, CountDownLatch countDownLatch) { - List<T> allFromDB = provider.getAllChangedFromDB(dataBaseAdapter, accountId, lastSync); + public <T extends IRemoteEntity> void doUpSyncFor(@NonNull AbstractSyncDataProvider<T> provider, @Nullable CountDownLatch countDownLatch) { + final List<T> allFromDB = provider.getAllChangedFromDB(dataBaseAdapter, accountId, lastSync); if (allFromDB != null && !allFromDB.isEmpty()) { for (T entity : allFromDB) { if (entity.getId() != null) { @@ -123,7 +126,7 @@ public class SyncHelper { } } - private <T extends IRemoteEntity> IResponseCallback<Void> getDeleteCallback(AbstractSyncDataProvider<T> provider, T entity) { + private <T extends IRemoteEntity> IResponseCallback<Void> getDeleteCallback(@NonNull AbstractSyncDataProvider<T> provider, T entity) { return new IResponseCallback<Void>(account) { @Override public void onResponse(Void response) { @@ -139,7 +142,7 @@ public class SyncHelper { }; } - private <T extends IRemoteEntity> IResponseCallback<T> getUpdateCallback(AbstractSyncDataProvider<T> provider, T entity, CountDownLatch countDownLatch) { + private <T extends IRemoteEntity> IResponseCallback<T> getUpdateCallback(@NonNull AbstractSyncDataProvider<T> provider, @NonNull T entity, @Nullable CountDownLatch countDownLatch) { return new IResponseCallback<T>(account) { @Override public void onResponse(T response) { @@ -165,13 +168,13 @@ public class SyncHelper { }; } - public void fixRelations(IRelationshipProvider relationshipProvider) { + public void fixRelations(@NonNull IRelationshipProvider relationshipProvider) { // this is OK, since the delete only affects records with status UP_TO_DATE relationshipProvider.deleteAllExisting(dataBaseAdapter, accountId); relationshipProvider.insertAllNecessary(dataBaseAdapter, accountId); } - private <T extends IRemoteEntity> T applyUpdatesFromRemote(AbstractSyncDataProvider<T> provider, T localEntity, T remoteEntity, Long accountId) { + private <T extends IRemoteEntity> T applyUpdatesFromRemote(@NonNull AbstractSyncDataProvider<T> provider, @NonNull T localEntity, @NonNull T remoteEntity, @NonNull Long accountId) { if (!accountId.equals(localEntity.getAccountId())) { throw new IllegalArgumentException("IDs of Accounts are not matching! WTF are you doin?!"); } @@ -180,7 +183,7 @@ public class SyncHelper { return remoteEntity; } - public SyncHelper setResponseCallback(IResponseCallback<Boolean> callback) { + public SyncHelper setResponseCallback(@NonNull IResponseCallback<Boolean> callback) { this.responseCallback = callback; this.account = responseCallback.getAccount(); accountId = account.getId(); |