Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue56 #57

Merged
merged 4 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=1.1.13-SNAPSHOT
VERSION_NAME=1.1.14-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Growth Monitoring Application
Expand Down
2 changes: 1 addition & 1 deletion opensrp-growth-monitoring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ allprojects {
}

dependencies {
implementation('org.smartregister:opensrp-client-core:1.8.6-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-core:1.8.16-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.github.bmelnychuk', module: 'atv'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static GrowthMonitoringLibrary getInstance() {

public WeightRepository weightRepository() {
if (weightRepository == null) {
weightRepository = new WeightRepository(getRepository());
weightRepository = new WeightRepository();
}
return weightRepository;
}
Expand All @@ -72,31 +72,31 @@ public Repository getRepository() {

public HeightRepository heightRepository() {
if (heightRepository == null) {
heightRepository = new HeightRepository(getRepository());
heightRepository = new HeightRepository();
}
return heightRepository;
}


public WeightZScoreRepository weightZScoreRepository() {
if (weightZScoreRepository == null) {
weightZScoreRepository = new WeightZScoreRepository(getRepository());
weightZScoreRepository = new WeightZScoreRepository();
}

return weightZScoreRepository;
}

public HeightZScoreRepository heightZScoreRepository() {
if (heightZScoreRepository == null) {
heightZScoreRepository = new HeightZScoreRepository(getRepository());
heightZScoreRepository = new HeightZScoreRepository();
}

return heightZScoreRepository;
}

public EventClientRepository eventClientRepository() {
if (eventClientRepository == null) {
eventClientRepository = new EventClientRepository(getRepository());
eventClientRepository = new EventClientRepository();
}

return eventClientRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.smartregister.location.helper.LocationHelper;
import org.smartregister.repository.AllSharedPreferences;
import org.smartregister.repository.BaseRepository;
import org.smartregister.repository.Repository;

import timber.log.Timber;

Expand All @@ -16,10 +15,6 @@
*/
public abstract class GrowthRepository extends BaseRepository {

public GrowthRepository(Repository repository) {
super(repository);
}

@Nullable
public static String getChildLocationId(@NonNull String defaultLocationId, @NonNull AllSharedPreferences allSharedPreferences) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.smartregister.growthmonitoring.domain.HeightZScore;
import org.smartregister.repository.AllSharedPreferences;
import org.smartregister.repository.EventClientRepository;
import org.smartregister.repository.Repository;

import java.text.ParseException;
import java.util.ArrayList;
Expand Down Expand Up @@ -86,11 +85,6 @@ public class HeightRepository extends GrowthRepository {
"CREATE INDEX " + HEIGHT_TABLE_NAME + "_" + UPDATED_AT_COLUMN + "_index ON " + HEIGHT_TABLE_NAME + "(" +
UPDATED_AT_COLUMN + ");";


public HeightRepository(Repository repository) {
super(repository);
}

public static void createTable(SQLiteDatabase database) {
database.execSQL(HEIGHT_SQL);
database.execSQL(BASE_ENTITY_ID_INDEX);
Expand Down Expand Up @@ -150,7 +144,7 @@ public void add(Height height) {
height.setUpdatedAt(Calendar.getInstance().getTimeInMillis());
}

SQLiteDatabase database = getRepository().getWritableDatabase();
SQLiteDatabase database = getWritableDatabase();
if (height.getId() == null) {
Height sameheight = findUnique(database, height);
if (sameheight != null) {
Expand Down Expand Up @@ -182,7 +176,7 @@ public Height findUnique(SQLiteDatabase db, Height height) {
try {
SQLiteDatabase database = db;
if (database == null) {
database = getRepository().getReadableDatabase();
database = getReadableDatabase();
}

String selection = null;
Expand Down Expand Up @@ -219,7 +213,7 @@ public void update(SQLiteDatabase database, Height height) {
try {
SQLiteDatabase db;
if (database == null) {
db = getRepository().getWritableDatabase();
db = getWritableDatabase();
} else {
db = database;
}
Expand Down Expand Up @@ -321,7 +315,7 @@ public List<Height> findUnSyncedBeforeTime(int hours) {

Long time = calendar.getTimeInMillis();

cursor = getRepository().getReadableDatabase().query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS,
cursor = getReadableDatabase().query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS,
UPDATED_AT_COLUMN + " < ? " + COLLATE_NOCASE + " AND " + SYNC_STATUS + " = ? " + COLLATE_NOCASE,
new String[]{time.toString(), TYPE_Unsynced}, null, null, null, null);
heights = readAllHeights(cursor);
Expand All @@ -340,7 +334,7 @@ public Height findUnSyncedByEntityId(String entityId) {
Cursor cursor = null;
try {

cursor = getRepository().getReadableDatabase().query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS,
cursor = getReadableDatabase().query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS,
BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE + " AND " + SYNC_STATUS + " = ? ",
new String[]{entityId, TYPE_Unsynced}, null, null, UPDATED_AT_COLUMN + COLLATE_NOCASE + " DESC", null);
List<Height> heights = readAllHeights(cursor);
Expand All @@ -361,7 +355,7 @@ public List<Height> findByEntityId(String entityId) {
List<Height> heights = null;
Cursor cursor = null;
try {
cursor = getRepository().getReadableDatabase()
cursor = getReadableDatabase()
.query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS, BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE,
new String[]{entityId}, null, null, null, null);
heights = readAllHeights(cursor);
Expand All @@ -380,7 +374,7 @@ public List<Height> findWithNoZScore() {
List<Height> result = new ArrayList<>();
Cursor cursor = null;
try {
cursor = getRepository().getReadableDatabase()
cursor = getReadableDatabase()
.query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS, Z_SCORE + " = " + DEFAULT_Z_SCORE, null, null, null,
null, null);
result = readAllHeights(cursor);
Expand All @@ -399,7 +393,7 @@ public Height find(Long caseId) {
Height height = null;
Cursor cursor = null;
try {
cursor = getRepository().getReadableDatabase()
cursor = getReadableDatabase()
.query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS, ID_COLUMN + " = ?", new String[]{caseId.toString()},
null, null, null, null);
List<Height> heights = readAllHeights(cursor);
Expand All @@ -420,7 +414,7 @@ public List<Height> findLast5(String entityId) {
List<Height> heightList = new ArrayList<>();
Cursor cursor = null;
try {
cursor = getRepository().getReadableDatabase()
cursor = getReadableDatabase()
.query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS, BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE,
new String[]{entityId}, null, null, UPDATED_AT_COLUMN + COLLATE_NOCASE + " DESC", null);
heightList = readAllHeights(cursor);
Expand All @@ -436,7 +430,7 @@ public List<Height> findLast5(String entityId) {

public void delete(String id) {
try {
getRepository().getWritableDatabase()
getWritableDatabase()
.delete(HEIGHT_TABLE_NAME, ID_COLUMN + " = ? " + COLLATE_NOCASE + " AND " + SYNC_STATUS + " = ? ",
new String[]{id, TYPE_Unsynced});
} catch (Exception e) {
Expand All @@ -448,7 +442,7 @@ public void close(Long caseId) {
try {
ContentValues values = new ContentValues();
values.put(SYNC_STATUS, TYPE_Synced);
getRepository().getWritableDatabase()
getWritableDatabase()
.update(HEIGHT_TABLE_NAME, values, ID_COLUMN + " = ?", new String[]{caseId.toString()});
} catch (Exception e) {
Timber.e(Log.getStackTraceString(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.smartregister.growthmonitoring.domain.HeightZScore;
import org.smartregister.growthmonitoring.util.GrowthMonitoringConstants;
import org.smartregister.repository.BaseRepository;
import org.smartregister.repository.Repository;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -49,9 +48,6 @@ public class HeightZScoreRepository extends BaseRepository {
"CREATE INDEX " + TABLE_NAME + "_" + GrowthMonitoringConstants.ColumnHeaders.COLUMN_MONTH + "_index ON " +
TABLE_NAME + "(" + GrowthMonitoringConstants.ColumnHeaders.COLUMN_MONTH + " COLLATE NOCASE);";

public HeightZScoreRepository(Repository repository) {
super(repository);
}

public static void createTable(SQLiteDatabase database) {
database.execSQL(CREATE_TABLE_QUERY);
Expand All @@ -61,12 +57,11 @@ public static void createTable(SQLiteDatabase database) {

/**
* @param query
*
* @return
*/
public boolean runRawQuery(String query) {
try {
getRepository().getWritableDatabase().execSQL(query);
getWritableDatabase().execSQL(query);
return true;
} catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
Expand All @@ -79,7 +74,7 @@ public List<HeightZScore> findByGender(Gender gender) {
List<HeightZScore> result = new ArrayList<>();
Cursor cursor = null;
try {
SQLiteDatabase database = getRepository().getReadableDatabase();
SQLiteDatabase database = getReadableDatabase();
cursor = database.query(TABLE_NAME, null,
GrowthMonitoringConstants.ColumnHeaders.COLUMN_SEX + " = ? " + COLLATE_NOCASE,
new String[]{gender.name()}, null, null, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.smartregister.growthmonitoring.domain.WeightZScore;
import org.smartregister.repository.AllSharedPreferences;
import org.smartregister.repository.EventClientRepository;
import org.smartregister.repository.Repository;

import java.text.ParseException;
import java.util.ArrayList;
Expand Down Expand Up @@ -85,11 +84,6 @@ public class WeightRepository extends GrowthRepository {
"CREATE INDEX " + WEIGHT_TABLE_NAME + "_" + UPDATED_AT_COLUMN + "_index ON " + WEIGHT_TABLE_NAME + "(" +
UPDATED_AT_COLUMN + ");";


public WeightRepository(Repository repository) {
super(repository);
}

public static void createTable(SQLiteDatabase database) {
database.execSQL(WEIGHT_SQL);
database.execSQL(BASE_ENTITY_ID_INDEX);
Expand Down Expand Up @@ -148,7 +142,7 @@ public void add(Weight weight) {
weight.setUpdatedAt(Calendar.getInstance().getTimeInMillis());
}

SQLiteDatabase database = getRepository().getWritableDatabase();
SQLiteDatabase database = getWritableDatabase();
if (weight.getId() == null) {
Weight sameWeight = findUnique(database, weight);
if (sameWeight != null) {
Expand Down Expand Up @@ -180,7 +174,7 @@ public Weight findUnique(SQLiteDatabase db, Weight weight) {
try {
SQLiteDatabase database = db;
if (database == null) {
database = getRepository().getReadableDatabase();
database = getReadableDatabase();
}

String selection = null;
Expand Down Expand Up @@ -218,7 +212,7 @@ public Weight findUniqueByDate(SQLiteDatabase db, String baseEntityId, Date enco

SQLiteDatabase database = db;
if (database == null) {
database = getRepository().getReadableDatabase();
database = getReadableDatabase();
}

String selection = BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE + " AND strftime('%d-%m-%Y', datetime(" + DATE + "/1000, 'unixepoch')) = strftime('%d-%m-%Y', datetime(?/1000, 'unixepoch')) " + COLLATE_NOCASE;
Expand All @@ -245,7 +239,7 @@ public void update(SQLiteDatabase database, Weight weight) {
try {
SQLiteDatabase db;
if (database == null) {
db = getRepository().getWritableDatabase();
db = getWritableDatabase();
} else {
db = database;
}
Expand Down Expand Up @@ -347,7 +341,7 @@ public List<Weight> findUnSyncedBeforeTime(int hours) {

long time = calendar.getTimeInMillis();

cursor = getRepository().getReadableDatabase().query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS,
cursor = getReadableDatabase().query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS,
UPDATED_AT_COLUMN + " < ? " + COLLATE_NOCASE + " AND " + SYNC_STATUS + " = ? " + COLLATE_NOCASE,
new String[]{Long.toString(time), TYPE_Unsynced}, null, null, null, null);
weights = readAllWeights(cursor);
Expand All @@ -366,7 +360,7 @@ public Weight findUnSyncedByEntityId(String entityId) {
Cursor cursor = null;
try {

cursor = getRepository().getReadableDatabase().query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS,
cursor = getReadableDatabase().query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS,
BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE + " AND " + SYNC_STATUS + " = ? ",
new String[]{entityId, TYPE_Unsynced}, null, null, UPDATED_AT_COLUMN + COLLATE_NOCASE + " DESC", null);
List<Weight> weights = readAllWeights(cursor);
Expand All @@ -387,7 +381,7 @@ public List<Weight> findByEntityId(String entityId) {
List<Weight> weights = null;
Cursor cursor = null;
try {
cursor = getRepository().getReadableDatabase()
cursor = getReadableDatabase()
.query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS, BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE,
new String[]{entityId}, null, null, null, null);
weights = readAllWeights(cursor);
Expand All @@ -406,7 +400,7 @@ public List<Weight> findWithNoZScore() {
List<Weight> result = new ArrayList<>();
Cursor cursor = null;
try {
cursor = getRepository().getReadableDatabase()
cursor = getReadableDatabase()
.query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS, Z_SCORE + " = " + DEFAULT_Z_SCORE, null, null, null,
null, null);
result = readAllWeights(cursor);
Expand All @@ -425,7 +419,7 @@ public Weight find(Long caseId) {
Weight weight = null;
Cursor cursor = null;
try {
cursor = getRepository().getReadableDatabase()
cursor = getReadableDatabase()
.query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS, ID_COLUMN + " = ?", new String[]{caseId.toString()},
null, null, null, null);
List<Weight> weights = readAllWeights(cursor);
Expand All @@ -446,7 +440,7 @@ public List<Weight> findLast5(String entityid) {
List<Weight> weightList = new ArrayList<>();
Cursor cursor = null;
try {
cursor = getRepository().getReadableDatabase()
cursor = getReadableDatabase()
.query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS, BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE,
new String[]{entityid}, null, null, UPDATED_AT_COLUMN + COLLATE_NOCASE + " DESC", null);
weightList = readAllWeights(cursor);
Expand All @@ -462,7 +456,7 @@ public List<Weight> findLast5(String entityid) {

public void delete(String id) {
try {
getRepository().getWritableDatabase()
getWritableDatabase()
.delete(WEIGHT_TABLE_NAME, ID_COLUMN + " = ? " + COLLATE_NOCASE + " AND " + SYNC_STATUS + " = ? ",
new String[]{id, TYPE_Unsynced});
} catch (Exception e) {
Expand All @@ -474,7 +468,7 @@ public void close(Long caseId) {
try {
ContentValues values = new ContentValues();
values.put(SYNC_STATUS, TYPE_Synced);
getRepository().getWritableDatabase()
getWritableDatabase()
.update(WEIGHT_TABLE_NAME, values, ID_COLUMN + " = ?", new String[]{caseId.toString()});
} catch (Exception e) {
Timber.e(Log.getStackTraceString(e));
Expand Down
Loading