📄 statusemail.java
字号:
/*******************************************************************************
* ***** BEGIN LICENSE BLOCK Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is the OpenCustomer CRM.
*
* The Initial Developer of the Original Code is Thomas Bader (Bader & Jene
* Software-Ingenieurb黵o). Portions created by the Initial Developer are
* Copyright (C) 2005 the Initial Developer. All Rights Reserved.
*
* Contributor(s): Thomas Bader <thomas.bader@bader-jene.de>
* Felix Breske <felix.breske@bader-jene.de>
*
* ***** END LICENSE BLOCK *****
*/
package org.opencustomer.connector.mail.messages;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.ResourceBundle;
import javax.mail.Message.RecipientType;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import org.apache.log4j.Logger;
import org.opencustomer.connector.mail.Email;
import org.opencustomer.connector.mail.exception.NoValidSenderException;
import org.opencustomer.db.vo.calendar.EventVO;
import org.opencustomer.db.vo.crm.JobVO;
import org.opencustomer.db.vo.system.UserVO;
/**
* The status email sends a overview of the actual evens and acitvities.
* @author fbreske
*
*/
public class StatusEmail extends Email
{
public static final Logger log = Logger.getLogger(StatusEmail.class);
private ArrayList<EventVO> events;
private ArrayList<JobVO> jobs;
private UserVO recipient;
/**
* Reads sender email address from ResourceBundle ("WebResource") "mail.reminder.sender".
* @throws AddressException
*/
public StatusEmail() throws AddressException
{
super();
events = new ArrayList<EventVO>();
jobs = new ArrayList<JobVO>();
setSender(new InternetAddress(ResourceBundle.getBundle("WebResources").getString("mail.status.sender")));
}
/**
* Adds a UserVO to the list of recipients.
* @param recipient The UserVo of the recipient.
* @throws NoValidSenderException if the recipient has no email address.
*/
public void addRecipient(UserVO user)
{
this.recipient = user;
if(user.getPerson() != null)
{
try
{
addRecipient(new Recipient(RecipientType.TO, new InternetAddress(user.getPerson().getEmail())));
}
catch (AddressException e)
{
log.error("recipient " + user.getUserName() + " has no valid email address",e);
}
}
else
{
log.warn("no person for user: " + recipient.getUserName());
}
}
/**
*
* @return the list of ActitivyVO in this email.
*/
public ArrayList<JobVO> getJobs()
{
return jobs;
}
/**
*
* @param job the JobVO to add.
*/
public void addJobs(JobVO job)
{
jobs.add(job);
}
/**
*
* @return the list of EventVO.
*/
public ArrayList<EventVO> getEvents()
{
return events;
}
/**
*
* @param event the EventVO to add.
*/
public void addEvents(EventVO event)
{
events.add(event);
}
/**
* This method overrides getTextMessageBody from Email.
* Reads the content from the resource bundle, and generates the email.
* @return The text Message Body from the reminder mail.
*/
@Override
public String getTextMessageBody()
{
String newline = System.getProperty("line.separator");
ResourceBundle resourceBundle = ResourceBundle.getBundle("WebResources", recipient.getLocale());
StringBuilder textMessage = new StringBuilder();
textMessage.append(resourceBundle.getString("mail.status.salutation"));
textMessage.append(" ").append(recipient.getPerson().getFirstName());
textMessage.append(" ").append(recipient.getPerson().getLastName()).append(",");
textMessage.append(newline).append(newline);
textMessage.append(resourceBundle.getString("mail.status.header")).append(newline).append(newline);
if(jobs.size() > 0)
{
textMessage.append(resourceBundle.getString("mail.status.headline.job")).append(newline);
for(JobVO job : jobs)
{
textMessage.append(resourceBundle.getString("entity.crm.job.subject")).append(": ");
textMessage.append(job.getSubject()).append(newline);
if(job.getReferencedCompany() != null || job.getReferencedCompany() != null)
{
textMessage.append(resourceBundle.getString("entity.crm.job.reference")).append(": ");
if(job.getReferencedPerson() != null)
textMessage.append(job.getReferencedPerson().getFirstName()).append(" ").append(job.getReferencedPerson().getLastName());
if(job.getReferencedCompany() != null)
textMessage.append(" ").append(job.getReferencedCompany());
textMessage.append(newline);
}
textMessage.append(resourceBundle.getString("entity.crm.job.status")).append(": ");
if(job.getStatus() == JobVO.Status.COMPLETED)
textMessage.append(resourceBundle.getString("entity.crm.job.status.completed")).append(newline);
else if(job.getStatus() == JobVO.Status.IN_PROGRESS)
textMessage.append(resourceBundle.getString("entity.crm.job.status.inProgress")).append(newline);
else if(job.getStatus() == JobVO.Status.PLANNED)
textMessage.append(resourceBundle.getString("entity.crm.job.status.planned")).append(newline);
textMessage.append(resourceBundle.getString("entity.crm.job.priority")).append(": ");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -