Commit 1d261dd6 by Antti Tonkyra

GameID functionality

1 parent 21974dc8
...@@ -34,6 +34,7 @@ import fi.codecrew.moya.enums.apps.UserPermission; ...@@ -34,6 +34,7 @@ import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.facade.ApprovalFacade; import fi.codecrew.moya.facade.ApprovalFacade;
import fi.codecrew.moya.facade.EventUserFacade; import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.FeedbackFacade; import fi.codecrew.moya.facade.FeedbackFacade;
import fi.codecrew.moya.facade.GameIDFacade;
import fi.codecrew.moya.facade.GroupMembershipFacade; import fi.codecrew.moya.facade.GroupMembershipFacade;
import fi.codecrew.moya.facade.PlaceGroupFacade; import fi.codecrew.moya.facade.PlaceGroupFacade;
import fi.codecrew.moya.facade.RoleFacade; import fi.codecrew.moya.facade.RoleFacade;
...@@ -43,6 +44,7 @@ import fi.codecrew.moya.facade.UserImageFacade; ...@@ -43,6 +44,7 @@ import fi.codecrew.moya.facade.UserImageFacade;
import fi.codecrew.moya.model.Approval; import fi.codecrew.moya.model.Approval;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Feedback; import fi.codecrew.moya.model.Feedback;
import fi.codecrew.moya.model.GameID;
import fi.codecrew.moya.model.GroupMembership; import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.IUser; import fi.codecrew.moya.model.IUser;
import fi.codecrew.moya.model.LanEvent; import fi.codecrew.moya.model.LanEvent;
...@@ -50,6 +52,7 @@ import fi.codecrew.moya.model.LanEventPropertyKey; ...@@ -50,6 +52,7 @@ import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.PlaceGroup; import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.PrintedCard; import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.model.Role; import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.User; import fi.codecrew.moya.model.User;
import fi.codecrew.moya.model.UserApproval; import fi.codecrew.moya.model.UserApproval;
import fi.codecrew.moya.model.UserImage; import fi.codecrew.moya.model.UserImage;
...@@ -124,6 +127,8 @@ public class UserBean implements UserBeanLocal { ...@@ -124,6 +127,8 @@ public class UserBean implements UserBeanLocal {
private ApprovalFacade approvalFacade; private ApprovalFacade approvalFacade;
@EJB @EJB
private UserApprovalFacade userApprovalFacade; private UserApprovalFacade userApprovalFacade;
@EJB
private GameIDFacade gameIDFacade;
@Override @Override
@RolesAllowed(UserPermission.S_VIEW_ALL) @RolesAllowed(UserPermission.S_VIEW_ALL)
...@@ -520,6 +525,32 @@ public class UserBean implements UserBeanLocal { ...@@ -520,6 +525,32 @@ public class UserBean implements UserBeanLocal {
eventUserFacade.create(evu); eventUserFacade.create(evu);
return 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 @Override
public boolean userExists(String login) { 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.LanEvent;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentParticipant;
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);
}
}
...@@ -10,6 +10,7 @@ import fi.codecrew.moya.model.EventUser; ...@@ -10,6 +10,7 @@ import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Feedback; import fi.codecrew.moya.model.Feedback;
import fi.codecrew.moya.model.GroupMembership; import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.Role; import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.User; import fi.codecrew.moya.model.User;
import fi.codecrew.moya.model.UserApproval; import fi.codecrew.moya.model.UserApproval;
import fi.codecrew.moya.model.UserImage; import fi.codecrew.moya.model.UserImage;
...@@ -91,4 +92,8 @@ public interface UserBeanLocal { ...@@ -91,4 +92,8 @@ public interface UserBeanLocal {
boolean initPasswordResetForUsername(String username, String url); boolean initPasswordResetForUsername(String username, String url);
void addGameID(TournamentGame game, String gameid);
void removeGameIdById(Integer gameIdId);
} }
...@@ -105,6 +105,17 @@ public class EventUser extends GenericEntity { ...@@ -105,6 +105,17 @@ public class EventUser extends GenericEntity {
@Column(name = "createtime", nullable = false, updatable = false) @Column(name = "createtime", nullable = false, updatable = false)
private Date eventuserCreated; 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() { public EventUser getCreator() {
return creator; 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; ...@@ -12,6 +12,7 @@ import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.OrderBy; import javax.persistence.OrderBy;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<h:messages errorClass="error" /> <h:messages errorClass="error" />
<h:panelGroup rendered="#{tournamentCreateView.tournamentGames.isEmpty() eq false}"> <h:panelGroup rendered="#{tournamentCreateView.tournamentGames.isEmpty() eq false}">
<h2>#{i18n['tournaments.admin.select_a_game']}</h2> <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}" /> <f:selectItems var="game" itemLabel="#{game.name}" value="#{tournamentCreateView.tournamentGames}" itemValue="#{game}" />
</h:selectOneMenu> </h:selectOneMenu>
</h:panelGroup> </h:panelGroup>
......
<!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
...@@ -1123,12 +1123,20 @@ user.cropImage = Crop image ...@@ -1123,12 +1123,20 @@ user.cropImage = Crop image
user.cropUserImage = Crop image user.cropUserImage = Crop image
user.defaultImage = Default picture user.defaultImage = Default picture
user.edit = Edit user.edit = Edit
user.edit.gameids = Edit GameIDs
user.edit.title = My information user.edit.title = My information
user.email = Email user.email = Email
user.firstNames = Firstname user.firstNames = Firstname
user.food.title = Choose Menu user.food.title = Choose Menu
user.foodwave.products.title = Choose Products user.foodwave.products.title = Choose Products
user.foodwavelist.title = Choose Foodwave 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.hasImage = Image
user.image = Image user.image = Image
user.imageTooBig = Image is too big user.imageTooBig = Image is too big
......
...@@ -1108,12 +1108,20 @@ user.cropImage = Rajaa ...@@ -1108,12 +1108,20 @@ user.cropImage = Rajaa
user.cropUserImage = Crop image user.cropUserImage = Crop image
user.defaultImage = Oletukuva user.defaultImage = Oletukuva
user.edit = Muokkaa user.edit = Muokkaa
user.edit.gameids = Muokkaa peli-id merkint\u00F6j\u00E4
user.edit.title = Omat tiedot user.edit.title = Omat tiedot
user.email = S\u00E4hk\u00F6posti user.email = S\u00E4hk\u00F6posti
user.firstNames = Etunimi user.firstNames = Etunimi
user.food.title = Valitse Menu user.food.title = Valitse Menu
user.foodwave.products.title = Valitse tuotteet user.foodwave.products.title = Valitse tuotteet
user.foodwavelist.title = Valitse Ruokatilaus 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.hasImage = Kuva
user.imageTooBig = Kuva on liian suuri user.imageTooBig = Kuva on liian suuri
user.imageUpload.imageNotFound = Valitse ensin kuva jonka haluat l\u00E4hett\u00E4\u00E4 user.imageUpload.imageNotFound = Valitse ensin kuva jonka haluat l\u00E4hett\u00E4\u00E4
......
package fi.codecrew.moya.web.cdiview.user;
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!