From 1fd5667e9789feff3ec21441a5b7adad336fba9c Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 25 May 2020 09:31:57 +0200 Subject: [PATCH 1/3] [ANDROSDK-831] Add support for TrackedEntityAttribute displayFormName --- ...uteCollectionRepositoryMockIntegrationShould.java | 10 ++++++++++ core/src/main/assets/migrations/75.sql | 3 +++ core/src/main/assets/snapshots/{74.sql => 75.sql} | 2 +- .../db/access/internal/BaseDatabaseOpenHelper.java | 2 +- .../access/internal/DatabaseMigrationExecutor.java | 2 +- .../core/trackedentity/TrackedEntityAttribute.java | 12 ++++++++++++ .../TrackedEntityAttributeCollectionRepository.java | 4 ++++ .../TrackedEntityAttributeTableInfo.java | 2 ++ .../internal/TrackedEntityAttributeFields.java | 3 ++- .../internal/TrackedEntityAttributeStore.java | 3 ++- .../trackedentity/TrackedEntityAttributeSamples.java | 1 + .../trackedentity/tracked_entity_attribute.json | 2 ++ .../trackedentity/tracked_entity_attributes.json | 1 + .../trackedentity/TrackedEntityAttributeShould.java | 2 ++ 14 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 core/src/main/assets/migrations/75.sql rename core/src/main/assets/snapshots/{74.sql => 75.sql} (99%) 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/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/74.sql b/core/src/main/assets/snapshots/75.sql similarity index 99% rename from core/src/main/assets/snapshots/74.sql rename to core/src/main/assets/snapshots/75.sql index d38a85bec2..91d6dfde60 100644 --- a/core/src/main/assets/snapshots/74.sql +++ b/core/src/main/assets/snapshots/75.sql @@ -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 18ed741e69..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 = 74; + 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 ef858f3505..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 = 74; + 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/trackedentity/TrackedEntityAttribute.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttribute.java index 8523a7fa62..520c13021a 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,11 +175,15 @@ 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 abstract Access access(); abstract ObjectStyle style(); + abstract String displayName(); + abstract String displayFormName(); public TrackedEntityAttribute build() { try { @@ -190,6 +198,10 @@ public TrackedEntityAttribute build() { style(ObjectStyle.builder().build()); } + if (displayFormName() == null) { + displayFormName(displayName()); + } + return autoBuild(); } } 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/TrackedEntityAttributeStore.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeStore.java index 69d8114bf3..cef8b99a52 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeStore.java @@ -63,7 +63,8 @@ public void bindToStatement(@NonNull TrackedEntityAttribute o, @NonNull Statemen w.bind(23, o.unique()); w.bind(24, o.inherit()); w.bind(25, o.formName()); - w.bind(26, o.fieldMask()); + w.bind(26, o.displayFormName()); + w.bind(27, o.fieldMask()); } }; 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/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(); From b05be5646282d1e39f54386474b088455e393978 Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 25 May 2020 10:43:13 +0200 Subject: [PATCH 2/3] [ANDROSDK-831] Handle null displayFormName in handler --- .../core/trackedentity/TrackedEntityAttribute.java | 6 ------ .../internal/TrackedEntityAttributeHandler.java | 12 +++++++++++- 2 files changed, 11 insertions(+), 7 deletions(-) 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 520c13021a..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 @@ -182,8 +182,6 @@ public abstract static class Builder extends BaseNameableObject.Builder // Auxiliary fields abstract Access access(); abstract ObjectStyle style(); - abstract String displayName(); - abstract String displayFormName(); public TrackedEntityAttribute build() { try { @@ -198,10 +196,6 @@ public TrackedEntityAttribute build() { style(ObjectStyle.builder().build()); } - if (displayFormName() == null) { - displayFormName(displayName()); - } - return autoBuild(); } } 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 Date: Mon, 25 May 2020 12:29:05 +0200 Subject: [PATCH 3/3] [ANDROSDK-831] Fix TEA handler test --- .../TrackedEntityAttributeHandlerShould.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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); }