View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.purap.document.dataaccess.impl;
20  
21  import java.util.Collection;
22  
23  import org.apache.log4j.Logger;
24  import org.apache.ojb.broker.query.Criteria;
25  import org.apache.ojb.broker.query.Query;
26  import org.apache.ojb.broker.query.QueryByCriteria;
27  import org.kuali.kfs.module.purap.businessobject.NegativePaymentRequestApprovalLimit;
28  import org.kuali.kfs.module.purap.document.dataaccess.NegativePaymentRequestApprovalLimitDao;
29  import org.kuali.kfs.sys.KFSPropertyConstants;
30  import org.kuali.rice.core.api.util.type.KualiDecimal;
31  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
32  import org.kuali.rice.krad.util.KRADPropertyConstants;
33  import org.springframework.transaction.annotation.Transactional;
34  
35  /**
36   * OJB Implementation of NegativePaymentRequestApprovalLimitDao.
37   */
38  @Transactional
39  public class NegativePaymentRequestApprovalLimitDaoOjb extends PlatformAwareDaoBaseOjb implements NegativePaymentRequestApprovalLimitDao {
40      private static Logger LOG = Logger.getLogger(NegativePaymentRequestApprovalLimitDaoOjb.class);
41  
42      /**
43       * @see org.kuali.kfs.module.purap.document.dataaccess.NegativePaymentRequestApprovalLimitDao#findByChart(java.lang.String)
44       */
45      public Collection<NegativePaymentRequestApprovalLimit> findByChart(String chartCode) {
46          LOG.debug("Entering findByChart(String)");
47          Criteria criteria = new Criteria();
48          criteria.addEqualTo(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
49          criteria.addIsNull(KFSPropertyConstants.ORGANIZATION_CODE);
50          criteria.addIsNull(KFSPropertyConstants.ACCOUNT_NUMBER);
51          criteria.addAndCriteria(buildActiveCriteria());
52          Query query = new QueryByCriteria(NegativePaymentRequestApprovalLimit.class, criteria);
53          LOG.debug("Leaving findByChart(String)");
54  
55          return getPersistenceBrokerTemplate().getCollectionByQuery(query);
56      }
57  
58      /**
59       * @see org.kuali.kfs.module.purap.document.dataaccess.NegativePaymentRequestApprovalLimitDao#findByChartAndAccount(java.lang.String,
60       *      java.lang.String)
61       */
62      public Collection<NegativePaymentRequestApprovalLimit> findByChartAndAccount(String chartCode, String accountNumber) {
63          LOG.debug("Entering findByChartAndAccount(String, String)");
64          Criteria criteria = new Criteria();
65          criteria.addEqualTo(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
66          criteria.addEqualTo(KFSPropertyConstants.ACCOUNT_NUMBER, accountNumber);
67          criteria.addIsNull(KFSPropertyConstants.ORGANIZATION_CODE);
68          criteria.addAndCriteria(buildActiveCriteria());
69          Query query = new QueryByCriteria(NegativePaymentRequestApprovalLimit.class, criteria);
70          LOG.debug("Leaving findByChartAndAccount(String, String)");
71  
72          return getPersistenceBrokerTemplate().getCollectionByQuery(query);
73      }
74  
75      /**
76       * @see org.kuali.kfs.module.purap.document.dataaccess.NegativePaymentRequestApprovalLimitDao#findByChartAndOrganization(java.lang.String,
77       *      java.lang.String)
78       */
79      public Collection<NegativePaymentRequestApprovalLimit> findByChartAndOrganization(String chartCode, String organizationCode) {
80          LOG.debug("Entering findByChartAndOrganization(String, String)");
81          Criteria criteria = new Criteria();
82          criteria.addEqualTo(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
83          criteria.addEqualTo(KFSPropertyConstants.ORGANIZATION_CODE, organizationCode);
84          criteria.addIsNull(KFSPropertyConstants.ACCOUNT_NUMBER);
85          criteria.addAndCriteria(buildActiveCriteria());
86          Query query = new QueryByCriteria(NegativePaymentRequestApprovalLimit.class, criteria);
87          LOG.debug("Leaving findByChartAndOrganization(String, String)");
88  
89          return getPersistenceBrokerTemplate().getCollectionByQuery(query);
90      }
91  
92      /**
93       * @see org.kuali.kfs.module.purap.document.dataaccess.NegativePaymentRequestApprovalLimitDao#findAboveLimit(org.kuali.rice.core.api.util.type.KualiDecimal)
94       */
95      public Collection<NegativePaymentRequestApprovalLimit> findAboveLimit(KualiDecimal limit) {
96          LOG.debug("Entering findAboveLimit(KualiDecimal)");
97          Criteria criteria = new Criteria();
98          criteria.addGreaterThan("negativePaymentRequestApprovalLimitAmount", limit);
99          criteria.addAndCriteria(buildActiveCriteria());
100         Query query = new QueryByCriteria(NegativePaymentRequestApprovalLimit.class, criteria);
101         LOG.debug("Leaving findAboveLimit(KualiDecimal)");
102 
103         return getPersistenceBrokerTemplate().getCollectionByQuery(query);
104     }
105 
106     /**
107      * @see org.kuali.kfs.module.purap.document.dataaccess.NegativePaymentRequestApprovalLimitDao#findBelowLimit(org.kuali.rice.core.api.util.type.KualiDecimal)
108      */
109     public Collection<NegativePaymentRequestApprovalLimit> findBelowLimit(KualiDecimal limit) {
110         LOG.debug("Entering findBelowLimit(KualiDecimal)");
111         Criteria criteria = new Criteria();
112         criteria.addLessThan("negativePaymentRequestApprovalLimitAmount", limit);
113         criteria.addAndCriteria(buildActiveCriteria());
114         Query query = new QueryByCriteria(NegativePaymentRequestApprovalLimit.class, criteria);
115         LOG.debug("Leaving findBelowLimit(KualiDecimal)");
116 
117         return getPersistenceBrokerTemplate().getCollectionByQuery(query);
118     }
119 
120     /**
121      * Builds a Criteria object for activeIndicator field set to true
122      * @return Criteria
123      */
124     protected Criteria buildActiveCriteria(){
125         Criteria criteria = new Criteria();
126         criteria.addEqualTo(KRADPropertyConstants.ACTIVE, true);
127         
128         return criteria;
129     }
130 }