|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
   package org.kuali.rice.kns.datadictionary.validation.processor;  | 
  |  17 |     | 
     | 
  |  18 |     | 
   import java.util.Collection;  | 
  |  19 |     | 
     | 
  |  20 |     | 
   import org.kuali.rice.core.util.RiceKeyConstants;  | 
  |  21 |     | 
   import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException;  | 
  |  22 |     | 
   import org.kuali.rice.kns.datadictionary.validation.AttributeValueReader;  | 
  |  23 |     | 
   import org.kuali.rice.kns.datadictionary.validation.ErrorLevel;  | 
  |  24 |     | 
   import org.kuali.rice.kns.datadictionary.validation.ValidationUtils;  | 
  |  25 |     | 
   import org.kuali.rice.kns.datadictionary.validation.constraint.Constraint;  | 
  |  26 |     | 
   import org.kuali.rice.kns.datadictionary.validation.constraint.PrerequisiteConstraint;  | 
  |  27 |     | 
   import org.kuali.rice.kns.datadictionary.validation.result.ConstraintValidationResult;  | 
  |  28 |     | 
     | 
  |  29 |     | 
     | 
  |  30 |     | 
     | 
  |  31 |     | 
     | 
  |  32 |     | 
     | 
  |  33 |    0 |    public abstract class BasePrerequisiteConstraintProcessor<C extends Constraint> extends MandatoryElementConstraintProcessor<C> { | 
  |  34 |     | 
             | 
  |  35 |     | 
           protected ConstraintValidationResult processPrerequisiteConstraint(PrerequisiteConstraint constraint, AttributeValueReader attributeValueReader) throws AttributeValidationException { | 
  |  36 |     | 
     | 
  |  37 |    0 |                    ConstraintValidationResult constraintValidationResult = new ConstraintValidationResult(getName());  | 
  |  38 |     | 
                     | 
  |  39 |    0 |                    if (constraint == null) { | 
  |  40 |    0 |                            constraintValidationResult.setStatus(ErrorLevel.NOCONSTRAINT);  | 
  |  41 |    0 |                            return constraintValidationResult;  | 
  |  42 |     | 
                   }  | 
  |  43 |     | 
                             | 
  |  44 |     | 
                     | 
  |  45 |     | 
                 | 
  |  46 |    0 |            String attributeName = constraint.getAttributePath();  | 
  |  47 |     | 
             | 
  |  48 |    0 |            if (ValidationUtils.isNullOrEmpty(attributeName)) { | 
  |  49 |    0 |                    throw new AttributeValidationException("Prerequisite constraints must include the name of the attribute that is required"); | 
  |  50 |     | 
           }  | 
  |  51 |     | 
             | 
  |  52 |    0 |            Object value = attributeValueReader.getValue(attributeName);  | 
  |  53 |     | 
     | 
  |  54 |    0 |            boolean isSuccessful = true;  | 
  |  55 |     | 
     | 
  |  56 |    0 |            if (value instanceof java.lang.String) { | 
  |  57 |    0 |                    isSuccessful = ValidationUtils.hasText((String) value);  | 
  |  58 |    0 |            } else if (value instanceof Collection) { | 
  |  59 |    0 |                    isSuccessful = (((Collection<?>) value).size() > 0);  | 
  |  60 |     | 
           } else { | 
  |  61 |    0 |                    isSuccessful = (null != value) ? true : false;  | 
  |  62 |     | 
           }  | 
  |  63 |     | 
     | 
  |  64 |     | 
             | 
  |  65 |     | 
             | 
  |  66 |    0 |            if (!isSuccessful) {                 | 
  |  67 |    0 |                    String label = attributeValueReader.getLabel(attributeName);   | 
  |  68 |    0 |                    if (label != null)  | 
  |  69 |    0 |                            attributeName = label;  | 
  |  70 |     | 
                     | 
  |  71 |    0 |                    constraintValidationResult.setError(RiceKeyConstants.ERROR_REQUIRES_FIELD, attributeName);  | 
  |  72 |     | 
           }   | 
  |  73 |     | 
             | 
  |  74 |    0 |            return constraintValidationResult;  | 
  |  75 |     | 
       }  | 
  |  76 |     | 
     | 
  |  77 |     | 
   }  |