MapView.java
2.4 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
package fi.codecrew.moya.web.cdiview.map;
import java.math.BigDecimal;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.web.annotations.SelectedUser;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@RequestScoped
public class MapView extends GenericCDIView {
private static final long serialVersionUID = 2374905512998240551L;
@Inject
@SelectedUser
private EventUser user;
private EventMap activeMap;
@EJB
private transient PlaceBeanLocal placeBean;
@EJB
private transient EventBeanLocal eventBean;
private BigDecimal balance;
private static final Logger logger = LoggerFactory.getLogger(MapView.class);
public void initViewMap()
{
super.requirePermissions(MapPermission.VIEW);
}
public boolean canView() {
return permbean.hasPermission(MapPermission.VIEW);
}
public boolean canUserBuy() {
if (user == null) {
return false;
}
return getAccountBalance().compareTo(BigDecimal.ZERO) > 0;
}
public BigDecimal getAccountBalance()
{
if (balance == null)
{
balance = user.getAccountBalance();
}
return balance;
}
public BigDecimal getReservationPrice() {
BigDecimal ret = null;
if (permbean.isCurrentUser(user))
ret = placeBean.getTotalReservationPrice(null);
else {
ret = placeBean.getTotalReservationPrice(user, null);
}
return ret;
}
public Long getPlacesLeftToSelect() {
Long ret = placeBean.selectablePlaceCount(getActiveMap());
logger.debug("Got {} places left for map {}", ret, getActiveMap());
return ret;
}
public Long getAvailablePlaces()
{
Long ret = placeBean.availablePlaceCount(getActiveMap());
logger.debug("Got {} availbale places for map {}", ret, getActiveMap());
return ret;
}
@Produces
public EventMap getActiveMap() {
if (activeMap == null) {
activeMap = placeBean.getActiveMap();
}
return activeMap;
}
public void setActiveMap(EventMap activeMap) {
this.activeMap = activeMap;
}
public void setUser(EventUser user) {
this.user = user;
}
public EventUser getUser() {
return user;
}
}