Commit 653c71ef authored by Vijay Akula's avatar Vijay Akula

Not sending mails on holidays

parent e623e977
...@@ -21,8 +21,8 @@ import org.slf4j.Logger; ...@@ -21,8 +21,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -104,14 +104,15 @@ public class LeaveNotificationScheduler { ...@@ -104,14 +104,15 @@ public class LeaveNotificationScheduler {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
String currentDate = dateTimeFormatter.format(LocalDateTime.now()); String currentDate = dateTimeFormatter.format(LocalDateTime.now());
String functionalGroupName; String functionalGroupName;
final String mailSubject = environment.getProperty("email.leave.notification.subject").concat("for the day::").concat(MyTeamDateUtils.parseDateForMailSubject()); final String mailSubject = environment.getProperty("email.leave.notification.subject").concat("for the day::").concat(MyTeamDateUtils.FormatTodaysDate());
Employee employee; Employee employee;
String empSubStatus; String empSubStatus;
try { try {
List<AttendenceData> attendenceList = attendanceService.getAttendanciesReport(currentDate, shift); if (!MyTeamDateUtils.isTodayHoliday(environment.getProperty("email.holidays.list.2019", ""))) {
List<AttendenceData> attendenceList = attendanceService.getAttendanciesReport(currentDate, shift);
List<AttendenceData> absentiesList = attendenceList.stream() 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) { for (AttendenceData absentee : absentiesList) {
...@@ -124,7 +125,7 @@ public class LeaveNotificationScheduler { ...@@ -124,7 +125,7 @@ public class LeaveNotificationScheduler {
employee = employeeService.getEmployeeById(absentee.getEmployeeId()); employee = employeeService.getEmployeeById(absentee.getEmployeeId());
EmployeeSubStatus subStatus = subStatusService.getCurrentSubStatus(employee.getEmployeeId()); EmployeeSubStatus subStatus = subStatusService.getCurrentSubStatus(employee.getEmployeeId());
empSubStatus = (String)subStatus.getSubStatus(); empSubStatus = (String) subStatus.getSubStatus();
if (empSubStatus == null) if (empSubStatus == null)
empSubStatus = ""; empSubStatus = "";
...@@ -147,11 +148,13 @@ public class LeaveNotificationScheduler { ...@@ -147,11 +148,13 @@ public class LeaveNotificationScheduler {
} }
} }
}
} catch (MyTeamException e) { } catch (MyTeamException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
package com.nisum.myteam.utils; package com.nisum.myteam.utils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.hsqldb.lib.StringUtil;
import org.springframework.beans.factory.annotation.Value;
import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.Calendar; import java.util.*;
import java.util.Date;
@Slf4j @Slf4j
public class MyTeamDateUtils { public class MyTeamDateUtils {
...@@ -16,6 +19,7 @@ public class MyTeamDateUtils { ...@@ -16,6 +19,7 @@ public class MyTeamDateUtils {
cal.add(Calendar.DATE, -1); cal.add(Calendar.DATE, -1);
return cal.getTime(); return cal.getTime();
} }
public static LocalDate convertUtilDateToLocalDate(Date dateToConvert) { public static LocalDate convertUtilDateToLocalDate(Date dateToConvert) {
return dateToConvert.toInstant() return dateToConvert.toInstant()
.atZone(ZoneId.systemDefault()) .atZone(ZoneId.systemDefault())
...@@ -23,35 +27,69 @@ public class MyTeamDateUtils { ...@@ -23,35 +27,69 @@ public class MyTeamDateUtils {
} }
public static Date getDayLessThanDate(Date date) public static Date getDayLessThanDate(Date date) {
{
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(date); calendar.setTime(date);
calendar.add(Calendar.DATE, -1); calendar.add(Calendar.DATE, -1);
Date yesterday = calendar.getTime(); Date yesterday = calendar.getTime();
log.info("Day before Date is::"+yesterday); log.info("Day before Date is::" + yesterday);
return yesterday; return yesterday;
} }
public static Date getDayMoreThanDate(Date date) public static Date getDayMoreThanDate(Date date) {
{
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(date); calendar.setTime(date);
calendar.add(Calendar.DATE, +1); calendar.add(Calendar.DATE, +1);
Date yesterday = calendar.getTime(); Date yesterday = calendar.getTime();
log.info("Day after Date is::"+yesterday); log.info("Day after Date is::" + yesterday);
return yesterday; return yesterday;
} }
public static String parseDateForMailSubject() public static String FormatTodaysDate() {
{ Date date = new Date();
Date date=new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
SimpleDateFormat dateFormat=new SimpleDateFormat("dd-MM-yyyy");
return dateFormat.format(date); return dateFormat.format(date);
} }
// public static void main(String[] args)
// { public static Date parseTodaysDate(String dateString) {
// MyTeamDateUtils.getDayMoreThanDate(new Date()); SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
// } try {
return dateFormat.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
return new Date();
}
}
public static boolean isTodayHoliday(String holidays) {
boolean isHoliday=false;
if(StringUtils.isNotBlank(holidays))
{
String[] holidayList = holidays.split(",");
String todayDate = FormatTodaysDate();
return Arrays.stream(holidayList).anyMatch(holiday -> holiday.equalsIgnoreCase(todayDate));
}
return isHoliday;
}
/* public boolean isTodayHoliday() {
Set<Date> dateList = new HashSet<Date>();
Date todayDate = new Date();
log.info("The holidays list from properties file::" + holidays);
String[] holidayList = holidays.split(",");
for (String holiday : holidayList)
dateList.add(parseTodaysDate(holiday));
log.info("The dateList::" + dateList);
return dateList.contains(todayDate);
} */
public static void main(String[] args) {
MyTeamDateUtils dateUtils = new MyTeamDateUtils();
//System.out.println(dateUtils.isTodayHoliday());
//System.out.println(dateUtils.isTodayHoliday());
}
} }
...@@ -63,4 +63,5 @@ email.project.notification.from=mytime.nisum@gmail.com ...@@ -63,4 +63,5 @@ email.project.notification.from=mytime.nisum@gmail.com
email.project.notification.subject=Project EndDate Email Notification email.project.notification.subject=Project EndDate Email Notification
email.project.notification.cron=00 00 15 * * 1-5 email.project.notification.cron=00 00 15 * * 1-5
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
message=this is from development message=this is from development
...@@ -65,4 +65,6 @@ email.project.notification.from=mytime.nisum@gmail.com ...@@ -65,4 +65,6 @@ email.project.notification.from=mytime.nisum@gmail.com
email.project.notification.subject=Project EndDate Email Notification email.project.notification.subject=Project EndDate Email Notification
email.project.notification.cron=00 00 15 * * 1-5 email.project.notification.cron=00 00 15 * * 1-5
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
message=this is from production message=this is from production
\ No newline at end of file
...@@ -65,3 +65,5 @@ email.project.notification.template.file.path=email/projectMailTemplate.html ...@@ -65,3 +65,5 @@ email.project.notification.template.file.path=email/projectMailTemplate.html
email.project.notification.from=mytime.nisum@gmail.com email.project.notification.from=mytime.nisum@gmail.com
email.project.notification.subject=Project EndDate Email Notification email.project.notification.subject=Project EndDate Email Notification
email.project.notification.cron=00 00 15 * * 1-5 email.project.notification.cron=00 00 15 * * 1-5
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
\ 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