This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
/
HPerson.java
215 lines (191 loc) · 5.77 KB
/
HPerson.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
* Copyright 2010, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.model;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Transient;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NaturalId;
import org.hibernate.validator.Email;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
import org.zanata.rest.dto.Person;
import lombok.EqualsAndHashCode;
import lombok.Setter;
import lombok.ToString;
/**
* @see Person
*
*/
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Setter
@EqualsAndHashCode(callSuper = true, of = {"account", "email", "maintainerProjects", "name"}, doNotUseGetters = true)
@ToString(callSuper = true, of = "name")
public class HPerson extends ModelEntityBase implements Serializable
{
private static final long serialVersionUID = 1L;
private String name;
private HAccount account;
private String email;
private Set<HProject> maintainerProjects;
private Set<HIterationGroup> maintainerVersionGroups;
private Set<HLocaleMember> languageTeamMemberships;
@NotEmpty
@Length(min = 2, max = 80)
public String getName()
{
return name;
}
@OneToOne(optional = true, fetch = FetchType.EAGER)
@JoinColumn(name = "accountId")
public HAccount getAccount()
{
return account;
}
@Transient
public boolean hasAccount()
{
return account != null;
}
@Email
@NotEmpty
@NaturalId(mutable = true)
public String getEmail()
{
return email;
}
/*
* This is a read-only side of the relationship. Changes to this collection are allowed but will not
* be persisted.
*/
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "maintainers")
public Set<HProject> getMaintainerProjects()
{
if (maintainerProjects == null)
{
maintainerProjects = new HashSet<HProject>();
}
return maintainerProjects;
}
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "maintainers")
public Set<HIterationGroup> getMaintainerVersionGroups()
{
if (maintainerVersionGroups == null)
{
maintainerVersionGroups = new HashSet<HIterationGroup>();
}
return maintainerVersionGroups;
}
@Transient
public Set<HLocale> getLanguageMemberships()
{
final Set<HLocale> memberships = new HashSet<HLocale>();
for( HLocaleMember locMem : this.getLanguageTeamMemberships() )
{
memberships.add( locMem.getSupportedLanguage() );
}
return memberships;
}
@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "id.person")
protected Set<HLocaleMember> getLanguageTeamMemberships()
{
if( this.languageTeamMemberships == null )
{
this.languageTeamMemberships = new HashSet<HLocaleMember>();
}
return languageTeamMemberships;
}
@Transient
public boolean isMaintainer(HProject proj)
{
// TODO consider implementing business key equality and using
// getMaintainerProjects().contains(proj)
for (HProject project : getMaintainerProjects())
{
if (project.getId().equals( proj.getId() ))
{
return true;
}
}
return false;
}
@Transient
public boolean isMaintainer(HIterationGroup grp)
{
// TODO consider implementing business key equality and using
// getMaintainerVersionGroups().contains(grp)
for (HIterationGroup group : getMaintainerVersionGroups())
{
if (group.getId().equals(grp.getId()))
{
return true;
}
}
return false;
}
@Transient
public boolean isMaintainerOfVersionGroups()
{
return !getMaintainerVersionGroups().isEmpty();
}
@Transient
public boolean isMaintainerOfProjects()
{
return !getMaintainerProjects().isEmpty();
}
@Transient
public boolean isCoordinator(HLocale locale)
{
// TODO PERF consider implementing business key equality
for (HLocaleMember membership : locale.getMembers())
{
if (membership.getPerson().getId().equals( this.getId() )
&& membership.isCoordinator())
{
return true;
}
}
return false;
}
@Transient
public boolean isMember(HLocale locale)
{
// TODO PERF consider implementing business key equality
for (HLocaleMember membership : locale.getMembers())
{
if (membership.getPerson().getId().equals( this.getId() ) )
{
return true;
}
}
return false;
}
}