Class InputValidationUtils

java.lang.Object
com.bonitasoft.processbuilder.extension.InputValidationUtils

public final class InputValidationUtils extends Object
Utility class for common input parameter validation checks (e.g., positive numbers, non-null values) typically used within Bonita connectors.

NOTE: This utility assumes the calling class has an accessible 'getInputParameter(String name)' method.

  • Method Details

    • parseStringToPositiveLong

      public static Optional<Long> parseStringToPositiveLong(String input, String paramName)
      Parses a String input to a positive Long value with comprehensive validation and logging.

      This method handles various edge cases for String-to-Long conversion:

      • If input is null → returns Optional.empty()
      • If trimmed input is empty or equals "null" (case-insensitive) → returns Optional.empty()
      • If parsing fails (NumberFormatException) → returns Optional.empty()
      • If parsed value is not positive (≤ 0) → returns Optional.empty()
      • If valid positive Long → returns Optional.of(value)

      All validation failures are logged with appropriate level (debug for null/empty, warn for invalid values).

      Parameters:
      input - the String value to parse (may be null)
      paramName - the parameter name for logging purposes (used in log messages)
      Returns:
      an Optional<Long> containing the positive Long value if valid, or Optional.empty() if the input is null, empty, "null", unparseable, or not positive
    • parseStringToLong

      public static Long parseStringToLong(String input, String paramName)
      Parses a String input to a Long value with comprehensive validation and logging.

      This method handles various edge cases for String-to-Long conversion:

      • If input is null → returns null
      • If trimmed input is empty or equals "null" (case-insensitive) → returns null
      • If parsing fails (NumberFormatException) → returns 0L
      • If valid number → returns the parsed Long value

      All validation failures are logged with appropriate level (debug for null/empty, error for parse failures).

      Usage Example:

      
       Long actionIdLong = InputValidationUtils.parseStringToLong(actionPersistenceIdInput, "actionPersistenceIdInput");
       if (actionIdLong == null || actionIdLong <= 0L) {
           logger.warn("Invalid input: '{}' is null or not positive.", "actionPersistenceIdInput");
           return Collections.emptyList();
       }
       
      Parameters:
      input - the String value to parse (may be null)
      paramName - the parameter name for logging purposes (used in log messages)
      Returns:
      the parsed Long value, null if input is null/empty/"null", or 0L if the input cannot be parsed as a number
    • checkPositiveIntegerInput

      public static void checkPositiveIntegerInput(String inputName, Supplier<Object> inputGetter) throws org.bonitasoft.engine.connector.ConnectorValidationException
      Checks if a given input parameter is a positive Integer.
      Parameters:
      inputName - The name of the input parameter.
      inputGetter - A functional interface (Supplier) to retrieve the input parameter value.
      Throws:
      org.bonitasoft.engine.connector.ConnectorValidationException - if the parameter is not a positive Integer.
    • checkPositiveLongInput

      public static void checkPositiveLongInput(String inputName, Supplier<Object> inputGetter) throws org.bonitasoft.engine.connector.ConnectorValidationException
      Checks if a given input parameter is a positive Long.
      Parameters:
      inputName - The name of the input parameter.
      inputGetter - A functional interface (Supplier) to retrieve the input parameter value.
      Throws:
      org.bonitasoft.engine.connector.ConnectorValidationException - if the parameter is not a positive Long.