class ObjectiveService {

  @Transactional
  public Objective updateObjective(Objective updatedObjective, User user) {
    Objective referencedObjective = findById(updatedObjective.getId());

    if (entityCrawlerService.getCycleOfObjective(referencedObjective).getCycleState()
        == CycleState.CLOSED) {
      referencedObjective.setReview(updatedObjective.getReview());
    } else {
      referencedObjective.setName(updatedObjective.getName());
      referencedObjective.setDescription(updatedObjective.getDescription());
      referencedObjective.setRemark(updatedObjective.getRemark());
      referencedObjective.setContactPersonId(updatedObjective.getContactPersonId());
      referencedObjective.setActive(updatedObjective.isActive());

      Objective newParentObjective = null;
      if (updatedObjective.hasParentObjective()) {
        newParentObjective = findById(updatedObjective.getParentObjective().getId());
        parentService.validateParentObjective(referencedObjective, newParentObjective);
      }
      referencedObjective.setParentObjective(newParentObjective);
    }

    referencedObjective = objectiveRepository.save(referencedObjective);

    logger.info(
        "Updated objective: "
            + updatedObjective.getName()
            + "(id:"
            + updatedObjective.getId()
            + ").");
    activityService.createActivity(user, referencedObjective, Action.EDITED);
    return referencedObjective;
  }

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

}