Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add not-null constraint for column trackedentitytypeid in trackedentity table [DHIS2-15066] #19112

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4627513
feat: Add not-null constraint for column trackedentitytypeid in track…
zubaira Nov 9, 2024
adf3d6a
Merge branch 'master' into DHIS2-15066
zubaira Nov 15, 2024
962dae2
fix test
zubaira Nov 15, 2024
972f8d5
fix unit test
zubaira Nov 16, 2024
e642c35
fix unit test
zubaira Nov 16, 2024
290ad52
fix unit test
zubaira Nov 16, 2024
bee4104
remove unused dependency
zubaira Nov 16, 2024
900f3d7
fix integration test
zubaira Nov 16, 2024
62ef7d6
fix controller tests
zubaira Nov 16, 2024
ea2402b
fix tests
zubaira Nov 16, 2024
81daef6
Merge branch 'master' into DHIS2-15066
zubaira Nov 21, 2024
4f26b27
update flyway to cover existin not null rows
zubaira Nov 21, 2024
adc0326
update flyway
zubaira Nov 21, 2024
4ac4a44
update flyway migration
zubaira Dec 4, 2024
13024a3
minor
zubaira Dec 4, 2024
2baca3a
minor
zubaira Dec 4, 2024
38edde3
Merge branch 'master' into DHIS2-15066
zubaira Dec 4, 2024
b0797bc
expcetion message
zubaira Dec 5, 2024
e62c46b
correction in markdown
zubaira Dec 5, 2024
72868f4
Find inconstent trackedentities, fix them and set trackentitytypeid n…
zubaira Dec 5, 2024
746ec8b
update
zubaira Dec 5, 2024
1484545
add exception
zubaira Dec 5, 2024
c3359ce
add exception
zubaira Dec 5, 2024
b265862
Merge branch 'master' into DHIS2-15066
zubaira Dec 5, 2024
d885171
code reviews
zubaira Dec 6, 2024
964ed52
code review
zubaira Dec 6, 2024
91189c9
minor
zubaira Dec 6, 2024
6dcdf05
fix unit test
zubaira Dec 6, 2024
f2adebf
set operation instead of looping through the records
zubaira Dec 6, 2024
cdb5bf8
Merge branch 'master' into DHIS2-15066
zubaira Dec 6, 2024
659a986
Merge branch 'master' into DHIS2-15066
zubaira Dec 11, 2024
cfea998
update flyway
zubaira Dec 11, 2024
2682751
Merge branch 'master' into DHIS2-15066
zubaira Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
foreign-key="fk_trackedentityinstance_organisationunitid" not-null="true" lazy="false"/>

<many-to-one name="trackedEntityType" class="org.hisp.dhis.trackedentity.TrackedEntityType"
column="trackedentitytypeid" foreign-key="fk_trackedentityinstance_trackedentitytypeid" lazy="false"/>
column="trackedentitytypeid" foreign-key="fk_trackedentityinstance_trackedentitytypeid" lazy="false" not-null="true"/>
</class>

