Commit ec3c5d20 authored by Vijay Akula's avatar Vijay Akula

Resolved the issue while sending the mail

parent 3e557516
...@@ -27,6 +27,7 @@ import javax.mail.MessagingException; ...@@ -27,6 +27,7 @@ import javax.mail.MessagingException;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -58,8 +59,8 @@ public class LeaveNotificationScheduler { ...@@ -58,8 +59,8 @@ public class LeaveNotificationScheduler {
private SubStatusService subStatusService; private SubStatusService subStatusService;
//@Scheduled(cron = "${email.leave.notification.shift1.cron}") @Scheduled(cron = "${email.leave.notification.shift1.cron}")
@Scheduled(cron = "0 * * * * ?") //@Scheduled(cron = "0 * * * * ?")
public void scheduleLeaveMailForShift1Empls() throws IOException, MessagingException, MyTeamException { public void scheduleLeaveMailForShift1Empls() throws IOException, MessagingException, MyTeamException {
//Shift 1(9:00 AM - 6:00 PM) //Shift 1(9:00 AM - 6:00 PM)
log.info(Shifts.SHIFT1.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now())); log.info(Shifts.SHIFT1.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
...@@ -75,7 +76,7 @@ public class LeaveNotificationScheduler { ...@@ -75,7 +76,7 @@ public class LeaveNotificationScheduler {
} }
// @Scheduled(cron = "${email.leave.notification.shift3.cron}") @Scheduled(cron = "${email.leave.notification.shift3.cron}")
public void scheduleLeaveMailForShift3Empls() throws IOException, MessagingException, MyTeamException { public void scheduleLeaveMailForShift3Empls() throws IOException, MessagingException, MyTeamException {
//Shift 3(10:00 PM - 6:00 AM) //Shift 3(10:00 PM - 6:00 AM)
log.info(Shifts.SHIFT3.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now())); log.info(Shifts.SHIFT3.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
...@@ -83,7 +84,7 @@ public class LeaveNotificationScheduler { ...@@ -83,7 +84,7 @@ public class LeaveNotificationScheduler {
} }
// @Scheduled(cron = "${email.leave.notification.shift4.cron}") @Scheduled(cron = "${email.leave.notification.shift4.cron}")
public void scheduleLeaveMailForShift4Empls() throws IOException, MessagingException, MyTeamException { public void scheduleLeaveMailForShift4Empls() throws IOException, MessagingException, MyTeamException {
//Shift 4(7:30 AM - 3:30 PM) //Shift 4(7:30 AM - 3:30 PM)
log.info(Shifts.SHIFT4.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now())); log.info(Shifts.SHIFT4.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
...@@ -91,7 +92,7 @@ public class LeaveNotificationScheduler { ...@@ -91,7 +92,7 @@ public class LeaveNotificationScheduler {
} }
// @Scheduled(cron = "${email.leave.notification.shift5.cron}") @Scheduled(cron = "${email.leave.notification.shift5.cron}")
public void scheduleLeaveMailForShift5Empls() throws IOException, MessagingException, MyTeamException { public void scheduleLeaveMailForShift5Empls() throws IOException, MessagingException, MyTeamException {
//Shift 5(11:30 AM - 7:30 PM) //Shift 5(11:30 AM - 7:30 PM)
log.info(Shifts.SHIFT5.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now())); log.info(Shifts.SHIFT5.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
...@@ -105,49 +106,56 @@ public class LeaveNotificationScheduler { ...@@ -105,49 +106,56 @@ public class LeaveNotificationScheduler {
String currentDate = dateTimeFormatter.format(LocalDateTime.now()); String currentDate = dateTimeFormatter.format(LocalDateTime.now());
String functionalGroupName; String functionalGroupName;
final String mailSubject = String.valueOf("Date::").concat(MyTeamDateUtils.FormatTodaysDate() + "::").concat(environment.getProperty("email.leave.notification.subject")); final String mailSubject = String.valueOf("Date::").concat(MyTeamDateUtils.FormatTodaysDate() + "::").concat(environment.getProperty("email.leave.notification.subject"));
List<AttendenceData> attendenceList = new ArrayList<>();
List<AttendenceData> absentiesList = new ArrayList<>();
Employee employee = new Employee();
String empSubStatus = "";
Employee employee=new Employee(); if (!MyTeamDateUtils.isTodayHoliday(environment.getProperty("email.holidays.list.2019", "14-01-2019,21-03-2019,19-04-2019,05-06-2019,12-08-2019,15-08-2019,02-09-2019,02-10-2019,08-10-2019,25-12-2019"))) {
String empSubStatus="";
try {
if (!MyTeamDateUtils.isTodayHoliday(environment.getProperty("email.holidays.list.2019", "14-01-2019,21-03-2019,19-04-2019,05-06-2019,12-08-2019,15-08-2019,02-09-2019,02-10-2019,08-10-2019,25-12-2019"))) { try {
attendenceList = attendanceService.getAttendanciesReport(currentDate, shift);
log.info("Inside not holiday"); absentiesList = attendenceList.stream()
List<AttendenceData> attendenceList = attendanceService.getAttendanciesReport(currentDate, shift);
List<AttendenceData> absentiesList = attendenceList.stream()
.filter(attendance -> attendance.getPresent().equalsIgnoreCase(MyTeamUtils.ABSENT)).collect(Collectors.toList()); .filter(attendance -> attendance.getPresent().equalsIgnoreCase(MyTeamUtils.ABSENT)).collect(Collectors.toList());
for (AttendenceData absentee : absentiesList) { } catch (MyTeamException ex) {
ex.printStackTrace();
//model.put("employeeName", );//mail.setModel(model); log.error("An exception occured while fetching absenties list::" + ex.getMessage());
System.out.println("inside loop"); }
Mail mail = new Mail();
mail.setFrom(environment.getProperty("email.leave.notification.from"));
mail.setSubject(mailSubject);
try { for (AttendenceData absentee : absentiesList) {
employee = employeeService.getEmployeeById(absentee.getEmployeeId());
System.out.println("employee Details::"+employee); //model.put("employeeName", );//mail.setModel(model);
EmployeeSubStatus subStatusObj = subStatusService.getCurrentSubStatus(employee.getEmployeeId()); Mail mail = new Mail();
System.out.println("Emplyee SubStatusObj::" + subStatusObj); mail.setFrom(environment.getProperty("email.leave.notification.from"));
if (subStatusObj != null) { mail.setSubject(mailSubject);
if (subStatusObj.getSubStatus() != null) {
empSubStatus = (String) subStatusObj.getSubStatus(); try {
System.out.println("The empSubssttatus::" + empSubStatus); employee = employeeService.getEmployeeById(absentee.getEmployeeId());
} else { log.info("employee Details::" + employee);
empSubStatus = ""; EmployeeSubStatus subStatusObj = subStatusService.getCurrentSubStatus(employee.getEmployeeId());
} log.info("Emplyee SubStatusObj::" + subStatusObj);
if (subStatusObj != null) {
if (subStatusObj.getSubStatus() != null) {
empSubStatus = (String) subStatusObj.getSubStatus();
} else {
empSubStatus = "";
} }
System.out.println("After IF"); } else {
} catch (Exception e) { empSubStatus = "";
e.printStackTrace();
} }
System.out.println("The final empSubStatus::"+empSubStatus); } catch (Exception statusException) {
if (employee.getEmpStatus().equalsIgnoreCase(EmployeeStatus.ACTIVE.getStatus()) && statusException.printStackTrace();
(!empSubStatus.equalsIgnoreCase(EmpSubStatus.LONG_LEAVE.getLeaveType()) && log.error("Exception happend while fetching the Employee sub status::" + statusException.getMessage());
!empSubStatus.equalsIgnoreCase(EmpSubStatus.MATERNITY_LEAVE.getLeaveType()) && }
!empSubStatus.equalsIgnoreCase(EmpSubStatus.ONSITE_TRAVEL.getLeaveType()) && log.info("The final empSubStatus::" + empSubStatus);
!empSubStatus.equalsIgnoreCase(EmpSubStatus.AT_CLIENT_LOCATION.getLeaveType()))) { if (employee.getEmpStatus().equalsIgnoreCase(EmployeeStatus.ACTIVE.getStatus()) &&
(!empSubStatus.equalsIgnoreCase(EmpSubStatus.LONG_LEAVE.getLeaveType()) &&
!empSubStatus.equalsIgnoreCase(EmpSubStatus.MATERNITY_LEAVE.getLeaveType()) &&
!empSubStatus.equalsIgnoreCase(EmpSubStatus.ONSITE_TRAVEL.getLeaveType()) &&
!empSubStatus.equalsIgnoreCase(EmpSubStatus.AT_CLIENT_LOCATION.getLeaveType()))) {
try {
log.info("Mail Notification is sending to:" + absentee.getEmployeeName() + "::" + absentee.getEmailId()); log.info("Mail Notification is sending to:" + absentee.getEmployeeName() + "::" + absentee.getEmailId());
mail.setEmpName(absentee.getEmployeeName()); 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");
...@@ -158,13 +166,15 @@ public class LeaveNotificationScheduler { ...@@ -158,13 +166,15 @@ public class LeaveNotificationScheduler {
} }
mailService.sendLeaveNotification(mail); mailService.sendLeaveNotification(mail);
} catch (Exception sentEx) {
sentEx.printStackTrace();
log.error("An error Occured while sending mail to Absentie::" + sentEx.getMessage());
} }
} }
}
} catch (MyTeamException e) { }
e.printStackTrace();
} }
......
...@@ -33,8 +33,6 @@ import java.util.Date; ...@@ -33,8 +33,6 @@ import java.util.Date;
@Slf4j @Slf4j
public class MailService implements IMailService { public class MailService implements IMailService {
private static final Logger logger = LoggerFactory.getLogger(MailService.class);
@Autowired @Autowired
JavaMailSender emailSender; JavaMailSender emailSender;
...@@ -79,10 +77,10 @@ public class MailService implements IMailService { ...@@ -79,10 +77,10 @@ public class MailService implements IMailService {
emailSender.send(msg); emailSender.send(msg);
} catch (MessagingException e) { } catch (MessagingException e) {
response = "Mail sending failed due to " + e.getMessage(); response = "Mail sending failed due to " + e.getMessage();
logger.error("Mail sending failed due to: ", e); log.error("Mail sending failed due to: ", e);
} catch (IOException e) { } catch (IOException e) {
response = "Mail sending failed due to " + e.getMessage(); response = "Mail sending failed due to " + e.getMessage();
logger.error("Mail sending failed due to: ", e); log.error("Mail sending failed due to: ", e);
} }
return response; return response;
} }
...@@ -112,7 +110,7 @@ public class MailService implements IMailService { ...@@ -112,7 +110,7 @@ public class MailService implements IMailService {
helper.setCc(mail.getCc());//helper.setBcc(mail.getBcc());//log.info("Mail Content::"+content);//log.info("The Mail Object::"+mail); helper.setCc(mail.getCc());//helper.setBcc(mail.getBcc());//log.info("Mail Content::"+content);//log.info("The Mail Object::"+mail);
} }
//emailSender.send(message); emailSender.send(message);
} }
public void sendProjectNotification(Mail mail) throws MessagingException, IOException public void sendProjectNotification(Mail mail) throws MessagingException, IOException
...@@ -129,10 +127,9 @@ public class MailService implements IMailService { ...@@ -129,10 +127,9 @@ public class MailService implements IMailService {
//Read File Content //Read File Content
String content = new String(Files.readAllBytes(file.toPath())); String content = new String(Files.readAllBytes(file.toPath()));
logger.info("In MailServiceIMPL::EmployeeName:::::"+mail.getEmpName()); log.info("EmployeeName:::::"+mail.getEmpName());
content=content.replaceAll("employeeName",mail.getEmpName()); content=content.replaceAll("employeeName",mail.getEmpName());
System.out.println(content); log.info(content);
helper.setTo(mail.getTo()); helper.setTo(mail.getTo());
helper.setText(content, true); helper.setText(content, true);
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration> <configuration>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<springProfile name="development"> <appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n</pattern> <encoder>
</springProfile>
<springProfile name="qa"> <springProfile name="development">
<pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n</pattern> <pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n</pattern>
</springProfile> </springProfile>
<springProfile name="production"> <springProfile name="qa">
<pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n</pattern> <pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n</pattern>
</springProfile> </springProfile>
<!-- If no active profile is set-->
<springProfile name="default">
<pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n</pattern>
</springProfile>
</encoder> <springProfile name="production">
</appender> <pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n</pattern>
</springProfile>
<!-- If no active profile is set-->
<springProfile name="default">
<pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n</pattern>
</springProfile>
</encoder>
</appender>
<springProfile name="default">
<root level="INFO">
<appender-ref ref="stdout" />
</root>
</springProfile>
<appender name="fileAppender" class="ch.qos.logback.core.FileAppender">
<file>/var/lib/Applications/myTeam/logs/myTeam-app.log</file>
<!--<file>/Users/nisum/Desktop/myTeamLogs/myTeam-app.log</file>-->
<springProfile name="development">
<root level="INFO">
<appender-ref ref="stdout" />
</root>
</springProfile>
<springProfile name="qa"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<root level="INFO">
<appender-ref ref="stdout" />
</root>
</springProfile>
<springProfile name="production"> <springProfile name="development">
<root level="DEBUG"> <Pattern>
<appender-ref ref="stdout" /> %d{dd-MM-yyyy HH:mm:ss.SSS} [%t] [%level] [%logger{36}] - %msg%n
</root> </Pattern>
</springProfile>
</springProfile>
<springProfile name="qa">
<Pattern>
%d{dd-MM-yyyy HH:mm:ss.SSS} [%t] [%level] [%logger{36}] - %msg%n
</Pattern>
</springProfile>
<springProfile name="production">
<Pattern>
%d{dd-MM-yyyy HH:mm:ss.SSS} [%t] [%level] [%logger{36}] - %msg%n
</Pattern>
</springProfile>
<springProfile name="default">
<Pattern>
%d{dd-MM-yyyy HH:mm:ss.SSS} [%t] [%level] [%logger{36}] - %msg%n
</Pattern>
</springProfile>
</encoder>
</appender>
<springProfile name="default">
<root level="INFO">
<appender-ref ref="consoleAppender"/>
<appender-ref ref="fileAppender"/>
fileAppender
</root>
</springProfile>
<springProfile name="development">
<root level="INFO">
<appender-ref ref="consoleAppender"/>
<appender-ref ref="fileAppender"/>
</root>
</springProfile>
<springProfile name="qa">
<root level="INFO">
<appender-ref ref="consoleAppender"/>
<appender-ref ref="fileAppender"/>
</root>
</springProfile>
<springProfile name="production">
<root level="INFO">
<appender-ref ref="consoleAppender"/>
<appender-ref ref="fileAppender"/>
</root>
</springProfile>
</configuration> </configuration>
\ No newline at end of file
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