LicenseView.java
3.47 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package fi.codecrew.moya.web.cdiview.license;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.model.ListDataModel;
import javax.inject.Named;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.LicenseBeanLocal;
import fi.codecrew.moya.beans.LicenseBeanLocal.GenerationException;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.ProductBeanLocal;
import fi.codecrew.moya.enums.apps.LicensePermission;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LicenseCode;
import fi.codecrew.moya.model.LicenseTarget;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@ConversationScoped
public class LicenseView extends GenericCDIView {
private static final long serialVersionUID = -8346420143750551402L;
private EventUser currentUser;
@EJB
private PermissionBeanLocal permissionBean;
@EJB
private EventBeanLocal eventBean;
@EJB
private LicenseBeanLocal licenseBean;
@EJB
private ProductBeanLocal productBean;
private ListDataModel<LicenseTarget> licenses;
private ListDataModel<LicenseCode> licenseCodes;
private LicenseTarget currentLicense;
public void initAdminView() {
if (super.requirePermissions(LicensePermission.MANAGE)) {
if (licenses == null) {
this.currentLicense = new LicenseTarget();
this.currentLicense.setEvent(eventBean.getCurrentEvent());
this.licenses = new ListDataModel<LicenseTarget>(licenseBean.findAll(eventBean.getCurrentEvent()));
this.beginConversation();
}
}
}
public void initUserView() {
if (super.requirePermissions(LicensePermission.VIEW_OWN_CODES)) {
if (licenseCodes == null) {
currentUser = permissionBean.getCurrentUser();
this.licenseCodes = new ListDataModel<LicenseCode>(currentUser.getUser().getLicenseCodes());
this.licenses = new ListDataModel<LicenseTarget>(licenseBean.findUnopenedUserGames(currentUser));
this.beginConversation();
}
}
}
public String saveCurrentLicense() {
licenseBean.saveOrCreateLicense(currentLicense);
this.licenses = new ListDataModel<LicenseTarget>(licenseBean.findAll(eventBean.getCurrentEvent()));
return null;
}
public String editSelected() {
return null;
}
public String openSelectedCode() {
if(this.licenses != null && this.licenses.isRowAvailable()) {
LicenseTarget license = this.licenses.getRowData();
try {
LicenseCode code = licenseBean.createAndAccessCode(license, currentUser.getUser());
} catch(GenerationException x) {
this.addFaceMessage("game.out");
}
licenseCodes = null;
initUserView();
}
return null;
}
public boolean isNoLicenseCodes() {
return (getLicenseCodes().getRowCount() <= 0);
}
public boolean isNoLicenses() {
return (getLicenses().getRowCount() <= 0);
}
public ListDataModel<LicenseCode> getLicenseCodes() {
return licenseCodes;
}
public void setLicenseCodes(ListDataModel<LicenseCode> licenseCodes) {
this.licenseCodes = licenseCodes;
}
public ListDataModel<LicenseTarget> getLicenses() {
return licenses;
}
public void setLicenses(ListDataModel<LicenseTarget> licenses) {
this.licenses = licenses;
}
public LicenseTarget getCurrentLicense() {
return currentLicense;
}
public void setCurrentLicense(LicenseTarget currentLicense) {
this.currentLicense = currentLicense;
}
public List<Product> getProductsForLicenses() {
return productBean.findPlaceProducts();
}
}