Registering Repository Event Listeners

You’re able to add a custom logic before or after specific operations execution (like creation, update or deletion of the entity) using Spring Data AbstractRepositoryEventListener.

Firstly, create your domain entity repository event listener:

public class SimpleRepositoryEventListener extends AbstractRepositoryEventListener<Customer> {

    private final Logger logger = LoggerFactory.getLogger(SimpleRepositoryEventListener.class);

    @Autowired
    private CustomerService customerService;

    @Override
    public void onBeforeSave(Customer customer) {
        final boolean vipCustomer = customerService.isVIP(customer);

        logger.info("#handleBeforeSave: Customer {} is VIP: {}", customer, vipCustomer);
    }

    @Override
    public void onAfterSave(Customer customer) {
        logger.info("#handleAfterSave: Hello");
    }
}

After adding all the logic you need, just register it in your AdministrationConfiguration:

public class CustomerAdministration extends AdministrationConfiguration<Customer> {

    public EntityMetadataConfigurationUnit configuration(EntityMetadataConfigurationUnitBuilder configurationBuilder) {
        return configurationBuilder
                .nameField("firstname")
                .singularName("Customer")
                .pluralName("Customers")
                .repositoryEventListener(SimpleRepositoryEventListener.class)
                .build();
    }

As a result, your custom event listener will be triggered for all the operations performed on the entity you declared it for.