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;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.mail.MessagingException;
import java.io.IOException;
import java.time.LocalDateTime;
......@@ -104,54 +104,57 @@ public class LeaveNotificationScheduler {
Map<String, Object> model = new HashMap<String, Object>();
String currentDate = dateTimeFormatter.format(LocalDateTime.now());
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;
String empSubStatus;
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()
.filter(attendance -> attendance.getPresent().equalsIgnoreCase(MyTeamUtils.ABSENT)).collect(Collectors.toList());
for (AttendenceData absentee : absentiesList) {
List<AttendenceData> absentiesList = attendenceList.stream()
.filter(attendance -> attendance.getPresent().equalsIgnoreCase(MyTeamUtils.ABSENT)).collect(Collectors.toList());
for (AttendenceData absentee : absentiesList) {
//model.put("employeeName", );//mail.setModel(model);
//model.put("employeeName", );//mail.setModel(model);
Mail mail = new Mail();
mail.setFrom(environment.getProperty("email.leave.notification.from"));
mail.setSubject(mailSubject);
Mail mail = new Mail();
mail.setFrom(environment.getProperty("email.leave.notification.from"));
mail.setSubject(mailSubject);
employee = employeeService.getEmployeeById(absentee.getEmployeeId());
EmployeeSubStatus subStatus = subStatusService.getCurrentSubStatus(employee.getEmployeeId());
empSubStatus = (String) subStatus.getSubStatus();
employee = employeeService.getEmployeeById(absentee.getEmployeeId());
EmployeeSubStatus subStatus = subStatusService.getCurrentSubStatus(employee.getEmployeeId());
empSubStatus = (String)subStatus.getSubStatus();
if (empSubStatus == null)
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()))) {
if (empSubStatus == null)
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()))) {
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");
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");
FunctionalGroup functionalGroup = functionalGroupService.getFunctionalGroup(employee.getFunctionalGroup());
if (functionalGroup != null) {
mail.setCc(new String[]{functionalGroup.getGroupHeadEmailId()});//mail.setCc(new String[]{"prayasjain21@gmail.com"});
}
mailService.sendLeaveNotification(mail);
FunctionalGroup functionalGroup = functionalGroupService.getFunctionalGroup(employee.getFunctionalGroup());
if (functionalGroup != null) {
mail.setCc(new String[]{functionalGroup.getGroupHeadEmailId()});//mail.setCc(new String[]{"prayasjain21@gmail.com"});
}
mailService.sendLeaveNotification(mail);
}
}
} catch (MyTeamException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
}
package com.nisum.myteam.utils;
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.time.LocalDate;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.*;
@Slf4j
public class MyTeamDateUtils {
......@@ -16,6 +19,7 @@ public class MyTeamDateUtils {
cal.add(Calendar.DATE, -1);
return cal.getTime();
}
public static LocalDate convertUtilDateToLocalDate(Date dateToConvert) {
return dateToConvert.toInstant()
.atZone(ZoneId.systemDefault())
......@@ -23,35 +27,69 @@ public class MyTeamDateUtils {
}
public static Date getDayLessThanDate(Date date)
{
public static Date getDayLessThanDate(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, -1);
Date yesterday = calendar.getTime();
log.info("Day before Date is::"+yesterday);
log.info("Day before Date is::" + yesterday);
return yesterday;
}
public static Date getDayMoreThanDate(Date date)
{
public static Date getDayMoreThanDate(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, +1);
Date yesterday = calendar.getTime();
log.info("Day after Date is::"+yesterday);
log.info("Day after Date is::" + yesterday);
return yesterday;
}
public static String parseDateForMailSubject()
{
Date date=new Date();
SimpleDateFormat dateFormat=new SimpleDateFormat("dd-MM-yyyy");
public static String FormatTodaysDate() {
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
return dateFormat.format(date);
}
// public static void main(String[] args)
// {
// MyTeamDateUtils.getDayMoreThanDate(new Date());
// }
public static Date parseTodaysDate(String dateString) {
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
email.project.notification.subject=Project EndDate Email Notification
email.project.notification.cron=00 00 15 * * 1-5
message=this is from development
\ No newline at end of file
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
......@@ -65,4 +65,6 @@ email.project.notification.from=mytime.nisum@gmail.com
email.project.notification.subject=Project EndDate Email Notification
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
\ No newline at end of file
......@@ -64,4 +64,6 @@ spring.thymeleaf.view-names:thymeleaf/*
email.project.notification.template.file.path=email/projectMailTemplate.html
email.project.notification.from=mytime.nisum@gmail.com
email.project.notification.subject=Project EndDate Email Notification
email.project.notification.cron=00 00 15 * * 1-5
\ No newline at end of file
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
......@@ -66,4 +66,4 @@ email.project.notification.cron=00 00 15 * * 1-5
spring.profiles.active=development
message=this is from default configuration
\ No newline at end of file
message=this is from default configuration
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