1
2
3
4
5 package org.directdemocracyportal.democracy.model.world;
6
7 import java.util.HashSet;
8 import java.util.Set;
9
10 import javax.persistence.CascadeType;
11 import javax.persistence.Entity;
12 import javax.persistence.FetchType;
13 import javax.persistence.OneToMany;
14 import javax.persistence.OneToOne;
15 import javax.persistence.Transient;
16
17 import org.directdemocracyportal.democracy.model.world.Vote.Position;
18 import org.hibernate.annotations.Cache;
19 import org.hibernate.annotations.CacheConcurrencyStrategy;
20
21 /***
22 * The Class VoteResult.
23 */
24 @Entity
25 @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
26 public class VoteResult extends Document
27 {
28
29 /*** The Constant serialVersionUID. */
30 private static final long serialVersionUID = 5477103732940234132L;
31
32 /*** The final position. */
33 private Position finalPosition;
34
35 /*** The href. */
36 private String href;
37
38 /*** The issue. */
39 private Issue issue;
40
41 /*** The votes. */
42 private Set<Vote> votes= new HashSet<Vote>();
43
44 /***
45 * Gets the final position.
46 *
47 * @return the final position
48 */
49 public Position getFinalPosition() {
50 return finalPosition;
51 }
52
53 /***
54 * Sets the final position.
55 *
56 * @param finalPosition the new final position
57 */
58 public void setFinalPosition(Position finalPosition) {
59 this.finalPosition = finalPosition;
60 }
61
62 /***
63 * Gets the href.
64 *
65 * @return the href
66 */
67 public String getHref() {
68 return href;
69 }
70
71 /***
72 * Sets the href.
73 *
74 * @param href the new href
75 */
76 public void setHref(String href) {
77 this.href = href;
78 }
79
80 /***
81 * Gets the issue.
82 *
83 * @return the issue
84 */
85 @OneToOne(mappedBy = "voteResult")
86 public Issue getIssue() {
87 return issue;
88 }
89
90 /***
91 * Sets the issue.
92 *
93 * @param issue the new issue
94 */
95 public void setIssue(Issue issue) {
96 this.issue = issue;
97 }
98
99 /***
100 * Gets the votes.
101 *
102 * @return the votes
103 */
104 @OneToMany(mappedBy = "voteResult", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
105 public Set<Vote> getVotes() {
106 return votes;
107 }
108
109 /***
110 * Sets the votes.
111 *
112 * @param votes the new votes
113 */
114 public void setVotes(Set<Vote> votes) {
115 this.votes = votes;
116 }
117
118 /***
119 * Contains vote.
120 *
121 * @param name the name
122 * @return true, if successful
123 */
124 @Transient
125 public boolean containsVote(String name) {
126 for (Vote vote : votes) {
127 if (name.equals(vote.getName())) {
128 return true;
129 }
130 }
131 return false;
132 }
133 }