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.world;
6   
7   import javax.persistence.Entity;
8   import javax.persistence.Transient;
9   
10  import org.directdemocracyportal.democracy.model.core.Agent;
11  import org.directdemocracyportal.democracy.model.core.Role;
12  import org.hibernate.annotations.Cache;
13  import org.hibernate.annotations.CacheConcurrencyStrategy;
14  
15  /***
16   * The Class Person.
17   */
18  @Entity
19  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
20  public class Person extends Agent
21  {
22  
23      /*** The Constant serialVersionUID. */
24      private static final long serialVersionUID = -8213090131046642286L;
25  
26      /***
27       * Instantiates a new person.
28       */
29      public Person() {
30      }
31  
32      /***
33       * Instantiates a new person.
34       *
35       * @param name the name
36       */
37      public Person(String name) {
38          super(name);
39      }
40  
41      /***
42       * Gets the political party.
43       *
44       * @return the political party
45       */
46      @Transient
47      public PoliticalParty getPoliticalParty() {
48          for (Role role : getRoles()) {
49              if (role.getGroupAgent() instanceof PoliticalParty) {
50                  return (PoliticalParty) role.getGroupAgent();
51              }
52          }
53          return null;
54      }
55  
56      /***
57       * Gets the role in org.
58       *
59       * @param organisation the organisation
60       * @return the role in org
61       */
62      @Transient
63      public Role getRoleInOrg(Organisation organisation) {
64          for (Role role : getRoles()) {
65              if (role.getGroupAgent().equals(organisation)) {
66                  return role;
67              }
68          }
69          return null;
70      }
71  
72  }