Class ValidationService

java.lang.Object
cf.maybelambda.httpvalidator.springboot.service.ValidationService

@Service public class ValidationService extends Object
Service for handling validation tasks, executing scheduled validations, and managing validation results.
  • Field Details

  • Constructor Details

    • ValidationService

      public ValidationService()
      Constructor to initialize the HTTP client with default connection-timeout and follow-redirects settings.
  • Method Details

    • execValidations

      @Scheduled(cron="${cron.expression}") public void execValidations() throws FileNotFoundException, XMLParseException, com.fasterxml.jackson.core.JsonProcessingException, ConnectIOException, ExecutionException, InterruptedException
      Executes validation tasks periodically based on a cron schedule. Retrieves tasks, sends HTTP requests, and processes responses. Sends email notifications for any validation failures and updates information about the last run of validation tasks.
      Throws:
      FileNotFoundException - if the data file is not found
      XMLParseException - if there is an error parsing the XML file
      com.fasterxml.jackson.core.JsonProcessingException - when a validation task contains invalid JSON content
      ConnectIOException - if there is an error sending notification email
      ExecutionException - when an unhandled error occurs while processing the HTTP requests
      InterruptedException - when interrupted before completing all the requests
    • getLastRunInfo

      public Map<String,String> getLastRunInfo()
      Retrieves information about the last run of validation tasks.
      Returns:
      A map containing start time, time elapsed, total tasks, successful tasks and failed tasks.
    • isValidConfig

      public boolean isValidConfig()
      Checks if the configuration is valid by validating the cron expression currently in use.
      Returns:
      true if the configuration is valid, false otherwise
    • isValidCronExpression

      public boolean isValidCronExpression(String cronExpr)
      Validates a given cron expression.
      Parameters:
      cronExpr - Cron expression to validate
      Returns:
      true if the cron expression is valid, false otherwise