// create a MailMessageVO
MailMessageVO messageVO = new MailMessageVO();
if (attachmentFileIDs != null && attachmentFileIDs.size() > 0) {
CvFileFacade fileRemote = new CvFileFacade();
for (int i = 0; i < attachmentFileIDs.size(); i++) {
int fileID = ((Integer)attachmentFileIDs.get(i)).intValue();
// get the CvFileVO from the EJB layer
CvFileVO fileVO = fileRemote.getFile(individualID, fileID, dataSource);
if (fileVO != null) {
// add this attachment to the messageVO
messageVO.addAttachedFiles(fileVO);
}
}
}
// Send Email to all the Individual with the updated information of
// the Template
PrintTemplateHome PTHome = (PrintTemplateHome)CVUtility.getHomeObject(
"com.centraview.printtemplate.PrintTemplateHome", "Printtemplate");
PrintTemplate PTRemote = PTHome.create();
PTRemote.setDataSource(dataSource);
if (ptfrom != null && !ptfrom.equals("") && !ptfrom.equals("null")) {
int accountID = Integer.parseInt(ptfrom);
Message[0] = PTRemote.sendPTEmail(individualID, accountID, emailList, ptSubject,
ptContent, messageVO);
}
} else {
// generate the Previewed Template into a File.
try {
CvFileFacade cvf = new CvFileFacade();
CvFileHome homeFile = (CvFileHome)CVUtility.getHomeObject(
"com.centraview.file.CvFileHome", "CvFile");
CvFile remoteFile = homeFile.create();
remoteFile.setDataSource(dataSource);
CvFolderVO homeFld = remoteFile.getHomeFolder(individualID);
int rn = (new Random()).nextInt();
Calendar c = Calendar.getInstance();
java.util.Date dt = c.getTime();
DateFormat df = new SimpleDateFormat("MM_dd_yyyy");
String dateStamp = df.format(dt);
CvFileVO flvo = new CvFileVO();
flvo.setTitle("Print Template_" + rn);
flvo.setName("Template_" + "_" + rn + "_" + dateStamp + ".html");
Message[1] = "Template_" + "_" + rn + "_" + dateStamp + ".html";
flvo.setPhysicalFolder(homeFld.getFolderId());
flvo.setIsTemporary("NO");
flvo.setOwner(individualID);
flvo.setPhysical(CvFileVO.FP_PHYSICAL);
StringBuffer documentContent = new StringBuffer();
for (int i = 0; i < ptContent.size(); i++) {
documentContent.append(ptContent.get(i));
if (i != (ptContent.size() - 1)) {
documentContent.append("<br><<Page Break>><br>");
}
}
ByteArrayInputStream inputStream = new ByteArrayInputStream(documentContent.toString()
.getBytes());
// Add the File to the Files Module so that we can download it...
int fileId = cvf.addFile(individualID, homeFld.getFolderId(), flvo, inputStream,
dataSource);
Message[2] = String.valueOf(fileId);
} catch (Exception e) {
logger.error("[execute] Exception thrown.", e);
}