class SplitReplaceOnValueAction implements BaseUpgradeTaskTo_2_1_0_PE {

    @Override
    public void run() {

        final Stream<PreparationActions> preparationActionsStream =
                preparationRepository.list(PreparationActions.class).filter(p -> p.getActions().stream().anyMatch(
                        a -> REPLACE_ON_VALUE.equals(a.getName()) && CELL.equals(a.getParameters().get("scope"))));

        AtomicLong actionsUpdated = new AtomicLong(0);
        preparationActionsStream.forEach(currentPrepActions -> {
            final List<Action> actions = currentPrepActions.getActions();
            boolean updatePrepActions = false;
            for (Action action : actions) {
                final Map<String, String> parameters = action.getParameters();
                // only deal with replace_on_value with scope cell
                if (REPLACE_ON_VALUE.equals(action.getName()) && CELL.equals(parameters.get("scope"))) {
                    // rename action
                    action.setName(REPLACE_CELL_VALUE);
                    // update parameters
                    updateActionParameters(parameters);
                    updatePrepActions = true;
                }
            }
            // only save updated preparation actions
            if (updatePrepActions) {
                preparationRepository.add(currentPrepActions);
                actionsUpdated.getAndIncrement();
            }
        });

        LOGGER.info("'Replace On Value' implementations were successfully split, {} action(s) updated", actionsUpdated);

    }

}