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

DataBiosphere / consent / #5692

18 Apr 2025 02:50PM UTC coverage: 78.932% (-0.02%) from 78.955%
#5692

push

web-flow
DT-1497: Add code to auto-set institution on user creation (#2485)

Institution is no longer selected by user but is assigned based on a user's email address and the DUOS configured domain-to-institution mapping.

52 of 68 new or added lines in 8 files covered. (76.47%)

1 existing line in 1 file now uncovered.

10183 of 12901 relevant lines covered (78.93%)

0.79 hits per line

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

97.26
/src/main/java/org/broadinstitute/consent/http/models/UserUpdateFields.java
1
package org.broadinstitute.consent.http.models;
2

3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.List;
6
import java.util.Objects;
7
import java.util.stream.Collectors;
8
import org.broadinstitute.consent.http.enumeration.UserFields;
9
import org.broadinstitute.consent.http.enumeration.UserRoles;
10

11
/**
12
 * This class represents the limited amount of information that is available for update from an
13
 * admin-only interface.
14
 */
15
public class UserUpdateFields {
16

17
  // We can only update non-DAC-related roles so always filter those out for addition or removal
18
  protected static final List<Integer> IGNORE_ROLE_IDS = List.of(UserRoles.CHAIRPERSON.getRoleId(),
1✔
19
      UserRoles.MEMBER.getRoleId());
1✔
20
  private static final List<Integer> VALID_ROLE_IDS = Arrays.stream(UserRoles.values())
1✔
21
      .map(UserRoles::getRoleId).toList();
1✔
22
  private String displayName;
23
  private Integer institutionId;
24
  private Boolean emailPreference;
25
  private List<Integer> userRoleIds;
26
  private String eraCommonsId;
27
  private Integer selectedSigningOfficialId;
28
  private String suggestedSigningOfficial;
29
  private Boolean daaAcceptance;
30

31
  public UserUpdateFields() {
1✔
32
  }
1✔
33

34
  public String getDisplayName() {
35
    return displayName;
1✔
36
  }
37

38
  public void setDisplayName(String displayName) {
39
    this.displayName = displayName;
1✔
40
  }
1✔
41

42
  public Integer getInstitutionId() {
43
    return institutionId;
1✔
44
  }
45

46
  public void setInstitutionId(Integer institutionId) {
47
    this.institutionId = institutionId;
1✔
48
  }
1✔
49

50
  public Boolean getEmailPreference() {
51
    return emailPreference;
1✔
52
  }
53

54
  public void setEmailPreference(Boolean emailPreference) {
55
    this.emailPreference = emailPreference;
1✔
56
  }
1✔
57

58
  public List<Integer> getUserRoleIds() {
59
    return userRoleIds;
1✔
60
  }
61

62
  public void setUserRoleIds(List<Integer> userRoleIds) {
63
    this.userRoleIds = userRoleIds;
1✔
64
  }
1✔
65

66
  public String getEraCommonsId() {
67
    return eraCommonsId;
1✔
68
  }
69

70
  public void setEraCommonsId(String eraCommonsId) {
71
    this.eraCommonsId = eraCommonsId;
1✔
72
  }
1✔
73

74
  public Integer getSelectedSigningOfficialId() {
75
    return selectedSigningOfficialId;
1✔
76
  }
77

78
  public void setSelectedSigningOfficialId(Integer selectedSigningOfficialId) {
79
    this.selectedSigningOfficialId = selectedSigningOfficialId;
1✔
80
  }
1✔
81

82
  public String getSuggestedSigningOfficial() {
83
    return suggestedSigningOfficial;
1✔
84
  }
85

86
  public void setSuggestedSigningOfficial(String suggestedSigningOfficial) {
87
    this.suggestedSigningOfficial = suggestedSigningOfficial;
1✔
88
  }
1✔
89

90
  public Boolean getDaaAcceptance() {
91
    return daaAcceptance;
1✔
92
  }
93

94
  public void setDaaAcceptance(Boolean daaAcceptance) {
95
    this.daaAcceptance = daaAcceptance;
1✔
96
  }
1✔
97

98
  public List<UserProperty> buildUserProperties(Integer userId) {
99
    List<UserProperty> userProps = new ArrayList<>();
1✔
100
    if (Objects.nonNull(this.getSelectedSigningOfficialId())) {
1✔
101
      UserProperty prop = new UserProperty();
1✔
102
      prop.setUserId(userId);
1✔
103
      prop.setPropertyKey(UserFields.SELECTED_SIGNING_OFFICIAL_ID.getValue());
1✔
104
      prop.setPropertyValue(this.getSelectedSigningOfficialId().toString());
1✔
105
      userProps.add(prop);
1✔
106
    }
107
    if (Objects.nonNull(this.getSuggestedSigningOfficial())) {
1✔
108
      UserProperty prop = new UserProperty();
1✔
109
      prop.setUserId(userId);
1✔
110
      prop.setPropertyKey(UserFields.SUGGESTED_SIGNING_OFFICIAL.getValue());
1✔
111
      prop.setPropertyValue(this.getSuggestedSigningOfficial());
1✔
112
      userProps.add(prop);
1✔
113
    }
114
    if (Objects.nonNull(this.getDaaAcceptance())) {
1✔
115
      UserProperty prop = new UserProperty();
1✔
116
      prop.setUserId(userId);
1✔
117
      prop.setPropertyKey(UserFields.DAA_ACCEPTANCE.getValue());
1✔
118
      prop.setPropertyValue(this.getDaaAcceptance().toString());
1✔
119
      userProps.add(prop);
1✔
120
    }
121
    return userProps;
1✔
122
  }
123

124
  /**
125
   * Takes a list of current user roles and compares with roles that are being requested to be added
126
   * to the user. The result is a list of user roles that should be added to the user based on
127
   * allowable conditions.
128
   *
129
   * @param currentUserRoleIds List of current user role ids.
130
   * @return List of role ids that need to be added to the user.
131
   */
132
  public List<Integer> getRoleIdsToAdd(List<Integer> currentUserRoleIds) {
133
    return this.getUserRoleIds().stream()
1✔
134
        .filter(
1✔
135
            id -> {
136
              return !currentUserRoleIds.contains(id) && // Don't add any that already exist
1✔
137
                  !IGNORE_ROLE_IDS.contains(id) &&    // Never add ignorable roles
1✔
138
                  VALID_ROLE_IDS.contains(id);        // Only add roles we know about
1✔
139
            })
140
        .collect(Collectors.toList());
1✔
141
  }
142

143
  /**
144
   * Takes a list of current user roles and compares with roles that are being requested to be
145
   * removed from the user. The result is a list of user roles that should be removed from the user
146
   * based on allowable conditions.
147
   *
148
   * @param currentUserRoleIds List of current user role ids.
149
   * @return List of role ids that need to be removed from the user.
150
   */
151
  public List<Integer> getRoleIdsToRemove(List<Integer> currentUserRoleIds) {
152
    return currentUserRoleIds.stream()
1✔
153
        .filter(
1✔
154
            id -> {
155
              return !getUserRoleIds().contains(id) &&
1✔
156
                  // Remove roles that are NOT in the new role id list
157
                  !Objects.equals(id, UserRoles.RESEARCHER.getRoleId()) &&
1✔
158
                  // Never remove the researcher role
159
                  !IGNORE_ROLE_IDS.contains(id) &&
1✔
160
                  // Never remove ignorable roles
161
                  VALID_ROLE_IDS.contains(
1✔
162
                      id);                            // Only remove roles we know about
163
            })
164
        .toList();
1✔
165
  }
166

167
  @Override
168
  public boolean equals(Object o) {
169
    if (o == null || getClass() != o.getClass()) {
1✔
170
      return false;
×
171
    }
172

173
    UserUpdateFields that = (UserUpdateFields) o;
1✔
174
    return Objects.equals(displayName, that.displayName) && Objects.equals(institutionId,
1✔
175
        that.institutionId) && Objects.equals(emailPreference, that.emailPreference)
1✔
176
        && Objects.equals(userRoleIds, that.userRoleIds) && Objects.equals(eraCommonsId,
1✔
177
        that.eraCommonsId) && Objects.equals(selectedSigningOfficialId,
1✔
178
        that.selectedSigningOfficialId) && Objects.equals(suggestedSigningOfficial,
1✔
179
        that.suggestedSigningOfficial) && Objects.equals(daaAcceptance, that.daaAcceptance);
1✔
180
  }
181

182
  @Override
183
  public int hashCode() {
NEW
184
    return Objects.hash(displayName, institutionId, emailPreference, userRoleIds, eraCommonsId,
×
185
        selectedSigningOfficialId, suggestedSigningOfficial, daaAcceptance);
186
  }
187
}
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