Committing improved swagger annotated cdm-f APIs

revert-70aa11f8
prabathabey 9 years ago
parent 0b9c64594c
commit 37aa05f79c

@ -21,6 +21,8 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.*; import io.swagger.annotations.*;
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.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@ -43,16 +45,50 @@ public interface ActivityInfoProviderService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Retrieving the operation details.", response = Activity.class,
notes = "This will return the operation details including the responses from the devices.") value = "Retrieve details of a particular activity.",
notes = "This will return information of a particular activity i.e. meta information of an operation, " +
"etc; including the responses from the devices.")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "Activity details provided successfully."), @ApiResponse(
@ApiResponse(code = 500, message = "Error occurred while fetching the activity for the supplied id.") code = 200,
message = "OK. \n Activity details is successfully fetched",
response = Activity.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 = 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 activity data.")
}) })
@Permission(scope = "operation-view", permissions = {"/permission/admin/device-mgt/admin/devices/view"}) @Permission(scope = "operation-view", permissions = {"/permission/admin/device-mgt/admin/devices/view"})
Response getActivity( Response getActivity(
@ApiParam(name = "id", value = "Activity id of the operation/activity to be retrieved.", @ApiParam(
name = "id",
value = "Activity id of the operation/activity to be retrieved.",
required = true) required = true)
@PathParam("id") String id); @PathParam("id") String id,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
} }

@ -22,7 +22,6 @@ import io.swagger.annotations.*;
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.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@ -40,54 +39,97 @@ import javax.ws.rs.core.Response;
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public interface ConfigurationManagementService { public interface ConfigurationManagementService {
@POST
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Configuring general platform settings",
notes = "Configure the general platform settings using this REST API.")
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Tenant configuration saved successfully"),
@ApiResponse(code = 500, message = "Error occurred while saving the tenant configuration")
})
@Permission(scope = "configuration-modify",
permissions = {"/permission/admin/device-mgt/admin/platform-configs/modify"})
Response saveConfiguration(@ApiParam(name = "configuration", value = "The required properties to "
+ "update the platform configurations.",
required = true) PlatformConfiguration configuration);
@GET @GET
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting General Platform Configurations.", value = "Get the general platform configurations.",
notes = "Get the general platform level configuration details using this REST API.", notes = "Get the general platform level configuration details.",
response = PlatformConfiguration.class) response = PlatformConfiguration.class)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "Tenant configuration saved successfully."), @ApiResponse(
@ApiResponse(code = 500, message = "Error occurred while retrieving the tenant configuration.") code = 200,
message = "OK. \n Successfully fetched general platform configuration.",
response = PlatformConfiguration.class,
responseContainer = "List",
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 = 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 general platform configuration.")
}) })
@Permission(scope = "configuration-view", @Permission(scope = "configuration-view",
permissions = {"/permission/admin/device-mgt/admin/platform-configs/view"}) permissions = {"/permission/admin/device-mgt/admin/platform-configs/view"})
Response getConfiguration(); Response getConfiguration(
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@PUT @PUT
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
value = "Updating General Platform Configurations.", value = "Update General Platform Configurations.",
notes = "Update the notification frequency using this REST API.") notes = "This resource is used to update the general platform configuration.")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 201, message = "Tenant configuration updated successfully."), @ApiResponse(
@ApiResponse(code = 500, message = "Error occurred while updating the tenant configuration.") code = 200,
message = "OK. \n Notification status has been updated successfully",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The URL of the updated device."),
@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 = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@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 modifying status of the notification.")
}) })
@Permission(scope = "configuration-modify", @Permission(scope = "configuration-modify",
permissions = {"/permission/admin/device-mgt/admin/platform-configs/modify"}) permissions = {"/permission/admin/device-mgt/admin/platform-configs/modify"})
Response updateConfiguration(@ApiParam(name = "configuration", value = "The required properties to " Response updateConfiguration(
+ "update the platform configurations.", @ApiParam(
required = true) PlatformConfiguration configuration); name = "configuration",
value = "The required properties to be updated in the platform configuration.",
required = true) PlatformConfiguration configuration);
} }

