Skip to content

Commit

Permalink
Merge pull request #48 from Onlineberatung/develop
Browse files Browse the repository at this point in the history
merge from os
  • Loading branch information
tkuzynow authored May 9, 2024
2 parents c2748ae + 2179c22 commit 2c46d6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
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

0 comments on commit 2c46d6b

Please sign in to comment.