Search in sources :

Example 6 with MUCRoom

use of org.jivesoftware.openfire.muc.MUCRoom in project Openfire by igniterealtime.

the class MUCRoomController method getChatRoom.

/**
	 * Gets the chat room.
	 * 
	 * @param roomName
	 *            the room name
	 * @param serviceName
	 *            the service name
	 * @return the chat room
	 * @throws MUCServiceException
	 *             the MUC service exception
	 */
public MUCRoomEntity getChatRoom(String roomName, String serviceName) throws MUCServiceException {
    MUCRoom chatRoom = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRoom(roomName);
    if (chatRoom == null) {
        throw new MUCServiceException("Could not fetch the channel", roomName, "Chat room could be not found");
    }
    MUCRoomEntity mucRoomEntity = convertToMUCRoomEntity(chatRoom);
    return mucRoomEntity;
}
Also used : MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) MUCServiceException(org.jivesoftware.openfire.exception.MUCServiceException) MUCRoomEntity(org.jivesoftware.openfire.entity.MUCRoomEntity)

Example 7 with MUCRoom

use of org.jivesoftware.openfire.muc.MUCRoom in project Openfire by igniterealtime.

the class MUCRoomController method createRoom.

/**
	 * Creates the room.
	 *
	 * @param mucRoomEntity
	 *            the MUC room entity
	 * @param serviceName
	 *            the service name
	 * @throws NotAllowedException
	 *             the not allowed exception
	 * @throws ForbiddenException
	 *             the forbidden exception
	 * @throws ConflictException
	 *             the conflict exception
	 */
private void createRoom(MUCRoomEntity mucRoomEntity, String serviceName) throws NotAllowedException, ForbiddenException, ConflictException {
    // Set owner
    JID owner = XMPPServer.getInstance().createJID("admin", null);
    if (mucRoomEntity.getOwners() != null && mucRoomEntity.getOwners().size() > 0) {
        owner = new JID(mucRoomEntity.getOwners().get(0));
    } else {
        List<String> owners = new ArrayList<String>();
        owners.add(owner.toBareJID());
        mucRoomEntity.setOwners(owners);
    }
    MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRoom(mucRoomEntity.getRoomName().toLowerCase(), owner);
    // Set values
    room.setNaturalLanguageName(mucRoomEntity.getNaturalName());
    room.setSubject(mucRoomEntity.getSubject());
    room.setDescription(mucRoomEntity.getDescription());
    room.setPassword(mucRoomEntity.getPassword());
    room.setPersistent(mucRoomEntity.isPersistent());
    room.setPublicRoom(mucRoomEntity.isPublicRoom());
    room.setRegistrationEnabled(mucRoomEntity.isRegistrationEnabled());
    room.setCanAnyoneDiscoverJID(mucRoomEntity.isCanAnyoneDiscoverJID());
    room.setCanOccupantsChangeSubject(mucRoomEntity.isCanOccupantsChangeSubject());
    room.setCanOccupantsInvite(mucRoomEntity.isCanOccupantsInvite());
    room.setChangeNickname(mucRoomEntity.isCanChangeNickname());
    room.setModificationDate(mucRoomEntity.getModificationDate());
    room.setLogEnabled(mucRoomEntity.isLogEnabled());
    room.setLoginRestrictedToNickname(mucRoomEntity.isLoginRestrictedToNickname());
    room.setMaxUsers(mucRoomEntity.getMaxUsers());
    room.setMembersOnly(mucRoomEntity.isMembersOnly());
    room.setModerated(mucRoomEntity.isModerated());
    // Set broadcast presence roles
    if (mucRoomEntity.getBroadcastPresenceRoles() != null) {
        room.setRolesToBroadcastPresence(mucRoomEntity.getBroadcastPresenceRoles());
    } else {
        room.setRolesToBroadcastPresence(new ArrayList<String>());
    }
    // Set all roles
    setRoles(room, mucRoomEntity);
    // Set creation date
    if (mucRoomEntity.getCreationDate() != null) {
        room.setCreationDate(mucRoomEntity.getCreationDate());
    } else {
        room.setCreationDate(new Date());
    }
    // Set modification date
    if (mucRoomEntity.getModificationDate() != null) {
        room.setModificationDate(mucRoomEntity.getModificationDate());
    } else {
        room.setModificationDate(new Date());
    }
    // Unlock the room, because the default configuration lock the room.  		
    room.unlock(room.getRole());
    // Save the room to the DB if the room should be persistant
    if (room.isPersistent()) {
        room.saveToDB();
    }
}
Also used : JID(org.xmpp.packet.JID) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 8 with MUCRoom

