1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.pdp.batch.service.impl;
17
18 import java.io.BufferedWriter;
19 import java.io.File;
20 import java.io.FileWriter;
21 import java.io.IOException;
22 import java.sql.Timestamp;
23 import java.text.MessageFormat;
24 import java.text.SimpleDateFormat;
25 import java.util.ArrayList;
26 import java.util.Date;
27 import java.util.HashMap;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Map;
31
32 import org.apache.commons.lang.StringUtils;
33 import org.kuali.ole.pdp.PdpConstants;
34 import org.kuali.ole.pdp.PdpKeyConstants;
35 import org.kuali.ole.pdp.batch.service.ExtractPaymentService;
36 import org.kuali.ole.pdp.businessobject.CustomerProfile;
37 import org.kuali.ole.pdp.businessobject.PaymentDetail;
38 import org.kuali.ole.pdp.businessobject.PaymentGroup;
39 import org.kuali.ole.pdp.businessobject.PaymentGroupHistory;
40 import org.kuali.ole.pdp.businessobject.PaymentNoteText;
41 import org.kuali.ole.pdp.businessobject.PaymentProcess;
42 import org.kuali.ole.pdp.businessobject.PaymentStatus;
43 import org.kuali.ole.pdp.dataaccess.PaymentGroupHistoryDao;
44 import org.kuali.ole.pdp.dataaccess.ProcessDao;
45 import org.kuali.ole.pdp.service.PaymentDetailService;
46 import org.kuali.ole.pdp.service.PaymentGroupService;
47 import org.kuali.ole.pdp.service.PdpEmailService;
48 import org.kuali.ole.sys.batch.InitiateDirectoryBase;
49 import org.kuali.ole.sys.businessobject.Bank;
50 import org.kuali.rice.core.api.config.property.ConfigurationService;
51 import org.kuali.rice.core.api.datetime.DateTimeService;
52 import org.kuali.rice.core.api.util.type.KualiDecimal;
53 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
54 import org.kuali.rice.krad.service.BusinessObjectService;
55 import org.kuali.rice.krad.util.ObjectUtils;
56 import org.kuali.rice.location.api.country.Country;
57 import org.kuali.rice.location.api.country.CountryService;
58 import org.springframework.transaction.annotation.Transactional;
59
60 @Transactional
61 public class ExtractPaymentServiceImpl extends InitiateDirectoryBase implements ExtractPaymentService {
62 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ExtractPaymentServiceImpl.class);
63
64 protected String directoryName;
65
66 protected DateTimeService dateTimeService;
67 protected ParameterService parameterService;
68 protected PaymentGroupService paymentGroupService;
69 protected PaymentDetailService paymentDetailService;
70 protected PaymentGroupHistoryDao paymentGroupHistoryDao;
71 protected ProcessDao processDao;
72 protected PdpEmailService paymentFileEmailService;
73 protected BusinessObjectService businessObjectService;
74 protected ConfigurationService kualiConfigurationService;
75 protected CountryService countryService;
76
77
78
79 public static boolean testMode = false;
80
81
82
83
84
85
86
87
88 protected String getOutputFile(String fileprefix, Date runDate) {
89
90
91 prepareDirectories(getRequiredDirectoryNames());
92
93 String filename = directoryName + "/" + fileprefix + "_";
94 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
95 filename = filename + sdf.format(runDate);
96 filename = filename + ".xml";
97
98 return filename;
99 }
100
101
102
103
104 @Override
105 public void extractCanceledChecks() {
106 LOG.debug("extractCancelledChecks() started");
107
108 Date processDate = dateTimeService.getCurrentDate();
109 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
110
111 String checkCancelledFilePrefix = this.kualiConfigurationService.getPropertyValueAsString(PdpKeyConstants.ExtractPayment.CHECK_CANCEL_FILENAME);
112 checkCancelledFilePrefix = MessageFormat.format(checkCancelledFilePrefix, new Object[] { null });
113
114 String filename = getOutputFile(checkCancelledFilePrefix, processDate);
115 if (LOG.isDebugEnabled()) {
116 LOG.debug("extractCanceledChecks() filename = " + filename);
117 }
118
119
120 BufferedWriter os = null;
121
122 try {
123 os = new BufferedWriter(new FileWriter(filename));
124 os.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
125 writeOpenTag(os, 0, "canceledChecks");
126
127 Iterator paymentIterator = paymentGroupHistoryDao.getCanceledChecks();
128 while (paymentIterator.hasNext()) {
129 PaymentGroupHistory history = (PaymentGroupHistory) paymentIterator.next();
130
131 writeOpenTag(os, 2, "check");
132
133 writeBank(os, 4, history.getPaymentGroup().getBank());
134 writePayee(os, 4, history.getPaymentGroup());
135
136 writeTag(os, 4, "netAmount", history.getPaymentGroup().getNetPaymentAmount().toString());
137 if (ObjectUtils.isNotNull(history.getOrigDisburseNbr())) {
138 writeTag(os, 4, "disbursementNumber", history.getOrigDisburseNbr().toString());
139 }
140 else {
141 writeTag(os, 4, "disbursementNumber", history.getPaymentGroup().getDisbursementNbr().toString());
142 }
143 if (ObjectUtils.isNotNull(history.getPaymentGroup().getDisbursementType())) {
144 writeTag(os, 4, "disbursementType", history.getPaymentGroup().getDisbursementType().getCode());
145 }
146 else {
147 writeTag(os, 4, "disbursementType", history.getDisbursementType().getCode());
148 }
149
150 writeCloseTag(os, 2, "check");
151
152 if (!testMode) {
153 history.setLastUpdate(new Timestamp(processDate.getTime()));
154 history.setPmtCancelExtractDate(new Timestamp(processDate.getTime()));
155 history.setPmtCancelExtractStat(Boolean.TRUE);
156 history.setChangeTime(new Timestamp(new Date().getTime()));
157
158 this.businessObjectService.save(history);
159 }
160 }
161
162 writeCloseTag(os, 0, "canceledChecks");
163 createDoneFile(filename);
164 }
165 catch (IOException ie) {
166 LOG.error("extractCanceledChecks() Problem reading file: " + filename, ie);
167 throw new IllegalArgumentException("Error writing to output file: " + ie.getMessage());
168 }
169 finally {
170
171 if (os != null) {
172 try {
173 os.close();
174 }
175 catch (IOException ie) {
176
177 }
178 }
179 }
180 }
181
182
183
184
185 @Override
186 public void extractAchPayments() {
187 LOG.debug("extractAchPayments() started");
188
189 Date processDate = dateTimeService.getCurrentDate();
190 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
191 PaymentStatus extractedStatus = (PaymentStatus) this.businessObjectService.findBySinglePrimaryKey(PaymentStatus.class, PdpConstants.PaymentStatusCodes.EXTRACTED);
192
193 String achFilePrefix = this.kualiConfigurationService.getPropertyValueAsString(PdpKeyConstants.ExtractPayment.ACH_FILENAME);
194 achFilePrefix = MessageFormat.format(achFilePrefix, new Object[] { null });
195
196 String filename = getOutputFile(achFilePrefix, processDate);
197 if (LOG.isDebugEnabled()) {
198 LOG.debug("extractAchPayments() filename = " + filename);
199 }
200
201
202 BufferedWriter os = null;
203
204 writeExtractAchFile(extractedStatus, filename, processDate, sdf);
205 createDoneFile(filename);
206
207 }
208
209
210
211
212 @Override
213 public void extractChecks() {
214 LOG.debug("extractChecks() started");
215
216 Date processDate = dateTimeService.getCurrentDate();
217 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
218 PaymentStatus extractedStatus = (PaymentStatus) this.businessObjectService.findBySinglePrimaryKey(PaymentStatus.class, PdpConstants.PaymentStatusCodes.EXTRACTED);
219
220 String checkFilePrefix = this.kualiConfigurationService.getPropertyValueAsString(PdpKeyConstants.ExtractPayment.CHECK_FILENAME);
221 checkFilePrefix = MessageFormat.format(checkFilePrefix, new Object[] { null });
222
223 String filename = getOutputFile(checkFilePrefix, processDate);
224 if (LOG.isDebugEnabled()) {
225 LOG.debug("extractChecks() filename: " + filename);
226 }
227
228 List<PaymentProcess> extractsToRun = this.processDao.getAllExtractsToRun();
229 for (PaymentProcess extractToRun : extractsToRun) {
230 writeExtractCheckFile(extractedStatus, extractToRun, filename, extractToRun.getId().intValue());
231 extractToRun.setExtractedInd(true);
232 businessObjectService.save(extractToRun);
233 }
234 }
235
236 protected void writeExtractCheckFile(PaymentStatus extractedStatus, PaymentProcess p, String filename, Integer processId) {
237 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
238 Date processDate = dateTimeService.getCurrentDate();
239 BufferedWriter os = null;
240
241 try {
242 os = new BufferedWriter(new FileWriter(filename));
243 os.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
244 writeOpenTagAttribute(os, 0, "checks", "processId", processId.toString(), "campusCode", p.getCampusCode());
245
246 List<String> bankCodes = paymentGroupService.getDistinctBankCodesForProcessAndType(processId, PdpConstants.DisbursementTypeCodes.CHECK);
247
248 for (String bankCode : bankCodes) {
249 List<Integer> disbNbrs = paymentGroupService.getDisbursementNumbersByDisbursementTypeAndBankCode(processId, PdpConstants.DisbursementTypeCodes.CHECK, bankCode);
250 for (Iterator<Integer> iter = disbNbrs.iterator(); iter.hasNext();) {
251 Integer disbursementNbr = iter.next();
252
253 boolean first = true;
254
255 KualiDecimal totalNetAmount = new KualiDecimal(0);
256
257
258 Iterator<PaymentDetail> i2 = paymentDetailService.getByDisbursementNumber(disbursementNbr, processId, PdpConstants.DisbursementTypeCodes.CHECK, bankCode);
259 while (i2.hasNext()) {
260 PaymentDetail pd = i2.next();
261 totalNetAmount = totalNetAmount.add(pd.getNetPaymentAmount());
262 }
263
264 Iterator<PaymentDetail> paymentDetails = paymentDetailService.getByDisbursementNumber(disbursementNbr, processId, PdpConstants.DisbursementTypeCodes.CHECK, bankCode);
265 while (paymentDetails.hasNext()) {
266 PaymentDetail detail = paymentDetails.next();
267 PaymentGroup group = detail.getPaymentGroup();
268 if (!testMode) {
269 group.setDisbursementDate(new java.sql.Date(processDate.getTime()));
270 group.setPaymentStatus(extractedStatus);
271 this.businessObjectService.save(group);
272 }
273
274 if (first) {
275 writeOpenTagAttribute(os, 2, "check", "disbursementNbr", group.getDisbursementNbr().toString());
276
277
278
279 writeBank(os, 4, group.getBank());
280
281 writeTag(os, 4, "disbursementDate", sdf.format(processDate));
282 writeTag(os, 4, "netAmount", totalNetAmount.toString());
283
284 writePayee(os, 4, group);
285 writeTag(os, 4, "campusAddressIndicator", group.getCampusAddress().booleanValue() ? "Y" : "N");
286 writeTag(os, 4, "attachmentIndicator", group.getPymtAttachment().booleanValue() ? "Y" : "N");
287 writeTag(os, 4, "specialHandlingIndicator", group.getPymtSpecialHandling().booleanValue() ? "Y" : "N");
288 writeTag(os, 4, "immediatePaymentIndicator", group.getProcessImmediate().booleanValue() ? "Y" : "N");
289 writeTag(os, 4, "paymentDate", sdf.format(group.getPaymentDate()));
290
291
292 CustomerProfile cp = group.getBatch().getCustomerProfile();
293 writeCustomerProfile(os, 4, cp);
294
295 writeOpenTag(os, 4, "payments");
296
297 }
298
299 writeOpenTag(os, 6, "payment");
300
301 writeTag(os, 8, "purchaseOrderNbr", detail.getPurchaseOrderNbr());
302 writeTag(os, 8, "invoiceNbr", detail.getInvoiceNbr());
303 writeTag(os, 8, "requisitionNbr", detail.getRequisitionNbr());
304 writeTag(os, 8, "custPaymentDocNbr", detail.getCustPaymentDocNbr());
305 writeTag(os, 8, "customerUnivNbr", detail.getCustomerInstitutionNumber());
306 writeTag(os, 8, "invoiceDate", sdf.format(detail.getInvoiceDate()));
307
308 writeTag(os, 8, "origInvoiceAmount", detail.getOrigInvoiceAmount().toString());
309 writeTag(os, 8, "netPaymentAmount", detail.getNetPaymentAmount().toString());
310 writeTag(os, 8, "invTotDiscountAmount", detail.getInvTotDiscountAmount().toString());
311 writeTag(os, 8, "invTotShipAmount", detail.getInvTotShipAmount().toString());
312 writeTag(os, 8, "invTotOtherDebitAmount", detail.getInvTotOtherDebitAmount().toString());
313 writeTag(os, 8, "invTotOtherCreditAmount", detail.getInvTotOtherCreditAmount().toString());
314
315 writeOpenTag(os, 8, "notes");
316 for (Iterator ix = detail.getNotes().iterator(); ix.hasNext();) {
317 PaymentNoteText note = (PaymentNoteText) ix.next();
318 writeTag(os, 10, "note", note.getCustomerNoteText());
319 }
320 writeCloseTag(os, 8, "notes");
321
322 writeCloseTag(os, 6, "payment");
323
324 first = false;
325 }
326 writeCloseTag(os, 4, "payments");
327 writeCloseTag(os, 2, "check");
328 }
329 }
330 writeCloseTag(os, 0, "checks");
331 createDoneFile(filename);
332 }
333 catch (IOException ie) {
334 LOG.error("extractChecks() Problem reading file: " + filename, ie);
335 throw new IllegalArgumentException("Error writing to output file: " + ie.getMessage());
336 }
337 finally {
338
339 if (os != null) {
340 try {
341 os.close();
342 }
343 catch (IOException ie) {
344
345 }
346 }
347 }
348 }
349
350 protected void writeExtractAchFile(PaymentStatus extractedStatus, String filename, Date processDate, SimpleDateFormat sdf) {
351 BufferedWriter os = null;
352 try {
353 os = new BufferedWriter(new FileWriter(filename));
354 os.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
355 writeOpenTag(os, 0, "achPayments");
356
357
358 Map<String, Integer> unitCounts = new HashMap<String, Integer>();
359 Map<String, KualiDecimal> unitTotals = new HashMap<String, KualiDecimal>();
360
361 Iterator iter = paymentGroupService.getByDisbursementTypeStatusCode(PdpConstants.DisbursementTypeCodes.ACH, PdpConstants.PaymentStatusCodes.PENDING_ACH);
362 while (iter.hasNext()) {
363 PaymentGroup paymentGroup = (PaymentGroup) iter.next();
364 if (!testMode) {
365 paymentGroup.setDisbursementDate(new java.sql.Date(processDate.getTime()));
366 paymentGroup.setPaymentStatus(extractedStatus);
367 businessObjectService.save(paymentGroup);
368 }
369
370 writeOpenTagAttribute(os, 2, "ach", "disbursementNbr", paymentGroup.getDisbursementNbr().toString());
371 PaymentProcess paymentProcess = paymentGroup.getProcess();
372 writeTag(os, 4, "processCampus", paymentProcess.getCampusCode());
373 writeTag(os, 4, "processId", paymentProcess.getId().toString());
374
375 writeBank(os, 4, paymentGroup.getBank());
376
377 writeTag(os, 4, "disbursementDate", sdf.format(processDate));
378 writeTag(os, 4, "netAmount", paymentGroup.getNetPaymentAmount().toString());
379
380 writePayeeAch(os, 4, paymentGroup);
381 writeTag(os, 4, "paymentDate", sdf.format(paymentGroup.getPaymentDate()));
382
383
384 CustomerProfile cp = paymentGroup.getBatch().getCustomerProfile();
385 writeCustomerProfile(os, 4, cp);
386
387
388 writeOpenTag(os, 4, "payments");
389 List pdList = paymentGroup.getPaymentDetails();
390 for (Iterator iterator = pdList.iterator(); iterator.hasNext();) {
391 PaymentDetail paymentDetail = (PaymentDetail) iterator.next();
392 writeOpenTag(os, 6, "payment");
393
394
395 writeTag(os, 6, "purchaseOrderNbr", paymentDetail.getPurchaseOrderNbr());
396 writeTag(os, 6, "invoiceNbr", paymentDetail.getInvoiceNbr());
397 writeTag(os, 6, "requisitionNbr", paymentDetail.getRequisitionNbr());
398 writeTag(os, 6, "custPaymentDocNbr", paymentDetail.getCustPaymentDocNbr());
399 writeTag(os, 6, "customerUnivNbr", paymentDetail.getCustomerInstitutionNumber());
400 writeTag(os, 6, "invoiceDate", sdf.format(paymentDetail.getInvoiceDate()));
401
402 writeTag(os, 6, "origInvoiceAmount", paymentDetail.getOrigInvoiceAmount().toString());
403 writeTag(os, 6, "netPaymentAmount", paymentDetail.getNetPaymentAmount().toString());
404 writeTag(os, 6, "invTotDiscountAmount", paymentDetail.getInvTotDiscountAmount().toString());
405 writeTag(os, 6, "invTotShipAmount", paymentDetail.getInvTotShipAmount().toString());
406 writeTag(os, 6, "invTotOtherDebitAmount", paymentDetail.getInvTotOtherDebitAmount().toString());
407 writeTag(os, 6, "invTotOtherCreditAmount", paymentDetail.getInvTotOtherCreditAmount().toString());
408
409 writeOpenTag(os, 6, "notes");
410 for (Iterator i = paymentDetail.getNotes().iterator(); i.hasNext();) {
411 PaymentNoteText note = (PaymentNoteText) i.next();
412 writeTag(os, 8, "note", escapeString(note.getCustomerNoteText()));
413 }
414 writeCloseTag(os, 6, "notes");
415
416 writeCloseTag(os, 4, "payment");
417
418 String unit = paymentGroup.getBatch().getCustomerProfile().getChartCode() + "-" + paymentGroup.getBatch().getCustomerProfile().getUnitCode() + "-" + paymentGroup.getBatch().getCustomerProfile().getSubUnitCode();
419
420 Integer count = 1;
421 if (unitCounts.containsKey(unit)) {
422 count = 1 + unitCounts.get(unit);
423 }
424 unitCounts.put(unit, count);
425
426 KualiDecimal unitTotal = paymentDetail.getNetPaymentAmount();
427 if (unitTotals.containsKey(unit)) {
428 unitTotal = paymentDetail.getNetPaymentAmount().add(unitTotals.get(unit));
429 }
430 unitTotals.put(unit, unitTotal);
431 }
432
433 writeCloseTag(os, 4, "payments");
434 writeCloseTag(os, 2, "ach");
435 }
436 writeCloseTag(os, 0, "achPayments");
437
438
439 paymentFileEmailService.sendAchSummaryEmail(unitCounts, unitTotals, dateTimeService.getCurrentDate());
440 }
441 catch (IOException ie) {
442 LOG.error("extractAchPayments() Problem reading file: " + filename, ie);
443 throw new IllegalArgumentException("Error writing to output file: " + ie.getMessage());
444 }
445 finally {
446
447 if (os != null) {
448 try {
449 os.close();
450 }
451 catch (IOException ie) {
452
453 }
454 }
455 }
456 }
457
458 protected static String SPACES = " ";
459
460 protected void writeTag(BufferedWriter os, int indent, String tag, String data) throws IOException {
461 if (data != null) {
462 os.write(SPACES.substring(0, indent));
463 os.write("<" + tag + ">" + escapeString(data) + "</" + tag + ">\n");
464 }
465 }
466
467 protected void writeOpenTag(BufferedWriter os, int indent, String tag) throws IOException {
468 os.write(SPACES.substring(0, indent));
469 os.write("<" + tag + ">\n");
470 }
471
472 protected void writeOpenTagAttribute(BufferedWriter os, int indent, String tag, String attr, String attrVal) throws IOException {
473 os.write(SPACES.substring(0, indent));
474 os.write("<" + tag + " " + attr + "=\"" + escapeString(attrVal) + "\">\n");
475 }
476
477 protected void writeOpenTagAttribute(BufferedWriter os, int indent, String tag, String attr1, String attr1Val, String attr2, String attr2Val) throws IOException {
478 os.write(SPACES.substring(0, indent));
479 os.write("<" + tag + " " + attr1 + "=\"" + escapeString(attr1Val) + "\" " + attr2 + "=\"" + escapeString(attr2Val) + "\">\n");
480 }
481
482 protected void writeCloseTag(BufferedWriter os, int indent, String tag) throws IOException {
483 os.write(SPACES.substring(0, indent));
484 os.write("</" + tag + ">\n");
485 }
486
487 protected void writeBank(BufferedWriter os, int indent, Bank b) throws IOException {
488 if (b != null) {
489 writeOpenTagAttribute(os, indent, "bank", "code", b.getBankCode());
490 writeTag(os, indent + 2, "accountNumber", b.getBankAccountNumber());
491 writeTag(os, indent + 2, "routingNumber", b.getBankRoutingNumber());
492 writeCloseTag(os, indent, "bank");
493 }
494 }
495
496 protected void writeCustomerProfile(BufferedWriter os, int indent, CustomerProfile cp) throws IOException {
497 writeOpenTag(os, indent, "customerProfile");
498 writeTag(os, indent + 2, "chartCode", cp.getChartCode());
499 writeTag(os, indent + 2, "orgCode", cp.getUnitCode());
500 writeTag(os, indent + 2, "subUnitCode", cp.getSubUnitCode());
501 writeOpenTag(os, indent + 2, "checkHeaderNoteLines");
502 writeTag(os, indent + 4, "note", cp.getCheckHeaderNoteTextLine1());
503 writeTag(os, indent + 4, "note", cp.getCheckHeaderNoteTextLine2());
504 writeTag(os, indent + 4, "note", cp.getCheckHeaderNoteTextLine3());
505 writeTag(os, indent + 4, "note", cp.getCheckHeaderNoteTextLine4());
506 writeCloseTag(os, indent + 2, "checkHeaderNoteLines");
507 writeOpenTag(os, indent + 2, "additionalCheckNoteLines");
508 writeTag(os, indent + 4, "note", cp.getAdditionalCheckNoteTextLine1());
509 writeTag(os, indent + 4, "note", cp.getAdditionalCheckNoteTextLine2());
510 writeTag(os, indent + 4, "note", cp.getAdditionalCheckNoteTextLine3());
511 writeTag(os, indent + 4, "note", cp.getAdditionalCheckNoteTextLine4());
512 writeCloseTag(os, indent + 2, "additionalCheckNoteLines");
513 writeCloseTag(os, indent, "customerProfile");
514 }
515
516 protected void writePayeeAch(BufferedWriter os, int indent, PaymentGroup pg) throws IOException {
517 writePayeeInformation(os, indent, pg, true);
518 }
519
520 protected void writePayee(BufferedWriter os, int indent, PaymentGroup pg) throws IOException {
521 writePayeeInformation(os, indent, pg, false);
522 }
523
524 protected void writePayeeInformation(BufferedWriter os, int indent, PaymentGroup pg, boolean includeAch) throws IOException {
525 os.write(SPACES.substring(0, indent));
526 os.write("<payee id=\"" + pg.getPayeeId() + "\" type=\"" + pg.getPayeeIdTypeCd() + "\">\n");
527 writeTag(os, indent + 2, "payeeName", pg.getPayeeName());
528 writeTag(os, indent + 2, "line1Address", pg.getLine1Address());
529 writeTag(os, indent + 2, "line2Address", pg.getLine2Address());
530 writeTag(os, indent + 2, "line3Address", pg.getLine3Address());
531 writeTag(os, indent + 2, "line4Address", pg.getLine4Address());
532 writeTag(os, indent + 2, "city", pg.getCity());
533 writeTag(os, indent + 2, "state", pg.getState());
534 writeTag(os, indent + 2, "zipCd", pg.getZipCd());
535
536
537 String countryName = "";
538 if ( StringUtils.isNotBlank(pg.getCountry()) ) {
539 Country country = countryService.getCountry(pg.getCountry());
540 if (country != null) {
541 countryName = country.getName();
542 }
543 if ( StringUtils.isBlank(countryName) ) {
544 countryName = pg.getCountry();
545 }
546 }
547 writeTag(os, indent + 2, "country", countryName);
548
549 if (includeAch) {
550 writeTag(os, indent + 2, "achBankRoutingNbr", pg.getAchBankRoutingNbr());
551 writeTag(os, indent + 2, "achBankAccountNbr", pg.getAchAccountNumber().getAchBankAccountNbr());
552 writeTag(os, indent + 2, "achAccountType", pg.getAchAccountType());
553 }
554 writeCloseTag(os, indent, "payee");
555 }
556
557
558
559
560 protected void createDoneFile(String filename) {
561 String doneFileName = StringUtils.substringBeforeLast(filename,".") + ".done";
562 File doneFile = new File(doneFileName);
563
564 if (!doneFile.exists()) {
565 boolean doneFileCreated = false;
566 try {
567 doneFileCreated = doneFile.createNewFile();
568 }
569 catch (IOException e) {
570 LOG.error("unable to create done file " + doneFileName, e);
571 throw new RuntimeException("Errors encountered while saving the file: Unable to create .done file " + doneFileName, e);
572 }
573
574 if (!doneFileCreated) {
575 LOG.error("unable to create done file " + doneFileName);
576 throw new RuntimeException("Errors encountered while saving the file: Unable to create .done file " + doneFileName);
577 }
578 }
579 }
580
581
582 protected String escapeString(String input) {
583 String output = input.replaceAll("\\&", "&");
584 output = output.replaceAll("\"", """);
585 output = output.replaceAll("\\'", "'");
586 output = output.replaceAll("\\<", "<");
587 output = output.replaceAll("\\>", ">");
588 return output;
589 }
590
591
592
593
594
595
596 public void setDirectoryName(String directoryName) {
597 this.directoryName = directoryName;
598 }
599
600
601
602
603
604
605
606 public void setDateTimeService(DateTimeService dateTimeService) {
607 this.dateTimeService = dateTimeService;
608 }
609
610
611
612
613
614
615 public void setParameterService(ParameterService parameterService) {
616 this.parameterService = parameterService;
617 }
618
619
620
621
622
623
624 public void setPaymentGroupService(PaymentGroupService paymentGroupService) {
625 this.paymentGroupService = paymentGroupService;
626 }
627
628
629
630
631
632
633 public void setPaymentDetailService(PaymentDetailService paymentDetailService) {
634 this.paymentDetailService = paymentDetailService;
635 }
636
637
638
639
640
641
642 public void setPaymentGroupHistoryDao(PaymentGroupHistoryDao paymentGroupHistoryDao) {
643 this.paymentGroupHistoryDao = paymentGroupHistoryDao;
644 }
645
646
647
648
649
650
651 public void setProcessDao(ProcessDao processDao) {
652 this.processDao = processDao;
653 }
654
655
656
657
658
659
660 public void setPaymentFileEmailService(PdpEmailService paymentFileEmailService) {
661 this.paymentFileEmailService = paymentFileEmailService;
662 }
663
664
665
666
667
668
669 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
670 this.businessObjectService = businessObjectService;
671 }
672
673 public void setConfigurationService(ConfigurationService kualiConfigurationService) {
674 this.kualiConfigurationService = kualiConfigurationService;
675 }
676
677
678
679
680
681
682 protected CountryService getCountryService() {
683 return countryService;
684 }
685
686
687
688
689
690
691 public void setCountryService(CountryService countryService) {
692 this.countryService = countryService;
693 }
694
695
696
697
698 @Override
699 public List<String> getRequiredDirectoryNames() {
700 return new ArrayList<String>() {{add(directoryName); }};
701 }
702
703 }