class DatabaseFDFlowManager extends BaseService implements FDFlowManager {

    @Override
    public void retainPublishEvents(final String flowId) {
        if (StringUtils.isBlank(flowId)) {
            throw new IllegalArgumentException("Flow id cannot be null or blank");
        }

        final Optional<FDFlowEntity> flowEntity = flowRepository.findById(flowId);
        if (!flowEntity.isPresent()) {
            throw new ResourceNotFoundException("No flow exists with the provided flow id");
        }

        final Optional<FDFlowEventEntity> latestPublishEvent = flowEventRepository.findFirstByFlowAndEventTypeOrderByFlowRevisionDesc(
                flowEntity.get(), FDFlowEventType.FLOW_PUBLISHED);
        if (!latestPublishEvent.isPresent()) {
            throw new IllegalArgumentException("Must have at least one publish event to retain");
        }

        // On a publish we remove the local history except for the publish events
        flowEventRepository.deleteByFlowAndEventTypeNot(flowEntity.get(), FDFlowEventType.FLOW_PUBLISHED);
    }

    @Autowired public  DatabaseFDFlowManager(final FDFlowRepository flowRepository,
                                 final FDFlowEventRepository flowEventRepository,
                                 final OptionalModelMapper modelMapper,
                                 final ObjectMapper objectMapper,
                                 final Validator validator);

}