001/*
002 * Copyright 2007 The Kuali Foundation
003 * 
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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 */
016package org.kuali.ole.module.purap.document.dataaccess.impl;
017
018import org.apache.log4j.Logger;
019import org.apache.ojb.broker.query.Criteria;
020import org.apache.ojb.broker.query.Query;
021import org.apache.ojb.broker.query.QueryByCriteria;
022import org.kuali.ole.module.purap.businessobject.NegativeInvoiceApprovalLimit;
023import org.kuali.ole.module.purap.document.dataaccess.NegativeInvoiceApprovalLimitDao;
024import org.kuali.ole.sys.OLEPropertyConstants;
025import org.kuali.rice.core.api.util.type.KualiDecimal;
026import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
027import org.kuali.rice.krad.util.KRADPropertyConstants;
028import org.springframework.transaction.annotation.Transactional;
029
030import java.util.Collection;
031
032/**
033 * OJB Implementation of NegativeInvoiceApprovalLimitDao.
034 */
035@Transactional
036public class NegativeInvoiceApprovalLimitDaoOjb extends PlatformAwareDaoBaseOjb implements NegativeInvoiceApprovalLimitDao {
037    private static Logger LOG = Logger.getLogger(NegativeInvoiceApprovalLimitDaoOjb.class);
038
039    /**
040     * @see org.kuali.ole.module.purap.document.dataaccess.NegativeInvoiceApprovalLimitDao#findByChart(String)
041     */
042    public Collection<NegativeInvoiceApprovalLimit> findByChart(String chartCode) {
043        LOG.debug("Entering findByChart(String)");
044        Criteria criteria = new Criteria();
045        criteria.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
046        criteria.addIsNull(OLEPropertyConstants.ORGANIZATION_CODE);
047        criteria.addIsNull(OLEPropertyConstants.ACCOUNT_NUMBER);
048        criteria.addAndCriteria(buildActiveCriteria());
049        Query query = new QueryByCriteria(NegativeInvoiceApprovalLimit.class, criteria);
050        LOG.debug("Leaving findByChart(String)");
051
052        return getPersistenceBrokerTemplate().getCollectionByQuery(query);
053    }
054
055    /**
056     * @see org.kuali.ole.module.purap.document.dataaccess.NegativeInvoiceApprovalLimitDao#findByChartAndAccount(String,
057     *      String)
058     */
059    public Collection<NegativeInvoiceApprovalLimit> findByChartAndAccount(String chartCode, String accountNumber) {
060        LOG.debug("Entering findByChartAndAccount(String, String)");
061        Criteria criteria = new Criteria();
062        criteria.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
063        criteria.addEqualTo(OLEPropertyConstants.ACCOUNT_NUMBER, accountNumber);
064        criteria.addIsNull(OLEPropertyConstants.ORGANIZATION_CODE);
065        criteria.addAndCriteria(buildActiveCriteria());
066        Query query = new QueryByCriteria(NegativeInvoiceApprovalLimit.class, criteria);
067        LOG.debug("Leaving findByChartAndAccount(String, String)");
068
069        return getPersistenceBrokerTemplate().getCollectionByQuery(query);
070    }
071
072    /**
073     * @see org.kuali.ole.module.purap.document.dataaccess.NegativeInvoiceApprovalLimitDao#findByChartAndOrganization(String,
074     *      String)
075     */
076    public Collection<NegativeInvoiceApprovalLimit> findByChartAndOrganization(String chartCode, String organizationCode) {
077        LOG.debug("Entering findByChartAndOrganization(String, String)");
078        Criteria criteria = new Criteria();
079        criteria.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
080        criteria.addEqualTo(OLEPropertyConstants.ORGANIZATION_CODE, organizationCode);
081        criteria.addIsNull(OLEPropertyConstants.ACCOUNT_NUMBER);
082        criteria.addAndCriteria(buildActiveCriteria());
083        Query query = new QueryByCriteria(NegativeInvoiceApprovalLimit.class, criteria);
084        LOG.debug("Leaving findByChartAndOrganization(String, String)");
085
086        return getPersistenceBrokerTemplate().getCollectionByQuery(query);
087    }
088
089    /**
090     * @see org.kuali.ole.module.purap.document.dataaccess.NegativeInvoiceApprovalLimitDao#findAboveLimit(org.kuali.rice.core.api.util.type.KualiDecimal)
091     */
092    public Collection<NegativeInvoiceApprovalLimit> findAboveLimit(KualiDecimal limit) {
093        LOG.debug("Entering findAboveLimit(KualiDecimal)");
094        Criteria criteria = new Criteria();
095        criteria.addGreaterThan("negativeInvoiceApprovalLimitAmount", limit);
096        criteria.addAndCriteria(buildActiveCriteria());
097        Query query = new QueryByCriteria(NegativeInvoiceApprovalLimit.class, criteria);
098        LOG.debug("Leaving findAboveLimit(KualiDecimal)");
099
100        return getPersistenceBrokerTemplate().getCollectionByQuery(query);
101    }
102
103    /**
104     * @see org.kuali.ole.module.purap.document.dataaccess.NegativeInvoiceApprovalLimitDao#findBelowLimit(org.kuali.rice.core.api.util.type.KualiDecimal)
105     */
106    public Collection<NegativeInvoiceApprovalLimit> findBelowLimit(KualiDecimal limit) {
107        LOG.debug("Entering findBelowLimit(KualiDecimal)");
108        Criteria criteria = new Criteria();
109        criteria.addLessThan("negativeInvoiceApprovalLimitAmount", limit);
110        criteria.addAndCriteria(buildActiveCriteria());
111        Query query = new QueryByCriteria(NegativeInvoiceApprovalLimit.class, criteria);
112        LOG.debug("Leaving findBelowLimit(KualiDecimal)");
113
114        return getPersistenceBrokerTemplate().getCollectionByQuery(query);
115    }
116
117    /**
118     * Builds a Criteria object for activeIndicator field set to true
119     *
120     * @return Criteria
121     */
122    protected Criteria buildActiveCriteria() {
123        Criteria criteria = new Criteria();
124        criteria.addEqualTo(KRADPropertyConstants.ACTIVE, true);
125
126        return criteria;
127    }
128}