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/snapshots/73.sql b/core/src/main/assets/snapshots/74.sql similarity index 99% rename from core/src/main/assets/snapshots/73.sql rename to core/src/main/assets/snapshots/74.sql index 92a482f7a6..d38a85bec2 100644 --- a/core/src/main/assets/snapshots/73.sql +++ b/core/src/main/assets/snapshots/74.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); 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 66997cdb85..18ed741e69 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 = 73; + static final int VERSION = 74; 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 f745b0fb34..ef858f3505 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 = 73; + private static final int SNAPSHOT_VERSION = 74; DatabaseMigrationExecutor(DatabaseAdapter databaseAdapter, AssetManager assetManager) { this.databaseAdapter = databaseAdapter; 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/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/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