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.vnd.dataaccess.impl;
017    
018    import java.util.Date;
019    
020    import org.apache.ojb.broker.query.Criteria;
021    import org.apache.ojb.broker.query.QueryByCriteria;
022    import org.kuali.kfs.vnd.businessobject.VendorContract;
023    import org.kuali.kfs.vnd.businessobject.VendorDetail;
024    import org.kuali.kfs.vnd.dataaccess.VendorDao;
025    import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb;
026    import org.kuali.rice.kns.service.DateTimeService;
027    
028    /**
029     * OJB implementation of VendorDao.
030     */
031    public class VendorDaoOjb extends PlatformAwareDaoBaseOjb implements VendorDao {
032        private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(VendorDaoOjb.class);
033    
034        private DateTimeService dateTimeService;
035    
036        public VendorContract getVendorB2BContract(VendorDetail vendorDetail, String campus) {
037            Date now = dateTimeService.getCurrentSqlDate();
038    
039            Criteria header = new Criteria();
040            Criteria detail = new Criteria();
041            Criteria campusCode = new Criteria();
042            Criteria beginDate = new Criteria();
043            Criteria endDate = new Criteria();
044            Criteria b2b = new Criteria();
045    
046            header.addEqualTo("VNDR_HDR_GNRTD_ID", vendorDetail.getVendorHeaderGeneratedIdentifier());
047            detail.addEqualTo("VNDR_DTL_ASND_ID", vendorDetail.getVendorDetailAssignedIdentifier());
048            campusCode.addEqualTo("VNDR_CMP_CD", campus);
049            beginDate.addLessOrEqualThan("VNDR_CONTR_BEG_DT", now);
050            endDate.addGreaterOrEqualThan("VNDR_CONTR_END_DT", now);
051            b2b.addEqualTo("VNDR_B2B_IND", "Y");
052    
053            header.addAndCriteria(detail);
054            header.addAndCriteria(campusCode);
055            header.addAndCriteria(beginDate);
056            header.addAndCriteria(endDate);
057            header.addAndCriteria(b2b);
058    
059            VendorContract contract = (VendorContract) getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(VendorContract.class, header));
060            return contract;
061        }        
062        
063        public void setDateTimeService(DateTimeService dateTimeService) {
064            this.dateTimeService = dateTimeService;
065        }
066    
067    }