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 | 0 | private StringBuilder builder = new StringBuilder (5000); |
14 | |
private ObjectStructureDefinition os; |
15 | 0 | private String rowSeperator = "\n"; |
16 | 0 | private String colSeperator = "|"; |
17 | |
private Map<String, SearchTypeInfo> searchInfoTypeMap; |
18 | |
|
19 | |
|
20 | |
private Map<String, String> queryMap; |
21 | |
|
22 | |
public SearchConfigFormatter (Map<String, SearchTypeInfo> searchInfoTypeMap, |
23 | |
Map<String, String> queryMap) |
24 | 0 | { |
25 | 0 | this.searchInfoTypeMap = searchInfoTypeMap; |
26 | 0 | this.queryMap = queryMap; |
27 | 0 | } |
28 | |
|
29 | |
public String getRowSeperator () |
30 | |
{ |
31 | 0 | return rowSeperator; |
32 | |
} |
33 | |
|
34 | |
public void setRowSeperator (String rowSeperator) |
35 | |
{ |
36 | 0 | this.rowSeperator = rowSeperator; |
37 | 0 | } |
38 | |
|
39 | |
public String getColSeparator () |
40 | |
{ |
41 | 0 | return colSeperator; |
42 | |
} |
43 | |
|
44 | |
public void setColSeparator (String separator) |
45 | |
{ |
46 | 0 | this.colSeperator = separator; |
47 | 0 | } |
48 | |
|
49 | |
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 | |
public String formatForWiki () |
61 | |
{ |
62 | 0 | for (String name : this.searchInfoTypeMap.keySet ()) |
63 | |
{ |
64 | 0 | formatSearchType (name, this.searchInfoTypeMap.get (name)); |
65 | |
} |
66 | |
|
67 | 0 | return builder.toString (); |
68 | |
} |
69 | |
|
70 | |
private void formatSearchType (String name, SearchTypeInfo st) |
71 | |
{ |
72 | 0 | builder.append (rowSeperator); |
73 | 0 | builder.append ("h1. " + st.getName () + " (" + name + ")"); |
74 | 0 | builder.append ("{anchor:" + name + "}"); |
75 | 0 | builder.append (rowSeperator); |
76 | 0 | builder.append (colSeperator); |
77 | 0 | builder.append ("*Search Type Key*"); |
78 | 0 | builder.append (colSeperator); |
79 | 0 | builder.append (st.getKey ()); |
80 | 0 | builder.append (colSeperator); |
81 | 0 | builder.append (rowSeperator); |
82 | 0 | builder.append (colSeperator); |
83 | 0 | builder.append ("*Name*"); |
84 | 0 | builder.append (colSeperator); |
85 | 0 | builder.append (st.getName ()); |
86 | 0 | builder.append (colSeperator); |
87 | 0 | builder.append (rowSeperator); |
88 | 0 | builder.append (colSeperator); |
89 | 0 | builder.append ("*Description*"); |
90 | 0 | builder.append (colSeperator); |
91 | 0 | builder.append (st.getDesc ()); |
92 | 0 | builder.append (colSeperator); |
93 | 0 | builder.append (rowSeperator); |
94 | |
|
95 | 0 | builder.append (rowSeperator); |
96 | 0 | builder.append ("h2. " |
97 | |
+ st.getSearchCriteriaTypeInfo ().getQueryParams ().size () |
98 | |
+ " Possible Search Criteria"); |
99 | 0 | builder.append (rowSeperator); |
100 | 0 | builder.append (colSeperator); |
101 | 0 | builder.append ("*Type Key*"); |
102 | 0 | builder.append (colSeperator); |
103 | 0 | builder.append (st.getSearchCriteriaTypeInfo ().getKey ()); |
104 | 0 | builder.append (colSeperator); |
105 | 0 | builder.append (rowSeperator); |
106 | 0 | builder.append (colSeperator); |
107 | 0 | builder.append ("*Name*"); |
108 | 0 | builder.append (colSeperator); |
109 | 0 | builder.append (st.getSearchCriteriaTypeInfo ().getName ()); |
110 | 0 | builder.append (colSeperator); |
111 | 0 | builder.append (rowSeperator); |
112 | 0 | builder.append (colSeperator); |
113 | 0 | builder.append ("*Description*"); |
114 | 0 | builder.append (colSeperator); |
115 | 0 | builder.append (st.getSearchCriteriaTypeInfo ().getDesc ()); |
116 | 0 | builder.append (colSeperator); |
117 | 0 | builder.append (rowSeperator); |
118 | |
|
119 | |
|
120 | 0 | builder.append (rowSeperator); |
121 | 0 | builder.append (colSeperator); |
122 | 0 | builder.append (colSeperator); |
123 | 0 | builder.append ("Name"); |
124 | 0 | builder.append (colSeperator); |
125 | 0 | builder.append (colSeperator); |
126 | 0 | builder.append ("Optional"); |
127 | 0 | builder.append (colSeperator); |
128 | 0 | builder.append (colSeperator); |
129 | 0 | builder.append ("DataType"); |
130 | 0 | builder.append (colSeperator); |
131 | 0 | builder.append (colSeperator); |
132 | 0 | builder.append ("Read Only"); |
133 | 0 | builder.append (colSeperator); |
134 | 0 | builder.append (colSeperator); |
135 | 0 | builder.append ("Type Key"); |
136 | 0 | builder.append (colSeperator); |
137 | 0 | builder.append (colSeperator); |
138 | 0 | builder.append ("Implementation"); |
139 | 0 | builder.append (colSeperator); |
140 | 0 | builder.append (colSeperator); |
141 | 0 | builder.append (rowSeperator); |
142 | 0 | for (QueryParamInfo qp : st.getSearchCriteriaTypeInfo ().getQueryParams ()) |
143 | |
{ |
144 | 0 | builder.append (colSeperator); |
145 | 0 | builder.append (qp.getFieldDescriptor ().getName ()); |
146 | 0 | builder.append (colSeperator); |
147 | 0 | builder.append (qp.isOptional ()); |
148 | 0 | builder.append (colSeperator); |
149 | 0 | builder.append (qp.getFieldDescriptor ().getDataType ()); |
150 | 0 | builder.append (colSeperator); |
151 | 0 | builder.append (qp.getFieldDescriptor ().isReadOnly ()); |
152 | 0 | builder.append (colSeperator); |
153 | 0 | builder.append (qp.getKey ()); |
154 | 0 | builder.append (colSeperator); |
155 | 0 | builder.append ("{code:borderStyle=none}" + queryMap.get (qp.getKey ()) + "{code}"); |
156 | 0 | builder.append (colSeperator); |
157 | 0 | builder.append (rowSeperator); |
158 | |
} |
159 | |
|
160 | |
|
161 | 0 | builder.append (rowSeperator); |
162 | 0 | builder.append ("h2. " |
163 | |
+ st.getSearchResultTypeInfo ().getResultColumns ().size () |
164 | |
+ " Result Columns Returned"); |
165 | 0 | builder.append (rowSeperator); |
166 | 0 | builder.append (colSeperator); |
167 | 0 | builder.append ("*Type Key*"); |
168 | 0 | builder.append (colSeperator); |
169 | 0 | builder.append (st.getSearchResultTypeInfo ().getKey ()); |
170 | 0 | builder.append (colSeperator); |
171 | 0 | builder.append (rowSeperator); |
172 | 0 | builder.append (colSeperator); |
173 | 0 | builder.append ("*Name*"); |
174 | 0 | builder.append (colSeperator); |
175 | 0 | builder.append (st.getSearchResultTypeInfo ().getName ()); |
176 | 0 | builder.append (colSeperator); |
177 | 0 | builder.append (rowSeperator); |
178 | 0 | builder.append (colSeperator); |
179 | 0 | builder.append ("*Description*"); |
180 | 0 | builder.append (colSeperator); |
181 | 0 | builder.append (st.getSearchResultTypeInfo ().getDesc ()); |
182 | 0 | builder.append (colSeperator); |
183 | 0 | builder.append (rowSeperator); |
184 | |
|
185 | |
|
186 | 0 | builder.append (rowSeperator); |
187 | 0 | builder.append (colSeperator); |
188 | 0 | builder.append (colSeperator); |
189 | 0 | builder.append ("Name"); |
190 | 0 | builder.append (colSeperator); |
191 | 0 | builder.append (colSeperator); |
192 | 0 | builder.append ("DataType"); |
193 | 0 | builder.append (colSeperator); |
194 | 0 | builder.append (colSeperator); |
195 | 0 | builder.append ("Type Key"); |
196 | 0 | builder.append (colSeperator); |
197 | 0 | builder.append (colSeperator); |
198 | 0 | builder.append (rowSeperator); |
199 | 0 | for (ResultColumnInfo rc : st.getSearchResultTypeInfo ().getResultColumns ()) |
200 | |
{ |
201 | 0 | builder.append (colSeperator); |
202 | 0 | builder.append (rc.getName ()); |
203 | 0 | builder.append (colSeperator); |
204 | 0 | builder.append (rc.getDataType ()); |
205 | 0 | builder.append (colSeperator); |
206 | 0 | builder.append (rc.getKey ()); |
207 | 0 | builder.append (colSeperator); |
208 | 0 | builder.append (rowSeperator); |
209 | |
} |
210 | |
|
211 | |
|
212 | 0 | builder.append (rowSeperator); |
213 | 0 | builder.append ("h2. JPQL Implementation"); |
214 | 0 | builder.append (rowSeperator); |
215 | 0 | builder.append ("{code}"); |
216 | 0 | builder.append (rowSeperator); |
217 | 0 | builder.append (queryMap.get (st.getKey ())); |
218 | 0 | builder.append (rowSeperator); |
219 | 0 | builder.append ("{code}"); |
220 | 0 | builder.append (rowSeperator); |
221 | 0 | } |
222 | |
|
223 | |
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 | |
case '\\': |
230 | |
case '[': |
231 | |
case '*': |
232 | |
case ']': |
233 | |
case '|': |
234 | 0 | if (!precededByBackSlash) { |
235 | 0 | bldr.append('\\'); |
236 | |
} |
237 | |
break; |
238 | |
default: |
239 | |
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 | |
} |