LectureUserView.java
3.18 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
package fi.codecrew.moya.web.lecture;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.model.ListDataModel;
import javax.inject.Inject;
import javax.inject.Named;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.LectureBeanLocal;
import fi.codecrew.moya.enums.apps.LecturePermission;
import fi.codecrew.moya.model.Lecture;
import fi.codecrew.moya.model.LectureGroup;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.cdiview.user.UserView;
@Named
@ConversationScoped
public class LectureUserView extends GenericCDIView {
private static final long serialVersionUID = 1L;
@Inject
UserView userView;
@EJB
LectureBeanLocal lectureBean;
@EJB
EventBeanLocal eventBean;
ListDataModel<LectureGroup> lectureGroups = null;
ListDataModel<Lecture> lectures = null;
ListDataModel<Lecture> participatedLectures = null;
LectureGroup currentLectureGroup;
public void initView() {
if (super.requirePermissions(LecturePermission.VIEW)) {
super.beginConversation();
}
}
public boolean isLectureGroupsVisible() {
if(lectureBean.getLectureGroups().size() <= 1)
return false;
return true;
}
public ListDataModel<LectureGroup> getLectureGroups() {
lectureGroups = new ListDataModel<LectureGroup>(lectureBean.getLectureGroups());
return lectureGroups;
}
public void selectCurrentLectureGroup() {
if (lectureGroups != null && lectureGroups.isRowAvailable()) {
currentLectureGroup = lectureGroups.getRowData();
lectures = null;
}
}
public LectureGroup getCurrentLectureGroup() {
List<LectureGroup> groups = lectureBean.getLectureGroups();
if (currentLectureGroup == null && groups.size() > 0) {
currentLectureGroup = groups.get(0);
}
return currentLectureGroup;
}
public ListDataModel<Lecture> getLectures() {
if (currentLectureGroup == null)
return new ListDataModel<Lecture>();
lectures = new ListDataModel<Lecture>(lectureBean.findAvailableLectures(getCurrentLectureGroup(), userView.getCurrentUser()));
return lectures;
}
public ListDataModel<Lecture> getParticipatedLectures() {
participatedLectures = new ListDataModel<Lecture>(lectureBean.getParticipatedLectures(userView.getCurrentUser()));
return participatedLectures;
}
public void participateCurrent() {
if (lectures != null && lectures.isRowAvailable()) {
Lecture lecture = lectures.getRowData();
lectureBean.participate(userView.getCurrentUser(), lecture);
super.addFaceMessage("lecture.participated");
this.lectures = null;
}
}
public void unParticipateCurrent() {
if (participatedLectures != null && participatedLectures.isRowAvailable()) {
Lecture lecture = participatedLectures.getRowData();
lectureBean.unparticipate(userView.getCurrentUser(), lecture);
super.addFaceMessage("lecture.unparticipated");
this.lectures = null;
}
}
public boolean isCurrentGroupFull() {
return (lectureBean.userLectureSelectsLeft(getCurrentLectureGroup(), userView.getCurrentUser()) <= 0);
}
public int getCurrentGroupParticipateCount() {
return lectureBean.userLectureSelects(getCurrentLectureGroup(), userView.getCurrentUser());
}
}