Package africa.absa.inception.mail
Class MailService
- java.lang.Object
-
- africa.absa.inception.mail.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 Summary
Constructors Constructor Description MailService(org.springframework.context.ApplicationContext applicationContext, javax.validation.Validator validator, MailTemplateRepository mailTemplateRepository, MailTemplateSummaryRepository mailTemplateSummaryRepository)Constructs a new MailService.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()MailTemplatecreateMailTemplate(MailTemplate mailTemplate)Create the new mail template.voiddeleteMailTemplate(String mailTemplateId)Delete the existing mail template.MailTemplategetMailTemplate(String mailTemplateId)Retrieve the mail template.StringgetMailTemplateName(String mailTemplateId)Retrieve the name of the mail template.List<MailTemplate>getMailTemplates()Returns all the mail templates.List<MailTemplateSummary>getMailTemplateSummaries()Returns the summaries for all the mail templates.MailTemplateSummarygetMailTemplateSummary(String mailTemplateId)Retrieve the summary for the mail template.LocalDateTimegetMailTemplateUpdated(String mailTemplateId)Returns the date and time the mail template was last updated.booleanmailTemplateExists(String mailTemplateId)Check whether the mail template exists.StringprocessMailTemplate(String mailTemplateId, Map<String,String> templateParameters)Process the mail template.voidsendMail(List<String> to, String subject, String from, String fromName, String mailTemplateId, Map<String,String> mailTemplateParameters)Send a mail.MailTemplateupdateMailTemplate(MailTemplate mailTemplate)Update the mail template.
-
-
-
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 contextvalidator- the JSR-303 validatormailTemplateRepository- the Mail Template RepositorymailTemplateSummaryRepository- the Mail Template Summary Repository
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet()
- Specified by:
afterPropertiesSetin interfaceorg.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.ServiceUnavailableExceptionDescription copied from interface:IMailServiceCreate the new mail template.- Specified by:
createMailTemplatein interfaceIMailService- 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 invalidDuplicateMailTemplateException- if the mail template already existsafrica.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.ServiceUnavailableExceptionDescription copied from interface:IMailServiceDelete the existing mail template.- Specified by:
deleteMailTemplatein interfaceIMailService- Parameters:
mailTemplateId- the ID for the mail template- Throws:
africa.absa.inception.core.service.InvalidArgumentException- if an argument is invalidMailTemplateNotFoundException- if the mail template could not be foundafrica.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.ServiceUnavailableExceptionDescription copied from interface:IMailServiceRetrieve the mail template.- Specified by:
getMailTemplatein interfaceIMailService- Parameters:
mailTemplateId- the ID for the mail template- Returns:
- the mail template
- Throws:
africa.absa.inception.core.service.InvalidArgumentException- if an argument is invalidMailTemplateNotFoundException- if the mail template could not be foundafrica.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:IMailServiceRetrieve the name of the mail template.- Specified by:
getMailTemplateNamein interfaceIMailService- 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 invalidMailTemplateNotFoundException- if the mail template could not be foundafrica.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:IMailServiceReturns the summaries for all the mail templates.- Specified by:
getMailTemplateSummariesin interfaceIMailService- 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:IMailServiceRetrieve the summary for the mail template.- Specified by:
getMailTemplateSummaryin interfaceIMailService- 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 invalidMailTemplateNotFoundException- if the mail template could not be foundafrica.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:IMailServiceReturns the date and time the mail template was last updated.- Specified by:
getMailTemplateUpdatedin interfaceIMailService- 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 invalidMailTemplateNotFoundException- if the mail template could not be foundafrica.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:IMailServiceReturns all the mail templates.- Specified by:
getMailTemplatesin interfaceIMailService- 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:IMailServiceCheck whether the mail template exists.- Specified by:
mailTemplateExistsin interfaceIMailService- 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 invalidafrica.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:IMailServiceProcess the mail template.- Specified by:
processMailTemplatein interfaceIMailService- Parameters:
mailTemplateId- the ID for the mail templatetemplateParameters- the template parameters- Returns:
- the output of processing the template
- Throws:
africa.absa.inception.core.service.InvalidArgumentException- if an argument is invalidafrica.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:IMailServiceSend a mail.- Specified by:
sendMailin interfaceIMailService- Parameters:
to- the list of e-mail addresses to send the mail tosubject- the subject for the mailfrom- the from e-mail addressfromName- the from e-mail namemailTemplateId- the ID for the mail templatemailTemplateParameters- the parameters to apply to the mail template- Throws:
africa.absa.inception.core.service.InvalidArgumentException- if an argument is invalidMailTemplateNotFoundException- if the mail template could not be foundafrica.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.ServiceUnavailableExceptionDescription copied from interface:IMailServiceUpdate the mail template.- Specified by:
updateMailTemplatein interfaceIMailService- 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 invalidMailTemplateNotFoundException- if the mail template could not be foundafrica.absa.inception.core.service.ServiceUnavailableException- if the mail template could not be updated
-
-