Esempio n. 1
0
  private List<Athlete> getAthletesWithCompetionResults(Long competitionid) {
    Query q =
        em.createNativeQuery(
            "select distinct a.* from athlete a join result r on a.id = r.athlete_id and r.competition_id = ?",
            Athlete.class);
    q.setParameter(1, competitionid);
    List<Athlete> as = q.getResultList();

    TypedQuery<Result> tq = em.createNamedQuery("Result.findByCompetition", Result.class);
    tq.setParameter("competitionId", competitionid);
    List<Result> results = tq.getResultList();
    Map<Long, List<Result>> map = new HashMap<>();
    for (Result r : results) {
      List<Result> entry = map.get(r.getAthlete_id());
      if (entry != null) {
        entry.add(r);
      } else {
        List<Result> list = new ArrayList<>();
        list.add(r);
        map.put(r.getAthlete_id(), list);
      }
    }

    for (Athlete a : as) {
      a.setResults(map.get(a.getId()));
    }
    return as;
  }
Esempio n. 2
0
  private List<Athlete> filterAndSortByTotalPoints(Competition competition, List<Athlete> list) {
    for (Athlete a : list) {
      a.setCategory(null);

      List<Result> rs = new ArrayList<>();
      for (Result r : a.getResults()) {
        if (r.getCompetition().equals(competition)) {
          rs.add(r);
        }
      }
      a.setResults(rs);
    }
    Collections.sort(list, new AthleteCompetitionResultComparator(competition));
    return list;
  }
Esempio n. 3
0
 private List<Athlete> filterAndSort(Series series, List<Athlete> list) {
   List<Athlete> filtered = new ArrayList<>();
   for (Athlete athlete : list) {
     if (athlete.getCategory().getEvents().size() * series.getCompetitions().size()
         == athlete.getResults().size()) {
       athlete.setCategory(null);
       List<Result> rs = new ArrayList<>();
       for (Result r : athlete.getResults()) {
         rs.add(r);
       }
       athlete.setResults(rs);
       filtered.add(athlete);
     }
   }
   Collections.sort(filtered, new AthleteSeriesResultComparator(series));
   return filtered;
 }
Esempio n. 4
0
  public SeriesRankingVO getSeriesRanking(Long seriesId) {
    Series series = em.find(Series.class, seriesId);
    if (series == null) {
      return null;
    }
    TypedQuery<Athlete> q = em.createNamedQuery("Athlete.findBySeries", Athlete.class);
    q.setParameter("series_id", seriesId);
    List<Athlete> list = q.getResultList();
    for (Athlete a : list) {
      TypedQuery<Result> tq = em.createNamedQuery("Result.findByAthleteAndSeries", Result.class);
      tq.setParameter("athleteId", a.getId());
      tq.setParameter("seriesId", seriesId);
      List<Result> results = tq.getResultList();
      a.setResults(results);
    }

    TypedQuery<Competition> qc = em.createNamedQuery("Competition.findAll", Competition.class);
    qc.setParameter("series_id", seriesId);
    List<Competition> cs = qc.getResultList();
    series.setCompetitions(cs);

    SeriesRankingVO ranking = new SeriesRankingVO();
    ranking.setSeries(series);

    Map<Category, List<Athlete>> map = new HashMap<>();
    for (Athlete a : list) {
      List<Athlete> as = map.get(a.getCategory());
      if (as == null) {
        as = new ArrayList<>();
      }
      as.add(a);
      map.put(a.getCategory(), as);
    }
    for (Map.Entry<Category, List<Athlete>> entry : map.entrySet()) {
      SeriesRankingCategoryVO rc = new SeriesRankingCategoryVO();
      Category c = entry.getKey();
      rc.setCategory(c);
      rc.setAthletes(filterAndSort(series, entry.getValue()));
      ranking.getCategories().add(rc);
    }
    Collections.sort(ranking.getCategories());
    return ranking;
  }