| 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.BeanConstraintDataProvider;     | 
  
            
  
    | 9 | 
    
            
    
     | 
    
      import org.kuali.student.common.validator.ConstraintDataProvider;     | 
  
            
  
    | 10 | 
    
            
    
     | 
    
      import org.kuali.student.common.validator.DefaultValidatorImpl;     | 
  
            
  
    | 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.CourseExpenditureInfo;     | 
  
            
  
    | 15 | 
    
            
    
     | 
    
      import org.kuali.student.lum.lu.dto.AffiliatedOrgInfo;     | 
  
            
  
    | 16 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 76.5% | 
           Uncovered Elements: 8 (34) | 
           Complexity: 8 | 
           Complexity Density: 0.36 | 
                        
            
        | 
    
  
  
    | 17 | 
    
            
    
     | 
    
      public class ExpenditurePercentValidator extends DefaultValidatorImpl {     | 
  
            
  
    | 18 | 
    
            
    
     | 
    
           | 
  
            
  
    | 19 | 
    
            
    
     | 
    
          private static final String COURSE_EXPENDITURE_FIELD = "expenditure";     | 
  
            
  
    | 20 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 21 | 
    
           0
    
     | 
    
           @Override...     | 
  
            
  
    | 22 | 
    
            
    
     | 
    
          public List<ValidationResultInfo> validateObject(Object data, ObjectStructureDefinition objStructure) {     | 
  
            
  
    | 23 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 24 | 
    
           0
    
     | 
    
              return null;     | 
  
            
  
    | 25 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 26 | 
    
            
    
     | 
    
           | 
  
            
  
    | 27 | 
    
            
    
     | 
    
               | 
  
            
  
    | 28 | 
    
            
    
     | 
    
      @see     | 
  
            
  
    | 29 | 
    
            
    
     | 
    
           | 
  
            
  
    | 30 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 80.6% | 
           Uncovered Elements: 6 (31) | 
           Complexity: 7 | 
           Complexity Density: 0.33 | 
                        
            
        | 
    
  
  
    | 31 | 
    
           7
    
     | 
    
           @Override...     | 
  
            
  
    | 32 | 
    
            
    
     | 
    
          public List<ValidationResultInfo> validateObject(FieldDefinition field, Object data, ObjectStructureDefinition objStructure, Stack<String> elementStack) {     | 
  
            
  
    | 33 | 
    
            
    
     | 
    
           | 
  
            
  
    | 34 | 
    
           7
    
     | 
    
              List<ValidationResultInfo> results = new ArrayList<ValidationResultInfo>();     | 
  
            
  
    | 35 | 
    
            
    
     | 
    
           | 
  
            
  
    | 36 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 37 | 
    
           7
    
     | 
    
              if (!COURSE_EXPENDITURE_FIELD.equalsIgnoreCase(field.getName())) {     | 
  
            
  
    | 38 | 
    
           0
    
     | 
    
                  throw new RuntimeException("Custom Validator " + this.getClass().getName() + " was not called on the right field: expenditure");     | 
  
            
  
    | 39 | 
    
            
    
     | 
    
              }     | 
  
            
  
    | 40 | 
    
            
    
     | 
    
           | 
  
            
  
    | 41 | 
    
           7
    
     | 
    
              ConstraintDataProvider dataProvider = new BeanConstraintDataProvider();     | 
  
            
  
    | 42 | 
    
           7
    
     | 
    
              dataProvider.initialize(data);     | 
  
            
  
    | 43 | 
    
            
    
     | 
    
           | 
  
            
  
    | 44 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 45 | 
    
           7
    
     | 
    
              Object expenditureObj = dataProvider.getValue(field.getName());     | 
  
            
  
    | 46 | 
    
            
    
     | 
    
           | 
  
            
  
    | 47 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 48 | 
    
           7
    
     | 
    
              if(null == expenditureObj) {     | 
  
            
  
    | 49 | 
    
           6
    
     | 
    
                  return results;     | 
  
            
  
    | 50 | 
    
            
    
     | 
    
              }     | 
  
            
  
    | 51 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 52 | 
    
           1
    
     | 
    
              if (!(expenditureObj instanceof CourseExpenditureInfo)) {     | 
  
            
  
    | 53 | 
    
           0
    
     | 
    
                  throw new RuntimeException("Custom Validator " + this.getClass().getName() + " was not called with right data: CourseExpenditureInfo");     | 
  
            
  
    | 54 | 
    
            
    
     | 
    
              }     | 
  
            
  
    | 55 | 
    
            
    
     | 
    
           | 
  
            
  
    | 56 | 
    
           1
    
     | 
    
              CourseExpenditureInfo courseExpInfo = (CourseExpenditureInfo) expenditureObj;     | 
  
            
  
    | 57 | 
    
            
    
     | 
    
           | 
  
            
  
    | 58 | 
    
           1
    
     | 
    
              long totalOrgPercent = 0l;     | 
  
            
  
    | 59 | 
    
           1
    
     | 
    
              if (courseExpInfo.getAffiliatedOrgs().size() > 0) {     | 
  
            
  
    | 60 | 
    
           1
    
     | 
    
                  for (AffiliatedOrgInfo org : courseExpInfo.getAffiliatedOrgs()) {     | 
  
            
  
    | 61 | 
    
           2
    
     | 
    
                      totalOrgPercent += org.getPercentage();     | 
  
            
  
    | 62 | 
    
            
    
     | 
    
                  }     | 
  
            
  
    | 63 | 
    
            
    
     | 
    
              }     | 
  
            
  
    | 64 | 
    
            
    
     | 
    
           | 
  
            
  
    | 65 | 
    
           1
    
     | 
    
              if (courseExpInfo.getAffiliatedOrgs().size() > 0 && totalOrgPercent != 100l) {     | 
  
            
  
    | 66 | 
    
           1
    
     | 
    
                  ValidationResultInfo valRes = new ValidationResultInfo(getElementXpath(elementStack));     | 
  
            
  
    | 67 | 
    
           1
    
     | 
    
                  valRes.setElement("/expenditure/affiliatedOrgs");     | 
  
            
  
    | 68 | 
    
           1
    
     | 
    
                  valRes.setError(MessageUtils.interpolate(getMessage("validation.expenditureTotal"), toMap(field)));     | 
  
            
  
    | 69 | 
    
           1
    
     | 
    
                  results.add(valRes);     | 
  
            
  
    | 70 | 
    
            
    
     | 
    
              }     | 
  
            
  
    | 71 | 
    
            
    
     | 
    
           | 
  
            
  
    | 72 | 
    
           1
    
     | 
    
              return results;     | 
  
            
  
    | 73 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 74 | 
    
            
    
     | 
    
      }     |