From 35b7314e10797e2ee17f0366b0d454a82bc55a42 Mon Sep 17 00:00:00 2001 From: Simon Njoroge Date: Tue, 16 Nov 2021 15:25:45 +0300 Subject: [PATCH 1/6] Update date formats in daily tallies computation --- .../reporting/dao/ReportIndicatorDaoImpl.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/dao/ReportIndicatorDaoImpl.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/dao/ReportIndicatorDaoImpl.java index ea45a78..7d63a43 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/dao/ReportIndicatorDaoImpl.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/dao/ReportIndicatorDaoImpl.java @@ -99,7 +99,7 @@ public void generateDailyIndicatorTallies(String lastProcessedDate) { for (Map.Entry dates : reportEventDates.entrySet()) { if (dates.getValue().getTime() != timeNow.getTime()) { - lastUpdatedDate = new SimpleDateFormat(eventDateFormat, Locale.getDefault()).format(dates.getValue()); + lastUpdatedDate = new SimpleDateFormat(eventDateFormat, Locale.ENGLISH).format(dates.getValue()); } saveTallies(indicatorQueries, dates, database, executedQueries); } @@ -163,7 +163,7 @@ protected void saveTallies(Map indicatorQueries, Map.Ent tally.setGrouping(indicatorQuery.getGrouping()); try { - tally.setCreatedAt(new SimpleDateFormat(DAILY_TALLY_DATE_FORMAT, Locale.getDefault()).parse(dates.getKey())); + tally.setCreatedAt(new SimpleDateFormat(DAILY_TALLY_DATE_FORMAT, Locale.ENGLISH).parse(dates.getKey())); } catch (ParseException e) { tally.setCreatedAt(new Date()); } @@ -197,7 +197,7 @@ protected LinkedHashMap getReportEventDates(@NonNull Date timeNow, eventDate = formatDate(eventDateString, eventDateFormat); updateDate = formatDate(val.get(EventClientRepository.event_column.updatedAt.name()), eventDateFormat); - String keyDate = new SimpleDateFormat(DAILY_TALLY_DATE_FORMAT, Locale.getDefault()).format(eventDate); + String keyDate = new SimpleDateFormat(DAILY_TALLY_DATE_FORMAT, Locale.ENGLISH).format(eventDate); if (reportEventDates.get(keyDate) != null && updateDate != null) { if (reportEventDates.get(keyDate).getTime() < updateDate.getTime()) { @@ -208,7 +208,7 @@ protected LinkedHashMap getReportEventDates(@NonNull Date timeNow, } } - String dateToday = new SimpleDateFormat(DAILY_TALLY_DATE_FORMAT, Locale.getDefault()).format(timeNow); + String dateToday = new SimpleDateFormat(DAILY_TALLY_DATE_FORMAT, Locale.ENGLISH).format(timeNow); if (reportEventDates.get(dateToday) == null) { reportEventDates.put(dateToday, timeNow); @@ -307,7 +307,7 @@ private ArrayList executeQueryAndReturnMultiResult(@NonNull String query @Nullable private Date formatDate(String date, String format) { try { - return new SimpleDateFormat(format, Locale.getDefault()).parse(date); + return new SimpleDateFormat(format, Locale.ENGLISH).parse(date); } catch (ParseException pe) { // Oh no! Timber.e(pe); From ea2a97303c0572a3b529044e05bcf8c0b4b5293c Mon Sep 17 00:00:00 2001 From: Simon Njoroge Date: Wed, 17 Nov 2021 18:02:28 +0300 Subject: [PATCH 2/6] Bump up version --- gradle.properties | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6c71054..40e3d23 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=0.1.5-SNAPSHOT +VERSION_NAME=0.1.6-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Reporting Library @@ -14,5 +14,3 @@ POM_SETTING_DEVELOPER_NAME=OpenSRP Onadev android.useAndroidX=true android.enableJetifier=true org.gradle.jvmargs=-Xmx2048M - - From 8b6a5785f42cd1ccc509d95a6c45c0c2a0af72bd Mon Sep 17 00:00:00 2001 From: Simon Njoroge Date: Tue, 23 Nov 2021 09:40:04 +0300 Subject: [PATCH 3/6] Bump up version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 40e3d23..e8c72a4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=0.1.6-SNAPSHOT +VERSION_NAME=0.1.6 VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Reporting Library From d648c0650e61740e3f91678e1313fcec9aab1066 Mon Sep 17 00:00:00 2001 From: Simon Njoroge Date: Thu, 8 Sep 2022 15:19:18 +0300 Subject: [PATCH 4/6] Update logging to Timber --- .../reporting/job/IndicatorGeneratorJobCreator.java | 7 +++---- .../reporting/job/RecurringIndicatorGeneratingJob.java | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/job/IndicatorGeneratorJobCreator.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/job/IndicatorGeneratorJobCreator.java index 4918acc..0dcb827 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/job/IndicatorGeneratorJobCreator.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/job/IndicatorGeneratorJobCreator.java @@ -1,13 +1,13 @@ package org.smartregister.reporting.job; -import android.util.Log; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.evernote.android.job.Job; import com.evernote.android.job.JobCreator; +import timber.log.Timber; + public class IndicatorGeneratorJobCreator implements JobCreator { @Nullable @Override @@ -16,9 +16,8 @@ public Job create(@NonNull String tag) { case RecurringIndicatorGeneratingJob.TAG: return new RecurringIndicatorGeneratingJob(); default: - Log.d(IndicatorGeneratorJobCreator.class.getCanonicalName(), "Looks like you tried to create a job " + tag + " that is not declared in the Job Creator"); + Timber.d("Looks like you tried to create a job %s that is not declared in the Job Creator", tag); return null; - } } } diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/job/RecurringIndicatorGeneratingJob.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/job/RecurringIndicatorGeneratingJob.java index 1cffdaf..595a347 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/job/RecurringIndicatorGeneratingJob.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/job/RecurringIndicatorGeneratingJob.java @@ -1,7 +1,6 @@ package org.smartregister.reporting.job; import android.content.Intent; -import android.util.Log; import androidx.annotation.NonNull; @@ -9,6 +8,8 @@ import org.smartregister.job.BaseJob; import org.smartregister.reporting.service.IndicatorGeneratorIntentService; +import timber.log.Timber; + public class RecurringIndicatorGeneratingJob extends BaseJob { public static final String TAG = "IndicatorGeneratingJob"; @@ -18,7 +19,7 @@ public class RecurringIndicatorGeneratingJob extends BaseJob { protected Result onRunJob(@NonNull Params params) { Intent intent = new Intent(getApplicationContext(), IndicatorGeneratorIntentService.class); getApplicationContext().startService(intent); - Log.i(TAG, "IndicatorGeneratorIntentService start service called"); + Timber.i("IndicatorGeneratorIntentService start service called"); return params != null && params.getExtras().getBoolean(AllConstants.INTENT_KEY.TO_RESCHEDULE, false) ? Result.RESCHEDULE : Result.SUCCESS; } } From fd4f59a78996d8e84af291677ed8179c2fd89833 Mon Sep 17 00:00:00 2001 From: Simon Njoroge Date: Thu, 8 Sep 2022 15:21:35 +0300 Subject: [PATCH 5/6] Bump up version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index e8c72a4..40e3d23 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=0.1.6 +VERSION_NAME=0.1.6-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Reporting Library From 379b360ef842e7a05b3b292d84f622747a6b6e7e Mon Sep 17 00:00:00 2001 From: Simon Njoroge Date: Thu, 8 Sep 2022 15:35:21 +0300 Subject: [PATCH 6/6] Use English locale for dates - Refactor logging to Timber --- .../DailyIndicatorCountRepository.java | 48 +++++++++---------- .../smartregister/reporting/dao/DaoTest.java | 4 +- .../DailyIndicatorCountRepositoryTest.java | 37 +++++++------- .../sample/SampleApplication.java | 6 +-- .../sample/repository/SampleRepository.java | 15 ++---- 5 files changed, 46 insertions(+), 64 deletions(-) diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/repository/DailyIndicatorCountRepository.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/repository/DailyIndicatorCountRepository.java index 4afb4a6..9628ed3 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/repository/DailyIndicatorCountRepository.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/repository/DailyIndicatorCountRepository.java @@ -96,28 +96,25 @@ public void add(@Nullable CompositeIndicatorTally indicatorTally) { } SQLiteDatabase database = getWritableDatabase(); - database.delete(Constants.DailyIndicatorCountRepository.INDICATOR_DAILY_TALLY_TABLE - , Constants.DailyIndicatorCountRepository.INDICATOR_CODE + " = ? AND " - + Constants.DailyIndicatorCountRepository.DAY + " = ? " - , new String[]{ + database.delete( + Constants.DailyIndicatorCountRepository.INDICATOR_DAILY_TALLY_TABLE, + Constants.DailyIndicatorCountRepository.INDICATOR_CODE + " = ? AND " + + Constants.DailyIndicatorCountRepository.DAY + " = ? ", + new String[]{ indicatorTally.getIndicatorCode(), - new SimpleDateFormat( - ReportIndicatorDaoImpl.DAILY_TALLY_DATE_FORMAT, - Locale.getDefault()).format(indicatorTally.getCreatedAt() - ) - }); + new SimpleDateFormat(ReportIndicatorDaoImpl.DAILY_TALLY_DATE_FORMAT, Locale.ENGLISH).format(indicatorTally.getCreatedAt()) + } + ); database.insert(Constants.DailyIndicatorCountRepository.INDICATOR_DAILY_TALLY_TABLE, null, createContentValues(indicatorTally)); } - public void updateIndicatorValue(String id, String Value) - { + public void updateIndicatorValue(String id, String Value) { SQLiteDatabase database = getWritableDatabase(); Cursor cursor = null; - try{ - cursor = database.rawQuery("UPDATE "+Constants.DailyIndicatorCountRepository.INDICATOR_DAILY_TALLY_TABLE+" SET "+ Constants.DailyIndicatorCountRepository.INDICATOR_VALUE+" = ? WHERE "+ Constants.DailyIndicatorCountRepository.ID+" = ?",new Object[]{Value,id}); + try { + cursor = database.rawQuery("UPDATE " + Constants.DailyIndicatorCountRepository.INDICATOR_DAILY_TALLY_TABLE + " SET " + Constants.DailyIndicatorCountRepository.INDICATOR_VALUE + " = ? WHERE " + Constants.DailyIndicatorCountRepository.ID + " = ?", new Object[]{Value, id}); cursor.moveToFirst(); - } - catch (Exception ex) { + } catch (Exception ex) { Timber.e(ex.toString()); } finally { if (cursor != null) { @@ -182,7 +179,6 @@ public List> getAllDailyTallies() { return indicatorTallies; } - @NonNull public ArrayList findDaysWithIndicatorCounts(@NonNull SimpleDateFormat dateFormat, @NonNull Date minDate, @NonNull Date maxDate) { return findDaysWithIndicatorCounts(dateFormat, minDate, maxDate, null); @@ -191,7 +187,7 @@ public ArrayList findDaysWithIndicatorCounts(@NonNull SimpleDateFormat dat @NonNull public ArrayList findDaysWithIndicatorCounts(@NonNull SimpleDateFormat dateFormat, @NonNull Date minDate, @NonNull Date maxDate, @Nullable String reportGrouping) { ArrayList daysWithCounts = new ArrayList<>(); - SimpleDateFormat dayFormat = new SimpleDateFormat(ReportIndicatorDaoImpl.DAILY_TALLY_DATE_FORMAT, Locale.getDefault()); + SimpleDateFormat dayFormat = new SimpleDateFormat(ReportIndicatorDaoImpl.DAILY_TALLY_DATE_FORMAT, Locale.ENGLISH); Cursor cursor = null; try { @@ -239,7 +235,7 @@ public ArrayList getIndicatorTalliesForDay(@NonNull Date queryDa public ArrayList getIndicatorTalliesForDay(@NonNull Date queryDate, @Nullable String reportGrouping) { ArrayList tallies = new ArrayList<>(); - SimpleDateFormat dateFormat = new SimpleDateFormat(ReportIndicatorDaoImpl.DAILY_TALLY_DATE_FORMAT, Locale.getDefault()); + SimpleDateFormat dateFormat = new SimpleDateFormat(ReportIndicatorDaoImpl.DAILY_TALLY_DATE_FORMAT, Locale.ENGLISH); Cursor cursor = null; try { Object[] queryArgs = { @@ -442,8 +438,8 @@ public Map getDailyTallies(@NonNull Date date) { try { cursor = database.rawQuery(String.format( - "SELECT %s.%s, %s.%s, %s.%s, %s.%s, %s.%s, %s.%s, %s.%s, %s.%s FROM %s INNER JOIN %s ON %s.%s = %s.%s WHERE %s.%s >= ? AND %s.%s < ?" - , queryArgs), + "SELECT %s.%s, %s.%s, %s.%s, %s.%s, %s.%s, %s.%s, %s.%s, %s.%s FROM %s INNER JOIN %s ON %s.%s = %s.%s WHERE %s.%s >= ? AND %s.%s < ?" + , queryArgs), new String[]{String.valueOf(dayStartMillis), String.valueOf(dayEndMillis)}); if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { @@ -468,7 +464,7 @@ public Map> findTalliesInMonth(@NonNull Date month) } public Map> findTalliesInMonth(@NonNull Date month, @Nullable String reportGrouping) { - SimpleDateFormat dateFormat = new SimpleDateFormat(ReportIndicatorDaoImpl.DAILY_TALLY_DATE_FORMAT, Locale.getDefault()); + SimpleDateFormat dateFormat = new SimpleDateFormat(ReportIndicatorDaoImpl.DAILY_TALLY_DATE_FORMAT, Locale.ENGLISH); Map> talliesFromMonth = new HashMap<>(); Cursor cursor = null; try { @@ -512,8 +508,8 @@ public Map> findTalliesInMonth(@NonNull Date month, }; cursor = database.rawQuery(String.format( - "SELECT %s.%s, %s.%s, %s.%s, %s.%s, %s.%s, %s.%s, %s.%s, %s.%s FROM %s INNER JOIN %s ON %s.%s = %s.%s WHERE %s.%s >= ? AND %s.%s <= ? AND %s.%s %s" - , queryArgs), + "SELECT %s.%s, %s.%s, %s.%s, %s.%s, %s.%s, %s.%s, %s.%s, %s.%s FROM %s INNER JOIN %s ON %s.%s = %s.%s WHERE %s.%s >= ? AND %s.%s <= ? AND %s.%s %s" + , queryArgs), new String[]{dateFormat.format(startDate.getTime()), dateFormat.format(endDate.getTime())}); MultiResultProcessor defaultMultiResultProcessor = ReportingLibrary.getInstance().getDefaultMultiResultProcessor(); @@ -568,7 +564,7 @@ public Map> findTalliesInMonth(@NonNull Date month, } private CompositeIndicatorTally processCursorRow(@NonNull Cursor cursor) { - SimpleDateFormat dateFormat = new SimpleDateFormat(ReportIndicatorDaoImpl.DAILY_TALLY_DATE_FORMAT, Locale.getDefault()); + SimpleDateFormat dateFormat = new SimpleDateFormat(ReportIndicatorDaoImpl.DAILY_TALLY_DATE_FORMAT, Locale.ENGLISH); CompositeIndicatorTally compositeIndicatorTally = new CompositeIndicatorTally(); compositeIndicatorTally.setId(cursor.getLong(cursor.getColumnIndex(Constants.DailyIndicatorCountRepository.ID))); compositeIndicatorTally.setIndicatorCode(cursor.getString(cursor.getColumnIndex(Constants.DailyIndicatorCountRepository.INDICATOR_CODE))); @@ -584,7 +580,7 @@ private CompositeIndicatorTally processCursorRow(@NonNull Cursor cursor) { if (cursor.getColumnIndex(Constants.IndicatorQueryRepository.INDICATOR_QUERY_EXPECTED_INDICATORS) != -1) { compositeIndicatorTally.setExpectedIndicators( (List) new Gson().fromJson(cursor.getString(cursor.getColumnIndex( - Constants.IndicatorQueryRepository.INDICATOR_QUERY_EXPECTED_INDICATORS)) + Constants.IndicatorQueryRepository.INDICATOR_QUERY_EXPECTED_INDICATORS)) , new TypeToken>() { }.getType()) ); @@ -601,7 +597,7 @@ private CompositeIndicatorTally processCursorRow(@NonNull Cursor cursor) { public ContentValues createContentValues(@NonNull CompositeIndicatorTally compositeIndicatorTally) { ContentValues values = new ContentValues(); - SimpleDateFormat dateFormat = new SimpleDateFormat(ReportIndicatorDaoImpl.DAILY_TALLY_DATE_FORMAT, Locale.getDefault()); + SimpleDateFormat dateFormat = new SimpleDateFormat(ReportIndicatorDaoImpl.DAILY_TALLY_DATE_FORMAT, Locale.ENGLISH); values.put(Constants.DailyIndicatorCountRepository.INDICATOR_CODE, compositeIndicatorTally.getIndicatorCode()); if (compositeIndicatorTally.isValueSet()) { diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/dao/DaoTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/dao/DaoTest.java index e80c4b3..304fc14 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/dao/DaoTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/dao/DaoTest.java @@ -104,8 +104,8 @@ public void generateDailyIndicatorTalliesSetsLastProcessedDatePreference() throw // Test data String lastProcessedDate = "2019-01-01 00:00"; LinkedHashMap reportEventDates = new LinkedHashMap<>(); - reportEventDates.put("20190413", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.getDefault()).parse("2019-04-13 12:19:37")); - reportEventDates.put("20190513", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.getDefault()).parse("2019-05-13 12:19:37")); + reportEventDates.put("20190413", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH).parse("2019-04-13 12:19:37")); + reportEventDates.put("20190513", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH).parse("2019-05-13 12:19:37")); Map indicatorQueries = new HashMap<>(); indicatorQueries.put("INDI-100", new IndicatorQuery(1L, "INDI-100", "select count(*) from table", 4, false, null)); diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/repository/DailyIndicatorCountRepositoryTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/repository/DailyIndicatorCountRepositoryTest.java index 68d2a55..0fff104 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/repository/DailyIndicatorCountRepositoryTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/repository/DailyIndicatorCountRepositoryTest.java @@ -94,7 +94,7 @@ public void addIndicatorTallyInvokesWritableDBInsert() throws Exception { CompositeIndicatorTally indicatorTally = Mockito.mock(CompositeIndicatorTally.class); Mockito.when(reportingLibraryInstance.getDateFormat()).thenReturn(dateFormat); - Mockito.when(indicatorTally.getCreatedAt()).thenReturn(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.getDefault()).parse("2019-04-13 12:19:37")); + Mockito.when(indicatorTally.getCreatedAt()).thenReturn(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH).parse("2019-04-13 12:19:37")); dailyIndicatorCountRepositorySpy.add(indicatorTally); @@ -103,29 +103,26 @@ public void addIndicatorTallyInvokesWritableDBInsert() throws Exception { } @Test - public void updateDailyTalliesTest() - { - dailyIndicatorCountRepositorySpy.updateIndicatorValue("1","2.0"); - Mockito.verify(dailyIndicatorCountRepositorySpy,Mockito.times(1)).getWritableDatabase(); - MatrixCursor matrixCursor = new MatrixCursor(new String[]{"id","value"}, 1); - matrixCursor.addRow(new Object[]{"1","2.0"}); + public void updateDailyTalliesTest() { + dailyIndicatorCountRepositorySpy.updateIndicatorValue("1", "2.0"); + Mockito.verify(dailyIndicatorCountRepositorySpy, Mockito.times(1)).getWritableDatabase(); + MatrixCursor matrixCursor = new MatrixCursor(new String[]{"id", "value"}, 1); + matrixCursor.addRow(new Object[]{"1", "2.0"}); Mockito.doReturn(matrixCursor).when(sqLiteDatabase).rawQuery(ArgumentMatchers.anyString(), ArgumentMatchers.isNotNull(Object[].class)); Mockito.verify(sqLiteDatabase, Mockito.times(1)) .rawQuery(ArgumentMatchers.anyString(), ArgumentMatchers.isNotNull(Object[].class)); - - } @Test - public void testCreatTable() - { + public void testCreatTable() { DailyIndicatorCountRepository.createTable(sqLiteDatabase); Mockito.verify(sqLiteDatabase, Mockito.times(2)) - .execSQL(ArgumentMatchers.anyString()); + .execSQL(ArgumentMatchers.anyString()); } + @Test public void getAllDailyTalliesInvokesReadableDBQuery() { dailyIndicatorCountRepositorySpy.getAllDailyTallies(); @@ -153,13 +150,13 @@ public void getAllDailyTalliesShouldProcessAndReturnIndicatorTallies() { ArgumentMatchers.eq("SELECT indicator_daily_tally._id, indicator_daily_tally.indicator_code, indicator_daily_tally.indicator_value, indicator_daily_tally.indicator_value_set, indicator_daily_tally.indicator_grouping, indicator_daily_tally.indicator_is_value_set, indicator_daily_tally.day, indicator_queries.expected_indicators FROM indicator_daily_tally INNER JOIN indicator_queries ON indicator_daily_tally.indicator_code = indicator_queries.indicator_code") , Mockito.nullable(String[].class)); - List> dailyTallies = dailyIndicatorCountRepositorySpy.getAllDailyTallies(); + List> dailyTallies = dailyIndicatorCountRepositorySpy.getAllDailyTallies(); Assert.assertEquals(4, dailyTallies.size()); HashMap> summaryTallies = new HashMap<>(); - for (Map indicatorTallyMap: dailyTallies) { - for (String indicatorCode: indicatorTallyMap.keySet()) { + for (Map indicatorTallyMap : dailyTallies) { + for (String indicatorCode : indicatorTallyMap.keySet()) { List indicatorTallyList = summaryTallies.get(indicatorCode); if (indicatorTallyList == null) { indicatorTallyList = new ArrayList<>(); @@ -283,7 +280,7 @@ public void extractOnlyRequiredIndicatorTalliesAndProvideDefaultShouldReturnZero compositeIndicatorTally.setIndicatorCode("ISN"); compositeIndicatorTally.setCreatedAt(timeNow); - List finalTallies = dailyIndicatorCountRepositorySpy.extractOnlyRequiredIndicatorTalliesAndProvideDefault(compositeIndicatorTally, indicatorTally); + List finalTallies = dailyIndicatorCountRepositorySpy.extractOnlyRequiredIndicatorTalliesAndProvideDefault(compositeIndicatorTally, indicatorTally); Assert.assertEquals(3, finalTallies.size()); Assert.assertEquals("ISN_BCG", finalTallies.get(0).getIndicatorCode()); @@ -310,7 +307,7 @@ public void extractOnlyRequiredIndicatorTalliesAndProvideDefaultShouldReturnZero compositeIndicatorTally.setIndicatorCode("ISN"); compositeIndicatorTally.setCreatedAt(timeNow); - List finalTallies = dailyIndicatorCountRepositorySpy.extractOnlyRequiredIndicatorTalliesAndProvideDefault(compositeIndicatorTally, null); + List finalTallies = dailyIndicatorCountRepositorySpy.extractOnlyRequiredIndicatorTalliesAndProvideDefault(compositeIndicatorTally, null); Assert.assertEquals(3, finalTallies.size()); Assert.assertEquals("ISN_BCG", finalTallies.get(0).getIndicatorCode()); @@ -407,7 +404,7 @@ public void findDaysWithIndicatorCountsWhenGivenValidDateRangeAndDateFormatShoul Date startDate = yyyMMdd.parse("2017-03-01"); Date endDate = yyyMMdd.parse("2017-03-31"); - ArrayList dates = dailyIndicatorCountRepositorySpy.findDaysWithIndicatorCounts(new SimpleDateFormat(ReportIndicatorDaoImpl.DAILY_TALLY_DATE_FORMAT), startDate, endDate); + ArrayList dates = dailyIndicatorCountRepositorySpy.findDaysWithIndicatorCounts(new SimpleDateFormat(ReportIndicatorDaoImpl.DAILY_TALLY_DATE_FORMAT, Locale.ENGLISH), startDate, endDate); Assert.assertEquals(10, dates.size()); Assert.assertEquals(yyyMMdd.parse("2017-03-01").getTime(), dates.get(0).getTime()); @@ -433,8 +430,8 @@ public void getIndicatorTalliesForDayShouldReturn8TalliesWhenGivenValidDateWithT ArrayList talliesForDay = dailyIndicatorCountRepositorySpy.getIndicatorTalliesForDay(new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH).parse("2017-03-10")); HashMap indicatorTallyHashMap = new HashMap<>(); - for (IndicatorTally indicatorTally: talliesForDay) { - indicatorTallyHashMap.put(indicatorTally.getIndicatorCode(),indicatorTally); + for (IndicatorTally indicatorTally : talliesForDay) { + indicatorTallyHashMap.put(indicatorTally.getIndicatorCode(), indicatorTally); } Set indicatorCodes = indicatorTallyHashMap.keySet(); diff --git a/sample/src/main/java/org/smartregister/sample/SampleApplication.java b/sample/src/main/java/org/smartregister/sample/SampleApplication.java index 511e3bf..6299abd 100644 --- a/sample/src/main/java/org/smartregister/sample/SampleApplication.java +++ b/sample/src/main/java/org/smartregister/sample/SampleApplication.java @@ -11,11 +11,8 @@ import org.smartregister.sample.repository.SampleRepository; import org.smartregister.view.activity.DrishtiApplication; - import timber.log.Timber; -import static org.smartregister.util.Log.logError; - public class SampleApplication extends DrishtiApplication { private static final String HAS_LOADED_SAMPLE_DATA = "has_loaded_sample_data"; @@ -61,8 +58,7 @@ public Repository getRepository() { repository = new SampleRepository(getInstance().getApplicationContext(), context); } } catch (UnsatisfiedLinkError e) { - logError("Error on getRepository: " + e); - + Timber.e(e, "Error on getRepository"); } return repository; } diff --git a/sample/src/main/java/org/smartregister/sample/repository/SampleRepository.java b/sample/src/main/java/org/smartregister/sample/repository/SampleRepository.java index c329583..ae8ab26 100644 --- a/sample/src/main/java/org/smartregister/sample/repository/SampleRepository.java +++ b/sample/src/main/java/org/smartregister/sample/repository/SampleRepository.java @@ -1,17 +1,14 @@ package org.smartregister.sample.repository; import android.content.Context; -import android.util.Log; import net.sqlcipher.database.SQLiteDatabase; -import org.joda.time.DateTime; import org.json.JSONException; import org.json.JSONObject; import org.smartregister.AllConstants; import org.smartregister.reporting.ReportingLibrary; import org.smartregister.reporting.domain.CompositeIndicatorTally; -import org.smartregister.reporting.domain.IndicatorTally; import org.smartregister.reporting.repository.DailyIndicatorCountRepository; import org.smartregister.reporting.repository.IndicatorQueryRepository; import org.smartregister.reporting.repository.IndicatorRepository; @@ -113,15 +110,13 @@ private static void addSampleIndicatorDailyTally() { String eventDateFormat = "E MMM dd hh:mm:ss z yyyy"; Date dateCreated = null; try { - dateCreated = new SimpleDateFormat(eventDateFormat, Locale.getDefault()).parse(new Date().toString()); + dateCreated = new SimpleDateFormat(eventDateFormat, Locale.ENGLISH).parse(new Date().toString()); } catch (ParseException pe) { Timber.e(pe.toString()); } dailyIndicatorCountRepository.add(new CompositeIndicatorTally(null, 80, ChartUtil.numericIndicatorKey, dateCreated)); dailyIndicatorCountRepository.add(new CompositeIndicatorTally(null, 60, ChartUtil.pieChartYesIndicatorKey, dateCreated)); dailyIndicatorCountRepository.add(new CompositeIndicatorTally(null, 20, ChartUtil.pieChartNoIndicatorKey, dateCreated)); - - } private static void addSampleEvents() { @@ -155,7 +150,7 @@ private static void addSampleEvent() { try { jsonObject = new JSONObject(eventJSONString); } catch (JSONException ex) { - Log.e(TAG, "Error creating Event JSONObject"); + Timber.e(ex, "Error creating Event JSONObject"); } eventClientRepository.addEvent(baseEntityId, jsonObject); } @@ -166,12 +161,10 @@ public static void addNewEvent() { try { JSONObject jsonObject = new JSONObject(); - jsonObject.put("eventDate", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault()).format(new Date())); + jsonObject.put("eventDate", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH).format(new Date())); eventClientRepository.addEvent(baseEntityId, jsonObject); } catch (JSONException ex) { - Log.e(TAG, Log.getStackTraceString(ex)); + Timber.e(ex); } } - - }