Coverage Report - org.kuali.student.lum.course.service.utils.ActiveDatesValidator
 
Classes in this File Line Coverage Branch Coverage Complexity
ActiveDatesValidator
0%
0/19
0%
0/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.dictionary.dto.FieldDefinition;
 8  
 import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition;
 9  
 import org.kuali.student.common.util.MessageUtils;
 10  
 import org.kuali.student.common.validation.dto.ValidationResultInfo;
 11  
 import org.kuali.student.common.validator.DefaultValidatorImpl;
 12  
 import org.kuali.student.core.atp.dto.AtpInfo;
 13  
 import org.kuali.student.core.atp.service.AtpService;
 14  
 import org.kuali.student.lum.course.dto.CourseInfo;
 15  
 
 16  0
 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  0
                 List<ValidationResultInfo> results = new ArrayList<ValidationResultInfo>();
 33  0
                 if (o instanceof CourseInfo) {
 34  0
                         CourseInfo course = (CourseInfo) o;
 35  0
                         if (course.getEndTerm() != null && course.getStartTerm() != null) {
 36  
                                 try {
 37  0
                                         AtpInfo startAtp = atpService.getAtp(course.getStartTerm());
 38  0
                                         AtpInfo endAtp = atpService.getAtp(course.getEndTerm());
 39  0
                                         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  0
                                 }
 49  
 
 50  
                         }
 51  
                 }
 52  0
                 return results;
 53  
         }
 54  
 
 55  
         public void setAtpService(AtpService atpService) {
 56  0
                 this.atpService = atpService;
 57  0
         }
 58  
 
 59  
 }