Class ValidatorUtils

java.lang.Object
com.sap.cds.services.impl.utils.ValidatorUtils

public class ValidatorUtils extends Object
Validation utilities.
  • Constructor Details

    • ValidatorUtils

      public ValidatorUtils()
  • Method Details

    • requiresNotNullCheck

      public static boolean requiresNotNullCheck(com.sap.cds.reflect.CdsElement element)
      Returns true, if the provided CdsElement requires a not null check based on its type, potential default value or whether its draft element.
      Parameters:
      element - the cds element
      Returns:
      true, if element requires a not null check
    • runNotNullCheck

      public static void runNotNullCheck(EventContext context, Predicate<com.sap.cds.reflect.CdsElement> requiredByModel, com.sap.cds.CdsDataProcessor.Validator validator)
      Runs a not null validation against the provided EventContext with the given predicate and validator implementation.
      Parameters:
      context - the event context
      requiredByModel - predicate returning whether validation is required based on model annotations
      validator - the validator implementation to use
    • process

      public static void process(com.sap.cds.CdsDataProcessor processor, EventContext context)
      Runs the given instance of a @CdsDataProcessor against the entity that is the target of the given event context or action or function arguments wrapped in the virtual CDS type.
      Parameters:
      processor - An instance of the @CdsDataProcessor that will process the entity.
      context - Instance of the @EventContext from where the entity will be extracted.
    • handleValidationError

      public static void handleValidationError(EventContext context, com.sap.cds.ql.cqn.Path path, com.sap.cds.reflect.CdsElement element, CdsErrorStatuses statuses, Object... args)
      Handles the given CdsErrorStatuses by either generating an error message or throwing a ErrorStatusException.
      Parameters:
      context - the event context
      path - the relative path to the target element
      element - the target element
      statuses - the cds error status
      args - message args
    • assertNotNull

      public static com.sap.cds.CdsDataProcessor.Validator assertNotNull(EventContext context, Predicate<Object> isNull, ValidatorUtils.Handler errorHandler)
      Returns a validator for mandatory annotated elements or elements with not null constraints. Validated elements can be of type association and requires a not null (or empty string) check on its foreign key elements.
      Parameters:
      context - the event context
      isNull - predicate checking whether an object is set to null (or an empty string)
      errorHandler - error handler that takes the element and entity name that is validated
      Returns:
      a validator implementation