<sql-query name="updateTrackedEntitiesLastUpdated">update trackedentity set lastUpdated = :lastUpdated, lastupdatedbyuserinfo = CAST(:lastupdatedbyuserinfo as jsonb) WHERE uid in :trackedEntities</sql-query>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.hisp.dhis.programrule.ProgramRuleVariableService;
import org.hisp.dhis.security.acl.AclService;
import org.hisp.dhis.test.TestBase;
import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserDetails;
import org.hisp.dhis.user.sharing.Sharing;
Expand Down Expand Up @@ -132,8 +133,11 @@ void setup() {
void testCopyProgramFromUidWithValidProgram() throws NotFoundException, ForbiddenException {

OrganisationUnit orgUnit = createOrganisationUnit("New Org 1");
TrackedEntityType trackedEntityType = createTrackedEntityType('E');

List<Enrollment> originalEnrollments =
List.of(createEnrollment(original, createTrackedEntity(orgUnit), orgUnit));
List.of(
createEnrollment(original, createTrackedEntity(orgUnit, trackedEntityType), orgUnit));
when(programService.getProgram(VALID_PROGRAM_UID)).thenReturn(original);

when(aclService.canWrite(UserDetails.fromUser(user), original)).thenReturn(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,14 +521,14 @@ private List<Enrollment> getEnrollments() {
}

private TrackedEntity getTrackedEntityA() {
TrackedEntity te = createTrackedEntity(organisationUnitA);
TrackedEntity te = createTrackedEntity(organisationUnitA, createTrackedEntityType('I'));
te.setTrackedEntityType(trackedEntityTypeA);
zubaira marked this conversation as resolved.
Show resolved Hide resolved

return te;
}

private TrackedEntity getTrackedEntityB() {
TrackedEntity te = createTrackedEntity(organisationUnitB);
TrackedEntity te = createTrackedEntity(organisationUnitB, createTrackedEntityType('F'));
te.setTrackedEntityType(trackedEntityTypeB);
zubaira marked this conversation as resolved.
Show resolved Hide resolved

return te;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void setUp() {
Program program = createProgram('A');
ProgramStage programStage = createProgramStage('A', program);

trackedEntity = createTrackedEntity(organisationUnit);
trackedEntity = createTrackedEntity(organisationUnit, createTrackedEntityType('P'));
trackedEntity.setUid(TE_UID.getValue());
enrollment = createEnrollment(program, trackedEntity, organisationUnit);
enrollment.setUid(EN_UID.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ public void setUp() {

OrganisationUnit organisationUnit = createOrganisationUnit('A');

teA = createTrackedEntity(organisationUnit);
teA = createTrackedEntity(organisationUnit, createTrackedEntityType('D'));
teA.setUid(TE_A_UID.getValue());
teB = createTrackedEntity(organisationUnit);
teB = createTrackedEntity(organisationUnit, createTrackedEntityType('E'));
teB.setUid(TE_B_UID.getValue());
teC = createTrackedEntity(organisationUnit);
teC = createTrackedEntity(organisationUnit, createTrackedEntityType('F'));
teC.setUid(TE_C_UID.getValue());

relationshipA =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void setUp() {
OrganisationUnit orgUnit = createOrganisationUnit('A');
Program program = createProgram('A');
Attribute attribute = createAttribute('A');
trackedEntity = createTrackedEntity('A', orgUnit);
trackedEntity = createTrackedEntity('A', orgUnit, createTrackedEntityType('U'));
trackedEntity.setUid(TE_UID.getValue());
trackedEntity.setAttributeValues(AttributeValues.of(Map.of(attribute.getUid(), UNIQUE_VALUE)));
enrollment = createEnrollment(program, trackedEntity, orgUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ private Attribute attribute(TrackedEntityAttribute trackedEntityAttribute, Strin
}

private TrackedEntity trackedEntity() {
return createTrackedEntity('I', organisationUnit, trackedEntityAttribute);
return createTrackedEntity(
'I', organisationUnit, trackedEntityAttribute, createTrackedEntityType('W'));
}

private org.hisp.dhis.tracker.imports.domain.Enrollment payloadEnrollment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private TrackedEntityType trackedEntityType(String uid, char uniqueChar) {
}

private TrackedEntity trackedEntity(UID uid, TrackedEntityType type, OrganisationUnit orgUnit) {
TrackedEntity te = createTrackedEntity(orgUnit);
TrackedEntity te = createTrackedEntity(orgUnit, createTrackedEntityType('R'));
te.setUid(uid.getValue());
te.setTrackedEntityType(type);
zubaira marked this conversation as resolved.
Show resolved Hide resolved
return te;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ void verifyValidationFailsForEnrollmentDeletionAndUserWithoutTrackedEntityTypeRe
}

private TrackedEntity teWithNoEnrollments() {
TrackedEntity trackedEntity = createTrackedEntity(organisationUnit);
TrackedEntity trackedEntity =
createTrackedEntity(organisationUnit, createTrackedEntityType('C'));
trackedEntity.setUid(TE_ID.getValue());
trackedEntity.setEnrollments(Sets.newHashSet());
trackedEntity.setTrackedEntityType(trackedEntityType);
zubaira marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ void verifySuccessEventValidationWhenEventHasNoOrgUnitAssigned() {
}

private TrackedEntity teWithNoEnrollments() {
TrackedEntity trackedEntity = createTrackedEntity(organisationUnit);
TrackedEntity trackedEntity =
createTrackedEntity(organisationUnit, createTrackedEntityType('E'));
trackedEntity.setUid(TE_ID.getValue());
trackedEntity.setEnrollments(Sets.newHashSet());
trackedEntity.setTrackedEntityType(trackedEntityType);
zubaira marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ void shouldFailWhenUpdateTEAndUserHasNoWriteAccess() {
}

private TrackedEntity teWithNoEnrollments() {
TrackedEntity trackedEntity = createTrackedEntity(organisationUnit);
TrackedEntity trackedEntity =
createTrackedEntity(organisationUnit, createTrackedEntityType('Z'));
trackedEntity.setUid(TE_ID.getValue());
trackedEntity.setEnrollments(Sets.newHashSet());
trackedEntity.setTrackedEntityType(trackedEntityType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setTrackedEntityType

Expand All @@ -311,7 +312,8 @@ private TrackedEntity teWithDeleteEnrollments() {
Enrollment enrollment = new Enrollment();
enrollment.setDeleted(true);

TrackedEntity trackedEntity = createTrackedEntity(organisationUnit);
TrackedEntity trackedEntity =
createTrackedEntity(organisationUnit, createTrackedEntityType('B'));
trackedEntity.setUid(TE_ID.getValue());
trackedEntity.setEnrollments(Sets.newHashSet(enrollment));
trackedEntity.setTrackedEntityType(trackedEntityType);
zubaira marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -320,7 +322,8 @@ private TrackedEntity teWithDeleteEnrollments() {
}

private TrackedEntity teWithEnrollments() {
TrackedEntity trackedEntity = createTrackedEntity(organisationUnit);
TrackedEntity trackedEntity =
createTrackedEntity(organisationUnit, createTrackedEntityType('R'));
trackedEntity.setUid(TE_ID.getValue());
trackedEntity.setEnrollments(Sets.newHashSet(new Enrollment()));
trackedEntity.setTrackedEntityType(trackedEntityType);
zubaira marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
DO $$
DECLARE
results RECORD;
inconsistent_records_count INTEGER;
BEGIN
SELECT COUNT(*) INTO inconsistent_records_count FROM trackedentity WHERE trackedentitytypeid IS NULL;

IF inconsistent_records_count > 0 THEN
RAISE NOTICE 'Inconsistencies found: %', inconsistent_records_count;

FOR results IN
SELECT programid, trackedentityid FROM enrollment WHERE trackedentityid IN (
SELECT trackedentityid
FROM trackedentity
WHERE trackedentitytypeid IS NULL
)
LOOP
UPDATE trackedentity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we shouldn't update any record.
We should only apply the constraint.
The we can suggest such a script in the migration notes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a lower possibility of errors if we handle the task ourselves rather than leaving it to the user. Therefore, we should aim to complete as much of the migration process as possible and leave as little as necessary for the user to manage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this kind of process that deal with data we need to be much more clear with the user and very very careful on any step.
Here you are fixing inconsistent data in a correct way, getting the tracked entity type from any underling enrollment but this is not the only issue that could happen and this SQL is running in a transaction (even without specifically start the transaction as done here, flyway will wrap this in a transaction), so if there is any inconsistent data that cannot be fixed in the way you provided, no data is fixed.
Than the user is sent to the guide and there we are not providing any explanation of what we attempted in the migration and we are not providing any option of fixing the data, only a script to delete tracked entitities and with all the enrollments and events.

To resume:
If the user has a number x of "fixable" tracked entities and one that is not automatically fixable, we are deleting ALL the tracked entities with inconsistent data.

SET trackedentitytypeid = (
SELECT trackedentitytypeid
FROM program
WHERE programid = results.programid
)
WHERE trackedentityid = results.trackedentityid;

RAISE NOTICE 'Updated trackedentity: programid = %, trackedentityid = %', results.programid, results.trackedentityid;
END LOOP;
SELECT COUNT(*) INTO inconsistent_records_count FROM trackedentity WHERE trackedentitytypeid IS NULL;

IF inconsistent_records_count = 0 THEN
ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL;
ELSE
zubaira marked this conversation as resolved.
Show resolved Hide resolved
RAISE EXCEPTION 'The database contains inconsistent data that must be resolved before re-running this migration. Please refer to the migration notes for detailed instructions on how to address this issue:
https://github.com/dhis2/dhis2-releases/blob/master/releases/2.42/migration-notes.md#null-tracked-entity-type. Detailed error message: %', SQLERRM;
END IF;
ELSE
RAISE NOTICE 'No inconsistencies found, trackedentitytypeid is already populated.';
END IF;
END $$;
Original file line number Diff line number Diff line change
Expand Up @@ -2141,29 +2141,36 @@ public static TrackedEntityType createTrackedEntityType(char uniqueChar) {
return trackedEntityType;
}

public static TrackedEntity createTrackedEntity(OrganisationUnit organisationUnit) {
public static TrackedEntity createTrackedEntity(
OrganisationUnit organisationUnit, TrackedEntityType trackedEntityType) {
TrackedEntity trackedEntity = new TrackedEntity();
trackedEntity.setAutoFields();
trackedEntity.setOrganisationUnit(organisationUnit);
trackedEntity.setTrackedEntityType(trackedEntityType);

return trackedEntity;
}

public static TrackedEntity createTrackedEntity(
char uniqueChar, OrganisationUnit organisationUnit) {
char uniqueChar, OrganisationUnit organisationUnit, TrackedEntityType trackedEntityType) {
TrackedEntity trackedEntity = new TrackedEntity();
trackedEntity.setAutoFields();
trackedEntity.setOrganisationUnit(organisationUnit);
trackedEntity.setUid(BASE_TE_UID + uniqueChar);
trackedEntity.setTrackedEntityType(trackedEntityType);

return trackedEntity;
}

public static TrackedEntity createTrackedEntity(
char uniqueChar, OrganisationUnit organisationUnit, TrackedEntityAttribute attribute) {
char uniqueChar,
OrganisationUnit organisationUnit,
TrackedEntityAttribute attribute,
TrackedEntityType trackedEntityType) {
TrackedEntity trackedEntity = new TrackedEntity();
trackedEntity.setAutoFields();
trackedEntity.setOrganisationUnit(organisationUnit);
trackedEntity.setTrackedEntityType(trackedEntityType);

TrackedEntityAttributeValue attributeValue = new TrackedEntityAttributeValue();
attributeValue.setAttribute(attribute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,8 @@ void setUp() throws ConflictException {
manager.save(trackedEntityType);

// Tracked Entity Instances (Registrations)
TrackedEntity teiA = createTrackedEntity(ouD);
TrackedEntity teiA = createTrackedEntity(ouD, trackedEntityType);
teiA.setUid("trackEntInA");
teiA.setTrackedEntityType(trackedEntityType);
manager.save(teiA);

// Tracked Entity Attribute Values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.hisp.dhis.test.integration.PostgresIntegrationTestBase;
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.hisp.dhis.tracker.trackedentityattributevalue.TrackedEntityAttributeValueService;
import org.junit.jupiter.api.Disabled;
Expand Down Expand Up @@ -108,7 +109,10 @@ void testSaveTrackedEntity() {
TrackedEntityAttribute attribute = createTrackedEntityAttribute('A');
manager.save(ou);
manager.save(attribute);
TrackedEntity trackedEntity = createTrackedEntity('A', ou, attribute);

TrackedEntityType trackedEntityType = createTrackedEntityType('O');
manager.save(trackedEntityType);
TrackedEntity trackedEntity = createTrackedEntity('A', ou, attribute, trackedEntityType);
manager.save(trackedEntity);
AuditQuery query = AuditQuery.builder().uid(Sets.newHashSet(trackedEntity.getUid())).build();
await().atMost(TIMEOUT, TimeUnit.SECONDS).until(() -> auditService.countAudits(query) >= 0);
Expand All @@ -127,7 +131,11 @@ void testSaveTrackedAttributeValue() {
TrackedEntityAttribute attribute = createTrackedEntityAttribute('A');
manager.save(ou);
manager.save(attribute);
TrackedEntity trackedEntity = createTrackedEntity('A', ou, attribute);

TrackedEntityType trackedEntityType = createTrackedEntityType('O');
manager.save(trackedEntityType);

TrackedEntity trackedEntity = createTrackedEntity('A', ou, attribute, trackedEntityType);
manager.save(trackedEntity);
TrackedEntityAttributeValue dataValue =
createTrackedEntityAttributeValue('A', trackedEntity, attribute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.hisp.dhis.test.integration.PostgresIntegrationTestBase;
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -70,7 +71,9 @@ class HardDeleteAuditTest extends PostgresIntegrationTestBase {
void testHardDeleteTrackedEntity() {
OrganisationUnit ou = createOrganisationUnit('A');
TrackedEntityAttribute attribute = createTrackedEntityAttribute('A');
TrackedEntity trackedEntity = createTrackedEntity('A', ou, attribute);
TrackedEntityType trackedEntityType = createTrackedEntityType('O');
manager.save(trackedEntityType);
TrackedEntity trackedEntity = createTrackedEntity('A', ou, attribute, trackedEntityType);
transactionTemplate.execute(
status -> {
manager.save(ou);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,11 @@ void setUp() {
programService.updateProgram(program);
TrackedEntityType trackedEntityType = createTrackedEntityType('A');
trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
trackedEntity = createTrackedEntity(organisationUnit);
trackedEntity.setTrackedEntityType(trackedEntityType);
trackedEntity = createTrackedEntity(organisationUnit, trackedEntityType);
manager.save(trackedEntity);
trackedEntityB = createTrackedEntity(organisationUnit);
trackedEntityB.setTrackedEntityType(trackedEntityType);
trackedEntityB = createTrackedEntity(organisationUnit, trackedEntityType);
manager.save(trackedEntityB);
trackedEntityWithAssociations = createTrackedEntity('T', organisationUnit);
trackedEntityWithAssociations = createTrackedEntity('T', organisationUnit, trackedEntityType);
DateTime testDate1 = DateTime.now();
testDate1.withTimeAtStartOfDay();
testDate1 = testDate1.minusDays(70);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
import org.hisp.dhis.test.integration.PostgresIntegrationTestBase;
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension;
import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.tracker.export.PageParams;
import org.hisp.dhis.tracker.export.event.EventChangeLog;
import org.hisp.dhis.tracker.export.event.EventChangeLogOperationParams;
Expand Down Expand Up @@ -1276,7 +1277,9 @@ void programIndicatorFilterMergeSourcesDeletedTest() throws ConflictException {
"Event eventDataValues references to source DataElements are replaced with target DataElement, source DataElements are not deleted")
void eventMergeTest() throws ConflictException {
// given
TrackedEntity trackedEntity = createTrackedEntity(ou1);
TrackedEntityType trackedEntityType = createTrackedEntityType('O');
identifiableObjectManager.save(trackedEntityType);
TrackedEntity trackedEntity = createTrackedEntity(ou1, trackedEntityType);
identifiableObjectManager.save(trackedEntity);
Enrollment enrollment = createEnrollment(program, trackedEntity, ou1);
identifiableObjectManager.save(enrollment);
Expand Down Expand Up @@ -1361,7 +1364,10 @@ void eventMergeTest() throws ConflictException {
"Event eventDataValues references with source DataElements are deleted when using DISCARD merge strategy")
void eventMergeDiscardTest() throws ConflictException {
// given
TrackedEntity trackedEntity = createTrackedEntity(ou1);

TrackedEntityType trackedEntityType = createTrackedEntityType('O');
identifiableObjectManager.save(trackedEntityType);
TrackedEntity trackedEntity = createTrackedEntity(ou1, trackedEntityType);
identifiableObjectManager.save(trackedEntity);
Enrollment enrollment = createEnrollment(program, trackedEntity, ou1);
identifiableObjectManager.save(enrollment);
Expand Down Expand Up @@ -1454,7 +1460,10 @@ void eventMergeDiscardTest() throws ConflictException {
"Event eventDataValues references to source DataElements are replaced with target DataElement, source DataElements are deleted")
void eventMergeSourcesDeletedTest() throws ConflictException {
// given
TrackedEntity trackedEntity = createTrackedEntity(ou1);

TrackedEntityType trackedEntityType = createTrackedEntityType('O');
identifiableObjectManager.save(trackedEntityType);
TrackedEntity trackedEntity = createTrackedEntity(ou1, trackedEntityType);
identifiableObjectManager.save(trackedEntity);
Enrollment enrollment = createEnrollment(program, trackedEntity, ou1);
identifiableObjectManager.save(enrollment);
Expand Down Expand Up @@ -2558,7 +2567,9 @@ void dataValueAuditMergeDeleteTest() throws ConflictException {
"EventChangeLogs with references to source DataElements are not changed or deleted when sources not deleted")
void eventChangeLogMergeTest() throws ConflictException, ForbiddenException, NotFoundException {
// given
TrackedEntity trackedEntity = createTrackedEntity(ou1);
TrackedEntityType trackedEntityType = createTrackedEntityType('O');
identifiableObjectManager.save(trackedEntityType);
TrackedEntity trackedEntity = createTrackedEntity(ou1, trackedEntityType);
identifiableObjectManager.save(trackedEntity);
Enrollment enrollment = createEnrollment(program, trackedEntity, ou1);
identifiableObjectManager.save(enrollment);
Expand Down Expand Up @@ -2612,7 +2623,9 @@ void eventChangeLogMergeTest() throws ConflictException, ForbiddenException, Not
void trackedEntityChangeLogMergeDeletedTest()
throws ConflictException, ForbiddenException, NotFoundException {
// given
TrackedEntity trackedEntity = createTrackedEntity(ou1);
TrackedEntityType trackedEntityType = createTrackedEntityType('O');
identifiableObjectManager.save(trackedEntityType);
TrackedEntity trackedEntity = createTrackedEntity(ou1, trackedEntityType);
identifiableObjectManager.save(trackedEntity);
Enrollment enrollment = createEnrollment(program, trackedEntity, ou1);
identifiableObjectManager.save(enrollment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.test.integration.PostgresIntegrationTestBase;
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
Expand Down Expand Up @@ -97,9 +98,12 @@ void setUp() {
manager.save(ouA);
manager.save(ouB);
manager.save(ouC);
trackedEntityA = createTrackedEntity('A', ouA);
trackedEntityB = createTrackedEntity('B', ouB);
trackedEntityC = createTrackedEntity('C', ouC);

TrackedEntityType trackedEntityType = createTrackedEntityType('O');
manager.save(trackedEntityType);
trackedEntityA = createTrackedEntity('A', ouA, trackedEntityType);
trackedEntityB = createTrackedEntity('B', ouB, trackedEntityType);
trackedEntityC = createTrackedEntity('C', ouC, trackedEntityType);
manager.save(trackedEntityA);
manager.save(trackedEntityB);
manager.save(trackedEntityC);
Expand Down
Loading
Loading