Skip to content

Commit 10fc174

Browse files
authored
Merge pull request #1239 from dhis2/androsdk-1129
fix: [ANDROSDK-1129] Include UPLOADING state in the list of uploadable states
2 parents 1334a65 + 610c076 commit 10fc174

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

core/src/main/java/org/hisp/dhis/android/core/common/State.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ public enum State {
6969

7070
public static State[] uploadableStates() {
7171
return new State[] {
72-
TO_POST, TO_UPDATE, SENT_VIA_SMS, SYNCED_VIA_SMS
72+
TO_POST, TO_UPDATE, SENT_VIA_SMS, SYNCED_VIA_SMS, UPLOADING
7373
};
7474
}
7575

7676
public static State[] uploadableStatesIncludingError() {
7777
return new State[] {
78-
TO_POST, TO_UPDATE, SENT_VIA_SMS, SYNCED_VIA_SMS, ERROR, WARNING
78+
TO_POST, TO_UPDATE, SENT_VIA_SMS, SYNCED_VIA_SMS, UPLOADING, ERROR, WARNING
7979
};
8080
}
8181
}

core/src/main/java/org/hisp/dhis/android/core/event/internal/EventStoreImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder;
3737
import org.hisp.dhis.android.core.arch.db.stores.binders.internal.StatementBinder;
3838
import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableDeletableDataObjectStoreImpl;
39+
import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper;
3940
import org.hisp.dhis.android.core.arch.helpers.internal.EnumHelper;
4041
import org.hisp.dhis.android.core.common.IdentifiableColumns;
4142
import org.hisp.dhis.android.core.common.State;
@@ -100,8 +101,10 @@ public Map<String, List<Event>> queryEventsAttachedToEnrollmentToPost() {
100101

101102
@Override
102103
public List<Event> querySingleEventsToPost() {
104+
String states = CollectionsHelper.commaAndSpaceSeparatedArrayValues(
105+
CollectionsHelper.withSingleQuotationMarksArray(EnumHelper.asStringList(State.uploadableStates())));
103106
String singleEventsToPostQuery = QUERY_SINGLE_EVENTS +
104-
" AND (Event.state = '" + State.TO_POST + "' OR Event.state = '" + State.TO_UPDATE + "')";
107+
" AND (Event.state IN (" + states + "))";
105108
return eventListFromQuery(singleEventsToPostQuery);
106109
}
107110

core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeValueStoreImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.hisp.dhis.android.core.arch.db.stores.binders.internal.WhereStatementBinder;
3838
import org.hisp.dhis.android.core.arch.db.stores.internal.ObjectWithoutUidStoreImpl;
3939
import org.hisp.dhis.android.core.arch.db.stores.projections.internal.SingleParentChildProjection;
40+
import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper;
41+
import org.hisp.dhis.android.core.arch.helpers.internal.EnumHelper;
4042
import org.hisp.dhis.android.core.common.State;
4143
import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValue;
4244
import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValueTableInfo;
@@ -98,10 +100,10 @@ public Map<String, List<TrackedEntityAttributeValue>> queryTrackedEntityAttribut
98100
return valueMap;
99101
}
100102

101-
// TODO Could we reuse EnumHelper.asStringList(State.uploadableStates())?
102103
private String teiInUploadableState() {
103-
return "(TrackedEntityInstance.state IN ('" + State.TO_POST + "', '" + State.TO_UPDATE + "', '"
104-
+ State.SENT_VIA_SMS + "', '" + State.SYNCED_VIA_SMS + "'))";
104+
String states = CollectionsHelper.commaAndSpaceSeparatedArrayValues(
105+
CollectionsHelper.withSingleQuotationMarksArray(EnumHelper.asStringList(State.uploadableStates())));
106+
return "(TrackedEntityInstance.state IN (" + states + "))";
105107
}
106108

107109
@Override

core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityDataValueStoreImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import org.hisp.dhis.android.core.arch.db.stores.binders.internal.WhereStatementBinder;
3939
import org.hisp.dhis.android.core.arch.db.stores.internal.ObjectWithoutUidStoreImpl;
4040
import org.hisp.dhis.android.core.arch.db.stores.projections.internal.SingleParentChildProjection;
41+
import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper;
42+
import org.hisp.dhis.android.core.arch.helpers.internal.EnumHelper;
4143
import org.hisp.dhis.android.core.common.State;
4244
import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue;
4345
import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueTableInfo;
@@ -114,10 +116,10 @@ public Map<String, List<TrackedEntityDataValue>> querySingleEventsTrackedEntityD
114116
return queryTrackedEntityDataValues(queryStatement);
115117
}
116118

117-
// TODO Could we reuse EnumHelper.asStringList(State.uploadableStates())?
118119
private String eventInUploadableState() {
119-
return "(Event.state IN ('" + State.TO_POST + "', '" + State.TO_UPDATE + "', '"
120-
+ State.SENT_VIA_SMS + "', '" + State.SYNCED_VIA_SMS + "'))";
120+
String states = CollectionsHelper.commaAndSpaceSeparatedArrayValues(
121+
CollectionsHelper.withSingleQuotationMarksArray(EnumHelper.asStringList(State.uploadableStates())));
122+
return "(Event.state IN (" + states + "))";
121123
}
122124

123125
@Override

core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceLocalQueryHelper.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
package org.hisp.dhis.android.core.trackedentity.search;
3030

3131
import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder;
32+
import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper;
33+
import org.hisp.dhis.android.core.arch.helpers.internal.EnumHelper;
3234
import org.hisp.dhis.android.core.arch.repositories.scope.internal.FilterItemOperator;
3335
import org.hisp.dhis.android.core.arch.repositories.scope.internal.RepositoryScopeFilterItem;
3436
import org.hisp.dhis.android.core.common.AssignedUserMode;
@@ -130,10 +132,15 @@ static String getSqlQuery(TrackedEntityInstanceQueryRepositoryScope scope, List<
130132
}
131133

132134
// TODO In case a program uid is provided, the server orders by enrollmentStatus.
133-
135+
String order1 = CollectionsHelper.commaAndSpaceSeparatedArrayValues(
136+
CollectionsHelper.withSingleQuotationMarksArray(
137+
EnumHelper.asStringList(State.TO_POST, State.TO_UPDATE, State.UPLOADING)));
138+
String order2 = CollectionsHelper.commaAndSpaceSeparatedArrayValues(
139+
CollectionsHelper.withSingleQuotationMarksArray(
140+
EnumHelper.asStringList(State.SYNCED, State.SYNCED_VIA_SMS, State.SENT_VIA_SMS)));
134141
queryStr += " ORDER BY CASE " +
135-
"WHEN " + TEI_STATE + " IN ('" + State.TO_POST + "','" + State.TO_UPDATE + "') THEN 1 " +
136-
"WHEN " + TEI_STATE + " = '" + State.SYNCED + "' THEN 2 ELSE 3 END ASC, " +
142+
"WHEN " + TEI_STATE + " IN (" + order1 + ") THEN 1 " +
143+
"WHEN " + TEI_STATE + " IN (" + order2 + ") THEN 2 ELSE 3 END ASC, " +
137144
TEI_LAST_UPDATED + " DESC ";
138145

139146
if (limit > 0) {

0 commit comments

Comments
 (0)