Skip to content

Commit

Permalink
custom log data key-value pairs are injected multiple times per opera…
Browse files Browse the repository at this point in the history
…tion (DAT-15572) (#4605)
  • Loading branch information
StevenMassaro committed Aug 15, 2023
1 parent 1678d5a commit 9cc5697
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 24 deletions.
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

## template of standalone object for all commands
liquibase.userMetadata:
- outputTologlevel: INFO
data:
- data:
FINDME: "example custom log data"
teamsize: 3
members:
Expand All @@ -24,12 +23,10 @@ liquibase.userMetadata:
## By specifying the command, these objects will be added only
## to the logs of the update command, in this example.
liquibase.command.update:
- outputToLoglevel: INFO
data:
- data:
awsRegion: "us-east"
deploymentlead: "name@example.com"
- outputToLogLevel: FINE
excludeData:
- excludeData:
- liquibaseTargetUrl
- commandLabelFilter
- commandContextFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

## template of standalone object for all commands
liquibase.userMetadata:
- outputTologlevel: INFO
data:
- data:
FINDME: "example custom log data"
teamsize: 3
members:
Expand All @@ -24,12 +23,10 @@ liquibase.userMetadata:
## By specifying the command, these objects will be added only
## to the logs of the update command, in this example.
liquibase.command.update:
- outputToLoglevel: INFO
data:
- data:
awsRegion: "us-east"
deploymentlead: "name@example.com"
- outputToLogLevel: FINE
excludeData:
- excludeData:
- liquibaseTargetUrl
- commandLabelFilter
- commandContextFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

## template of standalone object for all commands
liquibase.userMetadata:
- outputTologlevel: INFO
data:
- data:
FINDME: "example custom log data"
teamsize: 3
members:
Expand All @@ -24,12 +23,10 @@ liquibase.userMetadata:
## By specifying the command, these objects will be added only
## to the logs of the update command, in this example.
liquibase.command.update:
- outputToLoglevel: INFO
data:
- data:
awsRegion: "us-east"
deploymentlead: "name@example.com"
- outputToLogLevel: FINE
excludeData:
- excludeData:
- liquibaseTargetUrl
- commandLabelFilter
- commandContextFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

## template of standalone object for all commands
liquibase.userMetadata:
- outputTologlevel: INFO
data:
- data:
FINDME: "example custom log data"
teamsize: 3
members:
Expand All @@ -24,12 +23,10 @@ liquibase.userMetadata:
## By specifying the command, these objects will be added only
## to the logs of the update command, in this example.
liquibase.command.update:
- outputToLoglevel: INFO
data:
- data:
awsRegion: "us-east"
deploymentlead: "name@example.com"
- outputToLogLevel: FINE
excludeData:
- excludeData:
- liquibaseTargetUrl
- commandLabelFilter
- commandContextFilter
Expand Down

0 comments on commit 9cc5697

Please sign in to comment.