diff --git a/src/main/java/org/avniproject/etl/repository/sync/MediaTableSyncAction.java b/src/main/java/org/avniproject/etl/repository/sync/MediaTableSyncAction.java index 53b2e8a..f6a160f 100644 --- a/src/main/java/org/avniproject/etl/repository/sync/MediaTableSyncAction.java +++ b/src/main/java/org/avniproject/etl/repository/sync/MediaTableSyncAction.java @@ -137,7 +137,7 @@ private String wrapInQuotes(String parameter) { } private String wrapStringValue(String parameter) { - return parameter == null ? "null" : "'" + parameter + "'"; + return parameter == null ? "null" : "'" + parameter.replace("'", "''") + "'"; } public static boolean equalsButNotBothNull(Object a, Object b) { diff --git a/src/test/java/org/avniproject/etl/DataSyncIntegrationTest.java b/src/test/java/org/avniproject/etl/DataSyncIntegrationTest.java index fcac247..c88f669 100644 --- a/src/test/java/org/avniproject/etl/DataSyncIntegrationTest.java +++ b/src/test/java/org/avniproject/etl/DataSyncIntegrationTest.java @@ -297,7 +297,7 @@ public void allTablesHaveAddressIdAndIndividualIdColumns() { public void shouldPopulateMediaTable() { runDataSync(); List> media = jdbcTemplate.queryForList("select * from orgc.media;"); - assertThat(media.size(), is(2)); + assertThat(media.size(), is(3)); } @Test @@ -306,14 +306,14 @@ public void shouldPopulateMediaTable() { public void shouldPopulateMediaTableCorrectlyWhenTransactionalDataUpdates() throws InterruptedException { runDataSync(); List> media = jdbcTemplate.queryForList("select * from orgc.media;"); - assertThat("Verifying current value of media table", media.size(), is(2)); + assertThat("Verifying current value of media table", media.size(), is(3)); String newEncounterImage = "https://s3.amazon.com/newEncounterImage.jpg"; jdbcTemplate.execute("update encounter set observations = observations || jsonb_build_object('44163589-f76d-447d-9b6e-f5c32aa859eb', '" + newEncounterImage + "'), last_modified_date_time = now() where id = 1900;"); runDataSync(); media = jdbcTemplate.queryForList("select * from orgc.media;"); - assertThat("Media table number of rows has not changed since last run", media.size(), is(2)); + assertThat("Media table number of rows has not changed since last run", media.size(), is(3)); Optional> encounterMedia = media.stream().filter(stringObjectMap -> (Integer.valueOf(1900)).equals(stringObjectMap.get("entity_id"))).findAny(); assertThat(encounterMedia.isPresent(), is(true)); @@ -331,7 +331,7 @@ public void arrayStyleMediaObservationsCreateMultipleRowsInMediaTable() throws I runDataSync(); List> media = jdbcTemplate.queryForList("select * from orgc.media;"); - assertThat("Media table number of rows has not changed since last run", media.size(), is(3)); + assertThat("Media table number of rows has not changed since last run", media.size(), is(4)); } @Test diff --git a/src/test/resources/media-form-element.sql b/src/test/resources/media-form-element.sql index fcf5721..b2b97bc 100644 --- a/src/test/resources/media-form-element.sql +++ b/src/test/resources/media-form-element.sql @@ -1,7 +1,10 @@ -- Person 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 (108001, 'Image', null, null, null, null, 'Image concept', '44163589-f76d-447d-9b6e-f5c32aa859eb', 0, null, 12, false, create_audit(), null, true, 1, 1, '2022-04-13 15:49:55.019 +00:00', '2022-04-13 15:49:55.019 +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 (108002, 'Image', null, null, null, null, 'Person''s Image','b1815016-40d6-4045-9ae0-2f659fc5db6d', 0, null, 12, false, create_audit(), null, true, 1, 1, '2022-04-13 15:49:55.019 +00:00', '2022-04-13 15:49:55.019 +00:00'); 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) values (50116, 'Media form element', 8, false, '[]', 108001, 5569, 'fd5ad16f-c18e-45db-841c-a2f994862957', 0, 12, 'SingleSelect', null, null, create_audit(), false, null, 1, 1, '2022-04-13 10:51:44.705 +00:00', '2022-04-13 10:51:44.705 +00:00', 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) values (50117, 'Media form element', 15, false, '[]', 108002, 5569, 'ec952777-67b2-47c2-bd7c-8e277547cb6b', 0, 12, 'SingleSelect', null, null, create_audit(), false, null, 1, 1, '2022-04-13 10:51:44.705 +00:00', '2022-04-13 10:51:44.705 +00:00', null); update individual set observations = observations || jsonb_build_object('44163589-f76d-447d-9b6e-f5c32aa859eb', 'https://s3.amazon.com/wonderfulImage.jpg'), last_modified_date_time = '2022-04-13 10:51:44.705 +00:00' where subject_type_id = 339; +update individual set observations = observations || jsonb_build_object('b1815016-40d6-4045-9ae0-2f659fc5db6d', 'https://s3.amazon.com/wonderfulImage.jpg'), last_modified_date_time = '2022-04-13 10:51:44.705 +00:00' where subject_type_id = 339; -- Encounter