use of cz.metacentrum.perun.registrar.exceptions.ApplicationMailExistsException 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;
}
Aggregations