|
|
|
|
@@ -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();
|
|
|
|
|
|