PrintedCard.java
5.58 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fi.insomnia.bortal.model;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Comparator;
import java.util.List;
import javax.faces.model.ListDataModel;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/**
*
*/
@Entity
@Table(name = "printed_cards", uniqueConstraints = {
@UniqueConstraint(columnNames = { "event_id", "rfid_uid", }),
@UniqueConstraint(columnNames = { "event_id", "barcode" }) })
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class PrintedCard extends GenericEntity {
/**
*
*/
private static final long serialVersionUID = 8603481931116401027L;
public static final String EVENT_ID_COLUMN = "event_id";
@ManyToOne()
@JoinColumn(name = EVENT_ID_COLUMN, nullable = false)
private LanEvent event;
@Column(name = "print_time")
@Temporal(TemporalType.TIMESTAMP)
private Calendar printTime;
@Column(name = "barcode")
private String barcode;
@Column(name = "card_enabled", nullable = false)
private boolean enabled = true;
@Column(name = "rfid_uid")
private String rfidUid;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "printedCard")
private List<ReaderEvent> readerEvents = new ArrayList<ReaderEvent>();
@Column(name = "print_count", nullable = false)
private int printCount = 0;
@JoinColumn(name = "current_location_id", referencedColumnName = "id")
@ManyToOne
private Location currentLocation;
@JoinColumn(name = "user_id", referencedColumnName = "id", nullable = false)
@ManyToOne(optional = false)
private User user;
@JoinColumn(nullable = false, name = "card_template_id", referencedColumnName = CardTemplate.ID_COLUMN)
@ManyToOne(optional = false)
private CardTemplate template;
public PrintedCard(LanEvent event, Calendar printTime, boolean cardEnabled) {
this(event);
this.printTime = printTime;
this.enabled = cardEnabled;
}
public LanEvent getEvent() {
return event;
}
public void setEvent(LanEvent event) {
this.event = event;
}
public PrintedCard() {
super();
}
public PrintedCard(LanEvent event) {
super();
this.event = event;
}
public Calendar getPrintTime() {
return printTime;
}
public void setPrintTime(Calendar printTime) {
this.printTime = printTime;
}
public String getBarcode() {
return barcode;
}
public void setBarcode(String barcode) {
this.barcode = barcode;
}
public boolean getEnabled() {
return enabled;
}
public void setEnabled(boolean cardEnabled) {
this.enabled = cardEnabled;
}
public String getRfidUid() {
return rfidUid;
}
public void setRfidUid(String rfidUid) {
this.rfidUid = rfidUid;
}
public List<ReaderEvent> getReaderEvents() {
return readerEvents;
}
public void setReaderEvents(List<ReaderEvent> readerEventList) {
this.readerEvents = readerEventList;
}
public Location getCurrentLocation() {
return currentLocation;
}
public void setCurrentLocation(Location currentLocation) {
this.currentLocation = currentLocation;
}
public User getUser() {
return user;
}
public void setUser(User usersId) {
this.user = usersId;
}
public void setTemplate(CardTemplate template) {
this.template = template;
}
public CardTemplate getTemplate() {
return template;
}
public void setPrintCount(int printCount) {
this.printCount = printCount;
}
public int getPrintCount() {
return printCount;
}
public static final Comparator<PrintedCard> GAMEPOINT_COMPARATOR = new Comparator<PrintedCard>() {
@Override
public int compare(PrintedCard o1, PrintedCard o2) {
int ret = o2.getGamepoints().compareTo(o1.getGamepoints());
if (ret == 0 && o1.getUser().getNick() != null && o2.getUser().getNick() != null)
{
ret = o1.getUser().getNick().compareTo(o2.getUser().getNick());
}
return ret;
}
};
@Transient
private Integer gamepoints = null;
public Integer getGamepoints() {
if (gamepoints == null) {
Integer ret = 0;
for (ReaderEvent re : this.getReaderEvents()) {
ret += re.getGamePoint();
}
gamepoints = ret;
}
return gamepoints;
}
@Transient
private transient ListDataModel<ReaderEvent> revents;
public ListDataModel<ReaderEvent> getGameCards() {
if (revents == null) {
List<ReaderEvent> ev = this.getReaderEvents();
ArrayList<ReaderEvent> ret = new ArrayList<ReaderEvent>();
for (ReaderEvent e : ev) {
if (e.getGamePoint() > 0) {
ret.add(e);
}
}
revents = new ListDataModel<ReaderEvent>(ret);
}
return revents;
}
}