Commit 2cd8a858 by Antti Tönkyrä

tournament stuffing

1 parent fd37dc10
package fi.codecrew.moya.facade;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import fi.codecrew.moya.model.PrintedCard_;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.PrintedCard;
@Stateless
@LocalBean
public class TournamentFacade extends IntegerPkGenericFacade<PrintedCard> {
public TournamentFacade() {
super(PrintedCard.class);
}
@EJB
private EventBeanLocal eventbean;
public PrintedCard findByRfid(String uid) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<PrintedCard> cq = cb.createQuery(PrintedCard.class);
Root<PrintedCard> root = cq.from(PrintedCard.class);
cq.where(cb.equal(root.get(PrintedCard_.rfidUid), uid),
cb.equal(root.get(PrintedCard_.event), eventbean.getCurrentEvent()));
return getSingleNullableResult(getEm().createQuery(cq));
}
public PrintedCard findByBarcode(String barcode) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<PrintedCard> cq = cb.createQuery(PrintedCard.class);
Root<PrintedCard> root = cq.from(PrintedCard.class);
cq.where(cb.equal(root.get(PrintedCard_.barcode), barcode),
cb.equal(root.get(PrintedCard_.event), eventbean.getCurrentEvent()));
return getSingleNullableResult(getEm().createQuery(cq));
}
public List<PrintedCard> findAllEnabled(LanEvent currentEvent) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<PrintedCard> cq = cb.createQuery(PrintedCard.class);
Root<PrintedCard> root = cq.from(PrintedCard.class);
cq.where(cb.isTrue(root.get(PrintedCard_.enabled)),
cb.equal(root.get(PrintedCard_.event), eventbean.getCurrentEvent()));
return getEm().createQuery(cq).getResultList();
}
public List<PrintedCard> getCards(EventUser user) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<PrintedCard> cq = cb.createQuery(PrintedCard.class);
Root<PrintedCard> root = cq.from(PrintedCard.class);
cq.where(cb.equal(root.get(PrintedCard_.user), user),
cb.equal(root.get(PrintedCard_.event), eventbean.getCurrentEvent()));
return getEm().createQuery(cq).getResultList();
}
public PrintedCard findLatestByRfidFromAny(String uid) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<PrintedCard> cq = cb.createQuery(PrintedCard.class);
Root<PrintedCard> root = cq.from(PrintedCard.class);
cq.where(cb.equal(root.get(PrintedCard_.rfidUid), uid));
cq.orderBy(cb.desc(root.get(PrintedCard_.printTime)));
TypedQuery<PrintedCard> q = getEm().createQuery(cq);
q.setMaxResults(1);
return getSingleNullableResult(q);
}
}
package fi.codecrew.moya.model;
import fi.codecrew.moya.enums.TournamentStatus;
import fi.codecrew.moya.enums.TournamentType;
import fi.codecrew.moya.model.GenericEntity;
import java.io.Serializable;
......@@ -24,23 +25,43 @@ public class Tournament extends GenericEntity implements Serializable {
@Column(name="talyn_tournament_id", nullable=true)
private Integer talynTournamentId;
@Column(name = "event_id", nullable = false)
private LanEvent lanEvent;
@Column(name="tournament_name")
private String tournamentName;
@Column(name="registration_opens_at")
@Temporal(TemporalType.TIMESTAMP)
private Date registrationOpensAt;
@Column(name="registration_closes_at")
@Temporal(TemporalType.TIMESTAMP)
private Date registrationClosesAt;
@Column(name="begins_at")
@Temporal(TemporalType.TIMESTAMP)
private Date beginsAt;
@Column(name="tournament_type")
@Enumerated(EnumType.STRING)
private TournamentType tournamentType;
@Column(name="tournament_status")
@Enumerated(EnumType.STRING)
private TournamentStatus tournamentStatus;
@JoinColumn(name="tournament_root")
private Match tournamentRoot;
private TournamentMatch tournamentRoot;
@Column(name="players_per_match")
private Integer playersPerMatch;
@Column(name="players_per_team")
private Integer playersPerTeam;
@OneToMany
@OneToMany
@OrderBy("id ASC")
private List<Tournament> subTournaments;
public Tournament() { super(); }
......
package fi.codecrew.moya.model;
import static javax.persistence.FetchType.LAZY;
import fi.codecrew.moya.enums.TournamentType;
import fi.codecrew.moya.model.GenericEntity;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/**
* Entity implementation class for Entity: Tournament
*
*/
@Entity
@Table(name="tournament_games")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class TournamentGame extends GenericEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name="name")
private String name;
@Column(name="description")
private String description;
@Lob
@Column(name = "game_image")
@Basic(fetch = LAZY)
private byte[] gameImage;
@Column(name = "expected_single_game_duration")
private Integer expectedSingleGameDuration;
@Column(name = "event_id", nullable = false)
private LanEvent lanEvent;
@OneToMany
private List<TournamentRule> availableRules;
public TournamentGame() { super(); }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<TournamentRule> getAvailableRules() {
return availableRules;
}
public void setAvailableRules(List<TournamentRule> availableRules) {
this.availableRules = availableRules;
}
}
package fi.codecrew.moya.model;
import fi.codecrew.moya.enums.MatchStatus;
import fi.codecrew.moya.model.GenericEntity;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
......@@ -16,22 +18,60 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
@Entity
@Table(name="matches")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Match extends GenericEntity implements Serializable {
public class TournamentMatch extends GenericEntity implements Serializable {
private static final long serialVersionUID = 1L;
@OneToMany
private List<Match> sourceMatches;
private List<TournamentMatch> sourceMatches;
@ManyToMany
private List<TournamentParticipant> matchParticipants;
@Column(name="play_count_max")
private Integer playCountMax = 1;
@Column(name="play_count")
private Integer playCount;
@Column(name="match_status")
@Enumerated(EnumType.STRING)
private MatchStatus matchStatus;
@Temporal(TemporalType.TIMESTAMP)
private Date startTime;
@Temporal(TemporalType.TIMESTAMP)
private Date endTime;
@OneToMany
@OrderBy("ranking")
private List<MatchResult> matchResults;
private List<TournamentMatchResult> matchResults;
public Match() {
public TournamentMatch() {
super();
}
public List<TournamentMatch> getSourceMatches() {
return sourceMatches;
}
public void setSourceMatches(List<TournamentMatch> sourceMatches) {
this.sourceMatches = sourceMatches;
}
public List<TournamentParticipant> getMatchParticipants() {
return matchParticipants;
}
public void setMatchParticipants(List<TournamentParticipant> matchParticipants) {
this.matchParticipants = matchParticipants;
}
public List<TournamentMatchResult> getMatchResults() {
return matchResults;
}
public void setMatchResults(List<TournamentMatchResult> matchResults) {
this.matchResults = matchResults;
}
}
......@@ -13,7 +13,7 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
@Entity
@Table(name="match_results")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class MatchResult extends GenericEntity implements Serializable {
public class TournamentMatchResult extends GenericEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name="score")
......@@ -25,7 +25,33 @@ public class MatchResult extends GenericEntity implements Serializable {
@JoinColumn(name="tournament_participant")
private TournamentParticipant tournamentParticipant;
public MatchResult() {
public TournamentMatchResult() {
super();
}
public Integer getScore() {
return score;
}
public void setScore(Integer score) {
this.score = score;
}
public Integer getRank() {
return rank;
}
public void setRank(Integer rank) {
this.rank = rank;
}
public TournamentParticipant getTournamentParticipant() {
return tournamentParticipant;
}
public void setTournamentParticipant(TournamentParticipant tournamentParticipant) {
this.tournamentParticipant = tournamentParticipant;
}
}
package fi.codecrew.moya.model;
import static javax.persistence.FetchType.LAZY;
import fi.codecrew.moya.enums.TournamentType;
import fi.codecrew.moya.model.GenericEntity;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/**
* Entity implementation class for Entity: Tournament
*
*/
@Entity
@Table(name="tournament_rules")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class TournamentRule extends GenericEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name="name")
private String name;
@Lob
@Column(name="description")
private String description;
@Lob
@Column(name="rules")
private String rules;
@ManyToOne
@JoinColumn(name = "tournament_game_id")
private TournamentGame tournamentGame;
public TournamentRule() { super(); }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getRules() {
return rules;
}
public void setRules(String rules) {
this.rules = rules;
}
}
package fi.codecrew.moya.enums;
public enum MatchStatus {
UNFINISHED,
FINISHED
}
package fi.codecrew.moya.enums;
public enum TournamentStatus {
SETUP,
IN_PROGRESS,
COMPLETED
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!