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.service.impl;
017    
018    import java.util.Collection;
019    import java.util.Iterator;
020    
021    import org.apache.log4j.Logger;
022    import org.kuali.kfs.module.purap.businessobject.ReceivingAddress;
023    import org.kuali.kfs.module.purap.document.dataaccess.ReceivingAddressDao;
024    import org.kuali.kfs.module.purap.document.service.ReceivingAddressService;
025    import org.springframework.transaction.annotation.Transactional;
026    
027    @Transactional
028    public class ReceivingAddressServiceImpl implements ReceivingAddressService {
029        private static Logger LOG = Logger.getLogger(ReceivingAddressServiceImpl.class);
030    
031        private ReceivingAddressDao dao;
032    
033        public void setReceivingAddressDao(ReceivingAddressDao dao) {
034            this.dao = dao;
035        }
036    
037        /**
038         * @see org.kuali.kfs.module.purap.document.service.ReceivingAddressService#findActiveByChartOrg(java.lang.String,java.lang.String)
039         */
040        public Collection<ReceivingAddress> findActiveByChartOrg(String chartCode, String orgCode) {
041            LOG.debug("Entering findActiveByChartOrg(String,String)");
042            LOG.debug("Leaving findActiveByChartOrg(String,String)");
043            return dao.findActiveByChartOrg(chartCode,orgCode);
044        }
045    
046        /**
047         * @see org.kuali.kfs.module.purap.document.service.ReceivingAddressService#findDefaultByChartOrg(java.lang.String,java.lang.String)
048         */
049        public Collection<ReceivingAddress> findDefaultByChartOrg(String chartCode, String orgCode) {
050            LOG.debug("Entering findDefaultByChartOrg(String,String)");
051            LOG.debug("Leaving findDefaultByChartOrg(String,String)");
052            return dao.findDefaultByChartOrg(chartCode,orgCode);
053        }
054    
055        /**
056         * @see org.kuali.kfs.module.purap.document.service.ReceivingAddressService#findUniqueDefaultByChartOrg(java.lang.String,java.lang.String)
057         */
058        public ReceivingAddress findUniqueDefaultByChartOrg(String chartCode, String orgCode) {
059            LOG.debug("Entering findUniqueDefaultByChartOrg(String,String)");
060            Collection<ReceivingAddress> addresses  = findDefaultByChartOrg(chartCode,orgCode);      
061            if (addresses != null ) {
062                Iterator iter = addresses.iterator();
063                if (iter.hasNext()) {
064                    LOG.debug("Leaving findUniqueDefaultByChartOrg(String,String)");       
065                    return (ReceivingAddress)iter.next();
066                }
067            }
068            LOG.debug("Leaving findUniqueDefaultByChartOrg(String,String)");       
069            return null;
070            //TODO what if more than one is found? throw an exception
071        }
072        
073        /**
074         * @see org.kuali.kfs.module.purap.document.service.ReceivingAddressService#countActiveByChartOrg(java.lang.String,java.lang.String)
075         */
076        public int countActiveByChartOrg(String chartCode, String orgCode) {
077            LOG.debug("Entering countActiveByChartOrg(String,String)");
078            LOG.debug("Leaving countActiveByChartOrg(String,String)");
079            return dao.countActiveByChartOrg(chartCode,orgCode);
080        }
081    
082    }