UserGameIDView.java
2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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;
}
}