@ -21,13 +21,16 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.*; import io.swagger.annotations.*;
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.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.policy.mgt.common.Policy;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@ -38,62 +41,90 @@ import java.util.List;
/** /**
* Device related REST-API. This can be used to manipulated device related details. * Device related REST-API. This can be used to manipulated device related details.
*/ */
@API(name = "Device", version = "1.0.0", context = "/devicemgt_admin/devices", tags = {"devicemgt_admin"}) @API(name = "Device", version = "1.0.0", context = "/api/device-mgt/admin/devices", tags = {"devicemgt_admin"})
@Path("/devices") @Path("/devices")
@Api(value = "Device", description = "Device related operations such as get all the available devices, etc.") @Api(value = "Device Management API", description = "This API carries all device management related operations " +
"such as get all the available devices, etc.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public interface DeviceManagementService { public interface DeviceManagementService {
@GET @GET
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Get the device list.", value = "Get the list of devices enrolled with the system.",
notes = "Returns all devices enrolled with the system.", notes = "Returns all devices enrolled with the system.",
response = org.wso2.carbon.device.mgt.common.Device.class, response = Device.class,
responseContainer = "List") responseContainer = "List")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched the list of devices.", response = org.wso2.carbon @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.",
.device.mgt.common.Device.class, responseContainer = "List"), response = Device.class,
@ApiResponse(code = 404, message = "No device has currently been under the provided type."), responseContainer = "List",
@ApiResponse(code = 500, message = "Error occurred while fetching the device list.") 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 = 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 device list.")
}) })
@Permission(scope = "device-list", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @Permission(scope = "device-list", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDevices( Response getDevices(
@ApiParam(name = "offset", value = "Starting pagination index.",required = true) @ApiParam(
@QueryParam("offset") int offset, name = "type",
@ApiParam(name = "limit", value = "How many device details are required from the starting pagination " + value = "The device type, such as ios, android or windows.",
"index.", required = true) required = false)
@QueryParam("limit") int limit); @QueryParam("type") String type,
@ApiParam(
Response getDevices(@HeaderParam("If-Modified-Since") Date timestamp, @QueryParam("offset") int offset, name = "user", value = "Username of owner of the devices.",
@QueryParam("limit") int limit); required = true)
@QueryParam("user") String user,
@GET @ApiParam(
@ApiOperation( name = "roleName",
consumes = MediaType.APPLICATION_JSON, value = "Role name of the devices to be fetched.",
produces = MediaType.APPLICATION_JSON, required = false)
httpMethod = "GET", @QueryParam("roleName") String roleName,
value = "Get the device list corresponding to a device type.", @ApiParam(
notes = "Returns all devices enrolled with the system under the provided type.", name = "ownership",
response = org.wso2.carbon.device.mgt.common.Device.class, allowableValues = "BYOD, COPE",
responseContainer = "List") value = "Ownership of the devices to be fetched registered under.",
@ApiResponses(value = { required = false)
@ApiResponse(code = 200, message = "Successfully fetched the list of devices.", response = org.wso2.carbon @QueryParam("ownership") String ownership,
.device.mgt.common.Device.class, responseContainer = "List"), @ApiParam(
@ApiResponse(code = 404, message = "No device has currently been under the provided type."), name = "status",
@ApiResponse(code = 500, message = "Error occurred while fetching the device list.") value = "Enrollment status of devices to be fetched.",
}) required = false)
@Permission(scope = "device-list", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @QueryParam("status") String status,
Response getDevices( @ApiParam(
@ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true) name = "If-Modified-Since",
@QueryParam ("type") String type, value = "Timestamp of the last modified date",
@ApiParam(name = "offset", value = "Starting pagination index.",required = true) required = false)
@HeaderParam("If-Modified-Since") Date timestamp,
@ApiParam(
name = "offset",
value = "Starting point within the complete list of items qualified.",
required = false)
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many device details are required from the starting pagination " + @ApiParam(
"index.", required = true) name = "limit",
value = "Maximum size of resource array to return.",
required = false)
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
@POST @POST
@ -101,128 +132,123 @@ public interface DeviceManagementService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Get devices information from the supplied device identifies.", value = "Retrieve devices information from the supplied device identifies.",
notes = "This will return device information such as CPU usage, memory usage etc for supplied device " + notes = "This will return device information such as CPU usage, memory usage etc for supplied device " +
"identifiers.", "identifiers.",
response = DeviceInfo.class, response = DeviceInfo.class,
responseContainer = "List") responseContainer = "List")
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "Successfully fetched device information.", response = DeviceInfo.class, value = {
responseContainer = "List"), @ApiResponse(
@ApiResponse(code = 404, message = "No device information is available for the device list submitted."), code = 200,
@ApiResponse(code = 500, message = "Error occurred while getting the device information.") message = "OK. \n Information of the submitted list of devices is returned",
}) response = DeviceInfo.class,
responseContainer = "List",
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 = 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 = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@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 retrieving information of the list of the devices submitted.")
})
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDevicesInfo( Response getDevicesInfo(
@ApiParam(name = "deviceIds", value = "List of device identifiers", @ApiParam(
required = true) List<DeviceIdentifier> deviceIds); name = "deviceIds",
value = "List of device identifiers",
@GET required = true) List<DeviceIdentifier> deviceIds,
@ApiOperation( @ApiParam(
consumes = MediaType.APPLICATION_JSON, name = "If-Modified-Since",
produces = MediaType.APPLICATION_JSON, value = "Timestamp of the last modified date",
httpMethod = "GET", required = false)
value = "Get the device list of a user.", @HeaderParam("If-Modified-Since") Date timestamp);
notes = "Returns the set of devices that matches a given username.",
response = org.wso2.carbon.device.mgt.common.Device.class,
responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched the list of devices.", response = org.wso2.carbon
.device.mgt.common.Device.class, responseContainer = "List"),
@ApiResponse(code = 404, message = "No device has currently been enrolled by the user."),
@ApiResponse(code = 500, message = "Error occurred while fetching the device list.")
})
@Permission(scope = "device-list", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDeviceByUsername(
@ApiParam(name = "user", value = "Username of owner of the devices.", required = true)
@QueryParam("user") String user,
@ApiParam(name = "offset", value = "Starting pagination index.",required = true)
@QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many device details are required from the starting pagination " +
"index.", required = true)
@QueryParam("limit") int limit);
@GET
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Returns device list in a role.",
notes = "Returns the set of devices that matches a given role.",
response = org.wso2.carbon.device.mgt.common.Device.class,
responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched the list of devices.", response = org.wso2.carbon
.device.mgt.common.Device.class, responseContainer = "List"),
@ApiResponse(code = 404, message = "No device has currently been enrolled under the role."),
@ApiResponse(code = 500, message = "Error occurred while fetching the device list.")
})
@Permission(scope = "device-list", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDevicesByRole(
@ApiParam(name = "roleName", value = "Role name of the devices to be fetched.", required = true)
@QueryParam("roleName") String roleName,
@ApiParam(name = "offset", value = "Starting pagination index.",required = true)
@QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many device details are required from the starting pagination " +
"index.", required = true)
@QueryParam("limit") int limit);
@GET
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Returns device list of an ownership scheme.",
notes = "Returns the set of devices that matches a given ownership scheme.",
response = org.wso2.carbon.device.mgt.common.Device.class,
responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched the list of devices.", response = org.wso2.carbon
.device.mgt.common.Device.class, responseContainer = "List"),
@ApiResponse(code = 404, message = "No device has currently been enrolled under the given ownership " +
"scheme."),
@ApiResponse(code = 500, message = "Error occurred while fetching the device list.")
})
@Permission(scope = "device-list", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDevicesByOwnership(
@ApiParam(name = "ownership", value = "Ownership of the devices to be fetched registered under.",
required = true) EnrolmentInfo.OwnerShip ownership,
@ApiParam(name = "offset", value = "Starting pagination index.",required = true)
@QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many device details are required from the starting pagination " +
"index.", required = true)
@QueryParam("limit") int limit);
@GET @GET
@Path("/{type}/{id}")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Returns device list", value = "Get information of the requested device.",
notes = "Returns the set of devices that matches a given enrollment status", notes = "Returns information of the requested device.",
response = org.wso2.carbon.device.mgt.common.Device.class, response = Device.class)
responseContainer = "List") @ApiResponses(
@ApiResponses(value = { value = {
@ApiResponse(code = 200, message = "Successfully fetched the list of devices.", @ApiResponse(
response = org.wso2.carbon.device.mgt.common.Device.class, responseContainer = "List"), code = 200,
@ApiResponse(code = 404, message = "No device is currently in the given enrollment status."), message = "OK. \n Successfully fetched information of the device.",
@ApiResponse(code = 500, message = "Error occurred while fetching the device list.") response = Device.class,
}) responseHeaders = {
@Permission(scope = "device-list", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @ResponseHeader(
Response getDevicesByEnrollmentStatus( name = "Content-Type",
@ApiParam(name = "status", value = "Enrollment status of devices to be fetched.", required = true) description = "The content type of the body"),
EnrolmentInfo.Status status, @ResponseHeader(
@ApiParam(name = "offset", value = "Starting pagination index.",required = true) name = "ETag",
@QueryParam("offset") int offset, description = "Entity Tag of the response resource.\n" +
@ApiParam(name = "limit", value = "How many device details are required from the starting pagination " + "Used by caches, or in conditional requests."),
"index.", required = true) @ResponseHeader(
@QueryParam("limit") int limit); name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
@GET "Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 404,
message = "Not Found. \n No device is found under the provided type and id."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while retrieving information requested device.")
})
@Permission(scope = "device-view", permissions = { @Permission(scope = "device-view", permissions = {
"/permission/admin/device-mgt/admin/devices/view", "/permission/admin/device-mgt/admin/devices/view",
"/permission/admin/device-mgt/user/devices/view"}) "/permission/admin/device-mgt/user/devices/view"})
Response getDevice(@QueryParam("type") String type, @QueryParam("id") String id); Response getDevice(
@ApiParam(
name = "type",
value = "The device type, such as ios, android or windows.",
required = true)
@PathParam("type") String type,
@ApiParam(
name = "id",
value = "The device identifier of the device.",
required = true)
@PathParam("id") String id,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@GET @GET
@Path("/{type}/{id}/location") @Path("/{type}/{id}/location")
@ -234,18 +260,40 @@ public interface DeviceManagementService {
notes = "This will return the device location including latitude and longitude as well the " notes = "This will return the device location including latitude and longitude as well the "
+ "physical address.", + "physical address.",
response = DeviceLocation.class) response = DeviceLocation.class)
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "Successfully fetched the device location.", value = {
response = DeviceLocation.class), @ApiResponse(
@ApiResponse(code = 404, message = "Location details are not available for the given device."), code = 200,
@ApiResponse(code = 500, message = "Error occurred while getting the device location.") message = "Successfully fetched the device location.",
}) response = DeviceLocation.class),
@ApiResponse(
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 404,
message = "Location details are not available for the given device."),
@ApiResponse(
code = 500,
message = "Error occurred while getting the device location.")
})
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDeviceLocation( Response getDeviceLocation(
@ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true) @ApiParam(
name = "type",
value = "The device type, such as ios, android or windows.",
required = true)
@PathParam("type") String type, @PathParam("type") String type,
@ApiParam(name = "id", value = "The device identifier of the device.", required = true) @ApiParam(
@PathParam("id") String id); name = "id",
value = "The device identifier of the device.",
required = true)
@PathParam("id") String id,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@GET @GET
@Path("/{type}/{id}/features") @Path("/{type}/{id}/features")
@ -257,20 +305,71 @@ public interface DeviceManagementService {
notes = "WSO2 EMM features enable you to carry out many operations on a given device platform. " + notes = "WSO2 EMM features enable you to carry out many operations on a given device platform. " +
"Using this REST API you can get the features that can be carried out on a preferred device type," + "Using this REST API you can get the features that can be carried out on a preferred device type," +
" such as iOS, Android or Windows.", " such as iOS, Android or Windows.",
response = org.wso2.carbon.device.mgt.common.Feature.class, response = Feature.class,
responseContainer = "List") responseContainer = "List")
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "Successfully fetched the features.", value = {
response = org.wso2.carbon.device.mgt.common.Feature.class, responseContainer = "List"), @ApiResponse(
@ApiResponse(code = 500, message = "Error occurred while retrieving the list of features.") code = 200,
}) message = "OK. \n List of features of the device is returned",
response = Feature.class,
responseContainer = "List",
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 = 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 = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Device of which the feature list is requested, is not found."),
@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 retrieving feature list of the device.")
})
@Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/view", @Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/view",
"/permission/admin/device-mgt/user/devices/view"}) "/permission/admin/device-mgt/user/devices/view"})
Response getFeaturesOfDevice( Response getFeaturesOfDevice(
@ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true) @ApiParam(
name = "type",
value = "The device type, such as ios, android or windows.",
required = true)
@PathParam("type") String type, @PathParam("type") String type,
@ApiParam(name = "id", value = "The device identifier of the device.", required = true) @ApiParam(
@PathParam("id") String id); name = "id",
value = "The device identifier of the device.",
required = true)
@PathParam("id") String id,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@POST @POST
@Path("/search-devices") @Path("/search-devices")
@ -282,74 +381,300 @@ public interface DeviceManagementService {
notes = "Carry out an advanced search of devices.", notes = "Carry out an advanced search of devices.",
response = DeviceWrapper.class, response = DeviceWrapper.class,
responseContainer = "List") responseContainer = "List")
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "Successfully fetched matching devices.", response = DeviceWrapper.class, value = {
responseContainer = "List"), @ApiResponse(
@ApiResponse(code = 500, message = "Error occurred while searching the device information.") code = 200,
}) message = "OK. \n Device has successfully been enrolled. Location header " +
"contains URL of newly enrolled device",
response = DeviceWrapper.class,
responseContainer = "List",
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 already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@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 enrolling the device.")
})
@Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response searchDevices( Response searchDevices(
@ApiParam(name = "searchContext", value = "List of search conditions.", @ApiParam(
required = true) SearchContext searchContext); name = "searchContext",
value = "List of search conditions.",
required = true) SearchContext searchContext,
@ApiParam(
name = "offset",
value = "Starting point within the complete list of items qualified.",
required = false)
@QueryParam("offset") int offset,
@ApiParam(
name = "limit",
value = "Maximum size of resource array to return.",
required = false)
@QueryParam("limit") int limit);
@GET @GET
@Path("/{type}/{id}/applications") @Path("/{type}/{id}/applications")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting installed application details of a device.", value = "Getting installed application details of a device.",
responseContainer = "List", responseContainer = "List",
notes = "Get the list of applications that a device has subscribed.", notes = "Get the list of applications that a device has subscribed.",
response = Application.class) response = Application.class)
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "List of installed application details of a device.", value = {
response = Application.class, responseContainer = "List"), @ApiResponse(
@ApiResponse(code = 404, message = "No installed applications found on the device searched."), code = 200,
@ApiResponse(code = 500, message = "Error occurred while fetching the apps of the device.") message = "OK. \n List of applications installed into the device is returned",
}) response = Application.class,
responseContainer = "List",
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 = 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 = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Device of which the application list is requested, is not found."),
@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 retrieving installed application list of the device.")
})
@Permission(scope = "operation-view", permissions = { @Permission(scope = "operation-view", permissions = {
"/permission/admin/device-mgt/admin/devices/view", "/permission/admin/device-mgt/admin/devices/view",
"/permission/admin/device-mgt/user/devices/view" "/permission/admin/device-mgt/user/devices/view"
}) })
Response getInstalledApplications( Response getInstalledApplications(
@ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true) @ApiParam(
name = "type",
value = "The device type, such as ios, android or windows.", required = true)
@PathParam("type") String type, @PathParam("type") String type,
@ApiParam(name = "id", value = "The device identifier of the device.", required = true) @ApiParam(
@PathParam("id") String id); name = "id",
value = "The device identifier of the device.",
required = true)
@PathParam("id") String id,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@ApiParam(
name = "offset",
value = "Starting point within the complete list of items qualified.",
required = false)
@QueryParam("offset") int offset,
@ApiParam(
name = "limit",
value = "Maximum size of resource array to return.",
required = false)
@QueryParam("limit") int limit);
@GET @GET
@Path("/{type}/{id}/operations") @Path("/{type}/{id}/operations")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting paginated details for operations on a device.", value = "Getting paginated details for operations on a device.",
notes = "You will carry out many operations on a device. In a situation where you wish to view the all" + notes = "You will carry out many operations on a device. In a situation where you wish to view the all" +
" the operations carried out on a device it is not feasible to show all the details on one page" + " the operations carried out on a device it is not feasible to show all the details on one page" +
" therefore the details are paginated.", " therefore the details are paginated.",
response = org.wso2.carbon.device.mgt.common.operation.mgt.Operation.class) response = Operation.class)
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "List of Operations on a device.", value = {
response = org.wso2.carbon.device.mgt.common.operation.mgt.Operation.class, @ApiResponse(
responseContainer = "List"), code = 200,
@ApiResponse(code = 500, message = "Error occurred while fetching the operations for the " + message = "OK. \n List of operations scheduled for the device is returned",
"device.") response = Operation.class,
}) responseContainer = "List",
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 = 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 = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Device of which the operation list is requested, is not found."),
@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 retrieving operation list scheduled for the device.")
})
@Permission(scope = "operation-view", permissions = { @Permission(scope = "operation-view", permissions = {
"/permission/admin/device-mgt/admin/devices/view", "/permission/admin/device-mgt/admin/devices/view",
"/permission/admin/device-mgt/user/devices/view" "/permission/admin/device-mgt/user/devices/view"
}) })
Response getDeviceOperations( Response getDeviceOperations(
@ApiParam(name = "offset", value = "Starting pagination index.",required = true) @ApiParam(
@QueryParam("offset") int offset, name = "type",
@ApiParam(name = "limit", value = "How many device details are required from the starting pagination " + value = "The device type, such as ios, android or windows.",
"index.", required = true) required = true)
@QueryParam("limit") int limit,
@ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true)
@PathParam("type") String type, @PathParam("type") String type,
@ApiParam(name = "id", value = "The device identifier of the device.", required = true) @ApiParam(
@PathParam("id") String id); name = "id",
value = "The device identifier of the device.",
required = true)
@PathParam("id") String id,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@ApiParam(
name = "offset",
value = "Starting point within the complete list of items qualified.",
required = false)
@QueryParam("offset") int offset,
@ApiParam(
name = "limit",
value = "Maximum size of resource array to return.",
required = false)
@QueryParam("limit") int limit);
@GET
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Get the effective policy calculated for a device.",
notes = "When a device registers with WSO2 EMM a policy is enforced on the device. Initially the EMM " +
"filters the policies based on the Platform (device type), filters based on the device ownership" +
" type , filters based on the user role or name and finally the policy is enforced on the device.",
response = Policy.class)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Effective policy calculated for the device is returned",
response = Policy.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 = 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 = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Device of which the effective policy is requested, is not found."),
@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 retrieving the effective policy calculated for the device.")
})
Response getEffectivePolicyOfDevice(
@ApiParam(
name = "type",
value = "The device type, such as ios, android or windows.",
required = true)
@QueryParam("type") String type,
@ApiParam(
name = "id",
value = "Device Identifier",
required = true)
@QueryParam("id") String id,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
} }

@ -30,9 +30,9 @@ import javax.ws.rs.core.Response;
/** /**
* Notifications related REST-API. * Notifications related REST-API.
*/ */
@API(name = "Device Notification", version = "1.0.0", context = "/devicemgt_admin/notifications", @API(name = "Device Notification Management API", version = "1.0.0", context = "/devicemgt_admin/notifications",
tags = {"devicemgt_admin"}) tags = {"devicemgt_admin"})
@Api(value = "DeviceNotification", description = "Device notification related operations can be found here.") @Api(value = "Device Notification Management API", description = "Device notification related operations can be found here.")
@Path("/notifications") @Path("/notifications")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ -40,7 +40,6 @@ public interface NotificationManagementService {
@GET @GET
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting all device notification details.", value = "Getting all device notification details.",
@ -48,52 +47,62 @@ public interface NotificationManagementService {
+ "this REST API", + "this REST API",
response = Notification.class, response = Notification.class,
responseContainer = "List") responseContainer = "List")
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "Successfully fetched the list of notifications", value = {
response = Notification.class, responseContainer = "List"), @ApiResponse(
@ApiResponse(code = 404, message = "No notification is available to be retrieved."), code = 200,
@ApiResponse(code = 500, message = "Error occurred while retrieving the notification list.") message = "OK. \n Successfully fetched the list of notifications.",
}) response = Notification.class,
responseContainer = "List",
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 = 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 notification list.")
})
@Permission(scope = "device-notification-view", permissions = { @Permission(scope = "device-notification-view", permissions = {
"/permission/admin/device-mgt/admin/notifications/view", "/permission/admin/device-mgt/admin/notifications/view",
"/permission/admin/device-mgt/user/notifications/view" "/permission/admin/device-mgt/user/notifications/view"
}) })
Response getNotifications( Response getNotifications(
@ApiParam(name = "offset", value = "Starting pagination index.",required = true) @ApiParam(name = "status",
value = "Status of the notification.",
allowableValues = "NEW, CHECKED",
required = true)
@QueryParam("status") String status,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@ApiParam(
name = "offset",
value = "Starting point within the complete list of items qualified.",
required = false)
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How notification device details are required from the starting " + @ApiParam(
"pagination index.", required = true) name = "limit",
value = "Maximum size of resource array to return.",
required = false)
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
@GET
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Getting the device notifications filtered by the status.",
notes = "Get the details of all the unread notifications or the details of all the read "
+ "notifications using this REST API.",
response = Notification.class,
responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched the list of notifications.",
response = Notification.class, responseContainer = "List"),
@ApiResponse(code = 404, message = "No notification, which carries the given status " +
"is available to be retrieved."),
@ApiResponse(code = 500, message = "Error occurred while retrieving the notification list.")
})
@Permission(scope = "device-notification-view", permissions = {
"/permission/admin/device-mgt/admin/notifications/view",
"/permission/admin/device-mgt/user/notifications/view"
})
Response getNotificationsByStatus(
@ApiParam(name = "status", value = "Status of the notification.",required = true)
Notification.Status status,
@ApiParam(name = "offset", value = "Starting pagination index.",required = true)
@QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many notification details are required from the starting pagination " +
"index.", required = true)
@QueryParam("limit") int limit);
@PUT @PUT
@Path("/{id}/status") @Path("/{id}/status")
@ -101,35 +110,100 @@ public interface NotificationManagementService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
value = "Updating the device notification status", value = "Update the device notification status",
notes = "When a user has read the the device notifications, the device notification status must " notes = "When a user has read the the device notifications, the device notification status must "
+ "change from NEW to CHECKED. Update the device notification status using this REST API.") + "change from NEW to CHECKED. Update the device notification status using this REST API.")
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 201, message = "Notification status updated successfully."), value = {
@ApiResponse(code = 500, message = "Error occurred while updating notification status.") @ApiResponse(
}) code = 200,
message = "OK. \n Notification status has been updated successfully",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The URL of the updated device."),
@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 = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@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 modifying status of the notification.")
})
@Permission(scope = "device-notification-modify", @Permission(scope = "device-notification-modify",
permissions = {"/permission/admin/device-mgt/admin/notifications/modify"}) permissions = {"/permission/admin/device-mgt/admin/notifications/modify"})
Response updateNotificationStatus( Response updateNotificationStatus(
@ApiParam(name = "id", value = "The device identifier of the device.", required = true) @ApiParam(
name = "id",
value = "Notification identifier.",
required = true)
@PathParam("id") int id, @PathParam("id") int id,
@ApiParam(name = "status", value = "Status of the notification.",required = true) @ApiParam(
Notification.Status status); name = "status",
value = "Status of the notification.",
allowableValues = "NEW, CHECKED",
required = true) String status);
@POST @POST
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Sending a device notification.", value = "Add a device notification.",
notes = "Notify users on device operation failures and other information using this REST API.") notes = "Add a device notification, which will then be sent to a device.")
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 201, message = "Notification has added successfully."), value = {
@ApiResponse(code = 500, message = "Error occurred while updating notification status.") @ApiResponse(code = 201, message = "Created. \n Notification has been added successfully.",
}) responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The URL of the added notification."),
@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 = 400,
message = "Bad Request. \n Invalid request or validation error."),
@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 the notification.")
})
@Permission(scope = "device-notification-modify", @Permission(scope = "device-notification-modify",
permissions = {"/permission/admin/device-mgt/admin/notifications/modify"}) permissions = {"/permission/admin/device-mgt/admin/notifications/modify"})
Response addNotification(@ApiParam(name = "notification", value = "Notification details to be added.",required = Response addNotification(
true) Notification notification); @ApiParam(
name = "notification",
value = "Notification details to be added.",
required = true) Notification notification);
} }

@ -18,12 +18,10 @@
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.api; package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.*;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.wso2.carbon.apimgt.annotations.api.Permission; import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
import org.wso2.carbon.policy.mgt.common.Policy;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@ -44,38 +42,106 @@ public interface PolicyManagementService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Adding a policy.", value = "Add a new policy.",
notes = "Add a policy using this REST API command. Using the REST API command given below " + notes = "This particular resource can be used to add a new policy, which will be created in in-active state.")
"you are able to save a created Policy and this policy will be in the inactive state.") @ApiResponses(
@ApiResponses(value = { value = {
@ApiResponse(code = 201, message = "Created the policy."), @ApiResponse(
@ApiResponse(code = 401, message = "Current user is not authorized to add policies."), code = 201,
@ApiResponse(code = 500, message = "Policy Management related error occurred when adding the policy.")}) message = "Created. \n Policy has successfully been created",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The URL of the added policy."),
@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."),
@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 policy.")})
@Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/add"}) @Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/add"})
Response addPolicy(@ApiParam(name = "policy", value = "Policy details related to the operation.", Response addPolicy(
required = true) PolicyWrapper policy); @ApiParam(
name = "policy",
value = "Policy details related to the operation.",
required = true) PolicyWrapper policy);
@GET @GET
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting details of policies.", value = "Get details of policies.",
responseContainer = "List", responseContainer = "List",
notes = "Retrieve the details of all the policies that you have created in EMM.", notes = "Retrieve the details of all the policies that have been created in EMM.",
response = org.wso2.carbon.policy.mgt.common.Policy.class) response = Policy.class)
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "Fetched all policies.", value = {
response = org.wso2.carbon.policy.mgt.common.Policy.class, responseContainer = "List"), @ApiResponse(
@ApiResponse(code = 404, message = "No policies found."), code = 200,
@ApiResponse(code = 500, message = "Policy Management related error occurred when " + message = "OK. \n Successfully fetched policies.",
"fetching the policies.") response = Policy.class,
}) responseContainer = "List",
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 = 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 policies.")
})
@Permission(scope = "policy-view", permissions = {"/permission/admin/device-mgt/admin/policies/list"}) @Permission(scope = "policy-view", permissions = {"/permission/admin/device-mgt/admin/policies/list"})
Response getPolicies( Response getPolicies(
@ApiParam(name = "offset", value = "Starting pagination index.",required = true) @ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@ApiParam(
name = "offset",
value = "Starting point within the complete list of items qualified.",
required = false)
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many policy details are required from the starting pagination " + @ApiParam(
"index.", required = true) name = "limit",
value = "Maximum size of resource array to return.",
required = false)
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
@GET @GET
@ -83,20 +149,53 @@ public interface PolicyManagementService {
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting details of a policy.", value = "Get details of a policy.",
notes = "Retrieve the details of a given policy in EMM.", notes = "Retrieve the details of a given policy that has been created in EMM.",
response = org.wso2.carbon.policy.mgt.common.Policy.class) response = Policy.class)
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "Fetched policy details.", value = {
response = org.wso2.carbon.policy.mgt.common.Policy.class), @ApiResponse(
@ApiResponse(code = 404, message = "Policy not found."), code = 200,
@ApiResponse(code = 500, message = "Policy management related error occurred when " + message = "OK. \n Successfully fetched the policy.",
"fetching the policy.") response = Policy.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 = "Not Found. \n No policy is found with the given id."),
@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 policy.")
})
@Permission(scope = "policy-view", permissions = {"/permission/admin/device-mgt/admin/policies/list"}) @Permission(scope = "policy-view", permissions = {"/permission/admin/device-mgt/admin/policies/list"})
Response getPolicy( Response getPolicy(
@ApiParam(name = "id", value = "The device identifier of the device.", required = true) @ApiParam(
@PathParam("id") int id); name = "id",
value = "Policy identifier",
required = true)
@PathParam("id") int id,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@PUT @PUT
@Path("/{id}") @Path("/{id}")
@ -104,35 +203,86 @@ public interface PolicyManagementService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
value = "Updating a policy.", value = "Update a policy.",
notes = "If you wish to make changes to an existing policy, you can do so by updating the policy using " + notes = "If you wish to make changes to an existing policy, that can be done by updating the policy using " +
"this API.") "this resource.")
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 201, message = "Policy has been updated successfully."), value = {
@ApiResponse(code = 500, message = "Policy management related exception in policy update.") @ApiResponse(
}) code = 200,
message = "OK. \n Policy has been updated successfully",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The URL of the updated device."),
@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 = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@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 updating the policy.")
})
@Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/update"}) @Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/update"})
Response updatePolicy( Response updatePolicy(
@ApiParam(name = "id", value = "The device identifier of the device.", required = true) @ApiParam(
name = "id",
value = "The device identifier of the device.", required = true)
@PathParam("id") int id, @PathParam("id") int id,
@ApiParam(name = "policy", value = "Policy details related to the operation.", @ApiParam(
required = true) PolicyWrapper policy); name = "policy",
value = "Policy details related to the operation.",
required = true) PolicyWrapper policy);
@POST @POST
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Removing multiple policies.", value = "Remove multiple policies.",
notes = "In situations where you need to delete more than one policy you can do so using this API.") notes = "In situations where you need to delete more than one policy you can do so using this API.")
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "Policies have been successfully deleted."), value = {
@ApiResponse(code = 404, message = "Policy does not exist."), @ApiResponse(
@ApiResponse(code = 500, message = "Error in deleting policies.") code = 200,
}) message = "OK. \n Policies have successfully been removed"),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@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 bulk removing policies.")
})
@Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/remove"}) @Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/remove"})
Response removePolicies(@ApiParam(name = "policyIds", value = "Policy ID list to be deleted.", Response removePolicies(
required = true) List<Integer> policyIds); @ApiParam(
name = "policyIds",
value = "Policy id list to be deleted.",
required = true) List<Integer> policyIds);
@POST @POST
@Path("/activate-policy") @Path("/activate-policy")
@ -143,16 +293,17 @@ public interface PolicyManagementService {
value = "Activating policies.", value = "Activating policies.",
notes = "Using the REST API command you are able to publish a policy in order to bring a policy that is " + notes = "Using the REST API command you are able to publish a policy in order to bring a policy that is " +
"in the inactive state to the active state.") "in the inactive state to the active state.")
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "Policies have been successfully activated."), value = {
@ApiResponse(code = 500, message = "Error in activating policies.") @ApiResponse(code = 200, message = "Policies have been successfully activated."),
}) @ApiResponse(code = 500, message = "Error in activating policies.")
})
@Permission(scope = "policy-modify", permissions = { @Permission(scope = "policy-modify", permissions = {
"/permission/admin/device-mgt/admin/policies/update", "/permission/admin/device-mgt/admin/policies/update",
"/permission/admin/device-mgt/admin/policies/add"}) "/permission/admin/device-mgt/admin/policies/add"})
Response activatePolicies( Response activatePolicies(
@ApiParam(name = "policyIds", value = "Policy ID list to be activated.", @ApiParam(name = "policyIds", value = "Policy ID list to be activated.",
required = true) List<Integer> policyIds); required = true) List<Integer> policyIds);
@POST @POST
@Path("/deactivate-policy") @Path("/deactivate-policy")
@ -172,26 +323,7 @@ public interface PolicyManagementService {
"/permission/admin/device-mgt/admin/policies/add"}) "/permission/admin/device-mgt/admin/policies/add"})
Response deactivatePolicies( Response deactivatePolicies(
@ApiParam(name = "policyIds", value = "Policy ID list to be deactivated.", @ApiParam(name = "policyIds", value = "Policy ID list to be deactivated.",
required = true) List<Integer> policyIds); required = true) List<Integer> policyIds);
@GET
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Getting Policy Enforced Details of a Device.",
notes = "When a device registers with WSO2 EMM a policy is enforced on the device. Initially the EMM " +
"filters the policies based on the Platform (device type), filters based on the device ownership" +
" type , filters based on the user role or name and finally the policy is enforced on the device.",
response = org.wso2.carbon.policy.mgt.common.Policy.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Fetched current policy."),
@ApiResponse(code = 404, message = "No policy found."),
@ApiResponse(code = 500, message = "Error occurred while getting the current policy.")
})
Response getEffectivePolicyOfDevice(
@ApiParam(name = "device-type", value = "The device type, such as ios, android or windows.", required = true)
@QueryParam("device-type") String type,
@ApiParam(name = "device-id", value = "The device identifier of the device.", required = true)
@QueryParam("device-id") String deviceId);
} }

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.*; import io.swagger.annotations.*;
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.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleWrapper;
import org.wso2.carbon.user.mgt.common.UIPermissionNode; import org.wso2.carbon.user.mgt.common.UIPermissionNode;
@ -38,93 +39,78 @@ public interface RoleManagementService {
@GET @GET
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting the list of roles.", value = "Get the list of roles.",
responseContainer = "List", responseContainer = "List",
notes = "If you wish to get the details of all the roles in EMM, you can do so using this REST API. All " + notes = "If you wish to get the details of all the roles in EMM, you can do so using this REST API. All " +
"internal roles, roles created for Service-providers and application related roles are omitted.", "internal roles, roles created for Service-providers and application related roles are omitted.",
response = String.class) response = String.class)
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "Successfully fetched the list of available roles", value = {
response = String.class, responseContainer = "List"), @ApiResponse(
@ApiResponse(code = 404, message = "No roles found."), code = 200,
@ApiResponse(code = 500, message = "Error occurred while fetching the role list.") message = "OK. \n Successfully fetched the requested list of roles.",
}) response = String.class,
responseContainer = "List",
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 = 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 requested list of roles.")
})
@Permission(scope = "roles-view", permissions = { @Permission(scope = "roles-view", permissions = {
"/permission/admin/device-mgt/admin/roles/list", "/permission/admin/device-mgt/admin/roles/list",
"/permission/admin/device-mgt/admin/users/view", "/permission/admin/device-mgt/admin/users/view",
"/permission/admin/device-mgt/admin/policies/add", "/permission/admin/device-mgt/admin/policies/add",
"/permission/admin/device-mgt/admin/policies/update"}) "/permission/admin/device-mgt/admin/policies/update"})
Response getRoles( Response getRoles(
@ApiParam(name = "offset", value = "Starting pagination index.",required = true) @ApiParam(
@QueryParam("offset") int offset, name = "filter",
@ApiParam(name = "limit", value = "How many role details are required from the starting pagination " + value = "Role name or a part of it to search.",
"index.", required = true) required = false)
@QueryParam("limit") int limit);
@GET
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Getting the list of roles in a user store.",
responseContainer = "List",
notes = "If you wish to get the details of all the roles in EMM, you can do so using this REST API.",
response = String.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched the list of available roles",
response = String.class, responseContainer = "List"),
@ApiResponse(code = 404, message = "No roles found."),
@ApiResponse(code = 500, message = "Error occurred while fetching the role list.")
})
@Permission(scope = "roles-view", permissions = {
"/permission/admin/device-mgt/admin/users/add",
"/permission/admin/device-mgt/admin/roles/list"})
Response getRoles(
@ApiParam(name = "user-store", value = "From which user store the roles must be fetched.",required = true)
@QueryParam("user-store") String userStoreName,
@ApiParam(name = "offset", value = "Starting pagination index.",required = true)
@QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many role details are required from the starting pagination " +
"index.", required = true)
@QueryParam("limit") int limit);
@GET
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Searching for roles via the role name.",
responseContainer = "List",
notes = "You will have many roles created within EMM. As the admin you will need to confirm if a " +
"given role exists in the EMM. In such situation you can search for the role by giving a " +
"character or a few characters of the role name. The search will give you a list of roles that" +
" have the name in the exact order of the characters you provided.",
response = String.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched the list of matching roles.",
response = String.class, responseContainer = "List"),
@ApiResponse(code = 404, message = "No roles found."),
@ApiResponse(code = 500, message = "Error occurred while fetching the matching role list.")
})
@Permission(scope = "roles-view", permissions = {
"/permission/admin/device-mgt/admin/users/add",
"/permission/admin/device-mgt/admin/roles/list"})
Response searchRoles(
@ApiParam(name = "filter", value = "Role name or a part of it to search.",required = true)
@QueryParam("filter") String filter, @QueryParam("filter") String filter,
@ApiParam(name = "offset", value = "Starting pagination index.",required = true) @ApiParam(
name = "user-store",
value = "From which user store the roles must be fetched.",
required = false)
@QueryParam("user-store") String userStoreName,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@ApiParam(
name = "offset",
value = "Starting point within the complete list of items qualified.",
required = false)
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many role details are required from the starting pagination " + @ApiParam(
"index.", required = true) name = "limit",
value = "Maximum size of resource array to return.",
required = false)
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
@GET @GET
@Path("/{roleName}/permissions") @Path("/{roleName}/permissions")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting permission details of a role.", value = "Getting permission details of a role.",
@ -132,51 +118,158 @@ public interface RoleManagementService {
"role. In EMM you are able to configure permissions based on the responsibilities carried " + "role. In EMM you are able to configure permissions based on the responsibilities carried " +
"out by a role. Therefore if you wish to retrieve the permission details of a role, you can do " + "out by a role. Therefore if you wish to retrieve the permission details of a role, you can do " +
"so using this REST API.", "so using this REST API.",
response = UIPermissionNode.class) response = UIPermissionNode.class,
@ApiResponses(value = { responseContainer = "List"
@ApiResponse(code = 200, message = "Permission details of a role", response = UIPermissionNode.class), )
@ApiResponse(code = 404, message = "No permissions found for the role."), @ApiResponses(
@ApiResponse(code = 500, message = "Error occurred while fetching the permission details of a role.") value = {
}) @ApiResponse(
code = 200,
message = "OK. \n Successfully fetched the permission list of the given role.",
response = UIPermissionNode.class,
responseContainer = "List",
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 = "Not Found. \n Resource to be deleted does not exist."),
@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 permission list of the requested role.")
})
@Permission(scope = "roles-view", permissions = {"/permission/admin/device-mgt/admin/roles/list"}) @Permission(scope = "roles-view", permissions = {"/permission/admin/device-mgt/admin/roles/list"})
Response getPermissionsOfRole( Response getPermissionsOfRole(
@ApiParam(name = "roleName", value = "Name of the role.",required = true) @ApiParam(
@PathParam("roleName") String roleName); name = "roleName",
value = "Name of the role.",
required = true)
@PathParam("roleName") String roleName,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@GET @GET
@Path("/{roleName}") @Path("/{roleName}")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting details of a role.", value = "Get details of a role.",
notes = "If you wish to get the details of a role in EMM, you can do so using this REST API.", notes = "If you wish to get the details of a role in EMM, you can do so using this REST API.",
response = RoleWrapper.class) response = RoleWrapper.class)
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "Successfully fetched the role details.", response = RoleWrapper.class), value = {
@ApiResponse(code = 404, message = "No role details found for the provided role name."), @ApiResponse(
@ApiResponse(code = 500, message = "Error occurred while retrieving the role details.") code = 200,
message = "OK. \n Successfully fetched the requested role.",
response = RoleWrapper.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 = "Not Found. \n Resource to be deleted does not exist."),
@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 requested role.")
}) })
@Permission(scope = "roles-view", permissions = {"/permission/admin/device-mgt/admin/roles/list"}) @Permission(scope = "roles-view", permissions = {"/permission/admin/device-mgt/admin/roles/list"})
Response getRole( Response getRole(
@ApiParam(name = "roleName", value = "Name of the role.",required = true) @ApiParam(
@PathParam("roleName") String roleName); name = "roleName",
value = "Name of the role.",
required = true)
@PathParam("roleName") String roleName,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@POST @POST
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Adding a role.", value = "Add a role.",
notes = "You are able to add a new role to EMM using the REST API.") notes = "You are able to add a new role to EMM using the REST API.")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "Added the role."), @ApiResponse(
@ApiResponse(code = 500, message = "Error occurred while adding the user role.") code = 201,
message = "Created. \n Role has successfully been created",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The URL of the role added."),
@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."),
@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 role.")
}) })
@Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/add"}) @Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/add"})
Response addRole( Response addRole(
@ApiParam(name = "role", value = "Details about the role to be added.",required = true) @ApiParam(
RoleWrapper role); name = "role",
value = "Details about the role to be added.",
required = true) RoleWrapper role);
@PUT @PUT
@Path("/{roleName}") @Path("/{roleName}")
@ -184,60 +277,138 @@ public interface RoleManagementService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
value = "Updating a role.", value = "Update a role.",
notes = "There will be situations where you will need to update the role details, such as the permissions" + notes = "There will be situations where you will need to update the role details, such as the permissions" +
" or the role name. In such situation you can update the role details.") " or the role name. In such situation you can update the role details.")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "Updated the role."), @ApiResponse(
@ApiResponse(code = 500, message = "Error occurred while updating the user role details.") code = 200,
message = "OK. \n Role has been updated successfully",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "URL of the updated role."),
@ResponseHeader(
name = "Content-Type",
description = "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 = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@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 updating the role.")
}) })
@Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/update"}) @Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/update"})
Response updateRole( Response updateRole(
@ApiParam(name = "roleName", value = "Name of the role.",required = true) @ApiParam(
name = "roleName",
value = "Name of the role.",
required = true)
@PathParam("roleName") String roleName, @PathParam("roleName") String roleName,
@ApiParam(name = "role", value = "Details about the role to be added.",required = true) @ApiParam(
RoleWrapper role); name = "role",
value = "Details about the role to be added.",
required = true) RoleWrapper role);
@DELETE @DELETE
@Path("/{roleName}") @Path("/{roleName}")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE", httpMethod = "DELETE",
value = "Deleting a role.", value = "Delete a role.",
notes = "In a situation when your Organization identifies that a specific role is no longer required you " + notes = "In a situation when your Organization identifies that a specific role is no longer required you " +
"will need to remove the role details from EMM.") "will need to remove the role details from EMM.")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "Deleted the role."), @ApiResponse(
@ApiResponse(code = 500, message = "Error occurred while deleting the user role details.") code = 200,
message = "OK. \n Role has successfully been removed"),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while removing the role.")
}) })
@Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/remove"}) @Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/remove"})
Response deleteRole( Response deleteRole(
@ApiParam(name = "roleName", value = "Name of the role to de deleted.",required = true) @ApiParam(
name = "roleName",
value = "Name of the role to de deleted.",
required = true)
@PathParam("roleName") String roleName); @PathParam("roleName") String roleName);
@POST @PUT
@Path("/{roleName}/users") @Path("/{roleName}/users")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
value = "Adding users to a role.", value = "Add users to a role.",
notes = "Defining the users to a role at the point of creating a new role is optional, " + notes = "Defining the users to a role at the point of creating a new role is optional, " +
"therefore you are able to update the users that belong to a given role after you have created " + "therefore you are able to update the users that belong to a given role after you have created " +
"a role using this REST API." + "a role using this REST API." +
"Example: Your Organization hires 30 new engineers. Updating the role details for each user can " + "Example: Your Organization hires 30 new engineers. Updating the role details for each user can " +
"be cumbersome, therefore you can define all the new employees that belong to the engineering " + "be cumbersome, therefore you can define all the new employees that belong to the engineering " +
"role using this API.") "role using this API.")
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "Added Users to a Role."), value = {
@ApiResponse(code = 500, message = "Error occurred while saving the users of the role.") @ApiResponse(
code = 200,
message = "OK. \n User list of the role has been updated successfully",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "URL of the updated user list."),
@ResponseHeader(
name = "Content-Type",
description = "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 = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@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 updating the user list of the role.")
}) })
@Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/update"}) @Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/update"})
Response updateUsersOfRole( Response updateUsersOfRole(
@ApiParam(name = "roleName", value = "Name of the role.",required = true) @ApiParam(
name = "roleName",
value = "Name of the role.",
required = true)
@PathParam("roleName") String roleName, @PathParam("roleName") String roleName,
@ApiParam(name = "users", value = "List of usernames to be added.",required = true) @ApiParam(
List<String> users); name = "users",
value = "List of usernames to be added.",
required = true) List<String> users);
} }

@ -27,11 +27,12 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.UserWrapper;
import javax.ws.rs.*; import javax.ws.rs.*;
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.Date;
@API(name = "UserManagement", version = "1.0.0", context = "/devicemgt_admin/users", tags = {"devicemgt_admin"}) @API(name = "User Management API", version = "1.0.0", context = "/devicemgt_admin/users", tags = {"devicemgt_admin"})
@Path("/users") @Path("/users")
@Api(value = "UserManagement", description = "User management related operations can be found here.") @Api(value = "User Management API", description = "User management related operations can be found here.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public interface UserManagementService { public interface UserManagementService {
@ -41,15 +42,52 @@ public interface UserManagementService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Adding a user.", value = "Add a user.",
notes = "Adds a new user to EMM using this REST API.") notes = "A new user can be added to the user management system via this resource")
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 201, message = "Added the user successfully."), value = {
@ApiResponse(code = 500, message = "Exception in trying to add the user.") @ApiResponse(
}) code = 201,
message = "Created. \n User has successfully been created",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The URL of the role added."),
@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."),
@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 user.")
})
@Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/add"}) @Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/add"})
Response addUser( Response addUser(
@ApiParam(name = "user", value = "User related details.",required = true) UserWrapper user); @ApiParam(
name = "user",
value = "User related details.",
required = true) UserWrapper user);
@GET @GET
@Path("/{username}") @Path("/{username}")
@ -62,15 +100,48 @@ public interface UserManagementService {
+ " you can do so using the REST API.", + " you can do so using the REST API.",
response = UserWrapper.class) response = UserWrapper.class)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 201, message = "User information was retrieved successfully.", @ApiResponse(
response = UserWrapper.class), code = 200,
@ApiResponse(code = 404, message = "User by the provided username does not exist."), message = "OK. \n Successfully fetched the requested role.",
@ApiResponse(code = 500, message = "Exception in trying to retrieve user by username.") response = UserWrapper.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 = "Not Found. \n Resource to be deleted does not exist."),
@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 requested user.")
}) })
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/view"}) @Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/view"})
Response getUser( Response getUser(
@ApiParam(name = "username", value = "Username of the user to be fetched.",required = true) @ApiParam(
@PathParam("username") String username); name = "username",
value = "Username of the user to be fetched.",
required = true)
@PathParam("username") String username,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@PUT @PUT
@Path("/{username}") @Path("/{username}")
@ -78,95 +149,192 @@ public interface UserManagementService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
value = "Updating details of a user", value = "Update details of a user",
notes = "There will be situations where you will want to update the user details. In such " notes = "There will be situations where you will want to update the user details. In such "
+ "situation you can update the user details using this REST API.") + "situation you can update the user details using this REST API.")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "User was successfully updated"), @ApiResponse(
@ApiResponse(code = 409, message = "User by the provided username doesn't exists. Therefore, " code = 200,
+ "request made to update user was refused."), message = "OK. \n User has been updated successfully",
@ApiResponse(code = 500, message = "Exception in trying to update user by username: 'username'") responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "URL of the updated user."),
@ResponseHeader(
name = "Content-Type",
description = "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 = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@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 updating the user.")
}) })
@Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/update"}) @Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/update"})
Response updateUser( Response updateUser(
@ApiParam(name = "username", value = "Username of the user to be updated.",required = true) @ApiParam(
name = "username",
value = "Username of the user to be updated.",
required = true)
@PathParam("username") String username, @PathParam("username") String username,
@ApiParam(name = "user", value = "User related details.",required = true) @ApiParam(
UserWrapper user); name = "userData",
value = "User related details.",
required = true) UserWrapper userData);
@DELETE @DELETE
@Path("/{username}") @Path("/{username}")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE", httpMethod = "DELETE",
value = "Deleting a user.", value = "Deleting a user.",
notes = "In a situation where an employee leaves the organization you will need to remove the" notes = "In a situation where an employee leaves the organization you will need to remove the"
+ " user details from EMM. In such situations you can use this REST API to remove a user.") + " user details from EMM. In such situations you can use this REST API to remove a user.")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "User was successfully removed."), @ApiResponse(
@ApiResponse(code = 404, message = "User does not exist for removal."), code = 200,
@ApiResponse(code = 500, message = "Exception in trying to remove user.") message = "OK. \n User has successfully been removed"),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while removing the user.")
}) })
@Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/remove"}) @Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/remove"})
Response removeUser( Response removeUser(
@ApiParam(name = "username", value = "Username of the user to be deleted.",required = true) @ApiParam(name = "username", value = "Username of the user to be deleted.", required = true)
@PathParam("username") String username); @PathParam("username") String username);
@POST @GET
@Path("/{username}/roles") @Path("/{username}/roles")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting the role details of a user.", value = "Get the role list of a user.",
notes = "A user can be assigned to one or more role in EMM. Using this REST API you are " notes = "A user can be assigned to one or more role in EMM. Using this REST API you are "
+ "able to get the role/roles a user is assigned to.", + "able to get the role/roles a user is assigned to.",
response = String.class, response = String.class,
responseContainer = "List") responseContainer = "List")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "User roles obtained for the provided user.", response = String.class, @ApiResponse(
responseContainer = "List"), code = 200,
@ApiResponse(code = 404, message = "User does not exist for role retrieval."), message = "OK. \n Successfully fetched the role list assigned to the user.",
@ApiResponse(code = 500, message = "Exception in trying to retrieve roles for the provided user.") response = String.class,
responseContainer = "List",
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 = "Not Found. \n Resource to be deleted does not exist."),
@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 role list assigned to the user.")
}) })
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/view"}) @Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/view"})
Response getRolesOfUser( Response getRolesOfUser(
@ApiParam(name = "username", value = "Username of the user.",required = true) @ApiParam(name = "username", value = "Username of the user.", required = true)
@PathParam("username") String username); @PathParam("username") String username);
@GET @GET
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting details of users", value = "Get user list",
notes = "If you wish to get the details of all the user registered with EMM, you can do so " notes = "If you wish to get the details of all the users registered with EMM, you can do so "
+ "using the REST API", + "using the REST API",
response = UserWrapper.class, response = UserWrapper.class,
responseContainer = "List") responseContainer = "List")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "All users were successfully retrieved.", response = UserWrapper.class, @ApiResponse(
responseContainer = "List"), code = 200,
@ApiResponse(code = 404, message = "No users found."), message = "OK. \n Successfully fetched the requested role.",
@ApiResponse(code = 500, message = "Error occurred while retrieving the list of users.") response = UserWrapper.class,
responseContainer = "List",
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 = 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 user list.")
}) })
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"}) @Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"})
Response getUsers( Response getUsers(
@ApiParam(name = "filter", value = "Username of the user details to be fetched.",required = true) @ApiParam(
name = "filter",
value = "Username of the user details to be fetched.",
required = true)
@QueryParam("filter") String filter, @QueryParam("filter") String filter,
@ApiParam(name = "offset", value = "Starting pagination index.",required = true) @ApiParam(
name = "If-Modified-Since",
value = "Timestamp of the last modified date",
required = false)
@HeaderParam("If-Modified-Since") Date timestamp,
@ApiParam(
name = "offset",
value = "Starting point within the complete list of items qualified.",
required = false)
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many user details are required from the starting pagination " + @ApiParam(
"index.", required = true) name = "limit",
value = "Maximum size of resource array to return.",
required = false)
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
@GET @GET
@Path("/usernames")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Searching for a username.", value = "Search for a username.",
notes = "If you are unsure of the " notes = "If you are unsure of the "
+ "user name of a user and need to retrieve the details of a specific user, you can " + "user name of a user and need to retrieve the details of a specific user, you can "
+ "search for that user by giving a character or a few characters in the username. " + "search for that user by giving a character or a few characters in the username. "
@ -175,19 +343,55 @@ public interface UserManagementService {
response = String.class, response = String.class,
responseContainer = "List") responseContainer = "List")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "All users by username were successfully retrieved.", @ApiResponse(
response = String.class, responseContainer = "List"), code = 200,
@ApiResponse(code = 404, message = "No users found."), message = "OK. \n Successfully fetched the username list that matches the given filter.",
@ApiResponse(code = 500, message = "Error occurred while retrieving the list of users.") response = String.class,
responseContainer = "List",
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 = 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 username list that matches the given filter.")
}) })
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"}) @Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"})
Response getUserNames( Response getUserNames(
@ApiParam(name = "filter", value = "Username/part of the user name to search.",required = true) @ApiParam(
name = "filter",
value = "Username/part of the user name to search.",
required = true)
@QueryParam("filter") String filter, @QueryParam("filter") String filter,
@ApiParam(name = "offset", value = "Starting pagination index.",required = true) @ApiParam(
name = "If-Modified-Since",
value = "Timestamp of the last modified date",
required = false)
@HeaderParam("If-Modified-Since") Date timestamp,
@ApiParam(
name = "offset",
value = "Starting point within the complete list of items qualified.",
required = false)
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many user details are required from the starting pagination " + @ApiParam(
"index.", required = true) name = "limit",
value = "Maximum size of resource array to return.",
required = false)
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
@PUT @PUT
@ -199,16 +403,33 @@ public interface UserManagementService {
value = "Changing the user password.", value = "Changing the user password.",
notes = "A user is able to change the password to secure their EMM profile via this REST API.") notes = "A user is able to change the password to secure their EMM profile via this REST API.")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 201, message = "User password was successfully changed."), @ApiResponse(
@ApiResponse(code = 400, message = "Old password does not match."), code = 200,
@ApiResponse(code = 500, message = "Could not change the password of the user. The Character encoding is" + message = "OK. \n Credentials of the user have been updated successfully"),
" not supported.") @ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@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 updating credentials of the user.")
}) })
@Permission(scope = "user-modify", permissions = {"/permission/admin/login"}) @Permission(scope = "user-modify", permissions = {"/permission/admin/login"})
Response resetPassword( Response resetPassword(
@ApiParam(name = "username", value = "Username of the user.",required = true) @ApiParam(
name = "username",
value = "Username of the user.",
required = true)
@PathParam("username") String username, @PathParam("username") String username,
@ApiParam(name = "credentials", value = "Credential.",required = true) @ApiParam(
UserCredentialWrapper credentials); name = "credentials",
value = "Credential.",
required = true) UserCredentialWrapper credentials);
} }

