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