Search in sources :

Example 21 with GroupNotFoundException

use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.

the class UserServiceLegacyController method updateUser.

/**
	 * Update user.
	 *
	 * @param username the username
	 * @param password the password
	 * @param name the name
	 * @param email the email
	 * @param groupNames the group names
	 * @throws UserNotFoundException the user not found exception
	 * @throws GroupAlreadyExistsException the group already exists exception
	 */
public void updateUser(String username, String password, String name, String email, String groupNames) throws UserNotFoundException, GroupAlreadyExistsException {
    User user = getUser(username);
    if (password != null)
        user.setPassword(password);
    if (name != null)
        user.setName(name);
    if (email != null)
        user.setEmail(email);
    if (groupNames != null) {
        Collection<Group> newGroups = new ArrayList<Group>();
        StringTokenizer tkn = new StringTokenizer(groupNames, ",");
        while (tkn.hasMoreTokens()) {
            String groupName = tkn.nextToken();
            Group group = null;
            try {
                group = GroupManager.getInstance().getGroup(groupName);
            } catch (GroupNotFoundException e) {
                // Create this group ;
                group = GroupManager.getInstance().createGroup(groupName);
                group.getProperties().put("sharedRoster.showInRoster", "onlyGroup");
                group.getProperties().put("sharedRoster.displayName", groupName);
                group.getProperties().put("sharedRoster.groupList", "");
            }
            newGroups.add(group);
        }
        Collection<Group> existingGroups = GroupManager.getInstance().getGroups(user);
        // Get the list of groups to add to the user
        Collection<Group> groupsToAdd = new ArrayList<Group>(newGroups);
        groupsToAdd.removeAll(existingGroups);
        // Get the list of groups to remove from the user
        Collection<Group> groupsToDelete = new ArrayList<Group>(existingGroups);
        groupsToDelete.removeAll(newGroups);
        // Add the user to the new groups
        for (Group group : groupsToAdd) {
            group.getMembers().add(server.createJID(username, null));
        }
        // Remove the user from the old groups
        for (Group group : groupsToDelete) {
            group.getMembers().remove(server.createJID(username, null));
        }
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) StringTokenizer(java.util.StringTokenizer) User(org.jivesoftware.openfire.user.User) ArrayList(java.util.ArrayList) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 22 with GroupNotFoundException

use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.

the class UpdateGroup method execute.

@Override
public void execute(SessionData data, Element command) {
    Element note = command.addElement("note");
    // Get requested group
    Group group;
    try {
        group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
    } catch (GroupNotFoundException e) {
        // Group not found
        note.addAttribute("type", "error");
        note.setText("Group not found");
        return;
    }
    List<String> desc = data.getData().get("desc");
    if (desc != null) {
        group.setDescription(desc.get(0));
    }
    String showInRoster = data.getData().get("showInRoster").get(0);
    if ("nobody".equals(showInRoster)) {
        // New group is not a shared group
        group.getProperties().put("sharedRoster.showInRoster", "nobody");
        group.getProperties().put("sharedRoster.displayName", " ");
        group.getProperties().put("sharedRoster.groupList", " ");
    } else {
        // New group is configured as a shared group
        if ("spefgroups".equals(showInRoster)) {
            // Show shared group to other groups
            showInRoster = "onlyGroup";
        }
        List<String> displayName = data.getData().get("displayName");
        List<String> groupList = data.getData().get("groupList");
        if (displayName != null) {
            group.getProperties().put("sharedRoster.showInRoster", showInRoster);
            group.getProperties().put("sharedRoster.displayName", displayName.get(0));
            if (groupList != null) {
                StringBuilder buf = new StringBuilder();
                String sep = "";
                for (String groupName : groupList) {
                    buf.append(sep).append(groupName);
                    sep = ",";
                }
                group.getProperties().put("sharedRoster.groupList", buf.toString());
            }
        }
    }
    note.addAttribute("type", "info");
    note.setText("Operation finished successfully");
}
Also used : Group(org.jivesoftware.openfire.group.Group) Element(org.dom4j.Element) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 23 with GroupNotFoundException

use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.

the class AddGroupUsers method execute.

@Override
public void execute(SessionData data, Element command) {
    Element note = command.addElement("note");
    // Check if groups cannot be modified (backend is read-only)
    if (GroupManager.getInstance().isReadOnly()) {
        note.addAttribute("type", "error");
        note.setText("Groups are read only");
        return;
    }
    // Get requested group
    Group group;
    try {
        group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
    } catch (GroupNotFoundException e) {
        // Group not found
        note.addAttribute("type", "error");
        note.setText("Group name does not exist");
        return;
    }
    String admin = data.getData().get("admin").get(0);
    boolean isAdmin = "1".equals(admin) || "true".equals(admin);
    Collection<JID> users = (isAdmin ? group.getAdmins() : group.getMembers());
    boolean withErrors = false;
    for (String user : data.getData().get("users")) {
        try {
            users.add(new JID(user));
        } catch (Exception e) {
            Log.warn("User not added to group", e);
            withErrors = true;
        }
    }
    note.addAttribute("type", "info");
    note.setText("Operation finished" + (withErrors ? " with errors" : " successfully"));
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 24 with GroupNotFoundException

use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.

the class DeleteGroup method execute.

@Override
public void execute(SessionData data, Element command) {
    Element note = command.addElement("note");
    // Check if groups cannot be modified (backend is read-only)
    if (GroupManager.getInstance().isReadOnly()) {
        note.addAttribute("type", "error");
        note.setText("Groups are read only");
        return;
    }
    // Get requested group
    Group group;
    try {
        group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
    } catch (GroupNotFoundException e) {
        // Group not found
        note.addAttribute("type", "error");
        note.setText("Group name does not exist");
        return;
    }
    GroupManager.getInstance().deleteGroup(group);
    note.addAttribute("type", "info");
    note.setText("Operation finished successfully");
}
Also used : Group(org.jivesoftware.openfire.group.Group) Element(org.dom4j.Element) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 25 with GroupNotFoundException

use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.

the class DeleteGroupUsers method execute.

@Override
public void execute(SessionData data, Element command) {
    Element note = command.addElement("note");
    // Check if groups cannot be modified (backend is read-only)
    if (GroupManager.getInstance().isReadOnly()) {
        note.addAttribute("type", "error");
        note.setText("Groups are read only");
        return;
    }
    // Get requested group
    Group group;
    try {
        group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
    } catch (GroupNotFoundException e) {
        // Group not found
        note.addAttribute("type", "error");
        note.setText("Group name does not exist");
        return;
    }
    boolean withErrors = false;
    for (String user : data.getData().get("users")) {
        try {
            group.getAdmins().remove(new JID(user));
            group.getMembers().remove(new JID(user));
        } catch (Exception e) {
            Log.warn("User not deleted from group", e);
            withErrors = true;
        }
    }
    note.addAttribute("type", "info");
    note.setText("Operation finished" + (withErrors ? " with errors" : " successfully"));
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Aggregations

GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)40 Group (org.jivesoftware.openfire.group.Group)38 Element (org.dom4j.Element)15 JID (org.xmpp.packet.JID)12 ArrayList (java.util.ArrayList)11 List (java.util.List)8 StringTokenizer (java.util.StringTokenizer)6 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)5 GroupManager (org.jivesoftware.openfire.group.GroupManager)4 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)4 GroupJID (org.jivesoftware.openfire.group.GroupJID)3 GroupEntity (org.jivesoftware.openfire.plugin.rest.entity.GroupEntity)3 User (org.jivesoftware.openfire.user.User)3 Presence (org.xmpp.packet.Presence)3 HashMap (java.util.HashMap)2 NamingException (javax.naming.NamingException)2 MUCRole (org.jivesoftware.openfire.muc.MUCRole)2 DataForm (org.xmpp.forms.DataForm)2 FormField (org.xmpp.forms.FormField)2 RemoteException (java.rmi.RemoteException)1