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.fp.document.dataaccess;
017    
018    import java.util.HashMap;
019    import java.util.Map;
020    
021    import org.apache.ojb.broker.PersistenceBroker;
022    import org.apache.ojb.broker.accesslayer.QueryCustomizer;
023    import org.apache.ojb.broker.metadata.CollectionDescriptor;
024    import org.apache.ojb.broker.query.Query;
025    import org.apache.ojb.broker.query.QueryByCriteria;
026    import org.kuali.kfs.sys.KFSConstants;
027    import org.kuali.kfs.sys.KFSPropertyConstants;
028    
029    /**
030     * Query customizer for to seperate out the pre-paid and non prepaid collections from the dv expense table.
031     */
032    public class OJBTravelExpenseQueryCustomizer implements QueryCustomizer {
033        private static final String prepaidAttributeName = "PREPAID";
034        private static final String prepaidIndicatorField = KFSPropertyConstants.DISB_VCHR_EXPENSE + "." + KFSPropertyConstants.PREPAID_EXPENSE;
035        private Map attributes = new HashMap();
036    
037        /**
038         * @see org.apache.ojb.broker.accesslayer.QueryCustomizer#customizeQuery(java.lang.Object,
039         *      org.apache.ojb.broker.PersistenceBroker, org.apache.ojb.broker.metadata.CollectionDescriptor,
040         *      org.apache.ojb.broker.query.QueryByCriteria)
041         */
042        public Query customizeQuery(Object arg0, PersistenceBroker arg1, CollectionDescriptor arg2, QueryByCriteria arg3) {
043            if ("TRUE".equals(getAttribute(prepaidAttributeName))) {
044                arg3.getCriteria().addEqualTo(prepaidIndicatorField, KFSConstants.ACTIVE_INDICATOR);
045            }
046            else {
047                arg3.getCriteria().addEqualTo(prepaidIndicatorField, KFSConstants.NON_ACTIVE_INDICATOR);
048            }
049            return arg3;
050        }
051    
052        /**
053         * @see org.apache.ojb.broker.metadata.AttributeContainer#addAttribute(java.lang.String, java.lang.String)
054         */
055        public void addAttribute(String arg0, String arg1) {
056            attributes.put(arg0, arg1);
057        }
058    
059        /**
060         * @see org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(java.lang.String, java.lang.String)
061         */
062        public String getAttribute(String arg0, String arg1) {
063            return (String) attributes.get(arg0);
064        }
065    
066        /**
067         * @see org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(java.lang.String)
068         */
069        public String getAttribute(String arg0) {
070            return (String) attributes.get(arg0);
071        }
072    
073    }