Skip to content

Commit

Permalink
Merge pull request #1584 from dhis2/master-dev
Browse files Browse the repository at this point in the history
fix: [MASTER-DEV] Version 1.4.2
  • Loading branch information
vgarciabnz authored Jun 30, 2021
2 parents 5c8455f + fa1d45f commit 476b5be
Show file tree
Hide file tree
Showing 24 changed files with 1,042 additions and 634 deletions.
4 changes: 2 additions & 2 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ ext {
buildToolsVersion: "29.0.3",
minSdkVersion : 19,
targetSdkVersion : 29,
versionCode : 241,
versionName : "1.4.1"
versionCode : 242,
versionName : "1.4.2"
]

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

VERSION_NAME=1.4.1
VERSION_CODE=241
VERSION_NAME=1.4.2
VERSION_CODE=242

GROUP=org.hisp.dhis

Expand Down

This file was deleted.

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions core/src/main/assets/migrations/100.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Fix for Nigeria issue ANDROSDK-1396
UPDATE Event SET state = 'TO_UPDATE' WHERE state = 'UPLOADING';

UPDATE Enrollment SET state = 'TO_UPDATE' WHERE state = 'UPLOADING' OR uid IN (SELECT enrollment FROM Event WHERE state IN ('TO_POST', 'TO_UPDATE'));
UPDATE Enrollment SET state = 'ERROR' WHERE uid IN (SELECT enrollment FROM Event WHERE state IN ('ERROR', 'WARNING'));

UPDATE TrackedEntityInstance SET state = 'TO_UPDATE' WHERE state = 'UPLOADING' OR uid IN (SELECT trackedEntityInstance FROM Enrollment WHERE state IN ('TO_POST', 'TO_UPDATE'));
UPDATE TrackedEntityInstance SET state = 'ERROR' WHERE uid IN (SELECT trackedEntityInstance FROM Enrollment WHERE state IN ('ERROR', 'WARNING'));
11 changes: 11 additions & 0 deletions core/src/main/assets/migrations/101.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Fix missing ON CASCADE modifiers ANDROSDK-1398

ALTER TABLE DataElementOperand RENAME TO DataElementOperand_Old;
CREATE TABLE DataElementOperand (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, dataElement TEXT, categoryOptionCombo TEXT, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED);
INSERT INTO DataElementOperand (_id, uid, dataElement, categoryOptionCombo) SELECT _id, uid, dataElement, categoryOptionCombo FROM DataElementOperand_Old;
DROP TABLE DataElementOperand_Old;

ALTER TABLE TrackerImportConflict RENAME TO TrackerImportConflict_Old;
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, displayDescription TEXT, trackedEntityAttribute TEXT, dataElement TEXT, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED);
INSERT INTO TrackerImportConflict (_id, conflict, value, trackedEntityInstance, enrollment, event, tableReference, errorCode, status, created, displayDescription, trackedEntityAttribute, dataElement) SELECT _id, conflict, value, trackedEntityInstance, enrollment, event, tableReference, errorCode, status, created, displayDescription, trackedEntityAttribute, dataElement FROM TrackerImportConflict_Old;
DROP TABLE TrackerImportConflict_Old;
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ CREATE TABLE OrganisationUnitGroup (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid T
CREATE TABLE OrganisationUnitOrganisationUnitGroupLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, organisationUnit TEXT NOT NULL, organisationUnitGroup TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnitGroup) REFERENCES OrganisationUnitGroup (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, organisationUnitGroup));
CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, displayInReports INTEGER, compulsory INTEGER, allowProvidedElsewhere INTEGER, sortOrder INTEGER, allowFutureDate INTEGER, dataElement TEXT NOT NULL, programStage TEXT NOT NULL, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE ProgramStageSectionDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programStageSection TEXT NOT NULL, dataElement TEXT NOT NULL, sortOrder INTEGER NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE DataElementOperand (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, dataElement TEXT, categoryOptionCombo TEXT, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE DataElementOperand (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, dataElement TEXT, categoryOptionCombo TEXT, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, number INTEGER, factor INTEGER);
CREATE TABLE ForeignKeyViolation (_id INTEGER PRIMARY KEY AUTOINCREMENT, fromTable TEXT, fromColumn TEXT, toTable TEXT, toColumn TEXT, notFoundValue TEXT, fromObjectUid TEXT, fromObjectRow TEXT, created TEXT);
CREATE TABLE D2Error (_id INTEGER PRIMARY KEY AUTOINCREMENT, resourceType TEXT, uid TEXT, url TEXT, errorComponent TEXT, errorCode TEXT, errorDescription TEXT, httpErrorCode INTEGER, created TEXT);
Expand All @@ -62,7 +62,7 @@ CREATE TABLE OrganisationUnitLevel (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid T
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, displayFormName 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, displayDescription TEXT, trackedEntityAttribute TEXT, dataElement 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 TrackerImportConflict (_id INTEGER PRIMARY KEY AUTOINCREMENT, conflict TEXT, value TEXT, trackedEntityInstance TEXT, enrollment TEXT, event TEXT, tableReference TEXT, errorCode TEXT, status TEXT, created TEXT, displayDescription TEXT, trackedEntityAttribute TEXT, dataElement TEXT, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE 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));
CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, fromToName TEXT, toFromName TEXT, bidirectional INTEGER, accessDataWrite INTEGER );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

