diff --git a/src/main/java/com/vi/migrationtool/consultingtypeservice/MigrateConsultingTypeDescriptionToTopicMigrationTask.java b/src/main/java/com/vi/migrationtool/consultingtypeservice/MigrateConsultingTypeDescriptionToTopicMigrationTask.java index d69b2a7..68a58ee 100644 --- a/src/main/java/com/vi/migrationtool/consultingtypeservice/MigrateConsultingTypeDescriptionToTopicMigrationTask.java +++ b/src/main/java/com/vi/migrationtool/consultingtypeservice/MigrateConsultingTypeDescriptionToTopicMigrationTask.java @@ -16,6 +16,7 @@ @Slf4j public class MigrateConsultingTypeDescriptionToTopicMigrationTask extends MigrationTasks { + private static final String DE_JSON = "{ \"de\": \""; private final JdbcTemplate consultingTypeServiceJdbcTemplate; private final JdbcTemplate agencyServiceJdbcTemplate; private final TopicGroupMigrationService topicGroupMigrationService; @@ -65,8 +66,8 @@ private void batchInsertTopicsWithIdEqualToConsultingTypeId( new Object[] { ct.getId(), ct.getTenantId(), - "{ \"de\": \"" + ct.getTitles().getShort() + "\"}", - "{ \"de\": \"" + ct.getDescription() + "\"}", + DE_JSON + ct.getTitles().getShort() + "\"}", + DE_JSON + ct.getDescription() + "\"}", "ACTIVE", formattedCurrentDateTime, formattedCurrentDateTime, @@ -74,8 +75,8 @@ private void batchInsertTopicsWithIdEqualToConsultingTypeId( null, ct.getUrls() != null ? ct.getUrls().getRegistrationPostcodeFallbackUrl() : "", ct.getSendFurtherStepsMessage(), - "{ \"de\": \"" + ct.getTitles().getShort() + "\"}", - "{ \"de\": \"" + ct.getTitles().getLong() + "\"}", + DE_JSON + ct.getTitles().getShort() + "\"}", + DE_JSON + ct.getTitles().getLong() + "\"}", ct.getTitles().getWelcome(), ct.getTitles().getRegistrationDropdown(), ct.getSlug() @@ -99,7 +100,7 @@ private void addTopicGroupIfNeeded(ConsultingTypeEntity consultingTypeEntity) { topicGroups.forEach( topicGroup -> topicGroupMigrationService - .insertTopicGroupIfNotExists(convertToTranslateableJson(topicGroup)) + .insertTopicGroupIfNotExistsOrReturnExistingTopicGroup(convertToTranslateableJson(topicGroup)) .ifPresent( topicGroupId -> topicGroupMigrationService.createTopicGroupRelationIfNotExists( @@ -107,6 +108,6 @@ private void addTopicGroupIfNeeded(ConsultingTypeEntity consultingTypeEntity) { } private String convertToTranslateableJson(String topicGroup) { - return "{ \"de\": \"" + topicGroup + "\"}"; + return DE_JSON + topicGroup + "\"}"; } } diff --git a/src/main/java/com/vi/migrationtool/consultingtypeservice/TopicGroupMigrationService.java b/src/main/java/com/vi/migrationtool/consultingtypeservice/TopicGroupMigrationService.java index cc372f4..48e76d8 100644 --- a/src/main/java/com/vi/migrationtool/consultingtypeservice/TopicGroupMigrationService.java +++ b/src/main/java/com/vi/migrationtool/consultingtypeservice/TopicGroupMigrationService.java @@ -16,7 +16,7 @@ public class TopicGroupMigrationService { "INSERT INTO topic_group (id, name) VALUES (NEXT VALUE FOR sequence_topic_group, ?)"; private JdbcTemplate consultingTypeJdbcTemplate; - public Optional insertTopicGroupIfNotExists(String groupName) { + public Optional insertTopicGroupIfNotExistsOrReturnExistingTopicGroup(String groupName) { if (groupName == null) { log.info("Could not migrate topic with group null"); return Optional.empty(); @@ -34,7 +34,9 @@ public Optional insertTopicGroupIfNotExists(String groupName) { log.info("Topic group inserted: " + groupName); return Optional.of(consultingTypeJdbcTemplate.queryForObject(idQuery, Integer.class)); } else { - return Optional.empty(); + String sql = "SELECT topic_group_id FROM topic_group WHERE name = ?"; + Integer id = consultingTypeJdbcTemplate.queryForObject(sql, Integer.class, groupName); + return Optional.of(id); } } diff --git a/src/main/resources/migrations/master-digi.xml b/src/main/resources/migrations/master-digi.xml index d8f8780..c68d210 100644 --- a/src/main/resources/migrations/master-digi.xml +++ b/src/main/resources/migrations/master-digi.xml @@ -25,6 +25,6 @@ - +