use of org.jivesoftware.openfire.muc.MUCRoom in project Openfire by igniterealtime.

the class MUCRoomController method getChatRooms.

/**
	 * Gets the chat rooms.
	 * 
	 * @param serviceName
	 *            the service name
	 * @param channelType
	 *            the channel type
	 * @param roomSearch
	 *            the room search
	 * @return the chat rooms
	 */
public MUCRoomEntities getChatRooms(String serviceName, String channelType, String roomSearch) {
    List<MUCRoom> rooms = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRooms();
    List<MUCRoomEntity> mucRoomEntities = new ArrayList<MUCRoomEntity>();
    for (MUCRoom chatRoom : rooms) {
        if (roomSearch != null) {
            if (!chatRoom.getName().contains(roomSearch)) {
                continue;
            }
        }
        if (channelType.equals(MUCChannelType.ALL)) {
            mucRoomEntities.add(convertToMUCRoomEntity(chatRoom));
        } else if (channelType.equals(MUCChannelType.PUBLIC) && chatRoom.isPublicRoom()) {
            mucRoomEntities.add(convertToMUCRoomEntity(chatRoom));
        }
    }
    return new MUCRoomEntities(mucRoomEntities);
}
Also used : MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) MUCRoomEntity(org.jivesoftware.openfire.entity.MUCRoomEntity) ArrayList(java.util.ArrayList) MUCRoomEntities(org.jivesoftware.openfire.entity.MUCRoomEntities)

Example 9 with MUCRoom

use of org.jivesoftware.openfire.muc.MUCRoom in project Openfire by igniterealtime.

the class MUCRoomController method getChatRoom.

/**
	 * Gets the chat room.
	 * 
	 * @param roomName
	 *            the room name
	 * @param serviceName
	 *            the service name
	 * @return the chat room
	 * @throws ServiceException
	 *             the service exception
	 */
public MUCRoomEntity getChatRoom(String roomName, String serviceName, boolean expand) throws ServiceException {
    MUCRoom chatRoom = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRoom(roomName);
    if (chatRoom == null) {
        throw new ServiceException("Could not find the chat room", roomName, ExceptionType.ROOM_NOT_FOUND, Response.Status.NOT_FOUND);
    }
    MUCRoomEntity mucRoomEntity = convertToMUCRoomEntity(chatRoom, expand);
    return mucRoomEntity;
}
Also used : LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) MUCRoomEntity(org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntity)

Example 10 with MUCRoom

use of org.jivesoftware.openfire.muc.MUCRoom in project Openfire by igniterealtime.

the class MUCRoomController method createRoom.

/**
	 * Creates the room.
	 *
	 * @param mucRoomEntity
	 *            the MUC room entity
	 * @param serviceName
	 *            the service name
	 * @throws NotAllowedException
	 *             the not allowed exception
	 * @throws ForbiddenException
	 *             the forbidden exception
	 * @throws ConflictException
	 *             the conflict exception
	 * @throws AlreadyExistsException 
	 */
