Search in sources :

Example 1 with MailForGroupIdAdded

use of cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdAdded in project perun by CESNET.

the class MailManagerImpl method addMail.

@Override
@Transactional(rollbackFor = Exception.class)
public Integer addMail(PerunSession sess, ApplicationForm form, ApplicationMail mail) throws ApplicationMailExistsException, PrivilegeException {
    // Authorization
    if (form.getGroup() != null) {
        if (!AuthzResolver.authorizedInternal(sess, "group-addMail_ApplicationForm_ApplicationMail_policy", Arrays.asList(form.getGroup(), form.getVo()))) {
            throw new PrivilegeException(sess, "addMail");
        }
    } else {
        if (!AuthzResolver.authorizedInternal(sess, "vo-addMail_ApplicationForm_ApplicationMail_policy", Collections.singletonList(form.getVo()))) {
            throw new PrivilegeException(sess, "addMail");
        }
    }
    int id = Utils.getNewId(jdbc, "APPLICATION_MAILS_ID_SEQ");
    mail.setId(id);
    try {
        jdbc.update("insert into application_mails(id, form_id, app_type, mail_type, send) values (?,?,?,?,?)", mail.getId(), form.getId(), mail.getAppType().toString(), mail.getMailType().toString(), mail.getSend());
    } catch (DuplicateKeyException e) {
        throw new ApplicationMailExistsException("Application mail already exists.", mail);
    }
    for (Locale loc : mail.getMessage().keySet()) {
        try {
            jdbc.update("insert into application_mail_texts(mail_id,locale,subject,text) values (?,?,?,?)", mail.getId(), loc.toString(), mail.getMessage(loc).getSubject(), mail.getMessage(loc).getText());
        } catch (DuplicateKeyException e) {
            throw new ApplicationMailExistsException("Application mail already exists.", mail);
        }
    }
    log.info("[MAIL MANAGER] Mail notification definition created: {}", mail);
    if (form.getGroup() != null) {
        perun.getAuditer().log(sess, new MailForGroupIdAdded(mail, form.getGroup()));
    } else {
        perun.getAuditer().log(sess, new MailForVoIdAdded(mail, form.getVo()));
    }
    return id;
}
Also used : MailForGroupIdAdded(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdAdded) ApplicationMailExistsException(cz.metacentrum.perun.registrar.exceptions.ApplicationMailExistsException) MailForVoIdAdded(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdAdded) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

MailForGroupIdAdded (cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdAdded)1 MailForVoIdAdded (cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdAdded)1 ApplicationMailExistsException (cz.metacentrum.perun.registrar.exceptions.ApplicationMailExistsException)1 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)1 Transactional (org.springframework.transaction.annotation.Transactional)1