View Javadoc
1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @see CloseDao
33   */
34  public class CloseDaoOjb extends PlatformAwareDaoBaseOjb implements CloseDao {
35  
36      /**
37       * @see org.kuali.ole.module.cg.dataaccess.CloseDao#getMaxApprovedClose()
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       * @see org.kuali.ole.module.cg.dataaccess.CloseDao#getMostRecentClose(java.sql.Date)
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  }