class FlowLogDBService implements FlowLogService {

    public void cancelTooOldTerminationFlowForResource(Long resourceId, long olderThan) {
        Set<FlowLogIdWithTypeAndTimestamp> allRunningFlowIdsByResourceId = flowLogRepository.findAllRunningFlowLogByResourceId(resourceId);
        allRunningFlowIdsByResourceId.stream()
                .filter(flowLog -> applicationFlowInformation.getTerminationFlow().stream()
                        .map(Class::getName)
                        .anyMatch(terminationFlowClassName -> terminationFlowClassName.equals(flowLog.getFlowType().getName())))
                .filter(flowlog -> flowlog.getCreated() < olderThan)
                .findFirst().ifPresent(flowLog -> {
            try {
                LOGGER.info("Cancel flow [{}] for resource [{}] because it's too old", flowLog.getFlowId(), resourceId);
                cancel(resourceId, flowLog.getFlowId());
            } catch (TransactionExecutionException e) {
                LOGGER.error("Can't cancel termination flow: {}", flowLog.getFlowId(), e);
            }
        });
    }

}