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

DataBiosphere / consent / #5880

12 May 2025 01:41PM UTC coverage: 78.691% (-0.07%) from 78.764%
#5880

push

web-flow
[DT-400-maven]: Bump the maven-dependencies group with 2 updates (#2525)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

10063 of 12788 relevant lines covered (78.69%)

0.79 hits per line

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

96.23
/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 Boolean daaAcceptance;
28

29
  public UserUpdateFields() {
1✔
30
  }
1✔
31

32
  public String getDisplayName() {
33
    return displayName;
1✔
34
  }
35

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

40
  public Integer getInstitutionId() {
41
    return institutionId;
1✔
42
  }
43

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

48
  public Boolean getEmailPreference() {
49
    return emailPreference;
1✔
50
  }
51

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

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

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

64
  public String getEraCommonsId() {
65
    return eraCommonsId;
1✔
66
  }
67

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

72
  public Boolean getDaaAcceptance() {
73
    return daaAcceptance;
1✔
74
  }
75

76
  public void setDaaAcceptance(Boolean daaAcceptance) {
77
    this.daaAcceptance = daaAcceptance;
1✔
78
  }
1✔
79

80
  public List<UserProperty> buildUserProperties(Integer userId) {
81
    List<UserProperty> userProps = new ArrayList<>();
1✔
82
    if (Objects.nonNull(this.getDaaAcceptance())) {
1✔
83
      UserProperty prop = new UserProperty();
1✔
84
      prop.setUserId(userId);
1✔
85
      prop.setPropertyKey(UserFields.DAA_ACCEPTANCE.getValue());
1✔
86
      prop.setPropertyValue(this.getDaaAcceptance().toString());
1✔
87
      userProps.add(prop);
1✔
88
    }
89
    return userProps;
1✔
90
  }
91

92
  /**
93
   * Takes a list of current user roles and compares with roles that are being requested to be added
94
   * to the user. The result is a list of user roles that should be added to the user based on
95
   * allowable conditions.
96
   *
97
   * @param currentUserRoleIds List of current user role ids.
98
   * @return List of role ids that need to be added to the user.
99
   */
100
  public List<Integer> getRoleIdsToAdd(List<Integer> currentUserRoleIds) {
101
    return this.getUserRoleIds().stream()
1✔
102
        .filter(
1✔
103
            id -> {
104
              return !currentUserRoleIds.contains(id) && // Don't add any that already exist
1✔
105
                  !IGNORE_ROLE_IDS.contains(id) &&    // Never add ignorable roles
1✔
106
                  VALID_ROLE_IDS.contains(id);        // Only add roles we know about
1✔
107
            })
108
        .collect(Collectors.toList());
1✔
109
  }
110

111
  /**
112
   * Takes a list of current user roles and compares with roles that are being requested to be
113
   * removed from the user. The result is a list of user roles that should be removed from the user
114
   * based on allowable conditions.
115
   *
116
   * @param currentUserRoleIds List of current user role ids.
117
   * @return List of role ids that need to be removed from the user.
118
   */
119
  public List<Integer> getRoleIdsToRemove(List<Integer> currentUserRoleIds) {
120
    return currentUserRoleIds.stream()
1✔
121
        .filter(
1✔
122
            id -> {
123
              return !getUserRoleIds().contains(id) &&
1✔
124
                  // Remove roles that are NOT in the new role id list
125
                  !Objects.equals(id, UserRoles.RESEARCHER.getRoleId()) &&
1✔
126
                  // Never remove the researcher role
127
                  !IGNORE_ROLE_IDS.contains(id) &&
1✔
128
                  // Never remove ignorable roles
129
                  VALID_ROLE_IDS.contains(
1✔
130
                      id);                            // Only remove roles we know about
131
            })
132
        .toList();
1✔
133
  }
134

135
  @Override
136
  public boolean equals(Object o) {
137
    if (o == null || getClass() != o.getClass()) {
1✔
138
      return false;
×
139
    }
140

141
    UserUpdateFields that = (UserUpdateFields) o;
1✔
142
    return Objects.equals(displayName, that.displayName) && Objects.equals(institutionId,
1✔
143
        that.institutionId) && Objects.equals(emailPreference, that.emailPreference)
1✔
144
        && Objects.equals(userRoleIds, that.userRoleIds) && Objects.equals(eraCommonsId,
1✔
145
        that.eraCommonsId) && Objects.equals(daaAcceptance, that.daaAcceptance);
1✔
146
  }
147

148
  @Override
149
  public int hashCode() {
150
    return Objects.hash(displayName, institutionId, emailPreference, userRoleIds, eraCommonsId,
×
151
        daaAcceptance);
152
  }
153
}
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