Compare commits

..

No commits in common. '16bf8eeeee98f6f2086d16397454bba26c83bfe8' and '523ec323eaa5d458eac66d6a885c79d5ec13c2b4' have entirely different histories.

@ -15,7 +15,6 @@ 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;
@ -38,7 +37,7 @@ public class MailController {
msg = "Invalid email address";
logger.error(msg, e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(msg);
} catch (MessagingException | SQLException | IOException | ServiceUnavailableException exception) {
} catch (MessagingException | SQLException | IOException 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);
stmt.setNull(4, Types.BLOB); // Assuming attachment column is of type BLOB
}
stmt.setString(5, parametersJson);
@ -85,8 +85,7 @@ public class MailDAOImpl implements MailDAO {
@Override
public List<MailModel> getUnsentMessages() {
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)";
String sql = "SELECT * FROM EMAIL WHERE UUID NOT IN (SELECT UUID FROM SENTEMAIL)";//use expiry date and use left join for get the id
List<MailModel> unsentMails = new ArrayList<>();
@ -104,6 +103,7 @@ public class MailDAOImpl implements MailDAO {
logger.info(e.getMessage());
throw new DatabaseAccessException("Error accessing database", e);
}
logger.info(unsentMails.toString());
return unsentMails;
}
@ -120,7 +120,6 @@ 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,7 +16,6 @@ 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;
@ -43,11 +42,11 @@ public class MailServiceImpl implements MailService {
@Autowired
private MailDAO mailDAO;
public void sendEmail(MailModel emailModel) throws MailException, SQLException, ServiceUnavailableException {
public void sendEmail(MailModel emailModel) throws MailException, SQLException {
if (shutdownRequested) {
String msg = "Server is shutting down. Mail requests will not be accepted.";
logger.info(msg);
throw new ServiceUnavailableException(msg);
throw new BadRequestException(msg);
}
if (isValidEmailAddress(emailModel.getEmailAddress())) {
@ -111,7 +110,7 @@ public class MailServiceImpl implements MailService {
}
//Store the sent mail to the table
// mailDAO.addToSentMail(prioritizedMail.getUuId());
mailDAO.addToSentMail(prioritizedMail.getUuId());
});
}
@ -127,7 +126,6 @@ public class MailServiceImpl implements MailService {
public void syncMailWithDB() {
try {
List<MailModel> mailModels = mailDAO.getUnsentMessages();
if (!mailModels.isEmpty()) {
mailQueueService.enqueMails(mailModels);
}
@ -138,7 +136,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 -> {
@ -164,6 +162,8 @@ public class MailServiceImpl implements MailService {
}
logger.info(prioritizedMail.getUuId());
//Store the sent mail to the table
mailDAO.addToSentMail(prioritizedMail.getUuId());

@ -5,13 +5,12 @@ 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, MailException, SQLException, ServiceUnavailableException;
void sendEmail(MailModel emailModel) throws MessagingException, IOException, BadRequestException, MailException, SQLException;
boolean isValidEmailAddress(String email);

Loading…
Cancel
Save