/** * Add ServerGroups to the list of Default System groups. The ServerGroups <strong>MUST</strong> * exist otherwise a IllegalArgumentException is thrown. * * @param loggedInUser The current user in user. * @param login The login for the user whose Default ServerGroup list will be affected. * @param sgNames names of ServerGroups. * @return Returns 1 if successful (exception otherwise) * @xmlrpc.doc Add system groups to user's list of default system groups. * @xmlrpc.param #param("string", "sessionKey") * @xmlrpc.param #param_desc("string", "login", "User's login name.") * @xmlrpc.param #array_single("string", "serverGroupName") * @xmlrpc.returntype #return_int_success() */ public int addDefaultSystemGroups(User loggedInUser, String login, List sgNames) { User target = XmlRpcUserHelper.getInstance().lookupTargetUser(loggedInUser, login); if (sgNames == null || sgNames.size() < 1) { throw new IllegalArgumentException("no servergroup names supplied"); } List groups = ServerGroupFactory.listManagedGroups(target.getOrg()); Map groupMap = new HashMap(); // sigh. After looking through all of the apache collections package // I couldn't find anything that would create a map from a list using // a property from the object in the list as the key. This is where // python would be useful. for (Iterator itr = groups.iterator(); itr.hasNext(); ) { ServerGroup sg = (ServerGroup) itr.next(); groupMap.put(sg.getName(), sg); } // Doing full check of all supplied names, if one is bad // throw an exception, prior to altering the DefaultSystemGroup Set. for (Iterator itr = sgNames.iterator(); itr.hasNext(); ) { String name = (String) itr.next(); ServerGroup sg = (ServerGroup) groupMap.get(name); if (sg == null) { throw new LookupServerGroupException(name); } } // now for the real reason we're in this method. Set defaults = target.getDefaultSystemGroupIds(); for (Iterator itr = sgNames.iterator(); itr.hasNext(); ) { ServerGroup sg = (ServerGroup) groupMap.get(itr.next()); if (sg != null) { // not a simple add to the groups. Needs to call // UserManager as DataSource is being used. defaults.add(sg.getId()); } } UserManager.setDefaultSystemGroupIds(target, defaults); UserManager.storeUser(target); return 1; }
/** * Get the set of ManagedServerGroups that this Org is a member of. * * @return List of ServerGroup classes */ public List<ManagedServerGroup> getManagedServerGroups() { return ServerGroupFactory.listManagedGroups(this); }