Commit 757bb674 authored by daryl herzmann's avatar daryl herzmann

Merge pull request #292 from Redor/master

Updated the REST API plugin to 1.1.6
parents 6f732813 c6435b62
...@@ -44,6 +44,12 @@ ...@@ -44,6 +44,12 @@
REST API Plugin Changelog REST API Plugin Changelog
</h1> </h1>
<p><b>1.1.6</b> -- September 24th, 2015</p>
<ul>
<li>Added: Endpoints to add / remove a user from a user group</li>
<li>Fixed: Error response in JSON format</li>
</ul>
<p><b>1.1.5</b> -- September 1st, 2015</p> <p><b>1.1.5</b> -- September 1st, 2015</p>
<ul> <ul>
<li>Added: Send broadcast message to all online users</li> <li>Added: Send broadcast message to all online users</li>
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
<name>REST API</name> <name>REST API</name>
<description>Allows administration over a RESTful API.</description> <description>Allows administration over a RESTful API.</description>
<author>Roman Soldatow</author> <author>Roman Soldatow</author>
<version>1.1.5</version> <version>1.1.6</version>
<date>09/01/2015</date> <date>09/24/2015</date>
<minServerVersion>3.9.0</minServerVersion> <minServerVersion>3.9.0</minServerVersion>
<adminconsole> <adminconsole>
......
This diff is collapsed.
...@@ -395,6 +395,25 @@ public class UserServiceController { ...@@ -395,6 +395,25 @@ public class UserServiceController {
} }
} }
/**
* 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));
}
/** /**
* Delete user from groups. * Delete user from groups.
* *
...@@ -420,6 +439,24 @@ public class UserServiceController { ...@@ -420,6 +439,24 @@ public class UserServiceController {
} }
} }
/**
* Delete user from group.
*
* @param username the username
* @param groupName the group name
* @throws ServiceException the service exception
*/
public void deleteUserFromGroup(String username, String groupName) throws ServiceException {
Group group = null;
try {
group = GroupManager.getInstance().getGroup(groupName);
} catch (GroupNotFoundException e) {
throw new ServiceException("Could not find group", groupName, ExceptionType.GROUP_NOT_FOUND,
Response.Status.NOT_FOUND, e);
}
group.getMembers().remove(server.createJID(username, null));
}
/** /**
* Gets the user entities by property key and or value. * Gets the user entities by property key and or value.
* *
......
package org.jivesoftware.openfire.plugin.rest.exceptions; package org.jivesoftware.openfire.plugin.rest.exceptions;
import java.util.List;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider; import javax.ws.rs.ext.Provider;
...@@ -17,6 +22,11 @@ public class RESTExceptionMapper implements ExceptionMapper<ServiceException> { ...@@ -17,6 +22,11 @@ public class RESTExceptionMapper implements ExceptionMapper<ServiceException> {
/** The log. */ /** The log. */
private static Logger LOG = LoggerFactory.getLogger(RESTExceptionMapper.class); private static Logger LOG = LoggerFactory.getLogger(RESTExceptionMapper.class);
/** The headers. */
@Context
private HttpHeaders headers;
/** /**
* Instantiates a new REST exception mapper. * Instantiates a new REST exception mapper.
*/ */
...@@ -36,7 +46,17 @@ public class RESTExceptionMapper implements ExceptionMapper<ServiceException> { ...@@ -36,7 +46,17 @@ public class RESTExceptionMapper implements ExceptionMapper<ServiceException> {
LOG.error( LOG.error(
exception.getException() + ": " + exception.getMessage() + " with ressource " exception.getException() + ": " + exception.getMessage() + " with ressource "
+ exception.getRessource(), exception.getException()); + exception.getRessource(), exception.getException());
return Response.status(exception.getStatus()).entity(errorResponse).type(MediaType.APPLICATION_XML).build();
ResponseBuilder responseBuilder = Response.status(exception.getStatus()).entity(errorResponse);
List<MediaType> accepts = headers.getAcceptableMediaTypes();
if (accepts!=null && accepts.size() > 0) {
MediaType mediaType = accepts.get(0);
responseBuilder = responseBuilder.type(mediaType);
}
else {
responseBuilder = responseBuilder.type(headers.getMediaType());
}
return responseBuilder.build();
} }
} }
...@@ -54,7 +54,7 @@ public class GroupService { ...@@ -54,7 +54,7 @@ public class GroupService {
@DELETE @DELETE
@Path("/{groupName}") @Path("/{groupName}")
public Response deleteUserFromGroups(@PathParam("groupName") String groupName) throws ServiceException { public Response deleteGroup(@PathParam("groupName") String groupName) throws ServiceException {
groupController.deleteGroup(groupName); groupController.deleteGroup(groupName);
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
} }
......
...@@ -37,6 +37,22 @@ public class UserGroupService { ...@@ -37,6 +37,22 @@ public class UserGroupService {
return Response.status(Response.Status.CREATED).build(); return Response.status(Response.Status.CREATED).build();
} }
@POST
@Path("/{groupName}")
public Response addUserToGroup(@PathParam("username") String username, @PathParam("groupName") String groupName)
throws ServiceException {
plugin.addUserToGroup(username, groupName);
return Response.status(Response.Status.CREATED).build();
}
@DELETE
@Path("/{groupName}")
public Response deleteUserFromGroup(@PathParam("username") String username, @PathParam("groupName") String groupName)
throws ServiceException {
plugin.deleteUserFromGroup(username, groupName);
return Response.status(Response.Status.OK).build();
}
@DELETE @DELETE
public Response deleteUserFromGroups(@PathParam("username") String username, UserGroupsEntity userGroupsEntity) public Response deleteUserFromGroups(@PathParam("username") String username, UserGroupsEntity userGroupsEntity)
throws ServiceException { throws ServiceException {
......
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