Skip to content

Commit

Permalink
Merge pull request #1111 from dhis2/develop
Browse files Browse the repository at this point in the history
feat: Develop
  • Loading branch information
vgarciabnz authored Dec 9, 2019
2 parents e0d620d + 70c5117 commit 5e86580
Show file tree
Hide file tree
Showing 20 changed files with 116 additions and 32 deletions.
4 changes: 2 additions & 2 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ ext {
buildToolsVersion: "28.0.3",
minSdkVersion : 19,
targetSdkVersion : 28,
versionCode : 180,
versionName : "0.17.6-SNAPSHOT"
versionCode : 200,
versionName : "1.0.0"
]

libraries = [
Expand Down
4 changes: 2 additions & 2 deletions core/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
# Properties which are consumed by plugins/gradle-mvn-push.gradle plugin.
# They are used for publishing artifact to snapshot repository.

VERSION_NAME=0.17.6-SNAPSHOT
VERSION_CODE=180
VERSION_NAME=1.0.0
VERSION_CODE=200

GROUP=org.hisp.dhis

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void recreate_events_with_filters() {

List<Event> events = eventPostCall.queryDataToSync(
d2.eventModule().events().byProgramUid().eq(program.uid())
.byState().in(State.TO_POST, State.TO_UPDATE).blockingGet());
.byState().in(State.uploadableStates()).blockingGet());

assertThat(events.size()).isEqualTo(3);
assertThat(UidsHelper.getUidsList(events).containsAll(Lists.newArrayList(event1, event2, event3)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void recreate_teis_with_filters_and_relationships() throws Exception {

List<List<TrackedEntityInstance>> partitions = trackedEntityInstancePostCall.getPartitionsToSync(
d2.trackedEntityModule().trackedEntityInstances().byUid().eq(tei1)
.byState().in(State.TO_POST, State.TO_UPDATE).blockingGet());
.byState().in(State.uploadableStates()).blockingGet());

assertThat(partitions.size()).isEqualTo(1);
assertThat(partitions.get(0).size()).isEqualTo(3);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2004-2019, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.hisp.dhis.android.core.arch.helpers.internal;

import java.util.ArrayList;
import java.util.List;

public final class EnumHelper {

public static List<String> asStringList(Enum<?>... enums) {
List<String> enumsStr = new ArrayList<>(enums.length);
for (Enum<?> e: enums) {
enumsStr.add(e.name());
}
return enumsStr;
}

private EnumHelper() {
}
}
14 changes: 13 additions & 1 deletion core/src/main/java/org/hisp/dhis/android/core/common/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,17 @@ public enum State {
SENT_VIA_SMS,

/** Data is sent by sms and there is a successful response from the server. */
SYNCED_VIA_SMS
SYNCED_VIA_SMS;

public static State[] uploadableStates() {
return new State[] {
TO_POST, TO_UPDATE, SENT_VIA_SMS, SYNCED_VIA_SMS
};
}

public static State[] uploadableStatesIncludingError() {
return new State[] {
TO_POST, TO_UPDATE, SENT_VIA_SMS, SYNCED_VIA_SMS, ERROR, WARNING
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public DataSetCompleteRegistrationObjectRepository value(final String period,
@Override
public Observable<D2Progress> upload() {
return Observable.fromCallable(() ->
byState().in(State.TO_POST, State.TO_UPDATE).blockingGetWithoutChildren()
byState().in(State.uploadableStates()).blockingGetWithoutChildren()
).flatMap(postCall::uploadDataSetCompleteRegistrations);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public final class DataValueCollectionRepository
@Override
public Observable<D2Progress> upload() {
return Observable.fromCallable(() ->
byState().in(State.TO_POST, State.TO_UPDATE, State.WARNING, State.ERROR).blockingGetWithoutChildren()
byState().in(State.uploadableStatesIncludingError()).blockingGetWithoutChildren()
).flatMap(postCall::uploadDataValues);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
import org.hisp.dhis.android.core.arch.db.statementwrapper.internal.SQLStatementWrapper;
import org.hisp.dhis.android.core.arch.db.stores.binders.internal.StatementBinder;
import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableDeletableDataObjectStoreImpl;
import org.hisp.dhis.android.core.arch.helpers.internal.EnumHelper;
import org.hisp.dhis.android.core.common.DataColumns;
import org.hisp.dhis.android.core.common.State;
import org.hisp.dhis.android.core.enrollment.Enrollment;
import org.hisp.dhis.android.core.enrollment.EnrollmentTableInfo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -81,9 +81,7 @@ private EnrollmentStoreImpl(DatabaseAdapter databaseAdapter,
@Override
public Map<String, List<Enrollment>> queryEnrollmentsToPost() {
String enrollmentsToPostQuery = new WhereClauseBuilder()
.appendInKeyStringValues(DataColumns.STATE, Arrays.asList(
State.TO_POST.name(),
State.TO_UPDATE.name())).build();
.appendInKeyStringValues(DataColumns.STATE, EnumHelper.asStringList(State.uploadableStates())).build();

List<Enrollment> enrollmentList = selectWhere(enrollmentsToPostQuery);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public final class EventCollectionRepository

@Override
public Observable<D2Progress> upload() {
return Observable.fromCallable(() -> byState().in(State.TO_POST, State.TO_UPDATE)
return Observable.fromCallable(() -> byState().in(State.uploadableStates())
.byEnrollmentUid().isNull()
.blockingGetWithoutChildren())
.flatMap(postCall::uploadEvents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.hisp.dhis.android.core.arch.db.statementwrapper.internal.SQLStatementWrapper;
import org.hisp.dhis.android.core.arch.db.stores.binders.internal.StatementBinder;
import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableDeletableDataObjectStoreImpl;
import org.hisp.dhis.android.core.arch.helpers.internal.EnumHelper;
import org.hisp.dhis.android.core.common.IdentifiableColumns;
import org.hisp.dhis.android.core.common.State;
import org.hisp.dhis.android.core.enrollment.EnrollmentTableInfo;
Expand All @@ -45,7 +46,6 @@
import org.hisp.dhis.android.core.event.EventTableInfo.Columns;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -89,9 +89,7 @@ private EventStoreImpl(DatabaseAdapter databaseAdapter,
public Map<String, List<Event>> queryEventsAttachedToEnrollmentToPost() {
String eventsAttachedToEnrollmentsQuery = new WhereClauseBuilder()
.appendIsNotNullValue(Columns.ENROLLMENT)
.appendInKeyStringValues(Columns.STATE, Arrays.asList(
State.TO_POST.name(),
State.TO_UPDATE.name())).build();
.appendInKeyStringValues(Columns.STATE, EnumHelper.asStringList(State.uploadableStates())).build();

List<Event> eventList = selectWhere(eventsAttachedToEnrollmentsQuery);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public final class FileResourceCollectionRepository

@Override
public Observable<D2Progress> upload() {
return Observable.fromCallable(() -> byState().in(State.TO_POST, State.TO_UPDATE)
return Observable.fromCallable(() -> byState().in(State.uploadableStates())
.blockingGetWithoutChildren())
.flatMap(postCall::uploadFileResources);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Single<List<DataValue>> getDataValues(String orgUnit, String period, String attr
.byOrganisationUnitUid().eq(orgUnit)
.byPeriod().eq(period)
.byAttributeOptionComboUid().eq(attributeOptionComboUid)
.byState().in(Arrays.asList(State.TO_POST, State.TO_UPDATE))
.byState().in(Arrays.asList(State.uploadableStates()))
.blockingGet());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceInternalAccessor;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityModule;
import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstanceStore;
import org.hisp.dhis.android.core.user.UserModule;
import org.hisp.dhis.smscompression.models.SMSMetadata;

Expand Down Expand Up @@ -53,6 +54,7 @@ public class LocalDbRepositoryImpl implements LocalDbRepository {
private final OngoingSubmissionsStore ongoingSubmissionsStore;
private final RelationshipStore relationshipStore;
private final DataSetsStore dataSetsStore;
private final TrackedEntityInstanceStore trackedEntityInstanceStore;

@Inject
LocalDbRepositoryImpl(Context ctx,
Expand All @@ -63,7 +65,8 @@ public class LocalDbRepositoryImpl implements LocalDbRepository {
EventStore eventStore,
EnrollmentStore enrollmentStore,
RelationshipStore relationshipStore,
DataSetsStore dataSetsStore) {
DataSetsStore dataSetsStore,
TrackedEntityInstanceStore trackedEntityInstanceStore) {
this.context = ctx;
this.userModule = userModule;
this.trackedEntityModule = trackedEntityModule;
Expand All @@ -73,6 +76,7 @@ public class LocalDbRepositoryImpl implements LocalDbRepository {
this.enrollmentStore = enrollmentStore;
this.relationshipStore = relationshipStore;
this.dataSetsStore = dataSetsStore;
this.trackedEntityInstanceStore = trackedEntityInstanceStore;
metadataIdsStore = new MetadataIdsStore(context);
ongoingSubmissionsStore = new OngoingSubmissionsStore(context);
}
Expand Down Expand Up @@ -184,7 +188,11 @@ public Completable updateEventSubmissionState(String eventUid, State state) {

@Override
public Completable updateEnrollmentSubmissionState(String enrollmentUid, State state) {
return Completable.fromAction(() -> enrollmentStore.setState(enrollmentUid, state));
return Completable.fromAction(() -> {
enrollmentStore.setState(enrollmentUid, state);
Enrollment enrollment = enrollmentStore.selectByUid(enrollmentUid);
trackedEntityInstanceStore.setState(enrollment.trackedEntityInstance(), state);
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public final class TrackedEntityInstanceCollectionRepository
@Override
public Observable<D2Progress> upload() {
return Observable.fromCallable(() ->
byState().in(State.TO_POST, State.TO_UPDATE).blockingGetWithoutChildren()
byState().in(State.uploadableStates()).blockingGetWithoutChildren()
).flatMap(postCall::uploadTrackedEntityInstances);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public Map<String, List<TrackedEntityAttributeValue>> queryTrackedEntityAttribut
"SELECT TrackedEntityAttributeValue.* " +
"FROM (TrackedEntityAttributeValue INNER JOIN TrackedEntityInstance " +
"ON TrackedEntityAttributeValue.trackedEntityInstance = TrackedEntityInstance.uid) " +
"WHERE TrackedEntityInstance.state = '" + State.TO_POST + "' " +
"OR TrackedEntityInstance.state = '" + State.TO_UPDATE + "';";
"WHERE " + teiInUploadableState() + ";";

List<TrackedEntityAttributeValue> valueList = trackedEntityAttributeValueListFromQuery(toPostQuery);

Expand All @@ -104,6 +103,12 @@ public Map<String, List<TrackedEntityAttributeValue>> queryTrackedEntityAttribut
return valueMap;
}

// TODO Could we reuse EnumHelper.asStringList(State.uploadableStates())?
private String teiInUploadableState() {
return "(TrackedEntityInstance.state IN ('" + State.TO_POST + "', '" + State.TO_UPDATE + "', '"
+ State.SENT_VIA_SMS + "', '" + State.SYNCED_VIA_SMS + "'))";
}

@Override
public List<TrackedEntityAttributeValue> queryByTrackedEntityInstance(String trackedEntityInstanceUid) {
String selectByTrackedEntityInstanceQuery = new WhereClauseBuilder().appendKeyStringValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,24 @@ public Map<String, List<TrackedEntityDataValue>> querySingleEventsTrackedEntityD
String queryStatement = "SELECT TrackedEntityDataValue.* " +
" FROM (TrackedEntityDataValue INNER JOIN Event ON TrackedEntityDataValue.event = Event.uid)" +
" WHERE Event.enrollment ISNULL " +
"AND (Event.state = '" + State.TO_POST + "' OR Event.state = '" + State.TO_UPDATE + "');";
"AND " + eventInUploadableState() + ";";

return queryTrackedEntityDataValues(queryStatement);
}

// TODO Could we reuse EnumHelper.asStringList(State.uploadableStates())?
private String eventInUploadableState() {
return "(Event.state IN ('" + State.TO_POST + "', '" + State.TO_UPDATE + "', '"
+ State.SENT_VIA_SMS + "', '" + State.SYNCED_VIA_SMS + "'))";
}

@Override
public Map<String, List<TrackedEntityDataValue>> queryTrackerTrackedEntityDataValues() {

String queryStatement = "SELECT TrackedEntityDataValue.* " +
" FROM (TrackedEntityDataValue INNER JOIN Event ON TrackedEntityDataValue.event = Event.uid) " +
" WHERE Event.enrollment IS NOT NULL " +
"AND (Event.state = '" + State.TO_POST + "' OR Event.state = '" + State.TO_UPDATE + "');";
"AND " + eventInUploadableState() + ";";

return queryTrackedEntityDataValues(queryStatement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
import org.hisp.dhis.android.core.arch.db.statementwrapper.internal.SQLStatementWrapper;
import org.hisp.dhis.android.core.arch.db.stores.binders.internal.StatementBinder;
import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableDeletableDataObjectStoreImpl;
import org.hisp.dhis.android.core.arch.helpers.internal.EnumHelper;
import org.hisp.dhis.android.core.common.DataColumns;
import org.hisp.dhis.android.core.common.State;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceTableInfo;

import java.util.Arrays;
import java.util.List;

import static org.hisp.dhis.android.core.arch.db.stores.internal.StoreUtils.sqLiteBind;
Expand Down Expand Up @@ -71,9 +71,7 @@ public TrackedEntityInstanceStoreImpl(DatabaseAdapter databaseAdapter,
@Override
public List<TrackedEntityInstance> queryTrackedEntityInstancesToSync() {
String whereToSyncClause = new WhereClauseBuilder()
.appendInKeyStringValues(DataColumns.STATE, Arrays.asList(
State.TO_POST.name(),
State.TO_UPDATE.name()))
.appendInKeyStringValues(DataColumns.STATE, EnumHelper.asStringList(State.uploadableStates()))
.build();

return selectWhere(whereToSyncClause);
Expand Down
2 changes: 1 addition & 1 deletion docs/content/user/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Include dependency in build.gradle.

```gradle
dependencies {
implementation "org.hisp.dhis:android-core:0.17.0-SNAPSHOT"
implementation "org.hisp.dhis:android-core:1.0.0"
...
}
```
Expand Down
13 changes: 13 additions & 0 deletions docs/dhis2_android_sdk_user_guide_INDEX.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
---
title: 'DHIS 2 Android SDK User Guide'
author: 'DHIS 2'
date:
year: 2019
month: December
keywords: [DHIS2, Android]
commit:
version: master
applicable_txt: 'Applicable to version master'
---
<!--DHIS2-SECTION-ID:index-->

!INCLUDE "content/user/compatibility.md"
!INCLUDE "content/user/overview.md"
!INCLUDE "content/user/getting-started.md"
Expand Down

0 comments on commit 5e86580

Please sign in to comment.