class ObjectiveService {

  @Transactional
  public KeyResult createKeyResult(Long objectiveId, KeyResult keyResult, User user)
      throws KeyResultOverflowException {
    Objective referencedObjective = findById(objectiveId);
    throwIfKeyResultLimitIsHit(referencedObjective);
    throwIfCycleForObjectiveIsClosed(referencedObjective);

    for (KeyResult otherKeyResult : referencedObjective.getKeyResults()) {
      otherKeyResult.setSequence(otherKeyResult.getSequence() + 1);
      keyResultRepository.save(otherKeyResult);
    }
    keyResult.setParentObjective(referencedObjective);
    keyResult = keyResultRepository.save(keyResult);
    logger.info(
        "Created Key Result "
            + keyResult.getName()
            + " in Objective "
            + referencedObjective.getName()
            + "(id:"
            + objectiveId
            + ").");
    activityService.createActivity(user, keyResult, Action.CREATED);
    return keyResult;
  }

  @Autowired public  ObjectiveService(
      ParentService parentService,
      ObjectiveRepository objectiveRepository,
      KeyResultRepository keyResultRepository,
      ActivityService activityService,
      EntityCrawlerService entityCrawlerService,
      ConfigurationService configurationService,
      @Qualifier("okrUnitServiceUsers") OkrUnitServiceUsers<OkrChildUnit> unitService);

}