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
09d80345
Commit
09d80345
authored
Jul 29, 2019
by
Prayas Jain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Work Anniversary Service and backend code
parent
39bd924f
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
132 additions
and
22 deletions
+132
-22
WorkAnniversaryScheduler.java
.../com/nisum/myteam/schedular/WorkAnniversaryScheduler.java
+70
-0
IMailService.java
src/main/java/com/nisum/myteam/service/IMailService.java
+2
-0
MailService.java
src/main/java/com/nisum/myteam/service/impl/MailService.java
+38
-4
application-development.properties
src/main/resources/application-development.properties
+10
-4
application-production.properties
src/main/resources/application-production.properties
+5
-0
application.properties
src/main/resources/application.properties
+7
-1
workAnniversaryTemplate.html
src/main/resources/email/workAnniversaryTemplate.html
+0
-13
Happy-work-anniversary.png
src/main/webapp/WEB-INF/images/Happy-work-anniversary.png
+0
-0
workAnniversaryTemp.png
src/main/webapp/WEB-INF/images/workAnniversaryTemp.png
+0
-0
No files found.
src/main/java/com/nisum/myteam/schedular/WorkAnniversaryScheduler.java
0 → 100644
View file @
09d80345
package
com
.
nisum
.
myteam
.
schedular
;
import
java.io.IOException
;
import
java.time.LocalDate
;
import
java.util.List
;
import
javax.mail.MessagingException
;
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
com.nisum.myteam.exception.handler.MyTeamException
;
import
com.nisum.myteam.model.Mail
;
import
com.nisum.myteam.model.dao.Employee
;
import
com.nisum.myteam.service.IEmployeeService
;
import
com.nisum.myteam.service.IMailService
;
import
com.nisum.myteam.utils.MyTeamDateUtils
;
@Component
public
class
WorkAnniversaryScheduler
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
LeaveNotificationScheduler
.
class
);
@Autowired
private
IMailService
mailService
;
@Autowired
private
IEmployeeService
empService
;
@Autowired
private
Environment
environment
;
@Scheduled
(
cron
=
"${email.workAnniversary.notification.cron}"
)
private
void
sendWorkAnniversaryMailToEmployees
()
throws
MessagingException
,
IOException
{
logger
.
info
(
"Work Anniversary notification::"
);
Mail
mail
=
new
Mail
();
mail
.
setFrom
(
environment
.
getProperty
(
"email.workAnniversary.notification.from"
));
mail
.
setSubject
(
environment
.
getProperty
(
"email.workAnniversary.notification.subject"
));
try
{
List
<
Employee
>
activeEmpList
=
empService
.
getActiveEmployees
();
logger
.
info
(
"The active Employees count::"
+
activeEmpList
.
size
());
if
(
activeEmpList
!=
null
&&
activeEmpList
.
size
()
>
0
)
{
LocalDate
currentDate
=
LocalDate
.
now
();
for
(
Employee
activeEmployee
:
activeEmpList
)
{
LocalDate
empDateOfJoining
=
MyTeamDateUtils
.
convertUtilDateToLocalDate
(
activeEmployee
.
getDateOfJoining
());
logger
.
info
(
"Date Of Joining::"
+
empDateOfJoining
);
if
((
empDateOfJoining
.
getDayOfMonth
()
==
currentDate
.
getDayOfMonth
())
&&
(
empDateOfJoining
.
getMonthValue
()
==
currentDate
.
getMonthValue
()))
{
logger
.
info
(
"Mail Notification is sending to:"
+
activeEmployee
.
getEmployeeName
()
+
"::"
+
activeEmployee
.
getEmailId
());
mail
.
setTo
(
activeEmployee
.
getEmailId
());
mail
.
setCc
(
new
String
[]{
"hrops@nisum.com"
});
// mail.setTo("pjain@nisum.com");
// mail.setCc(new String[]{"vksingh@nisum.com"});
mailService
.
sendWorkAnniversaryNotification
(
mail
);
}
}
}
}
catch
(
MyTeamException
e
)
{
e
.
printStackTrace
();
}
}
}
src/main/java/com/nisum/myteam/service/IMailService.java
View file @
09d80345
...
...
@@ -20,6 +20,8 @@ public interface IMailService {
public
void
sendLeaveNotification
(
Mail
mail
)
throws
MessagingException
,
IOException
;
public
void
sendProjectNotification
(
Mail
mail
)
throws
MessagingException
,
IOException
;
public
void
sendWorkAnniversaryNotification
(
Mail
mail
)
throws
MessagingException
,
IOException
;
}
src/main/java/com/nisum/myteam/service/impl/MailService.java
View file @
09d80345
...
...
@@ -7,8 +7,6 @@ import com.nisum.myteam.model.EmailDomain;
import
com.nisum.myteam.model.Mail
;
import
com.nisum.myteam.service.IMailService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.io.FileSystemResource
;
...
...
@@ -19,10 +17,17 @@ import org.springframework.stereotype.Service;
import
org.springframework.util.ResourceUtils
;
import
org.thymeleaf.spring4.SpringTemplateEngine
;
import
javax.activation.DataHandler
;
import
javax.mail.MessagingException
;
import
javax.mail.internet.MimeBodyPart
;
import
javax.mail.internet.MimeMessage
;
import
javax.mail.internet.MimeMultipart
;
import
javax.mail.util.ByteArrayDataSource
;
import
javax.servlet.ServletContext
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.file.Files
;
import
java.util.Date
;
/**
...
...
@@ -36,11 +41,12 @@ public class MailService implements IMailService {
@Autowired
JavaMailSender
emailSender
;
@Autowired
ServletContext
servletContext
;
@Autowired
ResourceLoader
resourceLoader
;
@Autowired
private
SpringTemplateEngine
templateEngine
;
@Autowired
private
Environment
environment
;
...
...
@@ -140,6 +146,34 @@ public class MailService implements IMailService {
emailSender
.
send
(
message
);
}
public
void
sendWorkAnniversaryNotification
(
Mail
mail
)
throws
IOException
,
MessagingException
{
MimeMessage
message
=
emailSender
.
createMimeMessage
();
MimeMessageHelper
helper
=
new
MimeMessageHelper
(
message
,
true
);
MimeMultipart
multipart
=
new
MimeMultipart
(
"related"
);
MimeBodyPart
messageBodyPart
=
new
MimeBodyPart
();
String
htmlText
=
"<img src=\"cid:image\">"
;
messageBodyPart
.
setContent
(
htmlText
,
"text/html"
);
multipart
.
addBodyPart
(
messageBodyPart
);
messageBodyPart
=
new
MimeBodyPart
();
InputStream
targetStream
=
servletContext
.
getResourceAsStream
(
"/WEB-INF/images/workAnniversaryTemp.png"
);
ByteArrayDataSource
ds
=
new
ByteArrayDataSource
(
targetStream
,
"image/png"
);
messageBodyPart
.
setDataHandler
(
new
DataHandler
(
ds
));
messageBodyPart
.
setHeader
(
"Content-ID"
,
"<image>"
);
messageBodyPart
.
setDisposition
(
MimeBodyPart
.
INLINE
);
multipart
.
addBodyPart
(
messageBodyPart
);
message
.
setContent
(
multipart
);
helper
.
setTo
(
mail
.
getTo
());
helper
.
setSubject
(
mail
.
getSubject
());
helper
.
setFrom
(
mail
.
getFrom
());
helper
.
setCc
(
mail
.
getCc
());
//helper.setBcc(mail.getBcc());
emailSender
.
send
(
message
);
}
}
src/main/resources/application-development.properties
View file @
09d80345
...
...
@@ -58,10 +58,16 @@ email.leave.notification.subject=Employee Leave Email Notification
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
#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
#email.workAnniversary.notification.from=mytime.nisum@gmail.com
#email.workAnniversary.notification.subject=Happy Work Anniversary
#email.workAnniversary.notification.cron=00 00 06 * * 1-7
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
src/main/resources/application-production.properties
View file @
09d80345
...
...
@@ -65,6 +65,11 @@ 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.workAnniversary.notification.from
=
mytime.nisum@gmail.com
email.workAnniversary.notification.subject
=
Happy Work Anniversary
email.workAnniversary.notification.cron
=
00 00 06 * * 1-7
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
src/main/resources/application.properties
View file @
09d80345
...
...
@@ -59,11 +59,17 @@ email.leave.notification.shift5.cron=00 30 23 * * 1-5
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
spring.profiles.active
=
production
email.workAnniversary.notification.from
=
mytime.nisum@gmail.com
email.workAnniversary.notification.subject
=
Happy Work Anniversary
email.workAnniversary.notification.cron
=
00 00 06 * * 1-7
spring.profiles.active
=
development
message
=
this is from default configuration
\ No newline at end of file
src/main/resources/email/workAnniversaryTemplate.html
deleted
100644 → 0
View file @
39bd924f
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns:th=
"http://www.thymeleaf.org"
xmlns=
"http://www.w3.org/1999/xhtml"
>
<head>
<title>
Work Anniversary Notification
</title>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
/>
</head>
<body>
<div
style=
"margin: 0; padding: 0; text-align: center"
>
<img
src=
"../../webapp/WEB-INF/images/Happy-work-anniversary.png"
alt=
"Work Anniversary"
/>
</div>
</body>
</html>
\ No newline at end of file
src/main/webapp/WEB-INF/images/Happy-work-anniversary.png
deleted
100644 → 0
View file @
39bd924f
23.5 KB
src/main/webapp/WEB-INF/images/workAnniversaryTemp.png
0 → 100644
View file @
09d80345
22.3 KB
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