From cc5b5d0b01b04ace71dc94743b11b1c0787ae70a Mon Sep 17 00:00:00 2001 From: Guus der Kinderen Date: Wed, 22 Jun 2022 21:31:50 +0200 Subject: [PATCH] Minor fixes, mostly nonfuncional --- .../controller/UserServiceController.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/java/org/jivesoftware/openfire/plugin/rest/controller/UserServiceController.java b/src/java/org/jivesoftware/openfire/plugin/rest/controller/UserServiceController.java index 4eeb330dc..c7bde3825 100644 --- a/src/java/org/jivesoftware/openfire/plugin/rest/controller/UserServiceController.java +++ b/src/java/org/jivesoftware/openfire/plugin/rest/controller/UserServiceController.java @@ -52,22 +52,22 @@ * The Class UserServiceController. */ public class UserServiceController { - private static Logger LOG = LoggerFactory.getLogger(UserServiceController.class); + private static final Logger LOG = LoggerFactory.getLogger(UserServiceController.class); /** The Constant INSTANCE. */ private static UserServiceController INSTANCE = null; /** The user manager. */ - private UserManager userManager; + private final UserManager userManager; /** The roster manager. */ - private RosterManager rosterManager; + private final RosterManager rosterManager; /** The server. */ - private XMPPServer server; + private final XMPPServer server; /** The lock out manager. */ - private LockOutManager lockOutManager; + private final LockOutManager lockOutManager; /** * Gets the single instance of UserServiceController. @@ -192,10 +192,15 @@ public void deleteUser(String username) throws ServiceException { /** * Gets the user entities. * + * When a property key (and possibly value) is provided, then the user that is returned is one for which the + * specified property has been defined. + * * @param userSearch * the user search - * @param propertyValue * @param propertyKey + * the property key (can be null) + * @param propertyValue + * the property value (can be null) * @return the user entities * @throws ServiceException * the service exception @@ -275,7 +280,7 @@ public RosterEntities getRosterEntities(String username) throws ServiceException log("Get roster entities for user: " + username); Roster roster = getUserRoster(username); - List rosterEntities = new ArrayList(); + List rosterEntities = new ArrayList<>(); for (RosterItem rosterItem : roster.getRosterItems()) { RosterItemEntity rosterItemEntity = new RosterItemEntity(rosterItem.getJid().toBareJID(), rosterItem.getNickname(), rosterItem.getSubStatus().getValue()); @@ -318,13 +323,11 @@ public void addRosterItem(String username, RosterItemEntity rosterItemEntity) th // Roster item does not exist. Try to add it. } - if (roster != null) { - RosterItem rosterItem = roster.createRosterItem(jid, rosterItemEntity.getNickname(), - rosterItemEntity.getGroups(), false, true); - UserUtils.checkSubType(rosterItemEntity.getSubscriptionType()); - rosterItem.setSubStatus(RosterItem.SubType.getTypeFromInt(rosterItemEntity.getSubscriptionType())); - roster.updateRosterItem(rosterItem); - } + RosterItem rosterItem = roster.createRosterItem(jid, rosterItemEntity.getNickname(), + rosterItemEntity.getGroups(), false, true); + UserUtils.checkSubType(rosterItemEntity.getSubscriptionType()); + rosterItem.setSubStatus(RosterItem.SubType.getTypeFromInt(rosterItemEntity.getSubscriptionType())); + roster.updateRosterItem(rosterItem); } /** @@ -412,7 +415,7 @@ public List getUserGroups(String username) throws ServiceException { } User user = getAndCheckUser(username); Collection groups = GroupManager.getInstance().getGroups(user); - List groupNames = new ArrayList(); + List groupNames = new ArrayList<>(); for (Group group : groups) { groupNames.add(group.getName()); } @@ -433,7 +436,7 @@ public List getUserGroups(String username) throws ServiceException { public void addUserToGroups(String username, UserGroupsEntity userGroupsEntity) throws ServiceException { if (userGroupsEntity != null) { log("Adding user: " + username + " to groups"); - Collection groups = new ArrayList(); + Collection groups = new ArrayList<>(); for (String groupName : userGroupsEntity.getGroupNames()) { Group group; @@ -534,7 +537,7 @@ public void deleteUserFromGroup(String username, String groupName) throws Servic public UserEntities getUserEntitiesByProperty(String propertyKey, String propertyValue) throws ServiceException { log("Get user entities by property key : " + propertyKey + "and property value: " + propertyValue); List usernames = PropertyDAO.getUsernameByProperty(propertyKey, propertyValue); - List users = new ArrayList(); + List users = new ArrayList<>(); UserEntities userEntities = new UserEntities(); for (String username : usernames) {