use of cz.metacentrum.perun.registrar.model.ApplicationMail.MailType in project perun by CESNET.
the class MailManagerImpl method getMailByParams.
/**
* Retrieve mail definition from db by params.
* Mail contains all texts.
* If mail not exists, or no texts exists null is returned.
*
* @param formId relation to VO form
* @param appType application type
* @param mailType mail type
* @return mail if definition exists or null
*/
private ApplicationMail getMailByParams(Integer formId, AppType appType, MailType mailType) {
ApplicationMail mail;
// We want to use the initial notifications for the embedded applications
if (appType == AppType.EMBEDDED) {
appType = AppType.INITIAL;
}
// get mail def
try {
List<ApplicationMail> mails = jdbc.query(MAILS_SELECT_BY_PARAMS, (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")), formId, appType.toString(), mailType.toString());
// set
if (mails.size() != 1) {
log.error("[MAIL MANAGER] Wrong number of mail definitions returned by unique params, expected 1 but was: {}", mails.size());
return null;
}
mail = mails.get(0);
} catch (EmptyResultDataAccessException ex) {
return null;
}
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"HmacSHA256"
log.error("[MAIL MANAGER] Mail do not contains any text message.", ex);
return null;
}
texts.forEach(mt -> mail.getMessage().put(mt.getLocale(), mt));
return mail;
}
Aggregations