diff --git a/core/build.gradle b/core/build.gradle index 12f6f522ce..0f1af22494 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -36,8 +36,8 @@ ext { buildToolsVersion: "28.0.3", minSdkVersion : 19, targetSdkVersion : 28, - versionCode : 211, - versionName : "1.1.1" + versionCode : 212, + versionName : "1.1.2" ] libraries = [ diff --git a/core/gradle.properties b/core/gradle.properties index 0429703b38..93cfa4b54d 100644 --- a/core/gradle.properties +++ b/core/gradle.properties @@ -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=1.1.1 -VERSION_CODE=211 +VERSION_NAME=1.1.2 +VERSION_CODE=212 GROUP=org.hisp.dhis diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCompleteRegistrationObjectRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCompleteRegistrationObjectRepositoryMockIntegrationShould.java index 28ea234557..f1e8e08af5 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCompleteRegistrationObjectRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCompleteRegistrationObjectRepositoryMockIntegrationShould.java @@ -36,18 +36,19 @@ import org.junit.Assert; import org.junit.Test; -import java.util.List; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; public class DataSetCompleteRegistrationObjectRepositoryMockIntegrationShould extends BaseMockIntegrationTestFullDispatcher { + private String dataSetUid = "lyLU2wR22tC"; + private String orgUnitUid = "DiszpKrYNg8"; + private String cocUid = "bRowv6yZOF2"; + @Test public void delete() { - - List dataSetCompleteRegistrations = d2.dataSetModule().dataSetCompleteRegistrations().blockingGet(); - try { objectRepository().blockingDelete(); } catch (D2Error d2Error) { @@ -58,11 +59,24 @@ public void delete() { assertThat(dataSetCompleteRegistration.deleted(), is(true)); assertThat(dataSetCompleteRegistration.state(), is(State.TO_UPDATE)); + } + + @Test + public void delete_newly_created_record() throws D2Error { + DataSetCompleteRegistrationObjectRepository newObjectRepository = + d2.dataSetModule().dataSetCompleteRegistrations().value("2019", orgUnitUid, dataSetUid, cocUid); + + newObjectRepository.blockingSet(); + newObjectRepository.blockingDelete(); + + DataSetCompleteRegistration newObject = newObjectRepository.blockingGet(); + assertNull(newObject); + DataSetCompleteRegistration existingObject = objectRepository().blockingGet(); + assertNotNull(existingObject); } private DataSetCompleteRegistrationObjectRepository objectRepository() { - return d2.dataSetModule().dataSetCompleteRegistrations().value( - "2018", "DiszpKrYNg8", "lyLU2wR22tC","bRowv6yZOF2"); + return d2.dataSetModule().dataSetCompleteRegistrations().value("2018", orgUnitUid, dataSetUid, cocUid); } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/trackedentity/TrackedEntityAttributeCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/trackedentity/TrackedEntityAttributeCollectionRepositoryMockIntegrationShould.java index 44442511fd..3818c88c53 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/trackedentity/TrackedEntityAttributeCollectionRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/trackedentity/TrackedEntityAttributeCollectionRepositoryMockIntegrationShould.java @@ -191,6 +191,16 @@ public void by_form_name() { assertThat(trackedEntityAttributes.size(), is(1)); } + @Test + public void by_display_form_name() { + List trackedEntityAttributes = + d2.trackedEntityModule().trackedEntityAttributes() + .byDisplayFormName().eq("displayformname") + .blockingGet(); + + assertThat(trackedEntityAttributes.size(), is(1)); + } + @Test public void filter_by_field_color() { List trackedEntityAttributes = diff --git a/core/src/main/assets/migrations/73.sql b/core/src/main/assets/migrations/73.sql new file mode 100644 index 0000000000..0c22bbb642 --- /dev/null +++ b/core/src/main/assets/migrations/73.sql @@ -0,0 +1,2 @@ +# Related to ANDROSDK-1151 +UPDATE DataSetCompleteRegistration SET date = date() || 'T00:00:00.000' WHERE date IS NULL; \ No newline at end of file diff --git a/core/src/main/assets/migrations/74.sql b/core/src/main/assets/migrations/74.sql new file mode 100644 index 0000000000..291fbb3781 --- /dev/null +++ b/core/src/main/assets/migrations/74.sql @@ -0,0 +1,3 @@ +# Related to ANDROSDK-1147 +ALTER TABLE ProgramSectionAttributeLink ADD COLUMN sortOrder INTEGER; +UPDATE ProgramSectionAttributeLink SET sortOrder=_id; \ No newline at end of file diff --git a/core/src/main/assets/migrations/75.sql b/core/src/main/assets/migrations/75.sql new file mode 100644 index 0000000000..68cfb038c2 --- /dev/null +++ b/core/src/main/assets/migrations/75.sql @@ -0,0 +1,3 @@ +# Related to ANDROSDK-831 +ALTER TABLE TrackedEntityAttribute ADD COLUMN displayFormName TEXT; +UPDATE TrackedEntityAttribute SET displayFormName=displayName; \ No newline at end of file diff --git a/core/src/main/assets/snapshots/72.sql b/core/src/main/assets/snapshots/75.sql similarity index 98% rename from core/src/main/assets/snapshots/72.sql rename to core/src/main/assets/snapshots/75.sql index 92a482f7a6..91d6dfde60 100644 --- a/core/src/main/assets/snapshots/72.sql +++ b/core/src/main/assets/snapshots/75.sql @@ -34,7 +34,7 @@ CREATE TABLE Legend (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UN CREATE TABLE LegendSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, symbolizer TEXT); CREATE TABLE ProgramIndicatorLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programIndicator TEXT NOT NULL, legendSet TEXT NOT NULL, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programIndicator, legendSet)); CREATE TABLE SystemSetting (_id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT, value TEXT, UNIQUE (key)); -CREATE TABLE ProgramSectionAttributeLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programSection TEXT NOT NULL, attribute TEXT NOT NULL, FOREIGN KEY (programSection) REFERENCES ProgramSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programSection, attribute)); +CREATE TABLE ProgramSectionAttributeLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programSection TEXT NOT NULL, attribute TEXT NOT NULL, sortOrder INTEGER, FOREIGN KEY (programSection) REFERENCES ProgramSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programSection, attribute)); CREATE TABLE TrackedEntityAttributeReservedValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, ownerObject TEXT, ownerUid TEXT, key TEXT, value TEXT, created TEXT, expiryDate TEXT, organisationUnit TEXT, temporalValidityDate TEXT); CREATE TABLE CategoryOptionComboCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, categoryOptionCombo TEXT NOT NULL, categoryOption TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (categoryOptionCombo, categoryOption)); CREATE TABLE Section (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, description TEXT, sortOrder INTEGER, dataSet TEXT NOT NULL, showRowTotals INTEGER, showColumnTotals INTEGER, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); @@ -61,7 +61,7 @@ CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT CREATE TABLE OrganisationUnitLevel (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, level INTEGER); CREATE TABLE ProgramSection (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, description TEXT, program TEXT, sortOrder INTEGER, formName TEXT, color TEXT, icon TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE DataApproval (_id INTEGER PRIMARY KEY AUTOINCREMENT, workflow TEXT NOT NULL, organisationUnit TEXT NOT NULL, period TEXT NOT NULL, attributeOptionCombo TEXT NOT NULL, state TEXT, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (period) REFERENCES Period (periodId), FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (attributeOptionCombo, period, organisationUnit, workflow)); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, pattern TEXT, sortOrderInListNoProgram INTEGER, optionSet TEXT, valueType TEXT, expression TEXT, programScope INTEGER, displayInListNoProgram INTEGER, generated INTEGER, displayOnVisitSchedule INTEGER, orgunitScope INTEGER, uniqueProperty INTEGER, inherit INTEGER, formName TEXT, fieldMask TEXT, color TEXT, icon TEXT, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, pattern TEXT, sortOrderInListNoProgram INTEGER, optionSet TEXT, valueType TEXT, expression TEXT, programScope INTEGER, displayInListNoProgram INTEGER, generated INTEGER, displayOnVisitSchedule INTEGER, orgunitScope INTEGER, uniqueProperty INTEGER, inherit INTEGER, formName TEXT, displayFormName TEXT, fieldMask TEXT, color TEXT, icon TEXT, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE TrackerImportConflict (_id INTEGER PRIMARY KEY AUTOINCREMENT, conflict TEXT, value TEXT, trackedEntityInstance TEXT, enrollment TEXT, event TEXT, tableReference TEXT, errorCode TEXT, status TEXT, created TEXT, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) DEFERRABLE INITIALLY DEFERRED); CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL, organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, dataSet)); CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT, user TEXT NOT NULL, organisationUnit TEXT NOT NULL, organisationUnitScope TEXT NOT NULL, root INTEGER, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnitScope, user, organisationUnit)); diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/access/internal/BaseDatabaseOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/arch/db/access/internal/BaseDatabaseOpenHelper.java index 05ba344541..cc51f1f071 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/access/internal/BaseDatabaseOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/access/internal/BaseDatabaseOpenHelper.java @@ -36,7 +36,7 @@ class BaseDatabaseOpenHelper { - static final int VERSION = 72; + static final int VERSION = 75; private final AssetManager assetManager; private final int targetVersion; diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseMigrationExecutor.java b/core/src/main/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseMigrationExecutor.java index 1dfa8748a7..d4a3b7569c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseMigrationExecutor.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseMigrationExecutor.java @@ -42,7 +42,7 @@ class DatabaseMigrationExecutor { private final DatabaseAdapter databaseAdapter; private final DatabaseMigrationParser parser; - private static final int SNAPSHOT_VERSION = 72; + private static final int SNAPSHOT_VERSION = 75; DatabaseMigrationExecutor(DatabaseAdapter databaseAdapter, AssetManager assetManager) { this.databaseAdapter = databaseAdapter; diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetCompleteRegistrationCollectionRepository.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetCompleteRegistrationCollectionRepository.java index f517c4bdc2..680708f643 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetCompleteRegistrationCollectionRepository.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetCompleteRegistrationCollectionRepository.java @@ -43,6 +43,7 @@ import org.hisp.dhis.android.core.dataset.DataSetCompleteRegistrationTableInfo.Columns; import org.hisp.dhis.android.core.dataset.internal.DataSetCompleteRegistrationPostCall; import org.hisp.dhis.android.core.dataset.internal.DataSetCompleteRegistrationStore; +import org.hisp.dhis.android.core.user.UserCredentialsObjectRepository; import java.util.Map; @@ -59,6 +60,7 @@ public final class DataSetCompleteRegistrationCollectionRepository private final DataSetCompleteRegistrationPostCall postCall; private final DataSetCompleteRegistrationStore dataSetCompleteRegistrationStore; + private final UserCredentialsObjectRepository credentialsRepository; @Inject DataSetCompleteRegistrationCollectionRepository( @@ -66,14 +68,16 @@ public final class DataSetCompleteRegistrationCollectionRepository final Map> childrenAppenders, final RepositoryScope scope, final Handler handler, - final DataSetCompleteRegistrationPostCall postCall) { + final DataSetCompleteRegistrationPostCall postCall, + final UserCredentialsObjectRepository credentialsRepository) { super(store, childrenAppenders, scope, new FilterConnectorFactory<>(scope, s -> new DataSetCompleteRegistrationCollectionRepository(store, childrenAppenders, - s, handler, postCall))); + s, handler, postCall, credentialsRepository))); this.postCall = postCall; this.dataSetCompleteRegistrationStore = store; + this.credentialsRepository = credentialsRepository; } public DataSetCompleteRegistrationObjectRepository value(final String period, @@ -88,7 +92,7 @@ public DataSetCompleteRegistrationObjectRepository value(final String period, .scope; return new DataSetCompleteRegistrationObjectRepository( - dataSetCompleteRegistrationStore, childrenAppenders, + dataSetCompleteRegistrationStore, credentialsRepository, childrenAppenders, updatedScope, period, organisationUnit, dataSet, attributeOptionCombo); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetCompleteRegistrationObjectRepository.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetCompleteRegistrationObjectRepository.java index 625d6f4ebd..a4bf1cd868 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetCompleteRegistrationObjectRepository.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetCompleteRegistrationObjectRepository.java @@ -39,7 +39,9 @@ import org.hisp.dhis.android.core.maintenance.D2Error; import org.hisp.dhis.android.core.maintenance.D2ErrorCode; import org.hisp.dhis.android.core.maintenance.D2ErrorComponent; +import org.hisp.dhis.android.core.user.UserCredentialsObjectRepository; +import java.util.Date; import java.util.Map; import io.reactivex.Completable; @@ -50,6 +52,7 @@ public final class DataSetCompleteRegistrationObjectRepository implements ReadWriteObjectRepository { private final DataSetCompleteRegistrationStore dataSetCompleteRegistrationStore; + private final UserCredentialsObjectRepository credentialsRepository; private final String period; private final String dataSet; @@ -58,6 +61,7 @@ public final class DataSetCompleteRegistrationObjectRepository DataSetCompleteRegistrationObjectRepository( final DataSetCompleteRegistrationStore dataSetCompleteRegistrationStore, + final UserCredentialsObjectRepository credentialsRepository, final Map> childrenAppenders, final RepositoryScope scope, final String period, @@ -67,10 +71,11 @@ public final class DataSetCompleteRegistrationObjectRepository ) { super(dataSetCompleteRegistrationStore, childrenAppenders, scope, s -> new DataSetCompleteRegistrationObjectRepository( - dataSetCompleteRegistrationStore, childrenAppenders, s, + dataSetCompleteRegistrationStore, credentialsRepository, childrenAppenders, s, period, organisationUnit, dataSet, attributeOptionCombo)); this.dataSetCompleteRegistrationStore = dataSetCompleteRegistrationStore; + this.credentialsRepository = credentialsRepository; this.period = period; this.dataSet = dataSet; @@ -79,25 +84,31 @@ public final class DataSetCompleteRegistrationObjectRepository } public Completable set() { - return Completable.fromAction(() -> blockingSet()); + return Completable.fromAction(this::blockingSet); } public void blockingSet() { DataSetCompleteRegistration dataSetCompleteRegistration = blockingGetWithoutChildren(); if (dataSetCompleteRegistration == null) { + String username = credentialsRepository.blockingGet().username(); dataSetCompleteRegistrationStore.insert( DataSetCompleteRegistration.builder() - .state(State.TO_POST) - .deleted(false) .period(period) .dataSet(dataSet) .organisationUnit(organisationUnit) .attributeOptionCombo(attributeOptionCombo) + .date(new Date()) + .storedBy(username) + .state(State.TO_POST) + .deleted(false) .build()); } else { - dataSetCompleteRegistrationStore.setState(dataSetCompleteRegistration, - dataSetCompleteRegistration.state() == State.TO_POST ? State.TO_POST : State.TO_UPDATE); + DataSetCompleteRegistration newRecord = dataSetCompleteRegistration.toBuilder() + .deleted(false) + .state(dataSetCompleteRegistration.state() == State.TO_POST ? State.TO_POST : State.TO_UPDATE) + .build(); + dataSetCompleteRegistrationStore.updateWhere(newRecord); } } @@ -119,11 +130,13 @@ public void blockingDelete() throws D2Error { .build(); } else { if (dataSetCompleteRegistration.state() == State.TO_POST) { - dataSetCompleteRegistrationStore.delete(); + dataSetCompleteRegistrationStore.deleteWhere(dataSetCompleteRegistration); } else { - - dataSetCompleteRegistrationStore.setState( - dataSetCompleteRegistration.toBuilder().deleted(true).build(), State.TO_UPDATE); + DataSetCompleteRegistration deletedRecord = dataSetCompleteRegistration.toBuilder() + .deleted(true) + .state(State.TO_UPDATE) + .build(); + dataSetCompleteRegistrationStore.updateWhere(deletedRecord); } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/domain/aggregated/data/internal/AggregatedDataCallBundleFactory.java b/core/src/main/java/org/hisp/dhis/android/core/domain/aggregated/data/internal/AggregatedDataCallBundleFactory.java index d21406adc7..617fe9c391 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/domain/aggregated/data/internal/AggregatedDataCallBundleFactory.java +++ b/core/src/main/java/org/hisp/dhis/android/core/domain/aggregated/data/internal/AggregatedDataCallBundleFactory.java @@ -109,15 +109,18 @@ List getDataValueQueriesForDataSets(Collection periods = periodManager.getPeriodsInRange(periodType, pair.past, pair.future); - List periodIds = selectPeriodIds(periods); - AggregatedDataCallBundle bundle = AggregatedDataCallBundle.builder() - .dataSets(entry.getValue()) - .periodIds(periodIds) - .orgUnitUids(organisationUnitUids) - .build(); + if (!periods.isEmpty()) { + List periodIds = selectPeriodIds(periods); - queries.add(bundle); + AggregatedDataCallBundle bundle = AggregatedDataCallBundle.builder() + .dataSets(entry.getValue()) + .periodIds(periodIds) + .orgUnitUids(organisationUnitUids) + .build(); + + queries.add(bundle); + } } return queries; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventQueryBundleFactory.java b/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventQueryBundleFactory.java index befc9eab97..3efbd186d0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventQueryBundleFactory.java +++ b/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventQueryBundleFactory.java @@ -124,10 +124,12 @@ private List queryPerProgram(ProgramDataDownloadParams params, String programUid, String lastUpdated) { int limit = getLimit(params, programSettings, programUid); - String eventStartDate = getEventStartDate(programSettings, programUid); - List builders = new ArrayList<>(); + if (limit == 0) { + return Collections.emptyList(); + } + String eventStartDate = getEventStartDate(programSettings, programUid); List programs = Collections.singletonList(programUid); OrganisationUnitMode ouMode; List orgUnits; @@ -145,6 +147,8 @@ private List queryPerProgram(ProgramDataDownloadParams params, orgUnits = getRootCaptureOrgUnitUids(); } + List builders = new ArrayList<>(); + if (hasLimitByOrgunit) { for (String orgUnitUid : orgUnits) { builders.add(getBuilderFor(lastUpdated, Collections.singletonList(orgUnitUid), programs, ouMode, @@ -162,10 +166,12 @@ private List queryGlobal(ProgramDataDownloadParams params, List programList, String lastUpdated) { int limit = getLimit(params, programSettings, null); - String eventStartDate = getEventStartDate(programSettings, null); - List builders = new ArrayList<>(); + if (limit == 0) { + return Collections.emptyList(); + } + String eventStartDate = getEventStartDate(programSettings, null); OrganisationUnitMode ouMode; List orgUnits; @@ -182,6 +188,8 @@ private List queryGlobal(ProgramDataDownloadParams params, orgUnits = getRootCaptureOrgUnitUids(); } + List builders = new ArrayList<>(); + if (hasLimitByOrgunit) { for (String orgUnitUid : orgUnits) { builders.add(getBuilderFor(lastUpdated, Collections.singletonList(orgUnitUid), programList, ouMode, @@ -284,7 +292,7 @@ private boolean hasLimitByOrgUnit(ProgramDataDownloadParams params, ProgramSetti private int getLimit(ProgramDataDownloadParams params, ProgramSettings programSettings, String programUid) { - if (params.limit() != null) { + if (params.limit() != null && isGlobalOrUserDefinedProgram(params, programUid)) { return params.limit(); } @@ -327,4 +335,8 @@ private String getEventStartDate(ProgramSettings programSettings, String program private boolean hasEventDateDownload(ProgramSetting programSetting) { return programSetting != null && programSetting.eventDateDownload() != null; } + + private boolean isGlobalOrUserDefinedProgram(ProgramDataDownloadParams params, String programUid) { + return programUid == null || programUid.equals(params.program()); + } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitFields.java b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitFields.java index 9fa5908c99..a0ec073246 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitFields.java @@ -32,7 +32,6 @@ import org.hisp.dhis.android.core.arch.api.fields.internal.Fields; import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper; import org.hisp.dhis.android.core.common.FeatureType; -import org.hisp.dhis.android.core.common.Geometry; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitGroup; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitTableInfo.Columns; @@ -43,9 +42,9 @@ public final class OrganisationUnitFields { public static final String DATA_SETS = "dataSets"; private static final String ANCESTORS = "ancestors"; public static final String ORGANISATION_UNIT_GROUPS = "organisationUnitGroups"; - public final static String COORDINATES = "coordinates"; + //public final static String COORDINATES = "coordinates"; public final static String FEATURE_TYPE = "featureType"; - public final static String GEOMETRY = "geometry"; + //public final static String GEOMETRY = "geometry"; private static final FieldsHelper fh = new FieldsHelper<>(); @@ -62,9 +61,9 @@ public final class OrganisationUnitFields { openingDate, closedDate, fh.field(Columns.LEVEL), - fh.field(COORDINATES), + //fh.field(COORDINATES), fh.field(FEATURE_TYPE), - fh.field(GEOMETRY), + //fh.field(GEOMETRY), fh.nestedFieldWithUid(Columns.PARENT), fh.nestedFieldWithUid(PROGRAMS), fh.nestedFieldWithUid(DATA_SETS), diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/internal/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/internal/AbstractPeriodGenerator.java index 3cde3aa690..bd177dd13c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/internal/AbstractPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/internal/AbstractPeriodGenerator.java @@ -34,6 +34,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Locale; @@ -64,7 +65,7 @@ public final List generatePeriods(int past, int future) throws RuntimeEx } if (future + past < 1) { - throw new RuntimeException("Number of past + future periods must be positive."); + return Collections.emptyList(); } List periods = new ArrayList<>(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLink.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLink.java index 6904a0884b..db17f5666b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLink.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLink.java @@ -29,7 +29,7 @@ import android.database.Cursor; -import androidx.annotation.Nullable; +import androidx.annotation.NonNull; import com.google.auto.value.AutoValue; @@ -39,12 +39,15 @@ @AutoValue public abstract class ProgramSectionAttributeLink implements CoreObject { - @Nullable + @NonNull public abstract String programSection(); - @Nullable + @NonNull public abstract String attribute(); + @NonNull + public abstract Integer sortOrder(); + public static Builder builder() { return new AutoValue_ProgramSectionAttributeLink.Builder(); } @@ -64,6 +67,8 @@ public static abstract class Builder extends BaseObject.Builder { public abstract Builder attribute(String attribute); + public abstract Builder sortOrder(Integer integer); + public abstract ProgramSectionAttributeLink build(); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkTableInfo.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkTableInfo.java index 56826c3e21..4d0a075558 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkTableInfo.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkTableInfo.java @@ -54,10 +54,11 @@ public static class Columns extends CoreColumns { public static final String PROGRAM_SECTION = "programSection"; public static final String ATTRIBUTE = "attribute"; + public static final String SORT_ORDER = "sortOrder"; @Override public String[] all() { - return CollectionsHelper.appendInNewArray(super.all(), PROGRAM_SECTION, ATTRIBUTE); + return CollectionsHelper.appendInNewArray(super.all(), PROGRAM_SECTION, ATTRIBUTE, SORT_ORDER); } @Override diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionAttributeEntityDIModule.java b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionAttributeEntityDIModule.java index e15a6ce1b0..077c5bd33c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionAttributeEntityDIModule.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionAttributeEntityDIModule.java @@ -30,8 +30,8 @@ import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter; import org.hisp.dhis.android.core.arch.db.stores.internal.LinkStore; -import org.hisp.dhis.android.core.arch.handlers.internal.LinkHandler; -import org.hisp.dhis.android.core.arch.handlers.internal.LinkHandlerImpl; +import org.hisp.dhis.android.core.arch.handlers.internal.OrderedLinkHandler; +import org.hisp.dhis.android.core.arch.handlers.internal.OrderedLinkHandlerImpl; import org.hisp.dhis.android.core.program.ProgramSectionAttributeLink; import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttribute; @@ -50,8 +50,8 @@ public LinkStore store(DatabaseAdapter databaseAdap @Provides @Reusable - public LinkHandler handler( + public OrderedLinkHandler handler( LinkStore store) { - return new LinkHandlerImpl<>(store); + return new OrderedLinkHandlerImpl<>(store); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionAttributeLinkStore.java b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionAttributeLinkStore.java index 6cc3500c80..f56913412b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionAttributeLinkStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionAttributeLinkStore.java @@ -40,6 +40,7 @@ public final class ProgramSectionAttributeLinkStore { private static final StatementBinder BINDER = (o, w) -> { w.bind(1, o.programSection()); w.bind(2, o.attribute()); + w.bind(3, o.sortOrder()); }; private ProgramSectionAttributeLinkStore() {} diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionHandler.java b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionHandler.java index ca3f6e8a3c..ef55c2e748 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionHandler.java @@ -31,7 +31,7 @@ import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore; import org.hisp.dhis.android.core.arch.handlers.internal.HandleAction; import org.hisp.dhis.android.core.arch.handlers.internal.IdentifiableHandlerImpl; -import org.hisp.dhis.android.core.arch.handlers.internal.LinkHandler; +import org.hisp.dhis.android.core.arch.handlers.internal.OrderedLinkHandler; import org.hisp.dhis.android.core.program.ProgramSection; import org.hisp.dhis.android.core.program.ProgramSectionAttributeLink; import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttribute; @@ -42,12 +42,12 @@ @Reusable final class ProgramSectionHandler extends IdentifiableHandlerImpl { - private final LinkHandler + private final OrderedLinkHandler programSectionAttributeLinkHandler; @Inject ProgramSectionHandler(IdentifiableObjectStore programSectionStore, - LinkHandler + OrderedLinkHandler programSectionAttributeLinkHandler) { super(programSectionStore); this.programSectionAttributeLinkHandler = programSectionAttributeLinkHandler; @@ -55,9 +55,11 @@ final class ProgramSectionHandler extends IdentifiableHandlerImpl ProgramSectionAttributeLink.builder() - .programSection(programSection.uid()).attribute(trackedEntityAttribute.uid()).build()); + (trackedEntityAttribute, sortOrder) -> ProgramSectionAttributeLink.builder() + .programSection(programSection.uid()) + .attribute(trackedEntityAttribute.uid()) + .sortOrder(sortOrder) + .build()); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipHandlerImpl.java b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipHandlerImpl.java index 4cd4334ff8..a6011ea238 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipHandlerImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipHandlerImpl.java @@ -34,6 +34,8 @@ import org.hisp.dhis.android.core.relationship.Relationship; import org.hisp.dhis.android.core.relationship.RelationshipItem; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; import javax.inject.Inject; @@ -65,6 +67,20 @@ final class RelationshipHandlerImpl extends IdentifiableHandlerImpl beforeCollectionHandled(Collection relationships) { + Collection supportedRelationships = new ArrayList<>(); + + for (Relationship relationship : relationships) { + // Only TEI - TEI relationships are supported so far + if (relationship.from().hasTrackedEntityInstance() && relationship.to().hasTrackedEntityInstance()) { + supportedRelationships.add(relationship); + } + } + + return supportedRelationships; + } + @Override protected Relationship beforeObjectHandled(Relationship relationship) { if (!versionManager.isRelationshipSupported(relationship)) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttribute.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttribute.java index 8523a7fa62..e44d544e75 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttribute.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttribute.java @@ -121,6 +121,10 @@ public abstract class TrackedEntityAttribute extends BaseNameableObject @JsonProperty() public abstract String formName(); + @Nullable + @JsonProperty() + public abstract String displayFormName(); + public static Builder builder() { return new $$AutoValue_TrackedEntityAttribute.Builder(); } @@ -171,6 +175,8 @@ public abstract static class Builder extends BaseNameableObject.Builder public abstract Builder formName(String formName); + public abstract Builder displayFormName(String displayFormName); + abstract TrackedEntityAttribute autoBuild(); // Auxiliary fields diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeCollectionRepository.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeCollectionRepository.java index e97dcf3cdd..e5dfdb02d3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeCollectionRepository.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeCollectionRepository.java @@ -116,6 +116,10 @@ public StringFilterConnector byFormN return cf.string(Columns.FORM_NAME); } + public StringFilterConnector byDisplayFormName() { + return cf.string(Columns.DISPLAY_FORM_NAME); + } + public StringFilterConnector byColor() { return cf.string(Columns.COLOR); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeTableInfo.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeTableInfo.java index fae3308651..42b4ed0e45 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeTableInfo.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeTableInfo.java @@ -65,6 +65,7 @@ public static class Columns extends NameableWithStyleColumns { public static final String INHERIT = "inherit"; public static final String FIELD_MASK = "fieldMask"; public static final String FORM_NAME = "formName"; + public static final String DISPLAY_FORM_NAME = "displayFormName"; @Override public String[] all() { @@ -82,6 +83,7 @@ public String[] all() { UNIQUE, INHERIT, FORM_NAME, + DISPLAY_FORM_NAME, FIELD_MASK ); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeFields.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeFields.java index 7ab49bede3..02279552a4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeFields.java @@ -69,7 +69,8 @@ public final class TrackedEntityAttributeFields { fh.nestedFieldWithUid(Columns.OPTION_SET), fh.nestedField(STYLE).with(ObjectStyleFields.allFields), fh.nestedField(ACCESS).with(AccessFields.read), - fh.field(Columns.FORM_NAME) + fh.field(Columns.FORM_NAME), + fh.field(Columns.DISPLAY_FORM_NAME) ).build(); private TrackedEntityAttributeFields() { diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeHandler.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeHandler.java index a5ae391de9..31bb986f97 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeHandler.java @@ -46,7 +46,17 @@ final class TrackedEntityAttributeHandler extends IdentifiableHandlerImpl queryPerProgram(ProgramDataDownloadParams params, String programUid, String globalLastUpdated) { int limit = getLimit(params, programSettings, programUid); + + if (limit == 0) { + return Collections.emptyList(); + } + EnrollmentStatus programStatus = getProgramStatus(params, programSettings, programUid); String programStartDate = getProgramStartDate(programSettings, programUid); String lastUpdated = globalLastUpdated == null && params.uids().isEmpty() ? getInitialLastpdated(programSettings, programUid) : globalLastUpdated; - List builders = new ArrayList<>(); - OrganisationUnitMode ouMode; List orgUnits; @@ -149,6 +152,8 @@ private List queryPerProgram(ProgramDataDownloadParams params, orgUnits = getRootCaptureOrgUnitUids(); } + List builders = new ArrayList<>(); + if (hasLimitByOrgunit) { for (String orgUnitUid : orgUnits) { builders.add(getBuilderFor(lastUpdated, Collections.singletonList(orgUnitUid), ouMode, params, limit) @@ -167,11 +172,13 @@ private List queryGlobal(ProgramDataDownloadParams params, String globalLastUpdated) { int limit = getLimit(params, programSettings, null); + if (limit == 0) { + return Collections.emptyList(); + } + String lastUpdated = globalLastUpdated == null && params.uids().isEmpty() ? getInitialLastpdated(programSettings, null) : globalLastUpdated; - List builders = new ArrayList<>(); - OrganisationUnitMode ouMode; List orgUnits; @@ -188,6 +195,8 @@ private List queryGlobal(ProgramDataDownloadParams params, orgUnits = getRootCaptureOrgUnitUids(); } + List builders = new ArrayList<>(); + if (hasLimitByOrgunit) { for (String orgUnitUid : orgUnits) { builders.add(getBuilderFor(lastUpdated, Collections.singletonList(orgUnitUid), ouMode, params, limit)); @@ -285,7 +294,8 @@ private boolean hasLimitByOrgUnit(ProgramDataDownloadParams params, ProgramSetti private int getLimit(ProgramDataDownloadParams params, ProgramSettings programSettings, String programUid) { - if (params.limit() != null) { + + if (params.limit() != null && isGlobalOrUserDefinedProgram(params, programUid)) { return params.limit(); } @@ -307,7 +317,8 @@ private int getLimit(ProgramDataDownloadParams params, private EnrollmentStatus getProgramStatus(ProgramDataDownloadParams params, ProgramSettings programSettings, String programUid) { - if (params.programStatus() != null) { + + if (params.programStatus() != null && isGlobalOrUserDefinedProgram(params, programUid)) { return enrollmentScopeToProgramStatus(params.programStatus()); } @@ -384,4 +395,7 @@ private boolean hasUpdateDownload(ProgramSetting programSetting) { return programSetting != null && programSetting.updateDownload() != null; } + private boolean isGlobalOrUserDefinedProgram(ProgramDataDownloadParams params, String programUid) { + return programUid == null || programUid.equals(params.program()); + } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceLocalQueryHelper.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceLocalQueryHelper.java index d655be365b..b660f7aa59 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceLocalQueryHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceLocalQueryHelper.java @@ -29,8 +29,6 @@ package org.hisp.dhis.android.core.trackedentity.search; import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder; -import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper; -import org.hisp.dhis.android.core.arch.helpers.internal.EnumHelper; import org.hisp.dhis.android.core.arch.repositories.scope.internal.FilterItemOperator; import org.hisp.dhis.android.core.arch.repositories.scope.internal.RepositoryScopeFilterItem; import org.hisp.dhis.android.core.common.AssignedUserMode; @@ -60,7 +58,6 @@ final class TrackedEntityInstanceLocalQueryHelper { private static String TEI_UID = dot(TEI_ALIAS, "uid"); private static String TEI_ALL = dot(TEI_ALIAS, "*"); - private static String TEI_STATE = dot(TEI_ALIAS, DataColumns.STATE); private static String TEI_LAST_UPDATED = dot(TEI_ALIAS, "lastUpdated"); private static String ENROLLMENT_DATE = EnrollmentTableInfo.Columns.ENROLLMENT_DATE; @@ -132,16 +129,7 @@ static String getSqlQuery(TrackedEntityInstanceQueryRepositoryScope scope, List< } // TODO In case a program uid is provided, the server orders by enrollmentStatus. - String order1 = CollectionsHelper.commaAndSpaceSeparatedArrayValues( - CollectionsHelper.withSingleQuotationMarksArray( - EnumHelper.asStringList(State.TO_POST, State.TO_UPDATE, State.UPLOADING))); - String order2 = CollectionsHelper.commaAndSpaceSeparatedArrayValues( - CollectionsHelper.withSingleQuotationMarksArray( - EnumHelper.asStringList(State.SYNCED, State.SYNCED_VIA_SMS, State.SENT_VIA_SMS))); - queryStr += " ORDER BY CASE " + - "WHEN " + TEI_STATE + " IN (" + order1 + ") THEN 1 " + - "WHEN " + TEI_STATE + " IN (" + order2 + ") THEN 2 ELSE 3 END ASC, " + - TEI_LAST_UPDATED + " DESC "; + queryStr += " ORDER BY " + TEI_LAST_UPDATED + " DESC "; if (limit > 0) { queryStr += " LIMIT " + limit; diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/program/ProgramSectionAttributeLinkSamples.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/program/ProgramSectionAttributeLinkSamples.java index 17cf8d5b53..9e180e5e18 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/program/ProgramSectionAttributeLinkSamples.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/program/ProgramSectionAttributeLinkSamples.java @@ -37,6 +37,7 @@ public static ProgramSectionAttributeLink getProgramSectionAttributeLink() { .id(1L) .programSection("program_section") .attribute("attribute") + .sortOrder(1) .build(); } } \ No newline at end of file diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/trackedentity/TrackedEntityAttributeSamples.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/trackedentity/TrackedEntityAttributeSamples.java index d1a34e25d7..9054f3c4a5 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/trackedentity/TrackedEntityAttributeSamples.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/trackedentity/TrackedEntityAttributeSamples.java @@ -57,6 +57,7 @@ public static TrackedEntityAttribute get() { .inherit(Boolean.TRUE) .fieldMask("XXXXX") .formName("form_name") + .displayFormName("display_form_name") .build(); } } \ No newline at end of file diff --git a/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute.json b/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute.json index 0e165fbf4c..548bea0679 100644 --- a/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute.json +++ b/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute.json @@ -24,6 +24,8 @@ "unique": false, "inherit": false, "fieldMask": "XXXXX", + "formName": "number", + "displayFormName": "num", "optionSetValue": false, "dimensionItemType": "PROGRAM_ATTRIBUTE", "access": { diff --git a/core/src/sharedTest/resources/trackedentity/tracked_entity_attributes.json b/core/src/sharedTest/resources/trackedentity/tracked_entity_attributes.json index 9ada04bae7..3727b3bd5f 100644 --- a/core/src/sharedTest/resources/trackedentity/tracked_entity_attributes.json +++ b/core/src/sharedTest/resources/trackedentity/tracked_entity_attributes.json @@ -31,6 +31,7 @@ "name": "Age", "shortName": "Age", "formName": "formname", + "displayFormName": "displayformname", "valueType": "TEXT", "programScope": true, "orgunitScope": true, diff --git a/core/src/test/java/org/hisp/dhis/android/core/domain/aggregated/data/internal/AggregatedDataCallBundleFactoryShould.java b/core/src/test/java/org/hisp/dhis/android/core/domain/aggregated/data/internal/AggregatedDataCallBundleFactoryShould.java index c6e6533498..e19e458215 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/domain/aggregated/data/internal/AggregatedDataCallBundleFactoryShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/domain/aggregated/data/internal/AggregatedDataCallBundleFactoryShould.java @@ -30,6 +30,7 @@ import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore; import org.hisp.dhis.android.core.dataset.DataSet; +import org.hisp.dhis.android.core.period.Period; import org.hisp.dhis.android.core.period.PeriodType; import org.hisp.dhis.android.core.period.internal.PeriodForDataSetManager; import org.hisp.dhis.android.core.settings.DataSetSettings; @@ -47,6 +48,8 @@ import java.util.List; import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.when; @RunWith(JUnit4.class) @@ -79,6 +82,8 @@ public class AggregatedDataCallBundleFactoryShould { private List rootOrgUnits = Arrays.asList(ou1, ou2); + private List periods = Collections.singletonList(Period.builder().periodId("202002").build()); + // Object to test private AggregatedDataCallBundleFactory bundleFactory; @@ -89,6 +94,8 @@ public void setUp() throws Exception { when(dataSet1.uid()).thenReturn(ds1); when(dataSet2.uid()).thenReturn(ds2); when(dataSetSettings.specificSettings()).thenReturn(Collections.emptyMap()); + when(periodManager.getPeriodsInRange(PeriodType.Monthly, 0, 0)).thenReturn(Collections.emptyList()); + when(periodManager.getPeriodsInRange(any(), anyInt(), anyInt())).thenReturn(periods); bundleFactory = new AggregatedDataCallBundleFactory(dataSetStore, userOrganisationUnitLinkStore, dataSetSettingsObjectRepository, periodManager); diff --git a/core/src/test/java/org/hisp/dhis/android/core/event/internal/EventQueryBundleFactoryShould.java b/core/src/test/java/org/hisp/dhis/android/core/event/internal/EventQueryBundleFactoryShould.java index d652ee5094..ef75fb52f5 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/event/internal/EventQueryBundleFactoryShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/event/internal/EventQueryBundleFactoryShould.java @@ -169,6 +169,29 @@ public void get_event_date_if_defined() { } } + @Test + public void apply_user_defined_limit_only_to_global_if_no_program() { + ProgramDataDownloadParams params = ProgramDataDownloadParams.builder().limit(5000).build(); + + Map specificSettings = new HashMap<>(); + specificSettings.put(p1, ProgramSetting.builder().uid(p1).eventsDownload(100).build()); + + when(programSettings.specificSettings()).thenReturn(specificSettings); + + List bundles = bundleFactory.getEventQueryBundles(params); + + assertThat(bundles.size()).isEqualTo(2); + + for (EventQueryBundle bundle : bundles) { + if (bundle.programList().size() == 1) { + assertThat(bundle.programList().get(0)).isEqualTo(p1); + assertThat(bundle.limit()).isEqualTo(100); + } else { + assertThat(bundle.limit()).isEqualTo(5000); + } + } + } + private List getProgramList() { List programList = new ArrayList<>(); programList.add(p1); diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/internal/AbstractPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/internal/AbstractPeriodGeneratorShould.java index 8151b2c60b..0ed643ef42 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/internal/AbstractPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/internal/AbstractPeriodGeneratorShould.java @@ -83,12 +83,8 @@ public void throw_exception_for_negative_periods() { } @Test - public void throw_exception_for_zero_periods() { - try { - generator.generatePeriods(0, 0); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } + public void empty_list_for_zero_periods() { + List periods = generator.generatePeriods(0, 0); + assertThat(periods).isEmpty(); } } \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/internal/ProgramSectionHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/internal/ProgramSectionHandlerShould.java index 9dbada4883..cbb74ab527 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/internal/ProgramSectionHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/internal/ProgramSectionHandlerShould.java @@ -31,8 +31,7 @@ import org.assertj.core.util.Lists; import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore; import org.hisp.dhis.android.core.arch.handlers.internal.IdentifiableHandlerImpl; -import org.hisp.dhis.android.core.arch.handlers.internal.LinkHandler; -import org.hisp.dhis.android.core.arch.handlers.internal.Transformer; +import org.hisp.dhis.android.core.arch.handlers.internal.OrderedLinkHandler; import org.hisp.dhis.android.core.program.ProgramSection; import org.hisp.dhis.android.core.program.ProgramSectionAttributeLink; import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttribute; @@ -45,8 +44,8 @@ import java.util.List; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.same; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -58,7 +57,7 @@ public class ProgramSectionHandlerShould { private IdentifiableObjectStore programSectionStore; @Mock - private LinkHandler + private OrderedLinkHandler programSectionAttributeLinkHandler; @Mock @@ -85,7 +84,7 @@ public void setUp() throws Exception { public void save_program_section_attribute_links() throws Exception { programSectionHandler.handle(programSection); verify(programSectionAttributeLinkHandler).handleMany(same(SECTION_UID), - anyListOf(TrackedEntityAttribute.class), any(Transformer.class)); + anyList(), any()); } @Test diff --git a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeShould.java b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeShould.java index da895fba7d..3792c05cc0 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeShould.java @@ -61,6 +61,8 @@ public void map_from_json_string() throws IOException, ParseException { assertThat(trackedEntityAttribute.displayShortName()).isEqualTo("TB number"); assertThat(trackedEntityAttribute.description()).isEqualTo("TB number"); assertThat(trackedEntityAttribute.displayDescription()).isEqualTo("TB number"); + assertThat(trackedEntityAttribute.formName()).isEqualTo("number"); + assertThat(trackedEntityAttribute.displayFormName()).isEqualTo("num"); assertThat(trackedEntityAttribute.displayInListNoProgram()).isFalse(); assertThat(trackedEntityAttribute.displayOnVisitSchedule()).isFalse(); assertThat(trackedEntityAttribute.generated()).isFalse(); diff --git a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeHandlerShould.java index 57db94bc44..7897877b8d 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeHandlerShould.java @@ -52,15 +52,14 @@ public class TrackedEntityAttributeHandlerShould { @Mock private IdentifiableObjectStore trackedEntityAttributeStore; - @Mock - private TrackedEntityAttribute trackedEntityAttribute; - @Mock private ObjectStyle objectStyle; @Mock private Access access; + private TrackedEntityAttribute trackedEntityAttribute; + // object to test private List trackedEntityAttributes; private TrackedEntityAttributeHandler trackedEntityAttributeHandler; @@ -70,13 +69,18 @@ public void setUp() throws Exception { MockitoAnnotations.initMocks(this); trackedEntityAttributeHandler = new TrackedEntityAttributeHandler(trackedEntityAttributeStore); + trackedEntityAttribute = TrackedEntityAttribute.builder() + .uid("test_tracked_entity_attribute_uid") + .style(objectStyle) + .name("name") + .displayName("display_name") + .formName("form_name") + .access(access) + .build(); + trackedEntityAttributes = new ArrayList<>(); trackedEntityAttributes.add(trackedEntityAttribute); - when(trackedEntityAttribute.uid()).thenReturn("test_tracked_entity_attribute_uid"); - when(trackedEntityAttribute.style()).thenReturn(objectStyle); - when(trackedEntityAttribute.formName()).thenReturn("form_name"); - when(trackedEntityAttribute.access()).thenReturn(access); when(access.read()).thenReturn(true); } diff --git a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceQueryBuilderFactoryShould.java b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceQueryBuilderFactoryShould.java index 0cecb90284..15bad40ef1 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceQueryBuilderFactoryShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceQueryBuilderFactoryShould.java @@ -162,6 +162,31 @@ public void single_query_if_program_provided_by_user() { } } + @Test + public void apply_user_defined_limit_only_to_global_if_no_program() { + ProgramDataDownloadParams params = ProgramDataDownloadParams.builder().limit(5000).build(); + + Map specificSettings = new HashMap<>(); + specificSettings.put(p1, ProgramSetting.builder().uid(p1).teiDownload(100).build()); + + when(programSettings.specificSettings()).thenReturn(specificSettings); + + List builders = builderFactory.getTeiQueryBuilders(params); + + assertThat(builders.size()).isEqualTo(2); + + for (TeiQuery.Builder builder : builders) { + TeiQuery query = builder.build(); + + if (query.program() != null) { + assertThat(query.program()).isEqualTo(p1); + assertThat(query.limit()).isEqualTo(100); + } else { + assertThat(query.limit()).isEqualTo(5000); + } + } + } + private List getProgramList() { List programList = new ArrayList<>(); programList.add(p1); diff --git a/docs/content/developer/compatibility.md b/docs/content/developer/compatibility.md index b0aa407c24..ca828f12d9 100644 --- a/docs/content/developer/compatibility.md +++ b/docs/content/developer/compatibility.md @@ -12,3 +12,4 @@ Compatibility table between DHIS2 Android SDK library, DHIS2 core and Android SD | 1.0.3 | 2.29 -> 2.33 | 19 - 28 | | 1.1.0 | 2.29 -> 2.34 | 19 - 28 | | 1.1.1 | 2.29 -> 2.34 | 19 - 28 | +| 1.1.2 | 2.29 -> 2.34 | 19 - 28 | diff --git a/docs/content/developer/getting-started.md b/docs/content/developer/getting-started.md index 78a00535c5..d610ce6096 100644 --- a/docs/content/developer/getting-started.md +++ b/docs/content/developer/getting-started.md @@ -10,7 +10,7 @@ Include dependency in build.gradle. ```gradle dependencies { - implementation "org.hisp.dhis:android-core:1.1.1" + implementation "org.hisp.dhis:android-core:1.1.2" ... } ``` diff --git a/docs/dhis2_android_sdk_developer_guide_INDEX.md b/docs/dhis2_android_sdk_developer_guide_INDEX.md index 792deffbd2..db48cba920 100644 --- a/docs/dhis2_android_sdk_developer_guide_INDEX.md +++ b/docs/dhis2_android_sdk_developer_guide_INDEX.md @@ -3,11 +3,11 @@ title: 'DHIS 2 Android SDK Developer Guide' author: 'DHIS 2' date: year: 2020 -month: May +month: June keywords: [DHIS2, Android] commit: version: master -applicable_txt: 'Applicable to version 1.1.1' +applicable_txt: 'Applicable to version 1.1.2' ---