Example #1
0
  public byte[] createDiploma(Long competitionId, Locale locale) {
    CompetitionRankingVO ranking = getCompetitionRanking(competitionId);
    if (ranking == null) {
      return null;
    }
    Series series = get(Series.class, ranking.getCompetition().getSeries_id());

    Diplomas diploma = new Diplomas(ranking, series.getLogo(), locale);
    return diploma.create();
  }
Example #2
0
  public byte[] createEmptySheets(Long categoryid, Locale locale) {
    Category category = em.find(Category.class, categoryid);
    if (category == null) {
      throw new IllegalArgumentException();
    }
    Series series = em.find(Series.class, category.getSeries_id());
    if (series == null) {
      throw new IllegalArgumentException();
    }
    Athlete template = new Athlete();
    template.setCategory(category);

    Sheets sheet = new Sheets(template, series.getLogo(), locale);
    return sheet.create();
  }
Example #3
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;
  }
Example #4
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;
 }