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.bc.document.dataaccess.impl;
017    
018    import java.util.ArrayList;
019    import java.util.List;
020    
021    import org.apache.ojb.broker.query.Criteria;
022    import org.apache.ojb.broker.query.QueryFactory;
023    import org.apache.ojb.broker.util.ObjectModification;
024    import org.kuali.kfs.module.bc.businessobject.BudgetConstructionHeader;
025    import org.kuali.kfs.module.bc.businessobject.BudgetConstructionRequestMove;
026    import org.kuali.kfs.module.bc.document.dataaccess.ImportRequestDao;
027    import org.kuali.kfs.sys.KFSPropertyConstants;
028    import org.kuali.rice.kns.bo.BusinessObject;
029    import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb;
030    
031    public class ImportRequestDaoOjb extends PlatformAwareDaoBaseOjb  implements ImportRequestDao {
032       
033        public void save(BusinessObject businessObject, boolean isUpdate) {
034            getPersistenceBroker(true).store(businessObject, isUpdate ? ObjectModification.UPDATE : ObjectModification.INSERT); 
035        }
036    
037    
038        /**
039         * 
040         * @see org.kuali.kfs.module.bc.document.dataaccess.ImportRequestDao#findAllNonErrorCodeRecords()
041         */
042        public List<BudgetConstructionRequestMove> findAllNonErrorCodeRecords(String principalId) {
043            Criteria criteria = new Criteria();
044            criteria.addIsNull("requestUpdateErrorCode");
045            criteria.addEqualToColumn("principalId", principalId);
046            
047            List<BudgetConstructionRequestMove> records = new ArrayList<BudgetConstructionRequestMove>(getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(BudgetConstructionRequestMove.class, criteria)));
048            
049            return records;
050        }
051    
052        
053        public BudgetConstructionHeader getHeaderRecord(BudgetConstructionRequestMove record, Integer budgetYear) {
054            Criteria criteria = new Criteria();
055            criteria.addEqualTo(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, record.getChartOfAccountsCode());
056            criteria.addEqualTo(KFSPropertyConstants.ACCOUNT_NUMBER, record.getAccountNumber());
057            criteria.addEqualTo(KFSPropertyConstants.SUB_ACCOUNT_NUMBER, record.getSubAccountNumber());
058            criteria.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, budgetYear);
059            BudgetConstructionHeader header = (BudgetConstructionHeader)getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(BudgetConstructionHeader.class, criteria));
060            
061            return header;
062        }
063    
064    }
065