Updated code for the email signature while sending emails

This commit is contained in:
rajesh
2024-10-30 15:34:50 +05:30
parent 8360822009
commit 4b11d463e2
12 changed files with 125 additions and 29 deletions

View File

@@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import net.gepafin.tendermanagement.entities.CallEntity;
import net.gepafin.tendermanagement.entities.HubEntity;
import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity;
import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum;
import net.gepafin.tendermanagement.model.response.SystemEmailTemplateResponse;
@@ -25,24 +25,27 @@ public class SystemEmailTemplatesDao {
@Value("${fe.base.url}")
private String feBaseUrl;
@Value("${default.email.signature}")
private String defaultEmailSignature;
public SystemEmailTemplateResponse retrieveTemplate(SystemEmailTemplatesEntityTypeEnum type, CallEntity call, Locale language) {
public SystemEmailTemplateResponse retrieveTemplate(SystemEmailTemplatesEntityTypeEnum type, HubEntity hub, Locale language) {
SystemEmailTemplatesEntity dbSystemEmailTemplatesEntity = null;
if(call != null){
if(hub != null){
// dbSystemEmailTemplatesEntity = systemEmailTemplatesRespository
// .findByTypeAndCallId(type.getValue(), call.getId());
}
if(dbSystemEmailTemplatesEntity == null){
if(dbSystemEmailTemplatesEntity == null) {
dbSystemEmailTemplatesEntity = systemEmailTemplatesRespository
.findByType(type.getValue());
}
SystemEmailTemplateResponse systemEmailTemplateResponse = replaceHtmlContant(dbSystemEmailTemplatesEntity, call, language, Boolean.TRUE);
SystemEmailTemplateResponse systemEmailTemplateResponse = replaceHtmlContant(dbSystemEmailTemplatesEntity, hub, language, Boolean.TRUE);
return systemEmailTemplateResponse;
}
private SystemEmailTemplateResponse replaceHtmlContant(SystemEmailTemplatesEntity dbSystemEmailTemplatesEntity,
CallEntity call, Locale language1, Boolean isDefaultReplace) {
HubEntity hub, Locale language1, Boolean isDefaultReplace) {
String language = null;
String htmlContent = dbSystemEmailTemplatesEntity.getHtmlContent();
String subject = dbSystemEmailTemplatesEntity.getSubject();
@@ -69,7 +72,8 @@ public class SystemEmailTemplatesDao {
}
htmlContent = replacePlatformLinkPlaceholder(call, htmlContent, languageMap);
htmlContent = replacePlatformLinkPlaceholderAndEmailSignature(hub, htmlContent, languageMap);
subject = replacePlatformLinkPlaceholderAndEmailSignature(hub, subject, languageMap);
SystemEmailTemplateResponse systemEmailTemplateResponse = new SystemEmailTemplateResponse();
systemEmailTemplateResponse.setHtmlContent(htmlContent);
systemEmailTemplateResponse.setSubject(subject);
@@ -102,15 +106,28 @@ public class SystemEmailTemplatesDao {
}
return "";
}
private String replacePlatformLinkPlaceholder(CallEntity call, String htmlContent,
private String replacePlatformLinkPlaceholderAndEmailSignature(HubEntity hub, String htmlContent,
Map<String, String> languageMap) {
String platformLink = feBaseUrl;
htmlContent = replacePlatformLinkPlaceholder(hub, htmlContent, languageMap);
htmlContent = replaceEmailSignature(hub, htmlContent, languageMap);
// if(hubEntity != null && Boolean.FALSE.equals(isEmpty(hubEntity.getDomainName()))){
// platformLink = hubEntity.getDomainName();
// }
htmlContent = htmlContent.replace("{{platform_link}}", platformLink);
return htmlContent;
}
private String replaceEmailSignature(HubEntity hub, String htmlContent, Map<String, String> languageMap) {
String emailSignature = defaultEmailSignature;
if(hub != null && Boolean.FALSE.equals(StringUtils.isEmpty(hub.getEmailSignature()))){
emailSignature = hub.getEmailSignature();
}
return htmlContent.replace("{{email_signature}}", emailSignature);
}
private String replacePlatformLinkPlaceholder(HubEntity hub, String htmlContent, Map<String, String> languageMap) {
String platformLink = feBaseUrl;
if(hub != null && Boolean.FALSE.equals(StringUtils.isEmpty(hub.getDomainName()))){
platformLink = hub.getDomainName();
}
return htmlContent.replace("{{platform_link}}", platformLink);
}
}