Class ConstraintStateUtils

java.lang.Object
org.kuali.rice.krad.uif.util.ConstraintStateUtils

public class ConstraintStateUtils extends Object
Various utility methods for determining when to use constraints during states
Since:
2.2
Author:
Kuali Rice Team (rice.collab@kuali.org)
  • Constructor Details

    • ConstraintStateUtils

      public ConstraintStateUtils()
  • Method Details

    • constraintAppliesForState

      public static boolean constraintAppliesForState(String applicableState, Constraint constraint, StateMapping stateMapping)
      Determines if the constraint passed in applies for the applicableState, based on the stateMapping

      Note: this method will automatically return TRUE if the stateMapping is null, the Constraint is not a BaseConstraint, if there are no states defined on the Constraint, or if the state it applies to cannot be found in the stateMapping, because in all these cases the Constraint is considered stateless and will apply to any state

      Parameters:
      applicableState - the state to check to see if the constraint applies
      constraint - the Constraint to check
      stateMapping - the StateMapping object containing state information
      Returns:
      true if the Constraint applies to the applicableState, false otherwise
    • getApplicableConstraint

      public static <T extends Constraint> T getApplicableConstraint(T constraint, String validationState, StateMapping stateMapping)
      Gets the constraint that applies for the validationState passed in with the appropriate StateMapping (which should include validationState as one of its states).

      This method will essentially return the constraint passed in, in most cases, if the constraint applies. In cases where there are constraintStateOverrides set for the constraint, those will be evaluated to get the appropriate replacement. If the constraint does not apply for the validationState (as well as none of the replacements), this method will return null. If stateMapping passed in is null, the constraint is not a BaseConstraint, or validationState is blank, the original constraint will be returned (assumed stateless).

      Type Parameters:
      T - constraint type
      Parameters:
      constraint - the original constraint
      validationState - the validation state
      stateMapping - the state information for the model being evaluated
      Returns:
      the applicable constraint, null if this constraint does not apply to the validationState
      Throws:
      RuntimeException - if the type of constraint passed in cannot be cast to the replacement constraint
    • getClientViewValidationState

      public static String getClientViewValidationState(Object model, View view)
      Gets the client validation state. If there are customClientSideValidationStates configured for the view's stateMapping, these are used, otherwise client side validation state is assumed to be the next state (or current state if there is no next state). Returns null if there is no state for client side validation (ie stateless).
      Parameters:
      model -
      view -
      Returns:
      the state to validate against for client side view validation