1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.cg.dataaccess.impl;
17
18 import java.sql.Date;
19 import java.util.Iterator;
20
21 import org.apache.ojb.broker.query.Criteria;
22 import org.apache.ojb.broker.query.ReportQueryByCriteria;
23 import org.kuali.ole.module.cg.CGPropertyConstants;
24 import org.kuali.ole.module.cg.dataaccess.CloseDao;
25 import org.kuali.ole.module.cg.document.ProposalAwardCloseDocument;
26 import org.kuali.ole.sys.OLEConstants;
27 import org.kuali.ole.sys.OLEPropertyConstants;
28 import org.kuali.ole.sys.util.TransactionalServiceUtils;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31
32
33
34 public class CloseDaoOjb extends PlatformAwareDaoBaseOjb implements CloseDao {
35
36
37
38
39 public String getMaxApprovedClose(Date today) {
40
41 Criteria criteria = new Criteria();
42 criteria.addEqualTo(CGPropertyConstants.PROPOSAL_AWARD_CLOSE_DOC_USER_INITIATED_CLOSE_DATE, today);
43 criteria.addEqualTo(OLEPropertyConstants.DOCUMENT_HEADER + "." + OLEPropertyConstants.FINANCIAL_DOCUMENT_STATUS_CODE, OLEConstants.DocumentStatusCodes.ENROUTE);
44
45 ReportQueryByCriteria rqbc = new ReportQueryByCriteria(ProposalAwardCloseDocument.class, criteria);
46 rqbc.setAttributes(new String[] { OLEPropertyConstants.DOCUMENT_NUMBER });
47 rqbc.addOrderByDescending(OLEPropertyConstants.DOCUMENT_NUMBER);
48
49 Iterator<?> documentHeaderIdsIterator = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(rqbc);
50
51 if (documentHeaderIdsIterator.hasNext()) {
52 Object[] result = (Object[]) TransactionalServiceUtils.retrieveFirstAndExhaustIterator(documentHeaderIdsIterator);
53 if (result[0] != null) {
54 return result[0].toString();
55 }
56 else {
57 return null;
58 }
59 }
60 else {
61 return null;
62 }
63 }
64
65
66
67
68 public String getMostRecentClose(Date today) {
69
70 Criteria criteria = new Criteria();
71 criteria.addEqualTo(CGPropertyConstants.PROPOSAL_AWARD_CLOSE_DOC_USER_INITIATED_CLOSE_DATE, today);
72 criteria.addEqualTo(OLEPropertyConstants.DOCUMENT_HEADER + "." + OLEPropertyConstants.FINANCIAL_DOCUMENT_STATUS_CODE, OLEConstants.DocumentStatusCodes.APPROVED);
73 ReportQueryByCriteria rqbc = new ReportQueryByCriteria(ProposalAwardCloseDocument.class, criteria);
74 rqbc.setAttributes(new String[] { OLEPropertyConstants.DOCUMENT_NUMBER });
75
76 rqbc.addOrderByDescending(OLEPropertyConstants.DOCUMENT_NUMBER);
77 getPersistenceBrokerTemplate().clearCache();
78 if ( getPersistenceBrokerTemplate().getCount(rqbc) == 0) return null;
79
80 Iterator<?> documentHeaderIdsIterator = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(rqbc);
81
82
83 Object[] result = (Object[]) TransactionalServiceUtils.retrieveFirstAndExhaustIterator(documentHeaderIdsIterator);
84 if (result[0] != null) {
85 return result[0].toString();
86 }
87 else {
88 return null;
89 }
90 }
91
92 }