class BaseDatabaseOpenHelper {

static final int VERSION = 99;
static final int VERSION = 101;

private final AssetManager assetManager;
private final int targetVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@
import org.hisp.dhis.android.core.common.DataColumns;
import org.hisp.dhis.android.core.common.State;
import org.hisp.dhis.android.core.common.internal.DataStatePropagator;
import org.hisp.dhis.android.core.enrollment.Enrollment;
import org.hisp.dhis.android.core.enrollment.EnrollmentInternalAccessor;
import org.hisp.dhis.android.core.enrollment.EnrollmentTableInfo;
import org.hisp.dhis.android.core.event.Event;
import org.hisp.dhis.android.core.event.internal.EventImportHandler;
import org.hisp.dhis.android.core.imports.TrackerImportConflict;
import org.hisp.dhis.android.core.imports.TrackerImportConflictTableInfo;
import org.hisp.dhis.android.core.imports.internal.BaseImportSummaryHelper;
import org.hisp.dhis.android.core.imports.internal.EnrollmentImportSummary;
import org.hisp.dhis.android.core.imports.internal.EventImportSummaries;
import org.hisp.dhis.android.core.imports.internal.ImportConflict;
Expand All @@ -51,6 +55,7 @@
import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstanceStore;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

Expand All @@ -61,6 +66,7 @@
import static org.hisp.dhis.android.core.arch.db.stores.internal.StoreUtils.getState;

@Reusable
@SuppressWarnings("PMD.ExcessiveImports")
public class EnrollmentImportHandler {
private final EnrollmentStore enrollmentStore;
private final TrackedEntityInstanceStore trackedEntityInstanceStore;
Expand Down Expand Up @@ -88,44 +94,54 @@ public EnrollmentImportHandler(@NonNull EnrollmentStore enrollmentStore,
}

public void handleEnrollmentImportSummary(List<EnrollmentImportSummary> enrollmentImportSummaries,
List<Enrollment> enrollments,
String teiUid) {
if (enrollmentImportSummaries == null) {
return;
}

State parentState = null;
for (EnrollmentImportSummary enrollmentImportSummary : enrollmentImportSummaries) {
if (enrollmentImportSummary == null) {
break;
}

State state = getState(enrollmentImportSummary.status());
if (enrollmentImportSummaries != null) {
for (EnrollmentImportSummary enrollmentImportSummary : enrollmentImportSummaries) {
String enrollmentUid = enrollmentImportSummary == null ? null : enrollmentImportSummary.reference();

if (enrollmentUid == null) {
continue;
}

State state = getState(enrollmentImportSummary.status());
deleteEnrollmentConflicts(enrollmentUid);

HandleAction handleAction = null;
HandleAction handleAction = enrollmentStore.setStateOrDelete(enrollmentUid, state);

if (enrollmentImportSummary.reference() != null) {
handleAction = enrollmentStore.setStateOrDelete(enrollmentImportSummary.reference(), state);
if (state == State.ERROR || state == State.WARNING) {
if (state.equals(State.ERROR) || state.equals(State.WARNING)) {
parentState = parentState == State.ERROR ? State.ERROR : state;
dataStatePropagator.resetUploadingEventStates(enrollmentImportSummary.reference());
dataStatePropagator.resetUploadingEventStates(enrollmentUid);
}

deleteEnrollmentConflicts(enrollmentImportSummary.reference());
}
if (handleAction != HandleAction.Delete) {
storeEnrollmentImportConflicts(enrollmentImportSummary, teiUid);
handleNoteImportSummary(enrollmentUid, state);
handleEventImportSummaries(enrollmentImportSummary, enrollments, teiUid);
}

if (handleAction != HandleAction.Delete) {
handleNoteImportSummary(enrollmentImportSummary.reference(), state);
}
}

storeEnrollmentImportConflicts(enrollmentImportSummary, teiUid);
List<String> processedEnrollments = BaseImportSummaryHelper.getReferences(enrollmentImportSummaries);
for (Enrollment enrollment : enrollments) {
if (!processedEnrollments.contains(enrollment.uid())) {
State state = State.TO_UPDATE;
enrollmentStore.setStateOrDelete(enrollment.uid(), state);
parentState = parentState == State.ERROR || parentState == State.WARNING ? parentState : state;
dataStatePropagator.resetUploadingEventStates(enrollment.uid());

handleEventImportSummaries(enrollmentImportSummary, teiUid);
deleteEnrollmentConflicts(enrollment.uid());
}
}

updateParentState(parentState, teiUid);
}

private void handleEventImportSummaries(EnrollmentImportSummary enrollmentImportSummary,
List<Enrollment> enrollments,
String teiUid) {

if (enrollmentImportSummary.events() != null) {
Expand All @@ -134,9 +150,9 @@ private void handleEventImportSummaries(EnrollmentImportSummary enrollmentImport
if (eventImportSummaries.importSummaries() != null) {
eventImportHandler.handleEventImportSummaries(
eventImportSummaries.importSummaries(),
getEvents(enrollmentImportSummary.reference(), enrollments),
enrollmentImportSummary.reference(),
teiUid);

}
}
}
Expand Down Expand Up @@ -193,6 +209,16 @@ private void deleteEnrollmentConflicts(String enrollmentUid) {
trackerImportConflictStore.deleteWhereIfExists(whereClause);
}

private List<Event> getEvents(String enrollmentUid,
List<Enrollment> enrollments) {
for (Enrollment enrollment : enrollments) {
if (enrollmentUid.equals(enrollment.uid())) {
return EnrollmentInternalAccessor.accessEvents(enrollment);
}
}
return Collections.emptyList();
}

private TrackerImportConflict.Builder getConflictBuilder(String trackedEntityInstanceUid,
EnrollmentImportSummary enrollmentImportSummary) {
return TrackerImportConflict.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
import org.hisp.dhis.android.core.common.DataColumns;
import org.hisp.dhis.android.core.common.State;
import org.hisp.dhis.android.core.enrollment.internal.EnrollmentStore;
import org.hisp.dhis.android.core.event.Event;
import org.hisp.dhis.android.core.event.EventTableInfo;
import org.hisp.dhis.android.core.imports.TrackerImportConflict;
import org.hisp.dhis.android.core.imports.TrackerImportConflictTableInfo;
import org.hisp.dhis.android.core.imports.internal.BaseImportSummaryHelper;
import org.hisp.dhis.android.core.imports.internal.EventImportSummary;
import org.hisp.dhis.android.core.imports.internal.ImportConflict;
import org.hisp.dhis.android.core.imports.internal.TrackerImportConflictParser;
Expand Down Expand Up @@ -83,35 +85,43 @@ public EventImportHandler(@NonNull EventStore eventStore,
}

public void handleEventImportSummaries(List<EventImportSummary> eventImportSummaries,
List<Event> events,
String enrollmentUid,
String teiUid) {
if (eventImportSummaries == null) {
return;
}

State parentState = null;
for (EventImportSummary eventImportSummary : eventImportSummaries) {
if (eventImportSummary == null) {
break;
}

State state = getState(eventImportSummary.status());
if (eventImportSummaries != null) {
for (EventImportSummary eventImportSummary : eventImportSummaries) {
String eventUid = eventImportSummary == null ? null : eventImportSummary.reference();

if (eventUid == null) {
continue;
}

State state = getState(eventImportSummary.status());
deleteEventConflicts(eventUid);

HandleAction handleAction = null;
HandleAction handleAction = eventStore.setStateOrDelete(eventUid, state);

if (eventImportSummary.reference() != null) {
handleAction = eventStore.setStateOrDelete(eventImportSummary.reference(), state);
if (state == State.ERROR || state == State.WARNING) {
parentState = parentState == State.ERROR ? State.ERROR : state;
}

deleteEventConflicts(eventImportSummary.reference());
if (handleAction != HandleAction.Delete) {
storeEventImportConflicts(eventImportSummary, teiUid, enrollmentUid);
handleNoteImportSummary(eventUid, state);
}
}
}

if (handleAction != HandleAction.Delete) {
handleNoteImportSummary(eventImportSummary.reference(), state);
List<String> processedEvents = BaseImportSummaryHelper.getReferences(eventImportSummaries);
for (Event event : events) {
if (!processedEvents.contains(event.uid())) {
State state = State.TO_UPDATE;
eventStore.setStateOrDelete(event.uid(), state);
parentState = parentState == State.ERROR || parentState == State.WARNING ? parentState : state;

storeEventImportConflicts(eventImportSummary, teiUid, enrollmentUid);
deleteEventConflicts(event.uid());
}
}

Expand Down
Loading

0 comments on commit 476b5be

Please sign in to comment.