in ddm-notification-service/src/main/java/com/epam/digital/data/platform/notification/service/SaveDefaultNotificationTemplateService.java [62:84]
private NotificationTemplate saveTemplate(
String channel, String name, SaveNotificationTemplateInputDto inputDto) {
var templateOpt = notificationTemplateRepository.findByNameAndChannel(name, channel);
if (templateOpt.isEmpty()) {
log.info("Template does not exist, creating new");
var newTemplate = buildTemplateFromInput(channel, name, inputDto);
return notificationTemplateRepository.save(newTemplate);
} else {
var template = templateOpt.get();
var inputContentChecksum = DigestUtils.sha256Hex(inputDto.getContent());
if (StringUtils.equals(inputContentChecksum, template.getChecksum())
&& StringUtils.equals(inputDto.getTitle(), template.getTitle())) {
log.info("No update for template");
return template;
} else {
log.info("Updating existing template");
template.setContent(inputDto.getContent());
template.setChecksum(inputContentChecksum);
template.setTitle(inputDto.getTitle());
return notificationTemplateRepository.save(template);
}
}
}