Clover Coverage Report - KS Common 1.2-M1-SNAPSHOT (Aggregated)
Coverage timestamp: Fri Mar 4 2011 04:39:34 EST
../../../../../../../img/srcFileCovDistChart8.png 26% of files have more coverage
166   251   18   18.44
8   225   0.11   9
9     2  
1    
 
  SearchConfigFormatter       Line # 10 166 0% 18 43 76.5% 0.76502734
 
  (2)
 
1    package org.kuali.student.common.search.service.impl;
2   
3    import java.util.Map;
4   
5    import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition;
6    import org.kuali.student.common.search.dto.QueryParamInfo;
7    import org.kuali.student.common.search.dto.ResultColumnInfo;
8    import org.kuali.student.common.search.dto.SearchTypeInfo;
9   
 
10    public class SearchConfigFormatter
11    {
12   
13    private StringBuilder builder = new StringBuilder (5000);
14    private ObjectStructureDefinition os;
15    private String rowSeperator = "\n";
16    private String colSeperator = "|";
17    private Map<String, SearchTypeInfo> searchInfoTypeMap;
18    // private Map<String, SearchCriteriaTypeInfo> searchCriteriaTypeMap;
19    // private Map<String, SearchResultTypeInfo> searchResultTypeInfoMap;
20    private Map<String, String> queryMap;
21   
 
22  8 toggle public SearchConfigFormatter (Map<String, SearchTypeInfo> searchInfoTypeMap,
23    Map<String, String> queryMap)
24    {
25  8 this.searchInfoTypeMap = searchInfoTypeMap;
26  8 this.queryMap = queryMap;
27    }
28   
 
29  0 toggle public String getRowSeperator ()
30    {
31  0 return rowSeperator;
32    }
33   
 
34  0 toggle public void setRowSeperator (String rowSeperator)
35    {
36  0 this.rowSeperator = rowSeperator;
37    }
38   
 
39  0 toggle public String getColSeparator ()
40    {
41  0 return colSeperator;
42    }
43   
 
44  0 toggle public void setColSeparator (String separator)
45    {
46  0 this.colSeperator = separator;
47    }
48   
 
49  0 toggle private String pad (String str, int size)
50    {
51  0 StringBuilder padStr = new StringBuilder (size);
52  0 padStr.append (str);
53  0 while (padStr.length () < size)
54    {
55  0 padStr.append (' ');
56    }
57  0 return padStr.toString ();
58    }
59   
 
60  8 toggle public String formatForWiki ()
61    {
62  8 for (String name : this.searchInfoTypeMap.keySet ())
63    {
64  59 formatSearchType (name, this.searchInfoTypeMap.get (name));
65    }
66   
67  8 return builder.toString ();
68    }
69   
 
70  59 toggle private void formatSearchType (String name, SearchTypeInfo st)
71    {
72  59 builder.append (rowSeperator);
73  59 builder.append ("h1. " + st.getName () + " (" + name + ")");
74  59 builder.append ("{anchor:" + name + "}");
75  59 builder.append (rowSeperator);
76  59 builder.append (colSeperator);
77  59 builder.append ("*Search Type Key*");
78  59 builder.append (colSeperator);
79  59 builder.append (st.getKey ());
80  59 builder.append (colSeperator);
81  59 builder.append (rowSeperator);
82  59 builder.append (colSeperator);
83  59 builder.append ("*Name*");
84  59 builder.append (colSeperator);
85  59 builder.append (st.getName ());
86  59 builder.append (colSeperator);
87  59 builder.append (rowSeperator);
88  59 builder.append (colSeperator);
89  59 builder.append ("*Description*");
90  59 builder.append (colSeperator);
91  59 builder.append (st.getDesc ());
92  59 builder.append (colSeperator);
93  59 builder.append (rowSeperator);
94   
95  59 builder.append (rowSeperator);
96  59 builder.append ("h2. "
97    + st.getSearchCriteriaTypeInfo ().getQueryParams ().size ()
98    + " Possible Search Criteria");
99  59 builder.append (rowSeperator);
100  59 builder.append (colSeperator);
101  59 builder.append ("*Type Key*");
102  59 builder.append (colSeperator);
103  59 builder.append (st.getSearchCriteriaTypeInfo ().getKey ());
104  59 builder.append (colSeperator);
105  59 builder.append (rowSeperator);
106  59 builder.append (colSeperator);
107  59 builder.append ("*Name*");
108  59 builder.append (colSeperator);
109  59 builder.append (st.getSearchCriteriaTypeInfo ().getName ());
110  59 builder.append (colSeperator);
111  59 builder.append (rowSeperator);
112  59 builder.append (colSeperator);
113  59 builder.append ("*Description*");
114  59 builder.append (colSeperator);
115  59 builder.append (st.getSearchCriteriaTypeInfo ().getDesc ());
116  59 builder.append (colSeperator);
117  59 builder.append (rowSeperator);
118   
119    // criteria table
120  59 builder.append (rowSeperator);
121  59 builder.append (colSeperator);
122  59 builder.append (colSeperator);
123  59 builder.append ("Name");
124  59 builder.append (colSeperator);
125  59 builder.append (colSeperator);
126  59 builder.append ("Optional");
127  59 builder.append (colSeperator);
128  59 builder.append (colSeperator);
129  59 builder.append ("DataType");
130  59 builder.append (colSeperator);
131  59 builder.append (colSeperator);
132  59 builder.append ("Read Only");
133  59 builder.append (colSeperator);
134  59 builder.append (colSeperator);
135  59 builder.append ("Type Key");
136  59 builder.append (colSeperator);
137  59 builder.append (colSeperator);
138  59 builder.append ("Implementation");
139  59 builder.append (colSeperator);
140  59 builder.append (colSeperator);
141  59 builder.append (rowSeperator);
142  59 for (QueryParamInfo qp : st.getSearchCriteriaTypeInfo ().getQueryParams ())
143    {
144  193 builder.append (colSeperator);
145  193 builder.append (qp.getFieldDescriptor ().getName ());
146  193 builder.append (colSeperator);
147  193 builder.append (qp.isOptional ());
148  193 builder.append (colSeperator);
149  193 builder.append (qp.getFieldDescriptor ().getDataType ());
150  193 builder.append (colSeperator);
151  193 builder.append (qp.getFieldDescriptor ().isReadOnly ());
152  193 builder.append (colSeperator);
153  193 builder.append (qp.getKey ());
154  193 builder.append (colSeperator);
155  193 builder.append ("{code:borderStyle=none}" + queryMap.get (qp.getKey ()) + "{code}");
156  193 builder.append (colSeperator);
157  193 builder.append (rowSeperator);
158    }
159   
160   
161  59 builder.append (rowSeperator);
162  59 builder.append ("h2. "
163    + st.getSearchResultTypeInfo ().getResultColumns ().size ()
164    + " Result Columns Returned");
165  59 builder.append (rowSeperator);
166  59 builder.append (colSeperator);
167  59 builder.append ("*Type Key*");
168  59 builder.append (colSeperator);
169  59 builder.append (st.getSearchResultTypeInfo ().getKey ());
170  59 builder.append (colSeperator);
171  59 builder.append (rowSeperator);
172  59 builder.append (colSeperator);
173  59 builder.append ("*Name*");
174  59 builder.append (colSeperator);
175  59 builder.append (st.getSearchResultTypeInfo ().getName ());
176  59 builder.append (colSeperator);
177  59 builder.append (rowSeperator);
178  59 builder.append (colSeperator);
179  59 builder.append ("*Description*");
180  59 builder.append (colSeperator);
181  59 builder.append (st.getSearchResultTypeInfo ().getDesc ());
182  59 builder.append (colSeperator);
183  59 builder.append (rowSeperator);
184   
185    // results table
186  59 builder.append (rowSeperator);
187  59 builder.append (colSeperator);
188  59 builder.append (colSeperator);
189  59 builder.append ("Name");
190  59 builder.append (colSeperator);
191  59 builder.append (colSeperator);
192  59 builder.append ("DataType");
193  59 builder.append (colSeperator);
194  59 builder.append (colSeperator);
195  59 builder.append ("Type Key");
196  59 builder.append (colSeperator);
197  59 builder.append (colSeperator);
198  59 builder.append (rowSeperator);
199  59 for (ResultColumnInfo rc : st.getSearchResultTypeInfo ().getResultColumns ())
200    {
201  260 builder.append (colSeperator);
202  260 builder.append (rc.getName ());
203  260 builder.append (colSeperator);
204  260 builder.append (rc.getDataType ());
205  260 builder.append (colSeperator);
206  260 builder.append (rc.getKey ());
207  260 builder.append (colSeperator);
208  260 builder.append (rowSeperator);
209    }
210   
211    // impl
212  59 builder.append (rowSeperator);
213  59 builder.append ("h2. JPQL Implementation");
214  59 builder.append (rowSeperator);
215  59 builder.append ("{code}");
216  59 builder.append (rowSeperator);
217  59 builder.append (queryMap.get (st.getKey ()));
218  59 builder.append (rowSeperator);
219  59 builder.append ("{code}");
220  59 builder.append (rowSeperator);
221    }
222   
 
223  0 toggle private String escapeWiki(String str) {
224  0 StringBuilder bldr = new StringBuilder(str.length());
225  0 boolean precededByBackSlash = false;
226  0 for (int i = 0; i < str.length(); i++) {
227  0 char c = str.charAt(i);
228  0 switch (c) {
229  0 case '\\':
230  0 case '[':
231  0 case '*':
232  0 case ']':
233  0 case '|':
234  0 if (!precededByBackSlash) {
235  0 bldr.append('\\');
236    }
237  0 break;
238  0 default:
239  0 break;
240    }
241  0 bldr.append(c);
242  0 if (c == '\\') {
243  0 precededByBackSlash = true;
244    } else {
245  0 precededByBackSlash = false;
246    }
247    }
248  0 return bldr.toString();
249    }
250   
251    }