Example #1
0
  public CompetitionRankingVO getCompetitionRanking(Long competitionid) {
    Competition competition = em.find(Competition.class, competitionid);
    if (competition == null) {
      return null;
    }

    List<Athlete> list = getAthletesWithCompetionResults(competitionid);

    CompetitionRankingVO ranking = new CompetitionRankingVO();
    ranking.setCompetition(competition);

    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()) {
      CompetitionRankingCategoryVO rc = new CompetitionRankingCategoryVO();
      Category c = entry.getKey();
      c.setEvents(null);
      rc.setCategory(c);
      rc.setAthletes(filterAndSortByTotalPoints(competition, entry.getValue()));
      ranking.getCategories().add(rc);
    }
    Collections.sort(ranking.getCategories());
    return ranking;
  }