Class MailService

  • All Implemented Interfaces:
    IMailService, org.springframework.beans.factory.InitializingBean

    @Service
    public class MailService
    extends Object
    implements IMailService, org.springframework.beans.factory.InitializingBean
    The MailService class provides the Mail Service implementation.
    Author:
    Marcus Portmann
    • Constructor Detail

      • MailService

        public MailService​(org.springframework.context.ApplicationContext applicationContext,
                           javax.validation.Validator validator,
                           MailTemplateRepository mailTemplateRepository,
                           MailTemplateSummaryRepository mailTemplateSummaryRepository)
        Constructs a new MailService.
        Parameters:
        applicationContext - the Spring application context
        validator - the JSR-303 validator
        mailTemplateRepository - the Mail Template Repository
        mailTemplateSummaryRepository - the Mail Template Summary Repository
    • Method Detail

      • afterPropertiesSet

        public void afterPropertiesSet()
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      • createMailTemplate

        @Transactional
        @CachePut(cacheNames="mailTemplates",
                  key="#mailTemplate.id")
        public MailTemplate createMailTemplate​(MailTemplate mailTemplate)
                                        throws africa.absa.inception.core.service.InvalidArgumentException,
                                               DuplicateMailTemplateException,
                                               africa.absa.inception.core.service.ServiceUnavailableException
        Description copied from interface: IMailService
        Create the new mail template.
        Specified by:
        createMailTemplate in interface IMailService
        Parameters:
        mailTemplate - the MailTemplate instance containing the information for the new mail template
        Returns:
        the mail template
        Throws:
        africa.absa.inception.core.service.InvalidArgumentException - if an argument is invalid
        DuplicateMailTemplateException - if the mail template already exists
        africa.absa.inception.core.service.ServiceUnavailableException - if the mail template could not be created
      • deleteMailTemplate

        @Transactional
        @CacheEvict(cacheNames="mailTemplates",
                    key="#mailTemplateId")
        public void deleteMailTemplate​(String mailTemplateId)
                                throws africa.absa.inception.core.service.InvalidArgumentException,
                                       MailTemplateNotFoundException,
                                       africa.absa.inception.core.service.ServiceUnavailableException
        Description copied from interface: IMailService
        Delete the existing mail template.
        Specified by:
        deleteMailTemplate in interface IMailService
        Parameters:
        mailTemplateId - the ID for the mail template
        Throws:
        africa.absa.inception.core.service.InvalidArgumentException - if an argument is invalid
        MailTemplateNotFoundException - if the mail template could not be found
        africa.absa.inception.core.service.ServiceUnavailableException - if the mail template could not be deleted
      • getMailTemplate

        @Cacheable(cacheNames="mailTemplates",
                   key="#mailTemplateId")
        public MailTemplate getMailTemplate​(String mailTemplateId)
                                     throws africa.absa.inception.core.service.InvalidArgumentException,
                                            MailTemplateNotFoundException,
                                            africa.absa.inception.core.service.ServiceUnavailableException
        Description copied from interface: IMailService
        Retrieve the mail template.
        Specified by:
        getMailTemplate in interface IMailService
        Parameters:
        mailTemplateId - the ID for the mail template
        Returns:
        the mail template
        Throws:
        africa.absa.inception.core.service.InvalidArgumentException - if an argument is invalid
        MailTemplateNotFoundException - if the mail template could not be found
        africa.absa.inception.core.service.ServiceUnavailableException - if the mail template could not be retrieved
      • getMailTemplateName

        public String getMailTemplateName​(String mailTemplateId)
                                   throws africa.absa.inception.core.service.InvalidArgumentException,
                                          MailTemplateNotFoundException,
                                          africa.absa.inception.core.service.ServiceUnavailableException
        Description copied from interface: IMailService
        Retrieve the name of the mail template.
        Specified by:
        getMailTemplateName in interface IMailService
        Parameters:
        mailTemplateId - the ID for the mail template
        Returns:
        the name of the mail template
        Throws:
        africa.absa.inception.core.service.InvalidArgumentException - if an argument is invalid
        MailTemplateNotFoundException - if the mail template could not be found
        africa.absa.inception.core.service.ServiceUnavailableException - if the name of the mail template could not be retrieved
      • getMailTemplateSummaries

        public List<MailTemplateSummary> getMailTemplateSummaries()
                                                           throws africa.absa.inception.core.service.ServiceUnavailableException
        Description copied from interface: IMailService
        Returns the summaries for all the mail templates.
        Specified by:
        getMailTemplateSummaries in interface IMailService
        Returns:
        the summaries for all the mail templates
        Throws:
        africa.absa.inception.core.service.ServiceUnavailableException - if the mail template summaries could not be retrieved
      • getMailTemplateSummary

        public MailTemplateSummary getMailTemplateSummary​(String mailTemplateId)
                                                   throws africa.absa.inception.core.service.InvalidArgumentException,
                                                          MailTemplateNotFoundException,
                                                          africa.absa.inception.core.service.ServiceUnavailableException
        Description copied from interface: IMailService
        Retrieve the summary for the mail template.
        Specified by:
        getMailTemplateSummary in interface IMailService
        Parameters:
        mailTemplateId - the ID for the mail template
        Returns:
        the summary for the mail template
        Throws:
        africa.absa.inception.core.service.InvalidArgumentException - if an argument is invalid
        MailTemplateNotFoundException - if the mail template could not be found
        africa.absa.inception.core.service.ServiceUnavailableException - if the mail template summary could not be retrieved
      • getMailTemplateUpdated

        public LocalDateTime getMailTemplateUpdated​(String mailTemplateId)
                                             throws africa.absa.inception.core.service.InvalidArgumentException,
                                                    MailTemplateNotFoundException,
                                                    africa.absa.inception.core.service.ServiceUnavailableException
        Description copied from interface: IMailService
        Returns the date and time the mail template was last updated.
        Specified by:
        getMailTemplateUpdated in interface IMailService
        Parameters:
        mailTemplateId - the ID for the mail template
        Returns:
        the date and time the mail template was last updated
        Throws:
        africa.absa.inception.core.service.InvalidArgumentException - if an argument is invalid
        MailTemplateNotFoundException - if the mail template could not be found
        africa.absa.inception.core.service.ServiceUnavailableException - if the date and time the mail template was last updated could not be retrieved
      • getMailTemplates

        public List<MailTemplate> getMailTemplates()
                                            throws africa.absa.inception.core.service.ServiceUnavailableException
        Description copied from interface: IMailService
        Returns all the mail templates.
        Specified by:
        getMailTemplates in interface IMailService
        Returns:
        the mail templates
        Throws:
        africa.absa.inception.core.service.ServiceUnavailableException - if the mail templates could not be retrieved
      • mailTemplateExists

        public boolean mailTemplateExists​(String mailTemplateId)
                                   throws africa.absa.inception.core.service.InvalidArgumentException,
                                          africa.absa.inception.core.service.ServiceUnavailableException
        Description copied from interface: IMailService
        Check whether the mail template exists.
        Specified by:
        mailTemplateExists in interface IMailService
        Parameters:
        mailTemplateId - the ID for the mail template
        Returns:
        true if the mail template exists or false otherwise
        Throws:
        africa.absa.inception.core.service.InvalidArgumentException - if an argument is invalid
        africa.absa.inception.core.service.ServiceUnavailableException - if the check for the existing mail template failed
      • processMailTemplate

        public String processMailTemplate​(String mailTemplateId,
                                          Map<String,​String> templateParameters)
                                   throws africa.absa.inception.core.service.InvalidArgumentException,
                                          africa.absa.inception.core.service.ServiceUnavailableException
        Description copied from interface: IMailService
        Process the mail template.
        Specified by:
        processMailTemplate in interface IMailService
        Parameters:
        mailTemplateId - the ID for the mail template
        templateParameters - the template parameters
        Returns:
        the output of processing the template
        Throws:
        africa.absa.inception.core.service.InvalidArgumentException - if an argument is invalid
        africa.absa.inception.core.service.ServiceUnavailableException - if the mail template processing failed
      • sendMail

        public void sendMail​(List<String> to,
                             String subject,
                             String from,
                             String fromName,
                             String mailTemplateId,
                             Map<String,​String> mailTemplateParameters)
                      throws africa.absa.inception.core.service.InvalidArgumentException,
                             MailTemplateNotFoundException,
                             africa.absa.inception.core.service.ServiceUnavailableException
        Description copied from interface: IMailService
        Send a mail.
        Specified by:
        sendMail in interface IMailService
        Parameters:
        to - the list of e-mail addresses to send the mail to
        subject - the subject for the mail
        from - the from e-mail address
        fromName - the from e-mail name
        mailTemplateId - the ID for the mail template
        mailTemplateParameters - the parameters to apply to the mail template
        Throws:
        africa.absa.inception.core.service.InvalidArgumentException - if an argument is invalid
        MailTemplateNotFoundException - if the mail template could not be found
        africa.absa.inception.core.service.ServiceUnavailableException - if the mail could not be sent
      • updateMailTemplate

        @Transactional
        @CachePut(cacheNames="mailTemplates",
                  key="#mailTemplate.id")
        public MailTemplate updateMailTemplate​(MailTemplate mailTemplate)
                                        throws africa.absa.inception.core.service.InvalidArgumentException,
                                               MailTemplateNotFoundException,
                                               africa.absa.inception.core.service.ServiceUnavailableException
        Description copied from interface: IMailService
        Update the mail template.
        Specified by:
        updateMailTemplate in interface IMailService
        Parameters:
        mailTemplate - the MailTemplate instance containing the updated information for the mail template
        Returns:
        the mail template
        Throws:
        africa.absa.inception.core.service.InvalidArgumentException - if an argument is invalid
        MailTemplateNotFoundException - if the mail template could not be found
        africa.absa.inception.core.service.ServiceUnavailableException - if the mail template could not be updated