private void createRoom(MUCRoomEntity mucRoomEntity, String serviceName) throws NotAllowedException, ForbiddenException, ConflictException, AlreadyExistsException {
    // Set owner
    JID owner = XMPPServer.getInstance().createJID("admin", null);
    if (mucRoomEntity.getOwners() != null && mucRoomEntity.getOwners().size() > 0) {
        owner = new JID(mucRoomEntity.getOwners().get(0));
    } else {
        List<String> owners = new ArrayList<String>();
        owners.add(owner.toBareJID());
        mucRoomEntity.setOwners(owners);
    }
    //	Check if chat service is available, if not create a new one
    boolean serviceRegistered = XMPPServer.getInstance().getMultiUserChatManager().isServiceRegistered(serviceName);
    if (!serviceRegistered) {
        XMPPServer.getInstance().getMultiUserChatManager().createMultiUserChatService(serviceName, serviceName, false);
    }
    MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRoom(mucRoomEntity.getRoomName().toLowerCase(), owner);
    // Set values
    room.setNaturalLanguageName(mucRoomEntity.getNaturalName());
    room.setSubject(mucRoomEntity.getSubject());
    room.setDescription(mucRoomEntity.getDescription());
    room.setPassword(mucRoomEntity.getPassword());
    room.setPersistent(mucRoomEntity.isPersistent());
    room.setPublicRoom(mucRoomEntity.isPublicRoom());
    room.setRegistrationEnabled(mucRoomEntity.isRegistrationEnabled());
    room.setCanAnyoneDiscoverJID(mucRoomEntity.isCanAnyoneDiscoverJID());
    room.setCanOccupantsChangeSubject(mucRoomEntity.isCanOccupantsChangeSubject());
    room.setCanOccupantsInvite(mucRoomEntity.isCanOccupantsInvite());
    room.setChangeNickname(mucRoomEntity.isCanChangeNickname());
    room.setModificationDate(mucRoomEntity.getModificationDate());
    room.setLogEnabled(mucRoomEntity.isLogEnabled());
    room.setLoginRestrictedToNickname(mucRoomEntity.isLoginRestrictedToNickname());
    room.setMaxUsers(mucRoomEntity.getMaxUsers());
    room.setMembersOnly(mucRoomEntity.isMembersOnly());
    room.setModerated(mucRoomEntity.isModerated());
    // Fire RoomUpdateEvent if cluster is started
    if (ClusterManager.isClusteringStarted()) {
        CacheFactory.doClusterTask(new RoomUpdatedEvent((LocalMUCRoom) room));
    }
    // Set broadcast presence roles
    if (mucRoomEntity.getBroadcastPresenceRoles() != null) {
        room.setRolesToBroadcastPresence(mucRoomEntity.getBroadcastPresenceRoles());
    } else {
        room.setRolesToBroadcastPresence(new ArrayList<String>());
    }
    // Set all roles
    setRoles(room, mucRoomEntity);
    // Set creation date
    if (mucRoomEntity.getCreationDate() != null) {
        room.setCreationDate(mucRoomEntity.getCreationDate());
    } else {
        room.setCreationDate(new Date());
    }
    // Set modification date
    if (mucRoomEntity.getModificationDate() != null) {
        room.setModificationDate(mucRoomEntity.getModificationDate());
    } else {
        room.setModificationDate(new Date());
    }
    // Unlock the room, because the default configuration lock the room.  		
    room.unlock(room.getRole());
    // Save the room to the DB if the room should be persistant
    if (room.isPersistent()) {
        room.saveToDB();
    }
}
Also used : JID(org.xmpp.packet.JID) LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) RoomUpdatedEvent(org.jivesoftware.openfire.muc.cluster.RoomUpdatedEvent) LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) ArrayList(java.util.ArrayList) Date(java.util.Date)

Aggregations

MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)20 ArrayList (java.util.ArrayList)6 Date (java.util.Date)5 Element (org.dom4j.Element)5 LocalMUCRoom (org.jivesoftware.openfire.muc.spi.LocalMUCRoom)5 JID (org.xmpp.packet.JID)5 MultiUserChatService (org.jivesoftware.openfire.muc.MultiUserChatService)4 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)3 DataForm (org.xmpp.forms.DataForm)3 ArchivedMessage (com.reucon.openfire.plugin.archive.model.ArchivedMessage)2 List (java.util.List)2 MUCRoomEntity (org.jivesoftware.openfire.entity.MUCRoomEntity)2 ConflictException (org.jivesoftware.openfire.muc.ConflictException)2 ForbiddenException (org.jivesoftware.openfire.muc.ForbiddenException)2 MUCRole (org.jivesoftware.openfire.muc.MUCRole)2 MUCRoomEntity (org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntity)2 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)2 FormField (org.xmpp.forms.FormField)2 IQ (org.xmpp.packet.IQ)2 Presence (org.xmpp.packet.Presence)2