use of cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdUpdated in project perun by CESNET.
the class MailManagerImpl method updateMailById.
@Override
@Transactional(rollbackFor = Exception.class)
public void updateMailById(PerunSession sess, ApplicationMail mail) throws FormNotExistsException, ApplicationMailNotExistsException, PrivilegeException {
ApplicationForm form = registrarManager.getFormById(sess, mail.getFormId());
int numberOfExistences = jdbc.queryForInt("select count(1) from application_mails where id=?", mail.getId());
if (numberOfExistences < 1)
throw new ApplicationMailNotExistsException("Application mail does not exist.", mail);
if (numberOfExistences > 1)
throw new ConsistencyErrorException("There is more than one mail with id = " + mail.getId());
// update sending (enabled / disabled)
jdbc.update("update application_mails set send=? where id=?", mail.getSend(), mail.getId());
// update texts (easy way = delete and new insert)
jdbc.update("delete from application_mail_texts where mail_id=?", mail.getId());
for (Locale loc : mail.getMessage().keySet()) {
MailText text = mail.getMessage(loc);
jdbc.update("insert into application_mail_texts(mail_id,locale,subject,text) values (?,?,?,?)", mail.getId(), loc.toString(), text.getSubject(), text.getText());
}
if (form.getGroup() != null) {
perun.getAuditer().log(sess, new MailForGroupIdUpdated(mail, form.getGroup()));
} else {
perun.getAuditer().log(sess, new MailForVoIdUpdated(mail, form.getVo()));
}
}
Aggregations