From d9d8de0a53fd18e3e6e0bcdb86bdc6c0bb70f90f Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Thu, 20 Feb 2020 09:48:05 +0300 Subject: [PATCH 1/4] Make height & weight sync time configurable in client apps Increment version to 1.1.18r1-GIZ-0.2.7r11-SNAPSHOT --- gradle.properties | 2 +- .../growthmonitoring/GrowthMonitoringLibrary.java | 10 ++++++++++ .../service/intent/HeightIntentService.java | 2 +- .../service/intent/WeightIntentService.java | 2 +- .../util/GrowthMonitoringConstants.java | 2 -- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8fbbee2..63a6b8d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.1.18-SNAPSHOT +VERSION_NAME=1.1.18r1-GIZ-0.2.7r11-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Growth Monitoring Application diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/GrowthMonitoringLibrary.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/GrowthMonitoringLibrary.java index 0b231e4..80056db 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/GrowthMonitoringLibrary.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/GrowthMonitoringLibrary.java @@ -28,6 +28,8 @@ public class GrowthMonitoringLibrary { private int databaseVersion; private AppProperties appProperties; + private int growthMonitoringSyncTime = BuildConfig.GROWTH_MONITORING_SYNC_TIME; + private GrowthMonitoringLibrary(Context context, Repository repository, int applicationVersion, int databaseVersion) { this.repository = repository; this.context = context; @@ -125,4 +127,12 @@ public AppProperties getAppProperties() { public void setAppProperties(AppProperties appProperties) { this.appProperties = appProperties; } + + public int getGrowthMonitoringSyncTime() { + return growthMonitoringSyncTime; + } + + public void setGrowthMonitoringSyncTime(int growthMonitoringSyncTime) { + this.growthMonitoringSyncTime = growthMonitoringSyncTime; + } } diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/HeightIntentService.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/HeightIntentService.java index a44838b..f1f75b9 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/HeightIntentService.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/HeightIntentService.java @@ -40,7 +40,7 @@ protected void onHandleIntent(Intent intent) { try { List heights = - heightRepository.findUnSyncedBeforeTime(GrowthMonitoringConstants.GROWTH_MONITORING_SYNC_TIME); + heightRepository.findUnSyncedBeforeTime(GrowthMonitoringLibrary.getInstance().getGrowthMonitoringSyncTime()); if (!heights.isEmpty()) { for (Height height : heights) { diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/WeightIntentService.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/WeightIntentService.java index 62e0aaa..b12aaa3 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/WeightIntentService.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/WeightIntentService.java @@ -40,7 +40,7 @@ protected void onHandleIntent(Intent intent) { try { List weights = - weightRepository.findUnSyncedBeforeTime(GrowthMonitoringConstants.GROWTH_MONITORING_SYNC_TIME); + weightRepository.findUnSyncedBeforeTime(GrowthMonitoringLibrary.getInstance().getGrowthMonitoringSyncTime()); if (!weights.isEmpty()) { for (Weight weight : weights) { diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/util/GrowthMonitoringConstants.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/util/GrowthMonitoringConstants.java index 9b98135..922090f 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/util/GrowthMonitoringConstants.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/util/GrowthMonitoringConstants.java @@ -1,6 +1,5 @@ package org.smartregister.growthmonitoring.util; -import org.smartregister.growthmonitoring.BuildConfig; /** * Created by keyman on 26/07/2017. @@ -12,7 +11,6 @@ public class GrowthMonitoringConstants { public static final String CHILD_TABLE_NAME = "ec_client"; - public static final int GROWTH_MONITORING_SYNC_TIME = BuildConfig.GROWTH_MONITORING_SYNC_TIME; public static final String FIRST_NAME = "first_name"; public static final String LAST_NAME = "last_name"; public static final String FEMALE = "female"; From 8abdb5dd6ec4c0fb1f68838f800ca3770050371b Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Sat, 22 Feb 2020 11:04:08 +0300 Subject: [PATCH 2/4] Change sync time to make it configurable to largest minutes --- .../GrowthMonitoringLibrary.java | 20 +++++++++++++++---- .../repository/HeightRepository.java | 6 +++--- .../repository/WeightRepository.java | 4 ++-- .../service/intent/HeightIntentService.java | 6 +++--- .../service/intent/WeightIntentService.java | 4 ++-- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/GrowthMonitoringLibrary.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/GrowthMonitoringLibrary.java index 80056db..a06a197 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/GrowthMonitoringLibrary.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/GrowthMonitoringLibrary.java @@ -1,5 +1,7 @@ package org.smartregister.growthmonitoring; +import android.support.annotation.NonNull; + import org.smartregister.Context; import org.smartregister.growthmonitoring.repository.HeightRepository; import org.smartregister.growthmonitoring.repository.HeightZScoreRepository; @@ -10,6 +12,8 @@ import org.smartregister.repository.EventClientRepository; import org.smartregister.repository.Repository; +import java.util.concurrent.TimeUnit; + /** * Created by koros on 2/3/16. */ @@ -28,7 +32,7 @@ public class GrowthMonitoringLibrary { private int databaseVersion; private AppProperties appProperties; - private int growthMonitoringSyncTime = BuildConfig.GROWTH_MONITORING_SYNC_TIME; + private long growthMonitoringSyncTime = -1; private GrowthMonitoringLibrary(Context context, Repository repository, int applicationVersion, int databaseVersion) { this.repository = repository; @@ -128,11 +132,19 @@ public void setAppProperties(AppProperties appProperties) { this.appProperties = appProperties; } - public int getGrowthMonitoringSyncTime() { + public long getGrowthMonitoringSyncTime() { + if (growthMonitoringSyncTime == -1) { + setGrowthMonitoringSyncTime(BuildConfig.GROWTH_MONITORING_SYNC_TIME); + } + return growthMonitoringSyncTime; } - public void setGrowthMonitoringSyncTime(int growthMonitoringSyncTime) { - this.growthMonitoringSyncTime = growthMonitoringSyncTime; + public void setGrowthMonitoringSyncTime(int growthMonitoringSyncTimeInHours) { + setGrowthMonitoringSyncTime(growthMonitoringSyncTimeInHours, TimeUnit.HOURS); + } + + public void setGrowthMonitoringSyncTime(int growthMonitoringSyncTime, @NonNull TimeUnit timeUnit) { + this.growthMonitoringSyncTime = timeUnit.toMinutes(growthMonitoringSyncTime); } } diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/HeightRepository.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/HeightRepository.java index 17af913..def4d26 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/HeightRepository.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/HeightRepository.java @@ -305,13 +305,13 @@ private void getHeight(Cursor cursor, List heights, Double zScore, Date heights.add(height); } - public List findUnSyncedBeforeTime(int hours) { + public List findUnSyncedBeforeTime(int minutes) { List heights = new ArrayList<>(); Cursor cursor = null; - try { + try { Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.HOUR_OF_DAY, -hours); + calendar.add(Calendar.MINUTE, -minutes); Long time = calendar.getTimeInMillis(); diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/WeightRepository.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/WeightRepository.java index c5d8471..f057b3a 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/WeightRepository.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/WeightRepository.java @@ -331,13 +331,13 @@ private void getWeight(Cursor cursor, List weights, Double zScore, Date weights.add(weight); } - public List findUnSyncedBeforeTime(int hours) { + public List findUnSyncedBeforeTime(int minutes) { List weights = new ArrayList<>(); Cursor cursor = null; try { Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.HOUR_OF_DAY, -hours); + calendar.add(Calendar.MINUTE, -minutes); long time = calendar.getTimeInMillis(); diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/HeightIntentService.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/HeightIntentService.java index f1f75b9..8f66d7f 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/HeightIntentService.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/HeightIntentService.java @@ -40,7 +40,7 @@ protected void onHandleIntent(Intent intent) { try { List heights = - heightRepository.findUnSyncedBeforeTime(GrowthMonitoringLibrary.getInstance().getGrowthMonitoringSyncTime()); + heightRepository.findUnSyncedBeforeTime((int) GrowthMonitoringLibrary.getInstance().getGrowthMonitoringSyncTime()); if (!heights.isEmpty()) { for (Height height : heights) { @@ -57,9 +57,9 @@ protected void onHandleIntent(Intent intent) { //Zscore JSONObject zScoreObject = new JSONObject(); zScoreObject.put(GrowthMonitoringConstants.JsonForm.KEY, "Z_Score_Height_Age"); - zScoreObject.put(GrowthMonitoringConstants.JsonForm.OPENMRS_ENTITY, "concept"); + zScoreObject.put(GrowthMonitoringConstants.JsonForm.OPENMRS_ENTITY, ""); zScoreObject.put(GrowthMonitoringConstants.JsonForm.OPENMRS_ENTITY_ID, - "159429AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); + ""); zScoreObject.put(GrowthMonitoringConstants.JsonForm.OPENMRS_ENTITY_PARENT, ""); zScoreObject.put(GrowthMonitoringConstants.JsonForm.OPENMRS_DATA_TYPE, "calculation"); zScoreObject.put(GrowthMonitoringConstants.JsonForm.VALUE, height.getZScore()); diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/WeightIntentService.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/WeightIntentService.java index b12aaa3..909562d 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/WeightIntentService.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/service/intent/WeightIntentService.java @@ -40,7 +40,7 @@ protected void onHandleIntent(Intent intent) { try { List weights = - weightRepository.findUnSyncedBeforeTime(GrowthMonitoringLibrary.getInstance().getGrowthMonitoringSyncTime()); + weightRepository.findUnSyncedBeforeTime((int) GrowthMonitoringLibrary.getInstance().getGrowthMonitoringSyncTime()); if (!weights.isEmpty()) { for (Weight weight : weights) { @@ -59,7 +59,7 @@ protected void onHandleIntent(Intent intent) { zScoreObject.put(GrowthMonitoringConstants.JsonForm.KEY, "Z_Score_Weight_Age"); zScoreObject.put(GrowthMonitoringConstants.JsonForm.OPENMRS_ENTITY, "concept"); zScoreObject.put(GrowthMonitoringConstants.JsonForm.OPENMRS_ENTITY_ID, - "159428AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); + "1854AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); zScoreObject.put(GrowthMonitoringConstants.JsonForm.OPENMRS_ENTITY_PARENT, ""); zScoreObject.put(GrowthMonitoringConstants.JsonForm.OPENMRS_DATA_TYPE, "calculation"); zScoreObject.put(GrowthMonitoringConstants.JsonForm.VALUE, weight.getZScore()); From 2512880d7d0f7766a6034bbd66e085194338a77f Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Sat, 22 Feb 2020 11:14:25 +0300 Subject: [PATCH 3/4] Change versionName to 1.1.18r2-GIZ-0.2.8r1-SNAPSHOT --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 63a6b8d..7bcc001 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.1.18r1-GIZ-0.2.7r11-SNAPSHOT +VERSION_NAME=1.1.18r2-GIZ-0.2.8r1-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Growth Monitoring Application From 05928df7e442c325f9e59658e807850d8e9e2338 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Thu, 27 Feb 2020 13:21:10 +0300 Subject: [PATCH 4/4] Add GrowthMonitoringLibrary.getGrowthMonitoringSyncTime test Increment library version to 1.1.19 --- gradle.properties | 2 +- .../GrowthMonitoringLibraryTest.java | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 opensrp-growth-monitoring/src/test/java/org/smartregister/growthmonitoring/GrowthMonitoringLibraryTest.java diff --git a/gradle.properties b/gradle.properties index 7bcc001..8df1059 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.1.18r2-GIZ-0.2.8r1-SNAPSHOT +VERSION_NAME=1.1.19-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Growth Monitoring Application diff --git a/opensrp-growth-monitoring/src/test/java/org/smartregister/growthmonitoring/GrowthMonitoringLibraryTest.java b/opensrp-growth-monitoring/src/test/java/org/smartregister/growthmonitoring/GrowthMonitoringLibraryTest.java new file mode 100644 index 0000000..4c09730 --- /dev/null +++ b/opensrp-growth-monitoring/src/test/java/org/smartregister/growthmonitoring/GrowthMonitoringLibraryTest.java @@ -0,0 +1,40 @@ +package org.smartregister.growthmonitoring; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; +import org.robolectric.util.ReflectionHelpers; +import org.smartregister.Context; +import org.smartregister.repository.Repository; + +import static org.junit.Assert.assertEquals; + +@RunWith(RobolectricTestRunner.class) +@Config(sdk = {27}) +public class GrowthMonitoringLibraryTest { + + @Rule + public MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Before + public void setUp() throws Exception { + GrowthMonitoringLibrary.init(Mockito.mock(Context.class), Mockito.mock(Repository.class), 1, 1); + } + + @After + public void tearDown() throws Exception { + ReflectionHelpers.setStaticField(GrowthMonitoringLibrary.class, "instance", null); + } + + @Test + public void getGrowthMonitoringSyncTimeShouldReturnDefault15hoursInMinutes() { + assertEquals(60 * 15, GrowthMonitoringLibrary.getInstance().getGrowthMonitoringSyncTime()); + } +} \ No newline at end of file