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 javax.persistence.CascadeType;
9   import javax.persistence.Entity;
10  import javax.persistence.GeneratedValue;
11  import javax.persistence.GenerationType;
12  import javax.persistence.Id;
13  import javax.persistence.JoinColumn;
14  import javax.persistence.ManyToOne;
15  import javax.persistence.OneToOne;
16  import javax.persistence.Table;
17  import javax.persistence.Transient;
18  import javax.persistence.UniqueConstraint;
19  import javax.persistence.Version;
20  
21  import org.hibernate.annotations.Cache;
22  import org.hibernate.annotations.CacheConcurrencyStrategy;
23  
24  import com.hack23.cia.model.core.impl.BaseEntity;
25  
26  /***
27   * The Class ParliamentMember.
28   */
29  @Entity
30  @Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "fuzzyKey" }) })
31  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
32  public class ParliamentMember extends BaseEntity {
33  
34      /*** The Constant serialVersionUID. */
35      private static final long serialVersionUID = 1L;
36  
37      /*** The electoral region. */
38      private String electoralRegion;
39      
40      /*** The english wiki href. */
41      private String englishWikiHref;
42  
43      /*** The fuzzy key. */
44      private String fuzzyKey;
45  
46      /*** The href. */
47      private String href;
48  
49      /*** The id. */
50      private Long id;
51  
52      /*** The name. */
53      private String name;
54  
55  
56      /*** The parliament member ballot record. */
57      private ParliamentMemberBallotRecord parliamentMemberBallotRecord;
58  
59      /*** The party. */
60      private String party;
61  
62      /*** The political party. */
63      private PoliticalParty politicalParty;
64  
65      /*** The version. */
66      private Long version=1L;
67  
68      /*** The wiki href. */
69      private String wikiHref;
70      
71      /***
72       * Creates the fuzzy key.
73       */
74      @Transient
75      public final void createFuzzyKey() {
76          this.fuzzyKey = getName().replace(" ", "") + getParty() //$NON-NLS-1$ //$NON-NLS-2$
77                  + getElectoralRegion().replace(" ", ""); //$NON-NLS-1$ //$NON-NLS-2$
78      }
79  
80      /***
81       * Gets the electoral region.
82       *
83       * @return the electoral region
84       */
85      public String getElectoralRegion() {
86          return electoralRegion;
87      }
88  
89      /***
90       * Gets the english wiki href.
91       *
92       * @return the english wiki href
93       */
94      public String getEnglishWikiHref() {
95          return englishWikiHref;
96      }
97  
98  
99      /***
100      * Gets the fuzzy key.
101      *
102      * @return the fuzzy key
103      */
104     public String getFuzzyKey() {
105         return fuzzyKey;
106     }
107 
108     /***
109      * Gets the href.
110      *
111      * @return the href
112      */
113     public String getHref() {
114         return href;
115     }
116 
117     /*
118      * (non-Javadoc)
119      * 
120      * @see com.hack23.cia.model.core.BaseEntity#getId()
121      */
122     @Override
123     @Id
124     @GeneratedValue(strategy = GenerationType.AUTO)
125     public Long getId() {
126         return id;
127     }
128 
129     /***
130      * Gets the international href.
131      *
132      * @return the international href
133      */
134     @Transient
135     public String getInternationalHref() {
136         String intHref = null;
137         if (href != null) {
138             intHref = href.replace("nid=1111", "nid=1811");
139         }
140         return intHref;
141     }
142 
143     /***
144      * Gets the name.
145      *
146      * @return the name
147      */
148     public String getName() {
149         return name;
150     }
151 
152 
153     /***
154      * Gets the parliament member ballot record.
155      *
156      * @return the parliament member ballot record
157      */
158 	@OneToOne(cascade=CascadeType.ALL)
159 	@JoinColumn(name="parliamentMemberBallotRecordId")
160 	public ParliamentMemberBallotRecord getParliamentMemberBallotRecord() {
161 		return parliamentMemberBallotRecord;
162 	}
163 
164     /***
165      * Gets the party.
166      *
167      * @return the party
168      */
169     public String getParty() {
170         return party;
171     }
172 
173     /***
174      * Gets the political party.
175      *
176      * @return the political party
177      */
178     @ManyToOne
179 	public PoliticalParty getPoliticalParty() {
180 		return politicalParty;
181 	}
182  
183     /* (non-Javadoc)
184      * @see com.hack23.cia.model.core.BaseEntity#getVersion()
185      */
186     @Override
187     @Version
188     public Long getVersion() {
189         return version;
190     }
191 
192     /***
193      * Gets the wiki href.
194      *
195      * @return the wiki href
196      */
197     public String getWikiHref() {
198         return wikiHref;
199     }
200 
201 
202     /***
203      * Sets the electoral region.
204      *
205      * @param electoralRegion the new electoral region
206      */
207     public void setElectoralRegion(final String electoralRegion) {
208         this.electoralRegion = electoralRegion;
209     }
210 
211     /***
212      * Sets the english wiki href.
213      *
214      * @param englishWikiHref the new english wiki href
215      */
216     public void setEnglishWikiHref(final String englishWikiHref) {
217         this.englishWikiHref = englishWikiHref;
218     }
219 
220     /***
221      * Sets the fuzzy key.
222      *
223      * @param fuzzyKey the new fuzzy key
224      */
225     public void setFuzzyKey(final String fuzzyKey) {
226         this.fuzzyKey = fuzzyKey;
227     }
228 
229 
230     /***
231      * Sets the href.
232      *
233      * @param href the new href
234      */
235     public void setHref(final String href) {
236         this.href = href;
237     }
238 
239 
240     /***
241      * Sets the id.
242      *
243      * @param id the new id
244      */
245     public void setId(final Long id) {
246         this.id = id;
247     }
248 
249 
250     /***
251      * Sets the name.
252      *
253      * @param name the new name
254      */
255     public void setName(final String name) {
256         this.name = name;
257     }
258 
259     /***
260      * Sets the parliament member ballot record.
261      *
262      * @param parliamentMemberBallotRecord the new parliament member ballot record
263      */
264 	public void setParliamentMemberBallotRecord(
265 			final ParliamentMemberBallotRecord parliamentMemberBallotRecord) {
266 		this.parliamentMemberBallotRecord = parliamentMemberBallotRecord;
267 	}
268 
269 
270     /***
271      * Sets the party.
272      *
273      * @param party the new party
274      */
275     public void setParty(final String party) {
276         this.party = party;
277     }
278 
279 	/***
280 	 * Sets the political party.
281 	 *
282 	 * @param politicalParty the new political party
283 	 */
284 	public void setPoliticalParty(final PoliticalParty politicalParty) {
285 		this.politicalParty = politicalParty;
286 	}
287 
288 	/***
289 	 * Sets the version.
290 	 *
291 	 * @param version the new version
292 	 */
293     public void setVersion(final Long version) {
294         this.version = version;
295     }
296 
297 	/***
298 	 * Sets the wiki href.
299 	 *
300 	 * @param wikiHref the new wiki href
301 	 */
302     public void setWikiHref(final String wikiHref) {
303         this.wikiHref = wikiHref;
304     }
305 }