Commit 627d76d9 by Antti Tonkyra

Tournament stuff

1 parent 055e367f
...@@ -7,15 +7,20 @@ import javax.ejb.LocalBean; ...@@ -7,15 +7,20 @@ import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import fi.codecrew.moya.enums.TournamentStatus; import fi.codecrew.moya.enums.TournamentStatus;
import fi.codecrew.moya.enums.TournamentTeamMemberRole;
import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.TournamentFacade; import fi.codecrew.moya.facade.TournamentFacade;
import fi.codecrew.moya.facade.TournamentGameFacade; import fi.codecrew.moya.facade.TournamentGameFacade;
import fi.codecrew.moya.facade.TournamentParticipantFacade; import fi.codecrew.moya.facade.TournamentParticipantFacade;
import fi.codecrew.moya.facade.TournamentRuleFacade; import fi.codecrew.moya.facade.TournamentRuleFacade;
import fi.codecrew.moya.facade.UserFacade;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Tournament; import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentGame; import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.TournamentParticipant; import fi.codecrew.moya.model.TournamentParticipant;
import fi.codecrew.moya.model.TournamentRule; import fi.codecrew.moya.model.TournamentRule;
import fi.codecrew.moya.model.TournamentTeamMember;
import fi.codecrew.moya.model.User;
/** /**
* Session Bean implementation class TournamentBean * Session Bean implementation class TournamentBean
...@@ -28,6 +33,8 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -28,6 +33,8 @@ public class TournamentBean implements TournamentBeanLocal {
@EJB private TournamentGameFacade tournamentGameFacade; @EJB private TournamentGameFacade tournamentGameFacade;
@EJB private TournamentFacade tournamentFacade; @EJB private TournamentFacade tournamentFacade;
@EJB private TournamentParticipantFacade tournamentParticipantFacade; @EJB private TournamentParticipantFacade tournamentParticipantFacade;
@EJB private EventUserFacade eventUserFacade;
@EJB private EventBean eventBean;
/** /**
* Default constructor. * Default constructor.
...@@ -100,9 +107,25 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -100,9 +107,25 @@ public class TournamentBean implements TournamentBeanLocal {
@Override @Override
public void createParticipation(TournamentParticipant tournamentParticipant) throws Exception { public void createParticipation(TournamentParticipant tournamentParticipant) throws Exception {
Tournament t = tournamentFacade.find(tournamentParticipant.getTournament().getId()); Tournament t = tournamentFacade.find(tournamentParticipant.getTournament().getId());
// Assert participant size is smaller than max
if(t.getParticipants().size() < t.getMaxParticipants()) { if(t.getParticipants().size() < t.getMaxParticipants()) {
tournamentParticipant = tournamentParticipantFacade.create(tournamentParticipant); TournamentTeamMember capt = null;
t.getParticipants().add(tournamentParticipant); for(TournamentTeamMember ttm : tournamentParticipant.getTeamMembers()) if(ttm.getRole() == TournamentTeamMemberRole.CAPTAIN) capt=ttm;
// Assert team has a captain
if(capt != null) {
// Assert team has the correct number of players for a match
if(tournamentParticipant.getTeamMembers().size() >= tournamentParticipant.getTournament().getPlayersPerTeam()) {
tournamentParticipant = tournamentParticipantFacade.create(tournamentParticipant);
t.getParticipants().add(tournamentParticipant);
} else {
throw new Exception("tournament.not_enough_players");
}
} else {
throw new Exception("tournament.no_captain");
}
} else { } else {
throw new Exception("tournament.participation_full"); throw new Exception("tournament.participation_full");
} }
...@@ -111,7 +134,8 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -111,7 +134,8 @@ public class TournamentBean implements TournamentBeanLocal {
@Override @Override
public boolean hasParticipations(EventUser currentUser, Tournament tournament) { public boolean hasParticipations(EventUser currentUser, Tournament tournament) {
for(TournamentParticipant tp : tournament.getParticipants()) { for(TournamentParticipant tp : tournament.getParticipants()) {
for(EventUser eu : tp.getTeamMembers()) { for(TournamentTeamMember tm : tp.getTeamMembers()) {
EventUser eu = tm.getEventUser();
System.out.println(eu.getNick()); System.out.println(eu.getNick());
if(eu.equals(currentUser)) { if(eu.equals(currentUser)) {
return true; return true;
...@@ -121,4 +145,17 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -121,4 +145,17 @@ public class TournamentBean implements TournamentBeanLocal {
return false; return false;
} }
@Override
public EventUser findAvailablePlayerForTournamentByLogin(Tournament t, String login) throws Exception {
EventUser u = eventUserFacade.findByLogin(login);
if(u != null) {
if(!hasParticipations(u,t))
return u;
else
throw new Exception("tournaments.participation_already_exists");
} else {
throw new Exception("tournaments.participated_user_not_found");
}
}
} }
...@@ -28,5 +28,6 @@ public interface TournamentBeanLocal { ...@@ -28,5 +28,6 @@ public interface TournamentBeanLocal {
void deleteTournament(Tournament tournament); void deleteTournament(Tournament tournament);
void createParticipation(TournamentParticipant tournamentParticipant) throws Exception; void createParticipation(TournamentParticipant tournamentParticipant) throws Exception;
boolean hasParticipations(EventUser currentUser, Tournament tournament); boolean hasParticipations(EventUser currentUser, Tournament tournament);
EventUser findAvailablePlayerForTournamentByLogin(Tournament t, String login) throws Exception;
} }
...@@ -42,7 +42,7 @@ public class TournamentMatch extends GenericEntity implements Serializable { ...@@ -42,7 +42,7 @@ public class TournamentMatch extends GenericEntity implements Serializable {
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Date endTime; private Date endTime;
@OrderBy("rank") @OrderBy("rank")
private List<TournamentMatchResult> matchResults; private List<TournamentMatchResult> matchResults;
......
...@@ -22,8 +22,8 @@ public class TournamentParticipant extends GenericEntity implements Serializable ...@@ -22,8 +22,8 @@ public class TournamentParticipant extends GenericEntity implements Serializable
@JoinColumn(name="participator") @JoinColumn(name="participator")
private EventUser participator; private EventUser participator;
@OneToMany @OneToMany(mappedBy="team", cascade=CascadeType.PERSIST)
private List<EventUser> teamMembers; private List<TournamentTeamMember> teamMembers;
@ManyToOne @ManyToOne
@JoinColumn(name="tournament") @JoinColumn(name="tournament")
...@@ -41,11 +41,11 @@ public class TournamentParticipant extends GenericEntity implements Serializable ...@@ -41,11 +41,11 @@ public class TournamentParticipant extends GenericEntity implements Serializable
this.participator = participator; this.participator = participator;
} }
public List<EventUser> getTeamMembers() { public List<TournamentTeamMember> getTeamMembers() {
return teamMembers; return teamMembers;
} }
public void setTeamMembers(List<EventUser> teamMembers) { public void setTeamMembers(List<TournamentTeamMember> teamMembers) {
this.teamMembers = teamMembers; this.teamMembers = teamMembers;
} }
......
package fi.codecrew.moya.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import fi.codecrew.moya.enums.TournamentTeamMemberRole;
@Entity
@Table(name="tournament_team_members")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class TournamentTeamMember extends GenericEntity implements Serializable {
private static final long serialVersionUID = 8511689754953929329L;
@Column(name="role", nullable=true)
@Enumerated(EnumType.STRING)
private TournamentTeamMemberRole role;
@JoinColumn(name="tournament_participant_id")
private TournamentParticipant team;
@JoinColumn(name="event_user_id")
private EventUser eventUser;
public EventUser getEventUser() {
return eventUser;
}
public void setEventUser(EventUser eventUser) {
this.eventUser = eventUser;
}
public TournamentParticipant getTeam() {
return team;
}
public void setTeam(TournamentParticipant team) {
this.team = team;
}
public TournamentTeamMemberRole getRole() {
return role;
}
public void setRole(TournamentTeamMemberRole role) {
this.role = role;
}
}
package fi.codecrew.moya.enums;
public enum TournamentTeamMemberRole {
CAPTAIN,
PLAYER,
BACKUP_PLAYER
;
private final String key;
private static final String I18N_HEADER = "bortalApplication.tournamentteammemberrole.";
private TournamentTeamMemberRole() {
key = I18N_HEADER + name();
}
public String getI18nKey() {
return key;
}
}
...@@ -22,6 +22,12 @@ ...@@ -22,6 +22,12 @@
</p:column> </p:column>
<p:column> <p:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['tournament.game']}" />
</f:facet>
<h:outputText value="#{tournament.tournamentGame.name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.status']}" /> <h:outputText value="#{i18n['tournament.status']}" />
</f:facet> </f:facet>
<h:outputText value="#{i18n[tournament.tournamentStatus.i18nKey]}" /> <h:outputText value="#{i18n[tournament.tournamentStatus.i18nKey]}" />
...@@ -40,15 +46,23 @@ ...@@ -40,15 +46,23 @@
</p:column> </p:column>
<p:column> <p:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['tournament.game']}" /> <h:outputText value="#{i18n['tournament.participation_time']}" />
</f:facet> </f:facet>
<h:outputText value="#{tournament.tournamentGame.name}" /> <h:outputText value="#{tournament.registrationOpensAt}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText>
-
<h:outputText value="#{tournament.registrationClosesAt}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText>
</p:column> </p:column>
<p:column> <p:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['tournament.rules']}" /> <h:outputText value="#{i18n['tournament.rules']}" />
</f:facet> </f:facet>
<h:outputText value="#{tournament.rules.name}" /> <h:link value="#{tournament.rules.name}" outcome="/tournaments/showrules.xhtml">
<f:param name="tournament_id" value="#{tournament.id}" />
</h:link>
</p:column> </p:column>
<p:column> <p:column>
<f:facet name="header"> <f:facet name="header">
......
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:users="http://java.sun.com/jsf/composite/cditools/user" xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
</f:metadata>
<ui:define name="content">
<h1>#{i18n['tournaments.participate_title']} #{tournamentParticipateView.tournament.tournamentName}</h1>
<p>#{i18n['tournaments.participate_description']}</p>
<h2>#{i18n['tournaments.participate_rules']}</h2>
<p><h:outputText value="#{tournamentParticipateView.tournament.rules.rules}" escape="false" /></p>
<h2>#{i18n['tournaments.participate_team_members']}</h2>
<p:messages autoUpdate="true" redisplay="false"></p:messages>
<h:form>
<h3>#{i18n['tournaments.participate_actual_team_members']}</h3>
<p:dataTable id="teammember_table" value="#{tournamentParticipateView.players}" var="teamMember">
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.teammember.name']}" />
</f:facet>
<h:outputText value="#{teamMember.eventUser.user.nick}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.control']}" />
</f:facet>
<h:panelGroup>
<p:commandButton value="#{i18n['tournament.teammember.delete']}" action="#{tournamentParticipateView.removePlayerFromTeam(teamMember.eventUser.id)}" update="@form" />
</h:panelGroup>
</p:column>
</p:dataTable>
<h:panelGrid columns="3" rendered="#{tournamentParticipateView.teamMax > tournamentParticipateView.playerCount}">
<h:outputText value="#{i18n['tournament.teammember.login']}" />
<p:inputText value="#{tournamentParticipateView.selectedPlayerLogin}" />
<p:commandButton value="#{i18n['tournaments.add_player_to_team']}" action="#{tournamentParticipateView.addMainPlayerToTeam}" update="@form" />
</h:panelGrid>
<h:panelGroup rendered="#{tournamentParticipateView.backupMax > tournamentParticipateView.backupPlayerCount}">
<h3>#{i18n['tournaments.participate_backup_team_members']}</h3>
<p:dataTable id="backup_teammember_table" value="#{tournamentParticipateView.backupPlayers}" var="teamMember" rendered="#{tournamentParticipateView.backupMax > 0}">
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.teammember.name']}" />
</f:facet>
<h:outputText value="#{teamMember.eventUser.user.nick}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.control']}" />
</f:facet>
<h:panelGroup>
<p:commandButton value="#{i18n['tournament.teammember.delete']}" action="#{tournamentParticipateView.removePlayerFromTeam(teamMember.eventUser.id)}" update="@form" />
</h:panelGroup>
</p:column>
</p:dataTable>
<h:panelGrid columns="3">
<h:outputText value="#{i18n['tournament.teammember.login']}" />
<p:inputText value="#{tournamentParticipateView.selectedBackupPlayerLogin}" />
<p:commandButton value="#{i18n['tournaments.add_backup_player_to_team']}" action="#{tournamentParticipateView.addBackupPlayerToTeam}" update="@form" />
</h:panelGrid>
</h:panelGroup>
<h3>#{i18n['tournaments.participate_team_counters']}</h3>
<h:panelGrid columns="2">
<h:panelGroup>
#{i18n['tournaments.participate_player_count']}:
#{tournamentParticipateView.playerCount}/#{tournamentParticipateView.teamMax}
</h:panelGroup>
<h:panelGroup>
#{i18n['tournaments.participate_backup_player_count']}:
#{tournamentParticipateView.backupPlayerCount}/#{tournamentParticipateView.backupMax}
</h:panelGroup>
</h:panelGrid>
<p:commandButton value="#{i18n['tournaments.cancel_participation']}" action="#{tournamentParticipateView.cancelParticipation}" />
<p:commandButton value="#{i18n['tournaments.accept_rules_and_participate']}" action="#{tournamentParticipateView.saveParticipation}" disabled="#{tournamentParticipateView.teamMax != tournamentParticipateView.playerCount}" />
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:users="http://java.sun.com/jsf/composite/cditools/user" xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:viewParam name="tournament_id" value="#{tournamentRulesView.tournamentId}"/>
<f:event type="preRenderView" listener="#{tournamentRulesView.init}" />
</f:metadata>
<ui:define name="content">
<h1>#{i18n['tournament.rules_for_tournament']} #{tournamentRulesView.tournament.tournamentName} (#{tournamentRulesView.tournament.rules.name})</h1>
<h:outputText value="#{tournamentRulesView.tournament.rules.rules}" escape="false" />
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
...@@ -1008,40 +1008,82 @@ topnavi.usermgmt = Users ...@@ -1008,40 +1008,82 @@ topnavi.usermgmt = Users
topnavi.userplaces = Computer Places topnavi.userplaces = Computer Places
topnavi.usershop = Shop topnavi.usershop = Shop
tournament.admin.create = Create new tournament tournament.admin.control = Control
tournament.create = Create tournament tournament.admin.create = Create new tournament
tournament.edit = Edit tournament tournament.admin.delete = Delete
tournament.fillamount = Places taken tournament.admin.delete_cancel = Cancel Deletion
tournament.game = Game tournament.admin.delete_confirm = Confirm Deletion
tournament.name = Tournament name tournament.admin.edit = Edit
tournament.playerspermatch_slash_teamsize = Players / team size tournament.already_participated_into_tournament = Already participated into the selected tournament!
tournament.rules = Rules tournament.backup_player_successfully_added_to_team = Backup player added
tournament.status = Status tournament.cannot_add_anon_user = Cannot add anonymous user
tournament.type = Type tournament.cannot_remove_captain = Cannot remove the team captain (you)
tournament.control = Control
tournament.create = Create tournament
tournament.edit = Edit tournament
tournament.fillamount = Places taken
tournament.game = Game
tournament.name = Tournament name
tournament.participate = Participate
tournament.participation_failed = Participation failed
tournament.participation_success = Successfully participated into tournament
tournament.participation_time = Participation time
tournament.player_already_exists_in_team = Player already exists in the team
tournament.player_successfully_added_to_team = Player added to the team
tournament.playerspermatch_slash_teamsize = Players / team size
tournament.rules = Rules
tournament.rules_for_tournament = Rules for tournament
tournament.status = Status
tournament.teammember.delete = Delete
tournament.teammember.login = Login
tournament.teammember.name = Name
tournament.type = Type
tournaments.accept_rules_and_participate = Accept rules and participate
tournaments.active_tournaments = Active tournaments tournaments.active_tournaments = Active tournaments
tournaments.add_backup_player_to_team = Add backup player
tournaments.add_player_to_team = Add player to team
tournaments.admin.begin_time_constraints = Tournament begin time tournaments.admin.begin_time_constraints = Tournament begin time
tournaments.admin.cancel_edits = Cancel Edits
tournaments.admin.create = Create tournament tournaments.admin.create = Create tournament
tournaments.admin.create_a_game = Create a game tournaments.admin.create_a_game = Create a game
tournaments.admin.create_new_ruleset = Create a new ruleset tournaments.admin.create_new_ruleset = Create a new ruleset
tournaments.admin.create_tournament = Create a tournament tournaments.admin.create_tournament = Create a tournament
tournaments.admin.description = Manage tournaments tournaments.admin.description = Manage tournaments
tournaments.admin.edit = Edit tournament tournaments.admin.edit = Edit tournament
tournaments.admin.edit_tournament = Edit Tournament
tournaments.admin.game_description = Game description tournaments.admin.game_description = Game description
tournaments.admin.game_name = Game name tournaments.admin.game_name = Game name
tournaments.admin.registration_time_constraints = Registration time constraints tournaments.admin.registration_time_constraints = Registration time constraints
tournaments.admin.remove_confirmation_text = Are you sure you want to remove this tournament? THIS CANNOT BE REVERSED!
tournaments.admin.remove_title = Confirm Tournament Removal
tournaments.admin.rules = Rules tournaments.admin.rules = Rules
tournaments.admin.select_a_game = Select a game tournaments.admin.select_a_game = Select a game
tournaments.admin.select_a_ruleset = Select a ruleset tournaments.admin.select_a_ruleset = Select a ruleset
tournaments.admin.set_time_constraints = Set time constraints tournaments.admin.set_time_constraints = Set time constraints
tournaments.admin.title = Tournaments management tournaments.admin.title = Tournaments management
tournaments.backup_players = Max backup players tournaments.backup_players = Max backup players
tournaments.cancel_participation = Cancel participation
tournaments.description = You can view & participate into tournaments from this page.
tournaments.max_participants = Max participants
tournaments.open_tournaments = Open tournaments
tournaments.participate_actual_team_members = Actual team members
tournaments.participate_backup_player_count = Backup Player Count
tournaments.participate_backup_team_members = Backup team members
tournaments.participate_description = You may participate to the tournament from this page.
tournaments.participate_player_count = Player Count
tournaments.participate_rules = Rules
tournaments.participate_team_counters = Counters
tournaments.participate_team_members = Team members for participation
tournaments.participate_title = Participate to tournament
tournaments.players_per_match = Max players per match tournaments.players_per_match = Max players per match
tournaments.registration_closes = Set registration closing time tournaments.registration_closes = Set registration closing time
tournaments.registration_opens = Set registration opening time tournaments.registration_opens = Set registration opening time
tournaments.ruleset_description = Ruleset description tournaments.ruleset_description = Ruleset description
tournaments.ruleset_name = Ruleset name tournaments.ruleset_name = Ruleset name
tournaments.ruleset_rules = Tournament ruleset tournaments.ruleset_rules = Tournament ruleset
tournaments.start_time = Start Time
tournaments.title = Tournaments
tournaments.tournament_details = Tournament details tournaments.tournament_details = Tournament details
tournaments.tournament_name = Tournament name tournaments.tournament_name = Tournament name
tournaments.tournament_type = Tournament type tournaments.tournament_type = Tournament type
......
...@@ -992,40 +992,82 @@ topnavi.usermgmt = K\u00E4ytt\u00E4j\u00E4t ...@@ -992,40 +992,82 @@ topnavi.usermgmt = K\u00E4ytt\u00E4j\u00E4t
topnavi.userplaces = Konepaikat topnavi.userplaces = Konepaikat
topnavi.usershop = Kauppa topnavi.usershop = Kauppa
tournament.admin.create = Luo uusi turnaus tournament.admin.control = Hallitse
tournament.create = Luo turnaus tournament.admin.create = Luo uusi turnaus
tournament.edit = Muokkaa turnausta tournament.admin.delete = Poista
tournament.fillamount = Osallistujaa ilmottautunut tournament.admin.delete_cancel = Peruuta
tournament.game = Peli tournament.admin.delete_confirm = Vahvista Poisto
tournament.name = Turnauksen nimi tournament.admin.edit = Muokkaa
tournament.playerspermatch_slash_teamsize = Pelaajat / tiimin koko tournament.already_participated_into_tournament = Olet jo osallistunut valittuun turnaukseen!
tournament.rules = S\u00E4\u00E4nn\u00F6t tournament.backup_player_successfully_added_to_team = Varapelaaja lis\u00E4tty
tournament.status = Tilanne tournament.cannot_add_anon_user = Ei voida lis\u00E4t\u00E4 anomuumia
tournament.type = Tyyppi tournament.cannot_remove_captain = Kapteenia (sinua) ei voi poistaa joukkueesta
tournament.control = Hallitse
tournament.create = Luo turnaus
tournament.edit = Muokkaa turnausta
tournament.fillamount = Osallistujaa ilmottautunut
tournament.game = Peli
tournament.name = Turnauksen nimi
tournament.participate = Osallistu
tournament.participation_failed = Turnausilmoittautuminen ep\u00E4onnistui
tournament.participation_success = Osallistuminen vastaanotettu
tournament.participation_time = Osallistumisaika
tournament.player_already_exists_in_team = Pelaaja on jo lis\u00E4tty joukkueeseen
tournament.player_successfully_added_to_team = Pelaaja lis\u00E4tty joukkueeseen
tournament.playerspermatch_slash_teamsize = Pelaajat / tiimin koko
tournament.rules = S\u00E4\u00E4nn\u00F6t
tournament.rules_for_tournament = S\u00E4\u00E4nn\u00F6t turnaukselle
tournament.status = Tilanne
tournament.teammember.delete = Poista
tournament.teammember.login = Kirjautumistunnus
tournament.teammember.name = Nimi
tournament.type = Tyyppi
tournaments.accept_rules_and_participate = Hyv\u00E4ksyn s\u00E4\u00E4nn\u00F6t ja osallistun
tournaments.active_tournaments = Aktiiviset turnaukset tournaments.active_tournaments = Aktiiviset turnaukset
tournaments.add_backup_player_to_team = Lis\u00E4\u00E4 varaj\u00E4sen
tournaments.add_player_to_team = Lis\u00E4\u00E4 pelaaja joukkueeseen
tournaments.admin.begin_time_constraints = Turnauksen aloitusaika tournaments.admin.begin_time_constraints = Turnauksen aloitusaika
tournaments.admin.cancel_edits = Peruuta Muokkaukset
tournaments.admin.create = Luo turnaus tournaments.admin.create = Luo turnaus
tournaments.admin.create_a_game = Luo peli tournaments.admin.create_a_game = Luo peli
tournaments.admin.create_new_ruleset = Luo uusi s\u00E4\u00E4nn\u00F6st\u00F6 tournaments.admin.create_new_ruleset = Luo uusi s\u00E4\u00E4nn\u00F6st\u00F6
tournaments.admin.create_tournament = Luo turnaus tournaments.admin.create_tournament = Luo turnaus
tournaments.admin.description = Hallinnoi turnauksia tournaments.admin.description = Hallinnoi turnauksia
tournaments.admin.edit = Muokkaa turnausta tournaments.admin.edit = Muokkaa turnausta
tournaments.admin.edit_tournament = Muokkaa turnausta
tournaments.admin.game_description = Pelin kuvaus tournaments.admin.game_description = Pelin kuvaus
tournaments.admin.game_name = Pelin nimi tournaments.admin.game_name = Pelin nimi
tournaments.admin.registration_time_constraints = Rekister\u00F6itymisaika tournaments.admin.registration_time_constraints = Rekister\u00F6itymisaika
tournaments.admin.remove_confirmation_text = Oletko varma ett\u00E4 haluat poistaa turnauksen? T\u00C4T\u00C4 EI VOI PERUUTTAA!
tournaments.admin.remove_title = Vahvista turnauksen poisto
tournaments.admin.rules = S\u00E4\u00E4nn\u00F6t tournaments.admin.rules = S\u00E4\u00E4nn\u00F6t
tournaments.admin.select_a_game = Valitse peli tournaments.admin.select_a_game = Valitse peli
tournaments.admin.select_a_ruleset = Valitse s\u00E4\u00E4nn\u00F6st\u00F6 tournaments.admin.select_a_ruleset = Valitse s\u00E4\u00E4nn\u00F6st\u00F6
tournaments.admin.set_time_constraints = Aseta aikarajat tournaments.admin.set_time_constraints = Aseta aikarajat
tournaments.admin.title = Turnauksien hallinnointi tournaments.admin.title = Turnauksien hallinnointi
tournaments.backup_players = Maksimim\u00E4\u00E4r\u00E4 varapelaajia tournaments.backup_players = Maksimim\u00E4\u00E4r\u00E4 varapelaajia
tournaments.cancel_participation = Peruuta osallistuminen
tournaments.description = Voit osallistua sek\u00E4 katselmoida turnauksia t\u00E4ll\u00E4 sivulla.
tournaments.max_participants = Maksimiosallistujam\u00E4\u00E4r\u00E4
tournaments.open_tournaments = Avoimet turnaukset
tournaments.participate_actual_team_members = Varsinaiset joukkueen j\u00E4senet
tournaments.participate_backup_player_count = Varapelaajat
tournaments.participate_backup_team_members = Joukkueen varaj\u00E4senet
tournaments.participate_description = Voit osallistua turnaukseen t\u00E4ll\u00E4 sivulla.
tournaments.participate_player_count = Pelaajam\u00E4\u00E4r\u00E4
tournaments.participate_rules = S\u00E4\u00E4nn\u00F6t
tournaments.participate_team_counters = Laskurit
tournaments.participate_team_members = Valitse joukkueesi
tournaments.participate_title = Osallistu turnaukseen
tournaments.players_per_match = Maksimim\u00E4\u00E4r\u00E4 pelaajia matchissa tournaments.players_per_match = Maksimim\u00E4\u00E4r\u00E4 pelaajia matchissa
tournaments.registration_closes = Rekister\u00F6itymisen sulkeutumisaika tournaments.registration_closes = Rekister\u00F6itymisen sulkeutumisaika
tournaments.registration_opens = Rekister\u00F6itymisen aukeamisaika tournaments.registration_opens = Rekister\u00F6itymisen aukeamisaika
tournaments.ruleset_description = S\u00E4\u00E4nn\u00F6st\u00F6n kuvaus tournaments.ruleset_description = S\u00E4\u00E4nn\u00F6st\u00F6n kuvaus
tournaments.ruleset_name = S\u00E4\u00E4nn\u00F6st\u00F6n nimi tournaments.ruleset_name = S\u00E4\u00E4nn\u00F6st\u00F6n nimi
tournaments.ruleset_rules = Turnauksen s\u00E4\u00E4nn\u00F6t tournaments.ruleset_rules = Turnauksen s\u00E4\u00E4nn\u00F6t
tournaments.start_time = Aloitusaika
tournaments.title = Turnaukset
tournaments.tournament_details = Turnauksen yksityiskohdat tournaments.tournament_details = Turnauksen yksityiskohdat
tournaments.tournament_name = Turnauksen nimi tournaments.tournament_name = Turnauksen nimi
tournaments.tournament_type = Turnauksen tyyppi tournaments.tournament_type = Turnauksen tyyppi
......
package fi.codecrew.moya.web.cdiview.tournaments; package fi.codecrew.moya.web.cdiview.tournaments;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped; import javax.enterprise.context.ConversationScoped;
...@@ -8,9 +9,11 @@ import javax.inject.Named; ...@@ -8,9 +9,11 @@ import javax.inject.Named;
import fi.codecrew.moya.beans.PermissionBeanLocal; import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.TournamentBeanLocal; import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.enums.TournamentTeamMemberRole;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Tournament; import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentParticipant; import fi.codecrew.moya.model.TournamentParticipant;
import fi.codecrew.moya.model.TournamentTeamMember;
import fi.codecrew.moya.utilities.I18n; import fi.codecrew.moya.utilities.I18n;
import fi.codecrew.moya.utilities.jsf.MessageHelper; import fi.codecrew.moya.utilities.jsf.MessageHelper;
import fi.codecrew.moya.web.cdiview.GenericCDIView; import fi.codecrew.moya.web.cdiview.GenericCDIView;
...@@ -24,10 +27,46 @@ public class TournamentParticipateView extends GenericCDIView { ...@@ -24,10 +27,46 @@ public class TournamentParticipateView extends GenericCDIView {
@EJB private TournamentBeanLocal tournamentBean; @EJB private TournamentBeanLocal tournamentBean;
@EJB private PermissionBeanLocal permissionBean; @EJB private PermissionBeanLocal permissionBean;
private String selectedPlayerLogin;
private String selectedBackupPlayerLogin;
public Integer getTeamMax() {
return tournament.getPlayersPerMatch();
}
public Integer getBackupMax() {
return (tournament.getPlayersPerTeam() - tournament.getPlayersPerMatch());
}
public Integer getPlayerCount() {
return getPlayers().size();
}
public Integer getBackupPlayerCount() {
return getBackupPlayers().size();
}
public void removePlayerFromTeam(Integer euid) {
TournamentTeamMember ttcand = null;
for(TournamentTeamMember ttm : tournamentParticipant.getTeamMembers()) {
if(ttm.getEventUser().getId() == euid) {
ttcand = ttm;
}
}
if(ttcand != null) {
if(ttcand.getRole() == TournamentTeamMemberRole.CAPTAIN) {
MessageHelper.err("tournament.cannot_remove_captain");
} else {
tournamentParticipant.getTeamMembers().remove(ttcand);
}
}
}
public String participate(Integer tournamentId) { public String participate(Integer tournamentId) {
tournament = tournamentBean.getTournamentById(tournamentId); tournament = tournamentBean.getTournamentById(tournamentId);
if(tournamentBean.hasParticipations(permissionBean.getCurrentUser(), tournament)) { if(tournamentBean.hasParticipations(permissionBean.getCurrentUser(), tournament)) {
MessageHelper.err(I18n.get("tournament.already_participated_into_tournament")); MessageHelper.err("tournament.already_participated_into_tournament");
return "/tournaments/index.xhtml"; return "/tournaments/index.xhtml";
} }
this.beginConversation(); this.beginConversation();
...@@ -36,29 +75,103 @@ public class TournamentParticipateView extends GenericCDIView { ...@@ -36,29 +75,103 @@ public class TournamentParticipateView extends GenericCDIView {
tournamentParticipant = new TournamentParticipant(); tournamentParticipant = new TournamentParticipant();
tournamentParticipant.setTournament(tournament); tournamentParticipant.setTournament(tournament);
tournamentParticipant.setParticipator(permissionBean.getCurrentUser()); tournamentParticipant.setParticipator(permissionBean.getCurrentUser());
tournamentParticipant.setTeamMembers(new ArrayList<EventUser>()); tournamentParticipant.setTeamMembers(new ArrayList<TournamentTeamMember>());
tournamentParticipant.getTeamMembers().add(permissionBean.getCurrentUser()); TournamentTeamMember captain = new TournamentTeamMember();
captain.setRole(TournamentTeamMemberRole.CAPTAIN);
captain.setEventUser(permissionBean.getCurrentUser());
captain.setTeam(tournamentParticipant);
tournamentParticipant.getTeamMembers().add(captain);
if(tournament.getPlayersPerTeam() == 1) { if(tournament.getPlayersPerTeam() == 1) {
return "/tournaments/participate_single.xhtml"; return "/tournaments/participate_single.xhtml";
} else { } else {
return "/tournaments/index.xhtml"; return "/tournaments/participate_multi.xhtml";
} }
} else { } else {
return "/tournaments/index.xhtml"; return "/tournaments/index.xhtml";
} }
} }
public String addMainPlayerToTeam() {
try {
EventUser p = tournamentBean.findAvailablePlayerForTournamentByLogin(this.tournament, selectedPlayerLogin);
for(TournamentTeamMember member : tournamentParticipant.getTeamMembers())
if(member.getEventUser().equals(p))
throw new Exception("tournament.player_already_exists_in_team");
if(p.isAnonymous()) {
throw new Exception("tournament.cannot_add_anon_user");
}
TournamentTeamMember ttm = new TournamentTeamMember();
ttm.setEventUser(p);
ttm.setRole(TournamentTeamMemberRole.PLAYER);
ttm.setTeam(tournamentParticipant);
this.tournamentParticipant.getTeamMembers().add(ttm);
MessageHelper.info("tournament.player_successfully_added_to_team");
this.selectedPlayerLogin = "";
} catch (Exception e) {
MessageHelper.err(e.getMessage());
}
return "";
}
public String addBackupPlayerToTeam() {
try {
EventUser p = tournamentBean.findAvailablePlayerForTournamentByLogin(this.tournament, selectedBackupPlayerLogin);
for(TournamentTeamMember member : tournamentParticipant.getTeamMembers())
if(member.getEventUser().equals(p))
throw new Exception("tournament.player_already_exists_in_team");
if(p.isAnonymous()) {
throw new Exception("tournament.cannot_add_anon_user");
}
TournamentTeamMember ttm = new TournamentTeamMember();
ttm.setEventUser(p);
ttm.setRole(TournamentTeamMemberRole.BACKUP_PLAYER);
ttm.setTeam(tournamentParticipant);
this.tournamentParticipant.getTeamMembers().add(ttm);
MessageHelper.info("tournament.backup_player_successfully_added_to_team");
this.selectedBackupPlayerLogin = "";
} catch (Exception e) {
MessageHelper.err(e.getMessage());
}
return "";
}
public List<TournamentTeamMember> getPlayers() {
ArrayList<TournamentTeamMember> ttms = new ArrayList<>();
for(TournamentTeamMember ttm : tournamentParticipant.getTeamMembers()) {
if(ttm.getRole() == TournamentTeamMemberRole.CAPTAIN || ttm.getRole() == TournamentTeamMemberRole.PLAYER) {
ttms.add(ttm);
}
}
return ttms;
}
public List<TournamentTeamMember> getBackupPlayers() {
ArrayList<TournamentTeamMember> ttms = new ArrayList<>();
for(TournamentTeamMember ttm : tournamentParticipant.getTeamMembers()) {
if(ttm.getRole() == TournamentTeamMemberRole.BACKUP_PLAYER) {
ttms.add(ttm);
}
}
return ttms;
}
public String saveParticipation() { public String saveParticipation() {
if(tournamentParticipant != null) { if(tournamentParticipant != null) {
try { try {
tournamentBean.createParticipation(tournamentParticipant); tournamentBean.createParticipation(tournamentParticipant);
MessageHelper.info(I18n.get("tournament.admin.tournament_participation_success")); MessageHelper.info("tournament.participation_success");
} catch(Exception e) { } catch(Exception e) {
MessageHelper.err(I18n.get(e.getMessage())); MessageHelper.err(e.getMessage());
} }
} else { } else {
MessageHelper.err(I18n.get("tournament.admin.tournament_participation_failed")); MessageHelper.err("tournament.participation_failed");
} }
this.endConversation(); this.endConversation();
...@@ -77,4 +190,28 @@ public class TournamentParticipateView extends GenericCDIView { ...@@ -77,4 +190,28 @@ public class TournamentParticipateView extends GenericCDIView {
public void setTournament(Tournament tournament) { public void setTournament(Tournament tournament) {
this.tournament = tournament; this.tournament = tournament;
} }
public TournamentParticipant getTournamentParticipant() {
return this.tournamentParticipant;
}
public void setTournamentParticipant(TournamentParticipant tp) {
this.tournamentParticipant = tp;
}
public String getSelectedPlayerLogin() {
return selectedPlayerLogin;
}
public void setSelectedPlayerLogin(String selectedPlayerLogin) {
this.selectedPlayerLogin = selectedPlayerLogin;
}
public String getSelectedBackupPlayerLogin() {
return selectedBackupPlayerLogin;
}
public void setSelectedBackupPlayerLogin(String selectedBackupPlayerLogin) {
this.selectedBackupPlayerLogin = selectedBackupPlayerLogin;
}
} }
package fi.codecrew.moya.web.cdiview.tournaments;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedProperty;
import javax.inject.Named;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.enums.TournamentStatus;
import fi.codecrew.moya.model.Tournament;
@Named
@RequestScoped
public class TournamentRulesView {
@EJB private TournamentBeanLocal tournamentBean;
private Tournament tournament;
private Integer tournamentId;
public void init() {
tournament = tournamentBean.getTournamentById(tournamentId);
}
public Integer getTournamentId() {
return tournamentId;
}
public void setTournamentId(Integer tournamentId) {
this.tournamentId = tournamentId;
}
public Tournament getTournament() {
return tournament;
}
public void setTournament(Tournament tournament) {
this.tournament = tournament;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!