Commit 687f633c authored by Florian Sailer's avatar Florian Sailer Committed by daryl herzmann

Occupants endpoint for restAPI (#580)

* Added occupants endpoint to restAPI plugin
parent a4462425
......@@ -20,3 +20,4 @@ out/
# Ignore Netbeans project files
nbproject/
nbbuild/
/bin/
......@@ -1360,6 +1360,11 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
<li><a href="#examples-17">Examples</a></li>
</ul>
</li>
<li><a href="#retrieve-chat-room-occupants">Retrieve chat room occupants</a><ul>
<li><a href="#possible-parameters-get-occupants">Possible parameters</a></li>
<li><a href="#examples-get-occupants">Examples</a></li>
</ul>
</li>
<li><a href="#create-a-chat-room">Create a chat room</a><ul>
<li><a href="#possible-parameters-17">Possible parameters</a></li>
<li><a href="#xml-examples-1">XML Examples</a></li>
......@@ -3023,6 +3028,56 @@ Payload Example 1 (required parameters):</p>
<h2 id="retrieve-chat-room-occupants">Retrieve chat room occupants</h2>
<p>Endpoint to get all occupants (all roles / affiliations) of a specified room.</p>
<blockquote>
<p><strong>GET</strong> /chatrooms/{roomName}/occupants</p>
</blockquote>
<p><strong>Payload:</strong> none <br>
<strong>Return value:</strong> Occupants</p>
<h3 id="possible-parameters-get-occupants">Possible parameters</h3>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Parameter Type</th>
<th>Description</th>
<th>Default value</th>
</tr>
</thead>
<tbody><tr>
<td>roomname</td>
<td>@Path</td>
<td>Exact room name</td>
<td></td>
</tr>
<tr>
<td>servicename</td>
<td>@QueryParam</td>
<td>The name of the Group Chat Service</td>
<td>conference</td>
</tr>
</tbody></table>
<h3 id="examples-get-occupants">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU=</p>
<p><strong>GET</strong> <a href="http://example.org:9090/plugins/restapi/v1/chatrooms/room1/participants">http://example.org:9090/plugins/restapi/v1/chatrooms/room1/occupants</a></p>
</blockquote>
<h2 id="create-a-chat-room">Create a chat room</h2>
<p>Endpoint to create a new chat room.</p>
......
......@@ -12,6 +12,8 @@ import org.jivesoftware.openfire.cluster.ClusterManager;
import org.jivesoftware.openfire.plugin.rest.entity.MUCChannelType;
import org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntities;
import org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntity;
import org.jivesoftware.openfire.plugin.rest.entity.OccupantEntities;
import org.jivesoftware.openfire.plugin.rest.entity.OccupantEntity;
import org.jivesoftware.openfire.plugin.rest.entity.ParticipantEntities;
import org.jivesoftware.openfire.plugin.rest.entity.ParticipantEntity;
import org.jivesoftware.openfire.plugin.rest.exceptions.ExceptionType;
......@@ -308,6 +310,36 @@ public class MUCRoomController {
participantEntities.setParticipants(participants);
return participantEntities;
}
/**
* Gets the room occupants.
*
* @param roomName
* the room name
* @param serviceName
* the service name
* @return the room occupants
*/
public OccupantEntities getRoomOccupants(String roomName, String serviceName) {
OccupantEntities occupantEntities = new OccupantEntities();
List<OccupantEntity> occupants = new ArrayList<OccupantEntity>();
Collection<MUCRole> serverOccupants = XMPPServer.getInstance().getMultiUserChatManager()
.getMultiUserChatService(serviceName).getChatRoom(roomName).getOccupants();
for (MUCRole role : serverOccupants) {
OccupantEntity occupantEntity = new OccupantEntity();
occupantEntity.setJid(role.getRoleAddress().toFullJID());
occupantEntity.setRole(role.getRole().name());
occupantEntity.setAffiliation(role.getAffiliation().name());
occupants.add(occupantEntity);
}
occupantEntities.setOccupants(occupants);
return occupantEntities;
}
/**
* Convert to MUC room entity.
......
package org.jivesoftware.openfire.plugin.rest.entity;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "occupants")
public class OccupantEntities {
List<OccupantEntity> occupants;
public OccupantEntities() {
}
public OccupantEntities(List<OccupantEntity> occupants) {
this.occupants = occupants;
}
@XmlElement(name = "occupant")
public List<OccupantEntity> getOccupants() {
return occupants;
}
public void setOccupants(List<OccupantEntity> occupants) {
this.occupants = occupants;
}
}
package org.jivesoftware.openfire.plugin.rest.entity;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "occupant")
public class OccupantEntity {
private String jid;
private String role;
private String affiliation;
public OccupantEntity() {
}
@XmlElement
public String getJid() {
return jid;
}
public void setJid(String jid) {
this.jid = jid;
}
@XmlElement
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
@XmlElement
public String getAffiliation() {
return affiliation;
}
public void setAffiliation(String affiliation) {
this.affiliation = affiliation;
}
}
\ No newline at end of file
......@@ -16,6 +16,7 @@ import javax.ws.rs.core.Response.Status;
import org.jivesoftware.openfire.plugin.rest.entity.MUCChannelType;
import org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntities;
import org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntity;
import org.jivesoftware.openfire.plugin.rest.entity.OccupantEntities;
import org.jivesoftware.openfire.plugin.rest.entity.ParticipantEntities;
import org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException;
import org.jivesoftware.openfire.plugin.rest.controller.MUCRoomController;
......@@ -73,4 +74,12 @@ public class MUCRoomService {
@DefaultValue("conference") @QueryParam("servicename") String serviceName) {
return MUCRoomController.getInstance().getRoomParticipants(roomName, serviceName);
}
@GET
@Path("/{roomName}/occupants")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public OccupantEntities getMUCRoomOccupants(@PathParam("roomName") String roomName,
@DefaultValue("conference") @QueryParam("servicename") String serviceName) {
return MUCRoomController.getInstance().getRoomOccupants(roomName, serviceName);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment