
org.openfact.provider.ProviderConfigurationBuilder Maven / Gradle / Ivy
package org.openfact.provider;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
/**
* Builds a list of ProviderConfigProperty instances.
*/
public class ProviderConfigurationBuilder {
private List properties = new LinkedList<>();
private ProviderConfigurationBuilder() {
}
public static ProviderConfigurationBuilder create() {
return new ProviderConfigurationBuilder();
}
public ProviderConfigPropertyBuilder property() {
return new ProviderConfigPropertyBuilder();
}
public ProviderConfigurationBuilder property(ProviderConfigProperty property) {
properties.add(property);
return this;
}
public ProviderConfigurationBuilder property(String name, String label, String helpText, String type, Object defaultValue, List options, boolean secret) {
ProviderConfigProperty property = new ProviderConfigProperty(name, label, helpText, type, defaultValue);
property.setOptions(options);
property.setSecret(secret);
properties.add(property);
return this;
}
public ProviderConfigurationBuilder property(String name, String label, String helpText, String type, Object defaultValue, List options) {
ProviderConfigProperty property = new ProviderConfigProperty(name, label, helpText, type, defaultValue);
property.setOptions(options);
properties.add(property);
return this;
}
/**
* Create the list.
*
* @return
*/
public List build() {
return properties;
}
public class ProviderConfigPropertyBuilder {
private String name;
private String label;
private String helpText;
private String type;
private Object defaultValue;
private List options;
private boolean secret;
public ProviderConfigPropertyBuilder name(String name) {
this.name = name;
return this;
}
/**
* Label that will be shown for this configuration property in the admin console
*
* @param label
* @return
*/
public ProviderConfigPropertyBuilder label(String label) {
this.label = label;
return this;
}
/**
* Help text that will be shown for this configuration property in the admin console
* when you hover over the tooltip
*
* @param helpText
* @return
*/
public ProviderConfigPropertyBuilder helpText(String helpText) {
this.helpText = helpText;
return this;
}
/**
* Property type. i.e. boolean, string.
*
* @param type
* @return
* @see ProviderConfigProperty
*/
public ProviderConfigPropertyBuilder type(String type) {
this.type = type;
return this;
}
/**
* Default value that will be shown when configuring this property for the first time
*
* @param defaultValue
* @return
*/
public ProviderConfigPropertyBuilder defaultValue(Object defaultValue) {
this.defaultValue = defaultValue;
return this;
}
/**
* If configuring a list type, these are the options you can choose from.
*
* @param options
* @return
*/
public ProviderConfigPropertyBuilder options(String... options) {
this.options = Arrays.asList(options);
return this;
}
/**
* If configuring a list type, these are the options you can choose from.
*
* @param options
* @return
*/
public ProviderConfigPropertyBuilder options(List options) {
this.options = options;
return this;
}
/**
* If turned on, this property is only writable and never readable.
* This is useful for things like passwords where you never want an admin
* to be able to see what the password is.
*
* @param secret
* @return
*/
public ProviderConfigPropertyBuilder secret(boolean secret) {
this.secret = secret;
return this;
}
/**
* Add the current property, and start building the next one
*
* @return
*/
public ProviderConfigurationBuilder add() {
ProviderConfigProperty property = new ProviderConfigProperty();
property.setName(name);
property.setLabel(label);
property.setHelpText(helpText);
property.setType(type);
property.setDefaultValue(defaultValue);
property.setOptions(options);
property.setSecret(secret);
ProviderConfigurationBuilder.this.properties.add(property);
return ProviderConfigurationBuilder.this;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy