Clover Coverage Report - KS LUM 1.2-M2-SNAPSHOT (Aggregated)
Coverage timestamp: Fri Apr 22 2011 05:19:13 EST
../../../../../../../img/srcFileCovDistChart0.png 54% of files have more coverage
29   89   12   14.5
16   65   0.41   2
2     6  
1    
 
  SubjectAreaUnitOwnerValidator       Line # 25 29 0% 12 47 0% 0.0
 
No Tests
 
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    * Validates Subject COde usage
22    * If the Course has a subject code with usage of all, the
23    *
24    */
 
25    public class SubjectAreaUnitOwnerValidator extends DefaultValidatorImpl {
26   
27    private SearchDispatcher searchDispatcher;
28   
 
29  0 toggle @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    //Do a search for the orgs allowed under this subject code
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    //Parse the search results and get a list of all org ids, and if any of the subject code types was
50    //useage one of
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    //Make sure that the course has all the org ids in the found set of org ids
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    //Make sure that the course has only one of the org ids in the set by finding the intersection
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   
 
85  0 toggle public void setSearchDispatcher(SearchDispatcher searchDispatcher) {
86  0 this.searchDispatcher = searchDispatcher;
87    }
88   
89    }