Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom log data key-value pairs are injected multiple times per operation (DAT-15572) #4605

Merged
merged 6 commits into from
Aug 15, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package liquibase.util;

import java.util.Arrays;

public class ValueHandlerUtil {
/**
* Get the valid enum value from a configuration parameter if possible.
*
* @param enumClass the enum to use
* @param input the configuration input to search the enumClass
* @param parameterName the name to report to the user if no valid enum values are found
* @return the enum value or null
*/
public static <T extends Enum<T>> T getEnum(Class<T> enumClass, Object input, String parameterName) {
if (input == null) {
return null;
}
if (input instanceof String) {
String stringInput = (String) input;

if (Arrays.stream(enumClass.getEnumConstants()).noneMatch(enumValue -> enumValue.toString().equalsIgnoreCase(stringInput))) {
throw new IllegalArgumentException(String.format("WARNING: The %s value '%s' is not valid. Valid values include: '%s'",
parameterName.toLowerCase(),
stringInput,
StringUtil.join(enumClass.getEnumConstants(), "', '", Object::toString)));
}
return Enum.valueOf(enumClass, stringInput.toUpperCase());
} else if (enumClass.isAssignableFrom(input.getClass())) {
return enumClass.cast(input);
} else {
return null;
}
}

public static Boolean booleanValueHandler(Object input) {
if (input == null) {
return true;
}
if (input instanceof Boolean) {
return (Boolean) input;
}
String verboseString = (String) input;
if (verboseString.equalsIgnoreCase("true") || verboseString.equalsIgnoreCase("false")) {
return Boolean.valueOf(verboseString);
}
String messageString =
"\nWARNING: The input '" + verboseString + "' is not valid. Options: 'true' or 'false'.";
throw new IllegalArgumentException(messageString);
}
}