From 46275135f736b1898e2f30c501acb78f9ac7c4a4 Mon Sep 17 00:00:00 2001 From: zubaira Date: Sat, 9 Nov 2024 20:59:28 +0100 Subject: [PATCH 01/27] feat: Add not-null constraint for column trackedentitytypeid in trackedentity table --- .../hisp/dhis/trackedentity/hibernate/TrackedEntity.hbm.xml | 2 +- .../V2_42_26__Add_not_null_constraint_to_trackedentity.sql | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 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 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-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..4eeaed80691f --- /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,3 @@ +-- Add not null constraint to trackedentitytypeid column in trackedentity table +ALTER TABLE trackedentity + ALTER COLUMN trackedentitytypeid SET NOT NULL; \ No newline at end of file From 962dae2103f0d81074de65aa9b5f2da5232d55d1 Mon Sep 17 00:00:00 2001 From: zubaira Date: Fri, 15 Nov 2024 19:05:35 +0100 Subject: [PATCH 02/27] fix test --- .../org/hisp/dhis/copy/CopyServiceTest.java | 4 ++- .../DeduplicationHelperTest.java | 4 +-- ...RelationshipOperationParamsMapperTest.java | 2 +- .../DuplicateRelationshipSupplierTest.java | 6 ++-- .../supplier/UniqueAttributeSupplierTest.java | 2 +- .../programrule/RuleEngineMapperTest.java | 3 +- .../DataRelationsValidatorTest.java | 2 +- .../SecurityOwnershipValidatorTest.java | 3 +- .../event/SecurityOwnershipValidatorTest.java | 3 +- .../SecurityOwnershipValidatorTest.java | 9 ++++-- .../java/org/hisp/dhis/test/TestBase.java | 27 ++++++++++++++++-- .../event/data/EventAnalyticsServiceTest.java | 2 +- .../hisp/dhis/audit/AuditIntegrationTest.java | 6 ++-- .../dhis/maintenance/HardDeleteAuditTest.java | 3 +- .../maintenance/MaintenanceServiceTest.java | 7 +++-- .../DataElementMergeServiceTest.java | 10 +++---- .../TrackerOrgUnitMergeHandlerTest.java | 6 ++-- ...rogramNotificationMessageRendererTest.java | 2 +- .../predictor/EventPredictionServiceTest.java | 3 +- .../EventProgramEnrollmentServiceTest.java | 3 +- .../program/ProgramExpressionServiceTest.java | 3 +- .../program/ProgramIndicatorServiceTest.java | 3 +- .../dhis/program/ProgramMessageStoreTest.java | 4 +-- .../ProgramNotificationServiceTest.java | 12 +++++--- .../RelationshipDeletionHandlerTest.java | 5 ++-- .../HibernateReservedValueStoreTest.java | 8 +++--- ...ckedEntityDataValueChangeLogStoreTest.java | 2 +- .../TrackedEntityProgramOwnerServiceTest.java | 4 +-- .../TrackedEntityServiceTest.java | 11 +++++--- .../TrackerAccessManagerTest.java | 8 +++--- .../TrackerOwnershipManagerTest.java | 4 +-- ...uplicationServiceMergeIntegrationTest.java | 8 +++--- ...ntialDuplicateRemoveTrackedEntityTest.java | 19 +++++++------ ...tentialDuplicateStoreRelationshipTest.java | 8 +++--- .../PotentialDuplicateStoreTEAVTest.java | 6 ++-- .../enrollment/EnrollmentServiceTest.java | 12 ++++---- .../relationship/RelationshipServiceTest.java | 28 +++++++++++-------- .../TrackedEntityAuditServiceTest.java | 4 +-- .../TrackedEntityServiceTest.java | 13 +++++---- ...TrackerNotificationHandlerServiceTest.java | 2 +- ...nrollmentSecurityImportValidationTest.java | 11 ++++---- .../EventSecurityImportValidationTest.java | 8 +++--- ...rackedEntityAttributeValueServiceTest.java | 8 +++--- .../TrackedEntityAttributeValueStoreTest.java | 8 +++--- .../AnalyticsValidationServiceTest.java | 3 +- .../controller/ChangeLogControllerTest.java | 4 +-- .../ProgramMessageControllerTest.java | 2 +- .../TrackedEntityAttributeControllerTest.java | 2 +- .../DeduplicationControllerTest.java | 8 +++--- ...ramNotificationInstanceControllerTest.java | 3 +- .../ExportControllerPaginationTest.java | 2 +- .../EnrollmentsExportControllerTest.java | 2 +- .../EventsExportChangeLogsControllerTest.java | 2 +- .../event/EventsExportControllerTest.java | 2 +- .../RelationshipsExportControllerTest.java | 2 +- .../TrackedEntitiesExportControllerTest.java | 4 +-- .../TrackerCreateRelationshipSMSTest.java | 2 +- .../imports/TrackerEnrollmentSMSTest.java | 2 +- .../tracker/imports/TrackerEventSMSTest.java | 2 +- .../TrigramSummaryControllerTest.java | 2 +- 60 files changed, 203 insertions(+), 147 deletions(-) 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 177e20ecadc5..71ddd65efc2e 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 @@ -133,7 +133,9 @@ void testCopyProgramFromUidWithValidProgram() throws NotFoundException, Forbidde OrganisationUnit orgUnit = createOrganisationUnit("New Org 1"); List originalEnrollments = - List.of(createEnrollment(original, createTrackedEntity(orgUnit), orgUnit)); + List.of( + createEnrollment( + original, createTrackedEntity(orgUnit, createDefaultTrackedEntityType()), 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..754644817ca9 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,14 +521,14 @@ private List getEnrollments() { } private TrackedEntity getTrackedEntityA() { - TrackedEntity te = createTrackedEntity(organisationUnitA); + TrackedEntity te = createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); te.setTrackedEntityType(trackedEntityTypeA); return te; } private TrackedEntity getTrackedEntityB() { - TrackedEntity te = createTrackedEntity(organisationUnitB); + TrackedEntity te = createTrackedEntity(organisationUnitB, createDefaultTrackedEntityType()); te.setTrackedEntityType(trackedEntityTypeB); return te; 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..e1449fc63d26 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, createDefaultTrackedEntityType()); 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..9a253dd806c0 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, createDefaultTrackedEntityType()); teA.setUid(TE_A_UID.getValue()); - teB = createTrackedEntity(organisationUnit); + teB = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); teB.setUid(TE_B_UID.getValue()); - teC = createTrackedEntity(organisationUnit); + teC = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); 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..5ccc52de3bb5 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, createDefaultTrackedEntityType()); 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..11df2cf8c680 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, createDefaultTrackedEntityType()); } 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..4be2210f1a94 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, createDefaultTrackedEntityType()); 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 f471e3731b0d..42565e811623 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 @@ -389,7 +389,8 @@ void verifyValidationFailsForEnrollmentDeletionAndUserWithoutTrackedEntityTypeRe } private TrackedEntity teWithNoEnrollments() { - TrackedEntity trackedEntity = createTrackedEntity(organisationUnit); + TrackedEntity trackedEntity = + createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); 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/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 552ecdc2797d..cc4f9c127887 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 @@ -486,7 +486,8 @@ void verifySuccessEventValidationWhenEventHasNoOrgUnitAssigned() { } private TrackedEntity teWithNoEnrollments() { - TrackedEntity trackedEntity = createTrackedEntity(organisationUnit); + TrackedEntity trackedEntity = + createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); 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 38186f6b4c65..a59209d86711 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 @@ -299,7 +299,8 @@ void shouldFailWhenUpdateTEAndUserHasNoWriteAccess() { } private TrackedEntity teWithNoEnrollments() { - TrackedEntity trackedEntity = createTrackedEntity(organisationUnit); + TrackedEntity trackedEntity = + createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); trackedEntity.setUid(TE_ID.getValue()); trackedEntity.setEnrollments(Sets.newHashSet()); trackedEntity.setTrackedEntityType(trackedEntityType); @@ -311,7 +312,8 @@ private TrackedEntity teWithDeleteEnrollments() { Enrollment enrollment = new Enrollment(); enrollment.setDeleted(true); - TrackedEntity trackedEntity = createTrackedEntity(organisationUnit); + TrackedEntity trackedEntity = + createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); trackedEntity.setUid(TE_ID.getValue()); trackedEntity.setEnrollments(Sets.newHashSet(enrollment)); trackedEntity.setTrackedEntityType(trackedEntityType); @@ -320,7 +322,8 @@ private TrackedEntity teWithDeleteEnrollments() { } private TrackedEntity teWithEnrollments() { - TrackedEntity trackedEntity = createTrackedEntity(organisationUnit); + TrackedEntity trackedEntity = + createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); trackedEntity.setUid(TE_ID.getValue()); trackedEntity.setEnrollments(Sets.newHashSet(new Enrollment())); trackedEntity.setTrackedEntityType(trackedEntityType); 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 dc740f453a01..0ad12e149594 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 @@ -191,6 +191,7 @@ import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.trackedentity.TrackedEntityType; import org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute; +import org.hisp.dhis.trackedentity.TrackedEntityTypeService; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; import org.hisp.dhis.trackedentityfilter.EntityQueryCriteria; import org.hisp.dhis.trackedentityfilter.TrackedEntityFilter; @@ -286,13 +287,18 @@ public abstract class TestBase { @Autowired(required = false) protected CategoryService internalCategoryService; + @Autowired private TrackedEntityTypeService trackedEntityTypeService; + @Autowired protected HibernateService hibernateService; protected static CategoryService categoryService; + protected static TrackedEntityTypeService entityTypeService; + @PostConstruct protected void initServices() { categoryService = internalCategoryService; + entityTypeService = trackedEntityTypeService; } static { @@ -2141,29 +2147,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); @@ -2174,6 +2187,14 @@ public static TrackedEntity createTrackedEntity( return trackedEntity; } + public static TrackedEntityType createDefaultTrackedEntityType() { + TrackedEntityType trackedEntityType = new TrackedEntityType(); + trackedEntityType.setAutoFields(); + trackedEntityType.setName("TrackedEntityType" + CodeGenerator.generateCode(2)); + entityTypeService.addTrackedEntityType(trackedEntityType); + return trackedEntityType; + } + public static TrackedEntityAttributeValue createTrackedEntityAttributeValue( char uniqueChar, TrackedEntity trackedEntity, TrackedEntityAttribute attribute) { TrackedEntityAttributeValue attributeValue = new TrackedEntityAttributeValue(); 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..6c2bb9ca3f10 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,7 +411,7 @@ void setUp() throws ConflictException { manager.save(trackedEntityType); // Tracked Entity Instances (Registrations) - TrackedEntity teiA = createTrackedEntity(ouD); + TrackedEntity teiA = createTrackedEntity(ouD, createDefaultTrackedEntityType()); teiA.setUid("trackEntInA"); teiA.setTrackedEntityType(trackedEntityType); manager.save(teiA); 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..e15dfc6869a0 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 @@ -108,7 +108,8 @@ void testSaveTrackedEntity() { TrackedEntityAttribute attribute = createTrackedEntityAttribute('A'); manager.save(ou); manager.save(attribute); - TrackedEntity trackedEntity = createTrackedEntity('A', ou, attribute); + TrackedEntity trackedEntity = + createTrackedEntity('A', ou, attribute, createDefaultTrackedEntityType()); 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 +128,8 @@ void testSaveTrackedAttributeValue() { TrackedEntityAttribute attribute = createTrackedEntityAttribute('A'); manager.save(ou); manager.save(attribute); - TrackedEntity trackedEntity = createTrackedEntity('A', ou, attribute); + TrackedEntity trackedEntity = + createTrackedEntity('A', ou, attribute, createDefaultTrackedEntityType()); 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..48f0dd8333ae 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 @@ -70,7 +70,8 @@ class HardDeleteAuditTest extends PostgresIntegrationTestBase { void testHardDeleteTrackedEntity() { OrganisationUnit ou = createOrganisationUnit('A'); TrackedEntityAttribute attribute = createTrackedEntityAttribute('A'); - TrackedEntity trackedEntity = createTrackedEntity('A', ou, attribute); + TrackedEntity trackedEntity = + createTrackedEntity('A', ou, attribute, createDefaultTrackedEntityType()); 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 96f5aa075b91..dd5b51752e61 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,14 @@ void setUp() { programService.updateProgram(program); TrackedEntityType trackedEntityType = createTrackedEntityType('A'); trackedEntityTypeService.addTrackedEntityType(trackedEntityType); - trackedEntity = createTrackedEntity(organisationUnit); + trackedEntity = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); trackedEntity.setTrackedEntityType(trackedEntityType); manager.save(trackedEntity); - trackedEntityB = createTrackedEntity(organisationUnit); + trackedEntityB = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); trackedEntityB.setTrackedEntityType(trackedEntityType); manager.save(trackedEntityB); - trackedEntityWithAssociations = createTrackedEntity('T', organisationUnit); + trackedEntityWithAssociations = + createTrackedEntity('T', organisationUnit, createDefaultTrackedEntityType()); 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/dataelement/DataElementMergeServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/dataelement/DataElementMergeServiceTest.java index da9b724bf67b..2a94dfc9e978 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 @@ -1267,7 +1267,7 @@ 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); + TrackedEntity trackedEntity = createTrackedEntity(ou1, createDefaultTrackedEntityType()); identifiableObjectManager.save(trackedEntity); Enrollment enrollment = createEnrollment(program, trackedEntity, ou1); identifiableObjectManager.save(enrollment); @@ -1352,7 +1352,7 @@ 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); + TrackedEntity trackedEntity = createTrackedEntity(ou1, createDefaultTrackedEntityType()); identifiableObjectManager.save(trackedEntity); Enrollment enrollment = createEnrollment(program, trackedEntity, ou1); identifiableObjectManager.save(enrollment); @@ -1445,7 +1445,7 @@ 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); + TrackedEntity trackedEntity = createTrackedEntity(ou1, createDefaultTrackedEntityType()); identifiableObjectManager.save(trackedEntity); Enrollment enrollment = createEnrollment(program, trackedEntity, ou1); identifiableObjectManager.save(enrollment); @@ -2549,7 +2549,7 @@ void dataValueAuditMergeDeleteTest() throws ConflictException { "TrackedEntityDataValueChangeLog with references to source DataElements are not changed or deleted when sources not deleted") void trackedEntityDataValueChangeLogMergeTest() throws ConflictException { // given - TrackedEntity trackedEntity = createTrackedEntity(ou1); + TrackedEntity trackedEntity = createTrackedEntity(ou1, createDefaultTrackedEntityType()); identifiableObjectManager.save(trackedEntity); Enrollment enrollment = createEnrollment(program, trackedEntity, ou1); identifiableObjectManager.save(enrollment); @@ -2602,7 +2602,7 @@ void trackedEntityDataValueChangeLogMergeTest() throws ConflictException { "TrackedEntityDataValueChangeLog with references to source DataElements are deleted when sources are deleted") void trackedEntityDataValueChangeLogMergeDeletedTest() throws ConflictException { // given - TrackedEntity trackedEntity = createTrackedEntity(ou1); + TrackedEntity trackedEntity = createTrackedEntity(ou1, createDefaultTrackedEntityType()); 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..11ccf932e004 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 @@ -97,9 +97,9 @@ void setUp() { manager.save(ouA); manager.save(ouB); manager.save(ouC); - trackedEntityA = createTrackedEntity('A', ouA); - trackedEntityB = createTrackedEntity('B', ouB); - trackedEntityC = createTrackedEntity('C', ouC); + trackedEntityA = createTrackedEntity('A', ouA, createDefaultTrackedEntityType()); + trackedEntityB = createTrackedEntity('B', ouB, createDefaultTrackedEntityType()); + trackedEntityC = createTrackedEntity('C', ouC, createDefaultTrackedEntityType()); 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..26d6d1736df5 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 @@ -201,7 +201,7 @@ void setUp() { programStageService.updateProgramStage(programStageA); programA.setProgramStages(Sets.newHashSet(programStageA)); programService.updateProgram(programA); - trackedEntityA = createTrackedEntity(organisationUnitA); + trackedEntityA = createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); 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..9cd4c0b6f105 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 @@ -216,7 +216,8 @@ void setUp() { entityAttribute.setAggregationType(AggregationType.COUNT); entityAttribute.setUid(TRACKED_ENTITY_ATTRIBUTE_UID); entityAttributeService.addTrackedEntityAttribute(entityAttribute); - TrackedEntity trackedEntity = createTrackedEntity('A', orgUnitA, entityAttribute); + TrackedEntity trackedEntity = + createTrackedEntity('A', orgUnitA, entityAttribute, createDefaultTrackedEntityType()); 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..7917fe99c5f9 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 @@ -77,7 +77,8 @@ void setUp() { OrganisationUnit organisationUnitB = createOrganisationUnit('B'); manager.save(organisationUnitB); - TrackedEntity trackedEntity = createTrackedEntity(organisationUnitA); + TrackedEntity trackedEntity = + createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); 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..f9850b31d64b 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 @@ -99,7 +99,8 @@ void setUp() { dataElementB = createDataElement('B'); dataElementService.addDataElement(dataElementA); dataElementService.addDataElement(dataElementB); - TrackedEntity trackedEntity = createTrackedEntity(organisationUnit); + TrackedEntity trackedEntity = + createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); 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 27f87bd1af07..29c1152f44c4 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 @@ -227,7 +227,8 @@ void setUp() { // --------------------------------------------------------------------- // TrackedEntity // --------------------------------------------------------------------- - TrackedEntity trackedEntity = createTrackedEntity(organisationUnit); + TrackedEntity trackedEntity = + createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); 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 177aff10eac0..094962283764 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 @@ -106,7 +106,7 @@ void setUp() { programService.updateProgram(programA); // Initialize Tracked Entities, Enrollment and Event - TrackedEntity trackedEntityB = createTrackedEntity(orgUnitA); + TrackedEntity trackedEntityB = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); manager.save(trackedEntityB); enrollmentA = new Enrollment(new Date(), new Date(), trackedEntityB, programA); @@ -116,7 +116,7 @@ void setUp() { eventA.setScheduledDate(new Date()); eventA.setUid(CodeGenerator.generateUid()); - TrackedEntity trackedEntityA = createTrackedEntity(orgUnitA); + TrackedEntity trackedEntityA = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); 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 21d81a94686e..d3c5babbc4ad 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 @@ -117,9 +117,11 @@ void setUp() { OrganisationUnit organisationUnitB = createOrganisationUnit('B'); manager.save(organisationUnitA); manager.save(organisationUnitB); - TrackedEntity trackedEntityA = createTrackedEntity(organisationUnitA); + TrackedEntity trackedEntityA = + createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); manager.save(trackedEntityA); - TrackedEntity trackedEntityB = createTrackedEntity(organisationUnitB); + TrackedEntity trackedEntityB = + createTrackedEntity(organisationUnitB, createDefaultTrackedEntityType()); manager.save(trackedEntityB); programA = createProgram('A', new HashSet<>(), organisationUnitA); programService.addProgram(programA); @@ -396,8 +398,10 @@ void testGetEnrollmentsWithScheduledNotifications() { programNotificationStore.save(a2); programNotificationStore.save(a3); // TE - TrackedEntity trackedEntityX = createTrackedEntity(organisationUnitA); - TrackedEntity trackedEntityY = createTrackedEntity(organisationUnitA); + TrackedEntity trackedEntityX = + createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); + TrackedEntity trackedEntityY = + createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); 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..2d3fef8eee9f 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 @@ -58,9 +58,10 @@ public void setUp() { manager.save(deletableRelationshipType); OrganisationUnit orgUnit = createOrganisationUnit('A'); manager.save(orgUnit); - TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnit); + TrackedEntity trackedEntityFrom = + createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); manager.save(trackedEntityFrom); - TrackedEntity trackedEntityTo = createTrackedEntity(orgUnit); + TrackedEntity trackedEntityTo = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); 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..765dfb8de122 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 @@ -169,7 +169,7 @@ void getAvailableValuesWhenAlreadyUsed() throws TextPatternParser.TextPatternParsingException, IllegalAccessException { OrganisationUnit ou = createOrganisationUnit("OU"); organisationUnitStore.save(ou); - TrackedEntity trackedEntity = createTrackedEntity(ou); + TrackedEntity trackedEntity = createTrackedEntity(ou, createDefaultTrackedEntityType()); manager.save(trackedEntity); TrackedEntityAttribute tea = createTrackedEntityAttribute('Y'); TextPattern textPattern = TextPatternParser.parse(key); @@ -221,7 +221,7 @@ void shouldNotAddAlreadyReservedValues() { saveReservedValue(reservedValue.value(prog001).build()); OrganisationUnit ou = createOrganisationUnit("OU"); organisationUnitStore.save(ou); - TrackedEntity trackedEntity = createTrackedEntity(ou); + TrackedEntity trackedEntity = createTrackedEntity(ou, createDefaultTrackedEntityType()); manager.save(trackedEntity); TrackedEntityAttribute tea = createTrackedEntityAttribute('Y'); tea.setUid(teaUid); @@ -237,7 +237,7 @@ void shouldRemoveAlreadyUsedReservedValues() { saveReservedValue(reservedValue.value(prog001).build()); OrganisationUnit ou = createOrganisationUnit("OU"); organisationUnitStore.save(ou); - TrackedEntity trackedEntity = createTrackedEntity(ou); + TrackedEntity trackedEntity = createTrackedEntity(ou, createDefaultTrackedEntityType()); manager.save(trackedEntity); TrackedEntityAttribute tea = createTrackedEntityAttribute('Y'); tea.setUid(teaUid); @@ -261,7 +261,7 @@ void shouldRemoveAlreadyUsedOrExpiredReservedValues() { // used value OrganisationUnit ou = createOrganisationUnit("OU"); organisationUnitStore.save(ou); - TrackedEntity trackedEntity = createTrackedEntity(ou); + TrackedEntity trackedEntity = createTrackedEntity(ou, createDefaultTrackedEntityType()); 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/TrackedEntityDataValueChangeLogStoreTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueChangeLogStoreTest.java index 2d67833c6b26..c6a1661df78e 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueChangeLogStoreTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueChangeLogStoreTest.java @@ -159,7 +159,7 @@ void setUp() { dataElementService.addDataElement(deA); dataElementService.addDataElement(deB); - TrackedEntity teA = createTrackedEntity(ouA); + TrackedEntity teA = createTrackedEntity(ouA, createDefaultTrackedEntityType()); manager.save(teA); Enrollment enrollment = createEnrollment(pA, teA, ouA); 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..6ae4661374fa 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,9 @@ void setUp() { organisationUnitService.addOrganisationUnit(organisationUnitA); organisationUnitB = createOrganisationUnit('B'); organisationUnitService.addOrganisationUnit(organisationUnitB); - trackedEntityA1 = createTrackedEntity(organisationUnitA); + trackedEntityA1 = createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); trackedEntityA1.setUid(TE_A1); - trackedEntityB1 = createTrackedEntity(organisationUnitA); + trackedEntityB1 = createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); 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..f6596cc60b87 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); + trackedEntityA1 = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + TrackedEntity trackedEntityB1 = + createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + TrackedEntity trackedEntityC1 = + createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + TrackedEntity trackedEntityD1 = + createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); 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 4fb09bcbeb84..3012bf60fc06 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 @@ -155,10 +155,10 @@ 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 = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); + TrackedEntity trackedEntityB = createTrackedEntity(orgUnitB, createDefaultTrackedEntityType()); + TrackedEntity femaleA = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); + TrackedEntity femaleB = createTrackedEntity(orgUnitB, createDefaultTrackedEntityType()); trackedEntityA.setTrackedEntityType(trackedEntityType); trackedEntityB.setTrackedEntityType(trackedEntityType); femaleA.setTrackedEntityType(trackedEntityType); 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 c85e2dcacd0b..ee9a144e3010 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 @@ -116,9 +116,9 @@ void setUp() { trackedEntityType.setSharing(Sharing.builder().publicAccess(AccessStringHelper.FULL).build()); trackedEntityTypeService.updateTrackedEntityType(trackedEntityType); - trackedEntityA1 = createTrackedEntity(organisationUnitA); + trackedEntityA1 = createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); trackedEntityA1.setTrackedEntityType(trackedEntityType); - trackedEntityB1 = createTrackedEntity(organisationUnitB); + trackedEntityB1 = createTrackedEntity(organisationUnitB, createDefaultTrackedEntityType()); trackedEntityB1.setTrackedEntityType(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 0af6178ea4cf..d5c874b8ee43 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 @@ -84,8 +84,8 @@ void shouldManualMergeWithAuthorityAll() TrackedEntityType trackedEntityType = createTrackedEntityType('A'); trackedEntityTypeService.addTrackedEntityType(trackedEntityType); - TrackedEntity original = createTrackedEntity(ou); - TrackedEntity duplicate = createTrackedEntity(ou); + TrackedEntity original = createTrackedEntity(ou, createDefaultTrackedEntityType()); + TrackedEntity duplicate = createTrackedEntity(ou, createDefaultTrackedEntityType()); original.setTrackedEntityType(trackedEntityType); duplicate.setTrackedEntityType(trackedEntityType); manager.save(original); @@ -139,8 +139,8 @@ void shouldManualMergeWithUserGroupOfProgram() trackedEntityTypeService.addTrackedEntityType(trackedEntityType); trackedEntityType.setSharing(sharing); trackedEntityTypeService.updateTrackedEntityType(trackedEntityType); - TrackedEntity original = createTrackedEntity(ou); - TrackedEntity duplicate = createTrackedEntity(ou); + TrackedEntity original = createTrackedEntity(ou, createDefaultTrackedEntityType()); + TrackedEntity duplicate = createTrackedEntity(ou, createDefaultTrackedEntityType()); original.setTrackedEntityType(trackedEntityType); duplicate.setTrackedEntityType(trackedEntityType); manager.save(original); 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..e989748b91c6 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 @@ -107,10 +107,10 @@ 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); + TrackedEntity original = createTrackedEntity(ou, createDefaultTrackedEntityType()); + TrackedEntity duplicate = createTrackedEntity(ou, createDefaultTrackedEntityType()); + TrackedEntity control1 = createTrackedEntity(ou, createDefaultTrackedEntityType()); + TrackedEntity control2 = createTrackedEntity(ou, createDefaultTrackedEntityType()); manager.save(original); manager.save(duplicate); manager.save(control1); @@ -145,10 +145,10 @@ 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); + TrackedEntity original = createTrackedEntity(ou, createDefaultTrackedEntityType()); + TrackedEntity duplicate = createTrackedEntity(ou, createDefaultTrackedEntityType()); + TrackedEntity control1 = createTrackedEntity(ou, createDefaultTrackedEntityType()); + TrackedEntity control2 = createTrackedEntity(ou, createDefaultTrackedEntityType()); manager.save(original); manager.save(duplicate); manager.save(control1); @@ -187,7 +187,8 @@ void shouldDeleteEnrollments() throws ForbiddenException, NotFoundException { private TrackedEntity createTrackedEntity(TrackedEntityAttribute trackedEntityAttribute) { OrganisationUnit ou = createOrganisationUnit("OU_A"); organisationUnitService.addOrganisationUnit(ou); - TrackedEntity trackedEntity = createTrackedEntity('T', ou, trackedEntityAttribute); + TrackedEntity trackedEntity = + createTrackedEntity('T', ou, trackedEntityAttribute, createDefaultTrackedEntityType()); 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..0b6dec890926 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 @@ -79,10 +79,10 @@ 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); + original = createTrackedEntity(ou, createDefaultTrackedEntityType()); + duplicate = createTrackedEntity(ou, createDefaultTrackedEntityType()); + extra1 = createTrackedEntity(ou, createDefaultTrackedEntityType()); + extra2 = createTrackedEntity(ou, createDefaultTrackedEntityType()); 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..5e7c7604bdf9 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 @@ -85,9 +85,9 @@ class PotentialDuplicateStoreTEAVTest extends PostgresIntegrationTestBase { void setUp() { OrganisationUnit ou = createOrganisationUnit("OU_A"); organisationUnitService.addOrganisationUnit(ou); - original = createTrackedEntity(ou); - duplicate = createTrackedEntity(ou); - control = createTrackedEntity(ou); + original = createTrackedEntity(ou, createDefaultTrackedEntityType()); + duplicate = createTrackedEntity(ou, createDefaultTrackedEntityType()); + control = createTrackedEntity(ou, createDefaultTrackedEntityType()); 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..fa6222a75805 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,23 +158,25 @@ void setUp() { trackedEntityTypeA.getSharing().setOwner(user); manager.save(trackedEntityTypeA, false); - trackedEntityA = createTrackedEntity(orgUnitA); + trackedEntityA = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); trackedEntityA.setTrackedEntityType(trackedEntityTypeA); manager.save(trackedEntityA, false); - TrackedEntity trackedEntityB = createTrackedEntity(orgUnitB); + TrackedEntity trackedEntityB = createTrackedEntity(orgUnitB, createDefaultTrackedEntityType()); trackedEntityB.setTrackedEntityType(trackedEntityTypeA); manager.save(trackedEntityB, false); - TrackedEntity trackedEntityC = createTrackedEntity(orgUnitC); + TrackedEntity trackedEntityC = createTrackedEntity(orgUnitC, createDefaultTrackedEntityType()); trackedEntityC.setTrackedEntityType(trackedEntityTypeA); manager.save(trackedEntityC, false); - TrackedEntity trackedEntityChildA = createTrackedEntity(orgUnitChildA); + TrackedEntity trackedEntityChildA = + createTrackedEntity(orgUnitChildA, createDefaultTrackedEntityType()); trackedEntityChildA.setTrackedEntityType(trackedEntityTypeA); manager.save(trackedEntityChildA, false); - TrackedEntity trackedEntityGrandchildA = createTrackedEntity(orgUnitGrandchildA); + TrackedEntity trackedEntityGrandchildA = + createTrackedEntity(orgUnitGrandchildA, createDefaultTrackedEntityType()); trackedEntityGrandchildA.setTrackedEntityType(trackedEntityTypeA); manager.save(trackedEntityGrandchildA, false); 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 07af5aace287..046963caf521 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 @@ -136,15 +136,15 @@ void setUp() { inaccessibleTrackedEntityType.getSharing().setPublicAccess(AccessStringHelper.DEFAULT); manager.save(inaccessibleTrackedEntityType, false); - teA = createTrackedEntity(orgUnitA); + teA = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); teA.setTrackedEntityType(trackedEntityType); manager.save(teA, false); - teB = createTrackedEntity(orgUnitA); + teB = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); teB.setTrackedEntityType(trackedEntityType); manager.save(teB, false); - inaccessibleTe = createTrackedEntity(orgUnitA); + inaccessibleTe = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); inaccessibleTe.setTrackedEntityType(inaccessibleTrackedEntityType); manager.save(inaccessibleTe, false); @@ -295,7 +295,8 @@ void shouldNotReturnRelationshipWhenTeIsTransferredAndUserHasNoAccessToAtLeastOn program.setOrganisationUnits(Set.of(orgUnitA, orgUnitB)); manager.save(program, false); - TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA); + TrackedEntity trackedEntityFrom = + createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); trackedEntityFrom.setTrackedEntityType(trackedEntityType); manager.save(trackedEntityFrom); @@ -306,7 +307,7 @@ void shouldNotReturnRelationshipWhenTeIsTransferredAndUserHasNoAccessToAtLeastOn trackerOwnershipAccessManager.transferOwnership(trackedEntityFrom, program, orgUnitB); - TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA); + TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); trackedEntityTo.setTrackedEntityType(trackedEntityType); manager.save(trackedEntityTo); @@ -331,18 +332,19 @@ void shouldExcludeRelationshipWhenProgramIsProtectedAndUserHasNoAccess() throws ForbiddenException, NotFoundException, BadRequestException { injectAdminIntoSecurityContext(); - TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA); + TrackedEntity trackedEntityFrom = + createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); trackedEntityFrom.setTrackedEntityType(trackedEntityType); manager.save(trackedEntityFrom); - TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA); + TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); trackedEntityTo.setTrackedEntityType(trackedEntityType); manager.save(trackedEntityTo); Program inaccessibleProgram = protectedProgram('P', trackedEntityType, orgUnitB); manager.save(inaccessibleProgram, false); - TrackedEntity notAccessibleTe = createTrackedEntity(orgUnitB); + TrackedEntity notAccessibleTe = createTrackedEntity(orgUnitB, createDefaultTrackedEntityType()); notAccessibleTe.setTrackedEntityType(trackedEntityType); manager.save(notAccessibleTe); @@ -379,11 +381,12 @@ void shouldNotReturnRelationshipWhenUserHasNoMetadataAccessToProgram() { program.setProgramStages(Set.of(programStage)); manager.save(program, false); - TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA); + TrackedEntity trackedEntityFrom = + createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); trackedEntityFrom.setTrackedEntityType(trackedEntityType); manager.save(trackedEntityFrom); - TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA); + TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); trackedEntityTo.setTrackedEntityType(trackedEntityType); manager.save(trackedEntityTo); @@ -418,11 +421,12 @@ void shouldNotReturnRelationshipWhenUserHasNoDataReadAccessToProgram() { program.setProgramStages(Set.of(programStage)); manager.save(program, false); - TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA); + TrackedEntity trackedEntityFrom = + createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); trackedEntityFrom.setTrackedEntityType(trackedEntityType); manager.save(trackedEntityFrom); - TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA); + TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); trackedEntityTo.setTrackedEntityType(trackedEntityType); manager.save(trackedEntityTo); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAuditServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAuditServiceTest.java index fde9d26708a0..a10618309573 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAuditServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAuditServiceTest.java @@ -112,7 +112,7 @@ void setUp() { trackedEntityType = createTrackedEntityType('A'); manager.save(trackedEntityType, false); - trackedEntity = createTrackedEntity(orgUnitA); + trackedEntity = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); trackedEntity.setTrackedEntityType(trackedEntityType); manager.save(trackedEntity, false); @@ -177,7 +177,7 @@ void shouldFailWhenUserHasNoAccessToAnyTETA() { void shouldFailWhenUserHasNoAccessToOrgUnitScope() { OrganisationUnit outOfScopeOrgUnit = createOrganisationUnit("out of scope org unit"); manager.save(outOfScopeOrgUnit, false); - trackedEntity = createTrackedEntity(outOfScopeOrgUnit); + trackedEntity = createTrackedEntity(outOfScopeOrgUnit, createDefaultTrackedEntityType()); trackedEntity.setTrackedEntityType(trackedEntityType); manager.save(trackedEntity, false); 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 a4c81310c859..1095dbd57b01 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 @@ -327,7 +327,7 @@ void setUp() { trackedEntityAttributeValueB = new TrackedEntityAttributeValue(teaB, trackedEntityA, "B"); trackedEntityAttributeValueC = new TrackedEntityAttributeValue(teaC, trackedEntityA, "C"); - trackedEntityA = createTrackedEntity(orgUnitA); + trackedEntityA = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); trackedEntityA.setTrackedEntityType(trackedEntityTypeA); trackedEntityA.setTrackedEntityAttributeValues( Set.of( @@ -336,11 +336,12 @@ void setUp() { trackedEntityAttributeValueC)); manager.save(trackedEntityA, false); - trackedEntityChildA = createTrackedEntity(orgUnitChildA); + trackedEntityChildA = createTrackedEntity(orgUnitChildA, createDefaultTrackedEntityType()); trackedEntityChildA.setTrackedEntityType(trackedEntityTypeA); manager.save(trackedEntityChildA, false); - trackedEntityGrandchildA = createTrackedEntity(orgUnitGrandchildA); + trackedEntityGrandchildA = + createTrackedEntity(orgUnitGrandchildA, createDefaultTrackedEntityType()); trackedEntityGrandchildA.setTrackedEntityType(trackedEntityTypeA); manager.save(trackedEntityGrandchildA, false); @@ -383,7 +384,7 @@ void setUp() { enrollmentB.setEvents(Set.of(eventB)); manager.save(enrollmentB, false); - trackedEntityB = createTrackedEntity(orgUnitB); + trackedEntityB = createTrackedEntity(orgUnitB, createDefaultTrackedEntityType()); trackedEntityB.setTrackedEntityType(trackedEntityTypeA); manager.save(trackedEntityB, false); @@ -401,7 +402,7 @@ void setUp() { enrollmentC.setEvents(Set.of(eventC)); manager.save(enrollmentC, false); - TrackedEntity trackedEntityC = createTrackedEntity(orgUnitC); + TrackedEntity trackedEntityC = createTrackedEntity(orgUnitC, createDefaultTrackedEntityType()); trackedEntityC.setTrackedEntityType(trackedEntityTypeA); manager.save(trackedEntityC, false); @@ -1853,7 +1854,7 @@ void shouldFailWhenRequestingSingleTEAndTETNotAccessible() { TrackedEntityType inaccessibleTrackedEntityType = createTrackedEntityType('U'); inaccessibleTrackedEntityType.setSharing(Sharing.builder().publicAccess("rw------").build()); manager.save(inaccessibleTrackedEntityType, false); - TrackedEntity trackedEntity = createTrackedEntity(orgUnitA); + TrackedEntity trackedEntity = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); trackedEntity.setTrackedEntityType(inaccessibleTrackedEntityType); manager.save(trackedEntity); 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..1109b0630157 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,7 +101,7 @@ void setUp() { programA.getProgramStages().add(programStageA); manager.update(programA); - trackedEntityA = createTrackedEntity('T', orgUnitA); + trackedEntityA = createTrackedEntity('T', orgUnitA, createDefaultTrackedEntityType()); trackedEntityA.setTrackedEntityType(trackedEntityTypeA); manager.save(trackedEntityA, false); 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..507c77870e06 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,10 +163,10 @@ 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 = createTrackedEntity('A', organisationUnitA, createDefaultTrackedEntityType()); + maleB = createTrackedEntity(organisationUnitB, createDefaultTrackedEntityType()); + femaleA = createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); + femaleB = createTrackedEntity(organisationUnitB, createDefaultTrackedEntityType()); maleA.setTrackedEntityType(trackedEntityType); maleB.setTrackedEntityType(trackedEntityType); femaleA.setTrackedEntityType(trackedEntityType); @@ -352,7 +352,8 @@ private Program createProgram(OrganisationUnit orgUnit) { private TrackedEntity createTrackedEntity( TrackedEntityType trackedEntityType, OrganisationUnit orgUnit) { - TrackedEntity trackedEntity = createTrackedEntity('T', orgUnit); + TrackedEntity trackedEntity = + createTrackedEntity('T', orgUnit, createDefaultTrackedEntityType()); trackedEntity.setTrackedEntityType(trackedEntityType); manager.save(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 7785acafad44..759f2e443510 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 @@ -178,10 +178,10 @@ 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 = createTrackedEntity('A', organisationUnitA, createDefaultTrackedEntityType()); + maleB = createTrackedEntity(organisationUnitB, createDefaultTrackedEntityType()); + femaleA = createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); + femaleB = createTrackedEntity(organisationUnitB, createDefaultTrackedEntityType()); maleA.setTrackedEntityType(trackedEntityType); maleB.setTrackedEntityType(trackedEntityType); femaleA.setTrackedEntityType(trackedEntityType); 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 916912f1e6f8..3431e52abcd8 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 @@ -89,10 +89,10 @@ 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); + trackedEntityA = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + trackedEntityB = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + trackedEntityC = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + trackedEntityD = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); manager.save(trackedEntityA); manager.save(trackedEntityB); manager.save(trackedEntityC); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/trackedentityattributevalue/TrackedEntityAttributeValueStoreTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/trackedentityattributevalue/TrackedEntityAttributeValueStoreTest.java index 689093bff1d8..e2495104b1ac 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/trackedentityattributevalue/TrackedEntityAttributeValueStoreTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/trackedentityattributevalue/TrackedEntityAttributeValueStoreTest.java @@ -100,10 +100,10 @@ class TrackedEntityAttributeValueStoreTest extends PostgresIntegrationTestBase { void setUp() { OrganisationUnit organisationUnit = createOrganisationUnit('A'); organisationUnitService.addOrganisationUnit(organisationUnit); - trackedEntityA = createTrackedEntity(organisationUnit); - trackedEntityB = createTrackedEntity(organisationUnit); - trackedEntityC = createTrackedEntity(organisationUnit); - trackedEntityD = createTrackedEntity(organisationUnit); + trackedEntityA = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + trackedEntityB = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + trackedEntityC = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + trackedEntityD = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); 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..945aae2757f9 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 @@ -192,7 +192,8 @@ void setUp() { entityAttribute.setAggregationType(AggregationType.COUNT); entityAttribute.setUid(TRACKED_ENTITY_ATTRIBUTE_UID); entityAttributeService.addTrackedEntityAttribute(entityAttribute); - TrackedEntity trackedEntity = createTrackedEntity('A', orgUnitA, entityAttribute); + TrackedEntity trackedEntity = + createTrackedEntity('A', orgUnitA, entityAttribute, createDefaultTrackedEntityType()); 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/ChangeLogControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ChangeLogControllerTest.java index e72144268617..5e69d8b8d87c 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ChangeLogControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ChangeLogControllerTest.java @@ -117,13 +117,13 @@ void setUp() { trackedEntityType = trackedEntityTypeAccessible(); - te1 = createTrackedEntity(orgUnit); + te1 = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); te1.setTrackedEntityType(trackedEntityType); te1.getSharing().setPublicAccess(AccessStringHelper.DEFAULT); te1.getSharing().setOwner(owner); manager.save(te1, false); - te2 = createTrackedEntity(orgUnit); + te2 = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); te2.setTrackedEntityType(trackedEntityType); te2.getSharing().setPublicAccess(AccessStringHelper.DEFAULT); te2.getSharing().setOwner(owner); 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..235c83bffd34 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 @@ -66,7 +66,7 @@ void setUp() { manager.save(prA); ProgramStage psA = createProgramStage('A', prA); manager.save(psA); - TrackedEntity trackedEntityA = createTrackedEntity('A', ouA); + TrackedEntity trackedEntityA = createTrackedEntity('A', ouA, createDefaultTrackedEntityType()); 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..19c0531ab57a 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,7 +140,7 @@ void setUp() { program.getProgramAttributes().add(pteaB); manager.update(program); - te = createTrackedEntity(orgUnit); + te = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); te.setTrackedEntityType(trackedEntityType); manager.save(te); 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..c3b08e17a39b 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,11 @@ public void setUp() { trackedEntityType = createTrackedEntityType('A'); dbmsManager.save(trackedEntityType); - origin = createTrackedEntity(orgUnit); + origin = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); origin.setTrackedEntityType(trackedEntityType); - duplicate1 = createTrackedEntity(orgUnit); + duplicate1 = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); duplicate1.setTrackedEntityType(trackedEntityType); - TrackedEntity duplicate2 = createTrackedEntity(orgUnit); + TrackedEntity duplicate2 = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); dbmsManager.save(origin); dbmsManager.save(duplicate1); @@ -97,7 +97,7 @@ public void setUp() { @Test void shouldPostPotentialDuplicateWhenTrackedEntitiesExist() throws Exception { - TrackedEntity trackedEntity = createTrackedEntity(orgUnit); + TrackedEntity trackedEntity = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); trackedEntity.setTrackedEntityType(trackedEntityType); dbmsManager.save(trackedEntity); PotentialDuplicate potentialDuplicate = 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..4aedd61e42b7 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 @@ -86,7 +86,8 @@ void setUp() { manager.save(prA); ProgramStage psA = createProgramStage('A', prA); manager.save(psA); - TrackedEntity trackedEntityA = createTrackedEntity('A', orgUnit); + TrackedEntity trackedEntityA = + createTrackedEntity('A', orgUnit, createDefaultTrackedEntityType()); 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..57a2de902052 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,7 +357,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) { private TrackedEntity trackedEntity( OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) { - TrackedEntity te = createTrackedEntity(orgUnit); + TrackedEntity te = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); te.setTrackedEntityType(trackedEntityType); te.getSharing().setPublicAccess(AccessStringHelper.DEFAULT); te.getSharing().setOwner(owner); diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentsExportControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentsExportControllerTest.java index 75299997d412..2f64988b8d6a 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentsExportControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentsExportControllerTest.java @@ -136,7 +136,7 @@ void setUp() { tea.getSharing().setOwner(owner); manager.save(tea, false); - te = createTrackedEntity(orgUnit); + te = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); te.setTrackedEntityType(trackedEntityType); manager.save(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 26ced75b8f8d..b5c3083f4c4f 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 @@ -300,7 +300,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) { private TrackedEntity trackedEntity( OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) { - TrackedEntity te = createTrackedEntity(orgUnit); + TrackedEntity te = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); te.setTrackedEntityType(trackedEntityType); te.getSharing().setPublicAccess(AccessStringHelper.DEFAULT); te.getSharing().setOwner(owner); 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..66d666bc8299 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,7 +838,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) { private TrackedEntity trackedEntity( OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) { - TrackedEntity result = createTrackedEntity(orgUnit); + TrackedEntity result = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); result.setTrackedEntityType(trackedEntityType); result.getSharing().setPublicAccess(AccessStringHelper.DEFAULT); result.getSharing().setOwner(owner); 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 b10ce8864dcd..b250b7f83536 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 @@ -861,7 +861,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) { private TrackedEntity trackedEntity( OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) { - TrackedEntity te = createTrackedEntity(orgUnit); + TrackedEntity te = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); te.setTrackedEntityType(trackedEntityType); te.getSharing().setPublicAccess(AccessStringHelper.DEFAULT); te.getSharing().setOwner(owner); 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 078ad8c972d4..e1cfc5d5da17 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 @@ -159,7 +159,7 @@ void setUp() { program.setTrackedEntityType(trackedEntityType); manager.save(program, false); - softDeletedTrackedEntity = createTrackedEntity(orgUnit); + softDeletedTrackedEntity = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); softDeletedTrackedEntity.setDeleted(true); manager.save(softDeletedTrackedEntity, false); } @@ -1068,7 +1068,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) { private TrackedEntity trackedEntity( OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) { - TrackedEntity te = createTrackedEntity(orgUnit); + TrackedEntity te = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); te.setTrackedEntityType(trackedEntityType); te.getSharing().setPublicAccess(AccessStringHelper.DEFAULT); te.getSharing().setOwner(owner); 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..012ef04dd6df 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,7 +270,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) { private TrackedEntity trackedEntity( OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) { - TrackedEntity te = createTrackedEntity(orgUnit); + TrackedEntity te = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); te.setTrackedEntityType(trackedEntityType); te.getSharing().setPublicAccess(AccessStringHelper.DEFAULT); te.getSharing().setOwner(user); 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..61826349d48b 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,7 +510,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) { private TrackedEntity trackedEntity( OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) { - TrackedEntity te = createTrackedEntity(orgUnit); + TrackedEntity te = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); te.setTrackedEntityType(trackedEntityType); te.getSharing().setPublicAccess(AccessStringHelper.DEFAULT); te.getSharing().setOwner(user); 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..8c028cca9ae3 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,7 +864,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) { private TrackedEntity trackedEntity( OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) { - TrackedEntity te = createTrackedEntity(orgUnit); + TrackedEntity te = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); te.setTrackedEntityType(trackedEntityType); te.getSharing().setPublicAccess(AccessStringHelper.DEFAULT); te.getSharing().setOwner(user1); 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..dc95c68fbbe2 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,7 +183,7 @@ void setUp() { program.getProgramAttributes().add(pteaB); manager.update(program); - trackedEntity = createTrackedEntity(orgUnit); + trackedEntity = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); trackedEntity.setTrackedEntityType(trackedEntityType); manager.save(trackedEntity); From 972f8d5d75137651f7ff65158b025a24046c8d08 Mon Sep 17 00:00:00 2001 From: zubaira Date: Sat, 16 Nov 2024 02:43:57 +0100 Subject: [PATCH 03/27] fix unit test --- .../test/java/org/hisp/dhis/copy/CopyServiceTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 71ddd65efc2e..ed4fb3e98c2e 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,8 @@ 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.trackedentity.TrackedEntityTypeService; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserDetails; import org.hisp.dhis.user.sharing.Sharing; @@ -112,6 +114,8 @@ class CopyServiceTest extends TestBase { @Mock private IdentifiableObjectManager identifiableObjectManager; + @Mock private TrackedEntityTypeService trackedEntityTypeService; + @InjectMocks private CopyService copyService; private static final String VALID_PROGRAM_UID = "abcdefghijk"; @@ -132,10 +136,11 @@ void setup() { void testCopyProgramFromUidWithValidProgram() throws NotFoundException, ForbiddenException { OrganisationUnit orgUnit = createOrganisationUnit("New Org 1"); + TrackedEntityType trackedEntityType = createTrackedEntityType('E'); + List originalEnrollments = List.of( - createEnrollment( - original, createTrackedEntity(orgUnit, createDefaultTrackedEntityType()), orgUnit)); + createEnrollment(original, createTrackedEntity(orgUnit, trackedEntityType), orgUnit)); when(programService.getProgram(VALID_PROGRAM_UID)).thenReturn(original); when(aclService.canWrite(UserDetails.fromUser(user), original)).thenReturn(true); From e642c355f3fd8cd0e9e45661fa62bb8502f1bf68 Mon Sep 17 00:00:00 2001 From: zubaira Date: Sat, 16 Nov 2024 03:27:55 +0100 Subject: [PATCH 04/27] fix unit test --- .../dhis/tracker/deduplication/DeduplicationHelperTest.java | 4 ++-- .../relationship/RelationshipOperationParamsMapperTest.java | 2 +- .../imports/preheat/supplier/UniqueAttributeSupplierTest.java | 2 +- .../tracker/imports/programrule/RuleEngineMapperTest.java | 2 +- .../validator/enrollment/DataRelationsValidatorTest.java | 2 +- .../validator/event/SecurityOwnershipValidatorTest.java | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) 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 754644817ca9..86325b154cad 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,14 +521,14 @@ private List getEnrollments() { } private TrackedEntity getTrackedEntityA() { - TrackedEntity te = createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); + TrackedEntity te = createTrackedEntity(organisationUnitA, createTrackedEntityType('I')); te.setTrackedEntityType(trackedEntityTypeA); return te; } private TrackedEntity getTrackedEntityB() { - TrackedEntity te = createTrackedEntity(organisationUnitB, createDefaultTrackedEntityType()); + TrackedEntity te = createTrackedEntity(organisationUnitB, createTrackedEntityType('F')); te.setTrackedEntityType(trackedEntityTypeB); return te; 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 e1449fc63d26..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, createDefaultTrackedEntityType()); + 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/UniqueAttributeSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributeSupplierTest.java index 5ccc52de3bb5..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, createDefaultTrackedEntityType()); + 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 11df2cf8c680..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 @@ -328,7 +328,7 @@ private Attribute attribute(TrackedEntityAttribute trackedEntityAttribute, Strin private TrackedEntity trackedEntity() { return createTrackedEntity( - 'I', organisationUnit, trackedEntityAttribute, createDefaultTrackedEntityType()); + '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 4be2210f1a94..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, createDefaultTrackedEntityType()); + 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/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 cc4f9c127887..72c6476bf6f7 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,7 @@ void verifySuccessEventValidationWhenEventHasNoOrgUnitAssigned() { private TrackedEntity teWithNoEnrollments() { TrackedEntity trackedEntity = - createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + createTrackedEntity(organisationUnit, createTrackedEntityType('E')); trackedEntity.setUid(TE_ID.getValue()); trackedEntity.setEnrollments(Sets.newHashSet()); trackedEntity.setTrackedEntityType(trackedEntityType); From 290ad52069ec7391b7d40905759452102b5de2c5 Mon Sep 17 00:00:00 2001 From: zubaira Date: Sat, 16 Nov 2024 03:40:10 +0100 Subject: [PATCH 05/27] fix unit test --- .../preheat/supplier/DuplicateRelationshipSupplierTest.java | 6 +++--- .../enrollment/SecurityOwnershipValidatorTest.java | 2 +- .../trackedentity/SecurityOwnershipValidatorTest.java | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) 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 9a253dd806c0..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, createDefaultTrackedEntityType()); + teA = createTrackedEntity(organisationUnit, createTrackedEntityType('D')); teA.setUid(TE_A_UID.getValue()); - teB = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + teB = createTrackedEntity(organisationUnit, createTrackedEntityType('E')); teB.setUid(TE_B_UID.getValue()); - teC = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + 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/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 42565e811623..1b3027ca0ab0 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,7 +390,7 @@ void verifyValidationFailsForEnrollmentDeletionAndUserWithoutTrackedEntityTypeRe private TrackedEntity teWithNoEnrollments() { TrackedEntity trackedEntity = - createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + createTrackedEntity(organisationUnit, createTrackedEntityType('C')); 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 a59209d86711..e89a0872a692 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,7 @@ void shouldFailWhenUpdateTEAndUserHasNoWriteAccess() { private TrackedEntity teWithNoEnrollments() { TrackedEntity trackedEntity = - createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + createTrackedEntity(organisationUnit, createTrackedEntityType('Z')); trackedEntity.setUid(TE_ID.getValue()); trackedEntity.setEnrollments(Sets.newHashSet()); trackedEntity.setTrackedEntityType(trackedEntityType); @@ -313,7 +313,7 @@ private TrackedEntity teWithDeleteEnrollments() { enrollment.setDeleted(true); TrackedEntity trackedEntity = - createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + createTrackedEntity(organisationUnit, createTrackedEntityType('B')); trackedEntity.setUid(TE_ID.getValue()); trackedEntity.setEnrollments(Sets.newHashSet(enrollment)); trackedEntity.setTrackedEntityType(trackedEntityType); @@ -323,7 +323,7 @@ private TrackedEntity teWithDeleteEnrollments() { private TrackedEntity teWithEnrollments() { TrackedEntity trackedEntity = - createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + createTrackedEntity(organisationUnit, createTrackedEntityType('R')); trackedEntity.setUid(TE_ID.getValue()); trackedEntity.setEnrollments(Sets.newHashSet(new Enrollment())); trackedEntity.setTrackedEntityType(trackedEntityType); From bee41047a999af15d3db74ea78146fd25cb543ec Mon Sep 17 00:00:00 2001 From: zubaira Date: Sat, 16 Nov 2024 04:02:57 +0100 Subject: [PATCH 06/27] remove unused dependency --- .../src/test/java/org/hisp/dhis/copy/CopyServiceTest.java | 3 --- 1 file changed, 3 deletions(-) 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 ed4fb3e98c2e..b340f054bfd5 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 @@ -79,7 +79,6 @@ import org.hisp.dhis.security.acl.AclService; import org.hisp.dhis.test.TestBase; import org.hisp.dhis.trackedentity.TrackedEntityType; -import org.hisp.dhis.trackedentity.TrackedEntityTypeService; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserDetails; import org.hisp.dhis.user.sharing.Sharing; @@ -114,8 +113,6 @@ class CopyServiceTest extends TestBase { @Mock private IdentifiableObjectManager identifiableObjectManager; - @Mock private TrackedEntityTypeService trackedEntityTypeService; - @InjectMocks private CopyService copyService; private static final String VALID_PROGRAM_UID = "abcdefghijk"; From 900f3d73ef1fe7933ad1cba5fa726474a7a92818 Mon Sep 17 00:00:00 2001 From: zubaira Date: Sat, 16 Nov 2024 05:30:17 +0100 Subject: [PATCH 07/27] fix integration test --- .../java/org/hisp/dhis/test/TestBase.java | 14 ------- .../event/data/EventAnalyticsServiceTest.java | 3 +- .../hisp/dhis/audit/AuditIntegrationTest.java | 14 +++++-- .../dhis/maintenance/HardDeleteAuditTest.java | 6 ++- .../maintenance/MaintenanceServiceTest.java | 9 ++--- .../DataElementMergeServiceTest.java | 23 ++++++++--- .../TrackerOrgUnitMergeHandlerTest.java | 10 +++-- ...rogramNotificationMessageRendererTest.java | 5 ++- .../predictor/EventPredictionServiceTest.java | 5 ++- .../EventProgramEnrollmentServiceTest.java | 6 ++- .../program/ProgramExpressionServiceTest.java | 7 +++- .../program/ProgramIndicatorServiceTest.java | 7 +++- .../dhis/program/ProgramMessageStoreTest.java | 7 +++- .../ProgramNotificationServiceTest.java | 18 +++++---- .../RelationshipDeletionHandlerTest.java | 8 ++-- .../HibernateReservedValueStoreTest.java | 19 +++++++-- ...ckedEntityDataValueChangeLogStoreTest.java | 5 ++- .../TrackedEntityProgramOwnerServiceTest.java | 6 ++- .../TrackedEntityServiceTest.java | 14 +++---- .../TrackerAccessManagerTest.java | 11 +++-- .../TrackerOwnershipManagerTest.java | 6 +-- ...uplicationServiceMergeIntegrationTest.java | 12 ++---- ...ntialDuplicateRemoveTrackedEntityTest.java | 27 ++++++++----- ...tentialDuplicateStoreRelationshipTest.java | 12 ++++-- .../PotentialDuplicateStoreTEAVTest.java | 10 +++-- .../enrollment/EnrollmentServiceTest.java | 16 +++----- .../relationship/RelationshipServiceTest.java | 40 ++++++------------- .../TrackedEntityAuditServiceTest.java | 6 +-- .../TrackedEntityServiceTest.java | 19 +++------ ...TrackerNotificationHandlerServiceTest.java | 3 +- ...nrollmentSecurityImportValidationTest.java | 17 +++----- .../EventSecurityImportValidationTest.java | 13 +++--- ...rackedEntityAttributeValueServiceTest.java | 12 ++++-- .../TrackedEntityAttributeValueStoreTest.java | 12 ++++-- .../AnalyticsValidationServiceTest.java | 5 ++- 35 files changed, 215 insertions(+), 192 deletions(-) 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 0ad12e149594..26b59f94e173 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 @@ -191,7 +191,6 @@ import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.trackedentity.TrackedEntityType; import org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute; -import org.hisp.dhis.trackedentity.TrackedEntityTypeService; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; import org.hisp.dhis.trackedentityfilter.EntityQueryCriteria; import org.hisp.dhis.trackedentityfilter.TrackedEntityFilter; @@ -287,18 +286,13 @@ public abstract class TestBase { @Autowired(required = false) protected CategoryService internalCategoryService; - @Autowired private TrackedEntityTypeService trackedEntityTypeService; - @Autowired protected HibernateService hibernateService; protected static CategoryService categoryService; - protected static TrackedEntityTypeService entityTypeService; - @PostConstruct protected void initServices() { categoryService = internalCategoryService; - entityTypeService = trackedEntityTypeService; } static { @@ -2187,14 +2181,6 @@ public static TrackedEntity createTrackedEntity( return trackedEntity; } - public static TrackedEntityType createDefaultTrackedEntityType() { - TrackedEntityType trackedEntityType = new TrackedEntityType(); - trackedEntityType.setAutoFields(); - trackedEntityType.setName("TrackedEntityType" + CodeGenerator.generateCode(2)); - entityTypeService.addTrackedEntityType(trackedEntityType); - return trackedEntityType; - } - public static TrackedEntityAttributeValue createTrackedEntityAttributeValue( char uniqueChar, TrackedEntity trackedEntity, TrackedEntityAttribute attribute) { TrackedEntityAttributeValue attributeValue = new TrackedEntityAttributeValue(); 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 6c2bb9ca3f10..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, createDefaultTrackedEntityType()); + 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 e15dfc6869a0..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,8 +109,10 @@ void testSaveTrackedEntity() { TrackedEntityAttribute attribute = createTrackedEntityAttribute('A'); manager.save(ou); manager.save(attribute); - TrackedEntity trackedEntity = - createTrackedEntity('A', ou, attribute, createDefaultTrackedEntityType()); + + 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); @@ -128,8 +131,11 @@ void testSaveTrackedAttributeValue() { TrackedEntityAttribute attribute = createTrackedEntityAttribute('A'); manager.save(ou); manager.save(attribute); - TrackedEntity trackedEntity = - createTrackedEntity('A', ou, attribute, createDefaultTrackedEntityType()); + + 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 48f0dd8333ae..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,8 +71,9 @@ class HardDeleteAuditTest extends PostgresIntegrationTestBase { void testHardDeleteTrackedEntity() { OrganisationUnit ou = createOrganisationUnit('A'); TrackedEntityAttribute attribute = createTrackedEntityAttribute('A'); - TrackedEntity trackedEntity = - createTrackedEntity('A', ou, attribute, createDefaultTrackedEntityType()); + 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 dd5b51752e61..2dc866083328 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,14 +164,11 @@ void setUp() { programService.updateProgram(program); TrackedEntityType trackedEntityType = createTrackedEntityType('A'); trackedEntityTypeService.addTrackedEntityType(trackedEntityType); - trackedEntity = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); - trackedEntity.setTrackedEntityType(trackedEntityType); + trackedEntity = createTrackedEntity(organisationUnit, trackedEntityType); manager.save(trackedEntity); - trackedEntityB = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); - trackedEntityB.setTrackedEntityType(trackedEntityType); + trackedEntityB = createTrackedEntity(organisationUnit, trackedEntityType); manager.save(trackedEntityB); - trackedEntityWithAssociations = - createTrackedEntity('T', organisationUnit, createDefaultTrackedEntityType()); + 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/dataelement/DataElementMergeServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/dataelement/DataElementMergeServiceTest.java index 2a94dfc9e978..e8841f7db5b2 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 @@ -112,6 +112,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.event.EventChangeLogService; import org.hisp.dhis.tracker.export.event.TrackedEntityDataValueChangeLog; import org.hisp.dhis.tracker.export.event.TrackedEntityDataValueChangeLogQueryParams; @@ -1267,7 +1268,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, createDefaultTrackedEntityType()); + TrackedEntityType trackedEntityType = createTrackedEntityType('O'); + identifiableObjectManager.save(trackedEntityType); + TrackedEntity trackedEntity = createTrackedEntity(ou1, trackedEntityType); identifiableObjectManager.save(trackedEntity); Enrollment enrollment = createEnrollment(program, trackedEntity, ou1); identifiableObjectManager.save(enrollment); @@ -1352,7 +1355,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, createDefaultTrackedEntityType()); + + TrackedEntityType trackedEntityType = createTrackedEntityType('O'); + identifiableObjectManager.save(trackedEntityType); + TrackedEntity trackedEntity = createTrackedEntity(ou1, trackedEntityType); identifiableObjectManager.save(trackedEntity); Enrollment enrollment = createEnrollment(program, trackedEntity, ou1); identifiableObjectManager.save(enrollment); @@ -1445,7 +1451,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, createDefaultTrackedEntityType()); + + TrackedEntityType trackedEntityType = createTrackedEntityType('O'); + identifiableObjectManager.save(trackedEntityType); + TrackedEntity trackedEntity = createTrackedEntity(ou1, trackedEntityType); identifiableObjectManager.save(trackedEntity); Enrollment enrollment = createEnrollment(program, trackedEntity, ou1); identifiableObjectManager.save(enrollment); @@ -2549,7 +2558,9 @@ void dataValueAuditMergeDeleteTest() throws ConflictException { "TrackedEntityDataValueChangeLog with references to source DataElements are not changed or deleted when sources not deleted") void trackedEntityDataValueChangeLogMergeTest() throws ConflictException { // given - TrackedEntity trackedEntity = createTrackedEntity(ou1, createDefaultTrackedEntityType()); + TrackedEntityType trackedEntityType = createTrackedEntityType('O'); + identifiableObjectManager.save(trackedEntityType); + TrackedEntity trackedEntity = createTrackedEntity(ou1, trackedEntityType); identifiableObjectManager.save(trackedEntity); Enrollment enrollment = createEnrollment(program, trackedEntity, ou1); identifiableObjectManager.save(enrollment); @@ -2602,7 +2613,9 @@ void trackedEntityDataValueChangeLogMergeTest() throws ConflictException { "TrackedEntityDataValueChangeLog with references to source DataElements are deleted when sources are deleted") void trackedEntityDataValueChangeLogMergeDeletedTest() throws ConflictException { // given - TrackedEntity trackedEntity = createTrackedEntity(ou1, createDefaultTrackedEntityType()); + 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 11ccf932e004..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, createDefaultTrackedEntityType()); - trackedEntityB = createTrackedEntity('B', ouB, createDefaultTrackedEntityType()); - trackedEntityC = createTrackedEntity('C', ouC, createDefaultTrackedEntityType()); + + 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 26d6d1736df5..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, createDefaultTrackedEntityType()); + 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 9cd4c0b6f105..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,8 +217,10 @@ void setUp() { entityAttribute.setAggregationType(AggregationType.COUNT); entityAttribute.setUid(TRACKED_ENTITY_ATTRIBUTE_UID); entityAttributeService.addTrackedEntityAttribute(entityAttribute); + TrackedEntityType trackedEntityType = createTrackedEntityType('O'); + manager.save(trackedEntityType); TrackedEntity trackedEntity = - createTrackedEntity('A', orgUnitA, entityAttribute, createDefaultTrackedEntityType()); + 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 7917fe99c5f9..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,8 +78,9 @@ void setUp() { OrganisationUnit organisationUnitB = createOrganisationUnit('B'); manager.save(organisationUnitB); - TrackedEntity trackedEntity = - createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); + 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 f9850b31d64b..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,8 +100,10 @@ void setUp() { dataElementB = createDataElement('B'); dataElementService.addDataElement(dataElementA); dataElementService.addDataElement(dataElementB); - TrackedEntity trackedEntity = - createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + + 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 29c1152f44c4..34bdc70d6aee 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,8 +228,10 @@ void setUp() { // --------------------------------------------------------------------- // TrackedEntity // --------------------------------------------------------------------- - TrackedEntity trackedEntity = - createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + 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 094962283764..695ebc2a8d56 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, createDefaultTrackedEntityType()); + TrackedEntityType trackedEntityType = createTrackedEntityType('O'); + manager.save(trackedEntityType); + TrackedEntity trackedEntityB = createTrackedEntity(orgUnitA, trackedEntityType); manager.save(trackedEntityB); enrollmentA = new Enrollment(new Date(), new Date(), trackedEntityB, programA); @@ -116,7 +119,7 @@ void setUp() { eventA.setScheduledDate(new Date()); eventA.setUid(CodeGenerator.generateUid()); - TrackedEntity trackedEntityA = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); + 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 d3c5babbc4ad..95a95de6d80b 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,11 +118,11 @@ void setUp() { OrganisationUnit organisationUnitB = createOrganisationUnit('B'); manager.save(organisationUnitA); manager.save(organisationUnitB); - TrackedEntity trackedEntityA = - createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); + TrackedEntityType trackedEntityType = createTrackedEntityType('O'); + manager.save(trackedEntityType); + TrackedEntity trackedEntityA = createTrackedEntity(organisationUnitA, trackedEntityType); manager.save(trackedEntityA); - TrackedEntity trackedEntityB = - createTrackedEntity(organisationUnitB, createDefaultTrackedEntityType()); + TrackedEntity trackedEntityB = createTrackedEntity(organisationUnitB, trackedEntityType); manager.save(trackedEntityB); programA = createProgram('A', new HashSet<>(), organisationUnitA); programService.addProgram(programA); @@ -398,10 +399,11 @@ void testGetEnrollmentsWithScheduledNotifications() { programNotificationStore.save(a2); programNotificationStore.save(a3); // TE - TrackedEntity trackedEntityX = - createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); - TrackedEntity trackedEntityY = - createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); + + TrackedEntityType trackedEntityType = createTrackedEntityType('O'); + 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 2d3fef8eee9f..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,10 +59,11 @@ public void setUp() { manager.save(deletableRelationshipType); OrganisationUnit orgUnit = createOrganisationUnit('A'); manager.save(orgUnit); - TrackedEntity trackedEntityFrom = - createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); + TrackedEntityType trackedEntityType = createTrackedEntityType('O'); + manager.save(trackedEntityType); + TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnit, trackedEntityType); manager.save(trackedEntityFrom); - TrackedEntity trackedEntityTo = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); + 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 765dfb8de122..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, createDefaultTrackedEntityType()); + + 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, createDefaultTrackedEntityType()); + 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, createDefaultTrackedEntityType()); + + 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, createDefaultTrackedEntityType()); + 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/TrackedEntityDataValueChangeLogStoreTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueChangeLogStoreTest.java index c6a1661df78e..0e774bd6c55c 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueChangeLogStoreTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueChangeLogStoreTest.java @@ -158,8 +158,9 @@ void setUp() { deB = createDataElement('B'); dataElementService.addDataElement(deA); dataElementService.addDataElement(deB); - - TrackedEntity teA = createTrackedEntity(ouA, createDefaultTrackedEntityType()); + TrackedEntityType trackedEntityType = createTrackedEntityType('O'); + manager.save(trackedEntityType); + TrackedEntity teA = createTrackedEntity(ouA, trackedEntityType); manager.save(teA); Enrollment enrollment = createEnrollment(pA, teA, ouA); 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 6ae4661374fa..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, createDefaultTrackedEntityType()); + TrackedEntityType trackedEntityType = createTrackedEntityType('O'); + manager.save(trackedEntityType); + trackedEntityA1 = createTrackedEntity(organisationUnitA, trackedEntityType); trackedEntityA1.setUid(TE_A1); - trackedEntityB1 = createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); + 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 f6596cc60b87..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,13 +85,13 @@ void setUp() { OrganisationUnit organisationUnitB = createOrganisationUnit('B'); organisationUnitService.addOrganisationUnit(organisationUnitB); attributeService.addTrackedEntityAttribute(createTrackedEntityAttribute('A')); - trackedEntityA1 = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); - TrackedEntity trackedEntityB1 = - createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); - TrackedEntity trackedEntityC1 = - createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); - TrackedEntity trackedEntityD1 = - createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + + 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 3012bf60fc06..b43a2124d6a6 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 @@ -155,12 +155,11 @@ void setUp() { manager.update(programStageA); manager.update(programStageB); manager.update(programA); - trackedEntityA = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - TrackedEntity trackedEntityB = createTrackedEntity(orgUnitB, createDefaultTrackedEntityType()); - TrackedEntity femaleA = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - TrackedEntity femaleB = createTrackedEntity(orgUnitB, createDefaultTrackedEntityType()); - trackedEntityA.setTrackedEntityType(trackedEntityType); - trackedEntityB.setTrackedEntityType(trackedEntityType); + trackedEntityA = createTrackedEntity(orgUnitA, trackedEntityType); + TrackedEntity trackedEntityB = createTrackedEntity(orgUnitB, trackedEntityType); + TrackedEntity femaleA = createTrackedEntity(orgUnitA, trackedEntityType); + TrackedEntity femaleB = createTrackedEntity(orgUnitB, trackedEntityType); + femaleA.setTrackedEntityType(trackedEntityType); femaleB.setTrackedEntityType(trackedEntityType); manager.save(trackedEntityA); 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 ee9a144e3010..48c86ff5b133 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 @@ -116,10 +116,8 @@ void setUp() { trackedEntityType.setSharing(Sharing.builder().publicAccess(AccessStringHelper.FULL).build()); trackedEntityTypeService.updateTrackedEntityType(trackedEntityType); - trackedEntityA1 = createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); - trackedEntityA1.setTrackedEntityType(trackedEntityType); - trackedEntityB1 = createTrackedEntity(organisationUnitB, createDefaultTrackedEntityType()); - 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 d5c874b8ee43..ec4ff1f4e1be 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 @@ -84,10 +84,8 @@ void shouldManualMergeWithAuthorityAll() TrackedEntityType trackedEntityType = createTrackedEntityType('A'); trackedEntityTypeService.addTrackedEntityType(trackedEntityType); - TrackedEntity original = createTrackedEntity(ou, createDefaultTrackedEntityType()); - TrackedEntity duplicate = createTrackedEntity(ou, createDefaultTrackedEntityType()); - original.setTrackedEntityType(trackedEntityType); - duplicate.setTrackedEntityType(trackedEntityType); + TrackedEntity original = createTrackedEntity(ou, trackedEntityType); + TrackedEntity duplicate = createTrackedEntity(ou, trackedEntityType); manager.save(original); manager.save(duplicate); Program program = createProgram('A'); @@ -139,10 +137,8 @@ void shouldManualMergeWithUserGroupOfProgram() trackedEntityTypeService.addTrackedEntityType(trackedEntityType); trackedEntityType.setSharing(sharing); trackedEntityTypeService.updateTrackedEntityType(trackedEntityType); - TrackedEntity original = createTrackedEntity(ou, createDefaultTrackedEntityType()); - TrackedEntity duplicate = createTrackedEntity(ou, createDefaultTrackedEntityType()); - original.setTrackedEntityType(trackedEntityType); - duplicate.setTrackedEntityType(trackedEntityType); + TrackedEntity original = createTrackedEntity(ou, trackedEntityType); + TrackedEntity duplicate = createTrackedEntity(ou, trackedEntityType); manager.save(original); manager.save(duplicate); Program 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 e989748b91c6..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, createDefaultTrackedEntityType()); - TrackedEntity duplicate = createTrackedEntity(ou, createDefaultTrackedEntityType()); - TrackedEntity control1 = createTrackedEntity(ou, createDefaultTrackedEntityType()); - TrackedEntity control2 = createTrackedEntity(ou, createDefaultTrackedEntityType()); + 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, createDefaultTrackedEntityType()); - TrackedEntity duplicate = createTrackedEntity(ou, createDefaultTrackedEntityType()); - TrackedEntity control1 = createTrackedEntity(ou, createDefaultTrackedEntityType()); - TrackedEntity control2 = createTrackedEntity(ou, createDefaultTrackedEntityType()); + + 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,8 +193,11 @@ void shouldDeleteEnrollments() throws ForbiddenException, NotFoundException { private TrackedEntity createTrackedEntity(TrackedEntityAttribute trackedEntityAttribute) { OrganisationUnit ou = createOrganisationUnit("OU_A"); organisationUnitService.addOrganisationUnit(ou); + + TrackedEntityType trackedEntityType = createTrackedEntityType('R'); + manager.save(trackedEntityType); TrackedEntity trackedEntity = - createTrackedEntity('T', ou, trackedEntityAttribute, createDefaultTrackedEntityType()); + 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 0b6dec890926..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, createDefaultTrackedEntityType()); - duplicate = createTrackedEntity(ou, createDefaultTrackedEntityType()); - extra1 = createTrackedEntity(ou, createDefaultTrackedEntityType()); - extra2 = createTrackedEntity(ou, createDefaultTrackedEntityType()); + + 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 5e7c7604bdf9..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, createDefaultTrackedEntityType()); - duplicate = createTrackedEntity(ou, createDefaultTrackedEntityType()); - control = createTrackedEntity(ou, createDefaultTrackedEntityType()); + + 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 fa6222a75805..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,26 +158,20 @@ void setUp() { trackedEntityTypeA.getSharing().setOwner(user); manager.save(trackedEntityTypeA, false); - trackedEntityA = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - trackedEntityA.setTrackedEntityType(trackedEntityTypeA); + trackedEntityA = createTrackedEntity(orgUnitA, trackedEntityTypeA); manager.save(trackedEntityA, false); - TrackedEntity trackedEntityB = createTrackedEntity(orgUnitB, createDefaultTrackedEntityType()); - trackedEntityB.setTrackedEntityType(trackedEntityTypeA); + TrackedEntity trackedEntityB = createTrackedEntity(orgUnitB, trackedEntityTypeA); manager.save(trackedEntityB, false); - TrackedEntity trackedEntityC = createTrackedEntity(orgUnitC, createDefaultTrackedEntityType()); - trackedEntityC.setTrackedEntityType(trackedEntityTypeA); + TrackedEntity trackedEntityC = createTrackedEntity(orgUnitC, trackedEntityTypeA); manager.save(trackedEntityC, false); - TrackedEntity trackedEntityChildA = - createTrackedEntity(orgUnitChildA, createDefaultTrackedEntityType()); - trackedEntityChildA.setTrackedEntityType(trackedEntityTypeA); + TrackedEntity trackedEntityChildA = createTrackedEntity(orgUnitChildA, trackedEntityTypeA); manager.save(trackedEntityChildA, false); TrackedEntity trackedEntityGrandchildA = - createTrackedEntity(orgUnitGrandchildA, createDefaultTrackedEntityType()); - trackedEntityGrandchildA.setTrackedEntityType(trackedEntityTypeA); + 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 046963caf521..ad7018fb4b35 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 @@ -136,16 +136,13 @@ void setUp() { inaccessibleTrackedEntityType.getSharing().setPublicAccess(AccessStringHelper.DEFAULT); manager.save(inaccessibleTrackedEntityType, false); - teA = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - teA.setTrackedEntityType(trackedEntityType); + teA = createTrackedEntity(orgUnitA, trackedEntityType); manager.save(teA, false); - teB = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - teB.setTrackedEntityType(trackedEntityType); + teB = createTrackedEntity(orgUnitA, trackedEntityType); manager.save(teB, false); - inaccessibleTe = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - inaccessibleTe.setTrackedEntityType(inaccessibleTrackedEntityType); + inaccessibleTe = createTrackedEntity(orgUnitA, inaccessibleTrackedEntityType); manager.save(inaccessibleTe, false); program = createProgram('A', new HashSet<>(), orgUnitA); @@ -295,9 +292,7 @@ void shouldNotReturnRelationshipWhenTeIsTransferredAndUserHasNoAccessToAtLeastOn program.setOrganisationUnits(Set.of(orgUnitA, orgUnitB)); manager.save(program, false); - TrackedEntity trackedEntityFrom = - createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - trackedEntityFrom.setTrackedEntityType(trackedEntityType); + TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA, trackedEntityType); manager.save(trackedEntityFrom); manager.save(createEnrollment(program, trackedEntityFrom, orgUnitA)); @@ -307,8 +302,7 @@ void shouldNotReturnRelationshipWhenTeIsTransferredAndUserHasNoAccessToAtLeastOn trackerOwnershipAccessManager.transferOwnership(trackedEntityFrom, program, orgUnitB); - TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - trackedEntityTo.setTrackedEntityType(trackedEntityType); + TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA, trackedEntityType); manager.save(trackedEntityTo); relationship(trackedEntityFrom, trackedEntityTo); @@ -332,20 +326,16 @@ void shouldExcludeRelationshipWhenProgramIsProtectedAndUserHasNoAccess() throws ForbiddenException, NotFoundException, BadRequestException { injectAdminIntoSecurityContext(); - TrackedEntity trackedEntityFrom = - createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - trackedEntityFrom.setTrackedEntityType(trackedEntityType); + TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA, trackedEntityType); manager.save(trackedEntityFrom); - TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - 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, createDefaultTrackedEntityType()); - notAccessibleTe.setTrackedEntityType(trackedEntityType); + TrackedEntity notAccessibleTe = createTrackedEntity(orgUnitB, trackedEntityType); manager.save(notAccessibleTe); injectSecurityContextUser(user); @@ -381,13 +371,10 @@ void shouldNotReturnRelationshipWhenUserHasNoMetadataAccessToProgram() { program.setProgramStages(Set.of(programStage)); manager.save(program, false); - TrackedEntity trackedEntityFrom = - createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - trackedEntityFrom.setTrackedEntityType(trackedEntityType); + TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA, trackedEntityType); manager.save(trackedEntityFrom); - TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - trackedEntityTo.setTrackedEntityType(trackedEntityType); + TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA, trackedEntityType); manager.save(trackedEntityTo); relationship(trackedEntityFrom, trackedEntityTo); @@ -421,13 +408,10 @@ void shouldNotReturnRelationshipWhenUserHasNoDataReadAccessToProgram() { program.setProgramStages(Set.of(programStage)); manager.save(program, false); - TrackedEntity trackedEntityFrom = - createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - trackedEntityFrom.setTrackedEntityType(trackedEntityType); + TrackedEntity trackedEntityFrom = createTrackedEntity(orgUnitA, trackedEntityType); manager.save(trackedEntityFrom); - TrackedEntity trackedEntityTo = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - 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/TrackedEntityAuditServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAuditServiceTest.java index a10618309573..1677424673d4 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAuditServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAuditServiceTest.java @@ -112,8 +112,7 @@ void setUp() { trackedEntityType = createTrackedEntityType('A'); manager.save(trackedEntityType, false); - trackedEntity = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - trackedEntity.setTrackedEntityType(trackedEntityType); + trackedEntity = createTrackedEntity(orgUnitA, trackedEntityType); manager.save(trackedEntity, false); trackedEntityAttribute = createTrackedEntityAttribute('A'); @@ -177,8 +176,7 @@ void shouldFailWhenUserHasNoAccessToAnyTETA() { void shouldFailWhenUserHasNoAccessToOrgUnitScope() { OrganisationUnit outOfScopeOrgUnit = createOrganisationUnit("out of scope org unit"); manager.save(outOfScopeOrgUnit, false); - trackedEntity = createTrackedEntity(outOfScopeOrgUnit, createDefaultTrackedEntityType()); - trackedEntity.setTrackedEntityType(trackedEntityType); + trackedEntity = createTrackedEntity(outOfScopeOrgUnit, trackedEntityType); manager.save(trackedEntity, false); injectSecurityContextUser(user); 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 1095dbd57b01..94590e569c1e 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 @@ -327,8 +327,7 @@ void setUp() { trackedEntityAttributeValueB = new TrackedEntityAttributeValue(teaB, trackedEntityA, "B"); trackedEntityAttributeValueC = new TrackedEntityAttributeValue(teaC, trackedEntityA, "C"); - trackedEntityA = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - trackedEntityA.setTrackedEntityType(trackedEntityTypeA); + trackedEntityA = createTrackedEntity(orgUnitA, trackedEntityTypeA); trackedEntityA.setTrackedEntityAttributeValues( Set.of( trackedEntityAttributeValueA, @@ -336,13 +335,10 @@ void setUp() { trackedEntityAttributeValueC)); manager.save(trackedEntityA, false); - trackedEntityChildA = createTrackedEntity(orgUnitChildA, createDefaultTrackedEntityType()); - trackedEntityChildA.setTrackedEntityType(trackedEntityTypeA); + trackedEntityChildA = createTrackedEntity(orgUnitChildA, trackedEntityTypeA); manager.save(trackedEntityChildA, false); - trackedEntityGrandchildA = - createTrackedEntity(orgUnitGrandchildA, createDefaultTrackedEntityType()); - trackedEntityGrandchildA.setTrackedEntityType(trackedEntityTypeA); + trackedEntityGrandchildA = createTrackedEntity(orgUnitGrandchildA, trackedEntityTypeA); manager.save(trackedEntityGrandchildA, false); enrollmentA = createEnrollment(programA, trackedEntityA, orgUnitA); @@ -384,8 +380,7 @@ void setUp() { enrollmentB.setEvents(Set.of(eventB)); manager.save(enrollmentB, false); - trackedEntityB = createTrackedEntity(orgUnitB, createDefaultTrackedEntityType()); - trackedEntityB.setTrackedEntityType(trackedEntityTypeA); + trackedEntityB = createTrackedEntity(orgUnitB, trackedEntityTypeA); manager.save(trackedEntityB, false); Enrollment enrollmentC = createEnrollment(programB, trackedEntityB, orgUnitB); @@ -402,8 +397,7 @@ void setUp() { enrollmentC.setEvents(Set.of(eventC)); manager.save(enrollmentC, false); - TrackedEntity trackedEntityC = createTrackedEntity(orgUnitC, createDefaultTrackedEntityType()); - trackedEntityC.setTrackedEntityType(trackedEntityTypeA); + TrackedEntity trackedEntityC = createTrackedEntity(orgUnitC, trackedEntityTypeA); manager.save(trackedEntityC, false); trackerOwnershipManager.assignOwnership(trackedEntityA, programA, orgUnitA, true, true); @@ -1854,8 +1848,7 @@ void shouldFailWhenRequestingSingleTEAndTETNotAccessible() { TrackedEntityType inaccessibleTrackedEntityType = createTrackedEntityType('U'); inaccessibleTrackedEntityType.setSharing(Sharing.builder().publicAccess("rw------").build()); manager.save(inaccessibleTrackedEntityType, false); - TrackedEntity trackedEntity = createTrackedEntity(orgUnitA, createDefaultTrackedEntityType()); - 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 1109b0630157..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, createDefaultTrackedEntityType()); - 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 507c77870e06..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, createDefaultTrackedEntityType()); - maleB = createTrackedEntity(organisationUnitB, createDefaultTrackedEntityType()); - femaleA = createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); - femaleB = createTrackedEntity(organisationUnitB, createDefaultTrackedEntityType()); - 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,9 +349,7 @@ private Program createProgram(OrganisationUnit orgUnit) { private TrackedEntity createTrackedEntity( TrackedEntityType trackedEntityType, OrganisationUnit orgUnit) { - TrackedEntity trackedEntity = - createTrackedEntity('T', orgUnit, createDefaultTrackedEntityType()); - 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 759f2e443510..73e0c946c39e 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 @@ -178,14 +178,11 @@ void setUp() throws IOException { manager.update(programStageA); manager.update(programStageB); manager.update(programA); - maleA = createTrackedEntity('A', organisationUnitA, createDefaultTrackedEntityType()); - maleB = createTrackedEntity(organisationUnitB, createDefaultTrackedEntityType()); - femaleA = createTrackedEntity(organisationUnitA, createDefaultTrackedEntityType()); - femaleB = createTrackedEntity(organisationUnitB, createDefaultTrackedEntityType()); - 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 3431e52abcd8..c2977e4c2670 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, createDefaultTrackedEntityType()); - trackedEntityB = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); - trackedEntityC = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); - trackedEntityD = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + + 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/tracker/trackedentityattributevalue/TrackedEntityAttributeValueStoreTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/trackedentityattributevalue/TrackedEntityAttributeValueStoreTest.java index e2495104b1ac..c15a65eb7bf9 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/trackedentityattributevalue/TrackedEntityAttributeValueStoreTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/trackedentityattributevalue/TrackedEntityAttributeValueStoreTest.java @@ -42,6 +42,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.export.trackedentity.TrackedEntityAttributeValueChangeLog; import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityAttributeValueChangeLogQueryParams; @@ -100,10 +101,13 @@ class TrackedEntityAttributeValueStoreTest extends PostgresIntegrationTestBase { void setUp() { OrganisationUnit organisationUnit = createOrganisationUnit('A'); organisationUnitService.addOrganisationUnit(organisationUnit); - trackedEntityA = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); - trackedEntityB = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); - trackedEntityC = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); - trackedEntityD = createTrackedEntity(organisationUnit, createDefaultTrackedEntityType()); + + 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 945aae2757f9..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,8 +193,10 @@ void setUp() { entityAttribute.setAggregationType(AggregationType.COUNT); entityAttribute.setUid(TRACKED_ENTITY_ATTRIBUTE_UID); entityAttributeService.addTrackedEntityAttribute(entityAttribute); + TrackedEntityType trackedEntityType = createTrackedEntityType('O'); + manager.save(trackedEntityType); TrackedEntity trackedEntity = - createTrackedEntity('A', orgUnitA, entityAttribute, createDefaultTrackedEntityType()); + createTrackedEntity('A', orgUnitA, entityAttribute, trackedEntityType); manager.save(trackedEntity); TrackedEntityAttributeValue trackedEntityAttributeValue = new TrackedEntityAttributeValue(entityAttribute, trackedEntity); From 62ef7d6eb7e75da02f2d9c986ff1a64e7681f99e Mon Sep 17 00:00:00 2001 From: zubaira Date: Sat, 16 Nov 2024 15:28:58 +0100 Subject: [PATCH 08/27] fix controller tests --- .../webapi/controller/ChangeLogControllerTest.java | 6 ++---- .../controller/ProgramMessageControllerTest.java | 5 ++++- .../TrackedEntityAttributeControllerTest.java | 3 +-- .../deduplication/DeduplicationControllerTest.java | 11 ++++------- .../ProgramNotificationInstanceControllerTest.java | 6 ++++-- .../export/ExportControllerPaginationTest.java | 3 +-- .../enrollment/EnrollmentsExportControllerTest.java | 3 +-- .../event/EventsExportChangeLogsControllerTest.java | 3 +-- .../export/event/EventsExportControllerTest.java | 3 +-- .../RelationshipsExportControllerTest.java | 3 +-- .../TrackedEntitiesExportControllerTest.java | 5 ++--- .../imports/TrackerCreateRelationshipSMSTest.java | 3 +-- .../tracker/imports/TrackerEnrollmentSMSTest.java | 3 +-- .../tracker/imports/TrackerEventSMSTest.java | 3 +-- .../trigramsummary/TrigramSummaryControllerTest.java | 3 +-- 15 files changed, 26 insertions(+), 37 deletions(-) diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ChangeLogControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ChangeLogControllerTest.java index 5e69d8b8d87c..fb44c223d355 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ChangeLogControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ChangeLogControllerTest.java @@ -117,14 +117,12 @@ void setUp() { trackedEntityType = trackedEntityTypeAccessible(); - te1 = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); - te1.setTrackedEntityType(trackedEntityType); + te1 = createTrackedEntity(orgUnit, trackedEntityType); te1.getSharing().setPublicAccess(AccessStringHelper.DEFAULT); te1.getSharing().setOwner(owner); manager.save(te1, false); - te2 = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); - 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 235c83bffd34..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, createDefaultTrackedEntityType()); + 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 19c0531ab57a..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, createDefaultTrackedEntityType()); - 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 c3b08e17a39b..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, createDefaultTrackedEntityType()); - origin.setTrackedEntityType(trackedEntityType); - duplicate1 = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); - duplicate1.setTrackedEntityType(trackedEntityType); - TrackedEntity duplicate2 = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); + 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, createDefaultTrackedEntityType()); - 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 4aedd61e42b7..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,8 +87,9 @@ void setUp() { manager.save(prA); ProgramStage psA = createProgramStage('A', prA); manager.save(psA); - TrackedEntity trackedEntityA = - createTrackedEntity('A', orgUnit, createDefaultTrackedEntityType()); + 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 57a2de902052..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, createDefaultTrackedEntityType()); - 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/enrollment/EnrollmentsExportControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentsExportControllerTest.java index 2f64988b8d6a..e55084955dc1 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentsExportControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentsExportControllerTest.java @@ -136,8 +136,7 @@ void setUp() { tea.getSharing().setOwner(owner); manager.save(tea, false); - te = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); - te.setTrackedEntityType(trackedEntityType); + te = createTrackedEntity(orgUnit, trackedEntityType); manager.save(te); trackedEntityAttributeValue = new TrackedEntityAttributeValue(); 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 b5c3083f4c4f..2281220a3f6a 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 @@ -300,8 +300,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) { private TrackedEntity trackedEntity( OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) { - TrackedEntity te = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); - 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 66d666bc8299..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, createDefaultTrackedEntityType()); - 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 b250b7f83536..6cede0366615 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 @@ -861,8 +861,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) { private TrackedEntity trackedEntity( OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) { - TrackedEntity te = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); - 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 e1cfc5d5da17..865d718b6a5d 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 @@ -159,7 +159,7 @@ void setUp() { program.setTrackedEntityType(trackedEntityType); manager.save(program, false); - softDeletedTrackedEntity = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); + softDeletedTrackedEntity = createTrackedEntity(orgUnit, trackedEntityType); softDeletedTrackedEntity.setDeleted(true); manager.save(softDeletedTrackedEntity, false); } @@ -1068,8 +1068,7 @@ private TrackedEntity trackedEntity(OrganisationUnit orgUnit) { private TrackedEntity trackedEntity( OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) { - TrackedEntity te = createTrackedEntity(orgUnit, createDefaultTrackedEntityType()); - 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 012ef04dd6df..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, createDefaultTrackedEntityType()); - 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 61826349d48b..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, createDefaultTrackedEntityType()); - 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 8c028cca9ae3..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, createDefaultTrackedEntityType()); - 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/trigramsummary/TrigramSummaryControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/trigramsummary/TrigramSummaryControllerTest.java index dc95c68fbbe2..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, createDefaultTrackedEntityType()); - trackedEntity.setTrackedEntityType(trackedEntityType); + trackedEntity = createTrackedEntity(orgUnit, trackedEntityType); manager.save(trackedEntity); enrollment = new Enrollment(program, trackedEntity, orgUnit); From ea2402b0ab936c4134595685361f3613cf86fe30 Mon Sep 17 00:00:00 2001 From: zubaira Date: Sat, 16 Nov 2024 15:47:45 +0100 Subject: [PATCH 09/27] fix tests --- .../program/notification/ProgramNotificationServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 95a95de6d80b..4ffd0a01b0bb 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 @@ -400,7 +400,7 @@ void testGetEnrollmentsWithScheduledNotifications() { programNotificationStore.save(a3); // TE - TrackedEntityType trackedEntityType = createTrackedEntityType('O'); + TrackedEntityType trackedEntityType = createTrackedEntityType('M'); manager.save(trackedEntityType); TrackedEntity trackedEntityX = createTrackedEntity(organisationUnitA, trackedEntityType); TrackedEntity trackedEntityY = createTrackedEntity(organisationUnitA, trackedEntityType); From 4f26b27aec4fe44439e3ac86c329ce7f1b746ea6 Mon Sep 17 00:00:00 2001 From: zubaira Date: Thu, 21 Nov 2024 08:57:28 +0100 Subject: [PATCH 10/27] update flyway to cover existin not null rows --- ...d_not_null_constraint_to_trackedentity.sql | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) 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 index 4eeaed80691f..48e458c21aaf 100644 --- 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 @@ -1,3 +1,34 @@ --- Add not null constraint to trackedentitytypeid column in trackedentity table -ALTER TABLE trackedentity - ALTER COLUMN trackedentitytypeid SET NOT NULL; \ No newline at end of file +-- V3__Add_NotNull_Constraint_To_TrackedEntityTypeId.sql + +-- Step 1: Check if there are any rows with NULL values in trackedentitytypeid +DO $$ +DECLARE +dummy_tet_id INT; +dummy_tet_uid VARCHAR(11); +BEGIN + -- If there are NULL values in trackedentitytypeid, proceed with the update and NOT NULL constraint + IF EXISTS (SELECT 1 FROM trackedentity WHERE trackedentitytypeid IS NULL) THEN + -- Step 2: Generate a dummy ID for trackedentitytype + SELECT COALESCE(MAX(trackedentitytypeid), 0) + 1 INTO dummy_tet_id FROM trackedentitytype; + + -- Generate a unique UID for the dummy entry + LOOP + SELECT generate_uid() INTO dummy_tet_uid; + -- Ensure the UID is unique in trackedentitytype + EXIT WHEN NOT EXISTS (SELECT 1 FROM trackedentitytype WHERE uid = dummy_tet_uid); + END LOOP; + + -- Step 3: Insert dummy TrackedEntityType using generated ID and UID + INSERT INTO trackedentitytype( + trackedentitytypeid, uid, code, created, lastupdated, name, description, formname, style) + VALUES (dummy_tet_id, dummy_tet_uid, 'dummy_tet', now(), now(), 'dummy_tet', 'Placeholder for NULL values', 'dummy_tet', '{}'::jsonb); + + -- Step 4: Update rows with NULL values in trackedentitytypeid + UPDATE trackedentity + SET trackedentitytypeid = dummy_tet_id + WHERE trackedentitytypeid IS NULL; + + -- Step 5: Add NOT NULL constraint to trackedentitytypeid + ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; + END IF; +END $$; From adc03267e00dda3a73d7deab2ddb2265893778f8 Mon Sep 17 00:00:00 2001 From: zubaira Date: Thu, 21 Nov 2024 08:58:30 +0100 Subject: [PATCH 11/27] update flyway --- .../V2_42_26__Add_not_null_constraint_to_trackedentity.sql | 3 --- 1 file changed, 3 deletions(-) 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 index 48e458c21aaf..ef48323bdda5 100644 --- 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 @@ -1,6 +1,3 @@ --- V3__Add_NotNull_Constraint_To_TrackedEntityTypeId.sql - --- Step 1: Check if there are any rows with NULL values in trackedentitytypeid DO $$ DECLARE dummy_tet_id INT; From 4ac4a4438f7f7eb2aa7efbabe5da293ff2c329df Mon Sep 17 00:00:00 2001 From: zubaira Date: Wed, 4 Dec 2024 12:03:00 +0100 Subject: [PATCH 12/27] update flyway migration --- ...d_not_null_constraint_to_trackedentity.sql | 35 ++++--------------- 1 file changed, 7 insertions(+), 28 deletions(-) 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 index ef48323bdda5..ae869f995563 100644 --- 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 @@ -1,31 +1,10 @@ DO $$ -DECLARE -dummy_tet_id INT; -dummy_tet_uid VARCHAR(11); BEGIN - -- If there are NULL values in trackedentitytypeid, proceed with the update and NOT NULL constraint - IF EXISTS (SELECT 1 FROM trackedentity WHERE trackedentitytypeid IS NULL) THEN - -- Step 2: Generate a dummy ID for trackedentitytype - SELECT COALESCE(MAX(trackedentitytypeid), 0) + 1 INTO dummy_tet_id FROM trackedentitytype; - -- Generate a unique UID for the dummy entry - LOOP - SELECT generate_uid() INTO dummy_tet_uid; - -- Ensure the UID is unique in trackedentitytype - EXIT WHEN NOT EXISTS (SELECT 1 FROM trackedentitytype WHERE uid = dummy_tet_uid); - END LOOP; - - -- Step 3: Insert dummy TrackedEntityType using generated ID and UID - INSERT INTO trackedentitytype( - trackedentitytypeid, uid, code, created, lastupdated, name, description, formname, style) - VALUES (dummy_tet_id, dummy_tet_uid, 'dummy_tet', now(), now(), 'dummy_tet', 'Placeholder for NULL values', 'dummy_tet', '{}'::jsonb); - - -- Step 4: Update rows with NULL values in trackedentitytypeid - UPDATE trackedentity - SET trackedentitytypeid = dummy_tet_id - WHERE trackedentitytypeid IS NULL; - - -- Step 5: Add NOT NULL constraint to trackedentitytypeid - ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; - END IF; -END $$; +ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; +EXCEPTION + WHEN not_null_violation THEN + RAISE EXCEPTION 'Database contains inconsistent data. For more information about this issue and steps to resolve it, please refer to the migration notes: ' || + 'https://github.com/dhis2/dhis2-releases/blob/master/releases/2.42/migration-notes.md#null-trackedentitytype. Detailed error message: %', SQLERRM; +END +$$; From 13024a3d2ba3113e5f532cdadb92343623820557 Mon Sep 17 00:00:00 2001 From: zubaira Date: Wed, 4 Dec 2024 12:26:41 +0100 Subject: [PATCH 13/27] minor --- .../V2_42_26__Add_not_null_constraint_to_trackedentity.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index ae869f995563..91e3901dad55 100644 --- 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 @@ -4,7 +4,7 @@ BEGIN ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; EXCEPTION WHEN not_null_violation THEN - RAISE EXCEPTION 'Database contains inconsistent data. For more information about this issue and steps to resolve it, please refer to the migration notes: ' || - 'https://github.com/dhis2/dhis2-releases/blob/master/releases/2.42/migration-notes.md#null-trackedentitytype. Detailed error message: %', SQLERRM; + RAISE EXCEPTION 'Database contains inconsistent data. For more information about this issue and steps to resolve it, please refer to the migration notes: + https://github.com/dhis2/dhis2-releases/blob/master/releases/2.42/migration-notes.md#null-trackedentitytype. Detailed error message: %', SQLERRM; END $$; From 2baca3adf1f88670bd6cca06fffab16c4a1d9c1d Mon Sep 17 00:00:00 2001 From: zubaira Date: Wed, 4 Dec 2024 12:28:16 +0100 Subject: [PATCH 14/27] minor --- .../2.42/V2_42_26__Add_not_null_constraint_to_trackedentity.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 91e3901dad55..ff32db41abcd 100644 --- 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 @@ -1,7 +1,7 @@ DO $$ BEGIN -ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; +ALTER TABLE IF EXISTS trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; EXCEPTION WHEN not_null_violation THEN RAISE EXCEPTION 'Database contains inconsistent data. For more information about this issue and steps to resolve it, please refer to the migration notes: From b0797bcf7096bcbfe936cfa961e2b32af648e35a Mon Sep 17 00:00:00 2001 From: zubaira Date: Thu, 5 Dec 2024 09:43:05 +0100 Subject: [PATCH 15/27] expcetion message --- .../2.42/V2_42_26__Add_not_null_constraint_to_trackedentity.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index ff32db41abcd..af93e6536dd3 100644 --- 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 @@ -4,7 +4,7 @@ BEGIN ALTER TABLE IF EXISTS trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; EXCEPTION WHEN not_null_violation THEN - RAISE EXCEPTION 'Database contains inconsistent data. For more information about this issue and steps to resolve it, please refer to the migration notes: + RAISE EXCEPTION 'The database contains inconsistent data that must be resolved before re-running this migration. Please refer to the migration notes for detailed instructions on how to address this issue: https://github.com/dhis2/dhis2-releases/blob/master/releases/2.42/migration-notes.md#null-trackedentitytype. Detailed error message: %', SQLERRM; END $$; From e62c46be0ca06d5262e9139edd2f9c73efa17128 Mon Sep 17 00:00:00 2001 From: zubaira Date: Thu, 5 Dec 2024 10:06:31 +0100 Subject: [PATCH 16/27] correction in markdown --- .../2.42/V2_42_26__Add_not_null_constraint_to_trackedentity.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index af93e6536dd3..7e0b755a35fc 100644 --- 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 @@ -5,6 +5,6 @@ ALTER TABLE IF EXISTS trackedentity ALTER COLUMN trackedentitytypeid SET NOT NUL 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 on how to address this issue: - https://github.com/dhis2/dhis2-releases/blob/master/releases/2.42/migration-notes.md#null-trackedentitytype. Detailed error message: %', SQLERRM; + https://github.com/dhis2/dhis2-releases/blob/master/releases/2.42/migration-notes.md#null-tracked-entity-type. Detailed error message: %', SQLERRM; END $$; From 72868f4171983a126dd00e076dfcfea55cd71f5e Mon Sep 17 00:00:00 2001 From: zubaira Date: Thu, 5 Dec 2024 20:29:40 +0100 Subject: [PATCH 17/27] Find inconstent trackedentities, fix them and set trackentitytypeid not-null --- ...d_not_null_constraint_to_trackedentity.sql | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) 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 index 7e0b755a35fc..f12f3ecb580d 100644 --- 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 @@ -1,10 +1,41 @@ DO $$ +DECLARE +results RECORD; +inconsistent_records_count INTEGER; BEGIN +SELECT COUNT(*) INTO inconsistent_records_count FROM trackedentity WHERE trackedentitytypeid IS NULL; -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 on how to address this issue: - https://github.com/dhis2/dhis2-releases/blob/master/releases/2.42/migration-notes.md#null-tracked-entity-type. Detailed error message: %', SQLERRM; -END -$$; +IF inconsistent_records_count > 0 THEN + RAISE NOTICE 'Inconsistencies found: %', inconsistent_records_count; + +FOR results IN +SELECT programid, trackedentityid FROM enrollment WHERE trackedentityid IN ( + SELECT trackedentityid + FROM trackedentity + WHERE trackedentitytypeid IS NULL +) + LOOP +UPDATE trackedentity +SET trackedentitytypeid = ( + SELECT trackedentitytypeid + FROM program + WHERE programid = results.programid +) +WHERE trackedentityid = results.trackedentityid; + +RAISE NOTICE 'Updated trackedentity: programid = %, trackedentityid = %', results.programid, results.trackedentityid; +END LOOP; + +SELECT COUNT(*) INTO inconsistent_records_count FROM trackedentity WHERE trackedentitytypeid IS NULL; + +IF inconsistent_records_count = 0 THEN + ALTER TABLE IF EXISTS trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; + RAISE NOTICE 'trackedentitytypeid is now set to NOT NULL.'; +ELSE + RAISE NOTICE 'There are still NULL values in trackedentitytypeid. Please review the data.'; +END IF; + +ELSE + RAISE NOTICE 'No inconsistencies found, trackedentitytypeid is already populated.'; +END IF; +END $$; From 746ec8be54ae43ebb1fcdc101a2f389e027a262c Mon Sep 17 00:00:00 2001 From: zubaira Date: Thu, 5 Dec 2024 20:44:16 +0100 Subject: [PATCH 18/27] update --- ...d_not_null_constraint_to_trackedentity.sql | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) 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 index f12f3ecb580d..17ed5894b901 100644 --- 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 @@ -8,33 +8,24 @@ SELECT COUNT(*) INTO inconsistent_records_count FROM trackedentity WHERE tracked IF inconsistent_records_count > 0 THEN RAISE NOTICE 'Inconsistencies found: %', inconsistent_records_count; -FOR results IN -SELECT programid, trackedentityid FROM enrollment WHERE trackedentityid IN ( - SELECT trackedentityid - FROM trackedentity - WHERE trackedentitytypeid IS NULL -) + FOR results IN + SELECT programid, trackedentityid FROM enrollment WHERE trackedentityid IN ( + SELECT trackedentityid + FROM trackedentity + WHERE trackedentitytypeid IS NULL + ) LOOP -UPDATE trackedentity -SET trackedentitytypeid = ( - SELECT trackedentitytypeid - FROM program - WHERE programid = results.programid -) -WHERE trackedentityid = results.trackedentityid; + UPDATE trackedentity + SET trackedentitytypeid = ( + SELECT trackedentitytypeid + FROM program + WHERE programid = results.programid + ) + WHERE trackedentityid = results.trackedentityid; -RAISE NOTICE 'Updated trackedentity: programid = %, trackedentityid = %', results.programid, results.trackedentityid; -END LOOP; - -SELECT COUNT(*) INTO inconsistent_records_count FROM trackedentity WHERE trackedentitytypeid IS NULL; - -IF inconsistent_records_count = 0 THEN + RAISE NOTICE 'Updated trackedentity: programid = %, trackedentityid = %', results.programid, results.trackedentityid; + END LOOP; ALTER TABLE IF EXISTS trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; - RAISE NOTICE 'trackedentitytypeid is now set to NOT NULL.'; -ELSE - RAISE NOTICE 'There are still NULL values in trackedentitytypeid. Please review the data.'; -END IF; - ELSE RAISE NOTICE 'No inconsistencies found, trackedentitytypeid is already populated.'; END IF; From 148454536439e8486a8f39322cf4bfbd60a412d4 Mon Sep 17 00:00:00 2001 From: zubaira Date: Thu, 5 Dec 2024 21:32:49 +0100 Subject: [PATCH 19/27] add exception --- .../V2_42_26__Add_not_null_constraint_to_trackedentity.sql | 4 ++++ 1 file changed, 4 insertions(+) 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 index 17ed5894b901..c2869b357355 100644 --- 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 @@ -26,6 +26,10 @@ IF inconsistent_records_count > 0 THEN RAISE NOTICE 'Updated trackedentity: programid = %, trackedentityid = %', results.programid, results.trackedentityid; END LOOP; 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 on how to address this issue: + https://github.com/dhis2/dhis2-releases/blob/master/releases/2.42/migration-notes.md#null-tracked-entity-type. Detailed error message: %', SQLERRM; ELSE RAISE NOTICE 'No inconsistencies found, trackedentitytypeid is already populated.'; END IF; From c3359ce8ce508f1cf356e9e840b1c856d3885fd5 Mon Sep 17 00:00:00 2001 From: zubaira Date: Thu, 5 Dec 2024 21:45:53 +0100 Subject: [PATCH 20/27] add exception --- ...2_26__Add_not_null_constraint_to_trackedentity.sql | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 index c2869b357355..000e969bcc13 100644 --- 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 @@ -6,7 +6,7 @@ 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; + RAISE NOTICE 'Inconsistencies found: %', inconsistent_records_count; FOR results IN SELECT programid, trackedentityid FROM enrollment WHERE trackedentityid IN ( @@ -25,11 +25,14 @@ IF inconsistent_records_count > 0 THEN RAISE NOTICE 'Updated trackedentity: programid = %, trackedentityid = %', results.programid, results.trackedentityid; END LOOP; - ALTER TABLE IF EXISTS trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; - EXCEPTION - WHEN not_null_violation THEN + SELECT COUNT(*) INTO inconsistent_records_count FROM trackedentity WHERE trackedentitytypeid IS NULL; + + IF inconsistent_records_count = 0 THEN + ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; + ELSE RAISE EXCEPTION 'The database contains inconsistent data that must be resolved before re-running this migration. Please refer to the migration notes for detailed instructions on how to address this issue: https://github.com/dhis2/dhis2-releases/blob/master/releases/2.42/migration-notes.md#null-tracked-entity-type. Detailed error message: %', SQLERRM; + END IF; ELSE RAISE NOTICE 'No inconsistencies found, trackedentitytypeid is already populated.'; END IF; From d8851712e0f0aa6919b27e9c444b1e76da27af92 Mon Sep 17 00:00:00 2001 From: zubaira Date: Fri, 6 Dec 2024 12:38:14 +0100 Subject: [PATCH 21/27] code reviews --- .../dhis/tracker/deduplication/DeduplicationHelperTest.java | 4 ---- .../validator/enrollment/SecurityOwnershipValidatorTest.java | 2 -- .../trackedentity/SecurityOwnershipValidatorTest.java | 2 -- .../V2_42_26__Add_not_null_constraint_to_trackedentity.sql | 4 +--- .../org/hisp/dhis/trackedentity/TrackerAccessManagerTest.java | 2 -- 5 files changed, 1 insertion(+), 13 deletions(-) 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 86325b154cad..09204531a6c0 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 @@ -522,15 +522,11 @@ private List getEnrollments() { private TrackedEntity getTrackedEntityA() { TrackedEntity te = createTrackedEntity(organisationUnitA, createTrackedEntityType('I')); - te.setTrackedEntityType(trackedEntityTypeA); - return te; } private TrackedEntity getTrackedEntityB() { TrackedEntity te = createTrackedEntity(organisationUnitB, createTrackedEntityType('F')); - te.setTrackedEntityType(trackedEntityTypeB); - 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 1b3027ca0ab0..07ca6f5113f2 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 @@ -393,8 +393,6 @@ private TrackedEntity teWithNoEnrollments() { 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/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 e89a0872a692..2ce5834c20db 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 @@ -316,8 +316,6 @@ private TrackedEntity teWithDeleteEnrollments() { createTrackedEntity(organisationUnit, createTrackedEntityType('B')); trackedEntity.setUid(TE_ID.getValue()); trackedEntity.setEnrollments(Sets.newHashSet(enrollment)); - trackedEntity.setTrackedEntityType(trackedEntityType); - return trackedEntity; } 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 index 000e969bcc13..04f1b4e76f39 100644 --- 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 @@ -25,15 +25,13 @@ IF inconsistent_records_count > 0 THEN RAISE NOTICE 'Updated trackedentity: programid = %, trackedentityid = %', results.programid, results.trackedentityid; END LOOP; - SELECT COUNT(*) INTO inconsistent_records_count FROM trackedentity WHERE trackedentitytypeid IS NULL; - IF inconsistent_records_count = 0 THEN ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; - ELSE RAISE EXCEPTION 'The database contains inconsistent data that must be resolved before re-running this migration. Please refer to the migration notes for detailed instructions on how to address this issue: https://github.com/dhis2/dhis2-releases/blob/master/releases/2.42/migration-notes.md#null-tracked-entity-type. Detailed error message: %', SQLERRM; END IF; ELSE RAISE NOTICE 'No inconsistencies found, trackedentitytypeid is already populated.'; + ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; END IF; END $$; 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 b43a2124d6a6..dc48dbf6ef07 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 @@ -160,8 +160,6 @@ void setUp() { TrackedEntity femaleA = createTrackedEntity(orgUnitA, trackedEntityType); TrackedEntity femaleB = createTrackedEntity(orgUnitB, trackedEntityType); - femaleA.setTrackedEntityType(trackedEntityType); - femaleB.setTrackedEntityType(trackedEntityType); manager.save(trackedEntityA); manager.save(trackedEntityB); manager.save(femaleA); From 964ed52a8440dc7cc5d4e46eb49c74be63d9d07d Mon Sep 17 00:00:00 2001 From: zubaira Date: Fri, 6 Dec 2024 12:54:23 +0100 Subject: [PATCH 22/27] code review --- ...d_not_null_constraint_to_trackedentity.sql | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) 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 index 04f1b4e76f39..3502d28ab1d4 100644 --- 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 @@ -3,18 +3,21 @@ DECLARE results RECORD; inconsistent_records_count INTEGER; BEGIN + SELECT COUNT(*) INTO inconsistent_records_count FROM trackedentity WHERE trackedentitytypeid IS NULL; IF inconsistent_records_count > 0 THEN - RAISE NOTICE 'Inconsistencies found: %', inconsistent_records_count; + RAISE NOTICE 'Inconsistencies found: %', inconsistent_records_count; FOR results IN - SELECT programid, trackedentityid FROM enrollment WHERE trackedentityid IN ( + SELECT programid, trackedentityid + FROM enrollment + WHERE trackedentityid IN ( SELECT trackedentityid FROM trackedentity WHERE trackedentitytypeid IS NULL ) - LOOP + LOOP UPDATE trackedentity SET trackedentitytypeid = ( SELECT trackedentitytypeid @@ -25,13 +28,13 @@ IF inconsistent_records_count > 0 THEN RAISE NOTICE 'Updated trackedentity: programid = %, trackedentityid = %', results.programid, results.trackedentityid; END LOOP; - - ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; - RAISE EXCEPTION 'The database contains inconsistent data that must be resolved before re-running this migration. Please refer to the migration notes for detailed instructions on how to address this issue: - https://github.com/dhis2/dhis2-releases/blob/master/releases/2.42/migration-notes.md#null-tracked-entity-type. Detailed error message: %', SQLERRM; - END IF; + ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; ELSE - RAISE NOTICE 'No inconsistencies found, trackedentitytypeid is already populated.'; - ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; + RAISE NOTICE 'No inconsistencies found, trackedentitytypeid is already populated.'; + ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; END IF; -END $$; + +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 From 91189c98f2241d99512b94a640a56a9f56a4de40 Mon Sep 17 00:00:00 2001 From: zubaira Date: Fri, 6 Dec 2024 12:56:50 +0100 Subject: [PATCH 23/27] minor --- .../V2_42_26__Add_not_null_constraint_to_trackedentity.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 3502d28ab1d4..6e6541890506 100644 --- 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 @@ -28,10 +28,10 @@ IF inconsistent_records_count > 0 THEN RAISE NOTICE 'Updated trackedentity: programid = %, trackedentityid = %', results.programid, results.trackedentityid; END LOOP; - ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; + ALTER TABLE IF EXISTS trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; ELSE RAISE NOTICE 'No inconsistencies found, trackedentitytypeid is already populated.'; - ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; + ALTER TABLE IF EXISTS trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; END IF; EXCEPTION From 6dcdf054f596934210ae272bf432ffea7e68a506 Mon Sep 17 00:00:00 2001 From: zubaira Date: Fri, 6 Dec 2024 13:10:21 +0100 Subject: [PATCH 24/27] fix unit test --- .../dhis/tracker/deduplication/DeduplicationHelperTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 09204531a6c0..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,13 +521,11 @@ private List getEnrollments() { } private TrackedEntity getTrackedEntityA() { - TrackedEntity te = createTrackedEntity(organisationUnitA, createTrackedEntityType('I')); - return te; + return createTrackedEntity(organisationUnitA, trackedEntityTypeA); } private TrackedEntity getTrackedEntityB() { - TrackedEntity te = createTrackedEntity(organisationUnitB, createTrackedEntityType('F')); - return te; + return createTrackedEntity(organisationUnitB, trackedEntityTypeB); } private User getNoMergeAuthsUser() { From f2adebf7c6c6a3cdb371bd72453d6517ce345bd3 Mon Sep 17 00:00:00 2001 From: zubaira Date: Fri, 6 Dec 2024 23:41:08 +0100 Subject: [PATCH 25/27] set operation instead of looping through the records --- ...d_not_null_constraint_to_trackedentity.sql | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) 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 index 6e6541890506..3b123c29f49d 100644 --- 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 @@ -1,6 +1,5 @@ DO $$ DECLARE -results RECORD; inconsistent_records_count INTEGER; BEGIN @@ -9,25 +8,21 @@ SELECT COUNT(*) INTO inconsistent_records_count FROM trackedentity WHERE tracked IF inconsistent_records_count > 0 THEN RAISE NOTICE 'Inconsistencies found: %', inconsistent_records_count; - FOR results IN - SELECT programid, trackedentityid - FROM enrollment - WHERE trackedentityid IN ( - SELECT trackedentityid - FROM trackedentity - WHERE trackedentitytypeid IS NULL - ) - LOOP UPDATE trackedentity SET trackedentitytypeid = ( - SELECT trackedentitytypeid + SELECT program.trackedentitytypeid FROM program - WHERE programid = results.programid + JOIN enrollment ON program.programid = enrollment.programid + WHERE enrollment.trackedentityid = trackedentity.trackedentityid ) - WHERE trackedentityid = results.trackedentityid; + WHERE trackedentitytypeid IS NULL + AND EXISTS ( + SELECT 1 + FROM enrollment + JOIN program ON enrollment.programid = program.programid + WHERE enrollment.trackedentityid = trackedentity.trackedentityid + ); - RAISE NOTICE 'Updated trackedentity: programid = %, trackedentityid = %', results.programid, results.trackedentityid; - END LOOP; ALTER TABLE IF EXISTS trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; ELSE RAISE NOTICE 'No inconsistencies found, trackedentitytypeid is already populated.'; From cfea998bf4d2e97bc9028d4acec7f912e4dc4d2d Mon Sep 17 00:00:00 2001 From: zubaira Date: Wed, 11 Dec 2024 08:48:27 +0100 Subject: [PATCH 26/27] update flyway --- ...2_42_26__Add_not_null_constraint_to_trackedentity.sql | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) 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 index 3b123c29f49d..7f84235b1687 100644 --- 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 @@ -2,9 +2,7 @@ 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; @@ -22,13 +20,8 @@ IF inconsistent_records_count > 0 THEN JOIN program ON enrollment.programid = program.programid WHERE enrollment.trackedentityid = trackedentity.trackedentityid ); - - ALTER TABLE IF EXISTS trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; -ELSE - RAISE NOTICE 'No inconsistencies found, trackedentitytypeid is already populated.'; - ALTER TABLE IF EXISTS trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; 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; From d3c34d3d3a1171bbb522af7e9c819419dc56fb83 Mon Sep 17 00:00:00 2001 From: zubaira Date: Tue, 14 Jan 2025 09:28:57 +0100 Subject: [PATCH 27/27] fix test --- .../tracker/imports/TrackerImportNoteControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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);