View Javadoc

1   /**
2    * Copyright 2011 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
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 }