1 |
|
package org.kuali.student.lum.course.service.utils; |
2 |
|
|
3 |
|
import java.util.ArrayList; |
4 |
|
import java.util.HashSet; |
5 |
|
import java.util.List; |
6 |
|
import java.util.Set; |
7 |
|
import java.util.Stack; |
8 |
|
|
9 |
|
import org.kuali.student.common.dictionary.dto.FieldDefinition; |
10 |
|
import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition; |
11 |
|
import org.kuali.student.common.search.dto.SearchRequest; |
12 |
|
import org.kuali.student.common.search.dto.SearchResult; |
13 |
|
import org.kuali.student.common.search.dto.SearchResultCell; |
14 |
|
import org.kuali.student.common.search.dto.SearchResultRow; |
15 |
|
import org.kuali.student.common.search.service.SearchDispatcher; |
16 |
|
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
17 |
|
import org.kuali.student.common.validator.DefaultValidatorImpl; |
18 |
|
import org.kuali.student.lum.course.dto.CourseInfo; |
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
|
|
| 61.7% |
Uncovered Elements: 18 (47) |
Complexity: 12 |
Complexity Density: 0.41 |
|
25 |
|
public class SubjectAreaUnitOwnerValidator extends DefaultValidatorImpl { |
26 |
|
|
27 |
|
private SearchDispatcher searchDispatcher; |
28 |
|
|
|
|
| 59.1% |
Uncovered Elements: 18 (44) |
Complexity: 11 |
Complexity Density: 0.39 |
|
29 |
7
|
@Override... |
30 |
|
public List<ValidationResultInfo> validateObject(FieldDefinition field, |
31 |
|
Object o, ObjectStructureDefinition objStructure, |
32 |
|
Stack<String> elementStack) { |
33 |
|
|
34 |
7
|
List<ValidationResultInfo> validationResults = new ArrayList<ValidationResultInfo>(); |
35 |
|
|
36 |
7
|
if (o instanceof CourseInfo) { |
37 |
7
|
CourseInfo course = (CourseInfo) o; |
38 |
7
|
if(course.getSubjectArea()!=null && !course.getUnitsContentOwner().isEmpty()){ |
39 |
|
|
40 |
6
|
SearchRequest searchRequest = new SearchRequest("subjectCode.search.orgsForSubjectCode"); |
41 |
6
|
searchRequest.addParam("subjectCode.queryParam.code", course.getSubjectArea()); |
42 |
|
|
43 |
6
|
SearchResult result = searchDispatcher.dispatchSearch(searchRequest); |
44 |
|
|
45 |
6
|
Set<String> orgIds = new HashSet<String>(); |
46 |
6
|
boolean useageAllOf = true; |
47 |
|
|
48 |
6
|
if(result!=null){ |
49 |
|
|
50 |
|
|
51 |
6
|
for(SearchResultRow row:result.getRows()){ |
52 |
6
|
for(SearchResultCell cell:row.getCells()){ |
53 |
6
|
if("subjectCode.resultColumn.orgId".equals(cell.getKey())){ |
54 |
0
|
orgIds.add(cell.getValue()); |
55 |
6
|
}else if("subjectCode.resultColumn.type".equals(cell.getKey())&&"ks.core.subjectcode.usage.one".equals(cell.getValue())){ |
56 |
0
|
useageAllOf = false; |
57 |
|
} |
58 |
|
} |
59 |
|
} |
60 |
|
} |
61 |
|
|
62 |
6
|
List<String> units = new ArrayList<String>(course.getUnitsContentOwner()); |
63 |
6
|
if(useageAllOf){ |
64 |
|
|
65 |
6
|
if(!units.containsAll(orgIds)){ |
66 |
0
|
ValidationResultInfo validationResult = new ValidationResultInfo(getElementXpath(elementStack) + "/" + field.getName()); |
67 |
0
|
validationResult.setWarning(getMessage("validation.course.subjectAreaUsage.all")); |
68 |
0
|
validationResults.add(validationResult); |
69 |
|
} |
70 |
|
}else{ |
71 |
|
|
72 |
0
|
units.retainAll(orgIds); |
73 |
0
|
if(units.size()!=1){ |
74 |
0
|
ValidationResultInfo validationResult = new ValidationResultInfo(getElementXpath(elementStack) + "/" + field.getName()); |
75 |
0
|
validationResult.setWarning(getMessage("validation.course.subjectAreaUsage.one")); |
76 |
0
|
validationResults.add(validationResult); |
77 |
|
} |
78 |
|
} |
79 |
|
} |
80 |
|
} |
81 |
|
|
82 |
7
|
return validationResults; |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
1
|
public void setSearchDispatcher(SearchDispatcher searchDispatcher) {... |
86 |
1
|
this.searchDispatcher = searchDispatcher; |
87 |
|
} |
88 |
|
|
89 |
|
} |