| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ActivityTypeValidator | 
 | 
 | 7.0;7 | 
| 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.dto.AmountInfo; | |
| 10 |  import org.kuali.student.common.dto.TimeAmountInfo; | |
| 11 |  import org.kuali.student.common.validation.dto.ValidationResultInfo; | |
| 12 |  import org.kuali.student.common.validator.DefaultValidatorImpl; | |
| 13 |  import org.kuali.student.lum.course.dto.ActivityInfo; | |
| 14 | ||
| 15 |  /** | |
| 16 |   * Validates Subject COde usage | |
| 17 |   * If the Course has a subject code with usage of all, the  | |
| 18 |   * | |
| 19 |   */ | |
| 20 | 1 | public class ActivityTypeValidator extends DefaultValidatorImpl { | 
| 21 | ||
| 22 | @Override | |
| 23 |          public List<ValidationResultInfo> validateObject(FieldDefinition field,        Object o, ObjectStructureDefinition objStructure, | |
| 24 |                          Stack<String> elementStack) { | |
| 25 | ||
| 26 | 24 |                  List<ValidationResultInfo> validationResults = new ArrayList<ValidationResultInfo>(); | 
| 27 | ||
| 28 | 24 |                  if (o instanceof ActivityInfo && o != null) { | 
| 29 | 24 | ActivityInfo activity = (ActivityInfo)o; | 
| 30 | 24 |                          if (hasActivityData(activity) && !hasText(activity.getActivityType())){ | 
| 31 | 0 |                                  ValidationResultInfo vr = new ValidationResultInfo(); | 
| 32 | 0 |                                  String elementPath = getElementXpath(elementStack) + "/activityType"; | 
| 33 | 0 |                                  vr.setElement(elementPath); | 
| 34 | 0 |                                  vr.setError("validation.required"); | 
| 35 | 0 |                                  validationResults.add(vr); | 
| 36 | } | |
| 37 | } | |
| 38 | ||
| 39 | 24 |                  return validationResults; | 
| 40 | } | |
| 41 | ||
| 42 | protected boolean hasActivityData(ActivityInfo activity){ | |
| 43 | 24 | boolean hasData = false; | 
| 44 | ||
| 45 | 24 | AmountInfo contactHours = activity.getContactHours(); | 
| 46 | 24 |                  if (contactHours != null){ | 
| 47 | 24 |                          hasData = hasData || hasText(contactHours.getUnitQuantity()) || hasText(contactHours.getUnitType()); | 
| 48 | } | |
| 49 | ||
| 50 | 24 |                  int enrollmentEstimate = activity.getDefaultEnrollmentEstimate(); | 
| 51 | 24 |                  hasData = hasData || enrollmentEstimate >= 0; | 
| 52 | ||
| 53 | 24 | TimeAmountInfo duration = activity.getDuration(); | 
| 54 | 24 |                  if (duration != null){ | 
| 55 | 24 |                          hasData = hasData || hasText(duration.getAtpDurationTypeKey()); | 
| 56 | 24 |                          hasData = hasData || (duration.getTimeQuantity() != null && duration.getTimeQuantity().intValue() >= 0); | 
| 57 | } | |
| 58 | ||
| 59 | 24 |                  return hasData; | 
| 60 | } | |
| 61 | ||
| 62 | } |