ComponentValidatesConfiguration

Implement to support custom validation of component configuration

Add this interface to your component to add support for component configuration validation by your service.

Applies to: All component types

Source: Github

Example:

package my.org.components;

import io.dexi.service.AppContext;
import io.dexi.service.components.AppComponent;
import io.dexi.service.components.ComponentValidatesConfiguration;
import io.dexi.service.components.DataSourceAppComponent;
import io.dexi.service.exceptions.UserErrorException;
import io.dexi.service.utils.ResultStream;
import my.org.data.MyAppConfig;
import my.org.data.MyComponentConfig;
import org.apache.commons.lang.StringUtils;

@AppComponent("read-data-from-my-app")
public class MyAppDataSourceAppComponent implements DataSourceAppComponent<MyAppConfig, MyComponentConfig>,
                                                    ComponentValidatesConfiguration<MyAppConfig, MyComponentConfig> {


    @Override
    public void read(AppContext<MyAppConfig, MyComponentConfig> ctxt, String offset, int batchSize, ResultStream resultStream)  {
        /* ... component implementation ... */
    }

    @Override
    public void validate(AppContext<MyAppConfig, MyComponentConfig> ctxt) {
        final MyComponentConfig componentConfig = ctxt.getComponentConfig();
        
        if (StringUtils.isBlank(componentConfig.getMyTestProperty())) {
            throw new UserErrorException("myTestProperty is required!");
        }
    }

    @Override
    public Class<MyComponentConfig> getComponentConfigClass() {
        return MyComponentConfig.class;
    }
}
components:
- name: read-data-from-my-app
  type: data-source
  title: Read data from my app
  specification:
    validate: # Add the validation endpoint here
      url: "${baseUrl}/dexi/component/support/validate"
      method: POST
    endpoint:
      url: "${baseUrl}/dexi/data/source/read"
      method: POST
    outputs:
      id: 
        type: number
        title: ID