From 2e8156b3d4459b026bffd7c2c653cd795115de80 Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Mon, 19 Jul 2021 09:21:22 +0300 Subject: [PATCH 01/16] Saves sync configuration --- .../chw/application/ChwSyncConfiguration.java | 17 +++++++++---- .../org/smartregister/chw/dao/EventDao.java | 25 +++++++++++++++++++ .../chw/sync/ChwSyncIntentService.java | 19 ++++++++++++++ 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java b/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java index 81bd40e42c..b444c69f6a 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java @@ -8,6 +8,7 @@ import org.smartregister.chw.BuildConfig; import org.smartregister.chw.activity.LoginActivity; import org.smartregister.location.helper.LocationHelper; +import org.smartregister.repository.AllSharedPreferences; import org.smartregister.view.activity.BaseLoginActivity; import java.util.List; @@ -30,15 +31,21 @@ public SyncFilter getSyncFilterParam() { @Override public String getSyncFilterValue() { - String providerId = org.smartregister.Context.getInstance().allSharedPreferences().fetchRegisteredANM(); - String userLocationId = org.smartregister.Context.getInstance().allSharedPreferences().fetchUserLocalityId(providerId); + String providerId = allSharedPreferences().fetchRegisteredANM(); + String locationId = allSharedPreferences().fetchDefaultLocalityId(providerId); + if(StringUtils.isBlank(locationId)) locationId = allSharedPreferences().fetchUserLocalityId(providerId); + List locationIds = LocationHelper.getInstance().locationsFromHierarchy(true, null); if (!isEmptyCollection(locationIds)) { - int index = locationIds.indexOf(userLocationId); + int index = locationIds.indexOf(locationId); List subLocationIds = locationIds.subList(index, locationIds.size()); return StringUtils.join(subLocationIds, ","); } - return userLocationId; + return locationId; + } + + private AllSharedPreferences allSharedPreferences(){ + return org.smartregister.Context.getInstance().allSharedPreferences(); } @Override @@ -73,7 +80,7 @@ public boolean updateClientDetailsTable() { @Override public boolean isSyncUsingPost() { - return !BuildConfig.DEBUG && ChwApplication.getApplicationFlavor().syncUsingPost(); + return ChwApplication.getApplicationFlavor().syncUsingPost(); } @Override diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java b/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java index 813ce7bc22..14118c5575 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java @@ -1,20 +1,45 @@ package org.smartregister.chw.dao; import org.jetbrains.annotations.Nullable; +import org.joda.time.DateTime; import org.json.JSONException; import org.json.JSONObject; import org.smartregister.chw.application.ChwApplication; import org.smartregister.clientandeventmodel.Event; import org.smartregister.dao.AbstractDao; +import org.smartregister.repository.BaseRepository; import org.smartregister.sync.helper.ECSyncHelper; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; +import java.util.Locale; import timber.log.Timber; public class EventDao extends AbstractDao { + /*** + * This method forces the device to resync all the data without an event id + * NB: Critical bug detected on Sync + */ + public static void markEventsForReUpload() { + updateDB("update client set syncStatus = '" + BaseRepository.TYPE_Unsynced + "' where baseEntityId in (select baseEntityId from event where ifnull(eventId,'') = '') "); + updateDB("update ImageList set syncStatus = '" + BaseRepository.TYPE_Unsynced + "' where entityId in (select baseEntityId from event where ifnull(eventId,'') = '') "); + updateDB("update event set syncStatus = '" + BaseRepository.TYPE_Unsynced + "' where ifnull(eventId,'') = '' "); + } + + /*** + * Computes the minimum server Id before any possibly unsynced event found in the database. + * This method should return a NULL value if all events are synced. + * @return + */ + public static Long getMinimumVerifiedServerVersion(){ + String sql = "select max(serverVersion) serverVersion from event where dateCreated <= (select min(dateCreated) minDate from event where ifnull(eventId,'') = '' and syncStatus = 'Synced') "; + DataMap dataMap = c -> { return getCursorLongValue(c, "serverVersion"); }; + return AbstractDao.readSingleValue(sql, dataMap); + } public static List getEvents(String baseEntityID, String eventType, int limit) { String sql = "select json from event where baseEntityId = '" + baseEntityID + "' COLLATE NOCASE and eventType = '" + eventType + "' COLLATE NOCASE order by updatedAt desc limit " + limit; diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/sync/ChwSyncIntentService.java b/opensrp-chw/src/main/java/org/smartregister/chw/sync/ChwSyncIntentService.java index ac65c3db81..92b4535b25 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/sync/ChwSyncIntentService.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/sync/ChwSyncIntentService.java @@ -1,11 +1,30 @@ package org.smartregister.chw.sync; +import org.smartregister.chw.dao.EventDao; import org.smartregister.sync.intent.SyncIntentService; public class ChwSyncIntentService extends SyncIntentService { + @Override + protected void handleSync() { + // fetch the last downloaded serverVersion before any unsyced data + Long serverVersion = EventDao.getMinimumVerifiedServerVersion(); + if (serverVersion != null) + org.smartregister.util.Utils.getAllSharedPreferences().saveLastSyncDate(serverVersion); + + // flag all contentious events as unsynced + EventDao.markEventsForReUpload(); + super.handleSync(); + } + @Override public int getEventPullLimit() { return 1000; } + + + @Override + protected Integer getEventBatchSize(){ + return 250; + } } From e0e8d15f3f78287bdda19e97bf5f0b98e4e516b8 Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Mon, 19 Jul 2021 10:06:43 +0300 Subject: [PATCH 02/16] Update client-core to v2.1.0 --- opensrp-chw/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index 32d95042f0..6051ae5a9d 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -251,8 +251,8 @@ android { resConfigs "en", "fr" dimension = 'baseDimension' applicationIdSuffix ".drc" - versionCode 6 - versionName "1.0.11" + versionCode 8 + versionName "1.0.13" buildConfigField "String", 'opensrp_url', '"https://wcaro-cd.smartregister.org/opensrp/"' buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/drc/"' buildConfigField "String", 'opensrp_url_preview', '"https://wcaro-cd-preview.smartregister.org/opensrp/"' @@ -338,7 +338,7 @@ android { } dependencies { - implementation('org.smartregister:opensrp-client-chw-core:2.0.32-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-chw-core:2.1.0-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'appcompat-v7' exclude group: 'androidx.legacy', module: 'legacy-support-v4' From 5bf26f851338d1f9390730fd625c35fdd2f867d1 Mon Sep 17 00:00:00 2001 From: Allan O Date: Tue, 27 Jul 2021 18:58:51 +0300 Subject: [PATCH 03/16] :zap: Add max connection timeout config override --- opensrp-chw/build.gradle | 2 ++ .../smartregister/chw/application/ChwSyncConfiguration.java | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index 6051ae5a9d..8adf57ac36 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -82,6 +82,7 @@ android { buildConfigField "boolean", "IS_SYNC_SETTINGS", "false" buildConfigField "String", "THINKMD_BASE_URL", '"https://app.africa.thinkmd.tech"' buildConfigField "String", "THINKMD_END_POINT", '"/#/start"' + buildConfigField "int", "MAX_CONNECTION_TIMEOUT", '1' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" javaCompileOptions { annotationProcessorOptions { @@ -262,6 +263,7 @@ android { buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS_DEBUG", '{"Pays" , "Province(DPS)" , "Zone de Sante","Aire de Sante" , "CAC" ,"VILLAGE/COMMUNAUTE"}' buildConfigField "String", 'DEFAULT_LOCATION_DEBUG', '"VILLAGE/COMMUNAUTE"' buildConfigField "String", 'DEFAULT_LOCATION', '"VILLAGE/COMMUNAUTE"' + buildConfigField "int", "MAX_CONNECTION_TIMEOUT", '5' buildConfigField "int", "DATABASE_VERSION", '11' } guinea { diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java b/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java index b444c69f6a..43fd4a42fd 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java @@ -113,6 +113,11 @@ public String getOauthClientSecret() { return BuildConfig.OAUTH_CLIENT_SECRET; } + @Override + public int getConnectTimeout() { + return BuildConfig.MAX_CONNECTION_TIMEOUT * 60000; + } + @Override public Class getAuthenticationActivity() { return LoginActivity.class; From 6e4b3e207f486a2b8b21aa15dcf9af7335f8b215 Mon Sep 17 00:00:00 2001 From: Allan O Date: Tue, 27 Jul 2021 19:34:07 +0300 Subject: [PATCH 04/16] :heavy_minus_sign: Remove bintray repos --- build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index f38fd9b309..33a2c066ed 100644 --- a/build.gradle +++ b/build.gradle @@ -53,9 +53,8 @@ allprojects { maven { url "https://cloudant.github.io/cloudant-sync-eap/repository" } maven { url 'https://maven.fabric.io/public' } maven { url "https://s3.amazonaws.com/repo.commonsware.com" } - maven { url "https://dl.bintray.com/ona/rdt-capture" } + maven { url 'https://nexus.pentaho.org/content/groups/omni/' } maven { url 'https://dl.bintray.com/ibm-watson-health/ibm-fhir-server-releases' } - maven { url "https://dl.bintray.com/ona/kujaku" } } } From 1306f0f424cb1cc5274dd589fa2b69db99877f79 Mon Sep 17 00:00:00 2001 From: Allan O Date: Tue, 27 Jul 2021 19:34:59 +0300 Subject: [PATCH 05/16] :zap: Add max read timeout config --- opensrp-chw/build.gradle | 6 ++++-- .../smartregister/chw/application/ChwSyncConfiguration.java | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index 8adf57ac36..52fc238a3d 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -83,6 +83,7 @@ android { buildConfigField "String", "THINKMD_BASE_URL", '"https://app.africa.thinkmd.tech"' buildConfigField "String", "THINKMD_END_POINT", '"/#/start"' buildConfigField "int", "MAX_CONNECTION_TIMEOUT", '1' + buildConfigField "int", "MAX_READ_TIMEOUT", '1' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" javaCompileOptions { annotationProcessorOptions { @@ -252,8 +253,8 @@ android { resConfigs "en", "fr" dimension = 'baseDimension' applicationIdSuffix ".drc" - versionCode 8 - versionName "1.0.13" + versionCode 9 + versionName "1.0.14" buildConfigField "String", 'opensrp_url', '"https://wcaro-cd.smartregister.org/opensrp/"' buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/drc/"' buildConfigField "String", 'opensrp_url_preview', '"https://wcaro-cd-preview.smartregister.org/opensrp/"' @@ -264,6 +265,7 @@ android { buildConfigField "String", 'DEFAULT_LOCATION_DEBUG', '"VILLAGE/COMMUNAUTE"' buildConfigField "String", 'DEFAULT_LOCATION', '"VILLAGE/COMMUNAUTE"' buildConfigField "int", "MAX_CONNECTION_TIMEOUT", '5' + buildConfigField "int", "MAX_READ_TIMEOUT", '5' buildConfigField "int", "DATABASE_VERSION", '11' } guinea { diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java b/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java index 43fd4a42fd..f8b898ee12 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java @@ -118,6 +118,11 @@ public int getConnectTimeout() { return BuildConfig.MAX_CONNECTION_TIMEOUT * 60000; } + @Override + public int getReadTimeout() { + return BuildConfig.MAX_READ_TIMEOUT * 60000; + } + @Override public Class getAuthenticationActivity() { return LoginActivity.class; From 5df01b3b14ed4f3b475fd2aa5cd54ae69ab3d5d0 Mon Sep 17 00:00:00 2001 From: Allan O Date: Wed, 4 Aug 2021 19:12:56 +0300 Subject: [PATCH 06/16] :arrow_up: Update chw-core dependency --- opensrp-chw/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index 52fc238a3d..11d588c0aa 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -342,7 +342,7 @@ android { } dependencies { - implementation('org.smartregister:opensrp-client-chw-core:2.1.0-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-chw-core:2.1.1-alpha-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'appcompat-v7' exclude group: 'androidx.legacy', module: 'legacy-support-v4' From 269802cadf85340f425c8d11d9a320149aeb0f5a Mon Sep 17 00:00:00 2001 From: Allan O Date: Wed, 4 Aug 2021 19:14:10 +0300 Subject: [PATCH 07/16] :construction: Set has sync status progressbar --- .../chw/custom_view/DefaultNavigationMenuFlv.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/custom_view/DefaultNavigationMenuFlv.java b/opensrp-chw/src/main/java/org/smartregister/chw/custom_view/DefaultNavigationMenuFlv.java index 6699180c2b..fa390d1597 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/custom_view/DefaultNavigationMenuFlv.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/custom_view/DefaultNavigationMenuFlv.java @@ -17,6 +17,11 @@ public List> getSupportedLanguages() { return Arrays.asList(Pair.of("English", Locale.ENGLISH), Pair.of("Français", Locale.FRENCH)); } + @Override + public boolean hasSyncStatusProgressBar() { + return true; + } + @Override public HashMap getTableMapValues() { return new HashMap<>(); From a72aa4f84559156ff7451ff0e708269e0d9a0b8a Mon Sep 17 00:00:00 2001 From: Allan O Date: Mon, 16 Aug 2021 10:27:50 +0300 Subject: [PATCH 08/16] :arrow_up: Update chw-core version --- opensrp-chw/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index 11d588c0aa..f214d8dd94 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -297,7 +297,7 @@ android { buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '500' buildConfigField "String", 'opensrp_url', '"https://wcaro-tg.smartregister.org/opensrp/"' buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/togo/"' - buildConfigField "String", 'opensrp_url_debug', '"https://wcaro-togo-preview.smartregister.org/opensrp/"' + buildConfigField "String", 'opensrp_url_debug', '"https://wcaro-stage.smartregister.org/opensrp/"' buildConfigField "String[]", "LOCATION_HIERACHY", '{"National", "Regional" , "District" , "Formation sanitaire", "Supervisor", "Village" }' buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS_DEBUG", '{"National", "Regional" , "District" , "Formation sanitaire", "Supervisor", "Village"}' buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"National", "Regional" , "District" , "Formation sanitaire", "Supervisor", "Village"}' @@ -342,7 +342,7 @@ android { } dependencies { - implementation('org.smartregister:opensrp-client-chw-core:2.1.1-alpha-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-chw-core:2.1.2-alpha-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'appcompat-v7' exclude group: 'androidx.legacy', module: 'legacy-support-v4' From 2139b94a5df1561d796afea9b5b213a264c9828c Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 19 Aug 2021 10:05:59 +0300 Subject: [PATCH 09/16] :recycle: Remove unused imports --- .../java/org/smartregister/chw/dao/EventDao.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java b/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java index 14118c5575..343cc12fe1 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java @@ -1,7 +1,6 @@ package org.smartregister.chw.dao; import org.jetbrains.annotations.Nullable; -import org.joda.time.DateTime; import org.json.JSONException; import org.json.JSONObject; import org.smartregister.chw.application.ChwApplication; @@ -10,11 +9,8 @@ import org.smartregister.repository.BaseRepository; import org.smartregister.sync.helper.ECSyncHelper; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import java.util.List; -import java.util.Locale; import timber.log.Timber; @@ -35,10 +31,12 @@ public static void markEventsForReUpload() { * This method should return a NULL value if all events are synced. * @return */ - public static Long getMinimumVerifiedServerVersion(){ + public static Long getMinimumVerifiedServerVersion() { String sql = "select max(serverVersion) serverVersion from event where dateCreated <= (select min(dateCreated) minDate from event where ifnull(eventId,'') = '' and syncStatus = 'Synced') "; - DataMap dataMap = c -> { return getCursorLongValue(c, "serverVersion"); }; - return AbstractDao.readSingleValue(sql, dataMap); + DataMap dataMap = c -> { + return getCursorLongValue(c, "serverVersion"); + }; + return AbstractDao.readSingleValue(sql, dataMap); } public static List getEvents(String baseEntityID, String eventType, int limit) { From 90b97b8e551b61e0af486e8d132040188f4bff56 Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 19 Aug 2021 10:20:14 +0300 Subject: [PATCH 10/16] :construction: Implement no sync status bar for BA --- .../org/smartregister/chw/custom_view/NavigationMenuFlv.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/opensrp-chw/src/ba/java/org/smartregister/chw/custom_view/NavigationMenuFlv.java b/opensrp-chw/src/ba/java/org/smartregister/chw/custom_view/NavigationMenuFlv.java index 61ba6450bd..c0a5df02d6 100644 --- a/opensrp-chw/src/ba/java/org/smartregister/chw/custom_view/NavigationMenuFlv.java +++ b/opensrp-chw/src/ba/java/org/smartregister/chw/custom_view/NavigationMenuFlv.java @@ -44,6 +44,11 @@ public boolean hasCommunityResponders() { return true; } + @Override + public boolean hasSyncStatusProgressBar() { + return false; + } + @Override public Intent getStockReportIntent(Activity activity) { return new Intent(activity, CoreStockInventoryReportActivity.class); From f3615e7abcc14d44aedc77065f45a107644bab5c Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 19 Aug 2021 11:00:58 +0300 Subject: [PATCH 11/16] :arrow_up: Update Togo & DRC versions --- opensrp-chw/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index f214d8dd94..48b2277010 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -253,8 +253,8 @@ android { resConfigs "en", "fr" dimension = 'baseDimension' applicationIdSuffix ".drc" - versionCode 9 - versionName "1.0.14" + versionCode 10 + versionName "1.0.15" buildConfigField "String", 'opensrp_url', '"https://wcaro-cd.smartregister.org/opensrp/"' buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/drc/"' buildConfigField "String", 'opensrp_url_preview', '"https://wcaro-cd-preview.smartregister.org/opensrp/"' @@ -291,8 +291,8 @@ android { togo { dimension = 'baseDimension' applicationIdSuffix ".togo" - versionCode 22 - versionName "1.2.4" + versionCode 23 + versionName "1.2.5" buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '1000' buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '500' buildConfigField "String", 'opensrp_url', '"https://wcaro-tg.smartregister.org/opensrp/"' From 320f40031da3789f54d3929f91ccd4d3d68ca99c Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 9 Sep 2021 15:28:29 +0300 Subject: [PATCH 12/16] :construction: Update debug url to preview end-point --- opensrp-chw/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index 48b2277010..6251b114d8 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -311,7 +311,7 @@ android { versionName "0.1.12" buildConfigField "String", 'opensrp_url', '"https://wcaro-liberia.smartregister.org/opensrp/"' buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/liberia/"' - buildConfigField "String", 'opensrp_url_debug', '"https://wcaro-stage.smartregister.org/opensrp/"' + buildConfigField "String", 'opensrp_url_debug', '"https://wcaro-lr-preview.smartregister.org/opensrp/"' buildConfigField "String[]", "LOCATION_HIERACHY", '{"Clinic" , "CHSS" , "CHA"}' buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"Country" , "County" , "District", "Clinics", "CHSS", "Village"}' buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS_DEBUG", '{"Clinic" , "CHSS" , "CHA"}' From ae0c82edc4310df7cacb71556e52f07e1350d183 Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 9 Sep 2021 15:31:09 +0300 Subject: [PATCH 13/16] :wrench: Disable validate user assignments --- .../smartregister/chw/application/ChwSyncConfiguration.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java b/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java index f8b898ee12..fdf0589b1e 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java @@ -127,4 +127,9 @@ public int getReadTimeout() { public Class getAuthenticationActivity() { return LoginActivity.class; } + + @Override + public boolean validateUserAssignments() { + return false; + } } From 34d2c123b506b4e7164f487b7fe55012a7da6084 Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 9 Sep 2021 15:54:22 +0300 Subject: [PATCH 14/16] :wrench: Update CHAD connection and read timeouts --- opensrp-chw/build.gradle | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index 48b2277010..9126955eb3 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -237,8 +237,8 @@ android { chad { dimension = 'baseDimension' applicationIdSuffix ".chad" - versionCode 1 - versionName "1.0.1" + versionCode 2 + versionName "1.0.2" buildConfigField "String", 'opensrp_url', '"https://wcaro-td.smartregister.org/opensrp/"' buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/chad/"' buildConfigField "String", 'opensrp_url_debug', '"https://wcaro-stage.smartregister.org/opensrp/"' @@ -248,6 +248,8 @@ android { buildConfigField "String", 'DEFAULT_LOCATION', '"Village"' buildConfigField "String", 'DEFAULT_LOCATION_DEBUG', '"CHA"' buildConfigField "int", "DATABASE_VERSION", '14' + buildConfigField "int", "MAX_CONNECTION_TIMEOUT", '5' + buildConfigField "int", "MAX_READ_TIMEOUT", '5' } drc { resConfigs "en", "fr" From 231e053471a2da736066887bf95371aa45d1fe5d Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 16 Sep 2021 16:58:46 +0300 Subject: [PATCH 15/16] :arrow_up: Update chw-core version --- opensrp-chw/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index 7f0a3e8df1..b6c1b539a9 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -344,7 +344,7 @@ android { } dependencies { - implementation('org.smartregister:opensrp-client-chw-core:2.1.2-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-chw-core:2.1.3-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'appcompat-v7' exclude group: 'androidx.legacy', module: 'legacy-support-v4' From 2ba9736aa83fb2c1bcf5633c953172bde4afffa4 Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 16 Sep 2021 16:59:18 +0300 Subject: [PATCH 16/16] :white_check_mark: Add EventDao tests --- .../org/smartregister/chw/dao/EventDao.java | 2 +- .../smartregister/chw/dao/EventDaoTest.java | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java b/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java index 343cc12fe1..b1db063555 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java @@ -32,7 +32,7 @@ public static void markEventsForReUpload() { * @return */ public static Long getMinimumVerifiedServerVersion() { - String sql = "select max(serverVersion) serverVersion from event where dateCreated <= (select min(dateCreated) minDate from event where ifnull(eventId,'') = '' and syncStatus = 'Synced') "; + String sql = "select max(serverVersion) serverVersion from event where dateCreated <= (select min(dateCreated) minDate from event where ifnull(eventId,'') = '' and syncStatus = 'Synced') "; DataMap dataMap = c -> { return getCursorLongValue(c, "serverVersion"); }; diff --git a/opensrp-chw/src/test/java/org/smartregister/chw/dao/EventDaoTest.java b/opensrp-chw/src/test/java/org/smartregister/chw/dao/EventDaoTest.java index 94afbbe300..45e3d6bf18 100644 --- a/opensrp-chw/src/test/java/org/smartregister/chw/dao/EventDaoTest.java +++ b/opensrp-chw/src/test/java/org/smartregister/chw/dao/EventDaoTest.java @@ -13,6 +13,7 @@ import org.robolectric.RobolectricTestRunner; import org.smartregister.clientandeventmodel.Event; import org.smartregister.dao.AbstractDao; +import org.smartregister.repository.BaseRepository; import org.smartregister.repository.Repository; import java.util.Arrays; @@ -37,7 +38,7 @@ public void setUp() { } @Test - public void getEvents() { + public void getEventsReturnsCorrectEvents() { MatrixCursor matrixCursor = new MatrixCursor(new String[]{"json"}); matrixCursor.addRow(new Object[]{eventJson}); Mockito.doReturn(matrixCursor).when(database).rawQuery(Mockito.any(), Mockito.any()); @@ -48,7 +49,7 @@ public void getEvents() { } @Test - public void getLatestEvent() { + public void getLatestEventReturnsCorrectEvent() { MatrixCursor matrixCursor = new MatrixCursor(new String[]{"json"}); matrixCursor.addRow(new Object[]{eventJson}); Mockito.doReturn(matrixCursor).when(database).rawQuery(Mockito.any(), Mockito.any()); @@ -56,5 +57,23 @@ public void getLatestEvent() { Assert.assertNotNull(event); } + @Test + public void markEventsForReUploadExecutesCorrectUpdateQueries() { + Mockito.doReturn(database).when(repository).getWritableDatabase(); + EventDao.markEventsForReUpload(); + Mockito.verify(database).rawExecSQL("update client set syncStatus = '" + BaseRepository.TYPE_Unsynced + "' where baseEntityId in (select baseEntityId from event where ifnull(eventId,'') = '') "); + Mockito.verify(database).rawExecSQL("update ImageList set syncStatus = '" + BaseRepository.TYPE_Unsynced + "' where entityId in (select baseEntityId from event where ifnull(eventId,'') = '') "); + Mockito.verify(database).rawExecSQL("update event set syncStatus = '" + BaseRepository.TYPE_Unsynced + "' where ifnull(eventId,'') = '' "); + } + + @Test + public void getMinimumVerifiedServerVersionReturnsCorrectVersion() { + MatrixCursor matrixCursor = new MatrixCursor(new String[]{"serverVersion"}); + matrixCursor.addRow(new Object[]{12324567L}); + Mockito.doReturn(matrixCursor).when(database).rawQuery(Mockito.any(), Mockito.any()); + Long serverVersion = EventDao.getMinimumVerifiedServerVersion(); + Assert.assertNotNull(serverVersion); + Assert.assertTrue(serverVersion.equals(12324567L)); + } } \ No newline at end of file