| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
package org.directdemocracyportal.democracy.model.application; |
| 6 | |
|
| 7 | |
import java.util.ArrayList; |
| 8 | |
import java.util.Date; |
| 9 | |
import java.util.HashSet; |
| 10 | |
import java.util.List; |
| 11 | |
import java.util.Set; |
| 12 | |
|
| 13 | |
import javax.persistence.CascadeType; |
| 14 | |
import javax.persistence.Column; |
| 15 | |
import javax.persistence.Entity; |
| 16 | |
import javax.persistence.FetchType; |
| 17 | |
import javax.persistence.JoinColumn; |
| 18 | |
import javax.persistence.ManyToMany; |
| 19 | |
import javax.persistence.OneToMany; |
| 20 | |
import javax.persistence.OneToOne; |
| 21 | |
import javax.persistence.Temporal; |
| 22 | |
import javax.persistence.TemporalType; |
| 23 | |
import javax.persistence.Transient; |
| 24 | |
|
| 25 | |
import org.directdemocracyportal.democracy.model.core.Agent; |
| 26 | |
import org.directdemocracyportal.democracy.model.core.Role; |
| 27 | |
import org.directdemocracyportal.democracy.model.world.OrganisationType; |
| 28 | |
import org.directdemocracyportal.democracy.model.world.Person; |
| 29 | |
import org.hibernate.annotations.Cache; |
| 30 | |
import org.hibernate.annotations.CacheConcurrencyStrategy; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
@Entity |
| 36 | |
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) |
| 37 | |
public class User extends Agent |
| 38 | |
{ |
| 39 | |
|
| 40 | |
|
| 41 | |
private static final long serialVersionUID = -1381199844545595026L; |
| 42 | |
|
| 43 | |
|
| 44 | |
private String username; |
| 45 | |
|
| 46 | |
|
| 47 | |
private String password; |
| 48 | |
|
| 49 | |
|
| 50 | |
private String email; |
| 51 | |
|
| 52 | |
|
| 53 | |
private Date createdDate; |
| 54 | |
|
| 55 | |
|
| 56 | |
private Person person; |
| 57 | |
|
| 58 | |
|
| 59 | |
private boolean accountNonExpired; |
| 60 | |
|
| 61 | |
|
| 62 | |
private boolean accountNonLocked; |
| 63 | |
|
| 64 | |
|
| 65 | |
private boolean credentialsNonExpired; |
| 66 | |
|
| 67 | |
|
| 68 | |
private boolean enabled; |
| 69 | |
|
| 70 | |
|
| 71 | 11 | private Set<Authority> grantedAuthorities = new HashSet<Authority>(); |
| 72 | |
|
| 73 | |
|
| 74 | 11 | private List<Event> events = new ArrayList<Event>(); |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | 4 | public User() { |
| 80 | 4 | } |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
public User(Date createdDate, String username, String password,String email, |
| 92 | 7 | Person person) { |
| 93 | 7 | this.username = username; |
| 94 | 7 | this.password = password; |
| 95 | 7 | this.createdDate = createdDate; |
| 96 | 7 | this.email = email; |
| 97 | 7 | this.person = person; |
| 98 | 7 | } |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
public String getPassword() { |
| 106 | 2 | return this.password; |
| 107 | |
} |
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
public void setPassword(String password) { |
| 115 | 1 | this.password = password; |
| 116 | 1 | } |
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
@Column(unique = true) |
| 124 | |
public String getUsername() { |
| 125 | 4 | return this.username; |
| 126 | |
} |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
public void setUsername(String username) { |
| 134 | 1 | this.username = username; |
| 135 | 1 | } |
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
@Temporal(TemporalType.DATE) |
| 143 | |
public void setCreatedDate(Date createdDate) { |
| 144 | 1 | this.createdDate = createdDate; |
| 145 | 1 | } |
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
public Date getCreatedDate() { |
| 153 | 2 | return this.createdDate; |
| 154 | |
} |
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY) |
| 162 | |
public List<Event> getEvents() { |
| 163 | 2 | return events; |
| 164 | |
} |
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
public void setEvents(List<Event> events) { |
| 172 | 0 | this.events = events; |
| 173 | 0 | } |
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
@OneToOne(cascade = CascadeType.ALL) |
| 181 | |
@JoinColumn(name = "person_id") |
| 182 | |
public Person getPerson() { |
| 183 | 0 | return person; |
| 184 | |
} |
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
public void setPerson(Person person) { |
| 192 | 0 | this.person = person; |
| 193 | 0 | } |
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) |
| 201 | |
public Set<Authority> getGrantedAuthorities() { |
| 202 | 0 | return this.grantedAuthorities; |
| 203 | |
} |
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
public void setGrantedAuthorities(Set<Authority> grantedAuthorities) { |
| 211 | 0 | this.grantedAuthorities = grantedAuthorities; |
| 212 | 0 | } |
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
public void setAccountNonExpired(boolean accountNonExpired) { |
| 220 | 0 | this.accountNonExpired = accountNonExpired; |
| 221 | 0 | } |
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
public void setAccountNonLocked(boolean accountNonLocked) { |
| 229 | 0 | this.accountNonLocked = accountNonLocked; |
| 230 | 0 | } |
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
public void setCredentialsNonExpired(boolean credentialsNonExpired) { |
| 238 | 0 | this.credentialsNonExpired = credentialsNonExpired; |
| 239 | 0 | } |
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
public void setEnabled(boolean enabled) { |
| 247 | 0 | this.enabled = enabled; |
| 248 | 0 | } |
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
public boolean isAccountNonExpired() { |
| 256 | 0 | return accountNonExpired; |
| 257 | |
} |
| 258 | |
|
| 259 | |
|
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | |
public boolean isAccountNonLocked() { |
| 265 | 0 | return accountNonLocked; |
| 266 | |
} |
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
public boolean isCredentialsNonExpired() { |
| 274 | 0 | return credentialsNonExpired; |
| 275 | |
} |
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
|
| 282 | |
public boolean isEnabled() { |
| 283 | 0 | return enabled; |
| 284 | |
} |
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
|
| 291 | |
public String getEmail() { |
| 292 | 0 | return email; |
| 293 | |
} |
| 294 | |
|
| 295 | |
|
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
public void setEmail(String email) { |
| 301 | 0 | this.email = email; |
| 302 | 0 | } |
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
|
| 309 | |
@Transient |
| 310 | |
public GovernmentPortal getLocalGovernmentPortal() { |
| 311 | 0 | return getGovernmentPortal(OrganisationType.Local); |
| 312 | |
} |
| 313 | |
|
| 314 | |
|
| 315 | |
|
| 316 | |
|
| 317 | |
|
| 318 | |
|
| 319 | |
@Transient |
| 320 | |
public GovernmentPortal getRegionalGovernmentPortal() { |
| 321 | 0 | return getGovernmentPortal(OrganisationType.Regional); |
| 322 | |
} |
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
|
| 329 | |
@Transient |
| 330 | |
public GovernmentPortal getNationalGovernmentPortal() { |
| 331 | 0 | return getGovernmentPortal(OrganisationType.National); |
| 332 | |
} |
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | |
|
| 338 | |
|
| 339 | |
|
| 340 | |
@Transient |
| 341 | |
private GovernmentPortal getGovernmentPortal( |
| 342 | |
OrganisationType organisationType) { |
| 343 | 0 | for (Role role : getPerson().getRoles()) { |
| 344 | 0 | if (role.getGroupAgent() instanceof GovernmentPortal) { |
| 345 | 0 | GovernmentPortal governmentPortal = (GovernmentPortal) role |
| 346 | |
.getGroupAgent(); |
| 347 | |
|
| 348 | 0 | if (governmentPortal.getOrganisationType().equals( |
| 349 | |
organisationType)) { |
| 350 | 0 | return governmentPortal; |
| 351 | |
} |
| 352 | |
} |
| 353 | 0 | } |
| 354 | 0 | return null; |
| 355 | |
} |
| 356 | |
} |