Upgrading grouping backend

revert-70aa11f8
charitha 8 years ago
parent 406d49ad61
commit d1d6eefd17

@ -0,0 +1,57 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.jaxrs.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import java.util.ArrayList;
import java.util.List;
public class DeviceGroupList extends BasePaginatedResult {
@ApiModelProperty(value = "List of device groups returned")
@JsonProperty("groups")
private List<DeviceGroup> deviceGroups = new ArrayList<>();
public List<DeviceGroup> getList() {
return deviceGroups;
}
public void setList(List<DeviceGroup> deviceGroups) {
this.deviceGroups = deviceGroups;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n");
sb.append(" groups: [").append(deviceGroups).append("\n");
sb.append("]}\n");
return sb.toString();
}
}

@ -0,0 +1,58 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.jaxrs.beans;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.List;
/**
* This class holds Device Group user name and assigned roles of user for particular group. Exposed to external access.
*/
@ApiModel(value = "DeviceGroupShare", description = "This class carries roles assigned to a user of a managed device group.")
public class DeviceGroupShare implements Serializable {
private static final long serialVersionUID = 1998141711L;
@ApiModelProperty(name = "username", value = "Username of the user.", required = true)
private String username;
@ApiModelProperty(name = "roles", value = "List of roles assigned to user from the group.")
private List<String> groupRoles;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public List<String> getGroupRoles() {
return groupRoles;
}
public void setGroupRoles(List<String> groupRoles) {
this.groupRoles = groupRoles;
}
}

@ -0,0 +1,55 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.jaxrs.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
public class DeviceGroupUsersList extends BasePaginatedResult {
@ApiModelProperty(value = "List of device group users returned")
@JsonProperty("users")
private List<DeviceGroupShare> users = new ArrayList<>();
public List<DeviceGroupShare> getList() {
return users;
}
public void setList(List<DeviceGroupShare> users) {
this.users = users;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n");
sb.append(" users: [").append(users).append("\n");
sb.append("]}\n");
return sb.toString();
}
}

@ -18,11 +18,24 @@
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.api; package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader;
import org.apache.axis2.transport.http.HTTPConstants;
import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission; import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupShare;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupUsersList;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import javax.validation.Valid;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@ -34,80 +47,529 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
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 java.util.List;
/**
* Device group related REST-API. This can be used to manipulated device group related details.
*/
@API(name = "Group Management", version = "1.0.0", context = "/api/device-mgt/v1.0/groups", tags = {"devicemgt_admin"}) @API(name = "Group Management", version = "1.0.0", context = "/api/device-mgt/v1.0/groups", tags = {"devicemgt_admin"})
@Path("/groups") @Path("/groups")
@Api(value = "Device Group Management", description = "This API carries all device group management related operations " +
"such as get all the available groups, etc.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public interface GroupManagementService { public interface GroupManagementService {
@GET @GET
@Permission(name = "View Group", permission = "/permission/admin/device-mgt/user/groups/list") @ApiOperation(
Response getGroups(@QueryParam("user") String user, @QueryParam("offset") int offset, produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_GET,
value = "Get the list of groups belongs to current user.",
notes = "Returns all permitted groups enrolled with the system.",
tags = "Device Group Management")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of device groups.",
response = DeviceGroupList.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 404,
message = "No groups found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the groups list.",
response = ErrorResponse.class)
})
@Permission(name = "View Groups", permission = "/device-mgt/groups/view")
Response getGroups(@ApiParam(
name = "offset",
value = "Starting point within the complete list of items qualified.")
@QueryParam("offset") int offset,
@ApiParam(
name = "limit",
value = "Maximum size of resource array to return.")
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
@POST @POST
@Permission(name = "Add Group", permission = "/permission/admin/device-mgt/user/groups/add") @ApiOperation(
Response createGroup(DeviceGroup group); consumes = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_POST,
value = "Add new device group to the system.",
notes = "Add device group with current user as the owner.",
tags = "Device Group Management")
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "Created. \n Device group has successfully been created",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The URL of the added group."),
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests.")
}
),
@ApiResponse(
code = 303,
message = "See Other. \n Source can be retrieved from the URL specified at the Location header.",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The Source URL of the document.")}),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 401,
message = "Unauthorized. \n Current logged in user is not authorized to add device groups.",
response = ErrorResponse.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while adding a new device group.",
response = ErrorResponse.class)
})
@Permission(name = "Add Group", permission = "/device-mgt/groups/add")
Response createGroup(@ApiParam(
name = "group",
value = "Group object with data.",
required = true)
@Valid DeviceGroup group);
@Path("/{groupName}") @Path("/{groupName}")
@GET @GET
@Permission(name = "View Group", permission = "/permission/admin/device-mgt/user/groups/view") @ApiOperation(
Response getGroup(@PathParam("groupName") String groupName); produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_GET,
value = "View group specified with name.",
notes = "Returns details of group enrolled with the system.",
tags = "Device Group Management")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group.",
response = DeviceGroup.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 404,
message = "No groups found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the group details.",
response = ErrorResponse.class)
})
@Permission(name = "View Groups", permission = "/device-mgt/groups/view")
Response getGroup(@ApiParam(
name = "groupName",
value = "Name of the group to view.",
required = true)
@PathParam("groupName") String groupName);
@Path("/{groupName}") @Path("/{groupName}")
@PUT @PUT
@Permission(name = "Update Group", permission = "/permission/admin/device-mgt/user/groups/update") @ApiOperation(
Response updateGroup(@PathParam("groupName") String groupName, DeviceGroup deviceGroup); produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_PUT,
value = "Update a group.",
notes = "If you wish to make changes to an existing group, that can be done by updating the group using " +
"this resource.",
tags = "Device Group Management")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Group has been updated successfully.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body."),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 404,
message = "No groups found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while updating the group.",
response = ErrorResponse.class)
})
@Permission(name = "Update Group", permission = "/device-mgt/groups/update")
Response updateGroup(@ApiParam(
name = "groupName",
value = "Name of the group to be updated.",
required = true)
@PathParam("groupName") String groupName,
@ApiParam(
name = "group",
value = "Group object with data.",
required = true)
@Valid DeviceGroup deviceGroup);
@Path("/{groupName}") @Path("/{groupName}")
@DELETE @DELETE
@Permission(name = "Remove Groups", permission = "/permission/admin/device-mgt/user/groups/remove") @ApiOperation(
Response deleteGroup(@PathParam("groupName") String groupName); produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_DELETE,
@Path("/{groupName}/share-with-user") value = "Delete a group.",
@POST notes = "If you wish to remove an existing group, that can be done by updating the group using " +
@Permission(name = "Share Group to a User", permission = "/permission/admin/device-mgt/user/groups/share") "this resource.",
Response shareGroupWithUser(@PathParam("groupName") String groupName, String targetUser); tags = "Device Group Management")
@ApiResponses(value = {
@Path("/{groupName}/share-with-role") @ApiResponse(code = 200, message = "OK. \n Group has been deleted successfully.",
@POST responseHeaders = {
@Permission(name = "Share Group to a Role", permission = "/permission/admin/device-mgt/user/groups/share") @ResponseHeader(
Response shareGroupWithRole(@PathParam("groupName") String groupName, String targetRole); name = "Content-Type",
description = "The content type of the body."),
@Path("/{groupName}/remove-share-with-user") @ResponseHeader(
@POST name = "ETag",
@Permission(name = "Unshare a Group", permission = "/permission/admin/device-mgt/user/groups/unshare") description = "Entity Tag of the response resource.\n" +
Response removeShareWithUser(@PathParam("groupName") String groupName, String targetUser); "Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 404,
message = "No groups found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while removing the group.",
response = ErrorResponse.class)
})
@Permission(name = "Remove Group", permission = "/device-mgt/groups/remove")
Response deleteGroup(@ApiParam(
name = "groupName",
value = "Name of the group to be deleted.",
required = true)
@PathParam("groupName") String groupName);
@Path("/{groupName}/remove-share-with-role") @Path("/{groupName}/share")
@POST @POST
@Permission(name = "Unshare a Group", permission = "/permission/admin/device-mgt/user/groups/unshare") @ApiOperation(
Response removeShareWithRole(@PathParam("groupName") String groupName, String targetUser); produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_POST,
value = "Manage group sharing with a user.",
notes = "If you wish to share /un share an existing group with a user under defined sharing roles, " +
"that can be done using this resource.",
tags = "Device Group Management")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Sharing has been updated successfully.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body."),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 404,
message = "No groups found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while sharing the group.",
response = ErrorResponse.class)
})
@Permission(name = "Share Group", permission = "/device-mgt/groups/share")
Response manageGroupSharing(@ApiParam(
name = "groupName",
value = "Name of the group to be shared or unshared.",
required = true)
@PathParam("groupName") String groupName,
@ApiParam(
name = "deviceGroupShare",
value = "User name and the assigned roles for the share.",
required = true)
@Valid DeviceGroupShare deviceGroupShare);
@GET
@Path("/{groupName}/users") @Path("/{groupName}/users")
@Permission(name = "Get Users of Group", permission = "/permission/admin/device-mgt/user/groups/list")
Response getUsersOfGroup(@PathParam("groupName") String groupName);
@GET @GET
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_GET,
value = "View list of users of a device group.",
notes = "Returns details of users which particular group has been shared with.",
tags = "Device Group Management")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the users.",
response = DeviceGroupUsersList.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 404,
message = "No groups found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the users.",
response = ErrorResponse.class)
})
@Permission(name = "View users", permission = "/device-mgt/groups/users/view")
Response getUsersOfGroup(@ApiParam(
name = "groupName",
value = "Name of the group.",
required = true)
@PathParam("groupName") String groupName);
@Path("/{groupName}/devices") @Path("/{groupName}/devices")
@Permission(name = "Get Devices of Group", permission = "/permission/admin/device-mgt/groups/roles") @GET
Response getDevicesOfGroup(@PathParam("groupName") String groupName, @QueryParam("offset") int offset, @ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_GET,
value = "View list of devices in the device group.",
notes = "Returns list of devices in the device group.",
tags = "Device Group Management")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the devices.",
response = DeviceList.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 404,
message = "No groups found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the devices.",
response = ErrorResponse.class)
})
@Permission(name = "View devices", permission = "/device-mgt/groups/devices/view")
Response getDevicesOfGroup(@ApiParam(
name = "groupName",
value = "Name of the group.",
required = true)
@PathParam("groupName") String groupName,
@ApiParam(
name = "offset",
value = "Starting point within the complete list of items qualified.")
@QueryParam("offset") int offset,
@ApiParam(
name = "limit",
value = "Maximum size of resource array to return.")
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
@POST
@Path("/{groupName}/devices") @Path("/{groupName}/devices")
@Produces("application/json") @POST
@Permission(name = "Add Device to a Group", permission = "/permission/admin/device-mgt/user/groups/devices/add") @ApiOperation(
Response addDeviceToGroup(@PathParam("groupName") String groupName, DeviceIdentifier deviceIdentifier); produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_POST,
value = "Add devices to group.",
notes = "Add existing devices to the device group.",
tags = "Device Group Management")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully add devices to the group.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 404,
message = "No groups found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while adding devices to the group.",
response = ErrorResponse.class)
})
@Permission(name = "Add devices", permission = "/device-mgt/groups/devices/add")
Response addDevicesToGroup(@ApiParam(
name = "groupName",
value = "Name of the group.",
required = true)
@PathParam("groupName") String groupName,
@ApiParam(
name = "deviceIdentifiers",
value = "Device identifiers of the devices which needed be added.",
required = true)
@Valid List<DeviceIdentifier> deviceIdentifiers);
@DELETE
@Path("/{groupName}/devices") @Path("/{groupName}/devices")
@Permission(name = "Remove Devices from Group", @DELETE
permission = "/permission/admin/device-mgt/user/groups/devices/remove") @ApiOperation(
Response removeDeviceFromGroup(@PathParam("groupName") String groupName, @QueryParam("type") String type, produces = MediaType.APPLICATION_JSON,
@QueryParam("id") String id); httpMethod = HTTPConstants.HEADER_DELETE,
value = "Remove devices from group.",
notes = "Remove existing devices from the device group.",
tags = "Device Group Management")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully removed devices from the group.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 404,
message = "No groups found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while removing devices from the group.",
response = ErrorResponse.class)
})
@Permission(name = "Remove devices", permission = "/device-mgt/groups/devices/remove")
Response removeDevicesFromGroup(@ApiParam(
name = "groupName",
value = "Name of the group.",
required = true)
@PathParam("groupName") String groupName,
@ApiParam(
name = "deviceIdentifiers",
value = "Device identifiers of the devices which needed to be removed.",
required = true)
@Valid List<DeviceIdentifier> deviceIdentifiers);
} }