@ -46,11 +46,28 @@ public interface ApplicationManagementAdminService {
value = "Application installation API.(Internal API)", value = "Application installation API.(Internal API)",
notes = "This is an internal API used for application installation on a device.") notes = "This is an internal API used for application installation on a device.")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 201, message = "Application wil be installed on the device."), @ApiResponse(
@ApiResponse(code = 500, message = "Error while adding the application install operation.") code = 200,
message = "OK. \n Install application operations have been successfully scheduled upon given devices"),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be processed does not exist."),
@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 bulk issuing application installation operations upon " +
"a given set of devices.")
}) })
Response installApplication( Response installApplication(
@ApiParam(name = "applicationWrapper", value = "Application details of the application to be installed.", @ApiParam(
name = "applicationWrapper",
value = "Application details of the application to be installed.",
required = true) ApplicationWrapper applicationWrapper); required = true) ApplicationWrapper applicationWrapper);
@POST @POST
@ -59,14 +76,31 @@ public interface ApplicationManagementAdminService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Application uninstallation API.(Internal API)", value = "Application un-installation API.(Internal API)",
notes = "This is an internal API used for application uninstallation on a device.") notes = "This is an internal API used for application uninstallation on a device.")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 201, message = "Application wil be uninstalled on the device."), @ApiResponse(
@ApiResponse(code = 500, message = "Error while adding the application uninstall operation.") code = 200,
message = "OK. \n Uninstall application operations have been successfully scheduled upon given devices"),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be processed does not exist."),
@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 bulk issuing application un-installation operations upon " +
"a given set of devices.")
}) })
Response uninstallApplication( Response uninstallApplication(
@ApiParam(name = "applicationWrapper", value = "Application details of the application to be uninstalled.", @ApiParam(
name = "applicationWrapper",
value = "Application details of the application to be uninstalled.",
required = true) ApplicationWrapper applicationWrapper); required = true) ApplicationWrapper applicationWrapper);
} }

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.device.mgt.common.Device;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@ -36,23 +37,69 @@ public interface DeviceManagementAdminService {
@GET @GET
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Get devices by the name.", value = "Get devices by name.",
notes = "Get devices the name of device and tenant.", notes = "Get devices by name of the device and tenant that they belong to.",
response = org.wso2.carbon.device.mgt.common.Device.class, response = Device.class,
responseContainer = "List") responseContainer = "List")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched device details.", @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.",
response = org.wso2.carbon.device.mgt.common.Device.class, responseContainer = "List"), response = Device.class,
@ApiResponse(code = 404, message = "No matching device found in the provided tenant."), responseContainer = "List",
@ApiResponse(code = 500, message = "Error while fetching device information.") 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 = 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 device list.")
}) })
Response getDevicesByName( Response getDevicesByName(
@ApiParam(name = "name", value = "Name of the device.",required = true) @ApiParam(
name = "name",
value = "Name of the device.",
required = true)
@QueryParam("name") String name, @QueryParam("name") String name,
@ApiParam(name = "tenant-domain", value = "Name of the tenant.",required = true) @ApiParam(
@QueryParam("tenant-domain") String tenantDomain); name = "type",
value = "Type of the device.",
required = true)
@QueryParam("type") String type,
@ApiParam(
name = "tenant-domain",
value = "Name of the tenant.",
required = true)
@QueryParam("tenant-domain") String tenantDomain,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@ApiParam(
name = "offset",
value = "Starting point within the complete list of items qualified.",
required = false)
@QueryParam("offset") int offset,
@ApiParam(
name = "limit",
value = "Maximum size of resource array to return.",
required = false)
@QueryParam("limit") int limit);
} }

@ -18,15 +18,14 @@
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.api.admin; package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.*;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.wso2.carbon.apimgt.annotations.api.Permission; import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper;
import javax.ws.rs.*; import javax.ws.rs.*;
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.Date;
@Path("/groups") @Path("/groups")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -35,27 +34,60 @@ public interface GroupManagementAdminService {
@GET @GET
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Get groups by the name.", value = "Get groups by the name.",
notes = "Get devices the name of device and tenant.", notes = "Get devices the name of device and tenant.",
response = org.wso2.carbon.device.mgt.common.Device.class, response = DeviceGroupWrapper.class,
responseContainer = "List") responseContainer = "List")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched group details.", @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of groups.",
response = org.wso2.carbon.device.mgt.common.Device.class, responseContainer = "List"), response = DeviceGroupWrapper.class,
@ApiResponse(code = 404, message = "Device not found."), responseContainer = "List",
@ApiResponse(code = 500, message = "Error while fetching group information.") 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 = 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 list.")
}) })
@Permission(scope = "group-view", permissions = {"/permission/admin/device-mgt/user/groups/list"}) @Permission(scope = "group-view", permissions = {"/permission/admin/device-mgt/user/groups/list"})
Response getGroupsOfUser( Response getGroupsOfUser(
@ApiParam(name = "username", value = "Username of the user.",required = true) @ApiParam(
name = "username",
value = "Username of the user.",
required = true)
@QueryParam("username") String username, @QueryParam("username") String username,
@ApiParam(name = "offset", value = "Starting pagination index.",required = true) @ApiParam(
name = "If-Modified-Since",
value = "Timestamp of the last modified date",
required = false)
@HeaderParam("If-Modified-Since") Date timestamp,
@ApiParam(
name = "offset",
value = "Starting point within the complete list of items qualified.",
required = false)
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many policy details are required from the starting pagination " + @ApiParam(
"index.", required = true) name = "limit",
value = "Maximum size of resource array to return.",
required = false)
@QueryParam("limit") int limit); @QueryParam("limit") int limit);

@ -34,25 +34,42 @@ import javax.ws.rs.core.Response;
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public interface UserManagementAdminService { public interface UserManagementAdminService {
@POST @PUT
@Path("/{username}/credentials") @Path("/{username}/credentials")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Changing the user password.", value = "Change the user password.",
notes = "A user is able to change the password to secure their EMM profile via this REST API.") notes = "A user is able to change the password to secure their EMM profile via this REST API.")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 201, message = "User password was successfully changed."), @ApiResponse(
@ApiResponse(code = 400, message = "Old password does not match."), code = 200,
@ApiResponse(code = 500, message = "Could not change the password of the user. The Character encoding is" + message = "OK. \n Credentials of the user have been updated successfully"),
" not supported.") @ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@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 updating credentials of the user.")
}) })
@Permission(scope = "user-modify", permissions = {"/permission/admin/login"}) @Permission(scope = "user-modify", permissions = {"/permission/admin/login"})
Response resetPassword( Response resetPassword(
@ApiParam(name = "username", value = "Username of the user.",required = true) @ApiParam(
name = "username",
value = "Username of the user.",
required = true)
@PathParam("username") String username, @PathParam("username") String username,
@ApiParam(name = "credentials", value = "Credential.",required = true) @ApiParam(
UserCredentialWrapper credentials); name = "credentials",
value = "Credential.",
required = true) UserCredentialWrapper credentials);
} }

