Merge pull request 'uuid added for whole process' (#14) from get_connection into master

Reviewed-on: #14
master
commit 16bf8eeeee

@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.mail.MessagingException;
import javax.naming.ServiceUnavailableException;
import java.io.IOException;
import java.sql.SQLException;
@ -37,7 +38,7 @@ public class MailController {
msg = "Invalid email address";
logger.error(msg, e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(msg);
} catch (MessagingException | SQLException | IOException exception) {
} catch (MessagingException | SQLException | IOException | ServiceUnavailableException exception) {
msg = "Failed to send email";
logger.error(msg, exception);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(msg + exception);

@ -56,7 +56,7 @@ public class MailDAOImpl implements MailDAO {
if (mailModel.getAttachment() != null) {
stmt.setBytes(4, mailModel.getAttachment().getBytes());
} else {
stmt.setNull(4, Types.BLOB); // Assuming attachment column is of type BLOB
stmt.setNull(4, Types.BLOB);
}
stmt.setString(5, parametersJson);
@ -85,7 +85,8 @@ public class MailDAOImpl implements MailDAO {
@Override
public List<MailModel> getUnsentMessages() {
String sql = "SELECT * FROM EMAIL WHERE UUID NOT IN (SELECT UUID FROM SENTEMAIL)";//use expiry date and use left join for get the id
String sql = "SELECT E.* FROM EMAIL E LEFT JOIN SENTEMAIL SE ON E.UUID = SE.UUID WHERE SE.UUID IS NULL AND (E.EXPIRY_AT IS NULL OR E.EXPIRY_AT > CURRENT_DATE)";
List<MailModel> unsentMails = new ArrayList<>();
@ -103,7 +104,6 @@ public class MailDAOImpl implements MailDAO {
logger.info(e.getMessage());
throw new DatabaseAccessException("Error accessing database", e);
}
logger.info(unsentMails.toString());
return unsentMails;
}
@ -120,6 +120,7 @@ public class MailDAOImpl implements MailDAO {
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
mailModel.setEmailId(rs.getInt("EMAIL_ID"));
mailModel.setUuId(rs.getString("UUID"));
mailModel.setEmailAddress(rs.getString("EMAIL_ADDRESS"));
mailModel.setMsgTemplate(rs.getString("MSG_TEMPLATE"));
mailModel.setPriority(rs.getInt("PRIORITY"));

@ -16,6 +16,7 @@ import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import javax.naming.ServiceUnavailableException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@ -42,11 +43,11 @@ public class MailServiceImpl implements MailService {
@Autowired
private MailDAO mailDAO;
public void sendEmail(MailModel emailModel) throws MailException, SQLException {
public void sendEmail(MailModel emailModel) throws MailException, SQLException, ServiceUnavailableException {
if (shutdownRequested) {
String msg = "Server is shutting down. Mail requests will not be accepted.";
logger.info(msg);
throw new BadRequestException(msg);
throw new ServiceUnavailableException(msg);
}
if (isValidEmailAddress(emailModel.getEmailAddress())) {
@ -110,7 +111,7 @@ public class MailServiceImpl implements MailService {
}
//Store the sent mail to the table
mailDAO.addToSentMail(prioritizedMail.getUuId());
// mailDAO.addToSentMail(prioritizedMail.getUuId());
});
}
@ -126,6 +127,7 @@ public class MailServiceImpl implements MailService {
public void syncMailWithDB() {
try {
List<MailModel> mailModels = mailDAO.getUnsentMessages();
if (!mailModels.isEmpty()) {
mailQueueService.enqueMails(mailModels);
}
@ -136,7 +138,7 @@ public class MailServiceImpl implements MailService {
while (PriorityQueueHolder.getInstance().getPriorityQueue().peek() != null) {
MailModel prioritizedMail = mailDAO.getMailDetails(mailQueueService.getHighPriorityMail().getUuId());
logger.info("uuid : " ,prioritizedMail.getUuId());
javaMailSender.send(mimeMessage -> {
@ -162,8 +164,6 @@ public class MailServiceImpl implements MailService {
}
logger.info(prioritizedMail.getUuId());
//Store the sent mail to the table
mailDAO.addToSentMail(prioritizedMail.getUuId());

@ -5,12 +5,13 @@ import entgra.mailsender.exception.BadRequestException;
import entgra.mailsender.exception.MailException;
import javax.mail.MessagingException;
import javax.naming.ServiceUnavailableException;
import java.io.IOException;
import java.sql.SQLException;
public interface MailService {
void sendEmail(MailModel emailModel) throws MessagingException, IOException, BadRequestException, MailException, SQLException;
void sendEmail(MailModel emailModel) throws MessagingException, IOException, MailException, SQLException, ServiceUnavailableException;
boolean isValidEmailAddress(String email);

Loading…
Cancel
Save