class KeyResultService {

  @Transactional
  public void deleteKeyResult(Long keyResultId, User user) {
    KeyResult referencedKeyResult = keyResultRepository.findByIdOrThrow(keyResultId);
    throwIfCycleOfKeyResultIsClosed(referencedKeyResult);

    if (referencedKeyResult.getParentObjective() != null) {
      Collection<KeyResult> keyResultList =
          referencedKeyResult.getParentObjective().getKeyResults();
      for (KeyResult keyResult : keyResultList) {
        if (keyResult.getSequence() > referencedKeyResult.getSequence()) {
          keyResult.setSequence(keyResult.getSequence() - 1);
          keyResultRepository.save(keyResult);
        }
      }
    }

    keyResultRepository.deleteById(keyResultId);
    activityService.createActivity(user, referencedKeyResult, Action.DELETED);
  }

  @Autowired public  KeyResultService(
      KeyResultRepository keyResultRepository,
      NoteRepository noteRepository,
      ActivityService activityService,
      EntityCrawlerService entityCrawlerService,
      ObjectiveService objectiveService);

}