-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
custom log data key-value pairs are injected multiple times per opera…
…tion (DAT-15572) (#4605)
- Loading branch information
1 parent
1678d5a
commit 9cc5697
Showing
5 changed files
with
62 additions
and
24 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
liquibase-standard/src/main/java/liquibase/util/ValueHandlerUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters