/*
* The Kuali Financial System, a comprehensive financial management system for higher education.
*
* Copyright 2005-2014 The Kuali Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.kuali.kfs.fp.document.dataaccess;
import java.util.HashMap;
import java.util.Map;
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.accesslayer.QueryCustomizer;
import org.apache.ojb.broker.metadata.CollectionDescriptor;
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.query.QueryByCriteria;
import org.kuali.kfs.sys.KFSConstants;
import org.kuali.kfs.sys.KFSPropertyConstants;
/**
* Query customizer for to seperate out the pre-paid and non prepaid collections from the dv expense table.
*/
public class OJBTravelExpenseQueryCustomizer implements QueryCustomizer {
private static final String prepaidAttributeName = "PREPAID";
private static final String prepaidIndicatorField = KFSPropertyConstants.DISB_VCHR_EXPENSE + "." + KFSPropertyConstants.PREPAID_EXPENSE;
private Map attributes = new HashMap();
/**
* @see org.apache.ojb.broker.accesslayer.QueryCustomizer#customizeQuery(java.lang.Object,
* org.apache.ojb.broker.PersistenceBroker, org.apache.ojb.broker.metadata.CollectionDescriptor,
* org.apache.ojb.broker.query.QueryByCriteria)
*/
public Query customizeQuery(Object arg0, PersistenceBroker arg1, CollectionDescriptor arg2, QueryByCriteria arg3) {
if ("TRUE".equals(getAttribute(prepaidAttributeName))) {
arg3.getCriteria().addEqualTo(prepaidIndicatorField, KFSConstants.ACTIVE_INDICATOR);
}
else {
arg3.getCriteria().addEqualTo(prepaidIndicatorField, KFSConstants.NON_ACTIVE_INDICATOR);
}
return arg3;
}
/**
* @see org.apache.ojb.broker.metadata.AttributeContainer#addAttribute(java.lang.String, java.lang.String)
*/
public void addAttribute(String arg0, String arg1) {
attributes.put(arg0, arg1);
}
/**
* @see org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(java.lang.String, java.lang.String)
*/
public String getAttribute(String arg0, String arg1) {
return (String) attributes.get(arg0);
}
/**
* @see org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(java.lang.String)
*/
public String getAttribute(String arg0) {
return (String) attributes.get(arg0);
}
}