Clover Coverage Report - Kuali Student 1.2.1-SNAPSHOT (Aggregated)
Coverage timestamp: Wed Nov 2 2011 04:03:58 EST
../../../../../../../img/srcFileCovDistChart7.png 32% of files have more coverage
29   89   12   14.5
16   65   0.41   2
2     6  
1    
 
  SubjectAreaUnitOwnerValidator       Line # 25 29 0% 12 18 61.7% 0.61702126
 
  (1)
 
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  7 toggle @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    //Do a search for the orgs allowed under this subject code
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    //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  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    //Make sure that the course has all the org ids in the found set of org ids
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    //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  7 return validationResults;
83    }
84   
 
85  1 toggle public void setSearchDispatcher(SearchDispatcher searchDispatcher) {
86  1 this.searchDispatcher = searchDispatcher;
87    }
88   
89    }