View Javadoc
1   package org.kuali.ole.ingest.resolver; /**
2    * Copyright 2005-2012 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  
17  import org.apache.log4j.Logger;
18  import org.kuali.ole.OLEConstants;
19  import org.kuali.ole.ingest.function.*;
20  import org.kuali.rice.krms.api.repository.function.FunctionDefinition;
21  import org.kuali.rice.krms.framework.engine.Function;
22  import org.kuali.rice.krms.framework.type.FunctionTypeService;
23  
24  public class FunctionLoader implements FunctionTypeService {
25  
26      private ISBNFunction isbnFunction;
27      private OleCurrentDateComparison oleCurrentDateComparison;
28      private CheckDigitRoutine checkDigitRoutine;
29      private OleContainsComparison containsComparison;
30      private ISSNFunction issnFunction;
31      private OCLCFunction oclcFunction;
32      private LocationFunction locationFunction;
33      private ItemBarcodeFunction itemBarcodeFunction;
34      private VendorLineItemReferenceFunction vendorLineItemReferenceFunction;
35      private static final Logger LOG = Logger.getLogger(FunctionLoader.class);
36  
37      /**
38       *  Returns the instance of ISBNFunction or PatronMembershipExpiration based on function definition
39       * @param functionDefinition
40       * @return  Function(isbnFunction/patronMembershipExpiration).
41       */
42      @Override
43      public Function loadFunction(FunctionDefinition functionDefinition) {
44          if (functionDefinition.getName().equals(OLEConstants.ISBN_FUNCTION_DEF_NAME)) {
45              return getISBNFunction();
46          } else if(functionDefinition.getName().equals(OLEConstants.ISSN_FUNCTION_DEF_NAME)) {
47              return getISSNFunction();
48          } else if(functionDefinition.getName().equals(OLEConstants.OCLC_FUNCTION_DEF_NAME)) {
49              return getOCLCFunction();
50          } else if (functionDefinition.getName().equals(OLEConstants.OLE_CURRENT_DATE_FUNCTION)) {
51              return getOleCurrentDateComparison();
52          } else if(functionDefinition.getName().equals(OLEConstants.CHECK_DIGIT_ROUTINE))  {
53              return getCheckDigitRoutine();
54          } else if(functionDefinition.getName().equals(OLEConstants.LOCATION_FUNCTION_DEF_NAME)){
55              return getLocationFunction();
56          } else if(functionDefinition.getName().equals(OLEConstants.ITEM_BARCODE_FUNCTION_DEF_NAME)) {
57              return getItemBarcodeFunction();
58          }
59          else if(functionDefinition.getName().equals(OLEConstants.VENDOR_LINEITEM_REF_NUM_FUNCTION_DEF_NAME)){
60              return getVendorLineItemReferenceFunction();
61          }
62          else if(functionDefinition.getName().equals(OLEConstants.OLE_CONTAINS_FUNCTION)){
63              return getContainsComparison();
64          } else if(functionDefinition.getName().equals(OLEConstants.OLE_CIRC_POLICY_FOUND_FUNCTION))  {
65              return new CirculationPolicyFoundFunction();
66          }
67          else if(functionDefinition.getName().equals(OLEConstants.OLE_RENEWAL_DATE_FUNCTION))  {
68              return new OleRenewalDateComparison();
69          }
70          throw new IllegalArgumentException("Failed to load function for the given definition: " + functionDefinition.getName());
71      }
72  
73      /**
74       * Returns the VendorLineItemReferenceFunction.
75       * if VendorLineItemReferenceFunction is null return new instance,otherwise return existing instance of vendorLineItemReferenceFunction.
76       * @return  vendorLineItemReferenceFunction
77       */
78      public VendorLineItemReferenceFunction getVendorLineItemReferenceFunction() {
79          if (null == vendorLineItemReferenceFunction) {
80              vendorLineItemReferenceFunction = new VendorLineItemReferenceFunction();
81          }
82          return vendorLineItemReferenceFunction;
83      }
84  
85      /**
86       * Returns the LocationFunction.
87       * if LocationFunction is null return new instance,otherwise return existing instance of locationFunction.
88       * @return  locationFunction
89       */
90      public LocationFunction getLocationFunction() {
91          if (null == locationFunction) {
92              locationFunction = new LocationFunction();
93          }
94          return locationFunction;
95      }
96  
97      /**
98       * Returns the ItemBarcodeFunction.
99       * if ItemBarcodeFunction is null return new instance,otherwise return existing instance of itemBarcodeFunction.
100      * @return  itemBarcodeFunction
101      */
102     public ItemBarcodeFunction getItemBarcodeFunction() {
103         if(null == itemBarcodeFunction){
104             itemBarcodeFunction = new ItemBarcodeFunction();
105         }
106         return itemBarcodeFunction;
107     }
108 
109     /**
110      * Returns the ISBNFunction.
111      * if ISBNFunction is null return new instance,otherwise return existing instance of isbnFunction.
112      * @return  isbnFunction
113      */
114     private Function getISBNFunction() {
115         if (null == isbnFunction) {
116             isbnFunction = new ISBNFunction();
117         }
118         return isbnFunction;
119     }
120     /**
121      * Returns the ISSNFunction.
122      * if ISSNFunction is null return new instance,otherwise return existing instance of issnFunction.
123      * @return  issnFunction
124      */
125     private Function getISSNFunction() {
126         if (null == issnFunction) {
127             issnFunction = new ISSNFunction();
128         }
129         return issnFunction;
130     }
131 
132     /**
133      * Returns the OCLCFunction.
134      * if OCLCFunction is null return new instance,otherwise return existing instance of oclcFunction.
135      * @return  oclcFunction
136      */
137     private Function getOCLCFunction() {
138         if (null == oclcFunction) {
139             oclcFunction = new OCLCFunction();
140         }
141         return oclcFunction;
142     }
143 
144     /**
145      * Returns the new instance of patronMembershipExpiration.
146      * if patronMembershipExpiration is null returns new instance,otherwise returns existing patronMembershipExpiration.
147      * @return  patronMembershipExpiration
148      */
149     private Function getOleCurrentDateComparison(){
150         if(null == oleCurrentDateComparison){
151             oleCurrentDateComparison = new OleCurrentDateComparison();
152         }
153         return oleCurrentDateComparison;
154     }
155     /**
156      * Returns the new instance of containsComparison.
157      * if containsComparison is null returns new instance,otherwise returns existing containsComparison.
158      * @return  containsComparison
159      */
160     public OleContainsComparison getContainsComparison() {
161         if(null == containsComparison){
162             containsComparison = new OleContainsComparison();
163         }
164         return containsComparison;
165     }
166 
167     /**
168      * Returns the new instance of checkDigitRoutine.
169      * if checkDigitRoutine is null returns new instance,otherwise returns existing checkDigitRoutine.
170      * @return  checkDigitRoutine
171      */
172     public CheckDigitRoutine getCheckDigitRoutine() {
173         if(null == checkDigitRoutine){
174             checkDigitRoutine = new CheckDigitRoutine();
175         }
176         return checkDigitRoutine;
177     }
178 }