Search in sources :

Example 1 with MailType

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;
}
Also used : Message(javax.mail.Message) JdbcPerunTemplate(org.springframework.jdbc.core.JdbcPerunTemplate) ApplicationMailNotExistsException(cz.metacentrum.perun.registrar.exceptions.ApplicationMailNotExistsException) RegistrarManagerImpl(cz.metacentrum.perun.registrar.impl.RegistrarManagerImpl) LoggerFactory(org.slf4j.LoggerFactory) SecretKeySpec(javax.crypto.spec.SecretKeySpec) MessagingException(javax.mail.MessagingException) Autowired(org.springframework.beans.factory.annotation.Autowired) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) cz.metacentrum.perun.core.api(cz.metacentrum.perun.core.api) ApplicationMailExistsException(cz.metacentrum.perun.registrar.exceptions.ApplicationMailExistsException) MailManager(cz.metacentrum.perun.registrar.MailManager) MembersManagerBl(cz.metacentrum.perun.core.bl.MembersManagerBl) ApplicationMailAlreadyRemovedException(cz.metacentrum.perun.registrar.exceptions.ApplicationMailAlreadyRemovedException) Matcher(java.util.regex.Matcher) ApplicationMail(cz.metacentrum.perun.registrar.model.ApplicationMail) cz.metacentrum.perun.core.api.exceptions(cz.metacentrum.perun.core.api.exceptions) UsersManagerBl(cz.metacentrum.perun.core.bl.UsersManagerBl) BigInteger(java.math.BigInteger) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) ApplicationForm(cz.metacentrum.perun.registrar.model.ApplicationForm) RegistrarException(cz.metacentrum.perun.registrar.exceptions.RegistrarException) MailForVoIdUpdated(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdUpdated) MailSending(cz.metacentrum.perun.audit.events.MailManagerEvents.MailSending) URN_GROUP_FROM_EMAIL(cz.metacentrum.perun.registrar.impl.RegistrarManagerImpl.URN_GROUP_FROM_EMAIL) Mac(javax.crypto.Mac) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) ApplicationFormItemData(cz.metacentrum.perun.registrar.model.ApplicationFormItemData) StandardCharsets(java.nio.charset.StandardCharsets) Application(cz.metacentrum.perun.registrar.model.Application) Pattern(java.util.regex.Pattern) MailException(org.springframework.mail.MailException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) java.util(java.util) MailForGroupIdRemoved(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdRemoved) MailForVoIdAdded(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdAdded) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) MailText(cz.metacentrum.perun.registrar.model.ApplicationMail.MailText) MailType(cz.metacentrum.perun.registrar.model.ApplicationMail.MailType) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) InternetAddress(javax.mail.internet.InternetAddress) MailSentForApplication(cz.metacentrum.perun.audit.events.MailManagerEvents.MailSentForApplication) DataSource(javax.sql.DataSource) AuthzResolverBlImpl(cz.metacentrum.perun.core.blImpl.AuthzResolverBlImpl) URN_VO_FROM_EMAIL(cz.metacentrum.perun.registrar.impl.RegistrarManagerImpl.URN_VO_FROM_EMAIL) FormNotExistsException(cz.metacentrum.perun.registrar.exceptions.FormNotExistsException) MailForGroupIdAdded(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdAdded) Logger(org.slf4j.Logger) AppType(cz.metacentrum.perun.registrar.model.Application.AppType) ApplicationFormItem(cz.metacentrum.perun.registrar.model.ApplicationFormItem) RegistrarManager(cz.metacentrum.perun.registrar.RegistrarManager) MimeMessage(javax.mail.internet.MimeMessage) URLEncoder(java.net.URLEncoder) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) java.io(java.io) Utils(cz.metacentrum.perun.core.impl.Utils) MailForVoIdRemoved(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdRemoved) MailForGroupIdUpdated(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdUpdated) URN_GROUP_FROM_NAME_EMAIL(cz.metacentrum.perun.registrar.impl.RegistrarManagerImpl.URN_GROUP_FROM_NAME_EMAIL) InvitationSentEvent(cz.metacentrum.perun.audit.events.MailManagerEvents.InvitationSentEvent) Transactional(org.springframework.transaction.annotation.Transactional) MailText(cz.metacentrum.perun.registrar.model.ApplicationMail.MailText) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) ApplicationMail(cz.metacentrum.perun.registrar.model.ApplicationMail)

Aggregations

AuditEvent (cz.metacentrum.perun.audit.events.AuditEvent)1 InvitationSentEvent (cz.metacentrum.perun.audit.events.MailManagerEvents.InvitationSentEvent)1 MailForGroupIdAdded (cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdAdded)1 MailForGroupIdRemoved (cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdRemoved)1 MailForGroupIdUpdated (cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdUpdated)1 MailForVoIdAdded (cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdAdded)1 MailForVoIdRemoved (cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdRemoved)1 MailForVoIdUpdated (cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdUpdated)1 MailSending (cz.metacentrum.perun.audit.events.MailManagerEvents.MailSending)1 MailSentForApplication (cz.metacentrum.perun.audit.events.MailManagerEvents.MailSentForApplication)1 cz.metacentrum.perun.core.api (cz.metacentrum.perun.core.api)1 cz.metacentrum.perun.core.api.exceptions (cz.metacentrum.perun.core.api.exceptions)1 AttributesManagerBl (cz.metacentrum.perun.core.bl.AttributesManagerBl)1 GroupsManagerBl (cz.metacentrum.perun.core.bl.GroupsManagerBl)1 MembersManagerBl (cz.metacentrum.perun.core.bl.MembersManagerBl)1 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)1 UsersManagerBl (cz.metacentrum.perun.core.bl.UsersManagerBl)1 AuthzResolverBlImpl (cz.metacentrum.perun.core.blImpl.AuthzResolverBlImpl)1 Utils (cz.metacentrum.perun.core.impl.Utils)1 MailManager (cz.metacentrum.perun.registrar.MailManager)1