Skip to content

Commit

Permalink
annotation for user*class
Browse files Browse the repository at this point in the history
  • Loading branch information
mbussolotto committed Jan 31, 2025
1 parent d61315e commit e952755
Show file tree
Hide file tree
Showing 45 changed files with 350 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import com.redhat.rhn.domain.channel.Modules;
import com.redhat.rhn.domain.channel.test.ChannelFactoryTest;
import com.redhat.rhn.domain.rhnpackage.Package;
import com.redhat.rhn.domain.role.Role;
import com.redhat.rhn.domain.role.RoleFactory;
import com.redhat.rhn.domain.role.RoleImpl;
import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.server.ServerConstants;
import com.redhat.rhn.domain.server.test.ServerFactoryTest;
Expand Down Expand Up @@ -480,7 +480,7 @@ public void testCanEvalIfServerSupportsPtfRemoval() {
* Override the methods in User that talk to the database
*/
class MockUser extends UserImpl {
private final Set<Role> mockRoles;
private final Set<RoleImpl> mockRoles;

MockUser() {
mockRoles = new HashSet<>();
Expand All @@ -492,13 +492,13 @@ class MockUser extends UserImpl {
* that isn't necessary for this Unit Test
*/
@Override
public void addPermanentRole(Role label) {
public void addPermanentRole(RoleImpl label) {
mockRoles.add(label);
}

/** @see com.redhat.rhn.domain.user.User#hasRole */
@Override
public boolean hasRole(Role label) {
public boolean hasRole(RoleImpl label) {
return mockRoles.contains(label);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package com.redhat.rhn.domain.notification;

import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.domain.user.legacy.UserImpl;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
Expand Down Expand Up @@ -59,7 +59,7 @@ public UserNotification() {
* @param userIn the user
* @param messageIn the message
*/
public UserNotification(User userIn, NotificationMessage messageIn) {
public UserNotification(UserImpl userIn, NotificationMessage messageIn) {
this.userId = userIn.getId();
this.message = messageIn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import com.redhat.rhn.domain.notification.types.NotificationData;
import com.redhat.rhn.domain.notification.types.NotificationType;
import com.redhat.rhn.domain.org.Org;
import com.redhat.rhn.domain.role.Role;
import com.redhat.rhn.domain.role.RoleImpl;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.domain.user.UserFactory;
import com.redhat.rhn.domain.user.legacy.UserImpl;

import com.suse.manager.utils.MailHelper;
import com.suse.manager.webui.websocket.Notification;
Expand All @@ -35,13 +36,12 @@
import org.apache.logging.log4j.Logger;

import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaDelete;
Expand Down Expand Up @@ -99,7 +99,7 @@ public static void setMailer(Mail mailerIn) {
* @param messageIn the message
* @return new UserNotification
*/
public static UserNotification create(User userIn, NotificationMessage messageIn) {
public static UserNotification create(UserImpl userIn, NotificationMessage messageIn) {
return new UserNotification(userIn, messageIn);
}

Expand Down Expand Up @@ -151,7 +151,7 @@ public static NotificationMessage createNotificationMessage(NotificationData not
* @param notificationMessageIn notification to store
* @param users user that should see the notification
*/
public static void storeForUsers(NotificationMessage notificationMessageIn, Set<User> users) {
public static void storeForUsers(NotificationMessage notificationMessageIn, Set<UserImpl> users) {
// save first the message to get the 'id' auto generated
// because it is referenced by the UserNotification object
singleton.saveObject(notificationMessageIn);
Expand Down Expand Up @@ -191,21 +191,28 @@ public static void storeForUsers(NotificationMessage notificationMessageIn, Set<
* @param org org users need to be in to see the notification.
*/
public static void storeNotificationMessageFor(NotificationMessage notificationMessageIn,
Set<Role> rolesIn, Optional<Org> org) {
Set<RoleImpl> rolesIn, Optional<Org> org) {
// only users in the current Org
// do not create notifications for non active users
// only users with one role in the roles
Stream<User> allUsers = UserFactory.getInstance().findAllUsers(org).stream()
.filter(user -> !user.isDisabled());
Set<UserImpl> allUsers = UserFactory.getInstance().findAllUsers(org).stream()
.filter(user -> !user.isDisabled()).collect(Collectors.toSet());

if (rolesIn.isEmpty()) {
storeForUsers(notificationMessageIn, allUsers.collect(Collectors.toSet()));
storeForUsers(notificationMessageIn, allUsers);
}
else {
storeForUsers(
notificationMessageIn,
allUsers.filter(user -> !Collections.disjoint(user.getRoles(), rolesIn)).collect(Collectors.toSet())
);
Set<UserImpl> validUsers = new HashSet<>();
for (UserImpl user : allUsers) {
Set<RoleImpl> userRoles = user.getRoles();
for (RoleImpl role : userRoles) {
if (rolesIn.contains(role)) {
validUsers.add(user);
break;
}
}
}
storeForUsers(notificationMessageIn, validUsers);
}

// Update Notification WebSocket Sessions right now
Expand Down
13 changes: 7 additions & 6 deletions java/code/src/com/redhat/rhn/domain/org/Org.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.redhat.rhn.domain.org.usergroup.UserGroupFactory;
import com.redhat.rhn.domain.org.usergroup.UserGroupImpl;
import com.redhat.rhn.domain.role.Role;
import com.redhat.rhn.domain.role.RoleImpl;
import com.redhat.rhn.domain.server.EntitlementServerGroup;
import com.redhat.rhn.domain.server.ManagedServerGroup;
import com.redhat.rhn.domain.server.Pillar;
Expand Down Expand Up @@ -143,7 +144,7 @@ public class Org extends BaseDomainHelper implements SaltConfigurable {
/**
* Construct new Org
*/
protected Org() {
public Org() {
userGroups = new HashSet<>();
}

Expand Down Expand Up @@ -233,8 +234,8 @@ public void setName(String nameIn) {
* rule that roles are not changeable during runtime.
* @return Set of Roles associated with this Org
*/
public Set<Role> getRoles() {
Set<Role> orgRoles = new HashSet<>();
public Set<RoleImpl> getRoles() {
Set<RoleImpl> orgRoles = new HashSet<>();
for (UserGroup ug : userGroups) {
orgRoles.add(ug.getRole());
}
Expand All @@ -255,7 +256,7 @@ public boolean hasRole(Role role) {
* Add a Role to the Org.
* @param newRole the role label we want to add to this Org
*/
public void addRole(Role newRole) {
public void addRole(RoleImpl newRole) {
// Don't create and add a new group if the Org already has the
// specified role.
if (!hasRole(newRole)) {
Expand All @@ -272,8 +273,8 @@ public void addRole(Role newRole) {
* @param roleIn the Role.label to translate to a UserGroup.ID
* @return the UserGroup if found, otherwise null.
*/
public UserGroup getUserGroup(Role roleIn) {
for (UserGroup ug : userGroups) {
public UserGroupImpl getUserGroup(Role roleIn) {
for (UserGroupImpl ug : userGroups) {
if (ug.getRole().equals(roleIn)) {
return ug;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package com.redhat.rhn.domain.org.usergroup;

import com.redhat.rhn.domain.role.Role;
import com.redhat.rhn.domain.role.RoleImpl;
import com.redhat.rhn.manager.user.UserManager;

import java.util.HashSet;
Expand All @@ -26,12 +26,12 @@
*/
public class UserExtGroup extends ExtGroup {

private Set<Role> roles;
private Set<RoleImpl> roles;

/**
* @return Returns the roles.
*/
public Set<Role> getRoles() {
public Set<RoleImpl> getRoles() {
if (roles == null) {
return new HashSet<>();
}
Expand All @@ -41,7 +41,7 @@ public Set<Role> getRoles() {
/**
* @param rolesIn The roles to set.
*/
public void setRoles(Set<Role> rolesIn) {
public void setRoles(Set<RoleImpl> rolesIn) {
roles = rolesIn;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.redhat.rhn.domain.org.usergroup;

import com.redhat.rhn.domain.role.Role;
import com.redhat.rhn.domain.role.RoleImpl;

import java.io.Serializable;
import java.util.Date;
Expand Down Expand Up @@ -81,13 +82,13 @@ public interface UserGroup extends Serializable {
* Getter for role
* @return role
*/
Role getRole();
RoleImpl getRole();

/**
* Setter for role
* @param roleIn New value for role
*/
void setRole(Role roleIn);
void setRole(RoleImpl roleIn);

/**
* Getter for orgId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import com.redhat.rhn.common.localization.LocalizationService;
import com.redhat.rhn.common.security.PermissionException;
import com.redhat.rhn.domain.org.Org;
import com.redhat.rhn.domain.role.Role;
import com.redhat.rhn.domain.role.RoleFactory;
import com.redhat.rhn.domain.role.RoleImpl;
import com.redhat.rhn.domain.user.User;

import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -57,7 +57,7 @@ protected Logger getLogger() {
* @param role the Role to base this new UserGroup on.
* @return the UserGroup created
*/
public static UserGroup createUserGroup(Org org, Role role) {
public static UserGroup createUserGroup(Org org, RoleImpl role) {
UserGroup retval = new UserGroupImpl();
LocalizationService ls = LocalizationService.getInstance();
// Concat the Role name with the letter s to form the UserGroup name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.redhat.rhn.domain.BaseDomainHelper;
import com.redhat.rhn.domain.role.Role;
import com.redhat.rhn.domain.role.RoleImpl;

/**
* Class UserGroup that reflects the DB representation of RHNUSERGROUP
Expand All @@ -29,7 +30,7 @@ public class UserGroupImpl extends BaseDomainHelper implements UserGroup {
private String description;
private Long currentMembers;
private Long orgId;
private Role role;
private RoleImpl role;

/**
* Getter for id
Expand Down Expand Up @@ -108,7 +109,7 @@ public void setCurrentMembers(Long currentMembersIn) {
* {@inheritDoc}
*/
@Override
public Role getRole() {
public RoleImpl getRole() {
return role;
}

Expand All @@ -117,7 +118,7 @@ public Role getRole() {
* {@inheritDoc}
*/
@Override
public void setRole(Role roleIn) {
public void setRole(RoleImpl roleIn) {
role = roleIn;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
where ugs.temporary = 'Y']]>
</query>
</hibernate-mapping>

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package com.redhat.rhn.domain.org.usergroup;

import com.redhat.rhn.domain.BaseDomainHelper;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.domain.user.legacy.UserImpl;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
Expand All @@ -28,8 +28,8 @@
*/
public class UserGroupMembers extends BaseDomainHelper implements Serializable {

private User user;
private UserGroup userGroup;
private UserImpl user;
private UserGroupImpl userGroup;
private boolean temporary;

/**
Expand All @@ -44,7 +44,7 @@ public UserGroupMembers() {
* @param userIn user
* @param ugIn user group
*/
public UserGroupMembers(User userIn, UserGroup ugIn) {
public UserGroupMembers(UserImpl userIn, UserGroupImpl ugIn) {
user = userIn;
userGroup = ugIn;
temporary = false;
Expand All @@ -56,7 +56,7 @@ public UserGroupMembers(User userIn, UserGroup ugIn) {
* @param ugIn user group
* @param tempIn temporary flag
*/
public UserGroupMembers(User userIn, UserGroup ugIn, boolean tempIn) {
public UserGroupMembers(UserImpl userIn, UserGroupImpl ugIn, boolean tempIn) {
user = userIn;
userGroup = ugIn;
temporary = tempIn;
Expand All @@ -65,14 +65,14 @@ public UserGroupMembers(User userIn, UserGroup ugIn, boolean tempIn) {
/**
* @return Returns the user.
*/
public User getUser() {
public UserImpl getUser() {
return user;
}

/**
* @param userIn The user to set.
*/
public void setUser(User userIn) {
public void setUser(UserImpl userIn) {
user = userIn;
}

Expand All @@ -86,14 +86,14 @@ public UserGroup getUserGroup() {
/**
* @param userGroupIn The userGroup to set.
*/
public void setUserGroup(UserGroup userGroupIn) {
public void setUserGroup(UserGroupImpl userGroupIn) {
userGroup = userGroupIn;
}

/**
* @return Returns the temporary.
*/
public boolean getTemporary() {
public boolean isTemporary() {
return temporary;
}

Expand Down Expand Up @@ -126,7 +126,7 @@ public int hashCode() {
return new HashCodeBuilder()
.append(this.getUser())
.append(this.getUserGroup())
.append(this.getTemporary())
.append(this.isTemporary())
.toHashCode();
}
}
Loading

0 comments on commit e952755

Please sign in to comment.