• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DataBiosphere / consent / #6202

15 Jul 2025 11:16AM UTC coverage: 80.698% (+0.06%) from 80.634%
#6202

push

web-flow
DT-1941: Migrate user email domain lookups to database (#2603)

36 of 40 new or added lines in 6 files covered. (90.0%)

1 existing line in 1 file now uncovered.

10398 of 12885 relevant lines covered (80.7%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.12
/src/main/java/org/broadinstitute/consent/http/models/Institution.java
1
package org.broadinstitute.consent.http.models;
2

3
import java.util.ArrayList;
4
import java.util.Date;
5
import java.util.HashSet;
6
import java.util.List;
7
import java.util.Objects;
8
import org.apache.commons.lang3.StringUtils;
9
import org.apache.commons.lang3.builder.EqualsBuilder;
10
import org.broadinstitute.consent.http.enumeration.OrganizationType;
11
import org.broadinstitute.consent.http.service.UserService.SimplifiedUser;
12

13
public class Institution {
14

15
  public static final String QUERY_FIELDS_WITH_I_PREFIX =
16
      " i.institution_id as i_id, " +
17
          " i.institution_name as i_name, " +
18
          " i.it_director_name as i_it_director_name, " +
19
          " i.it_director_email as i_it_director_email, " +
20
          " i.create_date as i_create_date, " +
21
          " i.update_date as i_update_date ";
22

23
  private Integer id;
24
  private String name;
25
  private String itDirectorName;
26
  private String itDirectorEmail;
27
  private List<SimplifiedUser> signingOfficials;
28
  private String institutionUrl;
29
  private Integer dunsNumber;
30
  private String orgChartUrl;
31
  private String verificationUrl;
32
  private String verificationFilename;
33
  private OrganizationType organizationType;
34
  private List<String> domains;
35
  private Date createDate;
36
  private Integer createUserId;
37
  private Date updateDate;
38
  private Integer updateUserId;
39
  private User createUser;
40
  private User updateUser;
41

42
  //empty constructor sets all null values except create Date
43
  public Institution() {
1✔
44
    this.createDate = new Date();
1✔
45
  }
1✔
46

47
  public void setId(Integer id) {
48
    this.id = id;
1✔
49
  }
1✔
50

51
  public void setName(String name) {
52
    this.name = name;
1✔
53
  }
1✔
54

55
  public void setItDirectorEmail(String itDirectorEmail) {
56
    this.itDirectorEmail = itDirectorEmail;
1✔
57
  }
1✔
58

59
  public void setItDirectorName(String itDirectorName) {
60
    this.itDirectorName = itDirectorName;
1✔
61
  }
1✔
62

63
  public List<SimplifiedUser> getSigningOfficials() {
64
    return signingOfficials;
1✔
65
  }
66

67
  public void setSigningOfficials(List<SimplifiedUser> signingOfficials) {
68
    this.signingOfficials = signingOfficials;
1✔
69
  }
1✔
70

71
  public void addSigningOfficial(SimplifiedUser so) {
72
    if (Objects.isNull(signingOfficials)) {
1✔
73
      this.setSigningOfficials(new ArrayList<>());
1✔
74
    }
75
    if (!new HashSet<>(signingOfficials).contains(so)) {
1✔
76
      signingOfficials.add(so);
1✔
77
    }
78
  }
1✔
79

80
  public Integer getId() {
81
    return id;
1✔
82
  }
83

84
  public String getName() {
85
    return name;
1✔
86
  }
87

88
  public String getItDirectorName() {
89
    return itDirectorName;
1✔
90
  }
91

92
  public String getItDirectorEmail() {
93
    return itDirectorEmail;
1✔
94
  }
95

96
  public String getInstitutionUrl() {
97
    return institutionUrl;
1✔
98
  }
99

100
  public void setInstitutionUrl(String institutionUrl) {
101
    this.institutionUrl = institutionUrl;
1✔
102
  }
1✔
103

104
  public Integer getDunsNumber() {
105
    return dunsNumber;
1✔
106
  }
107

108
  public void setDunsNumber(Integer dunsNumber) {
109
    this.dunsNumber = dunsNumber;
1✔
110
  }
1✔
111

112
  public String getOrgChartUrl() {
113
    return orgChartUrl;
1✔
114
  }
115

116
  public void setOrgChartUrl(String orgChartUrl) {
117
    this.orgChartUrl = orgChartUrl;
1✔
118
  }
1✔
119

120
  public String getVerificationUrl() {
121
    return verificationUrl;
1✔
122
  }
123

124
  public void setVerificationUrl(String verificationUrl) {
125
    this.verificationUrl = verificationUrl;
1✔
126
  }
1✔
127

128
  public String getVerificationFilename() {
129
    return verificationFilename;
1✔
130
  }
131

132
  public void setVerificationFilename(String verificationFilename) {
133
    this.verificationFilename = verificationFilename;
1✔
134
  }
1✔
135

136
  public OrganizationType getOrganizationType() {
137
    return organizationType;
1✔
138
  }
139

140
  public void setOrganizationType(OrganizationType organizationType) {
141
    this.organizationType = organizationType;
1✔
142
  }
1✔
143

144
  public List<String> getDomains() {
145
    return domains;
1✔
146
  }
147

148
  public void setDomains(List<String> domains) {
149
    this.domains = domains;
1✔
150
  }
1✔
151

152
  public void addDomain(String domain) {
153
    if (Objects.isNull(domains)) {
1✔
154
      this.setDomains(new ArrayList<>());
1✔
155
    }
156
    if (!domains.contains(domain)) {
1✔
157
      domains.add(domain);
1✔
158
    }
159
  }
1✔
160

161
  public Date getCreateDate() {
162
    return createDate;
1✔
163
  }
164

165
  public Integer getCreateUserId() {
166
    return createUserId;
1✔
167
  }
168

169
  public Date getUpdateDate() {
170
    return updateDate;
1✔
171
  }
172

173
  public Integer getUpdateUserId() {
174
    return updateUserId;
1✔
175
  }
176

177
  public User getCreateUser() {
178
    return createUser;
×
179
  }
180

181
  public User getUpdateUser() {
182
    return updateUser;
×
183
  }
184

185
  public void setCreateUserId(Integer createUserId) {
186
    this.createUserId = createUserId;
1✔
187
  }
1✔
188

189
  public void setCreateDate(Date date) {
190
    this.createDate = date;
1✔
191
  }
1✔
192

193
  public void setUpdateUserId(Integer updateUserId) {
194
    this.updateUserId = updateUserId;
1✔
195
  }
1✔
196

197
  public void setUpdateDate(Date updateDate) {
198
    this.updateDate = updateDate;
1✔
199
  }
1✔
200

201
  public void setCreateUser(User createUser) {
202
    this.createUser = createUser;
1✔
203
  }
1✔
204

205
  public void setUpdateUser(User updateUser) {
206
    this.updateUser = updateUser;
1✔
207
  }
1✔
208

209

210
  @Override
211
  public boolean equals(Object institution) {
212
    if (institution == this) {
1✔
213
      return true;
1✔
214
    }
215
    if (institution == null || institution.getClass() != getClass()) {
1✔
UNCOV
216
      return false;
×
217
    }
218
    Institution other = (Institution) institution;
1✔
219
    return new EqualsBuilder()
1✔
220
        .append(id, other.getId())
1✔
221
        .isEquals();
1✔
222
  }
223

224
  @Override
225
  public int hashCode() {
226
    return Objects.hash(id);
1✔
227
  }
228

229
  /**
230
   * Merges the updatable fields into this institution from an existing institution. If a field in
231
   * this entity is null, it will be populated with the value of the existing institution. If a
232
   * field in this entity is blank, it will set that field to null to represent an instance of
233
   * intentional field deletion.
234
   *
235
   * @param existing The existing institution to merge from. Must be a full institution entity with
236
   *                 all required fields populated.
237
   */
238
  public Institution mergeUpdatableFields(Institution existing) {
239
    // These fields are not updatable, so we set them directly from the existing institution.
240
    this.setId(existing.getId());
1✔
241
    this.setCreateDate(existing.getCreateDate());
1✔
242
    this.setCreateUserId(existing.getCreateUserId());
1✔
243
    this.setUpdateDate(existing.getUpdateDate());
1✔
244
    this.setUpdateUserId(existing.getUpdateUserId());
1✔
245

246
    // The following fields are updatable, so we merge them from the existing institution.
247
    // Institution.name is not nullable, but it is updatable to a valid value.
248
    if (this.getName() == null || StringUtils.isBlank(this.getName()) ) {
1✔
249
      this.setName(existing.getName());
1✔
250
    }
251
    mergeStringField(this::getItDirectorName, existing::getItDirectorName, this::setItDirectorName);
1✔
252
    mergeStringField(this::getItDirectorEmail, existing::getItDirectorEmail,
1✔
253
        this::setItDirectorEmail);
254
    if (this.getDunsNumber() == null) {
1✔
255
      this.setDunsNumber(existing.getDunsNumber());
1✔
256
    }
257
    mergeStringField(this::getInstitutionUrl, existing::getInstitutionUrl, this::setInstitutionUrl);
1✔
258
    mergeStringField(this::getOrgChartUrl, existing::getOrgChartUrl, this::setOrgChartUrl);
1✔
259
    mergeStringField(this::getVerificationUrl, existing::getVerificationUrl,
1✔
260
        this::setVerificationUrl);
261
    mergeStringField(this::getVerificationFilename, existing::getVerificationFilename,
1✔
262
        this::setVerificationFilename);
263
    if (this.getOrganizationType() == null) {
1✔
264
      this.setOrganizationType(existing.getOrganizationType());
1✔
265
    }
266
    // If domains are not provided, we want to keep the existing domains.
267
    // In the case that empty domains are provided, we want to ensure that they are removed.
268
    if (this.getDomains() == null) {
1✔
269
      this.setDomains(existing.getDomains());
1✔
270
    } else if (this.getDomains().isEmpty()) {
1✔
271
      this.setDomains(null);
1✔
272
    }
273
    return this;
1✔
274
  }
275

276
  /**
277
   * Helper method to merge a value from the existing institution into the payload institution if
278
   * the payload is null. If the payload value is an empty string, it will be set to null to
279
   * represent an intentionally empty value.
280
   *
281
   * @param payloadGetter  The getter for the payload field.
282
   * @param existingGetter The getter for the existing field.
283
   * @param payloadSetter  The setter for the payload field.
284
   */
285
  private void mergeStringField(
286
      java.util.function.Supplier<String> payloadGetter,
287
      java.util.function.Supplier<String> existingGetter,
288
      java.util.function.Consumer<String> payloadSetter
289
  ) {
290
    String value = payloadGetter.get();
1✔
291
    if (value == null) {
1✔
292
      payloadSetter.accept(existingGetter.get());
1✔
293
    } else if (StringUtils.isBlank(value)) {
1✔
294
      payloadSetter.accept(null);
1✔
295
    }
296
  }
1✔
297

298
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc