Skip to content

Commit

Permalink
Merge pull request #1267 from dhis2/androsdk-1147
Browse files Browse the repository at this point in the history
fix: [ANDROSDK-1147] Add sortOrder in ProgramSectionAttributes
  • Loading branch information
vgarciabnz authored May 21, 2020
2 parents 26733e2 + da05479 commit cefec9e
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 22 deletions.
3 changes: 3 additions & 0 deletions core/src/main/assets/migrations/74.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Related to ANDROSDK-1147
ALTER TABLE ProgramSectionAttributeLink ADD COLUMN sortOrder INTEGER;
UPDATE ProgramSectionAttributeLink SET sortOrder=_id;
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

class BaseDatabaseOpenHelper {

static final int VERSION = 73;
static final int VERSION = 74;

private final AssetManager assetManager;
private final int targetVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import android.database.Cursor;

import androidx.annotation.Nullable;
import androidx.annotation.NonNull;

import com.google.auto.value.AutoValue;

Expand All @@ -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();
}
Expand All @@ -64,6 +67,8 @@ public static abstract class Builder extends BaseObject.Builder<Builder> {

public abstract Builder attribute(String attribute);

public abstract Builder sortOrder(Integer integer);

public abstract ProgramSectionAttributeLink build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -50,8 +50,8 @@ public LinkStore<ProgramSectionAttributeLink> store(DatabaseAdapter databaseAdap

@Provides
@Reusable
public LinkHandler<TrackedEntityAttribute, ProgramSectionAttributeLink> handler(
public OrderedLinkHandler<TrackedEntityAttribute, ProgramSectionAttributeLink> handler(
LinkStore<ProgramSectionAttributeLink> store) {
return new LinkHandlerImpl<>(store);
return new OrderedLinkHandlerImpl<>(store);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public final class ProgramSectionAttributeLinkStore {
private static final StatementBinder<ProgramSectionAttributeLink> BINDER = (o, w) -> {
w.bind(1, o.programSection());
w.bind(2, o.attribute());
w.bind(3, o.sortOrder());
};

private ProgramSectionAttributeLinkStore() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,22 +42,24 @@

@Reusable
final class ProgramSectionHandler extends IdentifiableHandlerImpl<ProgramSection> {
private final LinkHandler<TrackedEntityAttribute, ProgramSectionAttributeLink>
private final OrderedLinkHandler<TrackedEntityAttribute, ProgramSectionAttributeLink>
programSectionAttributeLinkHandler;

@Inject
ProgramSectionHandler(IdentifiableObjectStore<ProgramSection> programSectionStore,
LinkHandler<TrackedEntityAttribute, ProgramSectionAttributeLink>
OrderedLinkHandler<TrackedEntityAttribute, ProgramSectionAttributeLink>
programSectionAttributeLinkHandler) {
super(programSectionStore);
this.programSectionAttributeLinkHandler = programSectionAttributeLinkHandler;
}

@Override
protected void afterObjectHandled(ProgramSection programSection, HandleAction action) {

programSectionAttributeLinkHandler.handleMany(programSection.uid(), programSection.attributes(),
trackedEntityAttribute -> ProgramSectionAttributeLink.builder()
.programSection(programSection.uid()).attribute(trackedEntityAttribute.uid()).build());
(trackedEntityAttribute, sortOrder) -> ProgramSectionAttributeLink.builder()
.programSection(programSection.uid())
.attribute(trackedEntityAttribute.uid())
.sortOrder(sortOrder)
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static ProgramSectionAttributeLink getProgramSectionAttributeLink() {
.id(1L)
.programSection("program_section")
.attribute("attribute")
.sortOrder(1)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -58,7 +57,7 @@ public class ProgramSectionHandlerShould {
private IdentifiableObjectStore<ProgramSection> programSectionStore;

@Mock
private LinkHandler<TrackedEntityAttribute, ProgramSectionAttributeLink>
private OrderedLinkHandler<TrackedEntityAttribute, ProgramSectionAttributeLink>
programSectionAttributeLinkHandler;

@Mock
Expand All @@ -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
Expand Down

0 comments on commit cefec9e

Please sign in to comment.