Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kuali.rice.krad.service.impl;
 
 import java.util.Set;
 
This class implements the KualiFeedbackService and contains logic to send a feedback email to the feedback email list with information from users.
 
 public class KualiFeedbackServiceImpl implements KualiFeedbackService {
 	
 	private static final Logger LOG = Logger.getLogger(KualiFeedbackServiceImpl.class);
 	
 	private static final String FEEDBACK_EMAIL_SUBJECT_PARAM = "feedback.email.subject";
 	private static final String FEEDBACK_EMAIL_BODY_PARAM = "feedback.email.body";

A Mailer for sending report.
 
 	private Mailer mailer;
An email template is used to construct an email to be sent by the mail service.
 
This mails the report using the mail service from the mail template.

 
 	public void emailReport(String subjectString messagethrows Exception {
 		if (.isTraceEnabled()) {
 			String lm=String.format("ENTRY %s;%s",
 					(subject==null)?"null":subject.toString(),
 							(message==null)?"null":message.toString());
 			.trace(lm);
 		}
 
 		if ( == null) {
 			String errorMessage = "mailer property of KualiExceptionIncidentServiceImpl is null";
 			.fatal(errorMessage);
 			throw new IllegalStateException(errorMessage);
 		}
 
 		// Send mail
 		MailMessage msg = createMailMessage(subjectmessage);
 
 		if (.isTraceEnabled()) {
 			.trace("EXIT");
 		}
 	}
 
 	public void sendFeedback(String documentIdString componentNameString descriptionthrows Exception {
 		this.emailReport(this.createFeedbackReportSubject(), this.createFeedbackReportMessage(documentIdcomponentNamedescription));
 	}
 	
 		String subject = MessageFormat.format(formatStringenv);
 		return subject;
 	}
 
 	private String createFeedbackReportMessage(String documentIdString componentNameString description) {
 		documentId = (documentId == null) ? "" : documentId;
 		componentName = (componentName == null) ? "" : componentName;
 		description = (description == null) ? "" : description;
		String principalName = GlobalVariables.getUserSession().getLoggedInUserPrincipalName();
		principalName = (principalName == null) ? "" : principalName;
		String message = MessageFormat.format(formatStringdocumentIdprincipalNamecomponentNamedescription);
		return message;
	}

Creates an instance of MailMessage from the inputs using the given template.

Parameters:
subject the subject line text
message the body of the email message
Returns:
MailMessage
Throws:
java.lang.IllegalStateException if the <codeREPORT_MAIL_LIST</code> is not set or messageTemplate does not have ToAddresses already set.
    @SuppressWarnings("unchecked")
    protected MailMessage createMailMessage(String subjectString message)
            throws Exception {
            String lm=String.format("ENTRY %s%n%s",
                    (subject==null) ? "null" : subject.toString(),
                    (message==null) ? "null" : message.toString());
            .trace(lm);
        }
        
        MailMessage messageTemplate = this.getMessageTemplate();
        if (messageTemplate == null) {
            throw new IllegalStateException(String.format(
                    "%s.templateMessage is null or not set",
                    this.getClass().getName()));
        }
        
        // Copy input message reference for creating an instance of mail message
        MailMessage msg=new MailMessage();
        
        msg.setFromAddress(this.getFromAddress());
    	msg.setToAddresses(this.getToAddresses());
        msg.setBccAddresses(this.getBccAddresses());
        msg.setCcAddresses(this.getCcAddresses());
        // Set mail message subject
        msg.setSubject((subject==null) ? "" : subject);
        // Set mail message body
        msg.setMessage((message==null) ? "" : message);
        
        if (.isTraceEnabled()) {
            String lm = String.format("EXIT %s", (msg==null) ? "null" : msg.toString());
            .trace(lm);
        }
        return msg;
	}
	protected String getFromAddress() {    
		Person actualUser = GlobalVariables.getUserSession().getActualPerson();
        
        String fromEmail = actualUser.getEmailAddress();
        if (StringUtils.isNotBlank(fromEmail)) {
        	return fromEmail;
    	} else {
        	return this.getMessageTemplate().getFromAddress();
    	}
	}
	protected Set<StringgetToAddresses() {
		// First check if message template already define mailing list
        Set<Stringemails = this.getMessageTemplate().getToAddresses();
        if (emails == null || emails.isEmpty()) {
    		String mailingList = KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString(this.getToAddressesPropertyName());
            if (StringUtils.isBlank(mailingList)) {
                String em =  + " is not set or messageTemplate does not have ToAddresses already set.";
                .error(em);
                throw new IllegalStateException(em);
            } else {
                return new HashSet<String>(Arrays.asList(StringUtils.split(mailingList,
                                .)));
            }
        } else {
            return emails;
        }
	}
	}
	protected Set<StringgetCcAddresses() {
	}
	protected Set<StringgetBccAddresses() {
	}
	public Mailer getMailer() {
		return ;
	}
	public final void setMailer(Mailer mailer) {
		this. = mailer;
	}
	}
	public void setMessageTemplate(MailMessage messageTemplate) {
		this. = messageTemplate;
	}
New to GrepCode? Check out our FAQ X