|
|
|
@ -38,7 +38,7 @@ public class MailDAOImpl implements MailDAO {
|
|
|
|
|
PreparedStatement stmt;
|
|
|
|
|
int generatedId;
|
|
|
|
|
Connection conn = this.getConnection();
|
|
|
|
|
stmt = conn.prepareStatement("INSERT INTO email (EMAIL_ADDRESS, MSG_TEMPLATE, PRIORITY, ATTACHMENT, PARAMETERS, TIME, FILENAME, EXPIRY_AT) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", PreparedStatement.RETURN_GENERATED_KEYS);
|
|
|
|
|
stmt = conn.prepareStatement("INSERT INTO EMAIL (EMAIL_ADDRESS, MSG_TEMPLATE, PRIORITY, ATTACHMENT, PARAMETERS, TIME, FILENAME, EXPIRY_AT) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", PreparedStatement.RETURN_GENERATED_KEYS);
|
|
|
|
|
Timestamp current_time = new Timestamp(System.currentTimeMillis());
|
|
|
|
|
String parametersJson = new ObjectMapper().writeValueAsString(mailModel.getParameters());
|
|
|
|
|
stmt.setString(1, mailModel.getEmailAddress());
|
|
|
|
@ -70,7 +70,7 @@ public class MailDAOImpl implements MailDAO {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<MailModel> getUnsentMessages() {
|
|
|
|
|
String sql = "SELECT * FROM email WHERE email_id NOT IN (SELECT email_id FROM sentEmail)";
|
|
|
|
|
String sql = "SELECT * FROM EMAIL WHERE EMAIL_ID NOT IN (SELECT EMAIL_ID FROM SENTEMAIL)";
|
|
|
|
|
|
|
|
|
|
List<MailModel> unsentMails = new ArrayList<>();
|
|
|
|
|
|
|
|
|
@ -79,9 +79,9 @@ public class MailDAOImpl implements MailDAO {
|
|
|
|
|
ResultSet rs = statement.executeQuery()) {
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
MailModel mailModel = new MailModel();
|
|
|
|
|
mailModel.setEmailId(rs.getInt("email_id"));
|
|
|
|
|
mailModel.setPriority(rs.getInt("priority"));
|
|
|
|
|
mailModel.setExpiry_at(rs.getDate("expiry_at"));
|
|
|
|
|
mailModel.setEmailId(rs.getInt("EMAIL_ID"));
|
|
|
|
|
mailModel.setPriority(rs.getInt("PRIORITY"));
|
|
|
|
|
mailModel.setExpiry_at(rs.getDate("EXPIRY_AT"));
|
|
|
|
|
unsentMails.add(mailModel);
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
@ -94,7 +94,7 @@ public class MailDAOImpl implements MailDAO {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public MailModel getMailDetails(Integer mail_id) {
|
|
|
|
|
String sql = "SELECT * FROM email WHERE email_id = ?";
|
|
|
|
|
String sql = "SELECT * FROM EMAIL WHERE EMAIL_ID = ?";
|
|
|
|
|
MailModel mailModel = new MailModel();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
@ -103,19 +103,19 @@ public class MailDAOImpl implements MailDAO {
|
|
|
|
|
stmt.setInt(1, mail_id);
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) {
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
mailModel.setEmailId(rs.getInt("email_id"));
|
|
|
|
|
mailModel.setEmailAddress(rs.getString("email_address"));
|
|
|
|
|
mailModel.setMsgTemplate(rs.getString("msg_template"));
|
|
|
|
|
mailModel.setPriority(rs.getInt("priority"));
|
|
|
|
|
mailModel.setEmailId(rs.getInt("EMAIL_ID"));
|
|
|
|
|
mailModel.setEmailAddress(rs.getString("EMAIL_ADDRESS"));
|
|
|
|
|
mailModel.setMsgTemplate(rs.getString("MSG_TEMPLATE"));
|
|
|
|
|
mailModel.setPriority(rs.getInt("PRIORITY"));
|
|
|
|
|
|
|
|
|
|
String jsonData = rs.getString("parameters");
|
|
|
|
|
String jsonData = rs.getString("PARAMETERS");
|
|
|
|
|
List<MailModel.Parameter> parameters = parseJsonParameters(jsonData);
|
|
|
|
|
mailModel.setParameters(parameters);
|
|
|
|
|
|
|
|
|
|
String filename = rs.getString("filename");
|
|
|
|
|
String filename = rs.getString("FILENAME");
|
|
|
|
|
mailModel.setFilename(filename);
|
|
|
|
|
|
|
|
|
|
Blob blob = rs.getBlob("attachment");
|
|
|
|
|
Blob blob = rs.getBlob("ATTACHMENT");
|
|
|
|
|
File file = convertBlobToFile(blob, filename);
|
|
|
|
|
mailModel.setFile(file);
|
|
|
|
|
}
|
|
|
|
@ -161,7 +161,7 @@ public class MailDAOImpl implements MailDAO {
|
|
|
|
|
try {
|
|
|
|
|
PreparedStatement stmt;
|
|
|
|
|
Connection connection = this.getConnection();
|
|
|
|
|
stmt = connection.prepareStatement("INSERT INTO sentEmail (email_id,sent_time) VALUE (?,?)");
|
|
|
|
|
stmt = connection.prepareStatement("INSERT INTO SENTEMAIL (EMAIL_ID,SENT_TIME) VALUE (?,?)");
|
|
|
|
|
stmt.setInt(1, mail_id);
|
|
|
|
|
stmt.setDate(2, Date.valueOf(LocalDate.now()));
|
|
|
|
|
stmt.execute();
|
|
|
|
|