use of org.kuali.kfs.sys.mail.BodyMailMessage in project cu-kfs by CU-CommunityApps.
the class CuPdpEmailServiceImpl method sendAchAdviceEmail.
/**
* Send advice notification email to the payee receiving an ACH payment for both bundled and unbundled ACH payments.
*
* KFSPTS-1460:
* New method signature due to need for refactoring to deal with both the unbundled and bundled cases.
* The major change is that the paymentDetail input parameter is now a list of payment details instead of being a singleton.
* The caller will pass the entire list of payment detail records and sendAchAdviceEmail will loop through them taking into
* account cases for multiples and singletons when creating and sending the advice emails.
*
* @param paymentGroup Payment group corresponding to the payment detail records
* @param paymentDetails List of all payment details to process for the single advice email being sent
* @param customer Pdp customer profile for payment
*/
public void sendAchAdviceEmail(PaymentGroup paymentGroup, List<PaymentDetail> paymentDetails, CustomerProfile customer) {
LOG.debug("sendAchAdviceEmail() with payment details list starting");
Integer numPayments = 0;
String productionEnvironmentCode = kualiConfigurationService.getPropertyValueAsString(KFSConstants.PROD_ENVIRONMENT_CODE_KEY);
String environmentCode = kualiConfigurationService.getPropertyValueAsString(KFSConstants.ENVIRONMENT_KEY);
boolean shouldBundleAchPayments = this.getAchBundlerHelperService().shouldBundleAchPayments();
if (shouldBundleAchPayments) {
// Send out one email to the payee listing all the payment details for the specified payment group
BodyMailMessage bundledMessage = createAdviceMessageAndPopulateHeader(paymentGroup, customer, productionEnvironmentCode, environmentCode);
// create the formatted body
// this seems wasteful, but since the total net amount is needed in the message body before the payment details...it's needed
KualiDecimal totalNetAmount = new KualiDecimal(0);
Iterator<PaymentDetail> pdToNetAmountIter = paymentDetails.iterator();
while (pdToNetAmountIter.hasNext()) {
numPayments = numPayments + 1;
PaymentDetail pd = pdToNetAmountIter.next();
totalNetAmount = totalNetAmount.add(pd.getNetPaymentAmount());
}
// max # of payment detail records to include in email body as well as in the attachment, only used for non-DV advices
int maxNumDetailsForBody = 10;
StringBuffer bundledBody = createAdviceMessageBody(paymentGroup, customer, totalNetAmount, numPayments);
// format payment details based on the whether it is a DV or a PREQ
// formatting of payment details for DV is different than for PREQ
boolean adviceIsForDV = false;
// first time through loop
boolean firstPass = true;
StringBuffer bundledAtachmentData = new StringBuffer();
for (Iterator<PaymentDetail> payDetailsIter = paymentDetails.iterator(); payDetailsIter.hasNext(); ) {
PaymentDetail paymentDetail = payDetailsIter.next();
// initialize data the first time through the loop
if (firstPass) {
adviceIsForDV = (paymentDetail.getFinancialDocumentTypeCode().equalsIgnoreCase(DisbursementVoucherConstants.DOCUMENT_TYPE_CHECKACH)) ? true : false;
if (adviceIsForDV) {
// we will NOT be sending an attachment, all payment detail will be in the body of the message
bundledBody.append(getMessage(CUPdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_BODY_PAYMENT_HEADER_LINE_ONE));
bundledBody.append(customer.getAdviceHeaderText());
bundledBody.append(getMessage(CUPdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_BODY_PAYMENT_SEPARATOR));
} else {
// we will be sending an attachment
bundledAtachmentData = new StringBuffer();
// creating the payment detail table header
bundledAtachmentData.append(getMessage(CUPdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_ATTACHMENT_HEADING_SUMMARY_LINE_ONE));
bundledAtachmentData.append(getMessage(CUPdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_ATTACHMENT_HEADING_SUMMARY_LINE_TWO));
bundledAtachmentData.append(getMessage(CUPdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_ATTACHMENT_HEADING_SUMMARY_LINE_THREE));
// verbiage describing the payment details and attachment
bundledBody.append(getMessage(CUPdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_BODY_DETAIL_INFO_MSG, numPayments));
if (numPayments <= maxNumDetailsForBody) {
// email body will have details and an attachment will be sent
bundledBody.append(getMessage(CUPdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_BODY_DETAIL_UNDER_LIMIT_MSG));
// individual customer message for the payment
bundledBody.append(customer.getAdviceHeaderText());
bundledBody.append(getMessage(CUPdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_BODY_PAYMENT_SEPARATOR));
}
// implied else that numPayments is over the max so only send an attachment
}
// ensure headers only included once
firstPass = false;
}
if (adviceIsForDV) {
// format payment detail information and include it in the message body, do not send an attachment
bundledBody.append(createAdviceMessagePaymentDetail(paymentGroup, paymentDetail, adviceIsForDV, shouldBundleAchPayments));
} else {
// put payment detail information in the attachment
bundledAtachmentData.append(createAdviceMessagePaymentDetail(paymentGroup, paymentDetail, adviceIsForDV, shouldBundleAchPayments));
// also put payment detail in the body when the number of payments is fewer than the max
if (numPayments <= maxNumDetailsForBody) {
// explicitly using false instead of shouldBundleAchPayments so that we get the correct format for the email body
bundledBody.append(createAdviceMessagePaymentDetail(paymentGroup, paymentDetail, adviceIsForDV, false));
}
}
}
// for-loop
bundledMessage.setMessage(bundledBody.toString());
if (!adviceIsForDV) {
// only create the attachment file when the payments are NOT for DV's
Formatter integerFormatter = new IntegerFormatter();
String attachmentFileName = new String("paymentDetailsForDisbursement_" + (String) integerFormatter.formatForPresentation(paymentGroup.getDisbursementNbr()) + ".csv");
bundledMessage.setAttachmentFileName(attachmentFileName);
bundledMessage.setAttachmentContent(bundledAtachmentData.toString().getBytes());
bundledMessage.setAttachmentContentType(new String("text/csv"));
}
sendFormattedAchAdviceEmail(bundledMessage, customer, paymentGroup, productionEnvironmentCode, environmentCode);
} else {
// so that the appropriate mail "send" is invoked based on the message type that we created and passed.
for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) {
numPayments = paymentGroup.getPaymentDetails().size();
BodyMailMessage nonBundledMessage = createAdviceMessageAndPopulateHeader(paymentGroup, customer, productionEnvironmentCode, environmentCode);
StringBuffer nonBundledBody = createAdviceMessageBody(paymentGroup, customer, paymentDetail.getNetPaymentAmount(), numPayments);
nonBundledBody.append(getMessage(CUPdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_BODY_PAYMENT_HEADER_LINE_ONE));
nonBundledBody.append(customer.getAdviceHeaderText());
nonBundledBody.append(getMessage(CUPdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_BODY_PAYMENT_SEPARATOR));
boolean adviceIsForDV = (paymentDetail.getFinancialDocumentTypeCode().equalsIgnoreCase(DisbursementVoucherConstants.DOCUMENT_TYPE_CHECKACH)) ? true : false;
nonBundledBody.append(createAdviceMessagePaymentDetail(paymentGroup, paymentDetail, adviceIsForDV, shouldBundleAchPayments));
nonBundledMessage.setMessage(nonBundledBody.toString());
sendFormattedAchAdviceEmail(nonBundledMessage, customer, paymentGroup, productionEnvironmentCode, environmentCode);
}
}
}
use of org.kuali.kfs.sys.mail.BodyMailMessage in project cu-kfs by CU-CommunityApps.
the class CUTransactionFilter method doFilter.
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
boolean error = false;
String errorText = "";
HttpServletRequest httpReq = (HttpServletRequest) req;
if (!TransactionSynchronizationManager.getResourceMap().isEmpty()) {
errorText = errorText + ("Before: The Resource map is not empty. THIS IS SOOO BAD. URL: " + httpReq.getRequestURL());
LOG.error("Before: The Resource map is not empty. THIS IS SOOO BAD. URL: " + httpReq.getRequestURL());
Map aMap = TransactionSynchronizationManager.getResourceMap();
int mapsize = aMap.size();
Iterator keyValuePairs1 = aMap.entrySet().iterator();
for (int i = 0; i < mapsize; i++) {
Map.Entry entry = (Map.Entry) keyValuePairs1.next();
errorText = errorText + ("; Resources: key: " + entry.getKey().toString() + " ; Value " + entry.getValue().toString());
LOG.error("Resources: key: " + entry.getKey().toString() + " ; Value " + entry.getValue().toString());
}
error = true;
}
try {
chain.doFilter(req, res);
} finally {
if (TransactionSynchronizationManager.isSynchronizationActive()) {
LOG.error("JTA synchronizations are not active. THIS IS SOOO BAD. " + httpReq.getRequestURL());
error = true;
}
if (!TransactionSynchronizationManager.getResourceMap().isEmpty()) {
errorText = errorText + "After: The Resource map is not empty. THIS IS SOOO BAD.";
LOG.error("After: The Resource map is not empty. THIS IS SOOO BAD. URL: " + httpReq.getRequestURL());
Map aMap = TransactionSynchronizationManager.getResourceMap();
int mapsize = aMap.size();
Iterator keyValuePairs1 = aMap.entrySet().iterator();
for (int i = 0; i < mapsize; i++) {
Map.Entry entry = (Map.Entry) keyValuePairs1.next();
errorText = errorText + ("; Resources: key: " + entry.getKey().toString() + " ; Value " + entry.getValue().toString());
LOG.error("Resources: key: " + entry.getKey().toString() + " ; Value " + entry.getValue().toString());
}
error = true;
}
if (error) {
try {
LOG.error("ERROR Found! Sending an email...");
BodyMailMessage mm = new BodyMailMessage();
mm.addToAddress("kwk43@cornell.edu");
mm.setFromAddress("kwk43@cornell.edu");
mm.setSubject("There might be a closed connection problem. Please check the logs. Seach for the following phrase: SOOO BAD");
mm.setMessage("Request URL which had the problem: " + httpReq.getRequestURL() + " errorText = " + errorText);
SpringContext.getBean(EmailService.class).sendMessage(mm, false);
} catch (Throwable t) {
LOG.error("Error sending email.", t);
}
}
}
}
use of org.kuali.kfs.sys.mail.BodyMailMessage in project cu-kfs by CU-CommunityApps.
the class IWantDocumentServiceImpl method sendDocumentFinalizedMessage.
/**
* @see edu.cornell.kfs.module.purap.document.service.IWantDocumentService#sendDocumentFinalizedMessage(edu.cornell.kfs.module.purap.document.IWantDocument)
*/
public void sendDocumentFinalizedMessage(IWantDocument iWantDocument) {
BodyMailMessage message = buildDocumentFinalizedMessage(iWantDocument);
emailService.sendMessage(message, false);
}
use of org.kuali.kfs.sys.mail.BodyMailMessage in project cu-kfs by CU-CommunityApps.
the class IWantDocumentServiceImpl method buildDocumentFinalizedMessage.
/**
* Builds an email message to be sent when the input document has been finalized.
*
* @param iWantDocument
* @return an email message to be sent when the input document has been finalized
*/
private BodyMailMessage buildDocumentFinalizedMessage(IWantDocument iWantDocument) {
WorkflowDocument workflowDocument = iWantDocument.getDocumentHeader().getWorkflowDocument();
String initiator = workflowDocument.getInitiatorPrincipalId();
String documentNumber = iWantDocument.getDocumentNumber();
Person initiatorPerson = personService.getPerson(initiator);
String initiatorEmail = initiatorPerson.getEmailAddressUnmasked();
BodyMailMessage message = new BodyMailMessage();
message.addToAddress(initiatorEmail);
message.setFromAddress(initiatorEmail);
message.setSubject("I Want document: " + documentNumber + " has been finalized");
StringBuilder emailBody = new StringBuilder();
String vendorName = iWantDocument.getVendorName();
if (vendorName == null) {
vendorName = StringUtils.EMPTY;
}
emailBody.append("This is a message to inform you that the I Want document ").append(iWantDocument.getDocumentNumber()).append(" has been finalized: ").append(KRADConstants.NEWLINE).append(KRADConstants.NEWLINE);
emailBody.append("From: ").append(initiatorPerson.getNameUnmasked()).append(KRADConstants.NEWLINE);
emailBody.append("Title: ").append(iWantDocument.getDocumentTitle()).append(KRADConstants.NEWLINE);
emailBody.append("Type: ").append(workflowDocument.getDocumentTypeName()).append(KRADConstants.NEWLINE);
emailBody.append("Id: ").append(documentNumber).append(KRADConstants.NEWLINE);
emailBody.append("Vendor Name: ").append(vendorName).append("\n\n");
String docUrl = getDocumentURL(documentNumber, workflowDocument);
emailBody.append(" Go here to view this item: ").append(docUrl).append(KRADConstants.NEWLINE);
message.setMessage(emailBody.toString());
return message;
}
Aggregations