Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge from os #48

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,17 +66,17 @@ 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,
ct.getTitles().getShort(),
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()
Expand All @@ -99,14 +100,14 @@ private void addTopicGroupIfNeeded(ConsultingTypeEntity consultingTypeEntity) {
topicGroups.forEach(
topicGroup ->
topicGroupMigrationService
.insertTopicGroupIfNotExists(convertToTranslateableJson(topicGroup))
.insertTopicGroupIfNotExistsOrReturnExistingTopicGroup(convertToTranslateableJson(topicGroup))
.ifPresent(
topicGroupId ->
topicGroupMigrationService.createTopicGroupRelationIfNotExists(
topicGroupId, consultingTypeEntity.getId())));
}

private String convertToTranslateableJson(String topicGroup) {
return "{ \"de\": \"" + topicGroup + "\"}";
return DE_JSON + topicGroup + "\"}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> insertTopicGroupIfNotExists(String groupName) {
public Optional<Integer> insertTopicGroupIfNotExistsOrReturnExistingTopicGroup(String groupName) {
if (groupName == null) {
log.info("Could not migrate topic with group null");
return Optional.empty();
Expand All @@ -34,7 +34,9 @@ public Optional<Integer> 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);
}
}

Expand Down
Loading