Class RouteSegmentsValidator

java.lang.Object
com.endurancetrio.business.tracker.validator.RouteSegmentsValidator
All Implemented Interfaces:
jakarta.validation.ConstraintValidator<RouteSegmentsValid,RouteDTO>

public class RouteSegmentsValidator extends Object implements jakarta.validation.ConstraintValidator<RouteSegmentsValid,RouteDTO>
Validator for the RouteSegmentsValid constraint on RouteDTO.

This validator enforces two primary business rules for route integrity:

  1. Continuity: The endDevice of segment N must match the startDevice of segment N+1.
  2. Sequence: Segment orders must be strictly sequential (1, 2, 3...) without gaps.
  • Constructor Details

    • RouteSegmentsValidator

      public RouteSegmentsValidator()
  • Method Details

    • isValid

      public boolean isValid(RouteDTO route, jakarta.validation.ConstraintValidatorContext context)
      Validator for the RouteSegmentsValid constraint.

      Performs a comprehensive audit of the RouteDTO to ensure logical integrity. This validator does not "fail-fast"; it evaluates the entire segment list to report all instances of the following violations:

      • Order Initiation: The first segment (lowest order) must be 1.
      • Device Continuity: The endDevice of a segment must match the startDevice of the next segment in the sequence.
      • Numerical Sequence: Segment orders must be strictly incremental (e.g., 1, 2, 3) without gaps.
      Specified by:
      isValid in interface jakarta.validation.ConstraintValidator<RouteSegmentsValid,RouteDTO>