1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.mobility.feedback.service;
17
18 import javax.persistence.EntityManagerFactory;
19 import javax.persistence.PersistenceUnit;
20
21 import org.kuali.mobility.email.service.EmailService;
22 import org.kuali.mobility.feedback.dao.FeedbackDao;
23 import org.kuali.mobility.feedback.entity.Feedback;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.transaction.annotation.Transactional;
26
27 public class FeedbackServiceImpl implements FeedbackService {
28
29 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
30 .getLogger(FeedbackServiceImpl.class);
31
32 @PersistenceUnit
33 private EntityManagerFactory entityManagerFactory;
34
35 @Autowired
36 private FeedbackDao feedbackDao;
37
38 @Autowired
39 private EmailService emailService;
40
41 private String toEmailAddress;
42
43 private String fromEmailAddress;
44
45 @Override
46 @Transactional
47 public void saveFeedback(Feedback feedback) {
48 feedbackDao.saveFeedback(feedback);
49 sendEmail(feedback);
50 }
51
52 private void sendEmail(Feedback f) {
53 try {
54 String fromEmail = fromEmailAddress;
55 if (f.getEmail() != null) {
56 fromEmail = f.getEmail();
57 }
58 emailService.sendEmail(f.toString(), "MIU Feedback",
59 toEmailAddress, fromEmail);
60 } catch (Exception e) {
61 LOG.error("Error sending feedback email " + f.getFeedbackId(), e);
62 }
63 }
64
65 public EntityManagerFactory getEntityManagerFactory() {
66 return entityManagerFactory;
67 }
68
69 public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
70 this.entityManagerFactory = entityManagerFactory;
71 }
72
73 public FeedbackDao getFeedbackDao() {
74 return feedbackDao;
75 }
76
77 public void setFeedbackDao(FeedbackDao feedbackDao) {
78 this.feedbackDao = feedbackDao;
79 }
80
81 public EmailService getEmailService() {
82 return emailService;
83 }
84
85 public void setEmailService(EmailService emailService) {
86 this.emailService = emailService;
87 }
88
89 public String getToEmailAddress() {
90 return toEmailAddress;
91 }
92
93 public void setToEmailAddress(String toEmailAddress) {
94 this.toEmailAddress = toEmailAddress;
95 }
96
97 public String getFromEmailAddress() {
98 return fromEmailAddress;
99 }
100
101 public void setFromEmailAddress(String fromEmailAddress) {
102 this.fromEmailAddress = fromEmailAddress;
103 }
104
105 }