Done ticket GEPAFINBE-183

This commit is contained in:
Piyush
2025-03-17 16:36:21 +05:30
parent e061f734ec
commit 3f4d997aba
9 changed files with 169 additions and 24 deletions

View File

@@ -490,6 +490,9 @@ public class GepafinConstant {
public static final String REGION_ID="regionId";
public static final String EMAIL_SUPPORT = "email_support";
public static final String PHONE_SUPPORT = "phone_support";
}

View File

@@ -24,11 +24,11 @@ import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.util.Validator;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.ForbiddenAccessException;
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -40,10 +40,8 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.Map;
import java.util.stream.Collectors;
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
@@ -77,7 +75,13 @@ public class UserDao {
@Value("${default.hub.uuid}")
private String defaultHubUuid;
@Value("${app.confidi.login.url.suffix}")
private String confidiLogin;
@Value("${app.bandi.login.url.suffix}")
private String bandiLoginUrlSuffix;
@Autowired
private Validator validator;
@@ -139,35 +143,57 @@ public class UserDao {
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).newData(userEntity).build());
if(beneficiary == null){
sendEmailToOnboardingUser(userEntity);
sendEmailToOnboardingUser(userEntity, userReq );
}
return token;
}
public void sendEmailToOnboardingUser(UserEntity userEntity){
SystemEmailTemplateResponse emailTemplate = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(
SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.USER_ONBOARDING, userEntity.getHub(), null);
public void sendEmailToOnboardingUser(UserEntity userEntity,UserReq userReq){
SystemEmailTemplateResponse emailTemplate;
RoleStatusEnum roleStatus = RoleStatusEnum.valueOf(userEntity.getRoleEntity().getRoleType());
SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum templateType =
roleStatus.equals(RoleStatusEnum.ROLE_CONFIDI)
? SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.USER_ONBOARDING_CONFIDI
: SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.USER_ONBOARDING_BANDI;
emailTemplate = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(templateType, userEntity.getHub(), null);
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(emailTemplate.getEmailScenario(), RecipientTypeEnum.USER, userEntity.getId(), userEntity.getEmail(),
userEntity.getId(), null, null, null);
String firstName = userEntity.getFirstName() != null ? userEntity.getFirstName() : "";
String lastName = userEntity.getLastName() != null ? userEntity.getLastName() : "";
String userName = String.join(" ", firstName, lastName).trim();
String subject = Utils.replacePlaceholders(emailTemplate.getSubject(), Map.of(
"{{user_name}}", userName
));
String body = Utils.replacePlaceholders(emailTemplate.getHtmlContent(), Map.of(
"{{user_name}}", userName,
"{{user_email}}", userEntity.getEmail()
));
Map<String, String> placeholders = replacePlaceholders(userEntity, userReq);
String body = Utils.replacePlaceholders(emailTemplate.getHtmlContent(), placeholders);
emailNotificationDao.sendMail(
userEntity.getHub().getId(),
subject,
emailTemplate.getSubject(),
body,
List.of(userEntity.getEmail()),
emailLogRequest
);
}
private BeneficiaryEntity createBeneficiary(RoleEntity roleEntity, UserReq userReq, HubEntity hub) {
private Map<String, String> replacePlaceholders(UserEntity userEntity, UserReq userReq) {
RoleStatusEnum roleStatus = RoleStatusEnum.valueOf(userEntity.getRoleEntity().getRoleType());
String confidiLoginUrl = userEntity.getHub().getDomainName() + confidiLogin;
String bandiLoginUrl = userEntity.getHub().getDomainName() + bandiLoginUrlSuffix;
String hubConfigText = userEntity.getHub().getHubConfig();
JSONObject hubConfig = new JSONObject(hubConfigText);
String gepafinEmail = hubConfig.optString(GepafinConstant.EMAIL_SUPPORT, "");
String gepafinPhoneNumber = hubConfig.optString(GepafinConstant.PHONE_SUPPORT, "");
Map<String, String> placeholders = new HashMap<>();
placeholders.put("{{username}}", userEntity.getEmail());
placeholders.put("{{userpassword}}",userReq.getPassword());
String loginUrl = roleStatus.equals(RoleStatusEnum.ROLE_CONFIDI) ? confidiLoginUrl : bandiLoginUrl;
placeholders.put("{{login_url}}",loginUrl);
placeholders.put("{{gepafinphonenumber}}", gepafinPhoneNumber);
placeholders.put("{{gepafinemail}}", gepafinEmail);
return placeholders;
}
private BeneficiaryEntity createBeneficiary(RoleEntity roleEntity, UserReq userReq, HubEntity hub) {
BeneficiaryEntity beneficiaryEntity = null;
if (RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleEntity.getRoleType())) {
beneficiaryEntity = new BeneficiaryEntity();

View File

@@ -66,4 +66,7 @@ public class HubEntity extends BaseEntity{
@Column(name = "EVALUATION_EXPIRATION_DAYS")
private Long evaluationExpirationDays;
@Column(name = "HUB_CONFIG")
private String hubConfig;
}

View File

@@ -52,10 +52,10 @@ public class SystemEmailTemplatesEntity extends BaseEntity {
INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE("INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE"),
ADMISSIBILITY_NOTIFICATION("ADMISSIBILITY_NOTIFICATION"),
AMENDMENT_REMINDER("AMENDMENT_REMINDER"),
USER_ONBOARDING("USER_ONBOARDING"),
USER_ONBOARDING_CONFIDI("USER_ONBOARDING_CONFIDI"),
USER_ONBOARDING_BANDI("USER_ONBOARDING_BANDI"),
PASSWORD_RESET("PASSWORD_RESET"),
INADMISSIBILITY_TEMPLATE("INADMISSIBILITY_NOTIFICATION");
private String value;
SystemEmailTemplatesEntityTypeEnum(String value) {