Commit 1eeae2e4 by Tuomas Riihimäki

Merge branch 'devel' of codecrew.fi:bortal into devel

2 parents d0d41fdf a12d00ba
......@@ -118,6 +118,7 @@ public class MenuBean implements MenuBeanLocal {
userprofile.addPage(menuitemfacade.findOrCreate("/user/edit"), UserPermission.VIEW_SELF);
userprofile.addPage(menuitemfacade.findOrCreate("/user/changePassword"), UserPermission.VIEW_SELF);
userprofile.addPage(menuitemfacade.findOrCreate("/user/gameids"), TournamentPermission.VIEW);
userprofile.addPage(menuitemfacade.findOrCreate("/auth/logout"), UserPermission.LOGOUT);
MenuNavigation tournaments = usermenu.addPage(null, null);
......
......@@ -34,6 +34,7 @@ import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.facade.ApprovalFacade;
import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.FeedbackFacade;
import fi.codecrew.moya.facade.GameIDFacade;
import fi.codecrew.moya.facade.GroupMembershipFacade;
import fi.codecrew.moya.facade.PlaceGroupFacade;
import fi.codecrew.moya.facade.RoleFacade;
......@@ -43,6 +44,7 @@ import fi.codecrew.moya.facade.UserImageFacade;
import fi.codecrew.moya.model.Approval;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Feedback;
import fi.codecrew.moya.model.GameID;
import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.IUser;
import fi.codecrew.moya.model.LanEvent;
......@@ -50,6 +52,7 @@ import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.model.UserApproval;
import fi.codecrew.moya.model.UserImage;
......@@ -124,6 +127,8 @@ public class UserBean implements UserBeanLocal {
private ApprovalFacade approvalFacade;
@EJB
private UserApprovalFacade userApprovalFacade;
@EJB
private GameIDFacade gameIDFacade;
@Override
@RolesAllowed(UserPermission.S_VIEW_ALL)
......@@ -520,6 +525,38 @@ public class UserBean implements UserBeanLocal {
eventUserFacade.create(evu);
return evu;
}
@Override
@RolesAllowed(SpecialPermission.S_USER)
public void addGameID(TournamentGame game, String gameid) {
EventUser u = permbean.getCurrentUser();
GameID gid = new GameID();
gid.setIdentifier(gameid);
gid.setGame(game);
gid.setUser(u);
gid = gameIDFacade.create(gid);
u.getGameIDs().add(gid);
}
@Override
@RolesAllowed(SpecialPermission.S_USER)
public void removeGameIdById(Integer gameIdId) {
GameID gi = gameIDFacade.find(gameIdId);
if(!permbean.isCurrentUser(gi.getEventUser())) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "User tried to remove GameID from another user: " + gi.getEventUser());
throw new EJBAccessException("Not enough rights to remove another users' GameIDs");
}
gi.getEventUser().getGameIDs().remove(gi);
gameIDFacade.remove(gi);
}
@Override
@RolesAllowed(SpecialPermission.S_USER)
public GameID getGameIDByGameAndUser(TournamentGame tg, EventUser user) {
return gameIDFacade.getGameIDByGame(tg, user);
}
@Override
public boolean userExists(String login) {
......
package fi.codecrew.moya.facade;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import fi.codecrew.moya.enums.TournamentStatus;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GameID;
import fi.codecrew.moya.model.GameID_;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.TournamentParticipant;
import fi.codecrew.moya.model.TournamentRule;
import fi.codecrew.moya.model.TournamentRule_;
import fi.codecrew.moya.model.Tournament_;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.model.User_;
@Stateless
@LocalBean
public class GameIDFacade extends IntegerPkGenericFacade<GameID> {
public GameIDFacade() {
super(GameID.class);
}
public GameID getGameIDByGame(TournamentGame tg, EventUser user) {
// TODO Auto-generated method stub
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<GameID> cq = cb.createQuery(GameID.class);
Root<GameID> root = cq.from(GameID.class);
cq.where(cb.and(cb.equal(root.get(GameID_.game), tg), cb.equal(root.get(GameID_.eventUser), user)));
try {
return getEm().createQuery(cq).getSingleResult();
} catch(Exception e) {
return null;
}
}
}
......@@ -8,8 +8,10 @@ import javax.ejb.Local;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Feedback;
import fi.codecrew.moya.model.GameID;
import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.model.UserApproval;
import fi.codecrew.moya.model.UserImage;
......@@ -91,4 +93,10 @@ public interface UserBeanLocal {
boolean initPasswordResetForUsername(String username, String url);
void addGameID(TournamentGame game, String gameid);
void removeGameIdById(Integer gameIdId);
GameID getGameIDByGameAndUser(TournamentGame tg, EventUser user);
}
......@@ -105,6 +105,17 @@ public class EventUser extends GenericEntity {
@Column(name = "createtime", nullable = false, updatable = false)
private Date eventuserCreated;
@OneToMany(mappedBy = "eventUser")
private List<GameID> gameIDs;
public List<GameID> getGameIDs() {
return gameIDs;
}
public void setGameIDs(List<GameID> gameIDs) {
this.gameIDs = gameIDs;
}
public EventUser getCreator() {
return creator;
}
......
package fi.codecrew.moya.model;
import fi.codecrew.moya.model.GenericEntity;
import java.io.Serializable;
import javax.persistence.*;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/**
* Entity implementation class for Entity: GameID
*
*/
@Entity
@Table(name="game_ids")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class GameID extends GenericEntity implements Serializable {
private static final long serialVersionUID = 1L;
@JoinColumn(name="event_user_id", nullable=false)
@ManyToOne
private EventUser eventUser;
@JoinColumn(name="game_id", nullable=false)
@ManyToOne
private TournamentGame game;
@Lob
private String identifier;
public GameID() {
super();
}
public EventUser getEventUser() {
return eventUser;
}
public void setUser(EventUser eventUser) {
this.eventUser = eventUser;
}
public TournamentGame getGame() {
return game;
}
public void setGame(TournamentGame game) {
this.game = game;
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
}
......@@ -12,6 +12,7 @@ import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
......
......@@ -19,7 +19,7 @@
<h:messages errorClass="error" />
<h:panelGroup rendered="#{tournamentCreateView.tournamentGames.isEmpty() eq false}">
<h2>#{i18n['tournaments.admin.select_a_game']}</h2>
<h:selectOneMenu value="#{tournamentCreateView.game}" converter="#{tournamentGameConverter}">
<h:selectOneMenu value="#{userGameIDView.gameToAddIdTo}" converter="#{tournamentGameConverter}">
<f:selectItems var="game" itemLabel="#{game.name}" value="#{tournamentCreateView.tournamentGames}" itemValue="#{game}" />
</h:selectOneMenu>
</h:panelGroup>
......
......@@ -71,6 +71,7 @@
<f:facet name="header">
<h:outputText value="#{i18n['tournament.admin.control']}" />
</f:facet>
<p:commandButton value="#{i18n['tournament.admin.view']}" action="#{tournamentParticipantsView.showView(tournament.id)}"/>
<p:commandButton value="#{i18n['tournament.admin.edit']}" action="#{tournamentEditView.showEdit(tournament.id)}"/>
<p:commandButton value="#{i18n['tournament.admin.delete']}" action="#{tournamentDeleteView.showConfirm(tournament.id)}"/>
</p:column>
......
<!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.admin.view_tournament_title']} #{tournamentParticipantsView.tournament.tournamentName}</h1>
<p>#{i18n['tournaments.admin.view_tournament_description']}</p>
<h:form>
<p:dataTable value="#{tournamentParticipantsView.tournament.participants}" var="participant">
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.participant_nick']}" />
</f:facet>
<h:outputText value="#{participant.participator.nick}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.participant_gameid']}" />
</f:facet>
<h:outputText value="#{tournamentParticipantsView.eventUserGameID[participant.participator.id]}" />
</p:column>
</p:dataTable>
</h:form>
<h:form>
<p:commandButton value="#{i18n['tournament.admin.back_to_index']}" action="#{tournamentParticipantsView.cancel}" />
</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:metadata>
<ui:define name="content">
<h1>#{i18n['tournaments.admin.view_tournament_title']} #{tournamentParticipantsView.tournament.tournamentName}</h1>
<p>#{i18n['tournaments.admin.view_tournament_description']}</p>
<p>#{i18n['tournaments.admin.view_tournament_description_teamview_addition']}</p>
<h:form>
<p:dataTable value="#{tournamentParticipantsView.tournament.participants}" var="participant">
<p:column style="width:2%">
<p:rowToggler />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.team_name']}" />
</f:facet>
<h:outputText value="#{participant.teamName}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.participant_captain']}" />
</f:facet>
<h:outputText value="#{participant.participator.nick}" />
</p:column>
<p:rowExpansion>
<h:panelGrid id="display" columns="2" cellpadding="4" styleClass=" ui-widget-content grid">
<h:outputText value="#{i18n['tournament.team_members']}" />
<h:panelGroup>
<ul>
<ui:repeat var="member" value="#{participant.teamMembers}">
<li>
<h:outputText value="#{member.eventUser.nick}" />
(<h:outputText value="#{tournamentParticipantsView.eventUserGameID[member.eventUser.id]}" />)
</li>
</ui:repeat>
</ul>
</h:panelGroup>
</h:panelGrid>
</p:rowExpansion>
</p:dataTable>
</h:form>
<h:form>
<p:commandButton value="#{i18n['tournament.admin.back_to_index']}" action="#{tournamentParticipantsView.cancel}" />
</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:f="http://java.sun.com/jsf/core"
xmlns:users="http://java.sun.com/jsf/composite/cditools/user" xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:account="http://java.sun.com/jsf/composite/cditools/account"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:event type="preRenderView" listener="#{userGameIDView.initView}" />
</f:metadata>
<ui:define name="title">
<h1>#{i18n['user.edit.gameids']}</h1>
</ui:define>
<ui:define name="content">
<h:form>
<p:messages autoUpdate="true" redisplay="false"></p:messages>
<h2>#{i18n['user.game.current_gameids']}</h2>
<p:dataTable value="#{userGameIDView.eventUser.gameIDs}" var="gameid">
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.game']}" />
</f:facet>
<h:outputText value="#{gameid.game.name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.participant_gameid']}" />
</f:facet>
<h:outputText value="#{gameid.identifier}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['user.game.manage']}" />
</f:facet>
<p:commandButton value="#{i18n['user.game.remove_gameid']}" action="#{userGameIDView.removeGameID(gameid.id)}" ajax="false" />
</p:column>
</p:dataTable>
<h:panelGroup rendered="#{not empty userGameIDView.games}">
<h2>#{i18n['user.game.add_new_gameid']}</h2>
<h:panelGrid columns="2">
<h:outputText value="#{i18n['tournament.game']}" />
<h:selectOneMenu value="#{userGameIDView.gameToAddIdTo}" converter="#{tournamentGameConverter}">
<f:selectItems var="game" itemLabel="#{game.name}" value="#{userGameIDView.games}" itemValue="#{game}" />
</h:selectOneMenu>
<h:outputText value="#{i18n['tournament.participant_gameid']}" />
<p:inputText value="#{userGameIDView.identifier}" />
<p:commandButton value="#{i18n['user.game.add_gameid']}" action="#{userGameIDView.addGameID}" ajax="false" />
</h:panelGrid>
</h:panelGroup>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
......@@ -936,6 +936,7 @@ submenu.user.changePassword = Change password
submenu.user.create = Create new user
submenu.user.edit = My information
submenu.user.foodwave = Food
submenu.user.gameids = Set GameIDs
submenu.user.invite = Invite friends
submenu.user.manageuserlinks = Manage users
submenu.user.other = Other
......@@ -1010,12 +1011,14 @@ topnavi.usermgmt = Users
topnavi.userplaces = Computer Places
topnavi.usershop = Shop
tournament.admin.back_to_index = Back to tournament administration
tournament.admin.control = Control
tournament.admin.create = Create new tournament
tournament.admin.delete = Delete
tournament.admin.delete_cancel = Cancel Deletion
tournament.admin.delete_confirm = Confirm Deletion
tournament.admin.edit = Edit
tournament.admin.view = View
tournament.already_participated_into_tournament = Already participated into the selected tournament!
tournament.backup_player_successfully_added_to_team = Backup player added
tournament.cannot_add_anon_user = Cannot add anonymous user
......@@ -1024,9 +1027,13 @@ tournament.control = Control
tournament.create = Create tournament
tournament.edit = Edit tournament
tournament.fillamount = Places taken
tournament.full = Tournament Full
tournament.game = Game
tournament.name = Tournament name
tournament.not_within_participation_time = Not within the participation time for the tournament
tournament.participant_captain = Captain
tournament.participant_gameid = Game-ID
tournament.participant_nick = Nickname
tournament.participants = Participants
tournament.participate = Participate
tournament.participation_failed = Participation failed
......@@ -1038,6 +1045,7 @@ tournament.playerspermatch_slash_teamsize = Players / team size
tournament.rules = Rules
tournament.rules_for_tournament = Rules for tournament
tournament.status = Status
tournament.team_members = Team Members
tournament.team_name = Team Name
tournament.team_name_required = Team name is required
tournament.teammember.delete = Delete
......@@ -1068,6 +1076,9 @@ tournaments.admin.select_a_game = Select a game
tournaments.admin.select_a_ruleset = Select a ruleset
tournaments.admin.set_time_constraints = Set time constraints
tournaments.admin.title = Tournaments management
tournaments.admin.view_tournament_description = You may view tournament participants and verify details and make minor edits for the teams. You may also remove any invalid participations.
tournaments.admin.view_tournament_description_teamview_addition = Team listing is of form TeamMember (Game-ID).
tournaments.admin.view_tournament_title = View tournament:
tournaments.back_to_tournament_list = Back to tournament list
tournaments.backup_players = Max backup players
tournaments.cancel_participation = Cancel participation
......@@ -1116,12 +1127,20 @@ user.cropImage = Crop image
user.cropUserImage = Crop image
user.defaultImage = Default picture
user.edit = Edit
user.edit.gameids = Edit GameIDs
user.edit.title = My information
user.email = Email
user.firstNames = Firstname
user.food.title = Choose Menu
user.foodwave.products.title = Choose Products
user.foodwavelist.title = Choose Foodwave
user.game.add_gameid = Add
user.game.add_new_gameid = Add new GameID
user.game.current_gameids = Current GameIDs
user.game.gameid_added = GameID successfully added
user.game.gameid_removed = GameID successfully removed
user.game.manage = Manage
user.game.remove_gameid = Remove
user.hasImage = Image
user.image = Image
user.imageTooBig = Image is too big
......
......@@ -919,6 +919,7 @@ submenu.user.create = Luo k\u00E4ytt\u00E4j\u00E4
submenu.user.createCardTemplate = Luo korttiryhm\u00E4
submenu.user.edit = Omat tiedot
submenu.user.foodwave = Ruoka
submenu.user.gameids = Aseta Peli-IDt
submenu.user.invite = Kutsu yst\u00E4vi\u00E4
submenu.user.list = Kaikki k\u00E4ytt\u00E4j\u00E4t
submenu.user.listCardTemplates = Korttiryhm\u00E4t
......@@ -995,12 +996,14 @@ topnavi.usermgmt = K\u00E4ytt\u00E4j\u00E4t
topnavi.userplaces = Konepaikat
topnavi.usershop = Kauppa
tournament.admin.back_to_index = Takaisin turnauksen yll\u00E4pitosivulle
tournament.admin.control = Hallitse
tournament.admin.create = Luo uusi turnaus
tournament.admin.delete = Poista
tournament.admin.delete_cancel = Peruuta
tournament.admin.delete_confirm = Vahvista Poisto
tournament.admin.edit = Muokkaa
tournament.admin.view = Tarkastele
tournament.already_participated_into_tournament = Olet jo osallistunut valittuun turnaukseen!
tournament.backup_player_successfully_added_to_team = Varapelaaja lis\u00E4tty
tournament.cannot_add_anon_user = Ei voida lis\u00E4t\u00E4 anomuumia
......@@ -1009,9 +1012,13 @@ tournament.control = Hallitse
tournament.create = Luo turnaus
tournament.edit = Muokkaa turnausta
tournament.fillamount = Osallistujaa ilmottautunut
tournament.full = Turnaus t\u00E4ynn\u00E4
tournament.game = Peli
tournament.name = Turnauksen nimi
tournament.not_within_participation_time = Turnauksen ilmoittautuminen ei ole aktiivinen
tournament.participant_captain = Kapteeni
tournament.participant_gameid = Peli-ID
tournament.participant_nick = Nimimerkki
tournament.participants = Osallistujat
tournament.participate = Osallistu
tournament.participation_failed = Turnausilmoittautuminen ep\u00E4onnistui
......@@ -1023,6 +1030,7 @@ 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.team_members = Joukkueen j\u00E4senet
tournament.team_name = Joukkueen nimi
tournament.team_name_required = Joukkueen nimi vaaditaan
tournament.teammember.delete = Poista
......@@ -1053,6 +1061,9 @@ tournaments.admin.select_a_game = Valitse peli
tournaments.admin.select_a_ruleset = Valitse s\u00E4\u00E4nn\u00F6st\u00F6
tournaments.admin.set_time_constraints = Aseta aikarajat
tournaments.admin.title = Turnauksien hallinnointi
tournaments.admin.view_tournament_description = Voit t\u00E4ss\u00E4 n\u00E4kym\u00E4ss\u00E4 tarkastella osallistujien tietoja sek\u00E4 poistaa ep\u00E4kelvot osallistumiset.
tournaments.admin.view_tournament_description_teamview_addition = Joukkuelistaus on muotoa TiiminJ\u00E4sen (Peli-ID).
tournaments.admin.view_tournament_title = Tarkastele turnausta:
tournaments.back_to_tournament_list = Takaisin turnauslistaukseen
tournaments.backup_players = Maksimim\u00E4\u00E4r\u00E4 varapelaajia
tournaments.cancel_participation = Peruuta osallistuminen
......@@ -1101,12 +1112,20 @@ user.cropImage = Rajaa
user.cropUserImage = Crop image
user.defaultImage = Oletukuva
user.edit = Muokkaa
user.edit.gameids = Muokkaa peli-id merkint\u00F6j\u00E4
user.edit.title = Omat tiedot
user.email = S\u00E4hk\u00F6posti
user.firstNames = Etunimi
user.food.title = Valitse Menu
user.foodwave.products.title = Valitse tuotteet
user.foodwavelist.title = Valitse Ruokatilaus
user.game.add_gameid = Lis\u00E4\u00E4
user.game.add_new_gameid = Lis\u00E4\u00E4 uusi Peli-ID
user.game.current_gameids = Nykyiset Peli-IDt
user.game.gameid_added = Peli-ID lis\u00E4tty
user.game.gameid_removed = Peli-ID poistettu
user.game.manage = Hallitse
user.game.remove_gameid = Poista
user.hasImage = Kuva
user.imageTooBig = Kuva on liian suuri
user.imageUpload.imageNotFound = Valitse ensin kuva jonka haluat l\u00E4hett\u00E4\u00E4
......
package fi.codecrew.moya.web.cdiview.tournaments;
import java.util.HashMap;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.model.GameID;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentParticipant;
import fi.codecrew.moya.model.TournamentTeamMember;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@ConversationScoped
public class TournamentParticipantsView extends GenericCDIView {
private static final long serialVersionUID = -6066216858686165211L;
private HashMap<Integer, String> eventUserGameID = null;
@EJB private UserBeanLocal userBean;
@EJB private TournamentBeanLocal tournamentBean;
private Tournament tournament = null;
public String showView(Integer tournamentId) {
if(eventUserGameID == null) {
this.setTournament(tournamentBean.getTournamentById(tournamentId));
this.beginConversation();
eventUserGameID = new HashMap<Integer, String>();
for(TournamentParticipant tp : tournament.getParticipants()) {
for(TournamentTeamMember ttm : tp.getTeamMembers()) {
GameID gid = userBean.getGameIDByGameAndUser(tournament.getTournamentGame(), ttm.getEventUser());
if(gid != null)
eventUserGameID.put(ttm.getEventUser().getId(), gid.getIdentifier());
else
eventUserGameID.put(ttm.getEventUser().getId(), "n/a");
}
}
}
if(this.tournament.getPlayersPerTeam() == 1)
return "/tournaments/admin/view_tournament_single.xhtml";
else
return "/tournaments/admin/view_tournament_team.xhtml";
}
public String cancel() {
this.endConversation();
return "/tournaments/admin/index.xhtml";
}
public Tournament getTournament() {
return tournament;
}
public void setTournament(Tournament tournament) {
this.tournament = tournament;
}
public HashMap<Integer, String> getEventUserGameID() {
return eventUserGameID;
}
public void setEventUserGameID(HashMap<Integer, String> eventUserGameID) {
this.eventUserGameID = eventUserGameID;
}
}
package fi.codecrew.moya.web.cdiview.user;
import java.util.HashMap;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.enums.apps.TournamentPermission;
import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GameID;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.jsf.MessageHelper;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@ConversationScoped
public class UserGameIDView extends GenericCDIView {
private static final long serialVersionUID = -1154119029203251525L;
@EJB private UserBeanLocal userBean;
@EJB private TournamentBeanLocal tournamentBean;
@EJB private PermissionBeanLocal permissionBean;
private EventUser eventUser;
private TournamentGame gameToAddIdTo;
private String identifier;
private List<TournamentGame> games;
public void initView() {
if(this.eventUser == null) {
this.beginConversation();
this.eventUser = permissionBean.getCurrentUser();
}
if(super.requirePermissions(UserPermission.VIEW_SELF) && super.requirePermissions(TournamentPermission.VIEW)) {
this.setGameToAddIdTo(null);
refreshGames();
}
}
public void addGameID() {
if(gameToAddIdTo != null && identifier != null && identifier.trim().length() > 0) {
userBean.addGameID(gameToAddIdTo, identifier);
this.setGameToAddIdTo(null);
this.eventUser = permissionBean.getCurrentUser();
this.identifier = null;
refreshGames();
MessageHelper.info("user.game.gameid_added");
}
}
public void removeGameID(String gameIdIdStr) {
Integer gameIdId = Integer.parseInt(gameIdIdStr);
userBean.removeGameIdById(gameIdId);
this.eventUser = permissionBean.getCurrentUser();
refreshGames();
MessageHelper.info("user.game.gameid_removed");
}
private void refreshGames() {
this.games = tournamentBean.getGames();
for(GameID gi : eventUser.getGameIDs()) {
if(this.games.contains(gi.getGame())) this.games.remove(gi.getGame());
}
}
public EventUser getEventUser() {
return eventUser;
}
public void setUser(EventUser eventUser) {
this.eventUser = eventUser;
}
public List<TournamentGame> getGames() {
return games;
}
public void setGames(List<TournamentGame> games) {
this.games = games;
}
public TournamentGame getGameToAddIdTo() {
return gameToAddIdTo;
}
public void setGameToAddIdTo(TournamentGame gameToAddIdTo) {
this.gameToAddIdTo = gameToAddIdTo;
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!