View Javadoc
1   /*
2    * Copyright 2006 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.fp.document.dataaccess;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.apache.ojb.broker.PersistenceBroker;
22  import org.apache.ojb.broker.accesslayer.QueryCustomizer;
23  import org.apache.ojb.broker.metadata.CollectionDescriptor;
24  import org.apache.ojb.broker.query.Query;
25  import org.apache.ojb.broker.query.QueryByCriteria;
26  import org.kuali.ole.sys.OLEConstants;
27  import org.kuali.ole.sys.OLEPropertyConstants;
28  
29  /**
30   * Query customizer for to seperate out the pre-paid and non prepaid collections from the dv expense table.
31   */
32  public class OJBTravelExpenseQueryCustomizer implements QueryCustomizer {
33      private static final String prepaidAttributeName = "PREPAID";
34      private static final String prepaidIndicatorField = OLEPropertyConstants.DISB_VCHR_EXPENSE + "." + OLEPropertyConstants.PREPAID_EXPENSE;
35      private Map attributes = new HashMap();
36  
37      /**
38       * @see org.apache.ojb.broker.accesslayer.QueryCustomizer#customizeQuery(java.lang.Object,
39       *      org.apache.ojb.broker.PersistenceBroker, org.apache.ojb.broker.metadata.CollectionDescriptor,
40       *      org.apache.ojb.broker.query.QueryByCriteria)
41       */
42      public Query customizeQuery(Object arg0, PersistenceBroker arg1, CollectionDescriptor arg2, QueryByCriteria arg3) {
43          if ("TRUE".equals(getAttribute(prepaidAttributeName))) {
44              arg3.getCriteria().addEqualTo(prepaidIndicatorField, OLEConstants.ACTIVE_INDICATOR);
45          }
46          else {
47              arg3.getCriteria().addEqualTo(prepaidIndicatorField, OLEConstants.NON_ACTIVE_INDICATOR);
48          }
49          return arg3;
50      }
51  
52      /**
53       * @see org.apache.ojb.broker.metadata.AttributeContainer#addAttribute(java.lang.String, java.lang.String)
54       */
55      public void addAttribute(String arg0, String arg1) {
56          attributes.put(arg0, arg1);
57      }
58  
59      /**
60       * @see org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(java.lang.String, java.lang.String)
61       */
62      public String getAttribute(String arg0, String arg1) {
63          return (String) attributes.get(arg0);
64      }
65  
66      /**
67       * @see org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(java.lang.String)
68       */
69      public String getAttribute(String arg0) {
70          return (String) attributes.get(arg0);
71      }
72  
73  }