Skip to content

Commit

Permalink
skip local unsynced tasks when updating from server
Browse files Browse the repository at this point in the history
to allow for the local changes be uploaded to server,..and not reset
  • Loading branch information
LZRS committed Sep 3, 2021
1 parent 2dfd11d commit 0c7d444
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=4.3.20-SNAPSHOT
VERSION_NAME=4.3.21-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Core Application
Expand Down
10 changes: 10 additions & 0 deletions opensrp-app/src/main/java/org/smartregister/SyncConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,14 @@ public List<Pair<String, String>> getGlobalSettingsQueryParams() {
public boolean validateUserAssignments() {
return true;
}


/**
* Specifies whether to skip locally saved task marked as {@link org.smartregister.repository.BaseRepository#TYPE_Unsynced}
* when fetching tasks from the server, during sync
* @return {@link Boolean}
*/
public boolean skipUnsyncedTasksOnFetchFromServer(){
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ private List<Task> batchFetchTasksFromServer(Set<String> planDefinitions, List<S
if (tasks != null && tasks.size() > 0) {
for (Task task : tasks) {
try {
boolean skipUnsynced = CoreLibrary.getInstance().getSyncConfiguration()
.skipUnsyncedTasksOnFetchFromServer();

if (skipUnsynced) {
Task existingTask = taskRepository.getTaskByIdentifier(task.getIdentifier());
if (existingTask != null
&& (existingTask.getSyncStatus().equals(BaseRepository.TYPE_Unsynced)
|| existingTask.getSyncStatus().equals(BaseRepository.TYPE_Created))) {
continue;
}
}
task.setSyncStatus(BaseRepository.TYPE_Synced);
task.setLastModified(new DateTime());
taskRepository.addOrUpdate(task);
Expand Down

0 comments on commit 0c7d444

Please sign in to comment.