Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
Grievance
Commits
01b5caa8
Commit
01b5caa8
authored
1 year ago
by
shishir suman
Browse files
Options
Download
Patches
Plain Diff
adding temp code to send mail via sendgrid
parent
ef1db7f5
UPHRH_quartz_scheduler
UAT
UPHRH_7903_mobile_otp
1 merge request
!51
adding temp code to send mail via sendgrid
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/main/java/org/upsmf/grievance/controller/UserController.java
+11
-0
...n/java/org/upsmf/grievance/controller/UserController.java
src/main/java/org/upsmf/grievance/service/EmailService.java
+3
-0
src/main/java/org/upsmf/grievance/service/EmailService.java
src/main/java/org/upsmf/grievance/service/IntegrationService.java
+2
-0
.../java/org/upsmf/grievance/service/IntegrationService.java
src/main/java/org/upsmf/grievance/service/impl/EmailServiceImpl.java
+63
-19
...va/org/upsmf/grievance/service/impl/EmailServiceImpl.java
src/main/java/org/upsmf/grievance/service/impl/IntegrationServiceImpl.java
+9
-3
.../upsmf/grievance/service/impl/IntegrationServiceImpl.java
with
88 additions
and
22 deletions
+88
-22
src/main/java/org/upsmf/grievance/controller/UserController.java
+
11
−
0
View file @
01b5caa8
...
...
@@ -205,4 +205,15 @@ public class UserController {
}
}
@GetMapping
(
"/mail/test/{email}"
)
public
ResponseEntity
<
String
>
testMail
(
@PathVariable
(
"email"
)
String
email
)
{
try
{
return
integrationService
.
sendTestMail
(
email
);
}
catch
(
Exception
e
)
{
log
.
error
(
"error in firing test mail"
,
e
.
getLocalizedMessage
());
return
ResponseEntity
.
internalServerError
().
body
(
"Error in sending test mail - "
.
concat
(
e
.
getLocalizedMessage
()));
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/org/upsmf/grievance/service/EmailService.java
+
3
−
0
View file @
01b5caa8
...
...
@@ -51,4 +51,7 @@ public interface EmailService {
void
sendEscalationMailToGrievanceNodal
(
EmailDetails
details
,
Ticket
ticket
);
void
sendCreateTicketOTPMail
(
String
email
,
String
otp
,
String
recipientName
,
String
subject
,
int
otpExpirationMinutes
);
void
sendTestMail
(
String
email
);
}
This diff is collapsed.
Click to expand it.
src/main/java/org/upsmf/grievance/service/IntegrationService.java
+
2
−
0
View file @
01b5caa8
...
...
@@ -43,4 +43,6 @@ public interface IntegrationService {
ResponseEntity
<
Boolean
>
getUserStatusByEmail
(
String
userName
);
ResponseEntity
<
String
>
filterUsers
(
JsonNode
payload
)
throws
Exception
;
ResponseEntity
<
String
>
sendTestMail
(
String
email
)
throws
Exception
;
}
This diff is collapsed.
Click to expand it.
src/main/java/org/upsmf/grievance/service/impl/EmailServiceImpl.java
+
63
−
19
View file @
01b5caa8
...
...
@@ -58,6 +58,9 @@ public class EmailServiceImpl implements EmailService {
@Value
(
"${site.url}"
)
private
String
siteUrl
;
@Value
(
"${mail.sender}"
)
private
static
String
mailSender
;
@Autowired
private
TicketDepartmentRepository
ticketDepartmentRepository
;
...
...
@@ -128,7 +131,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"url"
,
feedbackUrl
);
velocityContext
.
put
(
"docLinks"
,
attachments
);
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/raiser_feedback.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -175,7 +178,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"Junk_by_reason"
,
ticket
.
getJunkByReason
());
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/raiser_junk_ticket.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -210,7 +213,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"other_by"
,
ticket
.
getOther
());
velocityContext
.
put
(
"other_by_reason"
,
ticket
.
getOtherByReason
());
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/raiser_update_ticket.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -261,7 +264,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"status"
,
ticket
.
getStatus
().
name
());
velocityContext
.
put
(
"site_url"
,
siteUrl
);
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/nodal_create_ticket.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -384,7 +387,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"ticket_description"
,
ticket
.
getDescription
());
velocityContext
.
put
(
"status"
,
ticket
.
getStatus
().
name
());
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/admin_create_ticket.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -453,7 +456,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"other_by"
,
ticket
.
getOther
());
velocityContext
.
put
(
"other_by_reason"
,
ticket
.
getOtherByReason
());
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/admin_create_ticket.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -472,13 +475,15 @@ public class EmailServiceImpl implements EmailService {
}
}
private
static
void
createCommonMailSignature
(
VelocityContext
velocityContext
)
{
private
static
void
createCommonMailSignature
(
VelocityContext
velocityContext
,
MimeMessageHelper
message
)
throws
MessagingException
{
velocityContext
.
put
(
"signature_name"
,
"U.P. State Medical Faculty"
);
velocityContext
.
put
(
"address"
,
"Address: 5, Sarvpalli, Mall Avenue Road, Lucknow - 226001 (U.P.) India"
);
velocityContext
.
put
(
"phone"
,
"Phone: (0522) 2238846, 2235964, 2235965, 3302100"
);
velocityContext
.
put
(
"mobile"
,
"Mobile : +91-8400955546 / +91-9151024463"
);
velocityContext
.
put
(
"fax"
,
"Fax : (0522) 2236600"
);
velocityContext
.
put
(
"email"
,
"Email: upmedicalfaculty@upsmfac.org"
);
// setting temporary
message
.
setFrom
(
mailSender
);
}
private
void
sendMailToRaiser
(
EmailDetails
details
,
Ticket
ticket
)
{
...
...
@@ -494,7 +499,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"id"
,
ticket
.
getId
());
velocityContext
.
put
(
"created_date"
,
DateUtil
.
getFormattedDateInString
(
ticket
.
getCreatedDate
()));
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/raiser-create-ticket.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -580,7 +585,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"junk"
,
assessmentMatrix
.
get
(
"Is Junk"
).
numberValue
());
velocityContext
.
put
(
"total"
,
assessmentMatrix
.
get
(
"Total"
).
numberValue
());
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/biweekly_report.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -641,7 +646,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"nudged_count"
,
ticket
.
getReminderCounter
());
velocityContext
.
put
(
"site_url"
,
siteUrl
);
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/nodal_nudge_ticket.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -682,7 +687,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"first_name"
,
ticket
.
getFirstName
());
velocityContext
.
put
(
"id"
,
ticket
.
getId
());
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/raiser_escalation_ticket.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -719,7 +724,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"created_date"
,
DateUtil
.
getFormattedDateInString
(
ticket
.
getCreatedDate
()));
velocityContext
.
put
(
"id"
,
ticket
.
getId
());
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/nodal_escaltion_ticket.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -759,7 +764,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"site_url"
,
siteUrl
);
velocityContext
.
put
(
"created_date"
,
DateUtil
.
getFormattedDateInString
(
ticket
.
getCreatedDate
()));
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/nodal_create_ticket.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -812,7 +817,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"nudged_count"
,
ticket
.
getReminderCounter
());
velocityContext
.
put
(
"site_url"
,
siteUrl
);
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/nodal_admin_nudge_ticket.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -890,7 +895,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"tickets"
,
openTicketsByID
.
size
()
>
0
?
openTicketsByID
:
null
);
log
.
debug
(
"openTicket size - {}"
,
openTicketsByID
.
size
());
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/nodal_officer_pending_ticket_mail.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -919,7 +924,7 @@ public class EmailServiceImpl implements EmailService {
VelocityContext
velocityContext
=
new
VelocityContext
();
velocityContext
.
put
(
"first_name"
,
user
.
getFirstName
());
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
if
(
active
)
{
...
...
@@ -960,7 +965,7 @@ public class EmailServiceImpl implements EmailService {
velocityContext
.
put
(
"password"
,
password
);
velocityContext
.
put
(
"url"
,
siteUrl
);
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
...
...
@@ -1018,12 +1023,13 @@ public class EmailServiceImpl implements EmailService {
MimeMessageHelper
message
=
new
MimeMessageHelper
(
mimeMessage
);
message
.
setTo
(
x
.
getEmail
());
message
.
setSubject
(
details
.
getSubject
());
VelocityContext
velocityContext
=
new
VelocityContext
();
velocityContext
.
put
(
"id"
,
ticket
.
getId
());
velocityContext
.
put
(
"created_date"
,
DateUtil
.
getFormattedDateInString
(
ticket
.
getCreatedDate
()));
velocityContext
.
put
(
"status"
,
ticket
.
getStatus
().
name
());
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/nodal_admin_escalation_ticket.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -1058,12 +1064,13 @@ public class EmailServiceImpl implements EmailService {
MimeMessageHelper
message
=
new
MimeMessageHelper
(
mimeMessage
);
message
.
setTo
(
email
);
message
.
setSubject
(
subject
);
VelocityContext
velocityContext
=
new
VelocityContext
();
velocityContext
.
put
(
"name"
,
finalRecipientName
);
velocityContext
.
put
(
"otp"
,
otp
);
velocityContext
.
put
(
"expiry"
,
finalOtpExpirationMinutes
);
// signature
createCommonMailSignature
(
velocityContext
);
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/raiser_otp_create_ticket_mail.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
...
...
@@ -1080,4 +1087,41 @@ public class EmailServiceImpl implements EmailService {
log
.
error
(
"Error while Sending Mail create ticket OTP mail"
,
e
);
}
}
@Override
public
void
sendTestMail
(
String
email
)
{
try
{
MimeMessagePreparator
preparator
=
new
MimeMessagePreparator
()
{
public
void
prepare
(
MimeMessage
mimeMessage
)
throws
Exception
{
MimeMessageHelper
message
=
new
MimeMessageHelper
(
mimeMessage
);
message
.
setTo
(
email
);
message
.
setSubject
(
"Test Mail"
);
VelocityContext
velocityContext
=
new
VelocityContext
();
velocityContext
.
put
(
"first_name"
,
"User"
);
velocityContext
.
put
(
"id"
,
-
1
);
velocityContext
.
put
(
"created_date"
,
DateUtil
.
getCurrentDate
());
velocityContext
.
put
(
"department"
,
"Test"
);
velocityContext
.
put
(
"comment"
,
"Test comment"
);
velocityContext
.
put
(
"url"
,
"http://uphrh.in"
);
// signature
createCommonMailSignature
(
velocityContext
,
message
);
// merge mail body
StringWriter
stringWriter
=
new
StringWriter
();
velocityEngine
.
mergeTemplate
(
"templates/raiser_feedback.vm"
,
"UTF-8"
,
velocityContext
,
stringWriter
);
message
.
setText
(
stringWriter
.
toString
(),
true
);
}
};
// Sending the mail
javaMailSender
.
send
(
preparator
);
log
.
info
(
"create ticket mail Sent Successfully..."
);
}
// Catch block to handle the exceptions
catch
(
Exception
e
)
{
log
.
error
(
"Error while Sending Mail"
,
e
);
throw
new
RuntimeException
(
"Error in sending test mail. Reason - "
.
concat
(
e
.
getLocalizedMessage
()));
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/org/upsmf/grievance/service/impl/IntegrationServiceImpl.java
+
9
−
3
View file @
01b5caa8
...
...
@@ -243,7 +243,7 @@ public class IntegrationServiceImpl implements IntegrationService {
if
(
attributeMap
!=
null
)
{
if
((
attributeMap
.
containsKey
(
"departmentId"
)
&&
!
attributeMap
.
containsKey
(
"councilId"
)
)
||
(
!
attributeMap
.
containsKey
(
"departmentId"
)
&&
attributeMap
.
containsKey
(
"councilId"
)
)
)
{
log
.
error
(
"Missing one of attrbutes department id or council id - both are allowed or none"
);
log
.
error
(
"Missing one of attr
i
butes department id or council id - both are allowed or none"
);
throw
new
InvalidDataException
(
"Both council and department id are allowed or none"
);
}
...
...
@@ -276,8 +276,8 @@ public class IntegrationServiceImpl implements IntegrationService {
return
attributeMap
;
}
catch
(
NumberFormatException
e
)
{
log
.
error
(
"Error while parsing departme
t
n | council id"
);
throw
new
InvalidDataException
(
"Department | coucil id only support number"
);
log
.
error
(
"Error while parsing departmen
t
| council id"
);
throw
new
InvalidDataException
(
"Department | cou
n
cil id only support number"
);
}
catch
(
CustomException
e
)
{
log
.
error
(
"Error while checking department and council for user"
);
throw
new
DataUnavailabilityException
(
e
.
getMessage
(),
"Error while checking department and council for user"
);
...
...
@@ -1123,4 +1123,10 @@ public class IntegrationServiceImpl implements IntegrationService {
}
return
users
;
}
@Override
public
ResponseEntity
<
String
>
sendTestMail
(
String
email
)
throws
Exception
{
emailService
.
sendTestMail
(
email
);
return
ResponseEntity
.
ok
(
"Test mail sent to email - "
.
concat
(
email
));
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets