Clover Coverage Report - Kuali Student 1.1.0-SNAPSHOT (Aggregated)
Coverage timestamp: Tue Feb 15 2011 04:04:07 EST
../../../../../img/srcFileCovDistChart7.png 38% of files have more coverage
137   372   65   13.7
84   337   0.47   10
10     6.5  
1    
 
  MetadataServiceDictionaryValidator       Line # 36 137 0% 65 90 61% 0.6103896
 
  (1)
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15    package org.kuali.student.lum.ui;
16   
17    import java.util.ArrayList;
18    import java.util.List;
19    import java.util.Map;
20   
21    import org.kuali.student.core.assembly.data.Data;
22    import org.kuali.student.core.assembly.data.LookupMetadata;
23    import org.kuali.student.core.assembly.data.LookupParamMetadata;
24    import org.kuali.student.core.assembly.data.LookupResultMetadata;
25    import org.kuali.student.core.assembly.data.Metadata;
26    import org.kuali.student.core.personsearch.service.impl.QuickViewByGivenNameSearchTypeCreator;
27    import org.kuali.student.core.search.dto.CrossSearchTypeInfo;
28    import org.kuali.student.core.search.dto.JoinResultMappingInfo;
29    import org.kuali.student.core.search.dto.QueryParamInfo;
30    import org.kuali.student.core.search.dto.ResultColumnInfo;
31    import org.kuali.student.core.search.dto.SearchTypeInfo;
32    import org.kuali.student.core.search.dto.SubSearchInfo;
33    import org.springframework.context.ApplicationContext;
34    import org.springframework.context.support.ClassPathXmlApplicationContext;
35   
 
