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;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -58,8 +59,8 @@ public class LeaveNotificationScheduler {
private SubStatusService subStatusService;
//@Scheduled(cron = "${email.leave.notification.shift1.cron}")
@Scheduled(cron = "0 * * * * ?")
@Scheduled(cron = "${email.leave.notification.shift1.cron}")
//@Scheduled(cron = "0 * * * * ?")
public void scheduleLeaveMailForShift1Empls() throws IOException, MessagingException, MyTeamException {
//Shift 1(9:00 AM - 6:00 PM)
log.info(Shifts.SHIFT1.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
......@@ -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 {
//Shift 3(10:00 PM - 6:00 AM)
log.info(Shifts.SHIFT3.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
......@@ -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 {
//Shift 4(7:30 AM - 3:30 PM)
log.info(Shifts.SHIFT4.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
......@@ -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 {
//Shift 5(11:30 AM - 7:30 PM)
log.info(Shifts.SHIFT5.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
......@@ -105,49 +106,56 @@ public class LeaveNotificationScheduler {
String currentDate = dateTimeFormatter.format(LocalDateTime.now());
String functionalGroupName;
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();
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"))) {
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"))) {
log.info("Inside not holiday");
List<AttendenceData> attendenceList = attendanceService.getAttendanciesReport(currentDate, shift);
List<AttendenceData> absentiesList = attendenceList.stream()
try {
attendenceList = attendanceService.getAttendanciesReport(currentDate, shift);
absentiesList = attendenceList.stream()
.filter(attendance -> attendance.getPresent().equalsIgnoreCase(MyTeamUtils.ABSENT)).collect(Collectors.toList());
for (AttendenceData absentee : absentiesList) {
//model.put("employeeName", );//mail.setModel(model);
System.out.println("inside loop");
Mail mail = new Mail();
mail.setFrom(environment.getProperty("email.leave.notification.from"));
mail.setSubject(mailSubject);
} catch (MyTeamException ex) {
ex.printStackTrace();
log.error("An exception occured while fetching absenties list::" + ex.getMessage());
}
try {
employee = employeeService.getEmployeeById(absentee.getEmployeeId());
System.out.println("employee Details::"+employee);
EmployeeSubStatus subStatusObj = subStatusService.getCurrentSubStatus(employee.getEmployeeId());
System.out.println("Emplyee SubStatusObj::" + subStatusObj);
if (subStatusObj != null) {
if (subStatusObj.getSubStatus() != null) {
empSubStatus = (String) subStatusObj.getSubStatus();
System.out.println("The empSubssttatus::" + empSubStatus);
} else {
empSubStatus = "";
}
for (AttendenceData absentee : absentiesList) {
//model.put("employeeName", );//mail.setModel(model);
Mail mail = new Mail();
mail.setFrom(environment.getProperty("email.leave.notification.from"));
mail.setSubject(mailSubject);
try {
employee = employeeService.getEmployeeById(absentee.getEmployeeId());
log.info("employee Details::" + employee);
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");
} catch (Exception e) {
e.printStackTrace();
} else {
empSubStatus = "";
}
System.out.println("The final empSubStatus::"+empSubStatus);
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()))) {
} catch (Exception statusException) {
statusException.printStackTrace();
log.error("Exception happend while fetching the Employee sub status::" + statusException.getMessage());
}
log.info("The final empSubStatus::" + empSubStatus);
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());
mail.setEmpName(absentee.getEmployeeName());
mail.setTo(absentee.getEmailId());//mail.setEmpName("Prayas");//mail.setTo("pjain@nisum.com");
......@@ -158,13 +166,15 @@ public class LeaveNotificationScheduler {
}
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;
@Slf4j
public class MailService implements IMailService {
private static final Logger logger = LoggerFactory.getLogger(MailService.class);
@Autowired
JavaMailSender emailSender;
......@@ -79,10 +77,10 @@ public class MailService implements IMailService {
emailSender.send(msg);
} catch (MessagingException e) {
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) {
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;
}
......@@ -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);
}
//emailSender.send(message);
emailSender.send(message);
}
public void sendProjectNotification(Mail mail) throws MessagingException, IOException
......@@ -129,10 +127,9 @@ public class MailService implements IMailService {
//Read File Content
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());
System.out.println(content);
log.info(content);
helper.setTo(mail.getTo());
helper.setText(content, true);
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<springProfile name="development">
<pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n</pattern>
</springProfile>
<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<springProfile name="qa">
<pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n</pattern>
</springProfile>
<springProfile name="development">
<pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n</pattern>
</springProfile>
<springProfile name="production">
<pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n</pattern>
</springProfile>
<springProfile name="qa">
<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="production">
<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">
<root level="INFO">
<appender-ref ref="stdout" />
</root>
</springProfile>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<springProfile name="production">
<root level="DEBUG">
<appender-ref ref="stdout" />
</root>
</springProfile>
<springProfile name="development">
<Pattern>
%d{dd-MM-yyyy HH:mm:ss.SSS} [%t] [%level] [%logger{36}] - %msg%n
</Pattern>
</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>
\ 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