use of cz.metacentrum.perun.registrar.model.ApplicationMail.MailText in project perun by CESNET.
the class MailManagerImpl method getApplicationMails.
@Override
public List<ApplicationMail> getApplicationMails(PerunSession sess, ApplicationForm form) throws PerunException {
List<ApplicationMail> mails = new ArrayList<ApplicationMail>();
mails = jdbc.query(MAILS_SELECT_BY_FORM_ID, new RowMapper<ApplicationMail>() {
@Override
public ApplicationMail mapRow(ResultSet rs, int arg1) throws SQLException {
return new ApplicationMail(rs.getInt("id"), AppType.valueOf(rs.getString("app_type")), rs.getInt("form_id"), MailType.valueOf(rs.getString("mail_type")), rs.getBoolean("send"));
}
}, form.getId());
for (ApplicationMail mail : mails) {
List<MailText> texts = new ArrayList<MailText>();
texts = jdbc.query(MAIL_TEXTS_SELECT_BY_MAIL_ID, new RowMapper<MailText>() {
@Override
public MailText mapRow(ResultSet rs, int arg1) throws SQLException {
return new MailText(new Locale(rs.getString("locale")), rs.getString("subject"), rs.getString("text"));
}
}, mail.getId());
for (MailText text : texts) {
// fil localized messages
mail.getMessage().put(text.getLocale(), text);
}
}
return mails;
}
use of cz.metacentrum.perun.registrar.model.ApplicationMail.MailText in project perun by CESNET.
the class MailManagerImpl method getMailTextInvitation.
private String getMailTextInvitation(ApplicationMail mail, Locale lang, Vo vo, Group group, User user, String name) {
MailText mt = mail.getMessage(lang);
String mailText = EMPTY_STRING;
if (mt.getText() != null && !mt.getText().isEmpty()) {
mailText = mt.getText();
mailText = substituteCommonStringsForInvite(vo, group, user, name, mailText);
}
return mailText;
}
use of cz.metacentrum.perun.registrar.model.ApplicationMail.MailText in project perun by CESNET.
the class MailManagerImpl method getMailById.
@Override
public ApplicationMail getMailById(PerunSession sess, Integer id) throws ApplicationMailNotExistsException {
// TODO authz
ApplicationMail mail;
// get mail def
try {
String query = "select id,app_type,form_id,mail_type,send from application_mails where id=?";
List<ApplicationMail> mails = jdbc.query(query, (resultSet, arg1) -> new ApplicationMail(resultSet.getInt("id"), AppType.valueOf(resultSet.getString("app_type")), resultSet.getInt("form_id"), MailType.valueOf(resultSet.getString("mail_type")), resultSet.getBoolean("send")), id);
// set
if (mails.size() > 1) {
log.error("[MAIL MANAGER] Wrong number of mail definitions returned by unique params, expected 1 but was: {}.", mails.size());
throw new ConsistencyErrorException("Wrong number of mail definitions returned by unique params, expected 1 but was: " + mails.size());
}
mail = mails.get(0);
} catch (EmptyResultDataAccessException ex) {
throw new ApplicationMailNotExistsException("Mail definition with ID=" + id + " doesn't exists.");
}
List<MailText> texts;
try {
texts = jdbc.query(MAIL_TEXTS_SELECT_BY_MAIL_ID, (resultSet, arg1) -> new MailText(new Locale(resultSet.getString("locale")), resultSet.getString("subject"), resultSet.getString("text")), mail.getId());
} catch (EmptyResultDataAccessException ex) {
// if no texts it's error
log.error("[MAIL MANAGER] Mail does not contain any text message.", ex);
return mail;
}
for (MailText text : texts) {
// fill localized messages
mail.getMessage().put(text.getLocale(), text);
}
return mail;
}
use of cz.metacentrum.perun.registrar.model.ApplicationMail.MailText 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()));
}
}
use of cz.metacentrum.perun.registrar.model.ApplicationMail.MailText in project perun by CESNET.
the class MailManagerImpl method getMailSubject.
private String getMailSubject(ApplicationMail mail, Locale lang, Application app, List<ApplicationFormItemData> data, String reason, List<Exception> exceptions) {
MailText mt = mail.getMessage(lang);
String mailSubject = EMPTY_STRING;
if (mt.getText() != null && !mt.getText().isEmpty()) {
mailSubject = mt.getSubject();
mailSubject = substituteCommonStrings(app, data, mailSubject, reason, exceptions);
}
// substitute common strings
return mailSubject;
}
Aggregations