class KeyResultService {

  @Transactional
  public void updateSequence(Long objectiveId, Collection<Long> sequenceList, User user)
      throws Exception {
    Objective objective = objectiveService.findById(objectiveId);
    throwIfSequenceInvalid(objective, sequenceList);

    ArrayList<Long> sequenceArray = new ArrayList<>(sequenceList);
    objective
        .getKeyResults()
        .forEach(
            keyResult -> {
              int currentOrder = sequenceArray.indexOf(keyResult.getId());
              keyResult.setSequence(currentOrder);
              keyResultRepository.save(keyResult);
              activityService.createActivity(user, keyResult, Action.EDITED);
              logger.info("Update sequence of KeyResult with id " + keyResult.getId());
            });
  }

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

}