ActivationHandler

Required to implement a dexi app. Implements validation for activation configuration - as well as optional hooks for listening for activations and deactivations from users.

Source: Github

Example:

package my.org.handlers;

import io.dexi.service.exceptions.ActivationException;
import io.dexi.service.exceptions.UserErrorException;
import io.dexi.service.handlers.ActivationHandler;
import my.org.data.MyAppConfig;
import my.org.data.SomeRepository;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

@Component
public class MyAppActivationHandler implements ActivationHandler<MyAppConfig> {
    
    private final SomeRepository someRepository;

    public MyAppActivationHandler(SomeRepository someRepository) {
        this.someRepository = someRepository;
    }

    @Override
    public void validate(MyAppConfig activationConfig) throws ActivationException {
        if (StringUtils.isBlank(activationConfig.getMyTestProperty())) {
            throw new UserErrorException("myTestProperty is required");
        }
    }

    @Override
    public void activate(String activationId, MyAppConfig activationConfig) throws ActivationException {
        //Keep track of activations in internal repository
        someRepository.insert(activationId, activationConfig);
    }

    @Override
    public void deactivate(String activationId) throws ActivationException {
        //Remove previous activations from internal repository
        someRepository.remove(activationId);
    }

    @Override
    public Class<MyAppConfig> getActivationConfigClass() {
        return MyAppConfig.class;
    }
}