EntryWrapper.java
1.92 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
package fi.codecrew.moya.web.cdiview.voting;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.VotingBeanLocal;
import fi.codecrew.moya.model.CompoEntry;
import fi.codecrew.moya.model.Vote;
public class EntryWrapper implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8261328741517788115L;
private Integer votetotal;
private final CompoEntry entry;
private Integer vote = 0;
private static final Logger logger = LoggerFactory.getLogger(EntryWrapper.class);
public EntryWrapper(CompoEntry entry, Vote voteEntity, boolean calcSummary) {
this.entry = entry;
if (voteEntity != null)
{
vote = voteEntity.getScore();
}
if (calcSummary) {
votetotal = 0;
for (Vote v : entry.getVotes()) {
votetotal += v.getScore();
}
}
}
public static ListDataModel<EntryWrapper> init(List<CompoEntry> compoEntries, VotingBeanLocal votbean, boolean calcSummary) {
ArrayList<EntryWrapper> ret = new ArrayList<EntryWrapper>();
for (CompoEntry entry : compoEntries)
{
if (entry.getSort() != null && entry.getSort() > 0)
{
Vote voteEntity = votbean.saveVote(entry, null);
EntryWrapper wrap = new EntryWrapper(entry, voteEntity, calcSummary);
ret.add(wrap);
}
}
return new ListDataModel<EntryWrapper>(ret);
}
public CompoEntry getEntry() {
return entry;
}
public Integer getVote() {
return vote;
}
public void setVote(Integer vot) {
if (vot == null) {
this.vote = 0;
} else {
this.vote = vot;
}
}
public Integer getVotetotal()
{
return votetotal;
}
public Integer getRatingVote()
{
return vote + 3;
}
public void setRatingVote(Integer vot)
{
if (vot < 1 || vot > 5)
{
vot = 3;
}
this.vote = vot - 3;
logger.info("setting ratevote {} to realvote {}", vot, vote);
}
}