001/**
002 * Copyright 2011 The Kuali Foundation Licensed under the
003 * Educational Community License, Version 2.0 (the "License"); you may
004 * not use this file except in compliance with the License. You may
005 * obtain a copy of the License at
006 *
007 * http://www.osedu.org/licenses/ECL-2.0
008 *
009 * Unless required by applicable law or agreed to in writing,
010 * software distributed under the License is distributed on an "AS IS"
011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing
013 * permissions and limitations under the License.
014 */
015
016package org.kuali.mobility.feedback.service;
017
018import javax.persistence.EntityManagerFactory;
019import javax.persistence.PersistenceUnit;
020
021import org.kuali.mobility.email.service.EmailService;
022import org.kuali.mobility.feedback.dao.FeedbackDao;
023import org.kuali.mobility.feedback.entity.Feedback;
024import org.springframework.beans.factory.annotation.Autowired;
025import org.springframework.transaction.annotation.Transactional;
026
027public class FeedbackServiceImpl implements FeedbackService {
028
029        private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
030                        .getLogger(FeedbackServiceImpl.class);
031
032        @PersistenceUnit
033        private EntityManagerFactory entityManagerFactory;
034
035        @Autowired
036        private FeedbackDao feedbackDao;
037
038        @Autowired
039        private EmailService emailService;
040
041        private String toEmailAddress;
042
043        private String fromEmailAddress;
044
045        @Override
046        @Transactional
047        public void saveFeedback(Feedback feedback) {
048                feedbackDao.saveFeedback(feedback);
049                sendEmail(feedback);
050        }
051
052        private void sendEmail(Feedback f) {
053                try {
054                        String fromEmail = fromEmailAddress;
055                        if (f.getEmail() != null) {
056                                fromEmail = f.getEmail();
057                        }
058                        emailService.sendEmail(f.toString(), "MIU Feedback",
059                                        toEmailAddress, fromEmail);                     
060                } catch (Exception e) {
061                        LOG.error("Error sending feedback email " + f.getFeedbackId(), e);
062                }
063        }       
064
065        public EntityManagerFactory getEntityManagerFactory() {
066                return entityManagerFactory;
067        }
068
069        public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
070                this.entityManagerFactory = entityManagerFactory;
071        }
072
073        public FeedbackDao getFeedbackDao() {
074                return feedbackDao;
075        }
076
077        public void setFeedbackDao(FeedbackDao feedbackDao) {
078                this.feedbackDao = feedbackDao;
079        }
080
081        public EmailService getEmailService() {
082                return emailService;
083        }
084
085        public void setEmailService(EmailService emailService) {
086                this.emailService = emailService;
087        }
088
089        public String getToEmailAddress() {
090                return toEmailAddress;
091        }
092
093        public void setToEmailAddress(String toEmailAddress) {
094                this.toEmailAddress = toEmailAddress;
095        }
096
097        public String getFromEmailAddress() {
098                return fromEmailAddress;
099        }
100
101        public void setFromEmailAddress(String fromEmailAddress) {
102                this.fromEmailAddress = fromEmailAddress;
103        }
104
105}