1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.gl.businessobject.lookup;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.Iterator;
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.kuali.ole.sys.OLEPropertyConstants;
25  
26  
27  
28  
29  public class BusinessObjectFieldConverter {
30  
31      
32  
33  
34  
35  
36  
37      public static List convertToTransactionFields(List fields) {
38          List transactionFields = new ArrayList();
39  
40          Iterator propsIter = fields.iterator();
41          while (propsIter.hasNext()) {
42              String propertyName = (String) propsIter.next();
43  
44              
45              String transactionPropertyName = propertyName;
46  
47              Map propertyMappingTable = getPropertyMappingTable();
48              transactionPropertyName = convertPropertyName(propertyMappingTable, propertyName);
49  
50              
51              transactionFields.add(transactionPropertyName);
52          }
53          return transactionFields;
54      }
55  
56      
57  
58  
59  
60  
61  
62      public static Map convertToTransactionFieldValues(Map fieldValues) {
63          Map transactionFieldValues = new HashMap();
64  
65          Iterator propsIter = fieldValues.keySet().iterator();
66          while (propsIter.hasNext()) {
67              String propertyName = (String) propsIter.next();
68              String propertyValue = (String) fieldValues.get(propertyName);
69  
70              
71              String transactionPropertyName = propertyName;
72  
73              Map propertyMappingTable = getPropertyMappingTable();
74              transactionPropertyName = convertPropertyName(propertyMappingTable, propertyName);
75  
76              
77              transactionFieldValues.put(transactionPropertyName, propertyValue);
78          }
79          return transactionFieldValues;
80      }
81  
82      
83  
84  
85  
86  
87  
88      public static String convertToTransactionPropertyName(String propertyName) {
89          return convertPropertyName(getPropertyMappingTable(), propertyName);
90      }
91  
92      
93  
94  
95  
96  
97  
98      public static String convertFromTransactionPropertyName(String propertyName) {
99          return convertPropertyName(getSwappedPropertyMappingTable(), propertyName);
100     }
101 
102     
103 
104 
105 
106 
107 
108     public static Map convertFromTransactionFieldValues(Map fieldValues) {
109         Map boFieldValues = new HashMap();
110 
111         Iterator propsIter = fieldValues.keySet().iterator();
112         while (propsIter.hasNext()) {
113             String propertyName = (String) propsIter.next();
114             String propertyValue = (String) fieldValues.get(propertyName);
115 
116             
117             String transactionPropertyName = propertyName;
118             Map propertyMappingTable = getSwappedPropertyMappingTable();
119             transactionPropertyName = convertPropertyName(propertyMappingTable, propertyName);
120 
121             
122             boFieldValues.put(transactionPropertyName, propertyValue);
123         }
124         return boFieldValues;
125     }
126 
127     
128 
129 
130 
131 
132     private static Map getPropertyMappingTable() {
133         Map propertyMappingTable = new HashMap();
134 
135         propertyMappingTable.put(OLEPropertyConstants.OBJECT_CODE, OLEPropertyConstants.FINANCIAL_OBJECT_CODE);
136         propertyMappingTable.put(OLEPropertyConstants.SUB_OBJECT_CODE, OLEPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
137         propertyMappingTable.put(OLEPropertyConstants.OBJECT_TYPE_CODE, OLEPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE);
138 
139         propertyMappingTable.put(OLEPropertyConstants.BALANCE_TYPE_CODE, OLEPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE);
140         propertyMappingTable.put(OLEPropertyConstants.ENCUMBRANCE_DOCUMENT_TYPE_CODE, OLEPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE);
141         propertyMappingTable.put(OLEPropertyConstants.ORIGIN_CODE, OLEPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE);
142         propertyMappingTable.put(OLEPropertyConstants.DOCUMENT_NUMBER, OLEPropertyConstants.DOCUMENT_NUMBER);
143 
144         return propertyMappingTable;
145     }
146 
147     
148 
149 
150 
151 
152     private static Map getSwappedPropertyMappingTable() {
153         Map propertyMappingTable = getPropertyMappingTable();
154         Map swappedPropertyMappingTable = new HashMap();
155 
156         Iterator iterator = propertyMappingTable.keySet().iterator();
157         while (iterator.hasNext()) {
158             String propertyKey = (String) iterator.next();
159             String propertyValue = (String) propertyMappingTable.get(propertyKey);
160 
161             if (propertyValue != null && !swappedPropertyMappingTable.containsKey(propertyValue)) {
162                 swappedPropertyMappingTable.put(propertyValue, propertyKey);
163             }
164         }
165         return swappedPropertyMappingTable;
166     }
167 
168     
169 
170 
171 
172 
173 
174 
175     private static String convertPropertyName(Map propertyMappingTable, String propertyName) {
176 
177         String transactionPropertyName = propertyName;
178         if (propertyMappingTable.containsKey(propertyName)) {
179             transactionPropertyName = (String) propertyMappingTable.get(propertyName);
180         }
181         return transactionPropertyName;
182     }
183 
184     
185 
186 
187 
188 
189 
190 
191     public static void escapeSpecialCharacter(Map fieldValues, String specialCharacter, String replacement) {
192         Iterator propsIter = fieldValues.keySet().iterator();
193         while (propsIter.hasNext()) {
194             String propertyName = (String) propsIter.next();
195             String propertyValue = (String) fieldValues.get(propertyName);
196 
197             String propertyValueAfterEscaped = propertyValue.replaceAll(specialCharacter, replacement);
198             fieldValues.put(propertyName, propertyValueAfterEscaped);
199         }
200     }
201 
202     
203 
204 
205 
206     public static void escapeSingleQuote(Map fieldValues) {
207         String specialCharacter = "'";
208         String replacement = " ";
209         escapeSpecialCharacter(fieldValues, specialCharacter, replacement);
210     }
211 }