private static void validateTrustAllRoots(final String trustAllRoots, final List<String> validationList) { if (!BooleanUtilities.isValid(trustAllRoots)) { validationList.add(INVALID_TRUST_ALL_ROOTS); } }
/** * If the string is null or empty string, it returns the defaultValue otherwise it returns the boolean value (see tooBoolean) * * @param booleanStr the string to convert to boolean * @param defaultValue the default value if the string is empty or null * @return true if the booleanStr is 'true', false if it's 'false' * @throws IllegalArgumentException if the booleanStr is not a valid boolean */ public static boolean toBoolean(@Nullable final String booleanStr, final boolean defaultValue) { return StringUtils.isNoneEmpty(booleanStr) ? toBoolean(booleanStr) : defaultValue; } }
/** * If the booleanStr is a valid boolean (see isValid) it returns the boolean value, otherwise it throws an exception * * @param booleanStr the string to convert to boolean * @return true if the booleanStr is 'true', false if it's 'false' * @throws IllegalArgumentException if the booleanStr is not a valid boolean */ public static boolean toBoolean(@Nullable final String booleanStr) { if (!isValid(booleanStr)) { throw new IllegalArgumentException(booleanStr + ExceptionValues.EXCEPTION_DELIMITER + ExceptionValues.INVALID_BOOLEAN_VALUE); } return BooleanUtils.toBoolean(getLowerCaseString(booleanStr)); }
private static List<String> validateCommonSqlInputs(String dbServerName, String dbType, String username, String password, String instance, String dbPort, String database, String authenticationType, String trustAllRoots, String trustStore, String trustStorePassword, String resultSetType, String resultSetConcurrency, String authLibraryPath) { final List<String> validationList = new ArrayList<>(); validateDbType(dbType, validationList); validateNoneEmpty(dbServerName, INVALID_DB_SERVER_NAME, validationList); if (!(AUTH_WINDOWS.equalsIgnoreCase(authenticationType) && MSSQL_DB_TYPE.equalsIgnoreCase(dbType))) { validateNoneEmpty(username, INVALID_USERNAME, validationList); validateNoneEmpty(password, INVALID_PASSWORD, validationList); } validateTrustAllRoots(trustAllRoots, validationList); validateResultSetType(resultSetType, validationList); validateResultSetConcurrency(resultSetConcurrency, validationList); validateDbPort(dbPort, validationList); if (isValidDbType(dbType)) { validateInstance(instance, dbType, validationList); validateDbName(database, dbType, validationList); validateAuthType(authenticationType, dbType, validationList); validateAuthLibraryPath(authenticationType, dbType, authLibraryPath, validationList); } if (BooleanUtilities.isValid(trustAllRoots)) { validateTrustAllRootsRequire(BooleanUtilities.toBoolean(trustAllRoots), trustStore, trustStorePassword, validationList); } return validationList; }
/** * Given a boolean in string format, it checks if it's 'true' or 'false' (case insensitive) * * @param booleanStr the string to check * @return true if booleanStr is 'true' or 'false' otherwise false */ public static boolean isValid(@Nullable final String booleanStr) { if (StringUtils.isBlank(booleanStr)) { return false; } final String lowerCaseBoolean = getLowerCaseString(booleanStr); return lowerCaseBoolean.equals(BooleanValues.TRUE) || lowerCaseBoolean.equals(BooleanValues.FALSE); }
/** * Given a boolean in string format, it checks if it's 'true' or 'false' (case insensitive) * * @param booleanStr the string to check * @return true if booleanStr is 'true' or 'false' otherwise false */ public static boolean isValid(@Nullable final String booleanStr) { if (StringUtils.isBlank(booleanStr)) { return false; } final String lowerCaseBoolean = getLowerCaseString(booleanStr); return lowerCaseBoolean.equals(BooleanValues.TRUE) || lowerCaseBoolean.equals(BooleanValues.FALSE); }
private static void validateIgnoreCase(final String ignoreCase, final List<String> validationList) { if (!BooleanUtilities.isValid(ignoreCase)) { validationList.add(String.format(INVALID_IGNORE_CASE, ignoreCase)); } }
/** * If the booleanStr is a valid boolean (see isValid) it returns the boolean value, otherwise it throws an exception * * @param booleanStr the string to convert to boolean * @return true if the booleanStr is 'true', false if it's 'false' * @throws IllegalArgumentException if the booleanStr is not a valid boolean */ public static boolean toBoolean(@Nullable final String booleanStr) { if (!isValid(booleanStr)) { throw new IllegalArgumentException(booleanStr + ExceptionValues.EXCEPTION_DELIMITER + ExceptionValues.INVALID_BOOLEAN_VALUE); } return BooleanUtils.toBoolean(getLowerCaseString(booleanStr)); }
/** * If the string is null or empty string, it returns the defaultValue otherwise it returns the boolean value (see tooBoolean) * * @param booleanStr the string to convert to boolean * @param defaultValue the default value if the string is empty or null * @return true if the booleanStr is 'true', false if it's 'false' * @throws IllegalArgumentException if the booleanStr is not a valid boolean */ public static boolean toBoolean(@Nullable final String booleanStr, final boolean defaultValue) { return StringUtils.isNoneEmpty(booleanStr) ? toBoolean(booleanStr) : defaultValue; } }
public Validator validateBoolean(@NotNull final String booleanValue, @NotNull final String inputName) { if (!isValid(booleanValue)) { errorList.add(format("[%s]: Invalid boolean value!", inputName)); } return this; }
.dbUrl(defaultIfEmpty(dbURL, EMPTY)) .sqlCommand(command) .trustAllRoots(BooleanUtilities.toBoolean(trustAllRoots)) .trustStore(trustStore) .trustStorePassword(defaultIfEmpty(trustStorePassword, EMPTY))
public Validator validateBoolean(@NotNull final String booleanValue, @NotNull final String inputName) { if (!isValid(booleanValue)) { errorList.add(format("[%s]: Invalid boolean value!", inputName)); } return this; } }
trim = defaultIfBlank(trim, BooleanValues.TRUE); final boolean validTrim = toBoolean(trim);
public Validator validateBoolean(@NotNull final String booleanValue, @NotNull final String inputName) { if (!isValid(booleanValue)) { errorList.add(format("[%s]: Invalid boolean value!", inputName)); } return this; }
final boolean async = toBoolean(asyncStr); final int timeout = Integer.parseInt(timeoutStr); final int pollingInterval = Integer.parseInt(pollingIntervalStr);
/** * If enforcedBoolean is "true" and string input is: null, empty, many empty chars, TrUe, tRuE... but not "false" * then returns "true". * If enforcedBoolean is "false" and string input is: null, empty, many empty chars, FaLsE, fAlSe... but not "true" * then returns "false" * This behavior is needed for inputs like: "imageNoReboot" when we want them to be set to "true" disregarding the * value provided (null, empty, many empty chars, TrUe, tRuE) except the case when is "false" * * @param input String to be evaluated. * @param enforcedBoolean Enforcement boolean. * @return A boolean according with above description. */ public static boolean getEnforcedBooleanCondition(String input, boolean enforcedBoolean) { return (enforcedBoolean) ? isValid(input) == parseBoolean(input) : parseBoolean(input); }
/** * If enforcedBoolean is "true" and string input is: null, empty, many empty chars, TrUe, tRuE... but not "false" * then returns "true". * If enforcedBoolean is "false" and string input is: null, empty, many empty chars, FaLsE, fAlSe... but not "true" * then returns "false" * This behavior is needed for inputs like: "imageNoReboot" when we want them to be set to "true" disregarding the * value provided (null, empty, many empty chars, TrUe, tRuE) except the case when is "false" * * @param input String to be evaluated. * @param enforcedBoolean Enforcement boolean. * @return A boolean according with above description. */ private static boolean getEnforcedBooleanCondition(String input, boolean enforcedBoolean) { return (enforcedBoolean) ? isValid(input) == Boolean.parseBoolean(input) : Boolean.parseBoolean(input); } }
.strDelim(delimiter) .sqlCommands(getSqlCommands(sqlCommands, scriptFileName, delimiter)) .trustAllRoots(toBoolean(trustAllRoots)) .trustStore(trustStore) .trustStorePassword(trustStorePassword)
public Validator validateBooleanList(@NotNull final String booleanValueList, @NotNull final String inputName, @NotNull final String delimiter) { for (String value : booleanValueList.split(delimiter)) { if (!isValid(value)) { errorList.add(format("[%s]: Invalid boolean value - [%s].", inputName, value)); } } return this; }