Skip to content

Conversation

Krish-cloudsufi
Copy link

Added custom message property and made it Nullable to avoid validation error (initialized it to a default message)

@Name(PluginConstants.PROPERTY_NAME_CUSTOM_MESSAGE)
@Description("Custom message")
@Nullable
public String message=PluginConstants.PROPERTY_CONFIG_DEFAULT_MESSAGE;
Copy link
Owner

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.

Comment on lines 23 to 29
public HelloWorldBatchSourceConfig(){
if(message==null || message.isEmpty())
{
message=PluginConstants.PROPERTY_CONFIG_DEFAULT_MESSAGE;
}
}

Copy link
Owner

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; }
Copy link
Owner

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";
Copy link
Owner

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";
Copy link
Owner

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());
Copy link
Owner

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

Copy link
Owner

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

@psainics
Copy link
Owner

Re-base with main and resolve conflicts !

@psainics
Copy link
Owner

Resolve merge conflicts and you are missing changes in your HelloWorld-batchsource.json

@psainics
Copy link
Owner

Also lets add a validation the message should not contain #

Comment on lines +18 to +21
@Name(PluginConstants.PROPERTY_NAME_USER_MESSAGE)
@Description("Custom message")
@Nullable
public String message;
Copy link
Owner

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());
Copy link
Owner

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done sir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants