@Override
  @Transactional(readOnly = true)
  public List<SessionExamen> findAllSessions() {
    ValueList currentAnnee = getCurrentScholarYear();

    if (currentAnnee != null) {
      return sessionExamenRepos.findByAnneeScolaireId(currentAnnee.getId());
    } else {
      return new ArrayList<SessionExamen>();
    }
  }
  @Override
  @Transactional(readOnly = true)
  public List<SessionExamen> findSessionByNE(NiveauEtude niveau) {
    ValueList currentAnnee = getCurrentScholarYear();

    if (currentAnnee != null && niveau != null) {
      return sessionExamenRepos.findByNiveauEtude(
          currentAnnee.getId(), niveau.getId(), SessionStatus.OPEN);
    } else {
      return new ArrayList<SessionExamen>();
    }
  }
  @Override
  @Transactional(readOnly = true)
  public List<SessionExamen> findAllSessionsWithStatus(SessionStatus sessionStatus) {
    ValueList currentAnnee = getCurrentScholarYear();

    if (currentAnnee != null) {
      return sessionExamenRepos.findByAnneeScolaireIdAndStatusOrderByNomAsc(
          currentAnnee.getId(), sessionStatus);
    } else {
      return new ArrayList<SessionExamen>();
    }
  }
  @Override
  @Transactional(readOnly = true)
  public List<SessionExamen> findAllSessions(List<Integer> sessionIdList) {
    ValueList currentAnnee = getCurrentScholarYear();

    if (currentAnnee != null) {
      return sessionExamenRepos.findByAnneeScolaireAndStatusList(
          currentAnnee.getId(), sessionIdList); // SessionStatus.OPEN);
    } else {
      return new ArrayList<SessionExamen>();
    }
  }
  private ValueList getCurrentScholarYear() {
    String currentScholarYear = DateUtils.currentYear() + "-" + (DateUtils.currentYear() + 1);
    ValueList scholarYear =
        valueListRepos.findByValueAndValueTypeCode(currentScholarYear, ValueTypeCode.SCHOOL_YEAR);
    if (scholarYear == null) {
      scholarYear = new ValueList();
      scholarYear.setLabel(currentScholarYear);
      scholarYear.setValue(currentScholarYear);
      scholarYear.setValueType(valueTypeRepos.findByCode(ValueTypeCode.BAC_YEAR));

      valueListRepos.save(scholarYear);
    }
    return scholarYear;
  }
 @Override
 @Transactional(readOnly = true)
 public List<SessionExamen> findAllSessionsWithStatusAndAnneeScolaire(
     SessionStatus sessionStatus, ValueList anneeScolaire) {
   if (anneeScolaire == null) {
     anneeScolaire = getCurrentScholarYear();
   }
   return sessionExamenRepos.findByAnneeScolaireIdAndStatusOrderByNomAsc(
       anneeScolaire.getId(), sessionStatus);
 }