diff --git a/src/main/java/org/avniproject/etl/service/AddressService.java b/src/main/java/org/avniproject/etl/service/AddressService.java deleted file mode 100644 index 7365bf6..0000000 --- a/src/main/java/org/avniproject/etl/service/AddressService.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.avniproject.etl.service; - -public class AddressService { -} diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml index f4004a2..b831561 100644 --- a/src/main/resources/log4j.xml +++ b/src/main/resources/log4j.xml @@ -24,7 +24,7 @@ - + diff --git a/src/test/java/org/avniproject/etl/DataSyncIntegrationTest.java b/src/test/java/org/avniproject/etl/DataSyncIntegrationTest.java index e166bb8..c1a17d6 100644 --- a/src/test/java/org/avniproject/etl/DataSyncIntegrationTest.java +++ b/src/test/java/org/avniproject/etl/DataSyncIntegrationTest.java @@ -145,6 +145,36 @@ public void changeDataTypeOfConcept_UsingVoiding_ButBetweenTwoRuns() { assertEquals(conceptName, newColumnMetaData.getName()); } + @Test + @Sql({"/test-data-teardown.sql", "/test-data.sql"}) + @Sql(scripts = "/test-data-teardown.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) + public void changeDataTypeOfConcept_UsingVoiding_ButBetweenTwoRuns_RepeatableQuestionGroup() { + String questionGroupName = "Asset Info"; + String conceptName = "Beneficiary Parent"; + String columnName = questionGroupName + " " + conceptName; + + runDataSync(); + ColumnMetadata columnMetadata = this.columnMetadataRepository.findByName(columnName); + assertFalse(columnMetadata.isConceptVoided()); + + String voidedConceptName = "Beneficiary Parent (voided)"; + String voidedColumnName = questionGroupName + " " + voidedConceptName; + jdbcTemplate.execute(format("update concept set name = '%s', is_voided = true, last_modified_date_time = '%s' where name = '%s'", + voidedConceptName, getCurrentTime(), conceptName)); + runDataSync(); + columnMetadata = this.columnMetadataRepository.findByUuid(columnMetadata.getConceptUuid()); + assertEquals(voidedColumnName, columnMetadata.getName()); + assertTrue(columnMetadata.isConceptVoided()); + + String newConceptUuid = "a379fcef-f0a1-4ac2-8555-400041162fee"; + jdbcTemplate.execute(format("insert into concept (data_type, high_absolute, high_normal, low_absolute, low_normal, name, uuid, version, unit, organisation_id, is_voided, audit_id, key_values, active, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) values ('Numeric', null, null, null, null, 'Beneficiary Parent', '%s', 0, null, 12, false, create_audit(), null, true, 1, 1, '%s', '%s');", newConceptUuid, getCurrentTime(), getCurrentTime())); + jdbcTemplate.execute(format("update form_element set concept_id = (select id from concept where name = '%s'), last_modified_date_time = '%s' where name = 'Beneficiary Parent Form Element'", conceptName, getCurrentTime())); + runDataSync(); + ColumnMetadata newColumnMetaData = this.columnMetadataRepository.findByUuid(newConceptUuid); + assertFalse(newColumnMetaData.isConceptVoided()); + assertEquals(columnName, newColumnMetaData.getName()); + } + @Test @Sql({"/test-data-teardown.sql", "/test-data.sql"}) @Sql(scripts = "/test-data-teardown.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) @@ -177,6 +207,38 @@ public void changeInDataTypeOfConcept_VoidOldAndRemoveFromForm_NewOneWithDiffere runDataSync(); } + @Test + @Sql({"/test-data-teardown.sql", "/test-data.sql"}) + @Sql(scripts = "/test-data-teardown.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) + public void changeInDataTypeOfConcept_VoidOldAndRemoveFromForm_NewOneWithDifferentDataType_LocationAttributes() { + String newConceptUuid = "4a8103ba-92a6-4b66-8440-9d1296f38bd3"; + String conceptName = "Address Identifier"; + // Name voiding convention between avni main db and etl db are decoupled + String voidedConceptName = "Address Identifier (voided)"; + + runDataSync(); + // void the old concept + jdbcTemplate.execute(format("update concept set name = '%s', is_voided = true, last_modified_date_time = '%s' where name = '%s'", voidedConceptName, getCurrentTime(), conceptName)); + // new concept with different data type + jdbcTemplate.execute(format(""" + insert into concept (data_type, high_absolute, high_normal, low_absolute, low_normal, name, uuid, version, unit, organisation_id, is_voided, audit_id, key_values, active, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) values ('Numeric', null, null, null, null, '%s', '%s', 0, null, 12, false, create_audit(), null, true, 1, 1, '%s', '%s'); + """, conceptName, newConceptUuid, getCurrentTime(), getCurrentTime())); + // point form element to new concept + jdbcTemplate.execute(format(""" + update form_element set concept_id = (select id from concept where name = '%s'), last_modified_date_time = '%s' where name = 'Address Identifier Form Element' + """, conceptName, getCurrentTime())); + runDataSync(); + + ColumnMetadata oldColumnMetaData = this.columnMetadataRepository.findByName(ColumnMetadata.getVoidedName(conceptName)); + assertTrue(oldColumnMetaData.isConceptVoided()); + + ColumnMetadata newColumnMetaData = this.columnMetadataRepository.findByUuid(newConceptUuid); + assertFalse(newColumnMetaData.isConceptVoided()); + assertEquals(conceptName, newColumnMetaData.getName()); + // run again without any changes, should not get any error + runDataSync(); + } + @Test @Sql({"/test-data-teardown.sql", "/test-data.sql", "/new-form-element.sql"}) @Sql(scripts = "/test-data-teardown.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) diff --git a/src/test/resources/test-data.sql b/src/test/resources/test-data.sql index f01d9f8..6d3d775 100644 --- a/src/test/resources/test-data.sql +++ b/src/test/resources/test-data.sql @@ -74,12 +74,19 @@ INSERT INTO concept (id, data_type, high_absolute, high_normal, low_absolute, lo INSERT INTO concept (id, data_type, high_absolute, high_normal, low_absolute, low_normal, name, uuid, version, unit, organisation_id, is_voided, audit_id, key_values, active, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) VALUES (107581, 'Text', null, null, null, null, 'Child 1', '62412d21-85a2-4bfa-9e74-1c21395235b9', 0, null, 12, false, create_audit(), '[]', true, 1, 1, '2022-04-13 16:51:16.414 +00:00', '2022-04-13 16:51:16.414 +00:00'); INSERT INTO concept (id, data_type, high_absolute, high_normal, low_absolute, low_normal, name, uuid, version, unit, organisation_id, is_voided, audit_id, key_values, active, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) VALUES (107582, 'Text', null, null, null, null, 'Child 2', 'eead9471-d160-42c0-a237-ea3ba20821ae', 0, null, 12, false, create_audit(), '[]', true, 1, 1, '2022-04-13 17:51:16.414 +00:00', '2022-04-13 17:51:16.414 +00:00'); INSERT INTO concept (id, data_type, high_absolute, high_normal, low_absolute, low_normal, name, uuid, version, unit, organisation_id, is_voided, audit_id, key_values, active, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) VALUES (107583, 'Text', null, null, null, null, 'Extra location info', '38c6a3cb-3e36-48ce-a445-3be503fd4cd9', 0, null, 12, false, create_audit(), '[]', true, 1, 1, '2022-04-17 17:51:16.414 +00:00', '2022-04-17 17:51:16.414 +00:00'); +-- Used for void and rename scenario for address +INSERT INTO concept (data_type, high_absolute, high_normal, low_absolute, low_normal, name, uuid, version, unit, organisation_id, is_voided, audit_id, key_values, active, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) VALUES ('Text', null, null, null, null, 'Address Identifier', '0436f859-5c67-4854-a9dc-74248fcf6dbd', 0, null, 12, false, create_audit(), '[]', true, 1, 1, '2022-04-17 17:51:16.414 +00:00', '2022-04-17 17:51:16.414 +00:00'); + +-- Used for void and rename scenario +INSERT INTO concept (data_type, high_absolute, high_normal, low_absolute, low_normal, name, uuid, version, unit, organisation_id, is_voided, audit_id, key_values, active, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) VALUES ('Text', null, null, null, null, 'Beneficiary Children', '0dd9c3c7-b195-4913-b72e-ab9f0a8cfb33', 0, null, 12, false, create_audit(), '[]', true, 1, 1, '2022-04-17 17:51:16.414 +00:00', '2022-04-17 17:51:16.414 +00:00'); + -- Repeatable QG INSERT INTO concept (id, data_type, high_absolute, high_normal, low_absolute, low_normal, name, uuid, version, unit, organisation_id, is_voided, audit_id, key_values, active, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) VALUES (107584, 'QuestionGroup', null, null, null, null, 'Asset Info', '6ed176f6-70d5-4db8-8f39-68c06f3459af', 0, null, 12, false, create_audit(), '[]', true, 1, 1, '2022-04-17 17:51:16.414 +00:00', '2022-04-17 17:51:16.414 +00:00'); INSERT INTO concept (id, data_type, high_absolute, high_normal, low_absolute, low_normal, name, uuid, version, unit, organisation_id, is_voided, audit_id, key_values, active, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) VALUES (107585, 'Numeric', null, null, null, null, 'Bitcoin', '0270c64f-6201-46b3-b126-2913af80a065', 0, null, 12, false, create_audit(), '[]', true, 1, 1, '2022-04-17 17:51:16.414 +00:00', '2022-04-17 17:51:16.414 +00:00'); INSERT INTO concept (id, data_type, high_absolute, high_normal, low_absolute, low_normal, name, uuid, version, unit, organisation_id, is_voided, audit_id, key_values, active, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) VALUES (107586, 'Text', null, null, null, null, 'Exchange', '14a66108-aaf8-4977-aba0-91027af1b1ec', 0, null, 12, false, create_audit(), '[]', true, 1, 1, '2022-04-17 17:51:16.414 +00:00', '2022-04-17 17:51:16.414 +00:00'); -INSERT INTO concept (data_type, high_absolute, high_normal, low_absolute, low_normal, name, uuid, version, unit, organisation_id, is_voided, audit_id, key_values, active, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) VALUES ('Text', null, null, null, null, 'Beneficiary Children', 'aaac96c4-4e1a-48a2-9323-726a515d7610', 0, null, 12, false, create_audit(), '[]', true, 1, 1, '2022-04-17 17:51:16.414 +00:00', '2022-04-17 17:51:16.414 +00:00'); +-- Used for void and rename of concept in Repeatable QG +INSERT INTO concept (data_type, high_absolute, high_normal, low_absolute, low_normal, name, uuid, version, unit, organisation_id, is_voided, audit_id, key_values, active, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) VALUES ('Text', null, null, null, null, 'Beneficiary Parent', '18b249d1-eac7-42ed-8d9e-64b3986d9531', 0, null, 12, false, create_audit(), '[]', true, 1, 1, '2022-04-17 17:51:16.414 +00:00', '2022-04-17 17:51:16.414 +00:00'); insert into concept_answer (id, concept_id, answer_concept_id, uuid, version, answer_order, organisation_id, abnormal, is_voided, uniq, audit_id, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) values (98934, 107565, 107564, 'cbde6ba5-22ae-410c-857c-2b41de35012d', 0, 1, 12, false, false, false, create_audit(), 1, 1, '2022-03-16 16:14:28.601 +00:00', '2022-03-16 16:14:28.601 +00:00'); insert into concept_answer (id, concept_id, answer_concept_id, uuid, version, answer_order, organisation_id, abnormal, is_voided, uniq, audit_id, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) values (98935, 107565, 107562, '7cf07e91-025c-4b8e-b79d-4428e177f88b', 0, 0, 12, false, false, false, create_audit(), 1, 1, '2022-03-16 16:14:28.617 +00:00', '2022-03-16 16:14:28.617 +00:00'); @@ -122,10 +129,16 @@ insert into form_element (id, name, display_order, is_mandatory, key_values, con insert into form_element (id, name, display_order, is_mandatory, key_values, concept_id, form_element_group_id, uuid, version, organisation_id, type, valid_format_regex, valid_format_description_key, audit_id, is_voided, rule, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, declarative_rule, group_id) values (40117, 'Asset Info', 12, false, '[{"key": "repeatable", "value": true}]', 107584, 5569, '2aa73372-d01b-4dab-8c8c-320622bc0b6a', 0, 12, null, null, null, create_audit(), false, null, 1, 1, '2022-04-17 17:51:18.414 +00:00', '2022-04-17 17:51:18.414 +00:00', null, null); insert into form_element (id, name, display_order, is_mandatory, key_values, concept_id, form_element_group_id, uuid, version, organisation_id, type, valid_format_regex, valid_format_description_key, audit_id, is_voided, rule, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, declarative_rule, group_id) values (40118, 'Bitcoin', 13, false, '[]', 107585, 5569, 'c8a01e61-ed5e-4383-bdd3-565fd7364eaa', 0, 12, null, null, null, create_audit(), false, null, 1, 1, '2022-04-17 17:51:18.414 +00:00', '2022-04-17 17:51:18.414 +00:00', null, 40117); insert into form_element (id, name, display_order, is_mandatory, key_values, concept_id, form_element_group_id, uuid, version, organisation_id, type, valid_format_regex, valid_format_description_key, audit_id, is_voided, rule, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, declarative_rule, group_id) values (40119, 'Exchange', 14, false, '[]', 107586, 5569, 'e276a49c-0d02-421d-84f1-bc5dfe318d08', 0, 12, null, null, null, create_audit(), false, null, 1, 1, '2022-04-17 17:51:18.414 +00:00', '2022-04-17 17:51:18.414 +00:00', null, 40117); -insert into form_element (name, display_order, is_mandatory, key_values, concept_id, form_element_group_id, uuid, version, organisation_id, type, valid_format_regex, valid_format_description_key, audit_id, is_voided, rule, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, declarative_rule, group_id) values ('Beneficiary Children Form Element', 15, false, '[]', (select id from concept where name = 'Beneficiary Children'), 5569, '5bb4234d-f014-4cae-9b2c-aef2cf4ed509', 0, 12, null, null, null, create_audit(), false, null, 1, 1, '2022-04-17 17:51:18.414 +00:00', '2022-04-17 17:51:18.414 +00:00', null, null); +-- Used for void and rename scenario in repeatable question group +insert into form_element (name, display_order, is_mandatory, key_values, concept_id, form_element_group_id, uuid, version, organisation_id, type, valid_format_regex, valid_format_description_key, audit_id, is_voided, rule, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, declarative_rule, group_id) values ('Beneficiary Parent Form Element', 15, false, '[]', (select id from concept where name = 'Beneficiary Parent'), 5569, '6b9d1928-ea02-4bda-832e-d73fb4240976', 0, 12, null, null, null, create_audit(), false, null, 1, 1, '2022-04-17 17:51:18.414 +00:00', '2022-04-17 17:51:18.414 +00:00', null, 40117); + + +-- Used for void and rename scenario +insert into form_element (name, display_order, is_mandatory, key_values, concept_id, form_element_group_id, uuid, version, organisation_id, type, valid_format_regex, valid_format_description_key, audit_id, is_voided, rule, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, declarative_rule, group_id) values ('Beneficiary Children Form Element', 16, false, '[]', (select id from concept where name = 'Beneficiary Children'), 5569, '5bb4234d-f014-4cae-9b2c-aef2cf4ed509', 0, 12, null, null, null, create_audit(), false, null, 1, 1, '2022-04-17 17:51:18.414 +00:00', '2022-04-17 17:51:18.414 +00:00', null, null); insert into form_element (id, name, display_order, is_mandatory, key_values, concept_id, form_element_group_id, uuid, version, organisation_id, type, valid_format_regex, valid_format_description_key, audit_id, is_voided, rule, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, declarative_rule, group_id) values (40113, 'Extra Column', 1, false, '[]', 107583, 5570, '49c7a3eb-0edd-4cdd-bdc6-5ab2bd53da57', 0, 12, 'SingleSelect', null, null, create_audit(), false, null, 1, 1, '2022-04-17 17:51:18.414 +00:00', '2022-04-17 17:51:18.414 +00:00', null, null); +insert into form_element (name, display_order, is_mandatory, key_values, concept_id, form_element_group_id, uuid, version, organisation_id, type, valid_format_regex, valid_format_description_key, audit_id, is_voided, rule, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, declarative_rule, group_id) values ('Address Identifier Form Element', 2, false, '[]', (select id from concept where name = 'Address Identifier'), 5570, 'a92d5e17-72c8-4ba1-8dd3-1b0ec3aa0152', 0, 12, 'Text', null, null, create_audit(), false, null, 1, 1, '2022-04-17 17:51:18.414 +00:00', '2022-04-17 17:51:18.414 +00:00', null, null); -- General Encounter, Repeatable Question Group insert into form_element (id, name, display_order, is_mandatory, key_values, concept_id, form_element_group_id, uuid, version, organisation_id, type, valid_format_regex, valid_format_description_key, audit_id, is_voided, rule, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, declarative_rule, group_id) values (40114, 'Asset Info', 2, false, '[{"key": "repeatable", "value": true}]', 107584, 5571, 'dc6f83a5-0bfa-464f-a64a-3590ab1a1f86', 0, 12, null, null, null, create_audit(), false, null, 1, 1, '2022-04-17 17:51:18.414 +00:00', '2022-04-17 17:51:18.414 +00:00', null, null);