Source Code Cross Referenced for PaymentFileServiceImpl.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » pdp » service » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » org.kuali.module.pdp.service.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 The Kuali Foundation.
003:         * 
004:         * Licensed under the Educational Community License, Version 1.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         * http://www.opensource.org/licenses/ecl1.php
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.kuali.module.pdp.service.impl;
017:
018:        import java.io.File;
019:        import java.io.FileNotFoundException;
020:        import java.io.FileOutputStream;
021:        import java.io.FilenameFilter;
022:        import java.io.IOException;
023:        import java.io.PrintStream;
024:        import java.math.BigDecimal;
025:        import java.util.ArrayList;
026:        import java.util.Iterator;
027:        import java.util.List;
028:
029:        import org.kuali.core.bo.user.UniversalUser;
030:        import org.kuali.core.exceptions.UserNotFoundException;
031:        import org.kuali.core.mail.InvalidAddressException;
032:        import org.kuali.core.mail.MailMessage;
033:        import org.kuali.core.service.MailService;
034:        import org.kuali.core.service.UniversalUserService;
035:        import org.kuali.kfs.context.SpringContext;
036:        import org.kuali.kfs.service.ParameterService;
037:        import org.kuali.kfs.service.impl.ParameterConstants;
038:        import org.kuali.module.pdp.PdpConstants;
039:        import org.kuali.module.pdp.bo.Batch;
040:        import org.kuali.module.pdp.bo.CustomerProfile;
041:        import org.kuali.module.pdp.bo.PdpUser;
042:        import org.kuali.module.pdp.dao.PaymentFileLoadDao;
043:        import org.kuali.module.pdp.exception.PaymentLoadException;
044:        import org.kuali.module.pdp.service.CustomerProfileService;
045:        import org.kuali.module.pdp.service.EnvironmentService;
046:        import org.kuali.module.pdp.service.LoadPaymentStatus;
047:        import org.kuali.module.pdp.service.PaymentFileService;
048:        import org.kuali.module.pdp.utilities.GeneralUtilities;
049:        import org.kuali.module.pdp.xml.PaymentFileParser;
050:        import org.kuali.module.pdp.xml.XmlHeader;
051:        import org.kuali.module.pdp.xml.XmlTrailer;
052:        import org.kuali.module.pdp.xml.impl.DataLoadHandler;
053:        import org.kuali.module.pdp.xml.impl.HardEditHandler;
054:        import org.springframework.transaction.annotation.Transactional;
055:
056:        @Transactional
057:        public class PaymentFileServiceImpl implements  PaymentFileService {
058:            private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
059:                    .getLogger(PaymentFileServiceImpl.class);
060:
061:            private MailService mailService;
062:            private ParameterService parameterService;
063:            private CustomerProfileService customerProfileService;
064:            private EnvironmentService environmentService;
065:            private PaymentFileLoadDao paymentFileLoadDao;
066:            private UniversalUserService universalUserService;
067:            private String incomingDirectoryName;
068:            private String outgoingDirectoryName;
069:
070:            public PaymentFileServiceImpl() {
071:                super ();
072:            }
073:
074:            public void processPaymentFiles() {
075:                LOG.debug("processPaymentFiles() started");
076:
077:                PdpUser pusr = null;
078:                try {
079:                    UniversalUser uu = universalUserService
080:                            .getUniversalUserByAuthenticationUserId("KULUSER");
081:                    pusr = new PdpUser(uu);
082:                } catch (UserNotFoundException u) {
083:                    LOG
084:                            .error(
085:                                    "processPaymentFiles() Unable to find requested user",
086:                                    u);
087:                    throw new IllegalArgumentException("Unable to find user");
088:                }
089:
090:                // Look for *.done in the incoming folder
091:                File dir = new File(incomingDirectoryName);
092:                FilenameFilter filter = new FilenameFilter() {
093:                    public boolean accept(File dir, String name) {
094:                        return name.endsWith(".done");
095:                    }
096:                };
097:                String[] files = dir.list(filter);
098:                for (int i = 0; i < files.length; i++) {
099:                    String doneFilename = files[i];
100:                    LOG.debug("processPaymentFiles() Found done file: "
101:                            + doneFilename);
102:
103:                    String inputDoneFullPath = incomingDirectoryName + "/"
104:                            + doneFilename;
105:                    String inputXmlFullPath = incomingDirectoryName + "/"
106:                            + getFilename(doneFilename) + ".xml";
107:                    String outputDoneFullPath = outgoingDirectoryName + "/"
108:                            + doneFilename;
109:
110:                    LOG.debug("processPaymentFiles() inputDoneFullPath: "
111:                            + inputDoneFullPath);
112:                    LOG.debug("processPaymentFiles() inputXmlFullPath: "
113:                            + inputXmlFullPath);
114:                    LOG.debug("processPaymentFiles() outputDoneFullPath: "
115:                            + outputDoneFullPath);
116:
117:                    File f = new File(inputXmlFullPath);
118:                    if (f.exists()) {
119:                        LOG.info("processPaymentFiles() Processing "
120:                                + inputXmlFullPath);
121:                        try {
122:                            LoadPaymentStatus status = loadPayments(
123:                                    inputXmlFullPath, pusr);
124:
125:                            // Create the output file
126:                            createOutputFile(outputDoneFullPath, "SUCCESS",
127:                                    "Successful Load", status.getDetailCount(),
128:                                    status.getDetailTotal(), status
129:                                            .getWarnings(), doneFilename);
130:
131:                            // Delete the file now that we have processed it
132:                            f.delete();
133:                        } catch (PaymentLoadException ple) {
134:                            String msg = ple.getMessage() == null ? "" : ple
135:                                    .getMessage();
136:                            createOutputFile(outputDoneFullPath, "FAIL",
137:                                    "Load Failed " + msg, 0, null, null,
138:                                    doneFilename);
139:                        }
140:
141:                        // Delete the done file
142:                        File df = new File(inputDoneFullPath);
143:                        df.delete();
144:                    } else {
145:                        LOG
146:                                .error("processPaymentFiles() Done file exists without xml file: "
147:                                        + inputXmlFullPath);
148:                    }
149:                }
150:            }
151:
152:            public boolean createOutputFile(String filename, String code,
153:                    String message, int count, BigDecimal total, List messages,
154:                    String inputFileName) {
155:                FileOutputStream out;
156:                PrintStream p;
157:
158:                try {
159:                    out = new FileOutputStream(filename);
160:                    p = new PrintStream(out);
161:
162:                    p.println("<pdp_load_status>");
163:                    p.println("  <input_file_name>" + inputFileName
164:                            + "</input_file_name>");
165:                    p.println("  <code>" + code + "</code>");
166:                    if ("SUCCESS".equals(code)) {
167:                        p.println("  <count>" + count + "</count>");
168:                        p.println("  <total>" + total + "</total>");
169:                    } else {
170:                        p.println("  <count>0</count>");
171:                        p.println("  <total>0</total>");
172:                    }
173:                    p.println("  <description>" + message + "</description>");
174:                    if (messages != null) {
175:                        p.println("  <messages>");
176:                        for (Iterator iter = messages.iterator(); iter
177:                                .hasNext();) {
178:                            String element = (String) iter.next();
179:                            p.println("    <message>" + element + "</message>");
180:                        }
181:                        p.println("  </messages>");
182:                    }
183:                    p.println("</pdp_load_status>");
184:
185:                    p.close();
186:                    out.close();
187:                    return true;
188:                } catch (FileNotFoundException e) {
189:                    LOG
190:                            .error(
191:                                    "createOutputFile() Cannot create output file",
192:                                    e);
193:                    return false;
194:                } catch (IOException e) {
195:                    LOG.error("createOutputFile() Cannot write to output file",
196:                            e);
197:                    return false;
198:                }
199:            }
200:
201:            public boolean createDoneFile(String filename) {
202:                FileOutputStream out;
203:                PrintStream p;
204:
205:                try {
206:                    out = new FileOutputStream(filename);
207:                    p = new PrintStream(out);
208:                    p.println("This file intentionally left blank");
209:                    p.close();
210:                    out.close();
211:                    return true;
212:                } catch (FileNotFoundException e) {
213:                    LOG.error("createDoneFile() Cannot create done file", e);
214:                    return false;
215:                } catch (IOException e) {
216:                    LOG.error("createDoneFile() Cannot write to done file", e);
217:                    return false;
218:                }
219:            }
220:
221:            private String getFilename(String doneFile) {
222:                return doneFile.replaceAll("\\.done", "");
223:            }
224:
225:            private int getMaxNoteLines() {
226:                return GeneralUtilities.getParameterInteger(parameterService,
227:                        ParameterConstants.PRE_DISBURSEMENT_ALL.class,
228:                        PdpConstants.ApplicationParameterKeys.MAX_NOTE_LINES);
229:            }
230:
231:            private String getBaseFileName(String filename) {
232:
233:                // Replace any backslashes with forward slashes. This makes it work on
234:                // Windows or Unix
235:                filename = filename.replaceAll("\\\\", "/");
236:
237:                int startingPointer = filename.length() - 1;
238:                while ((startingPointer > 0)
239:                        && (filename.charAt(startingPointer) != '/')) {
240:                    startingPointer--;
241:                }
242:                return filename.substring(startingPointer + 1);
243:            }
244:
245:            public void saveBatch(Batch batch) {
246:                paymentFileLoadDao.createBatch(batch);
247:            }
248:
249:            // This will parse the file for hard edit problems, then copy the file to
250:            // the batch directory. The batch job will actually load the file into the
251:            // database
252:            public LoadPaymentStatus loadPayments(String filename, PdpUser user)
253:                    throws PaymentLoadException {
254:                PaymentFileParser paymentFileParser = SpringContext
255:                        .getBean(PaymentFileParser.class);
256:
257:                HardEditHandler hardEditHandler;
258:
259:                LoadPaymentStatus status = new LoadPaymentStatus();
260:
261:                // Try to do the hard edits
262:                LOG.debug("loadPayments() hard edit check");
263:                hardEditHandler = new HardEditHandler();
264:                hardEditHandler.clear();
265:                hardEditHandler.setMaxNoteLines(getMaxNoteLines());
266:
267:                paymentFileParser.setFileHandler(hardEditHandler);
268:                try {
269:                    LOG.debug("loadPayments() begin hard edit parsing");
270:                    paymentFileParser.parse(filename);
271:                    LOG.debug("loadPayments() done hard edit parsing");
272:                } catch (Exception e) {
273:                    LOG.error("loadPayments() Exception when parsing XML", e);
274:
275:                    List errors = new ArrayList();
276:                    errors.add(e.getMessage());
277:
278:                    // Send error email
279:                    sendErrorEmail(hardEditHandler.getHeader(), hardEditHandler
280:                            .getTrailer(), errors);
281:
282:                    PaymentLoadException ple = new PaymentLoadException();
283:                    ple.setErrors(errors);
284:                    throw ple;
285:                }
286:
287:                List errors = hardEditHandler.getErrorMessages();
288:                if (errors.size() > 0) {
289:                    LOG
290:                            .debug("loadPayments() There were hard errors in the file");
291:
292:                    // Send error email
293:                    sendErrorEmail(hardEditHandler.getHeader(), hardEditHandler
294:                            .getTrailer(), errors);
295:
296:                    PaymentLoadException ple = new PaymentLoadException();
297:                    ple.setErrors(errors);
298:                    throw ple;
299:                }
300:                status.setDetailCount(hardEditHandler.getActualPaymentCount());
301:                status.setDetailTotal(hardEditHandler
302:                        .getCalculatedPaymentTotalAmount());
303:
304:                DataLoadHandler dataLoadHandler;
305:
306:                dataLoadHandler = new DataLoadHandler(hardEditHandler
307:                        .getTrailer());
308:                dataLoadHandler.setUser(user);
309:                dataLoadHandler.setFilename(getBaseFileName(filename));
310:                dataLoadHandler.setMaxNoteLines(getMaxNoteLines());
311:                paymentFileParser.setFileHandler(dataLoadHandler);
312:                try {
313:                    paymentFileParser.parse(filename);
314:                } catch (Exception e) {
315:                    LOG
316:                            .error(
317:                                    "loadPayments() Exception when parsing XML for load",
318:                                    e);
319:
320:                    List lerrors = new ArrayList();
321:                    lerrors.add(e.getMessage());
322:
323:                    // Send error email
324:                    sendErrorEmail(hardEditHandler.getHeader(), hardEditHandler
325:                            .getTrailer(), errors);
326:
327:                    PaymentLoadException ple = new PaymentLoadException();
328:                    ple.setErrors(lerrors);
329:                    throw ple;
330:                }
331:
332:                // Send list of warnings
333:                // sendLoadEmail(dataLoadHandler.getBatch().getId(),hardEditHandler.getHeader(), hardEditHandler.getTrailer(),
334:                // dataLoadHandler.getErrorMessages());
335:                sendLoadEmail(dataLoadHandler, hardEditHandler.getHeader(),
336:                        hardEditHandler.getTrailer());
337:                if (dataLoadHandler.isTaxEmailRequired()) {
338:                    sendTaxEmail(dataLoadHandler, hardEditHandler.getHeader());
339:                }
340:
341:                LOG.debug("loadPayments() parse was successful");
342:                status.setWarnings(dataLoadHandler.getErrorMessages());
343:                status.setHeader(hardEditHandler.getHeader());
344:                status.setBatchId(dataLoadHandler.getBatch().getId());
345:                return status;
346:            }
347:
348:            private void sendErrorEmail(XmlHeader header, XmlTrailer trailer,
349:                    List errors) {
350:                LOG.debug("sendErrorEmail() starting");
351:
352:                // To send email or not send email
353:                boolean noEmail = false;
354:                if (parameterService
355:                        .parameterExists(
356:                                ParameterConstants.PRE_DISBURSEMENT_ALL.class,
357:                                PdpConstants.ApplicationParameterKeys.NO_PAYMENT_FILE_EMAIL)) {
358:                    noEmail = parameterService
359:                            .getIndicatorParameter(
360:                                    ParameterConstants.PRE_DISBURSEMENT_ALL.class,
361:                                    PdpConstants.ApplicationParameterKeys.NO_PAYMENT_FILE_EMAIL);
362:                }
363:                if (noEmail) {
364:                    LOG
365:                            .debug("sendErrorEmail() sending payment file email is disabled");
366:                    return;
367:                }
368:
369:                CustomerProfile customer = null;
370:                MailMessage message = new MailMessage();
371:
372:                if (environmentService.isProduction()) {
373:                    message.setSubject("PDP --- Payment file NOT loaded");
374:                } else {
375:                    String env = environmentService.getEnvironment();
376:                    message
377:                            .setSubject(env
378:                                    + "-PDP --- Payment file NOT loaded");
379:                }
380:                StringBuffer body = new StringBuffer();
381:
382:                String ccAddresses = parameterService.getParameterValue(
383:                        ParameterConstants.PRE_DISBURSEMENT_ALL.class,
384:                        PdpConstants.ApplicationParameterKeys.HARD_EDIT_CC);
385:                String ccAddressList[] = ccAddresses.split(",");
386:
387:                if (header == null) {
388:                    LOG
389:                            .error("sendErrorEmail() Header is null.  Sending email to CC addresses");
390:                    if (ccAddressList.length == 0) {
391:                        LOG
392:                                .error("sendErrorEmail() No HARD_EDIT_CC addresses.  No email sent");
393:                        return;
394:                    }
395:                    for (int i = 0; i < ccAddressList.length; i++) {
396:                        if (ccAddressList[i] != null) {
397:                            message.addToAddress(ccAddressList[i].trim());
398:                        }
399:                    }
400:
401:                    body
402:                            .append("A file was uploaded that was so messed up, we don't even know who sent it:\n\n");
403:                } else {
404:                    // Get customer
405:                    customer = customerProfileService.get(header.getChart(),
406:                            header.getOrg(), header.getSubUnit());
407:                    if (customer == null) {
408:                        LOG
409:                                .error("sendErrorEmail() Invalid Customer.  Sending email to CC addresses");
410:
411:                        if (ccAddressList.length == 0) {
412:                            LOG
413:                                    .error("sendErrorEmail() No HARD_EDIT_CC addresses.  No email sent");
414:                            return;
415:                        }
416:                        for (int i = 0; i < ccAddressList.length; i++) {
417:                            if (ccAddressList[i] != null) {
418:                                message.addToAddress(ccAddressList[i].trim());
419:                            }
420:                        }
421:
422:                        body
423:                                .append("A file was uploaded for an invalid customer:\n\n");
424:                    } else {
425:                        String toAddresses = customer.getProcessingEmailAddr();
426:                        String toAddressList[] = toAddresses.split(",");
427:
428:                        if (toAddressList.length > 0) {
429:                            for (int i = 0; i < toAddressList.length; i++) {
430:                                if (toAddressList[i] != null) {
431:                                    message.addToAddress(toAddressList[i]
432:                                            .trim());
433:                                }
434:                            }
435:                        }
436:                        // message.addToAddress(customer.getProcessingEmailAddr());
437:
438:                        for (int i = 0; i < ccAddressList.length; i++) {
439:                            if (ccAddressList[i] != null) {
440:                                message.addCcAddress(ccAddressList[i].trim());
441:                            }
442:                        }
443:                    }
444:                }
445:
446:                String fromAddressList[] = { mailService.getBatchMailingList() };
447:
448:                if (fromAddressList.length > 0) {
449:                    for (int i = 0; i < fromAddressList.length; i++) {
450:                        if (fromAddressList[i] != null) {
451:                            message.setFromAddress(fromAddressList[i].trim());
452:                        }
453:                    }
454:                }
455:
456:                if (header != null) {
457:                    body
458:                            .append("The following payment file was NOT loaded\n\n");
459:                    body.append("Chart: " + header.getChart() + "\n");
460:                    body.append("Organization: " + header.getOrg() + "\n");
461:                    body.append("Sub Unit: " + header.getSubUnit() + "\n");
462:                    body.append("Creation Date: " + header.getCreationDate()
463:                            + "\n");
464:                }
465:
466:                if (trailer != null) {
467:                    body.append("\nPayment Count: " + trailer.getPaymentCount()
468:                            + "\n");
469:                    body.append("Payment Total Amount: "
470:                            + trailer.getPaymentTotalAmount() + "\n");
471:                }
472:
473:                body.append("\nThe following error messages were generated:\n");
474:                for (Iterator iter = errors.iterator(); iter.hasNext();) {
475:                    String msg = (String) iter.next();
476:                    body.append(msg + "\n\n");
477:                }
478:
479:                message.setMessage(body.toString());
480:                try {
481:                    mailService.sendMessage(message);
482:                } catch (InvalidAddressException e) {
483:                    LOG
484:                            .error(
485:                                    "sendErrorEmail() Invalid email address.  Message not sent",
486:                                    e);
487:                }
488:            }
489:
490:            private void sendLoadEmail(DataLoadHandler dataLoadHandler,
491:                    XmlHeader header, XmlTrailer trailer) {
492:                LOG.debug("sendLoadEmail() starting");
493:
494:                Integer batchId = dataLoadHandler.getBatch().getId();
495:                List errors = dataLoadHandler.getErrorMessages();
496:
497:                // To send email or not send email
498:                boolean noEmail = parameterService
499:                        .getIndicatorParameter(
500:                                ParameterConstants.PRE_DISBURSEMENT_ALL.class,
501:                                PdpConstants.ApplicationParameterKeys.NO_PAYMENT_FILE_EMAIL);
502:                if (noEmail) {
503:                    LOG
504:                            .debug("sendLoadEmail() sending payment file email is disabled");
505:                    return;
506:                }
507:
508:                CustomerProfile customer = null;
509:                MailMessage message = new MailMessage();
510:
511:                if (environmentService.isProduction()) {
512:                    message.setSubject("PDP --- Payment file loaded");
513:                } else {
514:                    String env = environmentService.getEnvironment();
515:                    message.setSubject(env + "-PDP --- Payment file loaded");
516:                }
517:
518:                StringBuffer body = new StringBuffer();
519:
520:                String ccAddresses = parameterService.getParameterValue(
521:                        ParameterConstants.PRE_DISBURSEMENT_ALL.class,
522:                        PdpConstants.ApplicationParameterKeys.SOFT_EDIT_CC);
523:                String ccAddressList[] = ccAddresses.split(",");
524:
525:                // Get customer
526:                customer = customerProfileService.get(header.getChart(), header
527:                        .getOrg(), header.getSubUnit());
528:                String toAddresses = customer.getProcessingEmailAddr();
529:                String toAddressList[] = toAddresses.split(",");
530:
531:                if (toAddressList.length > 0) {
532:                    for (int i = 0; i < toAddressList.length; i++) {
533:                        if (toAddressList[i] != null) {
534:                            message.addToAddress(toAddressList[i].trim());
535:                        }
536:                    }
537:                }
538:                // message.addToAddress(customer.getProcessingEmailAddr());
539:
540:                for (int i = 0; i < ccAddressList.length; i++) {
541:                    if (ccAddressList[i] != null) {
542:                        message.addCcAddress(ccAddressList[i].trim());
543:                    }
544:                }
545:
546:                String fromAddressList[] = { mailService.getBatchMailingList() };
547:
548:                if (fromAddressList.length > 0) {
549:                    for (int i = 0; i < fromAddressList.length; i++) {
550:                        if (fromAddressList[i] != null) {
551:                            message.setFromAddress(fromAddressList[i].trim());
552:                        }
553:                    }
554:                }
555:
556:                body.append("The following payment file was loaded\n\n");
557:                body.append("Batch ID: " + batchId + "\n");
558:                body.append("Chart: " + header.getChart() + "\n");
559:                body.append("Organization: " + header.getOrg() + "\n");
560:                body.append("Sub Unit: " + header.getSubUnit() + "\n");
561:                body
562:                        .append("Creation Date: " + header.getCreationDate()
563:                                + "\n");
564:                body.append("\nPayment Count: " + trailer.getPaymentCount()
565:                        + "\n");
566:                body.append("Payment Total Amount: "
567:                        + trailer.getPaymentTotalAmount() + "\n");
568:
569:                body
570:                        .append("\nThe following warning messages were generated:\n");
571:                for (Iterator iter = errors.iterator(); iter.hasNext();) {
572:                    String msg = (String) iter.next();
573:                    body.append(msg + "\n\n");
574:                }
575:
576:                message.setMessage(body.toString());
577:                try {
578:                    mailService.sendMessage(message);
579:                } catch (InvalidAddressException e) {
580:                    LOG
581:                            .error(
582:                                    "sendErrorEmail() Invalid email address. Message not sent",
583:                                    e);
584:                }
585:                if (dataLoadHandler.getFileThreshold().booleanValue()) {
586:                    sendThresholdEmail("file", dataLoadHandler, customer,
587:                            header, trailer);
588:                }
589:                if (dataLoadHandler.getDetailThreshold().booleanValue()) {
590:                    sendThresholdEmail("detail", dataLoadHandler, customer,
591:                            header, trailer);
592:                }
593:            }
594:
595:            private void sendThresholdEmail(String type,
596:                    DataLoadHandler dataLoadHandler, CustomerProfile customer,
597:                    XmlHeader header, XmlTrailer trailer) {
598:                MailMessage message = new MailMessage();
599:
600:                if (environmentService.isProduction()) {
601:                    message
602:                            .setSubject("PDP --- Payment file loaded with Threshold Warnings");
603:                } else {
604:                    String env = environmentService.getEnvironment();
605:                    message
606:                            .setSubject(env
607:                                    + "-PDP --- Payment file loaded with Threshold Warnings");
608:                }
609:
610:                StringBuffer body = new StringBuffer();
611:
612:                body.append("The following payment file was loaded\n\n");
613:                body.append("Batch ID: " + dataLoadHandler.getBatch().getId()
614:                        + "\n");
615:                body.append("Chart: " + header.getChart() + "\n");
616:                body.append("Organization: " + header.getOrg() + "\n");
617:                body.append("Sub Unit: " + header.getSubUnit() + "\n");
618:                body
619:                        .append("Creation Date: " + header.getCreationDate()
620:                                + "\n");
621:                body.append("\nPayment Count: " + trailer.getPaymentCount()
622:                        + "\n");
623:                body.append("Payment Total Amount: "
624:                        + trailer.getPaymentTotalAmount() + "\n");
625:
626:                // Hard Coded - Can only be 'file' or 'detail'
627:                if ("file".equals(type)) {
628:                    String toAddresses = customer
629:                            .getFileThresholdEmailAddress();
630:                    String toAddressList[] = toAddresses.split(",");
631:
632:                    if (toAddressList.length > 0) {
633:                        for (int i = 0; i < toAddressList.length; i++) {
634:                            if (toAddressList[i] != null) {
635:                                message.addToAddress(toAddressList[i].trim());
636:                            }
637:                        }
638:                    }
639:                    // message.addToAddress(customer.getFileThresholdEmailAddress());
640:                    body.append("\n"
641:                            + dataLoadHandler.getFileThresholdMessage());
642:                } else {
643:                    String toAddresses = customer
644:                            .getPaymentThresholdEmailAddress();
645:                    String toAddressList[] = toAddresses.split(",");
646:
647:                    if (toAddressList.length > 0) {
648:                        for (int i = 0; i < toAddressList.length; i++) {
649:                            if (toAddressList[i] != null) {
650:                                message.addToAddress(toAddressList[i].trim());
651:                            }
652:                        }
653:                    }
654:                    // message.addToAddress(customer.getPaymentThresholdEmailAddress());
655:                    body
656:                            .append("\nThe Detail Threshold Limit ("
657:                                    + customer.getPaymentThresholdAmount()
658:                                    + ") was exceeded with the following payments:\n\n");
659:                    for (Iterator iter = dataLoadHandler
660:                            .getDetailThresholdMessages().iterator(); iter
661:                            .hasNext();) {
662:                        String msg = (String) iter.next();
663:                        body.append(msg + "\n");
664:                    }
665:                }
666:
667:                String fromAddressList[] = { mailService.getBatchMailingList() };
668:
669:                if (fromAddressList.length > 0) {
670:                    for (int i = 0; i < fromAddressList.length; i++) {
671:                        if (fromAddressList[i] != null) {
672:                            message.setFromAddress(fromAddressList[i].trim());
673:                        }
674:                    }
675:                }
676:
677:                message.setMessage(body.toString());
678:                try {
679:                    mailService.sendMessage(message);
680:                } catch (InvalidAddressException e) {
681:                    LOG
682:                            .error(
683:                                    "sendErrorEmail() Invalid email address. Message not sent",
684:                                    e);
685:                }
686:            }
687:
688:            private void sendTaxEmail(DataLoadHandler dataLoadHandler,
689:                    XmlHeader header) {
690:                LOG.debug("sendTaxEmail() starting");
691:
692:                Integer batchId = dataLoadHandler.getBatch().getId();
693:
694:                CustomerProfile customer = null;
695:                MailMessage message = new MailMessage();
696:
697:                if (environmentService.isProduction()) {
698:                    message
699:                            .setSubject("PDP --- Payment file loaded with payment(s) held for Tax");
700:                } else {
701:                    String env = environmentService.getEnvironment();
702:                    message
703:                            .setSubject(env
704:                                    + "-PDP --- Payment file loaded with payment(s) held for Tax");
705:                }
706:
707:                StringBuffer body = new StringBuffer();
708:
709:                String taxEmail = parameterService
710:                        .getParameterValue(
711:                                ParameterConstants.PRE_DISBURSEMENT_ALL.class,
712:                                PdpConstants.ApplicationParameterKeys.TAX_GROUP_EMAIL_ADDRESS);
713:                if (GeneralUtilities.isStringEmpty(taxEmail)) {
714:                    LOG
715:                            .error("No Tax E-mail Application Setting found to send notification e-mail");
716:                    return;
717:                } else {
718:                    message.addToAddress(taxEmail);
719:                }
720:
721:                String fromAddressList[] = { mailService.getBatchMailingList() };
722:
723:                if (fromAddressList.length > 0) {
724:                    for (int i = 0; i < fromAddressList.length; i++) {
725:                        if (fromAddressList[i] != null) {
726:                            message.setFromAddress(fromAddressList[i].trim());
727:                        }
728:                    }
729:                }
730:
731:                body
732:                        .append("The following payment file was loaded with payment(s) held for Tax\n\n");
733:                body.append("Batch ID: " + batchId + "\n");
734:                body.append("Chart: " + header.getChart() + "\n");
735:                body.append("Organization: " + header.getOrg() + "\n");
736:                body.append("Sub Unit: " + header.getSubUnit() + "\n");
737:                body
738:                        .append("Creation Date: " + header.getCreationDate()
739:                                + "\n");
740:
741:                body
742:                        .append("\nPlease go to the PDP system to view the payments.\n");
743:
744:                message.setMessage(body.toString());
745:                try {
746:                    mailService.sendMessage(message);
747:                } catch (InvalidAddressException e) {
748:                    LOG
749:                            .error(
750:                                    "sendErrorEmail() Invalid email address. Message not sent",
751:                                    e);
752:                }
753:            }
754:
755:            /**
756:             * @see org.kuali.module.pdp.service.PaymentFileService#sendLoadEmail(org.kuali.module.pdp.bo.Batch)
757:             */
758:            public void sendLoadEmail(Batch batch) {
759:                LOG.debug("sendLoadEmail() starting");
760:
761:                CustomerProfile customer = batch.getCustomerProfile();
762:
763:                // To send email or not send email
764:                boolean noEmail = parameterService
765:                        .getIndicatorParameter(
766:                                ParameterConstants.PRE_DISBURSEMENT_ALL.class,
767:                                PdpConstants.ApplicationParameterKeys.NO_PAYMENT_FILE_EMAIL);
768:                if (noEmail) {
769:                    LOG
770:                            .debug("sendLoadEmail() sending payment file email is disabled");
771:                    return;
772:                }
773:
774:                MailMessage message = new MailMessage();
775:
776:                if (environmentService.isProduction()) {
777:                    message.setSubject("PDP --- Payment file loaded");
778:                } else {
779:                    String env = environmentService.getEnvironment();
780:                    message.setSubject(env + "-PDP --- Payment file loaded");
781:                }
782:
783:                StringBuffer body = new StringBuffer();
784:
785:                String ccAddresses = parameterService.getParameterValue(
786:                        ParameterConstants.PRE_DISBURSEMENT_ALL.class,
787:                        PdpConstants.ApplicationParameterKeys.SOFT_EDIT_CC);
788:                String ccAddressList[] = ccAddresses.split(",");
789:
790:                // Get customer
791:                String toAddresses = customer.getProcessingEmailAddr();
792:                String toAddressList[] = toAddresses.split(",");
793:
794:                if (toAddressList.length > 0) {
795:                    for (int i = 0; i < toAddressList.length; i++) {
796:                        if (toAddressList[i] != null) {
797:                            message.addToAddress(toAddressList[i].trim());
798:                        }
799:                    }
800:                }
801:
802:                for (int i = 0; i < ccAddressList.length; i++) {
803:                    if (ccAddressList[i] != null) {
804:                        message.addCcAddress(ccAddressList[i].trim());
805:                    }
806:                }
807:
808:                String fromAddressList[] = { mailService.getBatchMailingList() };
809:
810:                if (fromAddressList.length > 0) {
811:                    for (int i = 0; i < fromAddressList.length; i++) {
812:                        if (fromAddressList[i] != null) {
813:                            message.setFromAddress(fromAddressList[i].trim());
814:                        }
815:                    }
816:                }
817:
818:                body.append("The following payment file was loaded\n\n");
819:                body.append("Batch ID: " + batch.getId() + "\n");
820:                body.append("Chart: " + customer.getChartCode() + "\n");
821:                body.append("Organization: " + customer.getOrgCode() + "\n");
822:                body.append("Sub Unit: " + customer.getSubUnitCode() + "\n");
823:                body.append("Creation Date: "
824:                        + batch.getCustomerFileCreateTimestamp() + "\n");
825:                body.append("\nPayment Count: " + batch.getPaymentCount()
826:                        + "\n");
827:                body.append("Payment Total Amount: "
828:                        + batch.getPaymentTotalAmount() + "\n");
829:
830:                message.setMessage(body.toString());
831:                try {
832:                    mailService.sendMessage(message);
833:                } catch (InvalidAddressException e) {
834:                    LOG
835:                            .error(
836:                                    "sendErrorEmail() Invalid email address. Message not sent",
837:                                    e);
838:                }
839:            }
840:
841:            public void setParameterService(ParameterService parameterService) {
842:                this .parameterService = parameterService;
843:            }
844:
845:            public void setPaymentFileLoadDao(PaymentFileLoadDao pfld) {
846:                paymentFileLoadDao = pfld;
847:            }
848:
849:            public void setEnvironmentService(EnvironmentService es) {
850:                environmentService = es;
851:            }
852:
853:            public void setCustomerProfileService(CustomerProfileService cps) {
854:                customerProfileService = cps;
855:            }
856:
857:            public void setMailService(MailService ms) {
858:                mailService = ms;
859:            }
860:
861:            public void setUniversalUserService(UniversalUserService uus) {
862:                universalUserService = uus;
863:            }
864:
865:            public void setIncomingDirectoryName(String idn) {
866:                incomingDirectoryName = idn;
867:            }
868:
869:            public void setOutgoingDirectoryName(String odn) {
870:                outgoingDirectoryName = odn;
871:            }
872:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.