Search in sources :

Example 1 with MailForVoIdRemoved

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

the class MailManagerImpl method deleteMailById.

@Override
public void deleteMailById(PerunSession sess, ApplicationForm form, Integer id) throws ApplicationMailAlreadyRemovedException, PrivilegeException, ApplicationMailNotExistsException {
    // Authorization
    if (form.getGroup() != null) {
        if (!AuthzResolver.authorizedInternal(sess, "group-deleteMailById_ApplicationForm_Integer_policy", Arrays.asList(form.getGroup(), form.getVo()))) {
            throw new PrivilegeException(sess, "deleteMailById");
        }
    } else {
        if (!AuthzResolver.authorizedInternal(sess, "vo-deleteMailById_ApplicationForm_Integer_policy", Collections.singletonList(form.getVo()))) {
            throw new PrivilegeException(sess, "deleteMailById");
        }
    }
    ApplicationMail mail = getMailById(sess, id);
    int result = jdbc.update("delete from application_mails where id=?", id);
    if (result == 0)
        throw new ApplicationMailAlreadyRemovedException("Mail notification with id=" + id + " doesn't exists!");
    if (result == 1)
        log.info("[MAIL MANAGER] Mail notification with id={} deleted", id);
    if (result > 1)
        throw new ConsistencyErrorException("There is more than one mail notification with id=" + id);
    if (form.getGroup() != null) {
        perun.getAuditer().log(sess, new MailForGroupIdRemoved(mail, form.getGroup()));
    } else {
        perun.getAuditer().log(sess, new MailForVoIdRemoved(mail, form.getVo()));
    }
}
Also used : MailForGroupIdRemoved(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdRemoved) ApplicationMailAlreadyRemovedException(cz.metacentrum.perun.registrar.exceptions.ApplicationMailAlreadyRemovedException) ApplicationMail(cz.metacentrum.perun.registrar.model.ApplicationMail) MailForVoIdRemoved(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdRemoved)

Aggregations

MailForGroupIdRemoved (cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdRemoved)1 MailForVoIdRemoved (cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdRemoved)1 ApplicationMailAlreadyRemovedException (cz.metacentrum.perun.registrar.exceptions.ApplicationMailAlreadyRemovedException)1 ApplicationMail (cz.metacentrum.perun.registrar.model.ApplicationMail)1