Coverage Report - org.kuali.student.lum.course.service.utils.ActiveDatesValidator
 
Classes in this File Line Coverage Branch Coverage Complexity
ActiveDatesValidator
63%
12/19
62%
5/8
3
 
 1  
 package org.kuali.student.lum.course.service.utils;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.List;
 5  
 import java.util.Stack;
 6  
 
 7  
 import org.kuali.student.common.util.MessageUtils;
 8  
 import org.kuali.student.common.validator.DefaultValidatorImpl;
 9  
 import org.kuali.student.core.atp.dto.AtpInfo;
 10  
 import org.kuali.student.core.atp.service.AtpService;
 11  
 import org.kuali.student.core.dictionary.dto.FieldDefinition;
 12  
 import org.kuali.student.core.dictionary.dto.ObjectStructureDefinition;
 13  
 import org.kuali.student.core.validation.dto.ValidationResultInfo;
 14  
 import org.kuali.student.lum.course.dto.CourseInfo;
 15  
 
 16  1
 public class ActiveDatesValidator extends DefaultValidatorImpl {
 17  
         private AtpService atpService;
 18  
 
 19  
         @Override
 20  
         public List<ValidationResultInfo> validateObject(Object data,
 21  
                         ObjectStructureDefinition objStructure) {
 22  
                 // Custom validators are required to only override the other
 23  
                 // validateObject method
 24  0
                 return null;
 25  
         }
 26  
 
 27  
         @Override
 28  
         public List<ValidationResultInfo> validateObject(FieldDefinition field,
 29  
                         Object o, ObjectStructureDefinition objStructure,
 30  
                         Stack<String> elementStack) {
 31  
                 //Get ATPs and compare dates.  If the end is <= the start, throw a validation error.
 32  7
                 List<ValidationResultInfo> results = new ArrayList<ValidationResultInfo>();
 33  7
                 if (o instanceof CourseInfo) {
 34  7
                         CourseInfo course = (CourseInfo) o;
 35  7
                         if (course.getEndTerm() != null && course.getStartTerm() != null) {
 36  
                                 try {
 37  6
                                         AtpInfo startAtp = atpService.getAtp(course.getStartTerm());
 38  6
                                         AtpInfo endAtp = atpService.getAtp(course.getEndTerm());
 39  6
                                         if (startAtp.getStartDate()
 40  
                                                         .compareTo(endAtp.getStartDate()) > 0) {
 41  0
                                                 ValidationResultInfo vr = new ValidationResultInfo();
 42  0
                                                 vr.setElement(field.getName());
 43  0
                                                 vr.setError("validation.endDateAfterStartDate");
 44  0
                                                 results.add(vr);
 45  
                                         }
 46  0
                                 } catch (Exception e) {
 47  0
                                         throw new RuntimeException("Error validating.", e);
 48  6
                                 }
 49  
 
 50  
                         }
 51  
                 }
 52  7
                 return results;
 53  
         }
 54  
 
 55  
         public void setAtpService(AtpService atpService) {
 56  1
                 this.atpService = atpService;
 57  1
         }
 58  
 
 59  
 }