Search in sources :

Example 1 with MailForGroupIdUpdated

use of cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdUpdated 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()));
    }
}
Also used : ApplicationForm(cz.metacentrum.perun.registrar.model.ApplicationForm) ApplicationMailNotExistsException(cz.metacentrum.perun.registrar.exceptions.ApplicationMailNotExistsException) MailForGroupIdUpdated(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdUpdated) MailText(cz.metacentrum.perun.registrar.model.ApplicationMail.MailText) MailForVoIdUpdated(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdUpdated) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

MailForGroupIdUpdated (cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdUpdated)1 MailForVoIdUpdated (cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdUpdated)1 ApplicationMailNotExistsException (cz.metacentrum.perun.registrar.exceptions.ApplicationMailNotExistsException)1 ApplicationForm (cz.metacentrum.perun.registrar.model.ApplicationForm)1 MailText (cz.metacentrum.perun.registrar.model.ApplicationMail.MailText)1 Transactional (org.springframework.transaction.annotation.Transactional)1