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.dataaccess.impl;
017
018import org.apache.ojb.broker.query.Criteria;
019import org.apache.ojb.broker.query.QueryByCriteria;
020import org.apache.ojb.broker.query.QueryFactory;
021import org.kuali.ole.module.purap.PurapPropertyConstants;
022import org.kuali.ole.module.purap.businessobject.AccountsPayableSummaryAccount;
023import org.kuali.ole.module.purap.businessobject.PurApItem;
024import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
025import org.kuali.ole.module.purap.dataaccess.PurApAccountingDao;
026import org.kuali.ole.select.businessobject.OleInvoiceAccountsPayableSummaryAccount;
027import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
028
029import java.util.ArrayList;
030import java.util.Collection;
031import java.util.List;
032
033/**
034 * OJB Implementation of PurApAccountingDao.
035 */
036public class PurApAccountingDaoOjb extends PlatformAwareDaoBaseOjb implements PurApAccountingDao {
037
038    /**
039     * @see org.kuali.ole.module.purap.dataaccess.PurApAccountingDao#getAccountingLinesForItem(org.kuali.ole.module.purap.businessobject.PurApItem)
040     */
041    public List getAccountingLinesForItem(PurApItem item) {
042        Class clazz = item.getAccountingLineClass();
043        Criteria criteria = new Criteria();
044        criteria.addEqualTo("itemIdentifier", item.getItemIdentifier());
045
046        // if it's a purchaseOrderItem, we need to make sure we're getting for the right doc number
047        if (item instanceof PurchaseOrderItem) {
048            criteria.addEqualTo("documentNumber", ((PurchaseOrderItem) item).getDocumentNumber());
049        }
050
051        QueryByCriteria query = QueryFactory.newQuery(clazz, criteria);
052        Collection lines = getPersistenceBrokerTemplate().getCollectionByQuery(query);
053
054        return new ArrayList(lines);
055
056    }
057
058    /**
059     * @see org.kuali.ole.module.purap.dataaccess.PurApAccountingDao#deleteSummaryAccountsbyPaymentRequestIdentifier(java.lang.Integer)
060     */
061    public void deleteSummaryAccountsbyPaymentRequestIdentifier(Integer paymentRequestIdentifier) {
062        if (paymentRequestIdentifier != null) {
063            Criteria criteria = new Criteria();
064            criteria.addEqualTo(PurapPropertyConstants.PAYMENT_REQUEST_ID, paymentRequestIdentifier);
065
066            getPersistenceBrokerTemplate().deleteByQuery(QueryFactory.newQuery(AccountsPayableSummaryAccount.class, criteria));
067            getPersistenceBrokerTemplate().clearCache();
068        }
069    }
070
071    /**
072     * @see org.kuali.ole.module.purap.dataaccess.PurApAccountingDao#deleteSummaryAccountsbyPaymentRequestIdentifier(java.lang.Integer)
073     */
074    public void deleteSummaryAccountsbyInvoiceIdentifier(Integer invoiceIdentifier) {
075        if (invoiceIdentifier != null) {
076            Criteria criteria = new Criteria();
077            criteria.addEqualTo(PurapPropertyConstants.INVOICE_ID, invoiceIdentifier);
078
079            getPersistenceBrokerTemplate().deleteByQuery(QueryFactory.newQuery(OleInvoiceAccountsPayableSummaryAccount.class, criteria));
080            getPersistenceBrokerTemplate().clearCache();
081        }
082    }
083
084    /**
085     * @see org.kuali.ole.module.purap.dataaccess.PurApAccountingDao#deleteSummaryAccountsbyCreditMemoIdentifier(java.lang.Integer)
086     */
087    public void deleteSummaryAccountsbyCreditMemoIdentifier(Integer creditMemoIdentifier) {
088        if (creditMemoIdentifier != null) {
089            Criteria criteria = new Criteria();
090            criteria.addEqualTo(PurapPropertyConstants.CREDIT_MEMO_ID, creditMemoIdentifier);
091
092            getPersistenceBrokerTemplate().deleteByQuery(QueryFactory.newQuery(AccountsPayableSummaryAccount.class, criteria));
093            getPersistenceBrokerTemplate().clearCache();
094        }
095    }
096
097}