package it.hotel.model.mail;
import it.hotel.controller.locale.ILocaleContainer;
import it.hotel.model.CalendarUtils;
import it.hotel.model.booking.Booking;
import it.hotel.model.booking.manager.IBookingManager;
import java.util.Locale;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.util.StringUtils;
/**
*
*
*/
public class Mail {
private MailSender mailSender;
protected IBookingManager bookingManager;
protected ResourceBundleMessageSource messageSource;
private ILocaleContainer localeContainer;
private Locale local;
private boolean sendMail;
public boolean isSendMail() {
return sendMail;
}
public void setSendMail(boolean sendMail) {
this.sendMail = sendMail;
}
public Locale getLocal() {
return local;
}
public void setLocal(Locale local) {
this.local = local;
}
public void setLocaleContainer(ILocaleContainer localeContainer) {
this.localeContainer = localeContainer;
}
public void setMessageSource(ResourceBundleMessageSource messageSource) {
this.messageSource = messageSource;
}
public void setMailSender(MailSender mailSender) {
this.mailSender = mailSender;
}
public MailSender getMailSender() {
return mailSender;
}
/**
*
* @param booking
* @throws MailException
*/
public void sendMailHotel (Booking booking) throws MailException{
local = StringUtils.parseLocaleString(localeContainer.getLocale());
String text1=messageSource.getMessage("mailHotel1", null,local);
String text2=messageSource.getMessage("mailHotel2", null,local);
String text3=messageSource.getMessage("data.inizio", null,local);
String text4=messageSource.getMessage("data.fine", null,local);
String header=messageSource.getMessage("mailIntestazione", null,local);
//messageSource.getMe
SimpleMailMessage msg = new SimpleMailMessage();
String beginDate = CalendarUtils.GetDateAsString(booking.getBeginDate());
String finishDate = CalendarUtils.GetDateAsString(booking.getFinishDate());
msg.setText(text1 + booking.getCustomer().getName() + " " + booking.getCustomer().getSurname()+" " +text2+" "+booking.getRoom().getTypology().getName()+" "+ text3+" " + beginDate+" "+ text4+" "+finishDate);
msg.setTo(booking.getStructure().getMail());
msg.setFrom("labos@labos.com");
msg.setSubject(header+" " + booking.getStructure().getName());
sendMail(msg);
}
/**
*
* @param booking
* @throws MailException
*/
public void sendMailCustomer (Booking booking)throws MailException{
local = StringUtils.parseLocaleString(localeContainer.getLocale());
String text1=messageSource.getMessage("mailCustomer", null,local);
String text2=messageSource.getMessage("mailCustomer1", null,local);
String text3=messageSource.getMessage("data.inizio", null,local);
String text4=messageSource.getMessage("data.fine", null,local);
String header=messageSource.getMessage("mailIntestazione", null,local);
SimpleMailMessage msg = new SimpleMailMessage();
String beginDate = CalendarUtils.GetDateAsString(booking.getBeginDate());
String finishDate = CalendarUtils.GetDateAsString(booking.getFinishDate());
msg.setText(text1 +" "+ booking.getStructure().getName()+" " +text2+" "+booking.getRoom().getTypology().getName()+" "+ text3+" " + beginDate+" "+ text4+" "+finishDate);
msg.setTo(booking.getCustomer().getMail());
msg.setFrom("labos@labos.com");
msg.setSubject(header+" " + booking.getStructure().getName());
sendMail(msg);
}
/**
*
* @param booking
* @throws MailException
*/
public void sendMailEnable (Booking booking) throws MailException{
local = StringUtils.parseLocaleString(localeContainer.getLocale());
String text1=messageSource.getMessage("mailCustomer", null,local);
String text2=messageSource.getMessage("mailCustomer2", null,local);
String text3=messageSource.getMessage("data.inizio", null,local);
String text4=messageSource.getMessage("data.fine", null,local);
String text5=messageSource.getMessage("mailCustomer3", null,local);
String header=messageSource.getMessage("mailIntestazione", null,local);
SimpleMailMessage msg = new SimpleMailMessage();
String beginDate = CalendarUtils.GetDateAsString(booking.getBeginDate());
String finishDate = CalendarUtils.GetDateAsString(booking.getFinishDate());
msg.setText(text1 +" "+ booking.getStructure().getName()+" " +text2+" "+booking.getRoom().getTypology().getName()+" "+ text3+" " + beginDate+" "+ text4+" "+finishDate+ " "+text5);
msg.setTo(booking.getCustomer().getMail());
msg.setFrom("labos@labos.com");
msg.setSubject(header+" " + booking.getStructure().getName());
sendMail(msg);
}
/**
*
* @param booking
*/
public void sendMailPagamentoCustomer (Booking booking){
local = StringUtils.parseLocaleString(localeContainer.getLocale());
String text1=messageSource.getMessage("mailCustomer", null,local);
String text2=messageSource.getMessage("mailCustomer4", null,local);
String text3=messageSource.getMessage("data.inizio", null,local);
String text4=messageSource.getMessage("data.fine", null,local);
String text5=messageSource.getMessage("mailCustomer5", null,local);
String header=messageSource.getMessage("mailIntestazione", null,local);
SimpleMailMessage msg = new SimpleMailMessage();
String beginDate = CalendarUtils.GetDateAsString(booking.getBeginDate());
String finishDate = CalendarUtils.GetDateAsString(booking.getFinishDate());
msg.setText(text1 +" "+ booking.getStructure().getName()+" " +text2+" "+booking.getRoom().getTypology().getName()+" "+ text3+" " + beginDate+" "+ text4+" "+finishDate+ " "+text5+ " "+ booking.getStructure().getName());
msg.setTo(booking.getCustomer().getMail());
msg.setFrom("labos@labos.com");
msg.setSubject(header+" " + booking.getStructure().getName());
sendMail(msg);
}
/**
*
* @param booking
* @throws MailException
*/
public void sendMailPagamentoHotel (Booking booking) throws MailException{
local = StringUtils.parseLocaleString(localeContainer.getLocale());
String text1=messageSource.getMessage("mailHotel1", null,local);
String text2=messageSource.getMessage("mailHotelpagamento", null,local);
String text3=messageSource.getMessage("data.inizio", null,local);
String text4=messageSource.getMessage("data.fine", null,local);
String header=messageSource.getMessage("mailIntestazione", null,local);
//messageSource.getMe
SimpleMailMessage msg = new SimpleMailMessage();
String beginDate = CalendarUtils.GetDateAsString(booking.getBeginDate());
String finishDate = CalendarUtils.GetDateAsString(booking.getFinishDate());
msg.setText(text1 + booking.getCustomer().getName() + " " + booking.getCustomer().getSurname()+" " +text2+" "+booking.getRoom().getTypology().getName()+" "+ text3+" " + beginDate+" "+ text4+" "+finishDate);
msg.setTo(booking.getStructure().getMail());
msg.setFrom("labos@labos.com");
msg.setSubject(header+" " + booking.getStructure().getName());
sendMail(msg);
}
public void setBookingManager(IBookingManager bookingManager) {
this.bookingManager = bookingManager;
}
private void sendMail(SimpleMailMessage msg){
if (sendMail == true)
{
mailSender.send(msg);
}
}
}