Package com.sap.cds.services.impl.utils
Class ValidatorUtils
java.lang.Object
com.sap.cds.services.impl.utils.ValidatorUtils
Validation utilities.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.sap.cds.CdsDataProcessor.ValidatorassertNotNull(EventContext context, Predicate<Object> isNull, ValidatorUtils.Handler errorHandler) Returns a validator for mandatory annotated elements or elements with not null constraints.static voidhandleValidationError(EventContext context, com.sap.cds.ql.cqn.Path path, com.sap.cds.reflect.CdsElement element, CdsErrorStatuses statuses, Object... args) Handles the givenCdsErrorStatusesby either generating an error message or throwing aErrorStatusException.static voidprocess(com.sap.cds.CdsDataProcessor processor, EventContext context) Runs the given instance of a @CdsDataProcessoragainst the entity that is the target of the given event context or action or function arguments wrapped in the virtual CDS type.static booleanrequiresNotNullCheck(com.sap.cds.reflect.CdsElement element) Returns true, if the providedCdsElementrequires a not null check based on its type, potential default value or whether its draft element.static voidrunNotNullCheck(EventContext context, Predicate<com.sap.cds.reflect.CdsElement> requiredByModel, com.sap.cds.CdsDataProcessor.Validator validator) Runs a not null validation against the providedEventContextwith the given predicate and validator implementation.
-
Constructor Details
-
ValidatorUtils
public ValidatorUtils()
-
-
Method Details
-
requiresNotNullCheck
public static boolean requiresNotNullCheck(com.sap.cds.reflect.CdsElement element) Returns true, if the providedCdsElementrequires 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 providedEventContextwith the given predicate and validator implementation.- Parameters:
context- the event contextrequiredByModel- predicate returning whether validation is required based on model annotationsvalidator- the validator implementation to use
-
process
Runs the given instance of a @CdsDataProcessoragainst 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 @CdsDataProcessorthat will process the entity.context- Instance of the @EventContextfrom 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 givenCdsErrorStatusesby either generating an error message or throwing aErrorStatusException.- Parameters:
context- the event contextpath- the relative path to the target elementelement- the target elementstatuses- the cds error statusargs- 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 contextisNull- 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
-