View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
3   	$Id
4   */
5   
6   package com.hack23.cia.model.sweden.impl;
7   
8   import java.util.Date;
9   
10  import javax.persistence.CascadeType;
11  import javax.persistence.Entity;
12  import javax.persistence.EnumType;
13  import javax.persistence.Enumerated;
14  import javax.persistence.GeneratedValue;
15  import javax.persistence.GenerationType;
16  import javax.persistence.Id;
17  import javax.persistence.JoinColumn;
18  import javax.persistence.ManyToOne;
19  import javax.persistence.OneToOne;
20  import javax.persistence.Table;
21  import javax.persistence.Temporal;
22  import javax.persistence.TemporalType;
23  import javax.persistence.Transient;
24  import javax.persistence.UniqueConstraint;
25  import javax.persistence.Version;
26  
27  import org.hibernate.annotations.Cache;
28  import org.hibernate.annotations.CacheConcurrencyStrategy;
29  
30  import com.hack23.cia.model.core.impl.BaseEntity;
31  
32  /***
33   * The Class Vote.
34   */
35  @Entity
36  @Table(uniqueConstraints = { @UniqueConstraint(columnNames = {
37          "parliamentMember_id", "ballot_id" }) })
38  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
39  public class Vote extends BaseEntity {
40  
41      /***
42       * The Enum Position.
43       */
44      public enum Position {
45  
46          /*** The Absent. */
47          Absent,
48  
49          /*** The Neutral. */
50          Neutral,
51  
52          /*** The No. */
53          No,
54  
55          /*** The Yes. */
56          Yes
57      }
58  
59      /*** The Constant serialVersionUID. */
60      private static final long serialVersionUID = 1L;
61  
62      /*** The ballot. */
63      private Ballot ballot;
64  
65      /*** The datum. */
66      private Date datum;
67  
68      /*** The id. */
69      private Long id;
70  
71      /*** The parliament member. */
72      private ParliamentMember parliamentMember;
73  
74      /*** The position. */
75      private Position position;
76      
77      /*** The version. */
78      private Long version=1L;
79  
80      /*** The vote meta data. */
81      private VoteMetaData voteMetaData;
82  
83      /***
84       * Gets the ballot.
85       *
86       * @return the ballot
87       */
88      @ManyToOne
89      public Ballot getBallot() {
90          return ballot;
91      }
92  
93      /***
94       * Gets the datum.
95       *
96       * @return the datum
97       */
98      @Temporal(TemporalType.DATE)
99      public Date getDatum() {
100         return datum;
101     }
102 
103     /*
104      * (non-Javadoc)
105      * 
106      * @see com.hack23.cia.model.core.BaseEntity#getId()
107      */
108     @Override
109     @Id
110     @GeneratedValue(strategy = GenerationType.AUTO)
111     public Long getId() {
112         return id;
113     }
114 
115     /***
116      * Gets the parliament member.
117      *
118      * @return the parliament member
119      */
120     @ManyToOne
121     public ParliamentMember getParliamentMember() {
122         return parliamentMember;
123     }
124 
125     /***
126      * Gets the position.
127      *
128      * @return the position
129      */
130     @Enumerated(EnumType.STRING)
131     public Position getPosition() {
132         return position;
133     }
134 
135     /* (non-Javadoc)
136      * @see com.hack23.cia.model.core.BaseEntity#getVersion()
137      */
138     @Override
139     @Version
140     public Long getVersion() {
141         return version;
142     }
143 
144     /***
145      * Gets the vote meta data.
146      *
147      * @return the vote meta data
148      */
149     @OneToOne(cascade=CascadeType.ALL)
150     @JoinColumn(name="id")
151 	public VoteMetaData getVoteMetaData() {
152 		return voteMetaData;
153 	}
154 
155     /***
156      * Checks if is rebel.
157      *
158      * @return true, if is rebel
159      */
160     @Transient
161     public boolean isRebel() {
162     	return getBallot().isRebelVote(this);
163     }
164 
165     /***
166      * Checks if is winning.
167      *
168      * @return true, if is winning
169      */
170     @Transient
171     public boolean isWinning() {
172     	return getBallot().isWinningPosition(this.getPosition());
173     }
174 
175     /***
176      * Sets the ballot.
177      *
178      * @param ballot the new ballot
179      */
180     public void setBallot(final Ballot ballot) {
181         this.ballot = ballot;
182     }
183 
184     /***
185      * Sets the datum.
186      *
187      * @param datum the new datum
188      */
189     public void setDatum(final Date datum) {
190         this.datum = datum;
191     }
192 
193     /***
194      * Sets the id.
195      *
196      * @param id the new id
197      */
198     public void setId(final Long id) {
199         this.id = id;
200     }
201     
202     /***
203      * Sets the parliament member.
204      *
205      * @param parliamentMember the new parliament member
206      */
207     public void setParliamentMember(final ParliamentMember parliamentMember) {
208         this.parliamentMember = parliamentMember;
209     }
210 
211     /***
212      * Sets the position.
213      *
214      * @param position the new position
215      */
216     public void setPosition(final Position position) {
217         this.position = position;
218     }
219 
220     /***
221      * Sets the version.
222      *
223      * @param version the new version
224      */
225     public void setVersion(final Long version) {
226         this.version = version;
227     }
228 
229 	/***
230 	 * Sets the vote meta data.
231 	 *
232 	 * @param voteMetaData the new vote meta data
233 	 */
234 	public void setVoteMetaData(final VoteMetaData voteMetaData) {
235 		this.voteMetaData = voteMetaData;
236 	}
237 	
238 }