PEC service is enabled only on the production server
This commit is contained in:
@@ -26,6 +26,9 @@ public class PecEmailService implements EmailService {
|
||||
@Value("${isMailSendingEnabled}")
|
||||
private String isEmailSendingEnabled;
|
||||
|
||||
@Value("${isPecServiceEnabled}")
|
||||
private String isPecServiceEnabled;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@@ -55,23 +58,27 @@ public class PecEmailService implements EmailService {
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
||||
emailLogRequest.setRecipientEmails(Utils.listToCommaSeparatedString(emailRequest.getRecipient()));
|
||||
try {
|
||||
Unirest.setTimeouts(0, 0);
|
||||
response2 = Unirest.post(url)
|
||||
.header("Authorization", "Bearer " + authToken)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(Utils.convertObjectToJson(emailRequest)) // Serialize the emailRequest object to JSON
|
||||
.asString();
|
||||
if (Boolean.TRUE.equals(Boolean.parseBoolean(isPecServiceEnabled))) {
|
||||
Unirest.setTimeouts(0, 0);
|
||||
response2 = Unirest.post(url)
|
||||
.header("Authorization", "Bearer " + authToken)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(Utils.convertObjectToJson(emailRequest)) // Serialize the emailRequest object to JSON
|
||||
.asString();
|
||||
}
|
||||
}catch(Exception e) {
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE);
|
||||
emailLogRequest.setErrorMessage(e.getMessage());
|
||||
EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest);
|
||||
emailLogDao.createEmailLog(emailLogRequest);
|
||||
throw new RuntimeException("Failed to send email via PEC: " + response2.getStatus());
|
||||
}
|
||||
emailLogRequest.setEmailServiceResponse(response2.getBody());
|
||||
if(response2 != null) {
|
||||
emailLogRequest.setEmailServiceResponse(response2.getBody());
|
||||
}
|
||||
}
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE);
|
||||
EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest);
|
||||
emailLogDao.createEmailLog(emailLogRequest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user