| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.student.contract.writer.search; |
| 17 |
|
|
| 18 |
|
import org.kuali.student.contract.model.SearchCriteria; |
| 19 |
|
import org.kuali.student.contract.model.SearchCriteriaParameter; |
| 20 |
|
import org.kuali.student.contract.model.SearchImplementation; |
| 21 |
|
import org.kuali.student.contract.model.SearchModel; |
| 22 |
|
import org.kuali.student.contract.model.SearchResult; |
| 23 |
|
import org.kuali.student.contract.model.SearchResultColumn; |
| 24 |
|
import org.kuali.student.contract.model.SearchType; |
| 25 |
|
import org.kuali.student.contract.model.validation.DictionaryValidationException; |
| 26 |
|
import org.kuali.student.contract.model.validation.SearchModelValidator; |
| 27 |
|
import org.kuali.student.contract.writer.XmlWriter; |
| 28 |
|
import java.io.PrintStream; |
| 29 |
|
import java.util.ArrayList; |
| 30 |
|
import java.util.Collection; |
| 31 |
|
import java.util.Date; |
| 32 |
|
import java.util.HashSet; |
| 33 |
|
import java.util.List; |
| 34 |
|
import java.util.Set; |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
@author |
| 39 |
|
|
|
|
|
| 0% |
Uncovered Elements: 171 (171) |
Complexity: 31 |
Complexity Density: 0.23 |
|
| 40 |
|
public class SearchModelWriter { |
| 41 |
|
|
| 42 |
|
private SearchModel model; |
| 43 |
|
private XmlWriter writer; |
| 44 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 45 |
0
|
public SearchModelWriter(PrintStream out, SearchModel model) {... |
| 46 |
0
|
this.writer = new XmlWriter(out, 0); |
| 47 |
0
|
this.model = model; |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
@param |
| 53 |
|
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 2 |
Complexity Density: 0.11 |
|
| 54 |
0
|
public void write() {... |
| 55 |
0
|
Collection<String> errors = new SearchModelValidator(model).validate(); |
| 56 |
0
|
if (errors.size() > 0) { |
| 57 |
0
|
StringBuffer buf = new StringBuffer(); |
| 58 |
0
|
buf.append(errors.size() |
| 59 |
|
+ " errors found while validating the spreadsheet."); |
| 60 |
0
|
int cnt = 0; |
| 61 |
0
|
for (String msg : errors) { |
| 62 |
0
|
cnt++; |
| 63 |
0
|
buf.append("\n"); |
| 64 |
0
|
buf.append("*error*" + cnt + ":" + msg); |
| 65 |
|
} |
| 66 |
0
|
throw new DictionaryValidationException(buf.toString()); |
| 67 |
|
} |
| 68 |
0
|
writeHeader(); |
| 69 |
0
|
writeSearchTypes(); |
| 70 |
0
|
writeSearchCriteria(); |
| 71 |
0
|
writeSearchCriteriaParameters(); |
| 72 |
0
|
writeSearchResultTypes(); |
| 73 |
0
|
writeSearchResultColumns(); |
| 74 |
0
|
writeSqlQueryMap(); |
| 75 |
0
|
writeFooter(); |
| 76 |
|
} |
| 77 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 78 |
0
|
private void indentPrint(String str) {... |
| 79 |
0
|
writer.indentPrintln(str); |
| 80 |
|
} |
| 81 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 82 |
0
|
private void indentPrintln(String str) {... |
| 83 |
0
|
writer.indentPrintln(str); |
| 84 |
|
} |
| 85 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 86 |
0
|
private void println(String str) {... |
| 87 |
0
|
writer.indentPrintln(str); |
| 88 |
|
} |
| 89 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 90 |
0
|
private void writeComment(String str) {... |
| 91 |
0
|
writer.writeComment(str); |
| 92 |
|
} |
| 93 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 94 |
0
|
private void incrementIndent() {... |
| 95 |
0
|
writer.incrementIndent(); |
| 96 |
|
} |
| 97 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 98 |
0
|
private void decrementIndent() {... |
| 99 |
0
|
writer.decrementIndent(); |
| 100 |
|
} |
| 101 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 102 |
0
|
private void writeTag(String tag, String value) {... |
| 103 |
0
|
writer.writeTag(tag, value); |
| 104 |
|
} |
| 105 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 106 |
0
|
private void writeAttribute(String attribute, String value) {... |
| 107 |
0
|
writer.writeAttribute(attribute, value); |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
|
@param |
| 113 |
|
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
|
| 114 |
0
|
protected void writeHeader() {... |
| 115 |
0
|
indentPrintln("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
| 116 |
0
|
indentPrintln("<beans xmlns=\"http://www.springframework.org/schema/beans\""); |
| 117 |
0
|
indentPrintln("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""); |
| 118 |
0
|
indentPrintln("xmlns:search=\"http://student.kuali.org/xsd/search-extension\""); |
| 119 |
0
|
indentPrintln("xmlns:dict=\"http://student.kuali.org/xsd/dictionary-extension\""); |
| 120 |
0
|
indentPrintln("xsi:schemaLocation=\""); |
| 121 |
0
|
indentPrintln("http://student.kuali.org/xsd/search-extension http://student.kuali.org/xsd/search-extension/search-extension.xsd"); |
| 122 |
0
|
indentPrintln("http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"); |
| 123 |
0
|
indentPrintln("\">"); |
| 124 |
0
|
StringBuffer buf = new StringBuffer(); |
| 125 |
0
|
buf.append("*** Automatically Generated ***"); |
| 126 |
0
|
buf.append("\n"); |
| 127 |
0
|
buf.append("on: " + (new Date())); |
| 128 |
0
|
buf.append("\n"); |
| 129 |
0
|
buf.append("by: " + this.getClass().getName()); |
| 130 |
0
|
buf.append("\n"); |
| 131 |
0
|
buf.append("using: "); |
| 132 |
0
|
String comma = ""; |
| 133 |
0
|
for (String soureName : model.getSourceNames()) { |
| 134 |
0
|
buf.append(soureName); |
| 135 |
0
|
buf.append(comma); |
| 136 |
0
|
comma = ", "; |
| 137 |
|
} |
| 138 |
0
|
buf.append("\n"); |
| 139 |
0
|
writeComment(buf.toString()); |
| 140 |
|
} |
| 141 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 142 |
0
|
protected void writeFooter() {... |
| 143 |
0
|
indentPrintln("</beans>"); |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
@param |
| 149 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 150 |
0
|
protected void writeSearchTypes() {... |
| 151 |
0
|
println(""); |
| 152 |
0
|
writeComment("Search Types"); |
| 153 |
0
|
for (SearchType st : model.getSearchTypes()) { |
| 154 |
0
|
new SearchTypeWriter(writer.getOut(), writer.getIndent() + 1, st).write(); |
| 155 |
|
} |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
@param |
| 161 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 162 |
0
|
protected void writeSearchResultTypes() {... |
| 163 |
0
|
println(""); |
| 164 |
0
|
writeComment("Search Results"); |
| 165 |
0
|
for (SearchResult sr : getSearchResults()) { |
| 166 |
0
|
new SearchResultWriter(writer.getOut(), writer.getIndent() + 1, sr).write(); |
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
} |
| 170 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 171 |
0
|
private List<SearchResult> getSearchResults() {... |
| 172 |
0
|
List<SearchResult> list = new ArrayList(); |
| 173 |
0
|
Set<String> keys = new HashSet(); |
| 174 |
0
|
for (SearchType st : model.getSearchTypes()) { |
| 175 |
0
|
if (keys.add(st.getSearchResult().getKey())) { |
| 176 |
0
|
list.add(st.getSearchResult()); |
| 177 |
|
} |
| 178 |
|
} |
| 179 |
0
|
return list; |
| 180 |
|
} |
| 181 |
|
|
| 182 |
|
|
| 183 |
|
|
| 184 |
|
@param |
| 185 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 186 |
0
|
protected void writeSearchResultColumns() {... |
| 187 |
0
|
println(""); |
| 188 |
0
|
writeComment("Search Result Columns"); |
| 189 |
0
|
for (SearchResultColumn col : getSearchResultColumns()) { |
| 190 |
0
|
new SearchResultColumnWriter(writer.getOut(), writer.getIndent() + 1, col).write(); |
| 191 |
|
} |
| 192 |
|
} |
| 193 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 194 |
0
|
private List<SearchResultColumn> getSearchResultColumns() {... |
| 195 |
0
|
List<SearchResultColumn> list = new ArrayList(); |
| 196 |
0
|
Set<String> keys = new HashSet(); |
| 197 |
0
|
for (SearchResult searchResult : getSearchResults()) { |
| 198 |
0
|
for (SearchResultColumn col : searchResult.getResultColumns()) { |
| 199 |
0
|
if (keys.add(col.getKey())) { |
| 200 |
0
|
list.add(col); |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
} |
| 204 |
|
} |
| 205 |
0
|
return list; |
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
|
| 209 |
|
|
| 210 |
|
@param |
| 211 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 212 |
0
|
protected void writeSearchCriteria() {... |
| 213 |
0
|
println(""); |
| 214 |
0
|
writeComment("Search Criteria"); |
| 215 |
0
|
for (SearchCriteria sr : getSearchCriteria()) { |
| 216 |
0
|
new SearchCriteriaWriter(writer.getOut(), writer.getIndent() + 1, sr).write(); |
| 217 |
|
} |
| 218 |
|
} |
| 219 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 220 |
0
|
private List<SearchCriteria> getSearchCriteria() {... |
| 221 |
0
|
List<SearchCriteria> list = new ArrayList(); |
| 222 |
0
|
Set<String> keys = new HashSet(); |
| 223 |
0
|
for (SearchType st : model.getSearchTypes()) { |
| 224 |
0
|
if (keys.add(st.getSearchCriteria().getKey())) { |
| 225 |
0
|
list.add(st.getSearchCriteria()); |
| 226 |
|
} |
| 227 |
|
} |
| 228 |
0
|
return list; |
| 229 |
|
} |
| 230 |
|
|
| 231 |
|
|
| 232 |
|
|
| 233 |
|
@param |
| 234 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 235 |
0
|
protected void writeSearchCriteriaParameters() {... |
| 236 |
0
|
println(""); |
| 237 |
0
|
writeComment("Search Criteria Parameters"); |
| 238 |
0
|
for (SearchCriteriaParameter col : getSearchCriteriaParameters()) { |
| 239 |
0
|
new SearchCriteriaParameterWriter(writer.getOut(), writer.getIndent() + 1, col).write(); |
| 240 |
|
} |
| 241 |
|
} |
| 242 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 243 |
0
|
private List<SearchCriteriaParameter> getSearchCriteriaParameters() {... |
| 244 |
0
|
List<SearchCriteriaParameter> list = new ArrayList(); |
| 245 |
0
|
Set<String> keys = new HashSet(); |
| 246 |
0
|
for (SearchCriteria criteria : getSearchCriteria()) { |
| 247 |
0
|
for (SearchCriteriaParameter parm : criteria.getParameters()) { |
| 248 |
0
|
if (keys.add(parm.getKey())) { |
| 249 |
0
|
list.add(parm); |
| 250 |
|
} |
| 251 |
|
|
| 252 |
|
} |
| 253 |
|
} |
| 254 |
0
|
return list; |
| 255 |
|
} |
| 256 |
|
|
| 257 |
|
|
| 258 |
|
|
| 259 |
|
@param |
| 260 |
|
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
|
| 261 |
0
|
protected void writeSqlQueryMap() {... |
| 262 |
0
|
println(""); |
| 263 |
0
|
incrementIndent(); |
| 264 |
0
|
writeComment("Query Map"); |
| 265 |
0
|
indentPrintln("<bean id=\"queryMap\" class=\"org.springframework.beans.factory.config.MapFactoryBean\">"); |
| 266 |
0
|
indentPrintln("<property name=\"sourceMap\">"); |
| 267 |
0
|
indentPrintln("<map>"); |
| 268 |
0
|
incrementIndent(); |
| 269 |
0
|
for (SearchImplementation impl : getJPQLImplementations()) { |
| 270 |
0
|
println(""); |
| 271 |
0
|
indentPrint("<entry"); |
| 272 |
0
|
writeAttribute("key", impl.getKey()); |
| 273 |
0
|
indentPrintln(">"); |
| 274 |
0
|
writeComment(impl.getComments()); |
| 275 |
0
|
incrementIndent(); |
| 276 |
0
|
writeTag("value", "\n" + impl.getDescription() + "\n"); |
| 277 |
0
|
decrementIndent(); |
| 278 |
0
|
indentPrintln("</entry>"); |
| 279 |
|
} |
| 280 |
0
|
decrementIndent(); |
| 281 |
0
|
indentPrintln("</map>"); |
| 282 |
0
|
indentPrintln("</property>"); |
| 283 |
0
|
indentPrintln("</bean>"); |
| 284 |
0
|
decrementIndent(); |
| 285 |
|
} |
| 286 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 287 |
0
|
private List<SearchImplementation> getImplementations() {... |
| 288 |
0
|
List<SearchImplementation> list = new ArrayList(); |
| 289 |
0
|
Set<String> keys = new HashSet(); |
| 290 |
0
|
for (SearchType st : model.getSearchTypes()) { |
| 291 |
0
|
if (keys.add(st.getImplementation().getKey())) { |
| 292 |
0
|
list.add(st.getImplementation()); |
| 293 |
|
} |
| 294 |
|
} |
| 295 |
0
|
return list; |
| 296 |
|
} |
| 297 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 298 |
0
|
private List<SearchImplementation> getJPQLImplementations() {... |
| 299 |
0
|
List<SearchImplementation> list = new ArrayList(); |
| 300 |
0
|
Set<String> keys = new HashSet(); |
| 301 |
0
|
for (SearchImplementation impl : getImplementations()) { |
| 302 |
0
|
if (impl.getType().equals("JPQL")) { |
| 303 |
0
|
list.add(impl); |
| 304 |
|
} |
| 305 |
|
} |
| 306 |
0
|
return list; |
| 307 |
|
} |
| 308 |
|
} |