Search in sources :

Example 41 with Group

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

the class GroupController method getGroups.

/**
	 * Gets the groups.
	 *
	 * @return the groups
	 * @throws ServiceException
	 *             the service exception
	 */
public List<GroupEntity> getGroups() throws ServiceException {
    Collection<Group> groups = GroupManager.getInstance().getGroups();
    List<GroupEntity> groupEntities = new ArrayList<GroupEntity>();
    for (Group group : groups) {
        GroupEntity groupEntity = new GroupEntity(group.getName(), group.getDescription());
        groupEntities.add(groupEntity);
    }
    return groupEntities;
}
Also used : Group(org.jivesoftware.openfire.group.Group) GroupEntity(org.jivesoftware.openfire.plugin.rest.entity.GroupEntity) ArrayList(java.util.ArrayList)

Example 42 with Group

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

the class JustMarriedController method copyRoster.

/**
	 * Copy roster.
	 *
	 * @param currentUser
	 *            the current user
	 * @param newUser
	 *            the new user
	 * @param currentUserName
	 *            the current user name
	 * @throws ServiceException
	 *             the service exception
	 */
private static void copyRoster(User currentUser, User newUser, String currentUserName) throws ServiceException {
    Roster newRoster = newUser.getRoster();
    Roster currentRoster = currentUser.getRoster();
    for (RosterItem item : currentRoster.getRosterItems()) {
        try {
            List<String> groups = item.getGroups();
            RosterItem justCreated = newRoster.createRosterItem(item.getJid(), item.getNickname(), groups, true, true);
            justCreated.setAskStatus(item.getAskStatus());
            justCreated.setRecvStatus(item.getRecvStatus());
            justCreated.setSubStatus(item.getSubStatus());
            for (Group gr : item.getSharedGroups()) {
                justCreated.addSharedGroup(gr);
            }
            for (Group gr : item.getInvisibleSharedGroups()) {
                justCreated.addInvisibleSharedGroup(gr);
            }
            newRoster.updateRosterItem(justCreated);
            addNewUserToOthersRoster(newUser, item, currentUserName);
        } catch (UserAlreadyExistsException e) {
            throw new ServiceException("Could not create roster item for user ", newUser.getUsername(), ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.CONFLICT, e);
        } catch (SharedGroupException e) {
            throw new ServiceException("Could not create roster item, because it is a contact from a shared group", newUser.getUsername(), ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.BAD_REQUEST, e);
        } catch (UserNotFoundException e) {
            throw new ServiceException("Could not update roster item for user " + newUser.getUsername() + " because it was not properly created.", newUser.getUsername(), ExceptionType.USER_NOT_FOUND_EXCEPTION, Response.Status.NOT_FOUND, e);
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Group(org.jivesoftware.openfire.group.Group) Roster(org.jivesoftware.openfire.roster.Roster) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) SharedGroupException(org.jivesoftware.openfire.SharedGroupException)

Example 43 with Group

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

the class MUCRoomController method convertToMUCRoomEntity.

/**
	 * Convert to MUC room entity.
	 * 
	 * @param room
	 *            the room
	 * @return the MUC room entity
	 */
public MUCRoomEntity convertToMUCRoomEntity(MUCRoom room, boolean expand) {
    MUCRoomEntity mucRoomEntity = new MUCRoomEntity(room.getNaturalLanguageName(), room.getName(), room.getDescription());
    mucRoomEntity.setSubject(room.getSubject());
    mucRoomEntity.setCanAnyoneDiscoverJID(room.canAnyoneDiscoverJID());
    mucRoomEntity.setCanChangeNickname(room.canChangeNickname());
    mucRoomEntity.setCanOccupantsChangeSubject(room.canOccupantsChangeSubject());
    mucRoomEntity.setCanOccupantsInvite(room.canOccupantsInvite());
    mucRoomEntity.setPublicRoom(room.isPublicRoom());
    mucRoomEntity.setPassword(room.getPassword());
    mucRoomEntity.setPersistent(room.isPersistent());
    mucRoomEntity.setRegistrationEnabled(room.isRegistrationEnabled());
    mucRoomEntity.setLogEnabled(room.isLogEnabled());
    mucRoomEntity.setLoginRestrictedToNickname(room.isLoginRestrictedToNickname());
    mucRoomEntity.setMaxUsers(room.getMaxUsers());
    mucRoomEntity.setMembersOnly(room.isMembersOnly());
    mucRoomEntity.setModerated(room.isModerated());
    ConcurrentGroupList<JID> owners = new ConcurrentGroupList<JID>(room.getOwners());
    ConcurrentGroupList<JID> admins = new ConcurrentGroupList<JID>(room.getAdmins());
    ConcurrentGroupList<JID> members = new ConcurrentGroupList<JID>(room.getMembers());
    ConcurrentGroupList<JID> outcasts = new ConcurrentGroupList<JID>(room.getOutcasts());
    if (expand) {
        for (Group ownerGroup : owners.getGroups()) {
            owners.addAllAbsent(ownerGroup.getAll());
        }
        for (Group adminGroup : admins.getGroups()) {
            admins.addAllAbsent(adminGroup.getAll());
        }
        for (Group memberGroup : members.getGroups()) {
            members.addAllAbsent(memberGroup.getAll());
        }
        for (Group outcastGroup : outcasts.getGroups()) {
            outcasts.addAllAbsent(outcastGroup.getAll());
        }
    }
    mucRoomEntity.setOwners(MUCRoomUtils.convertJIDsToStringList(owners));
    mucRoomEntity.setAdmins(MUCRoomUtils.convertJIDsToStringList(admins));
    mucRoomEntity.setMembers(MUCRoomUtils.convertJIDsToStringList(members));
    mucRoomEntity.setOutcasts(MUCRoomUtils.convertJIDsToStringList(outcasts));
    mucRoomEntity.setOwnerGroups(MUCRoomUtils.convertGroupsToStringList(owners.getGroups()));
    mucRoomEntity.setAdminGroups(MUCRoomUtils.convertGroupsToStringList(admins.getGroups()));
    mucRoomEntity.setMemberGroups(MUCRoomUtils.convertGroupsToStringList(members.getGroups()));
    mucRoomEntity.setOutcastGroups(MUCRoomUtils.convertGroupsToStringList(outcasts.getGroups()));
    mucRoomEntity.setBroadcastPresenceRoles(room.getRolesToBroadcastPresence());
    mucRoomEntity.setCreationDate(room.getCreationDate());
    mucRoomEntity.setModificationDate(room.getModificationDate());
    return mucRoomEntity;
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) MUCRoomEntity(org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntity) ConcurrentGroupList(org.jivesoftware.openfire.group.ConcurrentGroupList)

Example 44 with Group

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

the class SearchPlugin method processSetPacket.

/**
	 * Processes an IQ stanza of type 'set', which in the context of 'Jabber Search' is a search request.
	 * 
	 * @param packet
	 *            An IQ stanza of type 'get'
	 * @return A result IQ stanza that contains the possbile search fields.
	 */
private IQ processSetPacket(IQ packet) {
    if (!packet.getType().equals(IQ.Type.set)) {
        throw new IllegalArgumentException("This method only accepts 'set' typed IQ stanzas as an argument.");
    }
    JID fromJID = packet.getFrom();
    final IQ resultIQ;
    // check if the request complies to the XEP-0055 standards
    if (!isValidSearchRequest(packet)) {
        resultIQ = IQ.createResultIQ(packet);
        resultIQ.setError(Condition.bad_request);
        return resultIQ;
    }
    final Element incomingForm = packet.getChildElement();
    final boolean isDataFormQuery = (incomingForm.element(QName.get("x", "jabber:x:data")) != null);
    final Element rsmElement = incomingForm.element(QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT));
    if (rsmElement != null) {
        final Element maxElement = rsmElement.element("max");
        final Element startIndexElement = rsmElement.element("index");
        int startIndex = 0;
        if (startIndexElement != null) {
            startIndex = Integer.parseInt(startIndexElement.getTextTrim());
        }
        int max = -1;
        if (maxElement != null) {
            max = Integer.parseInt(maxElement.getTextTrim());
        }
        final Set<User> searchResults = performSearch(incomingForm, startIndex, max);
        if (groupOnly) {
            Collection<Group> groups = GroupManager.getInstance().getGroups(fromJID);
            Set<User> allSearchResults = new HashSet<User>(searchResults);
            searchResults.clear();
            for (User user : allSearchResults) {
                for (Group group : groups) {
                    if (group.isUser(user.getUID())) {
                        searchResults.add(user);
                    }
                }
            }
        }
        // apply RSM
        final List<User> rsmResults;
        final ResultSet<User> rs = new ResultSetImpl<User>(searchResults);
        try {
            rsmResults = rs.applyRSMDirectives(rsmElement);
        } catch (NullPointerException e) {
            final IQ itemNotFound = IQ.createResultIQ(packet);
            itemNotFound.setError(Condition.item_not_found);
            return itemNotFound;
        }
        if (isDataFormQuery) {
            resultIQ = replyDataFormResult(rsmResults, packet);
        } else {
            resultIQ = replyNonDataFormResult(rsmResults, packet);
        }
        // add the additional 'set' element.
        final Element set = rs.generateSetElementFromResults(rsmResults);
        resultIQ.getChildElement().add(set);
    } else {
        final Set<User> searchResults = performSearch(incomingForm);
        if (groupOnly) {
            Collection<Group> groups = GroupManager.getInstance().getGroups(fromJID);
            Set<User> allSearchResults = new HashSet<User>(searchResults);
            searchResults.clear();
            for (User user : allSearchResults) {
                for (Group group : groups) {
                    if (group.isUser(user.getUID())) {
                        searchResults.add(user);
                    }
                }
            }
        }
        // don't apply RSM
        if (isDataFormQuery) {
            resultIQ = replyDataFormResult(searchResults, packet);
        } else {
            resultIQ = replyNonDataFormResult(searchResults, packet);
        }
    }
    return resultIQ;
}
Also used : Group(org.jivesoftware.openfire.group.Group) User(org.jivesoftware.openfire.user.User) ResultSetImpl(org.xmpp.resultsetmanagement.ResultSetImpl) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) HashSet(java.util.HashSet)