@ -20,20 +20,20 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupShare;
import org.wso2.carbon.device.mgt.jaxrs.service.api.GroupManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.GroupManagementService;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper; import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
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 java.util.ArrayList; import java.util.ArrayList;
@ -47,12 +47,12 @@ public class GroupManagementServiceImpl implements GroupManagementService {
private static final Log log = LogFactory.getLog(GroupManagementServiceImpl.class); private static final Log log = LogFactory.getLog(GroupManagementServiceImpl.class);
@Override @Override
public Response getGroups(@QueryParam("user") String user, @QueryParam("offset") int offset, public Response getGroups(int offset, int limit) {
@QueryParam("limit") int limit) {
try { try {
List<DeviceGroupWrapper> groupWrappers = new ArrayList<>(); List<DeviceGroupWrapper> groupWrappers = new ArrayList<>();
GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService(); GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService();
List<DeviceGroup> deviceGroups = service.getGroups(user); String currentUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
List<DeviceGroup> deviceGroups = service.getGroups(currentUser);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
for (DeviceGroup dg : deviceGroups) { for (DeviceGroup dg : deviceGroups) {
DeviceGroupWrapper gw = new DeviceGroupWrapper(); DeviceGroupWrapper gw = new DeviceGroupWrapper();
@ -76,61 +76,42 @@ public class GroupManagementServiceImpl implements GroupManagementService {
} }
@Override @Override
public Response getGroup(@PathParam("groupName") String groupName) { public Response getGroup(String groupName) {
return null; return null;
} }
@Override @Override
public Response updateGroup(@PathParam("groupName") String groupName, DeviceGroup deviceGroup) { public Response updateGroup(String groupName, DeviceGroup deviceGroup) {
return null; return null;
} }
@Override @Override
public Response deleteGroup(@PathParam("groupName") String groupName) { public Response deleteGroup(String groupName) {
return null; return null;
} }
@Override @Override
public Response shareGroupWithUser(String groupName, String targetUser) { public Response manageGroupSharing(String groupName, DeviceGroupShare deviceGroupShare) {
return null; return null;
} }
@Override @Override
public Response shareGroupWithRole(String groupName, String targetRole) { public Response getUsersOfGroup(String groupName) {
return null; return null;
} }
@Override @Override
public Response removeShareWithUser(@PathParam("groupName") String groupName, public Response getDevicesOfGroup(String groupName, int offset, int limit) {
@QueryParam("username") String targetUser) {
return null; return null;
} }
@Override @Override
public Response removeShareWithRole(@PathParam("groupName") String groupName, public Response addDeviceToGroup(String groupName, DeviceIdentifier deviceIdentifier) {
@QueryParam("roleName") String targetUser) {
return null; return null;
} }
@Override @Override
public Response getUsersOfGroup(@PathParam("groupName") String groupName) { public Response removeDevicesFromGroup(String groupName, String type, String id) {
return null;
}
@Override
public Response getDevicesOfGroup(@PathParam("groupName") String groupName, @QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
return null;
}
@Override
public Response addDeviceToGroup(@PathParam("groupName") String groupName, DeviceIdentifier deviceIdentifier) {
return null;
}
@Override
public Response removeDeviceFromGroup(@PathParam("groupName") String groupName, @QueryParam("type") String type,
@QueryParam("id") String id) {
return null; return null;
} }
} }

@ -17,6 +17,9 @@
*/ */
package org.wso2.carbon.device.mgt.common.group.mgt; package org.wso2.carbon.device.mgt.common.group.mgt;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable; import java.io.Serializable;
@ -25,19 +28,29 @@ import java.util.List;
/** /**
* Holds Device Group details and expose to external access * Holds Device Group details and expose to external access
*/ */
@XmlRootElement @ApiModel(value = "DeviceGroup", description = "This class carries all information related to a managed device group.")
public class DeviceGroup implements Serializable { public class DeviceGroup implements Serializable {
private static final long serialVersionUID = 1998121711L;
@ApiModelProperty(name = "id", value = "ID of the device group in the device group information database.",
required = true)
private int id; private int id;
@ApiModelProperty(name = "description", value = "The device group description that can be set on the device group by the user.",
required = true)
private String description; private String description;
@ApiModelProperty(name = "name", value = "The device group name that can be set on the device group by the user.",
required = true)
private String name; private String name;
private Long dateOfCreation; private Long dateOfCreation;
private Long dateOfLastUpdate; private Long dateOfLastUpdate;
private String owner; private String owner;
private List<GroupUser> users; private List<GroupUser> users;
private List<String> roles; private List<String> roles;
@XmlElement
public int getId() { public int getId() {
return id; return id;
} }
@ -46,7 +59,6 @@ public class DeviceGroup implements Serializable {
this.id = id; this.id = id;
} }
@XmlElement
public String getDescription() { public String getDescription() {
return description; return description;
} }
@ -55,7 +67,6 @@ public class DeviceGroup implements Serializable {
this.description = description; this.description = description;
} }
@XmlElement
public String getName() { public String getName() {
return name; return name;
} }
@ -64,7 +75,6 @@ public class DeviceGroup implements Serializable {
this.name = name; this.name = name;
} }
@XmlElement
public Long getDateOfCreation() { public Long getDateOfCreation() {
return dateOfCreation; return dateOfCreation;
} }
@ -73,7 +83,6 @@ public class DeviceGroup implements Serializable {
this.dateOfCreation = dateOfCreation; this.dateOfCreation = dateOfCreation;
} }
@XmlElement
public Long getDateOfLastUpdate() { public Long getDateOfLastUpdate() {
return dateOfLastUpdate; return dateOfLastUpdate;
} }
@ -82,7 +91,6 @@ public class DeviceGroup implements Serializable {
this.dateOfLastUpdate = dateOfLastUpdate; this.dateOfLastUpdate = dateOfLastUpdate;
} }
@XmlElement
public String getOwner() { public String getOwner() {
return owner; return owner;
} }
@ -91,7 +99,6 @@ public class DeviceGroup implements Serializable {
this.owner = owner; this.owner = owner;
} }
@XmlElement
public List<GroupUser> getUsers() { public List<GroupUser> getUsers() {
return users; return users;
} }
@ -100,7 +107,6 @@ public class DeviceGroup implements Serializable {
this.users = users; this.users = users;
} }
@XmlElement
public List<String> getRoles() { public List<String> getRoles() {
return roles; return roles;
} }

@ -18,6 +18,9 @@
*/ */
package org.wso2.carbon.device.mgt.common.group.mgt; package org.wso2.carbon.device.mgt.common.group.mgt;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable; import java.io.Serializable;
@ -26,12 +29,17 @@ import java.util.List;
/** /**
* This class holds Device Group user name and assigned group roles of user. Exposed to external access * This class holds Device Group user name and assigned group roles of user. Exposed to external access
*/ */
@XmlRootElement @ApiModel(value = "GroupUser", description = "This class carries all information related to a user of a managed device group.")
public class GroupUser implements Serializable { public class GroupUser implements Serializable {
private static final long serialVersionUID = 1998131711L;
@ApiModelProperty(name = "username", value = "Username of the user.", required = true)
private String username; private String username;
@ApiModelProperty(name = "roles", value = "List of roles assigned to the user.")
private List<String> groupRoles; private List<String> groupRoles;
@XmlElement
public String getUsername() { public String getUsername() {
return username; return username;
} }
@ -40,7 +48,6 @@ public class GroupUser implements Serializable {
this.username = username; this.username = username;
} }
@XmlElement
public List<String> getGroupRoles() { public List<String> getGroupRoles() {
return groupRoles; return groupRoles;
} }

Loading…
Cancel
Save