diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntity.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntity.hbm.xml
index e87fa2f4ca99..050fc36f4cc9 100644
--- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntity.hbm.xml
+++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntity.hbm.xml
@@ -58,7 +58,7 @@
foreign-key="fk_trackedentityinstance_organisationunitid" not-null="true" lazy="false"/>
+ column="trackedentitytypeid" foreign-key="fk_trackedentityinstance_trackedentitytypeid" lazy="false" not-null="true"/>
update trackedentity set lastUpdated = :lastUpdated, lastupdatedbyuserinfo = CAST(:lastupdatedbyuserinfo as jsonb) WHERE uid in :trackedEntities
diff --git a/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/copy/CopyServiceTest.java b/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/copy/CopyServiceTest.java
index aded62162396..dfae77804f26 100644
--- a/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/copy/CopyServiceTest.java
+++ b/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/copy/CopyServiceTest.java
@@ -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;
@@ -130,10 +131,12 @@ void setup() {
@Test
void testCopyProgramFromUidWithValidProgram() throws NotFoundException, ForbiddenException {
+ OrganisationUnit orgUnit = createOrganisationUnit("New Org 1");
+ TrackedEntityType trackedEntityType = createTrackedEntityType('E');
- OrganisationUnit orgUnit = createOrganisationUnit('A');
List 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);
diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationHelperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationHelperTest.java
index fb8e676f3137..08095b667ce4 100644
--- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationHelperTest.java
+++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationHelperTest.java
@@ -521,17 +521,11 @@ private List getEnrollments() {
}
private TrackedEntity getTrackedEntityA() {
- TrackedEntity te = createTrackedEntity(organisationUnitA);
- te.setTrackedEntityType(trackedEntityTypeA);
-
- return te;
+ return createTrackedEntity(organisationUnitA, trackedEntityTypeA);
}
private TrackedEntity getTrackedEntityB() {
- TrackedEntity te = createTrackedEntity(organisationUnitB);
- te.setTrackedEntityType(trackedEntityTypeB);
-
- return te;
+ return createTrackedEntity(organisationUnitB, trackedEntityTypeB);
}
private User getNoMergeAuthsUser() {
diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapperTest.java
index a7b8618f7746..f747fcb23ea2 100644
--- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapperTest.java
+++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapperTest.java
@@ -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());
diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/DuplicateRelationshipSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/DuplicateRelationshipSupplierTest.java
index 961c9a3e5ebb..22cb309f7c43 100644
--- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/DuplicateRelationshipSupplierTest.java
+++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/DuplicateRelationshipSupplierTest.java
@@ -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 =
diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributeSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributeSupplierTest.java
index d32c9d24b344..ef85a4bc3b6d 100644
--- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributeSupplierTest.java
+++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributeSupplierTest.java
@@ -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);
diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/RuleEngineMapperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/RuleEngineMapperTest.java
index 8bd0e5a0b4b0..e46559bffe82 100644
--- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/RuleEngineMapperTest.java
+++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/RuleEngineMapperTest.java
@@ -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() {
diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/DataRelationsValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/DataRelationsValidatorTest.java
index e3c731b14a2e..68d9cf81a725 100644
--- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/DataRelationsValidatorTest.java
+++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/DataRelationsValidatorTest.java
@@ -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);
return te;
diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/SecurityOwnershipValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/SecurityOwnershipValidatorTest.java
index a2a34fd7197f..0b9451c27fd2 100644
--- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/SecurityOwnershipValidatorTest.java
+++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/SecurityOwnershipValidatorTest.java
@@ -390,11 +390,10 @@ 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);
-
return trackedEntity;
}
diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/SecurityOwnershipValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/SecurityOwnershipValidatorTest.java
index c09843523208..9726961a2190 100644
--- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/SecurityOwnershipValidatorTest.java
+++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/SecurityOwnershipValidatorTest.java
@@ -487,7 +487,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);
diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/SecurityOwnershipValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/SecurityOwnershipValidatorTest.java
index 9228ee53a58a..5eb181f82c32 100644
--- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/SecurityOwnershipValidatorTest.java
+++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/SecurityOwnershipValidatorTest.java
@@ -300,7 +300,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);
@@ -312,16 +313,16 @@ 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);
-
return trackedEntity;
}
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);
diff --git a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_26__Add_not_null_constraint_to_trackedentity.sql b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_26__Add_not_null_constraint_to_trackedentity.sql
new file mode 100644
index 000000000000..7f84235b1687
--- /dev/null
+++ b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_26__Add_not_null_constraint_to_trackedentity.sql
@@ -0,0 +1,28 @@
+DO $$
+DECLARE
+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;
+
+ UPDATE trackedentity
+ SET trackedentitytypeid = (
+ SELECT program.trackedentitytypeid
+ FROM program
+ JOIN enrollment ON program.programid = enrollment.programid
+ WHERE enrollment.trackedentityid = trackedentity.trackedentityid
+ )
+ WHERE trackedentitytypeid IS NULL
+ AND EXISTS (
+ SELECT 1
+ FROM enrollment
+ JOIN program ON enrollment.programid = program.programid
+ WHERE enrollment.trackedentityid = trackedentity.trackedentityid
+ );
+END IF;
+ ALTER TABLE IF EXISTS trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL;
+EXCEPTION
+ WHEN not_null_violation THEN
+ 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: https://github.com/dhis2/dhis2-releases/blob/master/releases/2.42/migration-notes.md#null-tracked-entity-type. Detailed error message: %', SQLERRM;
+END $$;
\ No newline at end of file
diff --git a/dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/test/TestBase.java b/dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/test/TestBase.java
index f5e549b9218a..889509dd619d 100644
--- a/dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/test/TestBase.java
+++ b/dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/test/TestBase.java
@@ -2135,29 +2135,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);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java
index 3ca3e385d074..6383d7a1b41d 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java
@@ -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
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/audit/AuditIntegrationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/audit/AuditIntegrationTest.java
index e03c1b690de5..92e6787d5882 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/audit/AuditIntegrationTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/audit/AuditIntegrationTest.java
@@ -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;
@@ -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);
@@ -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);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/HardDeleteAuditTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/HardDeleteAuditTest.java
index b3a99948feee..db497884f55b 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/HardDeleteAuditTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/HardDeleteAuditTest.java
@@ -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;
@@ -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);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/MaintenanceServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/MaintenanceServiceTest.java
index c9d7ad93069d..36715834565d 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/MaintenanceServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/MaintenanceServiceTest.java
@@ -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);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/category/CategoryOptionComboMergeServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/category/CategoryOptionComboMergeServiceTest.java
index fce4dc7bee1d..649afb2ee550 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/category/CategoryOptionComboMergeServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/category/CategoryOptionComboMergeServiceTest.java
@@ -95,6 +95,7 @@
import org.hisp.dhis.sms.command.hibernate.SMSCommandStore;
import org.hisp.dhis.test.integration.PostgresIntegrationTestBase;
import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.util.DateUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
@@ -1385,7 +1386,9 @@ void dataApprovalMergeCocDiscardTest() throws ConflictException {
"Event attributeOptionCombo references to source COCs are replaced with target COC when using LAST_UPDATED, source COCs are not deleted")
void eventMergeTest() throws ConflictException {
// given
- TrackedEntity trackedEntity = createTrackedEntity(ou1);
+ TrackedEntityType entityType = createTrackedEntityType('T');
+ manager.save(entityType);
+ TrackedEntity trackedEntity = createTrackedEntity(ou1, entityType);
manager.save(trackedEntity);
Enrollment enrollment = createEnrollment(program, trackedEntity, ou1);
manager.save(enrollment);
@@ -1437,7 +1440,9 @@ void eventMergeTest() throws ConflictException {
"Event eventDataValues references to source COCs are deleted using DISCARD, source COCs are deleted")
void eventMergeSourcesDeletedTest() throws ConflictException {
// given
- TrackedEntity trackedEntity = createTrackedEntity(ou1);
+ TrackedEntityType entityType = createTrackedEntityType('T');
+ manager.save(entityType);
+ TrackedEntity trackedEntity = createTrackedEntity(ou1, entityType);
manager.save(trackedEntity);
Enrollment enrollment = createEnrollment(program, trackedEntity, ou1);
manager.save(enrollment);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/dataelement/DataElementMergeServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/dataelement/DataElementMergeServiceTest.java
index 6404405df508..c0a25c6157b5 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/dataelement/DataElementMergeServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/dataelement/DataElementMergeServiceTest.java
@@ -115,6 +115,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;
@@ -1277,7 +1278,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);
@@ -1362,7 +1365,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);
@@ -1455,7 +1461,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);
@@ -2559,7 +2568,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);
@@ -2613,7 +2624,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);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/orgunit/handler/TrackerOrgUnitMergeHandlerTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/orgunit/handler/TrackerOrgUnitMergeHandlerTest.java
index 23737b8ed415..bc73a543a463 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/orgunit/handler/TrackerOrgUnitMergeHandlerTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/orgunit/handler/TrackerOrgUnitMergeHandlerTest.java
@@ -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;
@@ -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);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/notification/ProgramNotificationMessageRendererTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/notification/ProgramNotificationMessageRendererTest.java
index 337ae87844f9..a85487049142 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/notification/ProgramNotificationMessageRendererTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/notification/ProgramNotificationMessageRendererTest.java
@@ -63,6 +63,7 @@
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.hisp.dhis.tracker.trackedentityattributevalue.TrackedEntityAttributeValueService;
import org.joda.time.DateTime;
@@ -201,7 +202,9 @@ void setUp() {
programStageService.updateProgramStage(programStageA);
programA.setProgramStages(Sets.newHashSet(programStageA));
programService.updateProgram(programA);
- trackedEntityA = createTrackedEntity(organisationUnitA);
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ trackedEntityA = createTrackedEntity(organisationUnitA, trackedEntityType);
trackedEntityA.setUid(trackedEntityUid);
manager.save(trackedEntityA);
trackedEntityAttributeValueA =
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/predictor/EventPredictionServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/predictor/EventPredictionServiceTest.java
index debd275ba0f3..231d83ff1310 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/predictor/EventPredictionServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/predictor/EventPredictionServiceTest.java
@@ -74,6 +74,7 @@
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.hisp.dhis.tracker.trackedentityattributevalue.TrackedEntityAttributeValueService;
import org.hisp.dhis.user.User;
@@ -216,7 +217,10 @@ void setUp() {
entityAttribute.setAggregationType(AggregationType.COUNT);
entityAttribute.setUid(TRACKED_ENTITY_ATTRIBUTE_UID);
entityAttributeService.addTrackedEntityAttribute(entityAttribute);
- TrackedEntity trackedEntity = createTrackedEntity('A', orgUnitA, entityAttribute);
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntity =
+ createTrackedEntity('A', orgUnitA, entityAttribute, trackedEntityType);
manager.save(trackedEntity);
TrackedEntityAttributeValue trackedEntityAttributeValue =
new TrackedEntityAttributeValue(entityAttribute, trackedEntity);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/EventProgramEnrollmentServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/EventProgramEnrollmentServiceTest.java
index 4a92fab692d2..99debd627ef3 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/EventProgramEnrollmentServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/EventProgramEnrollmentServiceTest.java
@@ -38,6 +38,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.test.integration.PostgresIntegrationTestBase;
import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -77,7 +78,9 @@ void setUp() {
OrganisationUnit organisationUnitB = createOrganisationUnit('B');
manager.save(organisationUnitB);
- TrackedEntity trackedEntity = createTrackedEntity(organisationUnitA);
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntity = createTrackedEntity(organisationUnitA, trackedEntityType);
manager.save(trackedEntity);
enrollmentA = createEnrollment(programA, trackedEntity, organisationUnitA);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramExpressionServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramExpressionServiceTest.java
index 714c7b1a7c25..922441bfc3e8 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramExpressionServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramExpressionServiceTest.java
@@ -40,6 +40,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnitService;
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;
@@ -99,7 +100,10 @@ void setUp() {
dataElementB = createDataElement('B');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
- TrackedEntity trackedEntity = createTrackedEntity(organisationUnit);
+
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntity = createTrackedEntity(organisationUnit, trackedEntityType);
manager.save(trackedEntity);
programExpressionA =
new ProgramExpression(
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java
index f7c124b61627..969bd08c4771 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java
@@ -60,6 +60,7 @@
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.hisp.dhis.tracker.trackedentityattributevalue.TrackedEntityAttributeValueService;
import org.hisp.dhis.util.DateUtils;
@@ -227,7 +228,10 @@ void setUp() {
// ---------------------------------------------------------------------
// TrackedEntity
// ---------------------------------------------------------------------
- TrackedEntity trackedEntity = createTrackedEntity(organisationUnit);
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+
+ TrackedEntity trackedEntity = createTrackedEntity(organisationUnit, trackedEntityType);
manager.save(trackedEntity);
// ---------------------------------------------------------------------
// Enrollment
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramMessageStoreTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramMessageStoreTest.java
index e462d4f2eccd..6ee27c651d73 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramMessageStoreTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramMessageStoreTest.java
@@ -48,6 +48,7 @@
import org.hisp.dhis.program.message.ProgramMessageStore;
import org.hisp.dhis.test.integration.PostgresIntegrationTestBase;
import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -106,7 +107,9 @@ void setUp() {
programService.updateProgram(programA);
// Initialize Tracked Entities, Enrollment and Event
- TrackedEntity trackedEntityB = createTrackedEntity(orgUnitA);
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntityB = createTrackedEntity(orgUnitA, trackedEntityType);
manager.save(trackedEntityB);
enrollmentA = new Enrollment(new Date(), new Date(), trackedEntityB, programA);
@@ -117,7 +120,7 @@ void setUp() {
eventA.setScheduledDate(new Date());
eventA.setUid(CodeGenerator.generateUid());
- TrackedEntity trackedEntityA = createTrackedEntity(orgUnitA);
+ TrackedEntity trackedEntityA = createTrackedEntity(orgUnitA, trackedEntityType);
manager.save(trackedEntityA);
ProgramMessageRecipients recipientsA = createRecipients(orgUnitA, trackedEntityA);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/notification/ProgramNotificationServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/notification/ProgramNotificationServiceTest.java
index 499182645024..ed51aa3ab5df 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/notification/ProgramNotificationServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/notification/ProgramNotificationServiceTest.java
@@ -60,6 +60,7 @@
import org.hisp.dhis.program.ProgramStageService;
import org.hisp.dhis.test.integration.PostgresIntegrationTestBase;
import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
@@ -117,9 +118,11 @@ void setUp() {
OrganisationUnit organisationUnitB = createOrganisationUnit('B');
manager.save(organisationUnitA);
manager.save(organisationUnitB);
- TrackedEntity trackedEntityA = createTrackedEntity(organisationUnitA);
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntityA = createTrackedEntity(organisationUnitA, trackedEntityType);
manager.save(trackedEntityA);
- TrackedEntity trackedEntityB = createTrackedEntity(organisationUnitB);
+ TrackedEntity trackedEntityB = createTrackedEntity(organisationUnitB, trackedEntityType);
manager.save(trackedEntityB);
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programService.addProgram(programA);
@@ -398,8 +401,11 @@ void testGetEnrollmentsWithScheduledNotifications() {
programNotificationStore.save(a2);
programNotificationStore.save(a3);
// TE
- TrackedEntity trackedEntityX = createTrackedEntity(organisationUnitA);
- TrackedEntity trackedEntityY = createTrackedEntity(organisationUnitA);
+
+ TrackedEntityType trackedEntityType = createTrackedEntityType('M');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntityX = createTrackedEntity(organisationUnitA, trackedEntityType);
+ TrackedEntity trackedEntityY = createTrackedEntity(organisationUnitA, trackedEntityType);
manager.save(trackedEntityX);
manager.save(trackedEntityY);
// Program
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/relationship/RelationshipDeletionHandlerTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/relationship/RelationshipDeletionHandlerTest.java
index b506a31971d7..32fc9faa31f7 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/relationship/RelationshipDeletionHandlerTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/relationship/RelationshipDeletionHandlerTest.java
@@ -35,6 +35,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
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;
@@ -58,9 +59,11 @@ public void setUp() {
manager.save(deletableRelationshipType);
OrganisationUnit orgUnit = createOrganisationUnit('A');
manager.save(orgUnit);
- TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnit);
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnit, trackedEntityType);
manager.save(trackedEntityFrom);
- TrackedEntity trackedEntityTo = createTrackedEntity(orgUnit);
+ TrackedEntity trackedEntityTo = createTrackedEntity(orgUnit, trackedEntityType);
manager.save(trackedEntityTo);
Relationship relationship =
createTeToTeRelationship(trackedEntityFrom, trackedEntityTo, relationshipType);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/reservedvalue/hibernate/HibernateReservedValueStoreTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/reservedvalue/hibernate/HibernateReservedValueStoreTest.java
index 60cd80f9122d..f727078bd550 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/reservedvalue/hibernate/HibernateReservedValueStoreTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/reservedvalue/hibernate/HibernateReservedValueStoreTest.java
@@ -48,6 +48,7 @@
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityAttributeStore;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.hisp.dhis.tracker.trackedentityattributevalue.TrackedEntityAttributeValueService;
import org.junit.jupiter.api.BeforeAll;
@@ -169,7 +170,10 @@ void getAvailableValuesWhenAlreadyUsed()
throws TextPatternParser.TextPatternParsingException, IllegalAccessException {
OrganisationUnit ou = createOrganisationUnit("OU");
organisationUnitStore.save(ou);
- TrackedEntity trackedEntity = createTrackedEntity(ou);
+
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntity = createTrackedEntity(ou, trackedEntityType);
manager.save(trackedEntity);
TrackedEntityAttribute tea = createTrackedEntityAttribute('Y');
TextPattern textPattern = TextPatternParser.parse(key);
@@ -221,7 +225,9 @@ void shouldNotAddAlreadyReservedValues() {
saveReservedValue(reservedValue.value(prog001).build());
OrganisationUnit ou = createOrganisationUnit("OU");
organisationUnitStore.save(ou);
- TrackedEntity trackedEntity = createTrackedEntity(ou);
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntity = createTrackedEntity(ou, trackedEntityType);
manager.save(trackedEntity);
TrackedEntityAttribute tea = createTrackedEntityAttribute('Y');
tea.setUid(teaUid);
@@ -237,7 +243,10 @@ void shouldRemoveAlreadyUsedReservedValues() {
saveReservedValue(reservedValue.value(prog001).build());
OrganisationUnit ou = createOrganisationUnit("OU");
organisationUnitStore.save(ou);
- TrackedEntity trackedEntity = createTrackedEntity(ou);
+
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntity = createTrackedEntity(ou, trackedEntityType);
manager.save(trackedEntity);
TrackedEntityAttribute tea = createTrackedEntityAttribute('Y');
tea.setUid(teaUid);
@@ -261,7 +270,9 @@ void shouldRemoveAlreadyUsedOrExpiredReservedValues() {
// used value
OrganisationUnit ou = createOrganisationUnit("OU");
organisationUnitStore.save(ou);
- TrackedEntity trackedEntity = createTrackedEntity(ou);
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntity = createTrackedEntity(ou, trackedEntityType);
manager.save(trackedEntity);
TrackedEntityAttribute tea = createTrackedEntityAttribute('Y');
tea.setUid(teaUid);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityProgramOwnerServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityProgramOwnerServiceTest.java
index 59a2732559a1..1746c79461d3 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityProgramOwnerServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityProgramOwnerServiceTest.java
@@ -82,9 +82,11 @@ void setUp() {
organisationUnitService.addOrganisationUnit(organisationUnitA);
organisationUnitB = createOrganisationUnit('B');
organisationUnitService.addOrganisationUnit(organisationUnitB);
- trackedEntityA1 = createTrackedEntity(organisationUnitA);
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ trackedEntityA1 = createTrackedEntity(organisationUnitA, trackedEntityType);
trackedEntityA1.setUid(TE_A1);
- trackedEntityB1 = createTrackedEntity(organisationUnitA);
+ trackedEntityB1 = createTrackedEntity(organisationUnitA, trackedEntityType);
trackedEntityB1.setUid(TE_B1);
manager.save(trackedEntityA1);
manager.save(trackedEntityB1);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityServiceTest.java
index 7a77e454a9f4..cd60ef1d2191 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityServiceTest.java
@@ -85,10 +85,13 @@ void setUp() {
OrganisationUnit organisationUnitB = createOrganisationUnit('B');
organisationUnitService.addOrganisationUnit(organisationUnitB);
attributeService.addTrackedEntityAttribute(createTrackedEntityAttribute('A'));
- trackedEntityA1 = createTrackedEntity(organisationUnit);
- TrackedEntity trackedEntityB1 = createTrackedEntity(organisationUnit);
- TrackedEntity trackedEntityC1 = createTrackedEntity(organisationUnit);
- TrackedEntity trackedEntityD1 = createTrackedEntity(organisationUnit);
+
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ trackedEntityA1 = createTrackedEntity(organisationUnit, trackedEntityType);
+ TrackedEntity trackedEntityB1 = createTrackedEntity(organisationUnit, trackedEntityType);
+ TrackedEntity trackedEntityC1 = createTrackedEntity(organisationUnit, trackedEntityType);
+ TrackedEntity trackedEntityD1 = createTrackedEntity(organisationUnit, trackedEntityType);
trackedEntityA1.setUid(TE_A_UID);
trackedEntityB1.setUid(TE_B_UID);
trackedEntityC1.setUid(TE_C_UID);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackerAccessManagerTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackerAccessManagerTest.java
index ba633bdbfbd7..10e08a0b4926 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackerAccessManagerTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackerAccessManagerTest.java
@@ -158,14 +158,11 @@ void setUp() {
manager.update(programStageA);
manager.update(programStageB);
manager.update(programA);
- trackedEntityA = createTrackedEntity(orgUnitA);
- TrackedEntity trackedEntityB = createTrackedEntity(orgUnitB);
- TrackedEntity femaleA = createTrackedEntity(orgUnitA);
- TrackedEntity femaleB = createTrackedEntity(orgUnitB);
- trackedEntityA.setTrackedEntityType(trackedEntityType);
- trackedEntityB.setTrackedEntityType(trackedEntityType);
- femaleA.setTrackedEntityType(trackedEntityType);
- femaleB.setTrackedEntityType(trackedEntityType);
+ trackedEntityA = createTrackedEntity(orgUnitA, trackedEntityType);
+ TrackedEntity trackedEntityB = createTrackedEntity(orgUnitB, trackedEntityType);
+ TrackedEntity femaleA = createTrackedEntity(orgUnitA, trackedEntityType);
+ TrackedEntity femaleB = createTrackedEntity(orgUnitB, trackedEntityType);
+
manager.save(trackedEntityA);
manager.save(trackedEntityB);
manager.save(femaleA);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackerOwnershipManagerTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackerOwnershipManagerTest.java
index 6440cb149a0d..61ac44ab7ad2 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackerOwnershipManagerTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackerOwnershipManagerTest.java
@@ -129,10 +129,8 @@ void setUp() {
trackedEntityType.setSharing(Sharing.builder().publicAccess(AccessStringHelper.FULL).build());
trackedEntityTypeService.updateTrackedEntityType(trackedEntityType);
- trackedEntityA1 = createTrackedEntity(organisationUnitA);
- trackedEntityA1.setTrackedEntityType(trackedEntityType);
- trackedEntityB1 = createTrackedEntity(organisationUnitB);
- trackedEntityB1.setTrackedEntityType(trackedEntityType);
+ trackedEntityA1 = createTrackedEntity(organisationUnitA, trackedEntityType);
+ trackedEntityB1 = createTrackedEntity(organisationUnitB, trackedEntityType);
manager.save(trackedEntityA1);
manager.save(trackedEntityB1);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationServiceMergeIntegrationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationServiceMergeIntegrationTest.java
index 7c68b06d6797..0990fba772f2 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationServiceMergeIntegrationTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationServiceMergeIntegrationTest.java
@@ -116,10 +116,8 @@ void setUp() throws PotentialDuplicateConflictException {
organisationUnitService.addOrganisationUnit(orgUnit);
trackedEntityType = createTrackedEntityType('A');
trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
- original = createTrackedEntity(orgUnit);
- duplicate = createTrackedEntity(orgUnit);
- original.setTrackedEntityType(trackedEntityType);
- duplicate.setTrackedEntityType(trackedEntityType);
+ original = createTrackedEntity(orgUnit, trackedEntityType);
+ duplicate = createTrackedEntity(orgUnit, trackedEntityType);
manager.save(original);
manager.save(duplicate);
program = createProgram('A');
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateRemoveTrackedEntityTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateRemoveTrackedEntityTest.java
index 8e3dbb5de456..b11cb5d9f3a4 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateRemoveTrackedEntityTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateRemoveTrackedEntityTest.java
@@ -49,6 +49,7 @@
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.tracker.export.enrollment.EnrollmentService;
import org.hisp.dhis.tracker.imports.bundle.persister.TrackerObjectDeletionService;
import org.hisp.dhis.tracker.trackedentityattributevalue.TrackedEntityAttributeValueService;
@@ -107,10 +108,12 @@ void shouldDeleteTeAndAttributeValues() throws NotFoundException {
void shouldDeleteRelationShips() throws NotFoundException {
OrganisationUnit ou = createOrganisationUnit("OU_A");
organisationUnitService.addOrganisationUnit(ou);
- TrackedEntity original = createTrackedEntity(ou);
- TrackedEntity duplicate = createTrackedEntity(ou);
- TrackedEntity control1 = createTrackedEntity(ou);
- TrackedEntity control2 = createTrackedEntity(ou);
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ TrackedEntity original = createTrackedEntity(ou, trackedEntityType);
+ TrackedEntity duplicate = createTrackedEntity(ou, trackedEntityType);
+ TrackedEntity control1 = createTrackedEntity(ou, trackedEntityType);
+ TrackedEntity control2 = createTrackedEntity(ou, trackedEntityType);
manager.save(original);
manager.save(duplicate);
manager.save(control1);
@@ -145,10 +148,13 @@ void shouldDeleteRelationShips() throws NotFoundException {
void shouldDeleteEnrollments() throws ForbiddenException, NotFoundException {
OrganisationUnit ou = createOrganisationUnit("OU_A");
organisationUnitService.addOrganisationUnit(ou);
- TrackedEntity original = createTrackedEntity(ou);
- TrackedEntity duplicate = createTrackedEntity(ou);
- TrackedEntity control1 = createTrackedEntity(ou);
- TrackedEntity control2 = createTrackedEntity(ou);
+
+ TrackedEntityType trackedEntityType = createTrackedEntityType('P');
+ manager.save(trackedEntityType);
+ TrackedEntity original = createTrackedEntity(ou, trackedEntityType);
+ TrackedEntity duplicate = createTrackedEntity(ou, trackedEntityType);
+ TrackedEntity control1 = createTrackedEntity(ou, trackedEntityType);
+ TrackedEntity control2 = createTrackedEntity(ou, trackedEntityType);
manager.save(original);
manager.save(duplicate);
manager.save(control1);
@@ -187,7 +193,11 @@ void shouldDeleteEnrollments() throws ForbiddenException, NotFoundException {
private TrackedEntity createTrackedEntity(TrackedEntityAttribute trackedEntityAttribute) {
OrganisationUnit ou = createOrganisationUnit("OU_A");
organisationUnitService.addOrganisationUnit(ou);
- TrackedEntity trackedEntity = createTrackedEntity('T', ou, trackedEntityAttribute);
+
+ TrackedEntityType trackedEntityType = createTrackedEntityType('R');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntity =
+ createTrackedEntity('T', ou, trackedEntityAttribute, trackedEntityType);
manager.save(trackedEntity);
return trackedEntity;
}
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateStoreRelationshipTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateStoreRelationshipTest.java
index 5ddf570097cb..3b5e14975b26 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateStoreRelationshipTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateStoreRelationshipTest.java
@@ -41,6 +41,7 @@
import org.hisp.dhis.relationship.RelationshipTypeService;
import org.hisp.dhis.test.integration.PostgresIntegrationTestBase;
import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@@ -79,10 +80,13 @@ class PotentialDuplicateStoreRelationshipTest extends PostgresIntegrationTestBas
void setUp() {
OrganisationUnit ou = createOrganisationUnit("OU_A");
organisationUnitService.addOrganisationUnit(ou);
- original = createTrackedEntity(ou);
- duplicate = createTrackedEntity(ou);
- extra1 = createTrackedEntity(ou);
- extra2 = createTrackedEntity(ou);
+
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ original = createTrackedEntity(ou, trackedEntityType);
+ duplicate = createTrackedEntity(ou, trackedEntityType);
+ extra1 = createTrackedEntity(ou, trackedEntityType);
+ extra2 = createTrackedEntity(ou, trackedEntityType);
manager.save(original);
manager.save(duplicate);
manager.save(extra1);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateStoreTEAVTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateStoreTEAVTest.java
index b81bbff66a56..530d848b8f55 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateStoreTEAVTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateStoreTEAVTest.java
@@ -40,6 +40,7 @@
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.tracker.trackedentityattributevalue.TrackedEntityAttributeValueService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
@@ -85,9 +86,12 @@ class PotentialDuplicateStoreTEAVTest extends PostgresIntegrationTestBase {
void setUp() {
OrganisationUnit ou = createOrganisationUnit("OU_A");
organisationUnitService.addOrganisationUnit(ou);
- original = createTrackedEntity(ou);
- duplicate = createTrackedEntity(ou);
- control = createTrackedEntity(ou);
+
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ original = createTrackedEntity(ou, trackedEntityType);
+ duplicate = createTrackedEntity(ou, trackedEntityType);
+ control = createTrackedEntity(ou, trackedEntityType);
manager.save(original);
manager.save(duplicate);
manager.save(control);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentServiceTest.java
index 55f9eafe3141..6704d239ada3 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentServiceTest.java
@@ -158,24 +158,20 @@ void setUp() {
trackedEntityTypeA.getSharing().setOwner(user);
manager.save(trackedEntityTypeA, false);
- trackedEntityA = createTrackedEntity(orgUnitA);
- trackedEntityA.setTrackedEntityType(trackedEntityTypeA);
+ trackedEntityA = createTrackedEntity(orgUnitA, trackedEntityTypeA);
manager.save(trackedEntityA, false);
- TrackedEntity trackedEntityB = createTrackedEntity(orgUnitB);
- trackedEntityB.setTrackedEntityType(trackedEntityTypeA);
+ TrackedEntity trackedEntityB = createTrackedEntity(orgUnitB, trackedEntityTypeA);
manager.save(trackedEntityB, false);
- TrackedEntity trackedEntityC = createTrackedEntity(orgUnitC);
- trackedEntityC.setTrackedEntityType(trackedEntityTypeA);
+ TrackedEntity trackedEntityC = createTrackedEntity(orgUnitC, trackedEntityTypeA);
manager.save(trackedEntityC, false);
- TrackedEntity trackedEntityChildA = createTrackedEntity(orgUnitChildA);
- trackedEntityChildA.setTrackedEntityType(trackedEntityTypeA);
+ TrackedEntity trackedEntityChildA = createTrackedEntity(orgUnitChildA, trackedEntityTypeA);
manager.save(trackedEntityChildA, false);
- TrackedEntity trackedEntityGrandchildA = createTrackedEntity(orgUnitGrandchildA);
- trackedEntityGrandchildA.setTrackedEntityType(trackedEntityTypeA);
+ TrackedEntity trackedEntityGrandchildA =
+ createTrackedEntity(orgUnitGrandchildA, trackedEntityTypeA);
manager.save(trackedEntityGrandchildA, false);
programA = createProgram('A', new HashSet<>(), orgUnitA);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipServiceTest.java
index 7c470ced7901..909a2088fd2c 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipServiceTest.java
@@ -139,16 +139,13 @@ void setUp() {
inaccessibleTrackedEntityType.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
manager.save(inaccessibleTrackedEntityType, false);
- teA = createTrackedEntity(orgUnitA);
- teA.setTrackedEntityType(trackedEntityType);
+ teA = createTrackedEntity(orgUnitA, trackedEntityType);
manager.save(teA, false);
- teB = createTrackedEntity(orgUnitA);
- teB.setTrackedEntityType(trackedEntityType);
+ teB = createTrackedEntity(orgUnitA, trackedEntityType);
manager.save(teB, false);
- inaccessibleTe = createTrackedEntity(orgUnitA);
- inaccessibleTe.setTrackedEntityType(inaccessibleTrackedEntityType);
+ inaccessibleTe = createTrackedEntity(orgUnitA, inaccessibleTrackedEntityType);
manager.save(inaccessibleTe, false);
program = createProgram('A', new HashSet<>(), orgUnitA);
@@ -298,8 +295,7 @@ void shouldNotReturnRelationshipWhenTeIsTransferredAndUserHasNoAccessToAtLeastOn
program.setOrganisationUnits(Set.of(orgUnitA, orgUnitB));
manager.save(program, false);
- TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA);
- trackedEntityFrom.setTrackedEntityType(trackedEntityType);
+ TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA, trackedEntityType);
manager.save(trackedEntityFrom);
manager.save(createEnrollment(program, trackedEntityFrom, orgUnitA));
@@ -309,8 +305,7 @@ void shouldNotReturnRelationshipWhenTeIsTransferredAndUserHasNoAccessToAtLeastOn
trackerOwnershipAccessManager.transferOwnership(trackedEntityFrom, program, orgUnitB);
- TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA);
- trackedEntityTo.setTrackedEntityType(trackedEntityType);
+ TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA, trackedEntityType);
manager.save(trackedEntityTo);
relationship(trackedEntityFrom, trackedEntityTo);
@@ -334,19 +329,16 @@ void shouldExcludeRelationshipWhenProgramIsProtectedAndUserHasNoAccess()
throws ForbiddenException, NotFoundException, BadRequestException {
injectAdminIntoSecurityContext();
- TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA);
- trackedEntityFrom.setTrackedEntityType(trackedEntityType);
+ TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA, trackedEntityType);
manager.save(trackedEntityFrom);
- TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA);
- trackedEntityTo.setTrackedEntityType(trackedEntityType);
+ TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA, trackedEntityType);
manager.save(trackedEntityTo);
Program inaccessibleProgram = protectedProgram('P', trackedEntityType, orgUnitB);
manager.save(inaccessibleProgram, false);
- TrackedEntity notAccessibleTe = createTrackedEntity(orgUnitB);
- notAccessibleTe.setTrackedEntityType(trackedEntityType);
+ TrackedEntity notAccessibleTe = createTrackedEntity(orgUnitB, trackedEntityType);
manager.save(notAccessibleTe);
injectSecurityContextUser(user);
@@ -382,12 +374,10 @@ void shouldNotReturnRelationshipWhenUserHasNoMetadataAccessToProgram() {
program.setProgramStages(Set.of(programStage));
manager.save(program, false);
- TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA);
- trackedEntityFrom.setTrackedEntityType(trackedEntityType);
+ TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA, trackedEntityType);
manager.save(trackedEntityFrom);
- TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA);
- trackedEntityTo.setTrackedEntityType(trackedEntityType);
+ TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA, trackedEntityType);
manager.save(trackedEntityTo);
relationship(trackedEntityFrom, trackedEntityTo);
@@ -421,12 +411,10 @@ void shouldNotReturnRelationshipWhenUserHasNoDataReadAccessToProgram() {
program.setProgramStages(Set.of(programStage));
manager.save(program, false);
- TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA);
- trackedEntityFrom.setTrackedEntityType(trackedEntityType);
+ TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA, trackedEntityType);
manager.save(trackedEntityFrom);
- TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA);
- trackedEntityTo.setTrackedEntityType(trackedEntityType);
+ TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA, trackedEntityType);
manager.save(trackedEntityTo);
relationship(trackedEntityFrom, trackedEntityTo);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityServiceTest.java
index c02670ca455e..1d241cd3973d 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityServiceTest.java
@@ -328,17 +328,16 @@ void setUp() {
tetavB = new TrackedEntityAttributeValue(teaB, trackedEntityA, "B");
pteavC = new TrackedEntityAttributeValue(teaC, trackedEntityA, "C");
- trackedEntityA = createTrackedEntity(orgUnitA);
+ trackedEntityA = createTrackedEntity(orgUnitA, trackedEntityTypeA);
trackedEntityA.setTrackedEntityType(trackedEntityTypeA);
trackedEntityA.setTrackedEntityAttributeValues(Set.of(tetavA, tetavB, pteavC));
+
manager.save(trackedEntityA, false);
- trackedEntityChildA = createTrackedEntity(orgUnitChildA);
- trackedEntityChildA.setTrackedEntityType(trackedEntityTypeA);
+ trackedEntityChildA = createTrackedEntity(orgUnitChildA, trackedEntityTypeA);
manager.save(trackedEntityChildA, false);
- trackedEntityGrandchildA = createTrackedEntity(orgUnitGrandchildA);
- trackedEntityGrandchildA.setTrackedEntityType(trackedEntityTypeA);
+ trackedEntityGrandchildA = createTrackedEntity(orgUnitGrandchildA, trackedEntityTypeA);
manager.save(trackedEntityGrandchildA, false);
enrollmentA = createEnrollment(programA, trackedEntityA, orgUnitA);
@@ -380,8 +379,7 @@ void setUp() {
enrollmentB.setEvents(Set.of(eventB));
manager.save(enrollmentB, false);
- trackedEntityB = createTrackedEntity(orgUnitB);
- trackedEntityB.setTrackedEntityType(trackedEntityTypeA);
+ trackedEntityB = createTrackedEntity(orgUnitB, trackedEntityTypeA);
manager.save(trackedEntityB, false);
Enrollment enrollmentC = createEnrollment(programB, trackedEntityB, orgUnitB);
@@ -398,8 +396,7 @@ void setUp() {
enrollmentC.setEvents(Set.of(eventC));
manager.save(enrollmentC, false);
- TrackedEntity trackedEntityC = createTrackedEntity(orgUnitC);
- trackedEntityC.setTrackedEntityType(trackedEntityTypeA);
+ TrackedEntity trackedEntityC = createTrackedEntity(orgUnitC, trackedEntityTypeA);
manager.save(trackedEntityC, false);
trackedEntityProgramOwnerService.createTrackedEntityProgramOwner(
@@ -1886,8 +1883,7 @@ void shouldFailWhenRequestingSingleTEAndTETNotAccessible() {
TrackedEntityType inaccessibleTrackedEntityType = createTrackedEntityType('U');
inaccessibleTrackedEntityType.setSharing(Sharing.builder().publicAccess("rw------").build());
manager.save(inaccessibleTrackedEntityType, false);
- TrackedEntity trackedEntity = createTrackedEntity(orgUnitA);
- trackedEntity.setTrackedEntityType(inaccessibleTrackedEntityType);
+ TrackedEntity trackedEntity = createTrackedEntity(orgUnitA, inaccessibleTrackedEntityType);
manager.save(trackedEntity);
ForbiddenException exception =
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerNotificationHandlerServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerNotificationHandlerServiceTest.java
index 62dd57196bc1..2dd38c0092ab 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerNotificationHandlerServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerNotificationHandlerServiceTest.java
@@ -101,8 +101,7 @@ void setUp() {
programA.getProgramStages().add(programStageA);
manager.update(programA);
- trackedEntityA = createTrackedEntity('T', orgUnitA);
- trackedEntityA.setTrackedEntityType(trackedEntityTypeA);
+ trackedEntityA = createTrackedEntity('T', orgUnitA, trackedEntityTypeA);
manager.save(trackedEntityA, false);
User user = createAndAddUser(false, "user", Set.of(orgUnitA), Set.of(orgUnitA), "ALL");
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentSecurityImportValidationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentSecurityImportValidationTest.java
index caa9954f3523..76b8e1cf6849 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentSecurityImportValidationTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentSecurityImportValidationTest.java
@@ -163,14 +163,11 @@ private void setup() {
manager.update(programStageA);
manager.update(programStageB);
manager.update(programA);
- maleA = createTrackedEntity('A', organisationUnitA);
- maleB = createTrackedEntity(organisationUnitB);
- femaleA = createTrackedEntity(organisationUnitA);
- femaleB = createTrackedEntity(organisationUnitB);
- maleA.setTrackedEntityType(trackedEntityType);
- maleB.setTrackedEntityType(trackedEntityType);
- femaleA.setTrackedEntityType(trackedEntityType);
- femaleB.setTrackedEntityType(trackedEntityType);
+ maleA = createTrackedEntity('A', organisationUnitA, trackedEntityType);
+ maleB = createTrackedEntity(organisationUnitB, trackedEntityType);
+ femaleA = createTrackedEntity(organisationUnitA, trackedEntityType);
+ femaleB = createTrackedEntity(organisationUnitB, trackedEntityType);
+
manager.save(maleA);
manager.save(maleB);
manager.save(femaleA);
@@ -352,8 +349,7 @@ private Program createProgram(OrganisationUnit orgUnit) {
private TrackedEntity createTrackedEntity(
TrackedEntityType trackedEntityType, OrganisationUnit orgUnit) {
- TrackedEntity trackedEntity = createTrackedEntity('T', orgUnit);
- trackedEntity.setTrackedEntityType(trackedEntityType);
+ TrackedEntity trackedEntity = createTrackedEntity('T', orgUnit, trackedEntityType);
manager.save(trackedEntity);
return trackedEntity;
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EventSecurityImportValidationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EventSecurityImportValidationTest.java
index e649f3633fb1..7e92e4b85846 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EventSecurityImportValidationTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EventSecurityImportValidationTest.java
@@ -180,14 +180,11 @@ void setUp() throws IOException {
manager.update(programStageA);
manager.update(programStageB);
manager.update(programA);
- maleA = createTrackedEntity('A', organisationUnitA);
- maleB = createTrackedEntity(organisationUnitB);
- femaleA = createTrackedEntity(organisationUnitA);
- femaleB = createTrackedEntity(organisationUnitB);
- maleA.setTrackedEntityType(trackedEntityType);
- maleB.setTrackedEntityType(trackedEntityType);
- femaleA.setTrackedEntityType(trackedEntityType);
- femaleB.setTrackedEntityType(trackedEntityType);
+ maleA = createTrackedEntity('A', organisationUnitA, trackedEntityType);
+ maleB = createTrackedEntity(organisationUnitB, trackedEntityType);
+ femaleA = createTrackedEntity(organisationUnitA, trackedEntityType);
+ femaleB = createTrackedEntity(organisationUnitB, trackedEntityType);
+
manager.save(maleA);
manager.save(maleB);
manager.save(femaleA);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/trackedentityattributevalue/TrackedEntityAttributeValueServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/trackedentityattributevalue/TrackedEntityAttributeValueServiceTest.java
index ce5459302f20..dcf2dfa9d567 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/trackedentityattributevalue/TrackedEntityAttributeValueServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/trackedentityattributevalue/TrackedEntityAttributeValueServiceTest.java
@@ -43,6 +43,7 @@
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -89,10 +90,13 @@ class TrackedEntityAttributeValueServiceTest extends PostgresIntegrationTestBase
void setUp() {
OrganisationUnit organisationUnit = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnit);
- trackedEntityA = createTrackedEntity(organisationUnit);
- trackedEntityB = createTrackedEntity(organisationUnit);
- trackedEntityC = createTrackedEntity(organisationUnit);
- trackedEntityD = createTrackedEntity(organisationUnit);
+
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ trackedEntityA = createTrackedEntity(organisationUnit, trackedEntityType);
+ trackedEntityB = createTrackedEntity(organisationUnit, trackedEntityType);
+ trackedEntityC = createTrackedEntity(organisationUnit, trackedEntityType);
+ trackedEntityD = createTrackedEntity(organisationUnit, trackedEntityType);
manager.save(trackedEntityA);
manager.save(trackedEntityB);
manager.save(trackedEntityC);
diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/validation/AnalyticsValidationServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/validation/AnalyticsValidationServiceTest.java
index 3ce227fced5e..3129993f4d7f 100644
--- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/validation/AnalyticsValidationServiceTest.java
+++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/validation/AnalyticsValidationServiceTest.java
@@ -85,6 +85,7 @@
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.hisp.dhis.tracker.trackedentityattributevalue.TrackedEntityAttributeValueService;
import org.hisp.dhis.user.User;
@@ -192,7 +193,10 @@ void setUp() {
entityAttribute.setAggregationType(AggregationType.COUNT);
entityAttribute.setUid(TRACKED_ENTITY_ATTRIBUTE_UID);
entityAttributeService.addTrackedEntityAttribute(entityAttribute);
- TrackedEntity trackedEntity = createTrackedEntity('A', orgUnitA, entityAttribute);
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntity =
+ createTrackedEntity('A', orgUnitA, entityAttribute, trackedEntityType);
manager.save(trackedEntity);
TrackedEntityAttributeValue trackedEntityAttributeValue =
new TrackedEntityAttributeValue(entityAttribute, trackedEntity);
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/AuditControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/AuditControllerTest.java
index ca61f1fae8d6..9038271de8ba 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/AuditControllerTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/AuditControllerTest.java
@@ -117,14 +117,12 @@ void setUp() {
trackedEntityType = trackedEntityTypeAccessible();
- te1 = createTrackedEntity(orgUnit);
- te1.setTrackedEntityType(trackedEntityType);
+ te1 = createTrackedEntity(orgUnit, trackedEntityType);
te1.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
te1.getSharing().setOwner(owner);
manager.save(te1, false);
- te2 = createTrackedEntity(orgUnit);
- te2.setTrackedEntityType(trackedEntityType);
+ te2 = createTrackedEntity(orgUnit, trackedEntityType);
te2.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
te2.getSharing().setOwner(owner);
manager.save(te2, false);
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ProgramMessageControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ProgramMessageControllerTest.java
index f1ac6e3bf836..ebe325afb3e1 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ProgramMessageControllerTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ProgramMessageControllerTest.java
@@ -41,6 +41,7 @@
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.test.webapi.H2ControllerIntegrationTestBase;
import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.webapi.controller.message.ProgramMessageController;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -66,7 +67,9 @@ void setUp() {
manager.save(prA);
ProgramStage psA = createProgramStage('A', prA);
manager.save(psA);
- TrackedEntity trackedEntityA = createTrackedEntity('A', ouA);
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntityA = createTrackedEntity('A', ouA, trackedEntityType);
manager.save(trackedEntityA);
enrollmentA = createEnrollment(prA, trackedEntityA, ouA);
manager.save(enrollmentA);
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/TrackedEntityAttributeControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/TrackedEntityAttributeControllerTest.java
index 09c631127f70..15aa1e623dcd 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/TrackedEntityAttributeControllerTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/TrackedEntityAttributeControllerTest.java
@@ -140,8 +140,7 @@ void setUp() {
program.getProgramAttributes().add(pteaB);
manager.update(program);
- te = createTrackedEntity(orgUnit);
- te.setTrackedEntityType(trackedEntityType);
+ te = createTrackedEntity(orgUnit, trackedEntityType);
manager.save(te);
enrollment = new Enrollment(program, te, orgUnit);
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/deduplication/DeduplicationControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/deduplication/DeduplicationControllerTest.java
index 3a1cf51e5045..8a2114bd5443 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/deduplication/DeduplicationControllerTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/deduplication/DeduplicationControllerTest.java
@@ -79,11 +79,9 @@ public void setUp() {
trackedEntityType = createTrackedEntityType('A');
dbmsManager.save(trackedEntityType);
- origin = createTrackedEntity(orgUnit);
- origin.setTrackedEntityType(trackedEntityType);
- duplicate1 = createTrackedEntity(orgUnit);
- duplicate1.setTrackedEntityType(trackedEntityType);
- TrackedEntity duplicate2 = createTrackedEntity(orgUnit);
+ origin = createTrackedEntity(orgUnit, trackedEntityType);
+ duplicate1 = createTrackedEntity(orgUnit, trackedEntityType);
+ TrackedEntity duplicate2 = createTrackedEntity(orgUnit, trackedEntityType);
dbmsManager.save(origin);
dbmsManager.save(duplicate1);
@@ -97,8 +95,7 @@ public void setUp() {
@Test
void shouldPostPotentialDuplicateWhenTrackedEntitiesExist() throws Exception {
- TrackedEntity trackedEntity = createTrackedEntity(orgUnit);
- trackedEntity.setTrackedEntityType(trackedEntityType);
+ TrackedEntity trackedEntity = createTrackedEntity(orgUnit, trackedEntityType);
dbmsManager.save(trackedEntity);
PotentialDuplicate potentialDuplicate =
new PotentialDuplicate(UID.of(trackedEntity), UID.of(duplicate1));
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/event/ProgramNotificationInstanceControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/event/ProgramNotificationInstanceControllerTest.java
index 130ed2f593f5..0e0552391a7a 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/event/ProgramNotificationInstanceControllerTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/event/ProgramNotificationInstanceControllerTest.java
@@ -47,6 +47,7 @@
import org.hisp.dhis.test.webapi.PostgresControllerIntegrationTestBase;
import org.hisp.dhis.test.webapi.json.domain.JsonIdentifiableObject;
import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.user.User;
import org.hisp.dhis.webapi.controller.tracker.JsonPage;
import org.junit.jupiter.api.BeforeEach;
@@ -86,7 +87,9 @@ void setUp() {
manager.save(prA);
ProgramStage psA = createProgramStage('A', prA);
manager.save(psA);
- TrackedEntity trackedEntityA = createTrackedEntity('A', orgUnit);
+ TrackedEntityType trackedEntityType = createTrackedEntityType('O');
+ manager.save(trackedEntityType);
+ TrackedEntity trackedEntityA = createTrackedEntity('A', orgUnit, trackedEntityType);
manager.save(trackedEntityA);
enrollment = createEnrollment(prA, trackedEntityA, orgUnit);
manager.save(enrollment);
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/ExportControllerPaginationTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/ExportControllerPaginationTest.java
index 05924435a9f8..150ce2a3056a 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/ExportControllerPaginationTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/ExportControllerPaginationTest.java
@@ -357,8 +357,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) {
private TrackedEntity trackedEntity(
OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) {
- TrackedEntity te = createTrackedEntity(orgUnit);
- te.setTrackedEntityType(trackedEntityType);
+ TrackedEntity te = createTrackedEntity(orgUnit, trackedEntityType);
te.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
te.getSharing().setOwner(owner);
return te;
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportChangeLogsControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportChangeLogsControllerTest.java
index 99c1a84e95c4..ee22a7342c46 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportChangeLogsControllerTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportChangeLogsControllerTest.java
@@ -351,8 +351,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) {
private TrackedEntity trackedEntity(
OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) {
- TrackedEntity te = createTrackedEntity(orgUnit);
- te.setTrackedEntityType(trackedEntityType);
+ TrackedEntity te = createTrackedEntity(orgUnit, trackedEntityType);
te.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
te.getSharing().setOwner(owner);
return te;
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportControllerTest.java
index 0daf050f0cfe..44b4d1b5a1ce 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportControllerTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportControllerTest.java
@@ -838,8 +838,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) {
private TrackedEntity trackedEntity(
OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) {
- TrackedEntity result = createTrackedEntity(orgUnit);
- result.setTrackedEntityType(trackedEntityType);
+ TrackedEntity result = createTrackedEntity(orgUnit, trackedEntityType);
result.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
result.getSharing().setOwner(owner);
return result;
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipsExportControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipsExportControllerTest.java
index 9261a496081b..54039ebc8308 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipsExportControllerTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipsExportControllerTest.java
@@ -866,8 +866,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) {
private TrackedEntity trackedEntity(
OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) {
- TrackedEntity te = createTrackedEntity(orgUnit);
- te.setTrackedEntityType(trackedEntityType);
+ TrackedEntity te = createTrackedEntity(orgUnit, trackedEntityType);
te.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
te.getSharing().setOwner(owner);
return te;
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportControllerTest.java
index 89cea37bf476..0d4f783a4a89 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportControllerTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportControllerTest.java
@@ -220,7 +220,7 @@ void setUpToBeMigrated() {
program.setTrackedEntityType(trackedEntityType);
manager.save(program, false);
- softDeletedTrackedEntity = createTrackedEntity(orgUnit);
+ softDeletedTrackedEntity = createTrackedEntity(orgUnit, trackedEntityType);
softDeletedTrackedEntity.setDeleted(true);
manager.save(softDeletedTrackedEntity, false);
}
@@ -1076,8 +1076,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) {
private TrackedEntity trackedEntity(
OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) {
- TrackedEntity te = createTrackedEntity(orgUnit);
- te.setTrackedEntityType(trackedEntityType);
+ TrackedEntity te = createTrackedEntity(orgUnit, trackedEntityType);
te.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
te.getSharing().setOwner(owner);
return te;
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerCreateRelationshipSMSTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerCreateRelationshipSMSTest.java
index a93543caa166..476824068d0d 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerCreateRelationshipSMSTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerCreateRelationshipSMSTest.java
@@ -270,8 +270,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) {
private TrackedEntity trackedEntity(
OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) {
- TrackedEntity te = createTrackedEntity(orgUnit);
- te.setTrackedEntityType(trackedEntityType);
+ TrackedEntity te = createTrackedEntity(orgUnit, trackedEntityType);
te.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
te.getSharing().setOwner(user);
return te;
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEnrollmentSMSTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEnrollmentSMSTest.java
index b8e55d8f0967..9f38eda4c66a 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEnrollmentSMSTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEnrollmentSMSTest.java
@@ -510,8 +510,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) {
private TrackedEntity trackedEntity(
OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) {
- TrackedEntity te = createTrackedEntity(orgUnit);
- te.setTrackedEntityType(trackedEntityType);
+ TrackedEntity te = createTrackedEntity(orgUnit, trackedEntityType);
te.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
te.getSharing().setOwner(user);
return te;
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEventSMSTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEventSMSTest.java
index ed78ae34ae7a..ca447f927d6b 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEventSMSTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEventSMSTest.java
@@ -864,8 +864,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) {
private TrackedEntity trackedEntity(
OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) {
- TrackedEntity te = createTrackedEntity(orgUnit);
- te.setTrackedEntityType(trackedEntityType);
+ TrackedEntity te = createTrackedEntity(orgUnit, trackedEntityType);
te.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
te.getSharing().setOwner(user1);
return te;
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportNoteControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportNoteControllerTest.java
index 3ce3693bb9cf..991bc4aa34cf 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportNoteControllerTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportNoteControllerTest.java
@@ -91,7 +91,7 @@ void setUp() {
.addUserAccess(new UserAccess(importUser, AccessStringHelper.DATA_READ));
manager.save(programStage, false);
- TrackedEntity te = createTrackedEntity(orgUnit);
+ TrackedEntity te = createTrackedEntity(orgUnit, trackedEntityType);
te.setTrackedEntityType(trackedEntityType);
manager.save(te);
diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/trigramsummary/TrigramSummaryControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/trigramsummary/TrigramSummaryControllerTest.java
index a8565a726414..57744014958f 100644
--- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/trigramsummary/TrigramSummaryControllerTest.java
+++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/trigramsummary/TrigramSummaryControllerTest.java
@@ -183,8 +183,7 @@ void setUp() {
program.getProgramAttributes().add(pteaB);
manager.update(program);
- trackedEntity = createTrackedEntity(orgUnit);
- trackedEntity.setTrackedEntityType(trackedEntityType);
+ trackedEntity = createTrackedEntity(orgUnit, trackedEntityType);
manager.save(trackedEntity);
enrollment = new Enrollment(program, trackedEntity, orgUnit);