| 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.Transient; |
| 15 | |
|
| 16 | |
import org.directdemocracyportal.democracy.model.core.Role; |
| 17 | |
import org.hibernate.annotations.Cache; |
| 18 | |
import org.hibernate.annotations.CacheConcurrencyStrategy; |
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
@Entity |
| 24 | |
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) |
| 25 | |
public class Government extends Organisation |
| 26 | |
{ |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | 0 | public enum GovernmentRoles { |
| 32 | |
|
| 33 | |
|
| 34 | 0 | Head_of_State |
| 35 | |
}; |
| 36 | |
|
| 37 | |
|
| 38 | |
private static final long serialVersionUID = -946981671229247412L; |
| 39 | |
|
| 40 | |
|
| 41 | |
private GovernmentType GovernmentType; |
| 42 | |
|
| 43 | |
|
| 44 | 2 | private Set<Election> elections = new HashSet<Election>(); |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | 2 | public Government() { |
| 50 | 2 | } |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
public GovernmentType getGovernmentType() { |
| 58 | 0 | return GovernmentType; |
| 59 | |
} |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
public void setGovernmentType(GovernmentType GovernmentType) { |
| 67 | 0 | this.GovernmentType = GovernmentType; |
| 68 | 0 | } |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
@OneToMany(mappedBy = "government", cascade = CascadeType.ALL, fetch = FetchType.LAZY) |
| 76 | |
public Set<Election> getElections() { |
| 77 | 2 | return elections; |
| 78 | |
} |
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
public void setElections(Set<Election> elections) { |
| 86 | 0 | this.elections = elections; |
| 87 | 0 | } |
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
@Transient |
| 95 | |
public Person getHeadofState() { |
| 96 | 0 | for (Role role : getDefinedRoles()) { |
| 97 | 0 | if (role.getName().equals(GovernmentRoles.Head_of_State.toString())) { |
| 98 | 0 | return (Person) role.getPlayers().iterator().next(); |
| 99 | |
} |
| 100 | 0 | } |
| 101 | 0 | return null; |
| 102 | |
} |
| 103 | |
} |