User extends AbstractDomainObject { public boolean hasAnyUserRole(UserRole... userRoles) { return Arrays.stream(userRoles).anyMatch(getUserRoles()::contains); }  @Column(nullable = false, length = COLUMN_LENGTH_DEFAULT) String getUserName(); void setUserName(String userName); @Size(max = 64) @Column(name = "password", nullable = false, length = 64) @AuditedAttribute(anonymous = true, anonymizingString = "*****") String getPassword(); void setPassword(String password); @Column(name = "seed", nullable = false, length = 16) @AuditedAttribute(anonymous = true, anonymizingString = "*****") String getSeed(); void setSeed(String seed); @Column(nullable = false) boolean isActive(); void setActive(boolean active); @Column(nullable = false, length = COLUMN_LENGTH_DEFAULT) String getFirstName(); void setFirstName(String firstName); @Column(nullable = false, length = COLUMN_LENGTH_DEFAULT) String getLastName(); void setLastName(String lastName); String getUserEmail(); void setUserEmail(String userEmail); String getPhone(); void setPhone(String phone); @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) Location getAddress(); void setAddress(Location address); @ManyToOne(cascade = {}) Region getRegion(); void setRegion(Region region); @ElementCollection(fetch = FetchType.LAZY) @Enumerated(EnumType.STRING) @CollectionTable(name = TABLE_NAME_USERROLES, joinColumns = @JoinColumn(name = "user_id", referencedColumnName = User.ID, nullable = false), uniqueConstraints = @UniqueConstraint(columnNames = { "user_id", "userrole" })) @Column(name = "userrole", nullable = false) Set<UserRole> getUserRoles(); void setUserRoles(Set<UserRole> userRoles); @ManyToOne(cascade = {}) User getAssociatedOfficer(); void setAssociatedOfficer(User associatedOfficer); @Override String toString(); UserReferenceDto toReference(); @Transient boolean isSupervisor(); @ManyToOne(cascade = {}) District getDistrict(); void setDistrict(District district); @ManyToOne(cascade = {}) Community getCommunity(); void setCommunity(Community community); @ManyToOne(cascade = {}) Facility getHealthFacility(); void setHealthFacility(Facility healthFacility); @ManyToOne(cascade = {}) Facility getLaboratory(); void setLaboratory(Facility laboratory); @ManyToOne(cascade = {}) PointOfEntry getPointOfEntry(); void setPointOfEntry(PointOfEntry pointOfEntry); @Enumerated(EnumType.STRING) Disease getLimitedDisease(); void setLimitedDisease(Disease limitedDisease); @Enumerated(EnumType.STRING) Language getLanguage(); void setLanguage(Language language); boolean hasAnyUserRole(UserRole... userRoles); @Transient JurisdictionLevel getJurisdictionLevel(); static final String TABLE_NAME_USERROLES; static final String USER_NAME; static final String PASSWORD; static final String SEED; static final String ACTIVE; static final String FIRST_NAME; static final String LAST_NAME; static final String USER_EMAIL; static final String PHONE; static final String ADDRESS; static final String REGION; static final String DISTRICT; static final String COMMUNITY; static final String USER_ROLES; static final String HEALTH_FACILITY; static final String LABORATORY; static final String POINT_OF_ENTRY; static final String ASSOCIATED_OFFICER; static final String LANGUAGE; }
@Test public void testHasAnyUserRole() { User u = new User(); Set<UserRole> userRoles = new HashSet<>(); u.setUserRoles(userRoles); MatcherAssert.assertThat(u.hasAnyUserRole(UserRole.ADMIN), Matchers.is(false)); userRoles.add(UserRole.ADMIN); MatcherAssert.assertThat(u.hasAnyUserRole(UserRole.ADMIN), Matchers.is(true)); userRoles.add(UserRole.CASE_OFFICER); MatcherAssert.assertThat(u.hasAnyUserRole(UserRole.ADMIN), Matchers.is(true)); MatcherAssert.assertThat(u.hasAnyUserRole(UserRole.CASE_OFFICER), Matchers.is(true)); MatcherAssert.assertThat(u.hasAnyUserRole(UserRole.CASE_SUPERVISOR), Matchers.is(false)); MatcherAssert.assertThat(u.hasAnyUserRole(UserRole.ADMIN, UserRole.CASE_OFFICER), Matchers.is(true)); MatcherAssert.assertThat(u.hasAnyUserRole(UserRole.CASE_OFFICER, UserRole.CASE_SUPERVISOR), Matchers.is(true)); }