36    public class MetadataServiceDictionaryValidator
37    {
38   
 
39  171 toggle private SearchTypeInfo getSearchTypeInfo (String searchType)
40    {
41  171 return this.getSearchInfoTypeMap ().get (searchType);
42    }
43    private Map<String, SearchTypeInfo> searchInfoTypeMap = null;
44   
 
45  171 toggle private Map<String, SearchTypeInfo> getSearchInfoTypeMap ()
46    {
47  171 if (this.searchInfoTypeMap != null)
48    {
49  170 return this.searchInfoTypeMap;
50    }
51  1 String[] searchConfigFiles =
52    {
53    "lu", "lo", "lrc", "proposal", "organization", "atp", "em"
54    };
55  8 for (int i = 0; i < searchConfigFiles.length; i ++)
56    {
57  7 System.out.println ("loading search configurations for "
58    + searchConfigFiles[i]);
59  7 ApplicationContext ac = new ClassPathXmlApplicationContext (
60    "classpath:" + searchConfigFiles[i] + "-search-config.xml");
61  7 if (searchInfoTypeMap == null)
62    {
63  1 searchInfoTypeMap = ac.getBeansOfType (SearchTypeInfo.class);
64    }
65    else
66    {
67  6 searchInfoTypeMap.putAll (ac.getBeansOfType (SearchTypeInfo.class));
68    }
69    }
70  1 SearchTypeInfo personSearchType =
71    new QuickViewByGivenNameSearchTypeCreator ().get ();
72  1 searchInfoTypeMap.put (personSearchType.getKey (), personSearchType);
73   
74  1 return searchInfoTypeMap;
75    }
76   
 
77  1165 toggle public List<String> validateMetadata (Metadata md, String name, String type)
78    {
79  1165 List<String> errors = new ArrayList ();
80  1165 if (md.getInitialLookup () != null && md.getInitialLookup ().getSearchTypeId () != null)
81    {
82  104 errors.addAll (validateLookup (md.getInitialLookup (), name, type, "initial"));
83    }
84  1165 if (md.getAdditionalLookups () != null)
85    {
86  1165 for (LookupMetadata lookup : md.getAdditionalLookups ())
87    {
88  67 errors.addAll (validateLookup (lookup, name, type, "additional"));
89    }
90    }
91  1165 if (md.getDataType ().equals (Data.DataType.DATA))
92    {
93  187 if (md.getProperties () == null)
94    {
95  0 errors.add (buildErrorPrefix1 (name, type)
96    + " is of type DATA but it has null for it's properties");
97    }
98  187 else if (md.getProperties ().size () == 0)
99    {
100  6 errors.add (buildErrorPrefix1 (name, type)
101    + " is of type DATA but it has no properties");
102    }
103    }
104   
105  1165 if (md.getProperties () != null && md.getProperties ().size () != 0)
106    {
107  329 if ( ! (md.getDataType ().equals (Data.DataType.DATA)
108    || md.getDataType ().equals (Data.DataType.LIST)))
109    {
110  0 errors.add (buildErrorPrefix1 (name, type)
111    + " is NOT of type DATA or LIST but it does have properties");
112    }
113  329 for (String key : md.getProperties ().keySet ())
114    {
115  1134 Metadata childMd = md.getProperties ().get (key);
116  1134 errors.addAll (this.validateMetadata (childMd, name + "." + key, type));
117    }
118    }
119  1165 return errors;
120    }
121   
 
122  171 toggle private List<String> validateLookup (LookupMetadata lookup, String name,
123    String type, String lookupType)
124    {
125  171 System.out.println ("Validating lookup " + name + "(" + type + ") "
126    + lookupType);
127  171 List<String> errors = new ArrayList ();
128  171 SearchTypeInfo st = getSearchTypeInfo (lookup.getSearchTypeId ());
129  171 if (st == null)
130    {
131  0 errors.add (buildErrorPrefix3 (lookup, name, type, lookupType)
132    + " that has an underlying search type "
133    + lookup.getSearchTypeId ()
134    + " that does not exist");
135  0 return errors;
136    }
137  171 if (lookup.getResultDisplayKey () != null)
138    {
139  171 String key = lookup.getResultDisplayKey ().trim ();
140  171 if ( ! key.equals (""))
141    {
142  171 ResultColumnInfo rc = findResultColumn (st, key);
143  171 if (rc == null)
144    {
145  0 errors.add (buildErrorPrefix3 (lookup, name, type, lookupType)
146    + " that has a result display column " + key
147    + " that does not exist in the underlying search "
148    + lookup.getSearchTypeId ());
149    }
150    }
151    }
152  171 if (lookup.getResultReturnKey () != null)
153    {
154  171 String key = lookup.getResultReturnKey ().trim ();
155  171 if (( ! key.equals ("")))
156    {
157  171 ResultColumnInfo rc = findResultColumn (st, key);
158  171 if (rc == null)
159    {
160  0 errors.add (buildErrorPrefix3 (lookup, name, type, lookupType)
161    + " that has a result return key " + key
162    + " that does not exist in the underlying search "
163    + lookup.getSearchTypeId ());
164    }
165    }
166    }
167  171 if (lookup.getResultSortKey () != null)
168    {
169  171 String key = lookup.getResultSortKey ().trim ();
170  171 if ( ! key.equals (""))
171    {
172  113 ResultColumnInfo rc = findResultColumn (st, key);
173  113 if (rc == null)
174    {
175  0 errors.add (buildErrorPrefix3 (lookup, name, type, lookupType)
176    + " that has a result sort key " + key
177    + " that does not exist in the underlying search "
178    + lookup.getSearchTypeId ());
179    }
180    }
181    }
182    // check params
183  171 for (LookupParamMetadata param : lookup.getParams ())
184    {
185  507 QueryParamInfo qp = findQueryParam (st, param.getKey ());
186  507 if (qp == null)
187    {
188  0 errors.add (buildErrorPrefix3 (lookup, name, type, lookupType)
189    + " that has a parameter " + param.getKey ()
190    + " that does not exist in the underlying search "
191    + lookup.getSearchTypeId ());
192  0 continue;
193    }
194  507 if ( ! dataTypeMatches (qp.getFieldDescriptor ().getDataType (),
195    param.getDataType ()))
196    {
197  0 errors.add (buildErrorPrefix3 (lookup, name, type, lookupType)
198    + " that has a parameter " + param.getKey ()
199    + " that who's datatype does not match the underlying parameter "
200    + qp.getFieldDescriptor ().getDataType () + " vs. "
201    + param.getDataType ());
202  0 continue;
203    }
204    }
205    // check results
206  171 for (LookupResultMetadata result : lookup.getResults ())
207    {
208  548 ResultColumnInfo rc = findResultColumn (st, result.getKey ());
209  548 if (rc == null)
210    {
211  0 errors.add (buildErrorPrefix3 (lookup, name, type, lookupType)
212    + " that has a result column " + result.getKey ()
213    + " that does not exist in the underlying search "
214    + lookup.getSearchTypeId ());
215  0 continue;
216    }
217  548 if ( ! dataTypeMatches (rc.getDataType (),
218    result.getDataType ()))
219    {
220  0 errors.add (buildErrorPrefix3 (lookup, name, type, lookupType)
221    + " that has a result column " + result.getKey ()
222    + " that who's datatype does not match the underlying result column "
223    + rc.getDataType () + " vs. "
224    + result.getDataType ());
225  0 continue;
226    }
227    }
228  171 return errors;
229    }
230   
 
231  1055 toggle private boolean dataTypeMatches (String qp, Data.DataType dt)
232    {
233  1055 if (dt == null)
234    {
235  137 dt = Data.DataType.STRING;
236    }
237  1055 if (qp == null)
238    {
239  11 qp = "string";
240    }
241  1055 switch (dt)
242    {
243  989 case STRING:
244  989 if (qp.equalsIgnoreCase ("string"))
245    {
246  989 return true;
247    }
248  0 if (qp == null)
249    {
250  0 return true;
251    }
252  0 return false;
253  2 case INTEGER:
254  2 if (qp.equalsIgnoreCase ("int"))
255    {
256  2 return true;
257    }
258  0 return false;
259  0 case LONG:
260  0 case FLOAT:
261  0 case DOUBLE:
262  18 case BOOLEAN:
263  18 if (qp.equalsIgnoreCase ("boolean"))
264    {
265  18 return true;
266    }
267  0 return false;
268  20 case DATE:
269  26 case TRUNCATED_DATE:
270  46 if (qp.equalsIgnoreCase ("date"))
271    {
272  42 return true;
273    }
274  4 if (qp.equalsIgnoreCase ("dateTime"))
275    {
276  4 return true;
277    }
278  0 return false;
279  0 case DATA:
280  0 if (qp.equalsIgnoreCase ("complex"))
281    {
282  0 return true;
283    }
284  0 return false;
285  0 case LIST:
286  0 return true;
287    }
288  0 return true;
289    }
290   
 
291  1003 toggle private ResultColumnInfo findResultColumn (SearchTypeInfo st, String paramKey)
292    {
293  1003 for (ResultColumnInfo rc : st.getSearchResultTypeInfo ().getResultColumns ())
294    {
295  3224 if (rc.getKey ().equals (paramKey))
296    {
297  1003 return rc;
298    }
299    }
300  0 if (st instanceof CrossSearchTypeInfo)
301    {
302    // System.out.println (
303    // "CROSS SEARCH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
304  0 CrossSearchTypeInfo cst = (CrossSearchTypeInfo) st;
305  0 if (cst.getJoinResultMappings () != null)
306    {
307  0 for (JoinResultMappingInfo jrm : cst.getJoinResultMappings ())
308    {
309  0 if (jrm.getResultParam ().equalsIgnoreCase (paramKey))
310    {
311  0 for (SubSearchInfo ss : cst.getSubSearches ())
312    {
313  0 if (ss.getKey ().equalsIgnoreCase (jrm.getSubSearchKey ()))
314    {
315  0 SearchTypeInfo subSearchType = this.getSearchTypeInfo (
316    ss.getSearchkey ());
317  0 if (subSearchType == null)
318    {
319  0 return null;
320    }
321  0 ResultColumnInfo rc = findResultColumn (subSearchType, jrm.getSubSearchResultParam ());
322  0 if (rc == null)
323    {
324  0 throw new RuntimeException ("Cross-Search " + st.getKey () + " is not configured properly "
325    + jrm.getSubSearchResultParam () + " is not defined as a result in the subSearchTyp e" + ss.getSearchkey ());
326    }
327    }
328    }
329    }
330    }
331    }
332    }
333  0 return null;
334    }
335   
 
336  507 toggle private QueryParamInfo findQueryParam (SearchTypeInfo st, String paramKey)
337    {
338  507 for (QueryParamInfo qp : st.getSearchCriteriaTypeInfo ().getQueryParams ())
339    {
340  2356 if (qp.getKey ().equals (paramKey))
341    {
342  507 return qp;
343    }
344    }
345  0 return null;
346    }
347   
 
348  0 toggle private String buildErrorPrefix3 (LookupMetadata lookup, String name,
349    String type, String lookupType)
350    {
351  0 return buildErrorPrefix2 (name, type, lookupType) + ": " + lookup.getId ();
352    }
353   
 
354  0 toggle private String buildErrorPrefix2 (String name, String type, String lookupType)
355    {
356  0 String msg = buildErrorPrefix1 (name, type);
357  0 msg += " has an " + lookupType + " lookup ";
358  0 return msg;
359    }
360   
 
361  6 toggle private String buildErrorPrefix1 (String name, String type)
362    {
363  6 String msg = name;
364  6 if (type != null)
365    {
366  0 msg += " with type " + type;
367    }
368    // System.out.println ("buildErrorPrefix called for " + msg);
369    // new RuntimeException ().printStackTrace ();
370  6 return msg;
371    }
372    }