class UserRest {

    @PUT
    @Path("{username}/groups")
    @RolesAllowed("admin")
    @ApiOperation("Add a Mobi user to a group")
    public Response addUserGroup(@PathParam("username") String username, @QueryParam("group") String groupTitle) {
        if (StringUtils.isEmpty(username) || StringUtils.isEmpty(groupTitle)) {
            throw ErrorUtils.sendError("Both username and group name must be provided", Response.Status.BAD_REQUEST);
        }
        try {
            User savedUser = engineManager.retrieveUser(username).orElseThrow(() ->
                    ErrorUtils.sendError("User " + username + " not found", Response.Status.BAD_REQUEST));
            Group savedGroup = engineManager.retrieveGroup(rdfEngine.getEngineName(), groupTitle).orElseThrow(() ->
                    ErrorUtils.sendError("Group " + groupTitle + " not found", Response.Status.BAD_REQUEST));
            savedGroup.addMember(savedUser);
            engineManager.updateGroup(rdfEngine.getEngineName(), savedGroup);
            logger.info("Added user " + username + " to group " + groupTitle);
            return Response.ok().build();
        } catch (IllegalArgumentException ex) {
            throw ErrorUtils.sendError(ex.getMessage(), Response.Status.BAD_REQUEST);
        }
    }

}