-
Notifications
You must be signed in to change notification settings - Fork 5
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?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"; | ||
| 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"; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep the default message same as before for backwards compatibility! |
||
| public static final String PLUGIN_OUT_VALUE = "Hello World!"; | ||
| public static final Schema PLUGIN_OUT_SCHEMA = Schema.recordOf("data", Schema.Field.of("message", Schema.of(Schema.Type.STRING))); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,27 @@ | |
| import io.cdap.cdap.api.plugin.PluginConfig; | ||
| import io.cdap.cdap.etl.api.FailureCollector; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| public class HelloWorldBatchSourceConfig extends PluginConfig { | ||
|
|
||
| @Name(PluginConstants.PROPERTY_NAME_FREQUENCY) | ||
| @Description("Number of times the plugin says hello world.") | ||
| public Integer frequency; | ||
|
|
||
|
|
||
| @Name(PluginConstants.PROPERTY_NAME_CUSTOM_MESSAGE) | ||
| @Description("Custom message") | ||
| @Nullable | ||
| public String message=PluginConstants.PROPERTY_CONFIG_DEFAULT_MESSAGE; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never set values directly using |
||
|
|
||
| public HelloWorldBatchSourceConfig(){ | ||
| if(message==null || message.isEmpty()) | ||
| { | ||
| message=PluginConstants.PROPERTY_CONFIG_DEFAULT_MESSAGE; | ||
| } | ||
| } | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comment here , this can be removed ! |
||
| public void validate(FailureCollector failureCollector) { | ||
| if (frequency != null && frequency < 1) { | ||
| failureCollector.addFailure("Property cannot be lower than 1.", "Use a frequency value of equal to or more than 1.").withConfigProperty(PluginConstants.PROPERTY_NAME_FREQUENCY); | ||
|
|
@@ -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; } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix formatting ! |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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()); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one can be |
||
| } | ||
|
|
||
| @Override | ||
|
|
||
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 !