Commit 9c90c6a1 authored by Vijay Akula's avatar Vijay Akula

Handled the exceptions raising while getting functionalOrgs

parent b368a146
......@@ -14,7 +14,6 @@ import com.nisum.myteam.statuscodes.EmployeeStatus;
import com.nisum.myteam.utils.MyTeamUtils;
import com.nisum.myteam.utils.constants.EmpSubStatus;
import com.nisum.myteam.utils.constants.Shifts;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -60,7 +59,7 @@ public class LeaveNotificationScheduler {
// private final String SHIFT5_CRON_EXP=environment.getProperty("email.leave.notification.shift5.cron");
//@Scheduled(cron = "0 * * * * ?")
// @Scheduled(cron = "0 * * * * ?")
@Scheduled(cron = "00 00 15 * * 1-5")
public void scheduleLeaveMailForShift1Empls() throws IOException, MessagingException, MyTeamException {
//Shift 1(9:00 AM - 6:00 PM)
......@@ -132,14 +131,13 @@ public class LeaveNotificationScheduler {
logger.info("Mail Notification is sending to:" + absentee.getEmployeeName() + "::" + absentee.getEmailId());
mail.setEmpName(absentee.getEmployeeName());
mail.setTo(absentee.getEmailId());
//mail.setEmpName("Prayas");
//mail.setTo("pjain@nisum.com");
mail.setTo(absentee.getEmailId());//mail.setEmpName("Prayas");//mail.setTo("pjain@nisum.com");
functionalGroup = functionalGroupService.getFunctionalGroup(employee.getFunctionalGroup());
mail.setCc(new String[]{functionalGroup.getGroupHeadEmailId()});
//mail.setCc(new String[]{"prayasjain21@gmail.com"});
if (functionalGroup != null) {
mail.setCc(new String[]{functionalGroup.getGroupHeadEmailId()});//mail.setCc(new String[]{"prayasjain21@gmail.com"});
}
mailService.sendLeaveNotification(mail);
}
......
......@@ -3,38 +3,34 @@
*/
package com.nisum.myteam.service.impl;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import com.nisum.myteam.model.EmailDomain;
import com.nisum.myteam.model.Mail;
import com.nisum.myteam.service.IMailService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import com.nisum.myteam.model.EmailDomain;
import com.nisum.myteam.service.IMailService;
import com.nisum.myteam.model.Mail;
import org.springframework.util.ResourceUtils;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring4.SpringTemplateEngine;
import java.nio.charset.StandardCharsets;
import org.springframework.core.io.ClassPathResource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.springframework.core.env.Environment;
import java.util.Date;
/**
* @author nisum
*
*/
@Service
@Slf4j
public class MailService implements IMailService {
private static final Logger logger = LoggerFactory.getLogger(MailService.class);
......@@ -92,9 +88,7 @@ public class MailService implements IMailService {
}
public void sendLeaveNotification(Mail mail) throws MessagingException, IOException
{
public void sendLeaveNotification(Mail mail) throws MessagingException, IOException {
MimeMessage message = emailSender.createMimeMessage();
//MimeMessageHelper helper = new MimeMessageHelper(message,MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,StandardCharsets.UTF_8.name());
//Context context = new Context();
......@@ -103,20 +97,20 @@ public class MailService implements IMailService {
MimeMessageHelper helper = new MimeMessageHelper(message);
File file = ResourceUtils.getFile("classpath:"+environment.getProperty("email.leave.notification.template.file.path"));
File file = ResourceUtils.getFile("classpath:" + environment.getProperty("email.leave.notification.template.file.path"));
//Read File Content
String content = new String(Files.readAllBytes(file.toPath()));
content=content.replaceAll("employeeName",mail.getEmpName());
//System.out.println(content);
content = content.replaceAll("employeeName", mail.getEmpName());
helper.setTo(mail.getTo());
helper.setText(content, true);
helper.setSubject(mail.getSubject());
helper.setFrom(mail.getFrom());
helper.setCc(mail.getCc());
//helper.setBcc(mail.getBcc());
if (mail.getCc() != null) {
helper.setCc(mail.getCc());//helper.setBcc(mail.getBcc());//log.info("Mail Content::"+content);//log.info("The Mail Object::"+mail);
}
emailSender.send(message);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment