| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 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.common.assembly.data.Data; |
| 22 |
|
import org.kuali.student.common.assembly.data.LookupMetadata; |
| 23 |
|
import org.kuali.student.common.assembly.data.LookupParamMetadata; |
| 24 |
|
import org.kuali.student.common.assembly.data.LookupResultMetadata; |
| 25 |
|
import org.kuali.student.common.assembly.data.Metadata; |
| 26 |
|
import org.kuali.student.common.search.dto.CrossSearchTypeInfo; |
| 27 |
|
import org.kuali.student.common.search.dto.JoinResultMappingInfo; |
| 28 |
|
import org.kuali.student.common.search.dto.QueryParamInfo; |
| 29 |
|
import org.kuali.student.common.search.dto.ResultColumnInfo; |
| 30 |
|
import org.kuali.student.common.search.dto.SearchTypeInfo; |
| 31 |
|
import org.kuali.student.common.search.dto.SubSearchInfo; |
| 32 |
|
import org.kuali.student.core.personsearch.service.impl.QuickViewByGivenNameSearchTypeCreator; |
| 33 |
|
import org.springframework.context.ApplicationContext; |
| 34 |
|
import org.springframework.context.support.ClassPathXmlApplicationContext; |
| 35 |
|
|
|
|
|
| 71.9% |
Uncovered Elements: 65 (231) |
Complexity: 67 |
Complexity Density: 0.49 |
|
| 36 |
|
public class MetadataServiceDictionaryValidator { |
| 37 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 38 |
181
|
private SearchTypeInfo getSearchTypeInfo(String searchType) {... |
| 39 |
181
|
return this.getSearchInfoTypeMap().get(searchType); |
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
private Map<String, SearchTypeInfo> searchInfoTypeMap = null; |
| 43 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
| 44 |
181
|
@SuppressWarnings("unchecked")... |
| 45 |
|
private Map<String, SearchTypeInfo> getSearchInfoTypeMap() { |
| 46 |
181
|
if (this.searchInfoTypeMap != null) { |
| 47 |
180
|
return this.searchInfoTypeMap; |
| 48 |
|
} |
| 49 |
1
|
String[] searchConfigFiles = { "lu", "lo", "lrc", "proposal", "organization", "atp", "em" }; |
| 50 |
|
|
| 51 |
8
|
for (int i = 0; i < searchConfigFiles.length; i++) { |
| 52 |
7
|
System.out.println("loading search configurations for " |
| 53 |
|
+ searchConfigFiles[i]); |
| 54 |
7
|
ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:" + searchConfigFiles[i] + "-search-config.xml"); |
| 55 |
7
|
if (searchInfoTypeMap == null) { |
| 56 |
1
|
searchInfoTypeMap = ac.getBeansOfType(SearchTypeInfo.class); |
| 57 |
|
} else { |
| 58 |
6
|
searchInfoTypeMap.putAll(ac.getBeansOfType(SearchTypeInfo.class)); |
| 59 |
|
} |
| 60 |
|
} |
| 61 |
|
|
| 62 |
1
|
SearchTypeInfo personSearchType = new QuickViewByGivenNameSearchTypeCreator().get(); |
| 63 |
1
|
searchInfoTypeMap.put(personSearchType.getKey(), personSearchType); |
| 64 |
|
|
| 65 |
1
|
return searchInfoTypeMap; |
| 66 |
|
} |
| 67 |
|
|
|
|
|
| 84.4% |
Uncovered Elements: 5 (32) |
Complexity: 11 |
Complexity Density: 0.61 |
|
| 68 |
1182
|
public List<String> validateMetadata(Metadata md, String name, String type) {... |
| 69 |
1182
|
List<String> errors = new ArrayList<String>(); |
| 70 |
1182
|
if (md.getInitialLookup() != null && md.getInitialLookup().getSearchTypeId() != null) { |
| 71 |
116
|
errors.addAll(validateLookup(md.getInitialLookup(), name, type, |
| 72 |
|
"initial")); |
| 73 |
|
} |
| 74 |
1182
|
if (md.getAdditionalLookups() != null) { |
| 75 |
1182
|
for (LookupMetadata lookup : md.getAdditionalLookups()) { |
| 76 |
65
|
errors.addAll(validateLookup(lookup, name, type, "additional")); |
| 77 |
|
} |
| 78 |
|
} |
| 79 |
1182
|
if (md.getDataType().equals(Data.DataType.DATA)) { |
| 80 |
188
|
if (md.getProperties() == null) { |
| 81 |
0
|
errors |
| 82 |
|
.add(buildErrorPrefix1(name, type) |
| 83 |
|
+ " is of type DATA but it has null for it's properties"); |
| 84 |
188
|
} else if (md.getProperties().size() == 0) { |
| 85 |
6
|
errors.add(buildErrorPrefix1(name, type) |
| 86 |
|
+ " is of type DATA but it has no properties"); |
| 87 |
|
} |
| 88 |
|
} |
| 89 |
|
|
| 90 |
1182
|
if (md.getProperties() != null && md.getProperties().size() != 0) { |
| 91 |
330
|
if (!(md.getDataType().equals(Data.DataType.DATA) || md |
| 92 |
|
.getDataType().equals(Data.DataType.LIST))) { |
| 93 |
0
|
errors |
| 94 |
|
.add(buildErrorPrefix1(name, type) |
| 95 |
|
+ " is NOT of type DATA or LIST but it does have properties"); |
| 96 |
|
} |
| 97 |
330
|
for (String key : md.getProperties().keySet()) { |
| 98 |
1151
|
Metadata childMd = md.getProperties().get(key); |
| 99 |
1151
|
errors.addAll(this.validateMetadata(childMd, name + "." + key, |
| 100 |
|
type)); |
| 101 |
|
} |
| 102 |
|
} |
| 103 |
1182
|
return errors; |
| 104 |
|
} |
| 105 |
|
|
|
|
|
| 75.4% |
Uncovered Elements: 17 (69) |
Complexity: 17 |
Complexity Density: 0.41 |
|
| 106 |
181
|
private List<String> validateLookup(LookupMetadata lookup, String name,... |
| 107 |
|
String type, String lookupType) { |
| 108 |
181
|
System.out.println("Validating lookup " + name + "(" + type + ") " |
| 109 |
|
+ lookupType); |
| 110 |
181
|
List<String> errors = new ArrayList(); |
| 111 |
181
|
SearchTypeInfo st = getSearchTypeInfo(lookup.getSearchTypeId()); |
| 112 |
181
|
if (st == null) { |
| 113 |
3
|
errors.add(buildErrorPrefix3(lookup, name, type, lookupType) |
| 114 |
|
+ " that has an underlying search type " |
| 115 |
|
+ lookup.getSearchTypeId() + " that does not exist"); |
| 116 |
3
|
return errors; |
| 117 |
|
} |
| 118 |
178
|
if (lookup.getResultDisplayKey() != null) { |
| 119 |
178
|
String key = lookup.getResultDisplayKey().trim(); |
| 120 |
178
|
if (!key.equals("")) { |
| 121 |
178
|
ResultColumnInfo rc = findResultColumn(st, key); |
| 122 |
178
|
if (rc == null) { |
| 123 |
0
|
errors |
| 124 |
|
.add(buildErrorPrefix3(lookup, name, type, |
| 125 |
|
lookupType) |
| 126 |
|
+ " that has a result display column " |
| 127 |
|
+ key |
| 128 |
|
+ " that does not exist in the underlying search " |
| 129 |
|
+ lookup.getSearchTypeId()); |
| 130 |
|
} |
| 131 |
|
} |
| 132 |
|
} |
| 133 |
178
|
if (lookup.getResultReturnKey() != null) { |
| 134 |
178
|
String key = lookup.getResultReturnKey().trim(); |
| 135 |
178
|
if ((!key.equals(""))) { |
| 136 |
178
|
ResultColumnInfo rc = findResultColumn(st, key); |
| 137 |
178
|
if (rc == null) { |
| 138 |
0
|
errors |
| 139 |
|
.add(buildErrorPrefix3(lookup, name, type, |
| 140 |
|
lookupType) |
| 141 |
|
+ " that has a result return key " |
| 142 |
|
+ key |
| 143 |
|
+ " that does not exist in the underlying search " |
| 144 |
|
+ lookup.getSearchTypeId()); |
| 145 |
|
} |
| 146 |
|
} |
| 147 |
|
} |
| 148 |
178
|
if (lookup.getResultSortKey() != null) { |
| 149 |
178
|
String key = lookup.getResultSortKey().trim(); |
| 150 |
178
|
if (!key.equals("")) { |
| 151 |
119
|
ResultColumnInfo rc = findResultColumn(st, key); |
| 152 |
119
|
if (rc == null) { |
| 153 |
0
|
errors |
| 154 |
|
.add(buildErrorPrefix3(lookup, name, type, |
| 155 |
|
lookupType) |
| 156 |
|
+ " that has a result sort key " |
| 157 |
|
+ key |
| 158 |
|
+ " that does not exist in the underlying search " |
| 159 |
|
+ lookup.getSearchTypeId()); |
| 160 |
|
} |
| 161 |
|
} |
| 162 |
|
} |
| 163 |
|
|
| 164 |
178
|
for (LookupParamMetadata param : lookup.getParams()) { |
| 165 |
578
|
QueryParamInfo qp = findQueryParam(st, param.getKey()); |
| 166 |
578
|
if (qp == null && !(st instanceof CrossSearchTypeInfo)) { |
| 167 |
|
|
| 168 |
|
|
| 169 |
0
|
errors.add(buildErrorPrefix3(lookup, name, type, lookupType) |
| 170 |
|
+ " that has a parameter " + param.getKey() |
| 171 |
|
+ " that does not exist in the underlying search " |
| 172 |
|
+ lookup.getSearchTypeId()); |
| 173 |
0
|
continue; |
| 174 |
|
} |
| 175 |
|
|
| 176 |
578
|
if (qp != null && !dataTypeMatches(qp.getFieldDescriptor().getDataType(), param.getDataType())) { |
| 177 |
|
|
| 178 |
19
|
errors.add(buildErrorPrefix3(lookup, name, type, lookupType) |
| 179 |
|
+ " that has a parameter " |
| 180 |
|
+ param.getKey() |
| 181 |
|
+ " who's datatype does not match the underlying parameter " |
| 182 |
|
+ qp.getFieldDescriptor().getDataType() |
| 183 |
|
+ " vs. " + param.getDataType()); |
| 184 |
19
|
continue; |
| 185 |
|
} |
| 186 |
|
} |
| 187 |
|
|
| 188 |
178
|
for (LookupResultMetadata result : lookup.getResults()) { |
| 189 |
584
|
ResultColumnInfo rc = findResultColumn(st, result.getKey()); |
| 190 |
584
|
if (rc == null) { |
| 191 |
1
|
errors.add(buildErrorPrefix3(lookup, name, type, lookupType) |
| 192 |
|
+ " that has a result column " + result.getKey() |
| 193 |
|
+ " that does not exist in the underlying search " |
| 194 |
|
+ lookup.getSearchTypeId()); |
| 195 |
1
|
continue; |
| 196 |
|
} |
| 197 |
583
|
if (!dataTypeMatches(rc.getDataType(), result.getDataType())) { |
| 198 |
0
|
errors |
| 199 |
|
.add(buildErrorPrefix3(lookup, name, type, lookupType) |
| 200 |
|
+ " that has a result column " |
| 201 |
|
+ result.getKey() |
| 202 |
|
+ " who's datatype does not match the underlying result column " |
| 203 |
|
+ rc.getDataType() + " vs. " |
| 204 |
|
+ result.getDataType()); |
| 205 |
0
|
continue; |
| 206 |
|
} |
| 207 |
|
} |
| 208 |
178
|
return errors; |
| 209 |
|
} |
| 210 |
|
|
|
|
|
| 63% |
Uncovered Elements: 20 (54) |
Complexity: 20 |
Complexity Density: 0.56 |
|
| 211 |
1113
|
private boolean dataTypeMatches(String qp, Data.DataType dt) {... |
| 212 |
1113
|
if (dt == null) { |
| 213 |
151
|
dt = Data.DataType.STRING; |
| 214 |
|
} |
| 215 |
1113
|
if (qp == null) { |
| 216 |
14
|
qp = "string"; |
| 217 |
|
} |
| 218 |
1113
|
switch (dt) { |
| 219 |
1044
|
case STRING: |
| 220 |
1044
|
if (qp.equalsIgnoreCase("string")) { |
| 221 |
1025
|
return true; |
| 222 |
|
} |
| 223 |
19
|
if (qp == null) { |
| 224 |
0
|
return true; |
| 225 |
|
} |
| 226 |
19
|
return false; |
| 227 |
2
|
case INTEGER: |
| 228 |
2
|
if (qp.equalsIgnoreCase("int")) { |
| 229 |
2
|
return true; |
| 230 |
|
} |
| 231 |
0
|
return false; |
| 232 |
0
|
case LONG: |
| 233 |
0
|
case FLOAT: |
| 234 |
0
|
case DOUBLE: |
| 235 |
18
|
case BOOLEAN: |
| 236 |
18
|
if (qp.equalsIgnoreCase("boolean")) { |
| 237 |
18
|
return true; |
| 238 |
|
} |
| 239 |
0
|
return false; |
| 240 |
21
|
case DATE: |
| 241 |
28
|
case TRUNCATED_DATE: |
| 242 |
49
|
if (qp.equalsIgnoreCase("date")) { |
| 243 |
44
|
return true; |
| 244 |
|
} |
| 245 |
5
|
if (qp.equalsIgnoreCase("dateTime")) { |
| 246 |
5
|
return true; |
| 247 |
|
} |
| 248 |
0
|
return false; |
| 249 |
0
|
case DATA: |
| 250 |
0
|
if (qp.equalsIgnoreCase("complex")) { |
| 251 |
0
|
return true; |
| 252 |
|
} |
| 253 |
0
|
return false; |
| 254 |
0
|
case LIST: |
| 255 |
0
|
return true; |
| 256 |
|
} |
| 257 |
0
|
return true; |
| 258 |
|
} |
| 259 |
|
|
|
|
|
| 25.8% |
Uncovered Elements: 23 (31) |
Complexity: 8 |
Complexity Density: 0.47 |
|
| 260 |
1059
|
private ResultColumnInfo findResultColumn(SearchTypeInfo st, String paramKey) {... |
| 261 |
1059
|
for (ResultColumnInfo rc : st.getSearchResultTypeInfo() |
| 262 |
|
.getResultColumns()) { |
| 263 |
3669
|
if (rc.getKey().equals(paramKey)) { |
| 264 |
1058
|
return rc; |
| 265 |
|
} |
| 266 |
|
} |
| 267 |
1
|
if (st instanceof CrossSearchTypeInfo) { |
| 268 |
|
|
| 269 |
|
|
| 270 |
0
|
CrossSearchTypeInfo cst = (CrossSearchTypeInfo) st; |
| 271 |
0
|
if (cst.getJoinResultMappings() != null) { |
| 272 |
0
|
for (JoinResultMappingInfo jrm : cst.getJoinResultMappings()) { |
| 273 |
0
|
if (jrm.getResultParam().equalsIgnoreCase(paramKey)) { |
| 274 |
0
|
for (SubSearchInfo ss : cst.getSubSearches()) { |
| 275 |
0
|
if (ss.getKey().equalsIgnoreCase( |
| 276 |
|
jrm.getSubSearchKey())) { |
| 277 |
0
|
SearchTypeInfo subSearchType = this |
| 278 |
|
.getSearchTypeInfo(ss.getSearchkey()); |
| 279 |
0
|
if (subSearchType == null) { |
| 280 |
0
|
return null; |
| 281 |
|
} |
| 282 |
0
|
ResultColumnInfo rc = findResultColumn( |
| 283 |
|
subSearchType, jrm |
| 284 |
|
.getSubSearchResultParam()); |
| 285 |
0
|
if (rc == null) { |
| 286 |
0
|
throw new RuntimeException( |
| 287 |
|
"Cross-Search " |
| 288 |
|
+ st.getKey() |
| 289 |
|
+ " is not configured properly " |
| 290 |
|
+ jrm |
| 291 |
|
.getSubSearchResultParam() |
| 292 |
|
+ " is not defined as a result in the subSearchTyp e" |
| 293 |
|
+ ss.getSearchkey()); |
| 294 |
|
} |
| 295 |
|
} |
| 296 |
|
} |
| 297 |
|
} |
| 298 |
|
} |
| 299 |
|
} |
| 300 |
|
} |
| 301 |
1
|
return null; |
| 302 |
|
} |
| 303 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 304 |
578
|
private QueryParamInfo findQueryParam(SearchTypeInfo st, String paramKey) {... |
| 305 |
578
|
for (QueryParamInfo qp : st.getSearchCriteriaTypeInfo() |
| 306 |
|
.getQueryParams()) { |
| 307 |
2733
|
if (qp.getKey().equals(paramKey)) { |
| 308 |
530
|
return qp; |
| 309 |
|
} |
| 310 |
|
} |
| 311 |
48
|
return null; |
| 312 |
|
} |
| 313 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 314 |
23
|
private String buildErrorPrefix3(LookupMetadata lookup, String name,... |
| 315 |
|
String type, String lookupType) { |
| 316 |
23
|
return buildErrorPrefix2(name, type, lookupType) + ": " |
| 317 |
|
+ lookup.getId(); |
| 318 |
|
} |
| 319 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 320 |
23
|
private String buildErrorPrefix2(String name, String type, String lookupType) {... |
| 321 |
23
|
String msg = buildErrorPrefix1(name, type); |
| 322 |
23
|
msg += " has an " + lookupType + " lookup "; |
| 323 |
23
|
return msg; |
| 324 |
|
} |
| 325 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 326 |
29
|
private String buildErrorPrefix1(String name, String type) {... |
| 327 |
29
|
String msg = name; |
| 328 |
29
|
if (type != null) { |
| 329 |
1
|
msg += " with type " + type; |
| 330 |
|
} |
| 331 |
|
|
| 332 |
|
|
| 333 |
29
|
return msg; |
| 334 |
|
} |
| 335 |
|
} |