Skip to content
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

feature: Support to register custom condition types #103

Open
rameshmalla opened this issue Jan 29, 2024 · 0 comments
Open

feature: Support to register custom condition types #103

rameshmalla opened this issue Jan 29, 2024 · 0 comments

Comments

@rameshmalla
Copy link
Contributor

rameshmalla commented Jan 29, 2024

Is your feature request related to a problem? Please describe.
By default, baigan supports the following conditions which can be used in the configurations.

  • Equals
  • In
  • EndsWith

To introduce a custom conditions, such as for gradual rollout of a feature, it is required to make changes directly to the baigan source code. As a result, impacting extension capability of baigan.

Describe the solution you'd like
The proposal is to make use of jackson polymorphic deserialization, by which baigan could provide the capability to register condition types directly to the objectmapper. This would allow the client to define their own custom condition types and register the relevant types while initializing configuration repository

Example

class StartsWith extends ConditionType{

    private final String startsWithValue;

    @JsonCreator
    public StartsWith(@JsonProperty("startsWithValue") final String startsWithValue) {
        this.startsWithValue = startsWithValue;
    }
    @Override
    public boolean eval(@Nullable final String paramValue) {
        return StringUtils.startsWithIgnoreCase(paramValue, startsWithValue);
    }
}

class Application{

        @Bean
        ConfigurationRepository configurationRepository(RepositoryFactory repositoryFactory) {

            final ObjectMapper objectMapper = new ObjectMapper().configure(FAIL_ON_UNKNOWN_PROPERTIES, false);

            return repositoryFactory.fileSystemConfigurationRepository()
                    .fileName(FileSystemConfigurationContextProviderEnd2EndTest.class.getClassLoader().getResource("test-config.json").getPath())
                    .refreshInterval(CONFIG_REFRESH_INTERVAL)
                    .objectMapper(objectMapper)
                    .conditions(StartsWith.class) // register new condition
                    .build();
        }

}



//somewhere in baigan we can register these condition types.
....
 public void registerConditions(final List<Class<? extends ConditionType>> conditionTypes) {
        registerDefaultConditions();
        conditionTypes.forEach(this.objectMapper::registerSubtypes);
    }

    private void registerDefaultConditions(){
        DEFAULT_CONDITION_TYPES.forEach(this.objectMapper::registerSubtypes);
    }
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

No branches or pull requests

1 participant