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
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!