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   package org.directdemocracyportal.democracy.model.core;
6   
7   import java.util.HashSet;
8   import java.util.Set;
9   
10  import javax.persistence.Entity;
11  import javax.persistence.FetchType;
12  import javax.persistence.GeneratedValue;
13  import javax.persistence.GenerationType;
14  import javax.persistence.Id;
15  import javax.persistence.Inheritance;
16  import javax.persistence.InheritanceType;
17  import javax.persistence.JoinColumn;
18  import javax.persistence.ManyToMany;
19  import javax.persistence.ManyToOne;
20  
21  import org.hibernate.annotations.Cache;
22  import org.hibernate.annotations.CacheConcurrencyStrategy;
23  
24  /***
25   * The Class Role.
26   */
27  @Entity
28  @Inheritance(strategy = InheritanceType.JOINED)
29  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
30  public class Role extends BaseEntity
31  {
32  
33      /*** The Constant serialVersionUID. */
34      private static final long serialVersionUID = 3342667773031897040L;
35  
36      /*** The id. */
37      private Long id;
38  
39      /*** The name. */
40      private String name;
41  
42      /*** The short description. */
43      private String shortDescription;
44  
45      /*** The long description. */
46      private String longDescription;
47  
48      /*** The group agent. */
49      private GroupAgent groupAgent;
50  
51      /*** The players. */
52      private Set<Agent> players = new HashSet<Agent>();
53  
54      /***
55       * Instantiates a new role.
56       */
57      public Role() {
58      }
59  
60      /*
61       * (non-Javadoc)
62       *
63       * @see org.directdemocracyportal.democracy.model.core.BaseEntity#getId()
64       */
65      @Override
66      @Id
67      @GeneratedValue(strategy = GenerationType.AUTO)
68      public Long getId() {
69          return this.id;
70      }
71  
72      /***
73       * Sets the id.
74       *
75       * @param id the new id
76       */
77      public void setId(Long id) {
78          this.id = id;
79      }
80  
81      /***
82       * Gets the name.
83       *
84       * @return the name
85       */
86      public String getName() {
87          return name;
88      }
89  
90      /***
91       * Sets the name.
92       *
93       * @param name the new name
94       */
95      public void setName(String name) {
96          this.name = name;
97      }
98  
99      /***
100      * Gets the group agent.
101      *
102      * @return the group agent
103      */
104     @ManyToOne
105     @JoinColumn
106     public GroupAgent getGroupAgent() {
107         return this.groupAgent;
108     }
109 
110     /***
111      * Sets the group agent.
112      *
113      * @param organisation the new group agent
114      */
115     public void setGroupAgent(GroupAgent organisation) {
116         this.groupAgent = organisation;
117     }
118 
119     /***
120      * Gets the players.
121      *
122      * @return the players
123      */
124     @ManyToMany(fetch = FetchType.LAZY)
125     public Set<Agent> getPlayers() {
126         return players;
127     }
128 
129     /***
130      * Sets the players.
131      *
132      * @param players the new players
133      */
134     public void setPlayers(Set<Agent> players) {
135         this.players = players;
136     }
137 
138     /***
139      * Gets the short description.
140      *
141      * @return the short description
142      */
143     public String getShortDescription() {
144         return shortDescription;
145     }
146 
147     /***
148      * Sets the short description.
149      *
150      * @param shortDescription the new short description
151      */
152     public void setShortDescription(String shortDescription) {
153         this.shortDescription = shortDescription;
154     }
155 
156     /***
157      * Gets the long description.
158      *
159      * @return the long description
160      */
161     public String getLongDescription() {
162         return longDescription;
163     }
164 
165     /***
166      * Sets the long description.
167      *
168      * @param longDescription the new long description
169      */
170     public void setLongDescription(String longDescription) {
171         this.longDescription = longDescription;
172     }
173 
174     /*
175      * (non-Javadoc)
176      *
177      * @see java.lang.Object#hashCode()
178      */
179     @Override
180     public int hashCode() {
181         final int prime = 31;
182         int result = 1;
183         result = prime * result + ((id == null) ? 0 : id.hashCode());
184         result = prime * result
185                 + ((longDescription == null) ? 0 : longDescription.hashCode());
186         result = prime * result + ((name == null) ? 0 : name.hashCode());
187         result = prime
188                 * result
189                 + ((shortDescription == null) ? 0 : shortDescription.hashCode());
190         return result;
191     }
192 
193     /*
194      * (non-Javadoc)
195      *
196      * @see java.lang.Object#equals(java.lang.Object)
197      */
198     @Override
199     public boolean equals(Object obj) {
200         if (this == obj)
201             return true;
202         if (obj == null)
203             return false;
204         if (getClass() != obj.getClass())
205             return false;
206         final Role other = (Role) obj;
207         if (id == null) {
208             if (other.id != null)
209                 return false;
210         } else if (!id.equals(other.id))
211             return false;
212         if (longDescription == null) {
213             if (other.longDescription != null)
214                 return false;
215         } else if (!longDescription.equals(other.longDescription))
216             return false;
217         if (name == null) {
218             if (other.name != null)
219                 return false;
220         } else if (!name.equals(other.name))
221             return false;
222         if (shortDescription == null) {
223             if (other.shortDescription != null)
224                 return false;
225         } else if (!shortDescription.equals(other.shortDescription))
226             return false;
227         return true;
228     }
229 }