Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mytime
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Narendar Vakiti
mytime
Commits
ec3c5d20
Commit
ec3c5d20
authored
Jun 27, 2019
by
Vijay Akula
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolved the issue while sending the mail
parent
3e557516
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
137 additions
and
89 deletions
+137
-89
LeaveNotificationScheduler.java
...om/nisum/myteam/schedular/LeaveNotificationScheduler.java
+54
-44
MailService.java
src/main/java/com/nisum/myteam/service/impl/MailService.java
+5
-8
logback-spring.xml
src/main/resources/logback-spring.xml
+78
-37
No files found.
src/main/java/com/nisum/myteam/schedular/LeaveNotificationScheduler.java
View file @
ec3c5d20
...
...
@@ -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
();
}
}
...
...
src/main/java/com/nisum/myteam/service/impl/MailService.java
View file @
ec3c5d20
...
...
@@ -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
();
log
ger
.
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
();
log
ger
.
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
()));
log
ger
.
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
);
...
...
src/main/resources/logback-spring.xml
View file @
ec3c5d20
<?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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment