1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
package org.directdemocracyportal.democracy.model.core; |
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.JoinColumn; |
14 | |
import javax.persistence.ManyToOne; |
15 | |
import javax.persistence.OneToMany; |
16 | |
import javax.persistence.Transient; |
17 | |
|
18 | |
import org.hibernate.annotations.Cache; |
19 | |
import org.hibernate.annotations.CacheConcurrencyStrategy; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
@Entity |
25 | |
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) |
26 | |
public abstract class GroupAgent extends Agent |
27 | |
{ |
28 | |
|
29 | |
|
30 | |
private GroupAgent parent; |
31 | |
|
32 | |
|
33 | 7 | private Set<GroupAgent> children = new HashSet<GroupAgent>(); |
34 | |
|
35 | |
|
36 | 7 | private Set<Role> definedRoles = new HashSet<Role>(); |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 7 | public GroupAgent() { |
42 | 7 | } |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
public GroupAgent(String name) { |
50 | 0 | super(name); |
51 | 0 | } |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
@ManyToOne |
59 | |
@JoinColumn(name = "PARENT_ID") |
60 | |
public GroupAgent getParent() { |
61 | 0 | return parent; |
62 | |
} |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public void setParent(GroupAgent parent) { |
70 | 0 | this.parent = parent; |
71 | 0 | } |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.LAZY) |
79 | |
public Set<GroupAgent> getChildren() { |
80 | 0 | return children; |
81 | |
} |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public void setChildren(Set<GroupAgent> children) { |
89 | 0 | this.children = children; |
90 | 0 | } |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
@OneToMany(mappedBy = "groupAgent", cascade = CascadeType.ALL, fetch = FetchType.LAZY) |
98 | |
public Set<Role> getDefinedRoles() { |
99 | 0 | return this.definedRoles; |
100 | |
} |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
public void setDefinedRoles(Set<Role> definedRoles) { |
108 | 0 | this.definedRoles = definedRoles; |
109 | 0 | } |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
@Transient |
118 | |
public GroupAgent findOrgByName(String name) { |
119 | 0 | for (GroupAgent organisation : getChildren()) { |
120 | 0 | if (name.equals(organisation.getName())) { |
121 | 0 | return organisation; |
122 | |
} |
123 | 0 | } |
124 | 0 | return null; |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
@Transient |
134 | |
public Role findDefinedRoleByName(String name) { |
135 | 0 | for (Role role : getDefinedRoles()) { |
136 | 0 | if (name.equals(role.getName())) { |
137 | 0 | return role; |
138 | |
} |
139 | 0 | } |
140 | 0 | return null; |
141 | |
} |
142 | |
} |