@ -21,12 +21,12 @@ 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.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.service.api.ActivityInfoProviderService; import org.wso2.carbon.device.mgt.jaxrs.service.api.ActivityInfoProviderService;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@ -37,7 +37,9 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
@Override @Override
@Path("/{id}") @Path("/{id}")
public Response getActivity(@PathParam("id") String id) { public Response getActivity(
@PathParam("id") String id,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
Activity operation = null; Activity operation = null;
DeviceManagementProviderService dmService; DeviceManagementProviderService dmService;
try { try {

@ -28,7 +28,10 @@ import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.util.MDMAppConstants; import org.wso2.carbon.device.mgt.jaxrs.util.MDMAppConstants;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil; import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
import javax.ws.rs.*; import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -38,25 +41,9 @@ public class ConfigurationServiceImpl implements ConfigurationManagementService
private static final Log log = LogFactory.getLog(ConfigurationServiceImpl.class); private static final Log log = LogFactory.getLog(ConfigurationServiceImpl.class);
@POST
@Override
public Response saveConfiguration(PlatformConfiguration config) {
try {
DeviceMgtAPIUtils.getPlatformConfigurationManagementService().saveConfiguration(config,
MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
//Schedule the task service
DeviceMgtAPIUtils.scheduleTaskService(DeviceMgtAPIUtils.getNotifierFrequency(config));
return Response.status(Response.Status.OK).entity("Platform configuration successfully saved.").build();
} catch (ConfigurationManagementException e) {
String msg = "Error occurred while saving the platform configuration.";
log.error(msg, e);
return javax.ws.rs.core.Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET @GET
@Override @Override
public Response getConfiguration() { public Response getConfiguration(@HeaderParam("If-Modified-Since") String ifModifiedSince) {
String msg; String msg;
try { try {
PlatformConfiguration config = DeviceMgtAPIUtils.getPlatformConfigurationManagementService(). PlatformConfiguration config = DeviceMgtAPIUtils.getPlatformConfigurationManagementService().

@ -37,6 +37,9 @@ import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService;
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.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@ -50,7 +53,15 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@GET @GET
@Override @Override
public Response getDevices(@QueryParam("offset") int offset, @QueryParam("limit") int limit) { public Response getDevices(
@QueryParam("type") String type,
@QueryParam("user") String user,
@QueryParam("roleName") String roleName,
@QueryParam("ownership") String ownership,
@QueryParam("status") String status,
@HeaderParam("If-Modified-Since") Date timestamp,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
try { try {
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
PaginationRequest request = new PaginationRequest(offset, limit); PaginationRequest request = new PaginationRequest(offset, limit);
@ -68,48 +79,11 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
} }
} }
@Override
public Response getDevices(@HeaderParam("If-Modified-Since") Date timestamp,
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
SearchManagerService searchManagerService;
List<DeviceWrapper> devices;
try {
searchManagerService = DeviceMgtAPIUtils.getSearchManagerService();
devices = searchManagerService.getUpdated(timestamp.getTime());
} catch (SearchMgtException e) {
String msg = "Error occurred while retrieving the updated device information after the given time.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(devices).build();
}
@GET
@Override
public Response getDevices(@QueryParam("type") String type, @QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
try {
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
PaginationRequest request = new PaginationRequest(offset, limit);
request.setDeviceType(type);
PaginationResult result = dms.getAllDevices(request);
if (result == null || result.getData().size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No device of type '" + type +
"' is currently enrolled with the server").build();
}
return Response.status(Response.Status.OK).entity(result.getData()).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while fetching the devices of type '" + type + "'";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@POST @POST
@Override @Override
public Response getDevicesInfo(List<DeviceIdentifier> deviceIds) { public Response getDevicesInfo(
List<DeviceIdentifier> deviceIds,
@HeaderParam("If-Modified-Since") Date timestamp) {
DeviceInformationManager informationManager; DeviceInformationManager informationManager;
List<DeviceInfo> deviceInfo; List<DeviceInfo> deviceInfo;
try { try {
@ -129,91 +103,10 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@GET @GET
@Override @Override
public Response getDeviceByUsername(@QueryParam("user") String user, @QueryParam("offset") int offset, public Response getDevice(
@QueryParam("limit") int limit) { @PathParam("type") String type,
PaginationResult result; @PathParam("id") String id,
try { @HeaderParam("If-Modified-Since") String ifModifiedSince) {
PaginationRequest request = new PaginationRequest(offset, limit);
request.setOwner(user);
result = DeviceMgtAPIUtils.getDeviceManagementService().getDevicesOfUser(request);
if (result == null || result.getData().size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No device has currently been " +
"enrolled by the user '" + user + "'").build();
}
return Response.status(Response.Status.OK).entity(result.getData()).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while fetching the devices of user '" + user + "'";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Override
public Response getDevicesByRole(@QueryParam("roleName") String roleName, @QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
List<Device> devices;
try {
devices = DeviceMgtAPIUtils.getDeviceManagementService().getAllDevicesOfRole(roleName);
if (devices == null || devices.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No device has currently been " +
"enrolled under the role '" + roleName + "'").build();
}
return Response.status(Response.Status.OK).entity(devices).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while fetching the devices of the role '" + roleName + "'";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Override
public Response getDevicesByOwnership(@QueryParam("ownership") EnrolmentInfo.OwnerShip ownership,
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
PaginationResult result;
try {
PaginationRequest request = new PaginationRequest(offset, limit);
request.setOwnership(ownership.toString());
result = DeviceMgtAPIUtils.getDeviceManagementService().getDevicesByOwnership(request);
if (result == null || result.getData().size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No device has currently been enrolled " +
"under the ownership scheme '" + ownership.toString() + "'").build();
}
return Response.status(Response.Status.OK).entity(result.getData()).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while fetching the devices enrolled under the ownership scheme '" +
ownership.toString() + "'";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Override
public Response getDevicesByEnrollmentStatus(@QueryParam("status") EnrolmentInfo.Status status,
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
PaginationResult result;
try {
PaginationRequest request = new PaginationRequest(offset, limit);
request.setStatus(status.toString());
result = DeviceMgtAPIUtils.getDeviceManagementService().getDevicesByOwnership(request);
if (result == null || result.getData().size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No device is currently in enrollment " +
"status '" + status.toString() + "'").build();
}
return Response.status(Response.Status.OK).entity(result.getData()).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while fetching the devices that carry the enrollment status '" +
status.toString() + "'";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Override
public Response getDevice(@QueryParam("type") String type, @QueryParam("id") String id) {
Device device; Device device;
try { try {
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
@ -233,7 +126,10 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@GET @GET
@Path("/{type}/{id}/location") @Path("/{type}/{id}/location")
@Override @Override
public Response getDeviceLocation(@PathParam("type") String type, @PathParam("id") String id) { public Response getDeviceLocation(
@PathParam("type") String type,
@PathParam("id") String id,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
DeviceInformationManager informationManager; DeviceInformationManager informationManager;
DeviceLocation deviceLocation; DeviceLocation deviceLocation;
try { try {
@ -256,7 +152,10 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@GET @GET
@Path("/{type}/{id}/features") @Path("/{type}/{id}/features")
@Override @Override
public Response getFeaturesOfDevice(@PathParam("type") String type, @PathParam("id") String id) { public Response getFeaturesOfDevice(
@PathParam("type") String type,
@PathParam("id") String id,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
List<Feature> features; List<Feature> features;
DeviceManagementProviderService dms; DeviceManagementProviderService dms;
try { try {
@ -278,7 +177,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@POST @POST
@Path("/search-devices") @Path("/search-devices")
@Override @Override
public Response searchDevices(SearchContext searchContext) { public Response searchDevices(SearchContext searchContext, @QueryParam("offset") int offset, int limit) {
SearchManagerService searchManagerService; SearchManagerService searchManagerService;
List<DeviceWrapper> devices; List<DeviceWrapper> devices;
try { try {
@ -299,7 +198,12 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@GET @GET
@Path("/{type}/{id}/applications") @Path("/{type}/{id}/applications")
@Override @Override
public Response getInstalledApplications(@PathParam("type") String type, @PathParam("id") String id) { public Response getInstalledApplications(
@PathParam("type") String type,
@PathParam("id") String id,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
List<Application> applications; List<Application> applications;
ApplicationManagementProviderService amc; ApplicationManagementProviderService amc;
try { try {
@ -321,8 +225,12 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@GET @GET
@Path("/{type}/{id}/operations") @Path("/{type}/{id}/operations")
@Override @Override
public Response getDeviceOperations(@QueryParam("offset") int offset, @QueryParam("limit") int limit, public Response getDeviceOperations(
@PathParam("type") String type, @PathParam("id") String id) { @PathParam("type") String type,
@PathParam("id") String id,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
List<? extends Operation> operations; List<? extends Operation> operations;
DeviceManagementProviderService dms; DeviceManagementProviderService dms;
try { try {
@ -337,4 +245,24 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
return Response.status(Response.Status.OK).entity(operations).build(); return Response.status(Response.Status.OK).entity(operations).build();
} }
@Override
public Response getEffectivePolicyOfDevice(@QueryParam("type") String type,
@QueryParam("id") String id,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
try {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
Policy policy = policyManagementService.getAppliedPolicyToDevice(new DeviceIdentifier(id, type));
if (policy == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No policy has been found for the '" +
type + "' device, which carries the id '" + id + "'").build();
}
return Response.status(Response.Status.OK).entity(policy).build();
} catch (PolicyManagementException e) {
String msg = "Error occurred while retrieving the current policy associated with the '" + type +
"' device, which carries the id '" + id + "'";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
} }

@ -39,7 +39,10 @@ public class NotificationManagementServiceImpl implements NotificationManagement
@GET @GET
@Override @Override
public Response getNotifications(@QueryParam("offset") int offset, @QueryParam("limit") int limit) { public Response getNotifications(
@QueryParam("status") String status,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
String msg; String msg;
try { try {
List<Notification> notifications = List<Notification> notifications =
@ -56,33 +59,13 @@ public class NotificationManagementServiceImpl implements NotificationManagement
} }
} }
@GET
@Override
public Response getNotificationsByStatus(@QueryParam("status") Notification.Status status,
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
String msg;
try {
List<Notification> notifications =
DeviceMgtAPIUtils.getNotificationManagementService().getNotificationsByStatus(status);
if (notifications == null || notifications.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No notification, which carries " +
"the status '" + status.toString() + "' is available to be retrieved").build();
}
return Response.status(Response.Status.OK).entity(notifications).build();
} catch (NotificationManagementException e) {
msg = "Error occurred while retrieving the notification list that carries the status '" +
status.toString() + "'";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@PUT @PUT
@Path("/{id}/status") @Path("/{id}/status")
@Override @Override
public Response updateNotificationStatus(@PathParam("id") int id, Notification.Status status) { public Response updateNotificationStatus(@PathParam("id") int id, String status) {
try { try {
DeviceMgtAPIUtils.getNotificationManagementService().updateNotificationStatus(id, status); DeviceMgtAPIUtils.getNotificationManagementService().updateNotificationStatus(id,
Notification.Status.valueOf(status));
return Response.status(Response.Status.OK).entity("Notification status has successfully been updated").build(); return Response.status(Response.Status.OK).entity("Notification status has successfully been updated").build();
} catch (NotificationManagementException e) { } catch (NotificationManagementException e) {
String msg = "Error occurred while updating notification status"; String msg = "Error occurred while updating notification status";

@ -26,9 +26,9 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
import org.wso2.carbon.device.mgt.jaxrs.service.api.PolicyManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.PolicyManagementService;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
@ -96,7 +96,10 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
@GET @GET
@Override @Override
public Response getPolicies(@QueryParam("offset") int offset, @QueryParam("limit") int limit) { public Response getPolicies(
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
List<Policy> policies; List<Policy> policies;
try { try {
@ -116,7 +119,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
@GET @GET
@Path("/{id}") @Path("/{id}")
@Override @Override
public Response getPolicy(@PathParam("id") int id) { public Response getPolicy(@PathParam("id") int id, @HeaderParam("If-Modified-Since") String ifModifiedSince) {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
final org.wso2.carbon.policy.mgt.common.Policy policy; final org.wso2.carbon.policy.mgt.common.Policy policy;
try { try {
@ -130,9 +133,6 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
if (policy == null) {
return Response.status(Response.Status.NOT_FOUND).entity("Policy for ID " + id + " not found").build();
}
return Response.status(Response.Status.OK).entity(policy).build(); return Response.status(Response.Status.OK).entity(policy).build();
} }
@ -186,7 +186,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
try { try {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
PolicyAdministratorPoint pap = policyManagementService.getPAP(); PolicyAdministratorPoint pap = policyManagementService.getPAP();
for(int i : policyIds) { for (int i : policyIds) {
pap.activatePolicy(i); pap.activatePolicy(i);
} }
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {
@ -204,7 +204,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
try { try {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
PolicyAdministratorPoint pap = policyManagementService.getPAP(); PolicyAdministratorPoint pap = policyManagementService.getPAP();
for(int i : policyIds) { for (int i : policyIds) {
pap.inactivatePolicy(i); pap.inactivatePolicy(i);
} }
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {
@ -216,24 +216,4 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
"deactivated").build(); "deactivated").build();
} }
@GET
@Override
public Response getEffectivePolicyOfDevice(@QueryParam("device-type") String type,
@QueryParam("device-id") String deviceId) {
try {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
Policy policy = policyManagementService.getAppliedPolicyToDevice(new DeviceIdentifier(deviceId, type));
if (policy == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No policy has been found for the '" +
type + "' device, which carries the id '" + deviceId + "'").build();
}
return Response.status(Response.Status.OK).entity(policy).build();
} catch (PolicyManagementException e) {
String msg = "Error occurred while retrieving the current policy associated with the '" + type +
"' device, which carries the id '" + deviceId + "'";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
} }

@ -44,7 +44,11 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@GET @GET
@Override @Override
public Response getRoles(@QueryParam("offset") int offset, @QueryParam("limit") int limit) { public Response getRoles(
@QueryParam("filter") String filter,
@QueryParam("user-store") String userStoreName,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
List<String> filteredRoles; List<String> filteredRoles;
try { try {
filteredRoles = getRolesFromUserStore(); filteredRoles = getRolesFromUserStore();
@ -59,73 +63,12 @@ public class RoleManagementServiceImpl implements RoleManagementService {
return Response.status(Response.Status.OK).entity(filteredRoles).build(); return Response.status(Response.Status.OK).entity(filteredRoles).build();
} }
@GET
@Override
public Response getRoles(@QueryParam("user-store") String userStoreName, @QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
String[] roles;
try {
AbstractUserStoreManager abstractUserStoreManager =
(AbstractUserStoreManager) DeviceMgtAPIUtils.getUserStoreManager();
if (log.isDebugEnabled()) {
log.debug("Getting the list of user roles");
}
roles = abstractUserStoreManager.getRoleNames(userStoreName + "/*", -1, false, true, true);
} catch (UserStoreException e) {
String msg = "Error occurred while retrieving the list of user roles from the underlying user-store '" +
userStoreName + "'";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
// removing all internal roles and roles created for Service-providers
List<String> filteredRoles = new ArrayList<>();
for (String role : roles) {
if (!(role.startsWith("Internal/") || role.startsWith("Authentication/"))) {
filteredRoles.add(role);
}
}
if (filteredRoles == null || filteredRoles.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No roles found.").build();
}
return Response.status(Response.Status.OK).entity(filteredRoles).build();
}
@GET
@Override
public Response searchRoles(@QueryParam("filter") String filter, @QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
String[] roles;
try {
AbstractUserStoreManager abstractUserStoreManager =
(AbstractUserStoreManager) DeviceMgtAPIUtils.getUserStoreManager();
if (log.isDebugEnabled()) {
log.debug("Getting the list of user roles using filter : " + filter);
}
roles = abstractUserStoreManager.getRoleNames("*" + filter + "*", -1, true, true, true);
} catch (UserStoreException e) {
String msg = "Error occurred while retrieving the list of user roles using the filter '" + filter + "'";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
// removing all internal roles and roles created for Service-providers
List<String> filteredRoles = new ArrayList<>();
for (String role : roles) {
if (!(role.startsWith("Internal/") || role.startsWith("Authentication/"))) {
filteredRoles.add(role);
}
}
if (filteredRoles == null || filteredRoles.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No roles found.").build();
}
return Response.status(Response.Status.OK).entity(filteredRoles).build();
}
@GET @GET
@Path("/{roleName}/permissions") @Path("/{roleName}/permissions")
@Override @Override
public Response getPermissionsOfRole(@PathParam("roleName") String roleName) { public Response getPermissionsOfRole(
@PathParam("roleName") String roleName,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
try { try {
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm(); final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
org.wso2.carbon.user.core.UserRealm userRealmCore = null; org.wso2.carbon.user.core.UserRealm userRealmCore = null;
@ -176,7 +119,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@GET @GET
@Path("/{roleName}") @Path("/{roleName}")
@Override @Override
public Response getRole(@PathParam("roleName") String roleName) { public Response getRole(@PathParam("roleName") String roleName,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
RoleWrapper roleWrapper = new RoleWrapper(); RoleWrapper roleWrapper = new RoleWrapper();
try { try {
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
@ -201,10 +145,6 @@ public class RoleManagementServiceImpl implements RoleManagementService {
String[] permListAr = new String[permList.size()]; String[] permListAr = new String[permList.size()];
roleWrapper.setPermissions(permList.toArray(permListAr)); roleWrapper.setPermissions(permList.toArray(permListAr));
} }
if (roleWrapper == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No roles found for the role name '"
+ roleName + ".").build();
}
} catch (UserStoreException | UserAdminException e) { } catch (UserStoreException | UserAdminException e) {
String msg = "Error occurred while retrieving the user role '" + roleName + "'"; String msg = "Error occurred while retrieving the user role '" + roleName + "'";
log.error(msg, e); log.error(msg, e);

@ -19,7 +19,6 @@
package org.wso2.carbon.device.mgt.jaxrs.service.impl; package org.wso2.carbon.device.mgt.jaxrs.service.impl;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -27,13 +26,12 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo; import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo;
import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService;
import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.util.ResponsePayload;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserCredentialWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.UserCredentialWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.UserWrapper;
import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
@ -162,7 +160,8 @@ public class UserManagementServiceImpl implements UserManagementService {
@GET @GET
@Path("/{username}") @Path("/{username}")
@Override @Override
public Response getUser(@PathParam("username") String username) { public Response getUser(@PathParam("username") String username,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
try { try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (userStoreManager.isExistingUser(username)) { if (userStoreManager.isExistingUser(username)) {
@ -175,10 +174,6 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("User by username: " + username + " was found."); log.debug("User by username: " + username + " was found.");
} }
if (user == null) {
return Response.status(Response.Status.NOT_FOUND).entity("User by username '" + username + "' " +
"doesn't exist").build();
}
return Response.status(Response.Status.OK).entity(user).build(); return Response.status(Response.Status.OK).entity(user).build();
} else { } else {
// Outputting debug message upon trying to remove non-existing user // Outputting debug message upon trying to remove non-existing user
@ -328,7 +323,8 @@ public class UserManagementServiceImpl implements UserManagementService {
@GET @GET
@Override @Override
public Response getUsers(@QueryParam("filter") String filter, @QueryParam("offset") int offset, public Response getUsers(@QueryParam("filter") String filter, @HeaderParam("If-Modified-Since") Date timestamp,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) { @QueryParam("limit") int limit) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting the list of users with all user-related information"); log.debug("Getting the list of users with all user-related information");
@ -359,9 +355,10 @@ public class UserManagementServiceImpl implements UserManagementService {
} }
@GET @GET
@Path("/usernames")
@Override @Override
public Response getUserNames(@QueryParam("filter") String filter, @QueryParam("offset") int offset, public Response getUserNames(@QueryParam("filter") String filter, @HeaderParam("If-Modified-Since") Date timestamp,
@QueryParam("limit") int limit) { @QueryParam("offset") int offset, @QueryParam("limit") int limit) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting the list of users with all user-related information using the filter : " + filter); log.debug("Getting the list of users with all user-related information using the filter : " + filter);
} }

@ -39,7 +39,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
@Override @Override
@GET @GET
public Response getDevicesByName(@QueryParam("name") String name, @QueryParam("tenant-domain") String tenantDomain) { public Response getDevicesByName(@QueryParam("name") String name,
@QueryParam("type") String type,
@QueryParam("tenant-domain") String tenantDomain,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
List<Device> devices; List<Device> devices;
try { try {
devices = DeviceMgtAPIUtils.getDeviceManagementService().getDevicesByName(name); devices = DeviceMgtAPIUtils.getDeviceManagementService().getDevicesByName(name);

@ -18,6 +18,7 @@
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin; package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin;
import io.swagger.annotations.ApiParam;
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.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
@ -25,12 +26,10 @@ import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.GroupManagementAdminService; import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.GroupManagementAdminService;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import javax.ws.rs.Consumes; import javax.ws.rs.*;
import javax.ws.rs.Path;
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.Date;
@Path("/groups") @Path("/groups")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -40,8 +39,11 @@ public class GroupManagementAdminServiceImpl implements GroupManagementAdminServ
private static final Log log = LogFactory.getLog(GroupManagementAdminServiceImpl.class); private static final Log log = LogFactory.getLog(GroupManagementAdminServiceImpl.class);
@Override @Override
public Response getGroupsOfUser(@QueryParam("username") String username, @QueryParam("offset") int offset, public Response getGroupsOfUser(
@QueryParam("limit") int limit) { @QueryParam("username") String username,
@HeaderParam("If-Modified-Since") Date timestamp,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
try { try {
PaginationResult result = PaginationResult result =
DeviceMgtAPIUtils.getGroupManagementProviderService().getGroups(username, offset, limit); DeviceMgtAPIUtils.getGroupManagementProviderService().getGroups(username, offset, limit);

@ -18,9 +18,9 @@
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin; package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserCredentialWrapper;
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.UserManagementAdminService; import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.UserManagementAdminService;
import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder; import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserCredentialWrapper;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;

@ -29,79 +29,79 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
@ApiModel(value = "Notification", description = "This is used to communicate Operation notifications to MDM.") @ApiModel(value = "Notification", description = "This is used to communicate Operation notifications to MDM.")
public class Notification { public class Notification {
public enum Status{ public enum Status {
NEW, CHECKED NEW, CHECKED
} }
public enum Type{ public enum Type {
ALERT, ALERT,
} }
@ApiModelProperty(name = "notificationId", value = "Defines the notification ID.", required = true ) @ApiModelProperty(name = "notificationId", value = "Defines the notification ID.", required = true)
private int notificationId; private int notificationId;
@ApiModelProperty(name = "deviceIdentifier", value = "Defines the device identification properties.", @ApiModelProperty(name = "deviceIdentifier", value = "Defines the device identification properties.",
required = true ) required = true)
private DeviceIdentifier deviceIdentifier; private DeviceIdentifier deviceIdentifier;
@ApiModelProperty(name = "description", value = "Provides the message you want to send to the user.", @ApiModelProperty(name = "description", value = "Provides the message you want to send to the user.",
required = true ) required = true)
private String description; private String description;
@ApiModelProperty(name = "operationId", value = "Provides the operationID.", required = true ) @ApiModelProperty(name = "operationId", value = "Provides the operationID.", required = true)
private int operationId; private int operationId;
@ApiModelProperty(name = "status", value = "Provides the status of the message." + @ApiModelProperty(name = "status", value = "Provides the status of the message." +
"The following values can be assigned for the status.\n" + "The following values can be assigned for the status.\n" +
"NEW: The message is in the unread state.\n" + "NEW: The message is in the unread state.\n" +
"CHECKED: The message is in the read state.", required = true ) "CHECKED: The message is in the read state.", required = true)
private Status status; private Status status;
public Status getStatus() { public Status getStatus() {
return status; return status;
} }
public void setStatus(String status) { public void setStatus(String status) {
this.status = Status.valueOf(status); this.status = Status.valueOf(status);
} }
public int getNotificationId() { public int getNotificationId() {
return notificationId; return notificationId;
} }
public void setNotificationId(int notificationId) { public void setNotificationId(int notificationId) {
this.notificationId = notificationId; this.notificationId = notificationId;
} }
public DeviceIdentifier getDeviceIdentifier() { public DeviceIdentifier getDeviceIdentifier() {
return deviceIdentifier; return deviceIdentifier;
} }
public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) { public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) {
this.deviceIdentifier = deviceIdentifier; this.deviceIdentifier = deviceIdentifier;
} }
public String getDescription() { public String getDescription() {
return description; return description;
} }
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
public int getOperationId() { public int getOperationId() {
return operationId; return operationId;
} }
public void setOperationId(int operationId) { public void setOperationId(int operationId) {
this.operationId = operationId; this.operationId = operationId;
} }
@Override @Override
public String toString() { public String toString() {
return "Notification{" + return "Notification{" +
"notificationId='" + notificationId + '\'' + "notificationId='" + notificationId + '\'' +
", deviceId=" + deviceIdentifier.getId() + ", deviceId=" + deviceIdentifier.getId() +
", deviceType=" + deviceIdentifier.getType() + ", deviceType=" + deviceIdentifier.getType() +
", status=" + status + ", status=" + status +
", description='" + description + '\'' + ", description='" + description + '\'' +
", operationId='" + operationId + '\'' + ", operationId='" + operationId + '\'' +
'}'; '}';
} }
} }

Loading…
Cancel
Save