001 /*
002 * Copyright 2011 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 */
016 package org.kuali.kfs.module.purap.document.dataaccess.impl;
017
018 import java.util.Collection;
019
020 import org.apache.log4j.Logger;
021 import org.apache.ojb.broker.query.Criteria;
022 import org.apache.ojb.broker.query.Query;
023 import org.apache.ojb.broker.query.QueryByCriteria;
024 import org.kuali.kfs.module.purap.PurapPropertyConstants;
025 import org.kuali.kfs.module.purap.businessobject.ReceivingAddress;
026 import org.kuali.kfs.module.purap.document.dataaccess.ReceivingAddressDao;
027 import org.kuali.kfs.sys.KFSPropertyConstants;
028 import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb;
029
030 /**
031 * OJB Implementation of ReceivingAddressDao.
032 */
033 public class ReceivingAddressDaoOjb extends PlatformAwareDaoBaseOjb implements ReceivingAddressDao {
034 private static Logger LOG = Logger.getLogger(ReceivingAddressDaoOjb.class);
035
036 /**
037 * @see org.kuali.kfs.module.purap.document.dataaccess.ReceivingAddressDao#findActiveByChartOrg(java.lang.String,java.lang.String)
038 */
039 public Collection<ReceivingAddress> findActiveByChartOrg(String chartCode, String orgCode) {
040 LOG.debug("Entering findActiveByChartOrg(String,String)");
041
042 Criteria criteria = new Criteria();
043 criteria.addEqualTo(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
044 if ( orgCode == null )
045 criteria.addIsNull(KFSPropertyConstants.ORGANIZATION_CODE);
046 else
047 criteria.addEqualTo(KFSPropertyConstants.ORGANIZATION_CODE, orgCode);
048 criteria.addEqualTo(PurapPropertyConstants.BO_ACTIVE, true);
049 Query query = new QueryByCriteria(ReceivingAddress.class, criteria);
050
051 LOG.debug("Leaving findActiveByChartOrg(String,String)");
052 return getPersistenceBrokerTemplate().getCollectionByQuery(query);
053 }
054
055 /**
056 * @see org.kuali.kfs.module.purap.document.dataaccess.ReceivingAddressDao#findDefaultByChartOrg(java.lang.String,java.lang.String)
057 */
058 public Collection<ReceivingAddress> findDefaultByChartOrg(String chartCode, String orgCode) {
059 LOG.debug("Entering findDefaultByChartOrg(String,String)");
060
061 Criteria criteria = new Criteria();
062 criteria.addEqualTo(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
063 if ( orgCode == null )
064 criteria.addIsNull(KFSPropertyConstants.ORGANIZATION_CODE);
065 else
066 criteria.addEqualTo(KFSPropertyConstants.ORGANIZATION_CODE, orgCode);
067 criteria.addEqualTo(PurapPropertyConstants.RECEIVING_ADDRESS_DEFAULT_INDICATOR, true);
068 criteria.addEqualTo(PurapPropertyConstants.BO_ACTIVE, true);
069 Query query = new QueryByCriteria(ReceivingAddress.class, criteria);
070
071 LOG.debug("Leaving findDefaultByChartOrg(String,String)");
072 return getPersistenceBrokerTemplate().getCollectionByQuery(query);
073 }
074
075 /**
076 * @see org.kuali.kfs.module.purap.document.dataaccess.ReceivingAddressDao#countActiveByChartOrg(java.lang.String,java.lang.String)
077 */
078 public int countActiveByChartOrg(String chartCode, String orgCode) {
079 LOG.debug("Entering countActiveByChartOrg(String,String)");
080
081 Criteria criteria = new Criteria();
082 criteria.addEqualTo(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
083 if ( orgCode == null )
084 criteria.addIsNull(KFSPropertyConstants.ORGANIZATION_CODE);
085 else
086 criteria.addEqualTo(KFSPropertyConstants.ORGANIZATION_CODE, orgCode);
087 criteria.addEqualTo(PurapPropertyConstants.BO_ACTIVE, true);
088 Query query = new QueryByCriteria(ReceivingAddress.class, criteria);
089
090 LOG.debug("Leaving countActiveByChartOrg(String,String)");
091 return getPersistenceBrokerTemplate().getCount(query);
092 }
093
094 }