| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 47 (47) |
Complexity: 12 |
Complexity Density: 0.41 |
|
| 25 |
|
public class SubjectAreaUnitOwnerValidator extends DefaultValidatorImpl { |
| 26 |
|
|
| 27 |
|
private SearchDispatcher searchDispatcher; |
| 28 |
|
|
|
|
|
| 0% |
Uncovered Elements: 44 (44) |
Complexity: 11 |
Complexity Density: 0.39 |
|
| 29 |
0
|
@Override... |
| 30 |
|
public List<ValidationResultInfo> validateObject(FieldDefinition field, |
| 31 |
|
Object o, ObjectStructureDefinition objStructure, |
| 32 |
|
Stack<String> elementStack) { |
| 33 |
|
|
| 34 |
0
|
List<ValidationResultInfo> validationResults = new ArrayList<ValidationResultInfo>(); |
| 35 |
|
|
| 36 |
0
|
if (o instanceof CourseInfo) { |
| 37 |
0
|
CourseInfo course = (CourseInfo) o; |
| 38 |
0
|
if(course.getSubjectArea()!=null && !course.getUnitsContentOwner().isEmpty()){ |
| 39 |
|
|
| 40 |
0
|
SearchRequest searchRequest = new SearchRequest("subjectCode.search.orgsForSubjectCode"); |
| 41 |
0
|
searchRequest.addParam("subjectCode.queryParam.code", course.getSubjectArea()); |
| 42 |
|
|
| 43 |
0
|
SearchResult result = searchDispatcher.dispatchSearch(searchRequest); |
| 44 |
|
|
| 45 |
0
|
Set<String> orgIds = new HashSet<String>(); |
| 46 |
0
|
boolean useageAllOf = true; |
| 47 |
|
|
| 48 |
0
|
if(result!=null){ |
| 49 |
|
|
| 50 |
|
|
| 51 |
0
|
for(SearchResultRow row:result.getRows()){ |
| 52 |
0
|
for(SearchResultCell cell:row.getCells()){ |
| 53 |
0
|
if("subjectCode.resultColumn.orgId".equals(cell.getKey())){ |
| 54 |
0
|
orgIds.add(cell.getValue()); |
| 55 |
0
|
}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 |
0
|
List<String> units = new ArrayList<String>(course.getUnitsContentOwner()); |
| 63 |
0
|
if(useageAllOf){ |
| 64 |
|
|
| 65 |
0
|
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 |
0
|
return validationResults; |
| 83 |
|
} |
| 84 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 85 |
0
|
public void setSearchDispatcher(SearchDispatcher searchDispatcher) {... |
| 86 |
0
|
this.searchDispatcher = searchDispatcher; |
| 87 |
|
} |
| 88 |
|
|
| 89 |
|
} |