-
Notifications
You must be signed in to change notification settings - Fork 2
Added custom message property #1
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
base: main
Are you sure you want to change the base?
Conversation
@Name(PluginConstants.PROPERTY_NAME_CUSTOM_MESSAGE) | ||
@Description("Custom message") | ||
@Nullable | ||
public String message=PluginConstants.PROPERTY_CONFIG_DEFAULT_MESSAGE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never set values directly using =
in config files, config values are set by platform based on user input on web UI.
public HelloWorldBatchSourceConfig(){ | ||
if(message==null || message.isEmpty()) | ||
{ | ||
message=PluginConstants.PROPERTY_CONFIG_DEFAULT_MESSAGE; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment here , this can be removed !
@@ -21,5 +36,6 @@ public void validate(FailureCollector failureCollector) { | |||
public int getFrequency() { | |||
return frequency == null ? PluginConstants.PROPERTY_DEFAULT_FREQUENCY : frequency; | |||
} | |||
public String getMessage(){ return (message == null || message.isEmpty()) ? PluginConstants.PROPERTY_CONFIG_DEFAULT_MESSAGE: message; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix formatting !
@@ -5,8 +5,10 @@ | |||
public final class PluginConstants { | |||
public static final String PLUGIN_NAME = "HelloWorld"; | |||
public static final String PROPERTY_NAME_FREQUENCY = "frequency"; | |||
public static final String PROPERTY_NAME_CUSTOM_MESSAGE="Custom Message"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable name can be better, this is too generic !
public static final String PROPERTY_CONFIG_FREQUENCY = "cdap.hello.world.config.frequency"; | ||
public static final int PROPERTY_DEFAULT_FREQUENCY = 1; | ||
public static final String PROPERTY_CONFIG_DEFAULT_MESSAGE = "Hello world, this is a custom message"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep the default message same as before for backwards compatibility!
@@ -13,6 +13,7 @@ public class HelloWorldInputFormatProvider implements InputFormatProvider { | |||
public HelloWorldInputFormatProvider(HelloWorldBatchSourceConfig config) { | |||
configMap = new HashMap<>(); | |||
configMap.put(PluginConstants.PROPERTY_CONFIG_FREQUENCY, Integer.toString(config.getFrequency())); | |||
configMap.put(PluginConstants.PROPERTY_CONFIG_DEFAULT_MESSAGE, config.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a key, although not required it's best to follow the standard, eg : cdap.hello.world.config.frequency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one can be cdap.hello.world.config.message
Re-base with main and resolve conflicts ! |
Resolve merge conflicts and you are missing changes in your |
Also lets add a validation the message should not contain |
@Name(PluginConstants.PROPERTY_NAME_USER_MESSAGE) | ||
@Description("Custom message") | ||
@Nullable | ||
public String message; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep these consistent, userMessage is more appropriate.
configMap.put(PluginConstants.PROPERTY_CONFIG_FREQUENCY, Integer.toString(config.getFrequency())); | ||
|
||
configMap.put(PluginConstants.PROPERTY_CONFIG_KEY_FREQUENCY, Integer.toString(config.getFrequency())); | ||
configMap.put(PluginConstants.PROPERTY_CONFIG_KEY_MESSAGE, config.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PROPERTY_CONFIG_KEY_USER_MESSAGE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done sir
Added custom message property and made it Nullable to avoid validation error (initialized it to a default message)