Search in sources :

Example 11 with ApplicationMail

use of cz.metacentrum.perun.registrar.model.ApplicationMail in project perun by CESNET.

the class MailManagerImpl method copyMailsFromVoToGroup.

@Override
public void copyMailsFromVoToGroup(PerunSession sess, Vo fromVo, Group toGroup, boolean reverse) throws PerunException {
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, fromVo)) {
        throw new PrivilegeException(sess, "copyMailsFromVoToVo");
    }
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, toGroup) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, toGroup)) {
        throw new PrivilegeException(sess, "copyMailsFromVoToVo");
    }
    if (reverse) {
        // copy notifications from Group to VO
        ApplicationForm voForm = registrarManager.getFormForVo(fromVo);
        ApplicationForm groupForm = registrarManager.getFormForGroup(toGroup);
        List<ApplicationMail> mails = getApplicationMails(sess, groupForm);
        for (ApplicationMail mail : mails) {
            // to start transaction
            try {
                registrarManager.getMailManager().addMail(sess, voForm, mail);
            } catch (DuplicateKeyException ex) {
                log.info("[MAIL MANAGER] Mail notification of type {} skipped while copying (was already present).", mail.getMailType() + "/" + mail.getAppType());
            }
        }
    } else {
        // copy notifications from VO to Group
        ApplicationForm voForm = registrarManager.getFormForVo(fromVo);
        ApplicationForm groupForm = registrarManager.getFormForGroup(toGroup);
        List<ApplicationMail> mails = getApplicationMails(sess, voForm);
        for (ApplicationMail mail : mails) {
            // to start transaction
            try {
                registrarManager.getMailManager().addMail(sess, groupForm, mail);
            } catch (DuplicateKeyException ex) {
                log.info("[MAIL MANAGER] Mail notification of type {} skipped while copying (was already present).", mail.getMailType() + "/" + mail.getAppType());
            }
        }
    }
}
Also used : ApplicationForm(cz.metacentrum.perun.registrar.model.ApplicationForm) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) ApplicationMail(cz.metacentrum.perun.registrar.model.ApplicationMail)

Example 12 with ApplicationMail

use of cz.metacentrum.perun.registrar.model.ApplicationMail in project perun by CESNET.

the class MailManagerImpl method deleteMailById.

@Override
public void deleteMailById(PerunSession sess, ApplicationForm form, Integer id) throws PerunException {
    if (form.getGroup() != null) {
        if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, form.getVo()) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, form.getGroup())) {
            throw new PrivilegeException(sess, "deleteMail");
        }
    } else {
        if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, form.getVo())) {
            throw new PrivilegeException(sess, "deleteMail");
        }
    }
    ApplicationMail mail = getMailById(sess, id);
    int result = jdbc.update("delete from application_mails where id=?", id);
    if (result == 0)
        throw new InternalErrorException("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, "Mail ID: {} of Type: {} removed for Group ID: {}.", id, mail.getMailType() + "/" + mail.getAppType(), form.getGroup().getId());
    } else {
        perun.getAuditer().log(sess, "Mail ID: {} of Type: {} removed for VO ID: {}.", id, mail.getMailType() + "/" + mail.getAppType(), form.getVo().getId());
    }
}
Also used : ApplicationMail(cz.metacentrum.perun.registrar.model.ApplicationMail)

Aggregations

ApplicationMail (cz.metacentrum.perun.registrar.model.ApplicationMail)12 ApplicationForm (cz.metacentrum.perun.registrar.model.ApplicationForm)8 MailText (cz.metacentrum.perun.registrar.model.ApplicationMail.MailText)7 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)6 SQLException (java.sql.SQLException)5 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)5 RegistrarException (cz.metacentrum.perun.registrar.exceptions.RegistrarException)4 ResultSet (java.sql.ResultSet)3 RowMapper (org.springframework.jdbc.core.RowMapper)3 MailException (org.springframework.mail.MailException)3 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)3 Application (cz.metacentrum.perun.registrar.model.Application)2 ApplicationFormItem (cz.metacentrum.perun.registrar.model.ApplicationFormItem)1 ApplicationFormItemData (cz.metacentrum.perun.registrar.model.ApplicationFormItemData)1 MailType (cz.metacentrum.perun.registrar.model.ApplicationMail.MailType)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Test (org.junit.Test)1 Transactional (org.springframework.transaction.annotation.Transactional)1