Source Code Cross Referenced for PaymentDetailDaoOjb.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » pdp » dao » ojb » 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.dao.ojb 
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.dao.ojb;
017:
018:        import java.math.BigDecimal;
019:        import java.sql.Timestamp;
020:        import java.util.ArrayList;
021:        import java.util.Calendar;
022:        import java.util.Collection;
023:        import java.util.Collections;
024:        import java.util.Date;
025:        import java.util.HashMap;
026:        import java.util.Iterator;
027:        import java.util.List;
028:        import java.util.Map;
029:
030:        import org.apache.commons.lang.builder.EqualsBuilder;
031:        import org.apache.commons.lang.builder.HashCodeBuilder;
032:        import org.apache.ojb.broker.query.Criteria;
033:        import org.apache.ojb.broker.query.QueryByCriteria;
034:        import org.apache.ojb.broker.query.QueryFactory;
035:        import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
036:        import org.kuali.core.exceptions.UserNotFoundException;
037:        import org.kuali.core.service.DateTimeService;
038:        import org.kuali.core.service.UniversalUserService;
039:        import org.kuali.kfs.service.ParameterService;
040:        import org.kuali.kfs.service.impl.ParameterConstants;
041:        import org.kuali.module.pdp.PdpConstants;
042:        import org.kuali.module.pdp.bo.Batch;
043:        import org.kuali.module.pdp.bo.DailyReport;
044:        import org.kuali.module.pdp.bo.DisbursementNumberRange;
045:        import org.kuali.module.pdp.bo.PaymentDetail;
046:        import org.kuali.module.pdp.bo.PaymentGroupHistory;
047:        import org.kuali.module.pdp.bo.PaymentProcess;
048:        import org.kuali.module.pdp.bo.UserRequired;
049:        import org.kuali.module.pdp.dao.PaymentDetailDao;
050:        import org.kuali.module.pdp.service.ReferenceService;
051:        import org.kuali.module.purap.PurapParameterConstants;
052:
053:        public class PaymentDetailDaoOjb extends PlatformAwareDaoBaseOjb
054:                implements  PaymentDetailDao {
055:            private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
056:                    .getLogger(PaymentDetailDaoOjb.class);
057:
058:            private UniversalUserService userService;
059:            private ReferenceService referenceService;
060:            private DateTimeService dateTimeService;
061:            private ParameterService parameterService;
062:
063:            public PaymentDetailDaoOjb() {
064:                super ();
065:            }
066:
067:            /**
068:             * @see org.kuali.module.pdp.dao.PaymentDetailDao#getAchPaymentsWithUnsentEmail()
069:             */
070:            public Iterator getAchPaymentsWithUnsentEmail() {
071:                LOG.debug("getAchPaymentsWithUnsentEmail() started");
072:
073:                Criteria crit = new Criteria();
074:                crit.addEqualTo("paymentGroup.paymentStatusCode",
075:                        PdpConstants.PaymentStatusCodes.EXTRACTED);
076:                crit.addEqualTo("paymentGroup.disbursementTypeCode",
077:                        PdpConstants.DisbursementTypeCodes.ACH);
078:                crit.addIsNull("paymentGroup.adviceEmailSentDate");
079:
080:                return getPersistenceBrokerTemplate().getIteratorByQuery(
081:                        new QueryByCriteria(PaymentDetail.class, crit));
082:            }
083:
084:            /**
085:             * @see org.kuali.module.pdp.dao.PaymentDetailDao#getByDisbursementNumber(java.lang.Integer)
086:             */
087:            public Iterator getByDisbursementNumber(Integer disbursementNumber) {
088:                LOG.debug("getByDisbursementNumber() started");
089:
090:                Criteria crit = new Criteria();
091:                crit.addEqualTo("paymentGroup.disbursementNbr",
092:                        disbursementNumber);
093:
094:                QueryByCriteria q = QueryFactory.newQuery(PaymentDetail.class,
095:                        crit);
096:
097:                q.addOrderByAscending("financialDocumentTypeCode");
098:                q.addOrderByAscending("custPaymentDocNbr");
099:
100:                return getPersistenceBrokerTemplate().getIteratorByQuery(q);
101:            }
102:
103:            /**
104:             * @see org.kuali.module.pdp.dao.PaymentDetailDao#getDailyReportData()
105:             */
106:            public List<DailyReport> getDailyReportData() {
107:                LOG.debug("getDailyReportData() started");
108:
109:                Timestamp now = dateTimeService.getCurrentTimestamp();
110:                java.sql.Date sqlDate = new java.sql.Date(now.getTime());
111:                Calendar c = Calendar.getInstance();
112:                c.setTime(sqlDate);
113:                c.set(Calendar.HOUR, 11);
114:                c.set(Calendar.MINUTE, 59);
115:                c.set(Calendar.SECOND, 59);
116:                c.set(Calendar.MILLISECOND, 59);
117:                c.set(Calendar.AM_PM, Calendar.PM);
118:                Timestamp paydateTs = new Timestamp(c.getTime().getTime());
119:                LOG.debug("getDailyReportData() " + paydateTs);
120:
121:                Criteria criteria = new Criteria();
122:                criteria.addEqualTo("paymentGroup.paymentStatusCode",
123:                        PdpConstants.PaymentStatusCodes.OPEN);
124:
125:                // (Payment date <= usePaydate OR immediate = TRUE)
126:                Criteria criteria1 = new Criteria();
127:                criteria1.addEqualTo("paymentGroup.processImmediate",
128:                        Boolean.TRUE);
129:
130:                Criteria criteria2 = new Criteria();
131:                criteria2.addLessOrEqualThan("paymentGroup.paymentDate",
132:                        paydateTs);
133:                criteria1.addOrCriteria(criteria2);
134:
135:                criteria.addAndCriteria(criteria1);
136:
137:                QueryByCriteria q = QueryFactory.newQuery(PaymentDetail.class,
138:                        criteria);
139:
140:                q.addOrderByDescending("paymentGroup.processImmediate");
141:                q.addOrderByDescending("paymentGroup.pymtSpecialHandling");
142:                q.addOrderByDescending("paymentGroup.pymtAttachment");
143:                q
144:                        .addOrderByAscending("paymentGroup.batch.customerProfile.chartCode");
145:                q
146:                        .addOrderByAscending("paymentGroup.batch.customerProfile.orgCode");
147:                q
148:                        .addOrderByAscending("paymentGroup.batch.customerProfile.subUnitCode");
149:                q.addOrderByAscending("paymentGroup.id");
150:
151:                Map<Key, Numbers> summary = new HashMap<Key, Numbers>();
152:                Integer lastGroupId = null;
153:                Iterator i = getPersistenceBrokerTemplate().getIteratorByQuery(
154:                        q);
155:                while (i.hasNext()) {
156:                    PaymentDetail d = (PaymentDetail) i.next();
157:                    Key rsk = new Key(d);
158:                    Numbers n = summary.get(rsk);
159:                    if (n == null) {
160:                        n = new Numbers();
161:                        n.amount = d.getCalculatedPaymentAmount();
162:                        n.payments = 1;
163:                        n.payees = 1;
164:                        summary.put(rsk, n);
165:                        lastGroupId = d.getPaymentGroup().getId();
166:                    } else {
167:                        n.payments++;
168:                        n.amount = n.amount.add(d.getCalculatedPaymentAmount());
169:                        if (lastGroupId.intValue() != d.getPaymentGroup()
170:                                .getId().intValue()) {
171:                            n.payees++;
172:                            lastGroupId = d.getPaymentGroup().getId();
173:                        }
174:                    }
175:                }
176:                // Now take the data and put it in our result list
177:                List<DailyReport> data = new ArrayList<DailyReport>();
178:                for (Iterator iter = summary.keySet().iterator(); iter
179:                        .hasNext();) {
180:                    Key e = (Key) iter.next();
181:                    Numbers n = summary.get(e);
182:                    DailyReport r = new DailyReport(e.pymtAttachment,
183:                            e.pymtSpecialHandling, e.processImmediate,
184:                            e.customerShortName, n.amount, n.payments, n.payees);
185:                    data.add(r);
186:                }
187:                Collections.sort(data);
188:                return data;
189:            }
190:
191:            class Key {
192:                public boolean pymtAttachment;
193:                public boolean pymtSpecialHandling;
194:                public boolean processImmediate;
195:                public String customerShortName;
196:
197:                public Key(PaymentDetail d) {
198:                    this (
199:                            d.getPaymentGroup().getPymtAttachment()
200:                                    .booleanValue(), d.getPaymentGroup()
201:                                    .getPymtSpecialHandling().booleanValue(), d
202:                                    .getPaymentGroup().getProcessImmediate()
203:                                    .booleanValue(), d.getPaymentGroup()
204:                                    .getBatch().getCustomerProfile()
205:                                    .getCustomerShortName());
206:                }
207:
208:                public Key(boolean att, boolean spec, boolean immed, String c) {
209:                    pymtAttachment = att;
210:                    pymtSpecialHandling = spec;
211:                    processImmediate = immed;
212:                    customerShortName = c;
213:                }
214:
215:                private String getGroupOrder() {
216:                    if (processImmediate) {
217:                        return "B";
218:                    } else if (pymtSpecialHandling) {
219:                        return "C";
220:                    } else if (pymtAttachment) {
221:                        return "D";
222:                    } else {
223:                        return "E";
224:                    }
225:                }
226:
227:                @Override
228:                public int hashCode() {
229:                    return new HashCodeBuilder(3, 5).append(getGroupOrder())
230:                            .append(customerShortName).toHashCode();
231:                }
232:
233:                @Override
234:                public boolean equals(Object obj) {
235:                    if (!(obj instanceof  Key)) {
236:                        return false;
237:                    }
238:                    Key this obj = (Key) obj;
239:                    return new EqualsBuilder().append(getGroupOrder(),
240:                            this obj.getGroupOrder()).append(customerShortName,
241:                            this obj.customerShortName).isEquals();
242:                }
243:
244:                @Override
245:                public String toString() {
246:                    return pymtAttachment + " " + pymtSpecialHandling + " "
247:                            + processImmediate + " " + customerShortName;
248:                }
249:            }
250:
251:            class Numbers {
252:                public BigDecimal amount = new BigDecimal("0");
253:                public int payments = 0;
254:                public int payees = 0;
255:            }
256:
257:            /**
258:             * @see org.kuali.module.pdp.dao.PaymentDetailDao#get(java.lang.Integer)
259:             */
260:            public PaymentDetail get(Integer id) {
261:                LOG.debug("get(id) started");
262:                List data = new ArrayList();
263:
264:                Criteria criteria = new Criteria();
265:                criteria.addEqualTo("id", id);
266:
267:                PaymentDetail cp = (PaymentDetail) getPersistenceBrokerTemplate()
268:                        .getObjectByQuery(
269:                                new QueryByCriteria(PaymentDetail.class,
270:                                        criteria));
271:
272:                if (cp.getPaymentGroup().getBatch() != null) {
273:                    updateBatchUser(cp.getPaymentGroup().getBatch());
274:                }
275:                if (cp.getPaymentGroup().getProcess() != null) {
276:                    updateProcessUser(cp.getPaymentGroup().getProcess());
277:                }
278:                if (cp.getPaymentGroup().getPaymentGroupHistory() != null) {
279:                    updateChangeUser(cp.getPaymentGroup()
280:                            .getPaymentGroupHistory());
281:                }
282:                return cp;
283:            }
284:
285:            /**
286:             * @see org.kuali.module.pdp.dao.PaymentDetailDao#save(org.kuali.module.pdp.bo.PaymentDetail)
287:             */
288:            public void save(PaymentDetail pd) {
289:                LOG.debug("save(paymentDetail) started... ID: " + pd.getId());
290:
291:                getPersistenceBrokerTemplate().store(pd);
292:            }
293:
294:            /**
295:             * @see org.kuali.module.pdp.dao.PaymentDetailDao#getDetailForEpic(java.lang.String, java.lang.String)
296:             */
297:            public PaymentDetail getDetailForEpic(String custPaymentDocNbr,
298:                    String fdocTypeCode) {
299:                LOG
300:                        .debug("getDetailForEpic(custPaymentDocNbr, fdocTypeCode) started");
301:                List data = new ArrayList();
302:
303:                Criteria criteria = new Criteria();
304:                criteria.addEqualTo("custPaymentDocNbr", custPaymentDocNbr);
305:                criteria.addEqualTo("financialDocumentTypeCode", fdocTypeCode);
306:
307:                String orgCode = parameterService.getParameterValue(
308:                        ParameterConstants.PURCHASING_BATCH.class,
309:                        PurapParameterConstants.PURAP_PDP_EPIC_ORG_CODE);
310:                String subUnitCode = parameterService.getParameterValue(
311:                        ParameterConstants.PURCHASING_BATCH.class,
312:                        PurapParameterConstants.PURAP_PDP_EPIC_SBUNT_CODE);
313:
314:                criteria.addEqualTo(
315:                        "paymentGroup.batch.customerProfile.orgCode", orgCode);
316:                criteria.addEqualTo(
317:                        "paymentGroup.batch.customerProfile.subUnitCode",
318:                        subUnitCode);
319:
320:                List paymentDetails = (List) getPersistenceBrokerTemplate()
321:                        .getCollectionByQuery(
322:                                new QueryByCriteria(PaymentDetail.class,
323:                                        criteria));
324:                PaymentDetail cp = null;
325:                for (Iterator iter = paymentDetails.iterator(); iter.hasNext();) {
326:                    PaymentDetail pd = (PaymentDetail) iter.next();
327:                    if (cp == null) {
328:                        cp = pd;
329:                    } else {
330:                        if ((pd.getPaymentGroup().getBatch()
331:                                .getCustomerFileCreateTimestamp().compareTo(cp
332:                                .getPaymentGroup().getBatch()
333:                                .getCustomerFileCreateTimestamp())) > 0) {
334:                            cp = pd;
335:                        }
336:                    }
337:                }
338:
339:                if (cp != null) {
340:                    if (cp.getPaymentGroup().getBatch() != null) {
341:                        updateBatchUser(cp.getPaymentGroup().getBatch());
342:                    }
343:                    if (cp.getPaymentGroup().getProcess() != null) {
344:                        updateProcessUser(cp.getPaymentGroup().getProcess());
345:                    }
346:                    if (cp.getPaymentGroup().getPaymentGroupHistory() != null) {
347:                        updateChangeUser(cp.getPaymentGroup()
348:                                .getPaymentGroupHistory());
349:                    }
350:                }
351:                return cp;
352:            }
353:
354:            /**
355:             * @see org.kuali.module.pdp.dao.PaymentDetailDao#getDisbursementNumberRanges(java.lang.String)
356:             */
357:            public List getDisbursementNumberRanges(String campus) {
358:                LOG.debug("getDisbursementNumberRanges() started");
359:
360:                Date now = new Date();
361:                Timestamp nowTs = new Timestamp(now.getTime());
362:
363:                Criteria criteria = new Criteria();
364:                criteria.addGreaterOrEqualThan("disbNbrExpirationDt", nowTs);
365:                criteria.addLessOrEqualThan("disbNbrEffectiveDt", nowTs);
366:                criteria.addEqualTo("physCampusProcCode", campus);
367:
368:                QueryByCriteria qbc = new QueryByCriteria(
369:                        DisbursementNumberRange.class, criteria);
370:                qbc.addOrderBy("bankId", true);
371:
372:                List l = (List) getPersistenceBrokerTemplate()
373:                        .getCollectionByQuery(qbc);
374:                updateDnr(l);
375:                return l;
376:            }
377:
378:            /**
379:             * @see org.kuali.module.pdp.dao.PaymentDetailDao#saveDisbursementNumberRange(org.kuali.module.pdp.bo.DisbursementNumberRange)
380:             */
381:            public void saveDisbursementNumberRange(
382:                    DisbursementNumberRange range) {
383:                LOG.debug("saveDisbursementNumberRange() started");
384:
385:                getPersistenceBrokerTemplate().store(range);
386:            }
387:
388:            /**
389:             * @see org.kuali.module.pdp.dao.PaymentDetailDao#getUnprocessedCancelledDetails(java.lang.String, java.lang.String)
390:             */
391:            public Iterator getUnprocessedCancelledDetails(String organization,
392:                    List<String> subUnits) {
393:                LOG.debug("getUnprocessedCancelledDetails() started");
394:
395:                Collection codes = new ArrayList();
396:                codes.add(PdpConstants.PaymentStatusCodes.CANCEL_DISBURSEMENT);
397:                codes.add(PdpConstants.PaymentStatusCodes.CANCEL_PAYMENT);
398:
399:                Criteria criteria = new Criteria();
400:                criteria.addIn(
401:                        "paymentGroup.batch.customerProfile.subUnitCode",
402:                        subUnits);
403:                criteria.addEqualTo(
404:                        "paymentGroup.batch.customerProfile.orgCode",
405:                        organization);
406:                criteria.addIn("paymentGroup.paymentStatusCode", codes);
407:                criteria
408:                        .addIsNull("paymentGroup.epicPaymentCancelledExtractedDate");
409:
410:                return getPersistenceBrokerTemplate().getIteratorByQuery(
411:                        new QueryByCriteria(PaymentDetail.class, criteria));
412:            }
413:
414:            /**
415:             * @see org.kuali.module.pdp.dao.PaymentDetailDao#getUnprocessedPaidDetails(java.lang.String, java.lang.String)
416:             */
417:            public Iterator getUnprocessedPaidDetails(String organization,
418:                    List<String> subUnits) {
419:                LOG.debug("getUnprocessedPaidDetails() started");
420:
421:                Criteria criteria = new Criteria();
422:                criteria.addIn(
423:                        "paymentGroup.batch.customerProfile.subUnitCode",
424:                        subUnits);
425:                criteria.addEqualTo(
426:                        "paymentGroup.batch.customerProfile.orgCode",
427:                        organization);
428:                criteria.addEqualTo("paymentGroup.paymentStatusCode",
429:                        PdpConstants.PaymentStatusCodes.EXTRACTED);
430:                criteria.addIsNull("paymentGroup.epicPaymentPaidExtractedDate");
431:
432:                return getPersistenceBrokerTemplate().getIteratorByQuery(
433:                        new QueryByCriteria(PaymentDetail.class, criteria));
434:            }
435:
436:            private void updateChangeUser(List l) {
437:                for (Iterator iter = l.iterator(); iter.hasNext();) {
438:                    updateChangeUser((PaymentGroupHistory) iter.next());
439:                }
440:            }
441:
442:            private void updateChangeUser(PaymentGroupHistory b) {
443:                UserRequired ur = (UserRequired) b;
444:                try {
445:                    ur.updateUser(userService);
446:                } catch (UserNotFoundException e) {
447:                    b.setChangeUser(null);
448:                }
449:            }
450:
451:            private void updateBatchUser(Batch b) {
452:                UserRequired ur = (UserRequired) b;
453:                try {
454:                    ur.updateUser(userService);
455:                } catch (UserNotFoundException e) {
456:                    b.setSubmiterUser(null);
457:                }
458:            }
459:
460:            private void updateProcessUser(PaymentProcess b) {
461:                UserRequired ur = (UserRequired) b;
462:                try {
463:                    ur.updateUser(userService);
464:                } catch (UserNotFoundException e) {
465:                    b.setProcessUser(null);
466:                }
467:            }
468:
469:            private void updateDnr(List l) {
470:                for (Iterator iter = l.iterator(); iter.hasNext();) {
471:                    updateDnr((DisbursementNumberRange) iter.next());
472:                }
473:            }
474:
475:            private void updateDnr(DisbursementNumberRange b) {
476:                UserRequired ur = (UserRequired) b;
477:                try {
478:                    ur.updateUser(userService);
479:                } catch (UserNotFoundException e) {
480:                    b.setLastUpdateUser(null);
481:                }
482:            }
483:
484:            public void setUniversalUserService(UniversalUserService us) {
485:                userService = us;
486:            }
487:
488:            public void setReferenceService(ReferenceService ref) {
489:                referenceService = ref;
490:            }
491:
492:            public void setDateTimeService(DateTimeService dts) {
493:                dateTimeService = dts;
494:            }
495:
496:            public void setParameterService(ParameterService ps) {
497:                parameterService = ps;
498:            }
499:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.