Example 45 with Group

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

the class UserServiceController method addUserToGroup.

/**
	 * Adds the user to group.
	 *
	 * @param username the username
	 * @param groupName the group name
	 * @throws ServiceException the service exception
	 */
public void addUserToGroup(String username, String groupName) throws ServiceException {
    Group group = null;
    try {
        group = GroupManager.getInstance().getGroup(groupName);
    } catch (GroupNotFoundException e) {
        // Create this group
        group = GroupController.getInstance().createGroup(new GroupEntity(groupName, ""));
    }
    group.getMembers().add(server.createJID(username, null));
}
Also used : Group(org.jivesoftware.openfire.group.Group) GroupEntity(org.jivesoftware.openfire.plugin.rest.entity.GroupEntity) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Aggregations

Group (org.jivesoftware.openfire.group.Group)84 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)42 JID (org.xmpp.packet.JID)30 Element (org.dom4j.Element)20 ArrayList (java.util.ArrayList)19 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)11 User (org.jivesoftware.openfire.user.User)9 List (java.util.List)7 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)7 StringTokenizer (java.util.StringTokenizer)6 GroupManager (org.jivesoftware.openfire.group.GroupManager)5 HashMap (java.util.HashMap)4 GroupEntity (org.jivesoftware.openfire.plugin.rest.entity.GroupEntity)4 DataForm (org.xmpp.forms.DataForm)4 IQ (org.xmpp.packet.IQ)4 HashSet (java.util.HashSet)3 XMPPServer (org.jivesoftware.openfire.XMPPServer)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2