swagger annotations added to APIs

revert-70aa11f8
inoshperera 9 years ago
parent 30f6fc53b5
commit 4623fa2269

@ -18,10 +18,8 @@
*/ */
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 org.wso2.carbon.apimgt.annotations.api.API;
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 javax.ws.rs.*; import javax.ws.rs.*;
@ -31,7 +29,10 @@ import javax.ws.rs.core.Response;
/** /**
* Activity related REST-API implementation. * Activity related REST-API implementation.
*/ */
@API(name = "Activities", version = "1.0.0", context = "/devicemgt_admin/activities", tags = {"devicemgt_admin"})
@Path("/activities") @Path("/activities")
@Api(value = "ActivityInfo", description = "Activity related information manipulation. For example operation details " +
"and responses from devices.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public interface ActivityInfoProviderService { public interface ActivityInfoProviderService {
@ -39,15 +40,19 @@ public interface ActivityInfoProviderService {
@GET @GET
@Path("/{id}") @Path("/{id}")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Retrieving the operation details.", value = "Retrieving the operation details.",
notes = "This will return the operation details including the responses from the devices.") notes = "This will return the operation details including the responses from the devices.")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Activity details provided successfully."), @ApiResponses(value = {
@ApiResponse(code = 500, message = "Error occurred while fetching the activity for the supplied id.")}) @ApiResponse(code = 200, message = "Activity details provided successfully."),
@ApiResponse(code = 500, message = "Error occurred while fetching the activity for the supplied id.")
})
@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(@ApiParam(name = "id", value = "Activity id of the operation/activity to be retrieved", Response getActivity(
required = true) @PathParam("id") String id); @ApiParam(name = "id", value = "Activity id of the operation/activity to be retrieved.",
required = true)
@PathParam("id") String id);
} }

@ -0,0 +1,93 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission;
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.core.MediaType;
import javax.ws.rs.core.Response;
/**
* General Tenant Configuration REST-API.
*/
@API(name = "Configuration", version = "1.0.0", context = "/devicemgt_admin/configuration", tags = {"devicemgt_admin"})
@Path("/configuration")
@Api(value = "Configuration", description = "General Tenant Configuration management capabilities are exposed " +
"through this API")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
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
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Getting General Platform Configurations.",
notes = "Get the general platform level configuration details using this REST API.",
response = PlatformConfiguration.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Tenant configuration saved successfully."),
@ApiResponse(code = 500, message = "Error occurred while retrieving the tenant configuration.")
})
@Permission(scope = "configuration-view",
permissions = {"/permission/admin/device-mgt/admin/platform-configs/view"})
Response getConfiguration();
@PUT
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Updating General Platform Configurations.",
notes = "Update the notification frequency using this REST API.")
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Tenant configuration updated successfully."),
@ApiResponse(code = 500, message = "Error occurred while updating the tenant configuration.")
})
@Permission(scope = "configuration-modify",
permissions = {"/permission/admin/device-mgt/admin/platform-configs/modify"})
Response updateConfiguration(@ApiParam(name = "configuration", value = "The required properties to "
+ "update the platform configurations.",
required = true) PlatformConfiguration configuration);
}

@ -18,10 +18,8 @@
*/ */
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 org.wso2.carbon.apimgt.annotations.api.API;
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.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.EnrolmentInfo;
@ -38,15 +36,18 @@ import java.util.Date;
import java.util.List; import java.util.List;
/** /**
* Device related REST-API implementation. 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"})
@Path("/devices") @Path("/devices")
@Api(value = "Device", description = "Device 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 device list.",
@ -72,6 +73,7 @@ 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 corresponding to a device type.", value = "Get the device list corresponding to a device type.",
@ -117,6 +119,7 @@ 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 of a user.", value = "Get the device list of a user.",
@ -141,6 +144,7 @@ public interface DeviceManagementService {
@GET @GET
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Returns device list in a role.", value = "Returns device list in a role.",
@ -165,6 +169,7 @@ public interface DeviceManagementService {
@GET @GET
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Returns device list of an ownership scheme.", value = "Returns device list of an ownership scheme.",
@ -181,8 +186,7 @@ public interface DeviceManagementService {
@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 getDevicesByOwnership( Response getDevicesByOwnership(
@ApiParam(name = "ownership", value = "Ownership of the devices to be fetched registered under.", @ApiParam(name = "ownership", value = "Ownership of the devices to be fetched registered under.",
required = true) required = true) EnrolmentInfo.OwnerShip ownership,
@QueryParam("ownership") EnrolmentInfo.OwnerShip ownership,
@ApiParam(name = "offset", value = "Starting pagination index.",required = true) @ApiParam(name = "offset", value = "Starting pagination index.",required = true)
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many device details are required from the starting pagination " + @ApiParam(name = "limit", value = "How many device details are required from the starting pagination " +
@ -191,6 +195,7 @@ public interface DeviceManagementService {
@GET @GET
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Returns device list", value = "Returns device list",
@ -206,7 +211,7 @@ public interface DeviceManagementService {
@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 getDevicesByEnrollmentStatus( Response getDevicesByEnrollmentStatus(
@ApiParam(name = "status", value = "Enrollment status of devices to be fetched.", required = true) @ApiParam(name = "status", value = "Enrollment status of devices to be fetched.", required = true)
@QueryParam("status") EnrolmentInfo.Status status, EnrolmentInfo.Status status,
@ApiParam(name = "offset", value = "Starting pagination index.",required = true) @ApiParam(name = "offset", value = "Starting pagination index.",required = true)
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many device details are required from the starting pagination " + @ApiParam(name = "limit", value = "How many device details are required from the starting pagination " +
@ -222,6 +227,7 @@ public interface DeviceManagementService {
@GET @GET
@Path("/{type}/{id}/location") @Path("/{type}/{id}/location")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Get the device location of a given device and a device type.", value = "Get the device location of a given device and a device type.",
@ -238,14 +244,14 @@ public interface DeviceManagementService {
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 = "type", value = "The device identifier of the device.", required = true) @ApiParam(name = "id", value = "The device identifier of the device.", required = true)
@PathParam("id") String id); @PathParam("id") String id);
@GET @GET
@Path("/{type}/{id}/features") @Path("/{type}/{id}/features")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Get Feature Details of a Device", value = "Get Feature Details of a Device",
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. " +
@ -256,13 +262,14 @@ public interface DeviceManagementService {
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched the features.", @ApiResponse(code = 200, message = "Successfully fetched the features.",
response = org.wso2.carbon.device.mgt.common.Feature.class, responseContainer = "List"), response = org.wso2.carbon.device.mgt.common.Feature.class, responseContainer = "List"),
@ApiResponse(code = 500, message = "Error occurred while retrieving the list of features.") }) @ApiResponse(code = 500, message = "Error occurred while retrieving the list of features.")
})
@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 = "type", value = "The device identifier of the device.", required = true) @ApiParam(name = "id", value = "The device identifier of the device.", required = true)
@PathParam("id") String id); @PathParam("id") String id);
@POST @POST
@ -288,8 +295,8 @@ public interface DeviceManagementService {
@GET @GET
@Path("/{type}/{id}/applications") @Path("/{type}/{id}/applications")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, 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",
@ -299,22 +306,24 @@ public interface DeviceManagementService {
@ApiResponse(code = 200, message = "List of installed application details of a device.", @ApiResponse(code = 200, message = "List of installed application details of a device.",
response = Application.class, responseContainer = "List"), response = Application.class, responseContainer = "List"),
@ApiResponse(code = 404, message = "No installed applications found on the device searched."), @ApiResponse(code = 404, message = "No installed applications found on the device searched."),
@ApiResponse(code = 500, message = "Error occurred while fetching the apps of the device.")}) @ApiResponse(code = 500, message = "Error occurred while fetching the apps 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 = "type", value = "The device identifier of the device.", required = true) @ApiParam(name = "id", value = "The device identifier of the device.", required = true)
@PathParam("id") String id); @PathParam("id") String id);
@GET @GET
@Path("/{type}/{id}/operations") @Path("/{type}/{id}/operations")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, 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" +
@ -326,10 +335,12 @@ public interface DeviceManagementService {
response = org.wso2.carbon.device.mgt.common.operation.mgt.Operation.class, response = org.wso2.carbon.device.mgt.common.operation.mgt.Operation.class,
responseContainer = "List"), responseContainer = "List"),
@ApiResponse(code = 500, message = "Error occurred while fetching the operations for the " + @ApiResponse(code = 500, message = "Error occurred while fetching the operations for the " +
"device.")}) "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(name = "offset", value = "Starting pagination index.",required = true)
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@ -338,7 +349,7 @@ public interface DeviceManagementService {
@QueryParam("limit") int limit, @QueryParam("limit") int limit,
@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 = "type", value = "The device identifier of the device.", required = true) @ApiParam(name = "id", value = "The device identifier of the device.", required = true)
@PathParam("id") String id); @PathParam("id") String id);
} }

@ -1,97 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.wso2.carbon.apimgt.annotations.api.Permission;
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.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/device-types")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface DeviceTypeManagementService {
@GET
@ApiOperation(
httpMethod = "GET",
value = "Getting Details of the Devices Supported via WSO2 EMM",
notes = "You are able to register Android, iOS and Windows devices with WSO2 EMM. This API will "
+ "retrieve the device type details that can register with the EMM",
response = DeviceType.class,
responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "List of devices based on the type"),
@ApiResponse(code = 500, message = "Error occurred while fetching the list of device types") })
@Permission(scope = "device-list", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getTypes();
@POST
@Path("/{type}/configuration")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
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(@PathParam("type") String type, PlatformConfiguration config);
@GET
@Path("/{type}/configuration")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
httpMethod = "GET",
value = "Getting General Platform Configurations",
notes = "Get the general platform level configuration details using this REST API",
response = PlatformConfiguration.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 500, message = "Error occurred while retrieving the tenant configuration")
})
@Permission(scope = "configuration-view", permissions = {"/permission/admin/device-mgt/admin/platform-configs/view"})
Response getConfiguration(@PathParam("type") String type);
@PUT
@Path("/{type}/configuration")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
httpMethod = "PUT",
value = "Updating General Platform Configurations",
notes = "Update the notification frequency using this REST API")
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Tenant configuration updated successfully"),
@ApiResponse(code = 500, message = "Error occurred while updating the tenant configuration")
})
@Permission(scope = "configuration-modify", permissions = {"/permission/admin/device-mgt/admin/platform-configs/modify"})
Response updateConfiguration(@PathParam("type") String type, PlatformConfiguration config);
}

@ -18,9 +18,8 @@
*/ */
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.ApiResponse; import org.wso2.carbon.apimgt.annotations.api.API;
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.common.notification.mgt.Notification; import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
@ -28,6 +27,12 @@ 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;
/**
* Notifications related REST-API.
*/
@API(name = "Device Notification", version = "1.0.0", context = "/devicemgt_admin/notifications",
tags = {"devicemgt_admin"})
@Api(value = "DeviceNotification", 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)
@ -35,75 +40,96 @@ public interface NotificationManagementService {
@GET @GET
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting all Device Notification Details", value = "Getting all device notification details.",
notes = "Get the details of all notifications that were pushed to the device in WSO2 EMM using " notes = "Get the details of all notifications that were pushed to the device in WSO2 EMM using "
+ "this REST API", + "this REST API",
response = Notification.class, response = Notification.class,
responseContainer = "List") responseContainer = "List")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "List of Notifications", response = Notification.class, @ApiResponse(code = 200, message = "Successfully fetched the list of notifications",
responseContainer = "List"), response = Notification.class, responseContainer = "List"),
@ApiResponse(code = 500, message = "Error occurred while retrieving the notification list") @ApiResponse(code = 404, message = "No notification is available to be retrieved."),
@ApiResponse(code = 500, message = "Error occurred while retrieving 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(@QueryParam("offset") int offset, @QueryParam("limit") int limit); })
Response getNotifications(
@ApiParam(name = "offset", value = "Starting pagination index.",required = true)
@QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How notification device details are required from the starting " +
"pagination index.", required = true)
@QueryParam("limit") int limit);
@GET @GET
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting the Device Notifications Filtered by the Status", 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 " notes = "Get the details of all the unread notifications or the details of all the read "
+ "notifications using this REST API", + "notifications using this REST API.",
response = Notification.class, response = Notification.class,
responseContainer = "List") responseContainer = "List")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "List of Notifications", response = Notification.class, @ApiResponse(code = 200, message = "Successfully fetched the list of notifications.",
responseContainer = "List"), response = Notification.class, responseContainer = "List"),
@ApiResponse(code = 500, message = "Error occurred while retrieving the notification 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(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 getNotificationsByStatus(@QueryParam("status") Notification.Status status, })
@QueryParam("offset") int offset, @QueryParam("limit") int limit); 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")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
value = "Updating the Device Notification Status", value = "Updating the device notification status",
notes = "When a user has read the the device notification 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(value = {
@ApiResponse(code = 201, message = "Notification status updated successfully"), @ApiResponse(code = 201, message = "Notification status updated successfully."),
@ApiResponse(code = 500, message = "Error occurred while updating notification status") @ApiResponse(code = 500, message = "Error occurred while updating notification status.")
}) })
@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(@PathParam("id") int id, Notification.Status status); Response updateNotificationStatus(
@ApiParam(name = "id", value = "The device identifier of the device.", required = true)
@PathParam("id") int id,
@ApiParam(name = "status", value = "Status of the notification.",required = true)
Notification.Status status);
@POST @POST
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Sending a Device Notification", value = "Sending a device notification.",
notes = "Notify users on device operation failures and other information using this REST API") notes = "Notify users on device operation failures and other information using this REST API.")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 201, message = "NNotification has added successfully"), @ApiResponse(code = 201, message = "Notification has added successfully."),
@ApiResponse(code = 500, message = "Error occurred while updating notification status") @ApiResponse(code = 500, message = "Error occurred while updating notification status.")
}) })
@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(Notification notification); Response addNotification(@ApiParam(name = "notification", value = "Notification details to be added.",required =
true) Notification notification);
} }

@ -19,6 +19,7 @@
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.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ApiResponses;
import org.wso2.carbon.apimgt.annotations.api.Permission; import org.wso2.carbon.apimgt.annotations.api.Permission;
@ -29,6 +30,10 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
/**
* Policy related REST-API. This can be used to manipulated policies and associate them with devices, users, roles,
* groups.
*/
@Path("/policies") @Path("/policies")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ -39,44 +44,59 @@ 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 = "Adding a policy.",
notes = "Add a policy using this REST API command. When adding a policy you will have the option of " + notes = "Add a policy using this REST API command. Using the REST API command given below " +
"saving the policy or saving and publishing the policy. Using the REST API command given below " + "you are able to save a created Policy and this policy will be in the inactive state.")
"you are able to save a created Policy and this policy will be in the inactive state") @ApiResponses(value = {
@ApiResponses(value = {@ApiResponse(code = 201, message = "Created the policy."), @ApiResponse(code = 201, message = "Created the policy."),
@ApiResponse(code = 500, message = "Policy Management related error occurred when " + @ApiResponse(code = 401, message = "Current user is not authorized to add policies."),
"adding the policy")}) @ApiResponse(code = 500, message = "Policy Management related error occurred when adding the 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(PolicyWrapper policy); Response addPolicy(@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 = "Getting details of policies.",
responseContainer = "List", responseContainer = "List",
notes = "Retrieve the details of all the policies that you have created in WSO2 EMM.", notes = "Retrieve the details of all the policies that you have created in EMM.",
response = org.wso2.carbon.policy.mgt.common.Policy.class) response = org.wso2.carbon.policy.mgt.common.Policy.class)
@ApiResponses(value = {@ApiResponse(code = 200, message = "Fetched all policies.", @ApiResponses(value = {
@ApiResponse(code = 200, message = "Fetched all policies.",
response = org.wso2.carbon.policy.mgt.common.Policy.class, responseContainer = "List"), response = org.wso2.carbon.policy.mgt.common.Policy.class, responseContainer = "List"),
@ApiResponse(code = 404, message = "No policies found."),
@ApiResponse(code = 500, message = "Policy Management related error occurred when " + @ApiResponse(code = 500, message = "Policy Management related error occurred when " +
"fetching the policies.")}) "fetching the 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(@QueryParam("offset") int offset, @QueryParam("limit") int limit); Response getPolicies(
@ApiParam(name = "offset", value = "Starting pagination index.",required = true)
@QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many policy details are required from the starting pagination " +
"index.", required = true)
@QueryParam("limit") int limit);
@GET @GET
@Path("/{id}") @Path("/{id}")
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting Details of a Policy.", value = "Getting details of a policy.",
notes = "Retrieve the details of a selected policy in WSO2 EMM.", notes = "Retrieve the details of a given policy in EMM.",
response = org.wso2.carbon.policy.mgt.common.Policy.class) response = org.wso2.carbon.policy.mgt.common.Policy.class)
@ApiResponses(value = {@ApiResponse(code = 200, message = "Fetched policy details."), @ApiResponses(value = {
@ApiResponse(code = 500, message = "Policy Management related error occurred when " + @ApiResponse(code = 200, message = "Fetched policy details.",
"fetching the policies.")}) response = org.wso2.carbon.policy.mgt.common.Policy.class),
@ApiResponse(code = 404, message = "Policy not found."),
@ApiResponse(code = 500, message = "Policy management related error occurred when " +
"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(@PathParam("id") int id); Response getPolicy(
@ApiParam(name = "id", value = "The device identifier of the device.", required = true)
@PathParam("id") int id);
@PUT @PUT
@Path("/{id}") @Path("/{id}")
@ -84,27 +104,35 @@ 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 = "Updating 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, you can do so by updating the policy using " +
"this API") "this API.")
@ApiResponses(value = {@ApiResponse(code = 201, message = "Policy has been updated successfully."), @ApiResponses(value = {
@ApiResponse(code = 500, message = "Policy Management related exception in policy " + @ApiResponse(code = 201, message = "Policy has been updated successfully."),
"update")}) @ApiResponse(code = 500, message = "Policy management related exception in policy update.")
})
@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(@PathParam("id") int id, PolicyWrapper policyWrapper); Response updatePolicy(
@ApiParam(name = "id", value = "The device identifier of the device.", required = true)
@PathParam("id") int id,
@ApiParam(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 = "Removing 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 = {@ApiResponse(code = 200, message = "Policies have been successfully deleted."), @ApiResponses(value = {
@ApiResponse(code = 400, message = "Policy does not exist."), @ApiResponse(code = 200, message = "Policies have been successfully deleted."),
@ApiResponse(code = 500, message = "Error in deleting policies.")}) @ApiResponse(code = 404, message = "Policy does not exist."),
@ApiResponse(code = 500, message = "Error in deleting 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(List<Integer> policyIds); Response removePolicies(@ApiParam(name = "policyIds", value = "Policy ID list to be deleted.",
required = true) List<Integer> policyIds);
@POST @POST
@Path("/activate-policy") @Path("/activate-policy")
@ -112,15 +140,19 @@ public interface PolicyManagementService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
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 = {@ApiResponse(code = 200, message = "Policies have been successfully activated."), @ApiResponses(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(List<Integer> policyIds); Response activatePolicies(
@ApiParam(name = "policyIds", value = "Policy ID list to be activated.",
required = true) List<Integer> policyIds);
@POST @POST
@Path("/deactivate-policy") @Path("/deactivate-policy")
@ -128,15 +160,19 @@ public interface PolicyManagementService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
value = "Deactivating Policies.", value = "Deactivating policies.",
notes = "Using the REST API command you are able to unpublish a policy in order to bring a policy that " + notes = "Using the REST API command you are able to unpublish a policy in order to bring a policy that " +
"is in the active state to the inactive state.") "is in the active state to the inactive state.")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Policies have been successfully deactivated."), @ApiResponses(value = {
@ApiResponse(code = 500, message = "Error in deactivating policies.")}) @ApiResponse(code = 200, message = "Policies have been successfully deactivated."),
@ApiResponse(code = 500, message = "Error in deactivating 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 deactivatePolicies(List<Integer> policyIds); Response deactivatePolicies(
@ApiParam(name = "policyIds", value = "Policy ID list to be deactivated.",
required = true) List<Integer> policyIds);
@GET @GET
@ApiOperation( @ApiOperation(
@ -147,9 +183,15 @@ public interface PolicyManagementService {
"filters the policies based on the Platform (device type), filters based on the device ownership" + "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.", " 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) response = org.wso2.carbon.policy.mgt.common.Policy.class)
@ApiResponses(value = {@ApiResponse(code = 200, message = "Fetched current policy."), @ApiResponses(value = {
@ApiResponse(code = 500, message = "Error occurred while getting the current policy.")}) @ApiResponse(code = 200, message = "Fetched current policy."),
Response getEffectivePolicyOfDevice(@QueryParam("device-type") String type, @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); @QueryParam("device-id") String deviceId);
} }

@ -18,9 +18,8 @@
*/ */
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.ApiResponse; import org.wso2.carbon.apimgt.annotations.api.API;
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.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;
@ -30,7 +29,9 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
@API(name = "Role", version = "1.0.0", context = "/devicemgt_admin/roles", tags = {"devicemgt_admin"})
@Path("/roles") @Path("/roles")
@Api(value = "Role", description = "Role 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 RoleManagementService { public interface RoleManagementService {
@ -40,34 +41,54 @@ public interface RoleManagementService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting the List of Roles.", value = "Getting the list of roles.",
responseContainer = "List", responseContainer = "List",
notes = "If you wish to get the details of all the roles in WSO2 EMM, you can do so using this REST API.", 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.",
response = String.class) response = String.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "List of available roles"), @ApiResponses(value = {
@ApiResponse(code = 500, message = "Error occurred while fetching the role list.") }) @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(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(@QueryParam("offset") int offset, @QueryParam("limit") int limit); Response getRoles(
@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 @GET
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting the List of Roles in a User Store.", value = "Getting the list of roles in a user store.",
responseContainer = "List", responseContainer = "List",
notes = "If you wish to get the details of all the roles in WSO2 EMM, you can do so using this REST API.", 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) response = String.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "List of available roles"), @ApiResponses(value = {
@ApiResponse(code = 500, message = "Error occurred while fetching the role list.") }) @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(scope = "roles-view", permissions = {
"/permission/admin/device-mgt/admin/users/add", "/permission/admin/device-mgt/admin/users/add",
"/permission/admin/device-mgt/admin/roles/list"}) "/permission/admin/device-mgt/admin/roles/list"})
Response getRoles(@QueryParam("user-store") String userStoreName, @QueryParam("offset") int offset, 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); @QueryParam("limit") int limit);
@GET @GET
@ -75,20 +96,29 @@ public interface RoleManagementService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Searching for Roles via the Role Name.", value = "Searching for roles via the role name.",
responseContainer = "List", responseContainer = "List",
notes = "You will have many roles created within WSO2 EMM. As the admin you will need to confirm if a " + 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 " + "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" + "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.", " have the name in the exact order of the characters you provided.",
response = String.class) response = String.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "List of matching roles"), @ApiResponses(value = {
@ApiResponse(code = 500, message = "Error occurred while fetching the matching role list" + @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(scope = "roles-view", permissions = {
"/permission/admin/device-mgt/admin/users/add", "/permission/admin/device-mgt/admin/users/add",
"/permission/admin/device-mgt/admin/roles/list"}) "/permission/admin/device-mgt/admin/roles/list"})
Response searchRoles(@QueryParam("filter") String filter, @QueryParam("offset") int offset, Response searchRoles(
@ApiParam(name = "filter", value = "Role name or a part of it to search.",required = true)
@QueryParam("filter") String filter,
@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); @QueryParam("limit") int limit);
@GET @GET
@ -97,17 +127,21 @@ public interface RoleManagementService {
consumes = MediaType.APPLICATION_JSON, 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.",
notes = "In an organization an individual is associated a with set of responsibilities based on their " + notes = "In an organization an individual is associated a with set of responsibilities based on their " +
"role. In WSO2 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 = { @ApiResponse(code = 200, message = "Permission details of a role"), @ApiResponses(value = {
@ApiResponse(code = 500, message = "Error occurred while fetching the permission " + @ApiResponse(code = 200, message = "Permission details of a role", response = UIPermissionNode.class),
"details of a role.") }) @ApiResponse(code = 404, message = "No permissions found for the role."),
@ApiResponse(code = 500, message = "Error occurred while fetching the permission details of a 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(@PathParam("roleName") String roleName); Response getPermissionsOfRole(
@ApiParam(name = "roleName", value = "Name of the role.",required = true)
@PathParam("roleName") String roleName);
@GET @GET
@Path("/{roleName}") @Path("/{roleName}")
@ -115,25 +149,34 @@ public interface RoleManagementService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting Details of a Role.", value = "Getting details of a role.",
notes = "If you wish to get the details of a role in WSO2 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 = { @ApiResponse(code = 200, message = "Details of a role."), @ApiResponses(value = {
@ApiResponse(code = 500, message = "Error occurred while retrieving the user role.") }) @ApiResponse(code = 200, message = "Successfully fetched the role details.", response = RoleWrapper.class),
@ApiResponse(code = 404, message = "No role details found for the provided role name."),
@ApiResponse(code = 500, message = "Error occurred while retrieving the role details.")
})
@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(@PathParam("roleName") String roleName); Response getRole(
@ApiParam(name = "roleName", value = "Name of the role.",required = true)
@PathParam("roleName") String roleName);
@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 = "Adding a role.",
notes = "You are able to add a new role to WSO2 EMM using the REST API.") notes = "You are able to add a new role to EMM using the REST API.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Added the role."), @ApiResponses(value = {
@ApiResponse(code = 500, message = "Error occurred while adding the user role.") }) @ApiResponse(code = 200, message = "Added the role."),
@ApiResponse(code = 500, message = "Error occurred while adding the user 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(RoleWrapper role); Response addRole(
@ApiParam(name = "role", value = "Details about the role to be added.",required = true)
RoleWrapper role);
@PUT @PUT
@Path("/{roleName}") @Path("/{roleName}")
@ -141,14 +184,19 @@ 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 = "Updating 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 = { @ApiResponse(code = 200, message = "Updated the role."), @ApiResponses(value = {
@ApiResponse(code = 500, message = "Error occurred while updating the user role details" + @ApiResponse(code = 200, message = "Updated the role."),
".") }) @ApiResponse(code = 500, message = "Error occurred while updating the user role details.")
})
@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(@PathParam("roleName") String roleName, RoleWrapper role); Response updateRole(
@ApiParam(name = "roleName", value = "Name of the role.",required = true)
@PathParam("roleName") String roleName,
@ApiParam(name = "role", value = "Details about the role to be added.",required = true)
RoleWrapper role);
@DELETE @DELETE
@Path("/{roleName}") @Path("/{roleName}")
@ -156,14 +204,17 @@ public interface RoleManagementService {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE", httpMethod = "DELETE",
value = "Deleting a Role.", value = "Deleting 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 WSO2 EMM.") "will need to remove the role details from EMM.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Deleted the role."), @ApiResponses(value = {
@ApiResponse(code = 500, message = "Error occurred while deleting the user role details" + @ApiResponse(code = 200, message = "Deleted the role."),
".") }) @ApiResponse(code = 500, message = "Error occurred while deleting the user role details.")
})
@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(@PathParam("roleName") String roleName); Response deleteRole(
@ApiParam(name = "roleName", value = "Name of the role to de deleted.",required = true)
@PathParam("roleName") String roleName);
@POST @POST
@Path("/{roleName}/users") @Path("/{roleName}/users")
@ -171,16 +222,22 @@ public interface RoleManagementService {
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 = "Adding 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 = { @ApiResponse(code = 200, message = "Added Users to a Role."), @ApiResponses(value = {
@ApiResponse(code = 500, message = "Error occurred while saving the users of the role.") }) @ApiResponse(code = 200, message = "Added Users to a Role."),
@ApiResponse(code = 500, message = "Error occurred while saving the users 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(@PathParam("roleName") String roleName, List<String> users); Response updateUsersOfRole(
@ApiParam(name = "roleName", value = "Name of the role.",required = true)
@PathParam("roleName") String roleName,
@ApiParam(name = "users", value = "List of usernames to be added.",required = true)
List<String> users);
} }

@ -18,9 +18,8 @@
*/ */
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.ApiResponse; import org.wso2.carbon.apimgt.annotations.api.API;
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.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;
@ -29,7 +28,10 @@ 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;
@API(name = "UserManagement", 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.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public interface UserManagementService { public interface UserManagementService {
@ -39,121 +41,153 @@ 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 via the REST API", value = "Adding a user.",
notes = "Adds a new user to WSO2 EMM using this REST API") notes = "Adds a new user to EMM using this REST API.")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 201, message = "Created"), @ApiResponse(code = 201, message = "Added the user successfully."),
@ApiResponse(code = 500, message = "Exception in trying to add user by username: 'username'") @ApiResponse(code = 500, message = "Exception in trying to add the 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(UserWrapper user); Response addUser(
@ApiParam(name = "user", value = "User related details.",required = true) UserWrapper user);
@GET @GET
@Path("/{username}") @Path("/{username}")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting Details of a User", value = "Getting details of a user.",
notes = "If you wish to get the details of a specific user that is registered with WSO2 EMM," notes = "If you wish to get the details of a specific user that is registered with EMM,"
+ " 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(code = 201, message = "User information was retrieved successfully.",
@ApiResponse(code = 400, message = "User by username: 'username' does not exist"), response = UserWrapper.class),
@ApiResponse(code = 500, message = "Exception in trying to retrieve user by username: 'username'") @ApiResponse(code = 404, message = "User by the provided username does not exist."),
@ApiResponse(code = 500, message = "Exception in trying to retrieve user by username.")
}) })
@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(@PathParam("username") String username); Response getUser(
@ApiParam(name = "username", value = "Username of the user to be fetched.",required = true)
@PathParam("username") String username);
@PUT @PUT
@Path("/{username}") @Path("/{username}")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
value = "Updating Details of a User", value = "Updating 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 by username: 'username' was successfully updated"), @ApiResponse(code = 200, message = "User was successfully updated"),
@ApiResponse(code = 409, message = "User by username: 'username' doesn't exists. Therefore, " @ApiResponse(code = 409, message = "User by the provided username doesn't exists. Therefore, "
+ "request made to update user was refused"), + "request made to update user was refused."),
@ApiResponse(code = 500, message = "Exception in trying to update user by username: 'username'") @ApiResponse(code = 500, message = "Exception in trying to update user by username: 'username'")
}) })
@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(@PathParam("username") String username, UserWrapper user); Response updateUser(
@ApiParam(name = "username", value = "Username of the user to be updated.",required = true)
@PathParam("username") String username,
@ApiParam(name = "user", value = "User related details.",required = true)
UserWrapper user);
@DELETE @DELETE
@Path("/{username}") @Path("/{username}")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = 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 WSO2 EMM. In such situations you can use this REST API " + " user details from EMM. In such situations you can use this REST API to remove a user.")
+ "to remove a user")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "User by username: 'username' was successfully removed"), @ApiResponse(code = 200, message = "User was successfully removed."),
@ApiResponse(code = 400, message = "User by username: 'username' does not exist for removal"), @ApiResponse(code = 404, message = "User does not exist for removal."),
@ApiResponse(code = 500, message = "Exception in trying to remove user by username: 'username'") @ApiResponse(code = 500, message = "Exception in trying to remove 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(@PathParam("username") String username); Response removeUser(
@ApiParam(name = "username", value = "Username of the user to be deleted.",required = true)
@PathParam("username") String username);
@POST @POST
@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 = "Getting the role details of a user.",
notes = "A user can be assigned to one or more role in WSO2 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 user : 'username'"), @ApiResponse(code = 200, message = "User roles obtained for the provided user.", response = String.class,
@ApiResponse(code = 400, message = "User by username: 'username' does not exist for role retrieval"), responseContainer = "List"),
@ApiResponse(code = 500, message = "Exception in trying to retrieve roles for user by username: 'username'") @ApiResponse(code = 404, message = "User does not exist for role retrieval."),
@ApiResponse(code = 500, message = "Exception in trying to retrieve roles for the provided 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(@PathParam("username") String username); Response getRolesOfUser(
@ApiParam(name = "username", value = "Username of the user.",required = true)
@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 = "Getting details of users",
notes = "If you wish to get the details of all the user registered with WSO2 EMM, you can do so " notes = "If you wish to get the details of all the user 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"), @ApiResponse(code = 200, message = "All users were successfully retrieved.", response = UserWrapper.class,
@ApiResponse(code = 500, message = "Error occurred while retrieving the list of users") responseContainer = "List"),
@ApiResponse(code = 404, message = "No users found."),
@ApiResponse(code = 500, message = "Error occurred while retrieving the list of users.")
}) })
@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(@QueryParam("filter") String filter, @QueryParam("offset") int offset, Response getUsers(
@ApiParam(name = "filter", value = "Username of the user details to be fetched.",required = true)
@QueryParam("filter") String filter,
@ApiParam(name = "offset", value = "Starting pagination index.",required = true)
@QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many user details are required from the starting pagination " +
"index.", required = true)
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
@GET @GET
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Searching for a User Name", value = "Searching for a username.",
notes = "You will have 100+ users registered with WSO2 EMM. Therefore 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. "
+ "You will be given a list of users having the user name with the exact order of the " + "You will be given a list of users having the user name with the exact order of the "
+ "characters you provided", + "characters you provided.",
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. Obtained" @ApiResponse(code = 200, message = "All users by username were successfully retrieved.",
+ " user count: 'count'"), response = String.class, responseContainer = "List"),
@ApiResponse(code = 500, message = "Error occurred while retrieving the list of users") @ApiResponse(code = 404, message = "No users found."),
@ApiResponse(code = 500, message = "Error occurred while retrieving the list of users.")
}) })
@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(@QueryParam("filter") String filter, @QueryParam("offset") int offset, Response getUserNames(
@ApiParam(name = "filter", value = "Username/part of the user name to search.",required = true)
@QueryParam("filter") String filter,
@ApiParam(name = "offset", value = "Starting pagination index.",required = true)
@QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many user details are required from the starting pagination " +
"index.", required = true)
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
@PUT @PUT
@ -162,17 +196,19 @@ public interface UserManagementService {
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 = "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 = "UserImpl password by username: 'Username' was " @ApiResponse(code = 201, message = "User password was successfully changed."),
+ "successfully changed"), @ApiResponse(code = 400, message = "Old password does not match."),
@ApiResponse(code = 400, message = "Old password does not match"), @ApiResponse(code = 500, message = "Could not change the password of the user. The Character encoding is" +
@ApiResponse(code = 400, message = "Could not change the password of the user: 'Username'. The" " not supported.")
+ " Character Encoding is not supported"),
@ApiResponse(code = 500, message = "Internal Server Error")
}) })
@Permission(scope = "user-modify", permissions = {"/permission/admin/login"}) @Permission(scope = "user-modify", permissions = {"/permission/admin/login"})
Response resetPassword(@PathParam("username") String username, UserCredentialWrapper credentials); Response resetPassword(
@ApiParam(name = "username", value = "Username of the user.",required = true)
@PathParam("username") String username,
@ApiParam(name = "credentials", value = "Credential.",required = true)
UserCredentialWrapper credentials);
} }

@ -18,6 +18,8 @@
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.api.admin; package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationWrapper;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@ -27,17 +29,44 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@API(name = "Application", version = "1.0.0", context = "/devicemgt_admin/applications", tags = {"devicemgt_admin"})
@Path("/applications") @Path("/applications")
@Api(value = "Application", description = "Application related operations are exposed through this API.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public interface ApplicationManagementAdminService { public interface ApplicationManagementAdminService {
@POST @POST
@Path("/install-application") @Path("/install-application")
Response installApplication(ApplicationWrapper applicationWrapper); @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Application installation API.(Internal API)",
notes = "This is an internal API used for application installation on a device.")
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Application wil be installed on the device."),
@ApiResponse(code = 500, message = "Error while adding the application install operation.")
})
Response installApplication(
@ApiParam(name = "applicationWrapper", value = "Application details of the application to be installed.",
required = true) ApplicationWrapper applicationWrapper);
@POST @POST
@Path("/uninstall-application") @Path("/uninstall-application")
Response uninstallApplication(ApplicationWrapper applicationWrapper); @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Application uninstallation API.(Internal API)",
notes = "This is an internal API used for application uninstallation on a device.")
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Application wil be uninstalled on the device."),
@ApiResponse(code = 500, message = "Error while adding the application uninstall operation.")
})
Response uninstallApplication(
@ApiParam(name = "applicationWrapper", value = "Application details of the application to be uninstalled.",
required = true) ApplicationWrapper applicationWrapper);
} }

@ -18,18 +18,41 @@
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.api.admin; package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
import javax.ws.rs.Consumes; import io.swagger.annotations.*;
import javax.ws.rs.Path; import org.wso2.carbon.apimgt.annotations.api.API;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; 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;
@API(name = "DeviceManagementAdmin", version = "1.0.0", context = "/devicemgt_admin/applications",
tags = {"devicemgt_admin"})
@Path("/devices") @Path("/devices")
@Api(value = "DeviceManagementAdmin", description = "Device management admin related operations are exposed through " +
"this API.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public interface DeviceManagementAdminService { public interface DeviceManagementAdminService {
Response getDevicesByName(@QueryParam("name") String name, @QueryParam("tenant-domain") String tenantDomain); @GET
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Get devices by the name.",
notes = "Get devices the name of device and tenant.",
response = org.wso2.carbon.device.mgt.common.Device.class,
responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched device details.",
response = org.wso2.carbon.device.mgt.common.Device.class, responseContainer = "List"),
@ApiResponse(code = 404, message = "No matching device found in the provided tenant."),
@ApiResponse(code = 500, message = "Error while fetching device information.")
})
Response getDevicesByName(
@ApiParam(name = "name", value = "Name of the device.",required = true)
@QueryParam("name") String name,
@ApiParam(name = "tenant-domain", value = "Name of the tenant.",required = true)
@QueryParam("tenant-domain") String tenantDomain);
} }

@ -18,6 +18,10 @@
*/ */
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.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 javax.ws.rs.*; import javax.ws.rs.*;
@ -30,8 +34,28 @@ import javax.ws.rs.core.Response;
public interface GroupManagementAdminService { public interface GroupManagementAdminService {
@GET @GET
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Get groups by the name.",
notes = "Get devices the name of device and tenant.",
response = org.wso2.carbon.device.mgt.common.Device.class,
responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully fetched group details.",
response = org.wso2.carbon.device.mgt.common.Device.class, responseContainer = "List"),
@ApiResponse(code = 404, message = "Device not found."),
@ApiResponse(code = 500, message = "Error while fetching group information.")
})
@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(@QueryParam("username") String username, @QueryParam("offset") int offset, Response getGroupsOfUser(
@ApiParam(name = "username", value = "Username of the user.",required = true)
@QueryParam("username") String username,
@ApiParam(name = "offset", value = "Starting pagination index.",required = true)
@QueryParam("offset") int offset,
@ApiParam(name = "limit", value = "How many policy details are required from the starting pagination " +
"index.", required = true)
@QueryParam("limit") int limit); @QueryParam("limit") int limit);

@ -18,6 +18,11 @@
*/ */
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.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserCredentialWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.UserCredentialWrapper;
import javax.ws.rs.*; import javax.ws.rs.*;
@ -31,6 +36,23 @@ public interface UserManagementAdminService {
@POST @POST
@Path("/{username}/credentials") @Path("/{username}/credentials")
Response resetPassword(@PathParam("username") String user, UserCredentialWrapper credentials); @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Changing the user password.",
notes = "A user is able to change the password to secure their EMM profile via this REST API.")
@ApiResponses(value = {
@ApiResponse(code = 201, message = "User password was successfully changed."),
@ApiResponse(code = 400, message = "Old password does not match."),
@ApiResponse(code = 500, message = "Could not change the password of the user. The Character encoding is" +
" not supported.")
})
@Permission(scope = "user-modify", permissions = {"/permission/admin/login"})
Response resetPassword(
@ApiParam(name = "username", value = "Username of the user.",required = true)
@PathParam("username") String username,
@ApiParam(name = "credentials", value = "Credential.",required = true)
UserCredentialWrapper credentials);
} }

@ -23,10 +23,9 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
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.jaxrs.service.api.DeviceTypeManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.ConfigurationManagementService;
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.util.MDMAppConstants; import org.wso2.carbon.device.mgt.jaxrs.util.MDMAppConstants;
import org.wso2.carbon.device.mgt.jaxrs.util.ResponsePayload;
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.*;
@ -34,40 +33,30 @@ import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@Path("/device-types") @Path("/configuration")
public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementService { public class ConfigurationServiceImpl implements ConfigurationManagementService {
private static final Log log = LogFactory.getLog(DeviceTypeManagementServiceImpl.class); private static final Log log = LogFactory.getLog(ConfigurationServiceImpl.class);
@GET
@Override
public Response getTypes() {
return null;
}
@POST @POST
@Path("/{type}/configuration")
@Override @Override
public Response saveConfiguration(@PathParam("type") String type, PlatformConfiguration config) { public Response saveConfiguration(PlatformConfiguration config) {
ResponsePayload responseMsg = new ResponsePayload();
try { try {
DeviceMgtAPIUtils.getPlatformConfigurationManagementService().saveConfiguration(config, DeviceMgtAPIUtils.getPlatformConfigurationManagementService().saveConfiguration(config,
MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH); MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
//Schedule the task service //Schedule the task service
DeviceMgtAPIUtils.scheduleTaskService(DeviceMgtAPIUtils.getNotifierFrequency(config)); DeviceMgtAPIUtils.scheduleTaskService(DeviceMgtAPIUtils.getNotifierFrequency(config));
return Response.status(Response.Status.OK).entity("Platform configuration of device type '" + type + return Response.status(Response.Status.OK).entity("Platform configuration successfully saved.").build();
"' has successfully been saved").build();
} catch (ConfigurationManagementException e) { } catch (ConfigurationManagementException e) {
String msg = "Error occurred while saving the platform configuration of device type '" + type + "'"; String msg = "Error occurred while saving the platform configuration.";
log.error(msg, e); log.error(msg, e);
return javax.ws.rs.core.Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return javax.ws.rs.core.Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
} }
@GET @GET
@Path("/{type}/configuration")
@Override @Override
public Response getConfiguration(@PathParam("type") String type) { public Response getConfiguration() {
String msg; String msg;
try { try {
PlatformConfiguration config = DeviceMgtAPIUtils.getPlatformConfigurationManagementService(). PlatformConfiguration config = DeviceMgtAPIUtils.getPlatformConfigurationManagementService().
@ -84,26 +73,24 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
config.setConfiguration(configList); config.setConfiguration(configList);
return Response.status(Response.Status.OK).entity(config).build(); return Response.status(Response.Status.OK).entity(config).build();
} catch (ConfigurationManagementException e) { } catch (ConfigurationManagementException e) {
msg = "Error occurred while retrieving the configuration of device type '" + type + "'"; msg = "Error occurred while retrieving the configurations.";
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();
} }
} }
@PUT @PUT
@Path("/{type}/configuration")
@Override @Override
public Response updateConfiguration(@PathParam("type") String type, PlatformConfiguration config) { public Response updateConfiguration(PlatformConfiguration config) {
ResponsePayload responseMsg = new ResponsePayload();
try { try {
DeviceMgtAPIUtils.getPlatformConfigurationManagementService().saveConfiguration(config, DeviceMgtAPIUtils.getPlatformConfigurationManagementService().saveConfiguration(config,
MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH); MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
//Schedule the task service //Schedule the task service
DeviceMgtAPIUtils.scheduleTaskService(DeviceMgtAPIUtils.getNotifierFrequency(config)); DeviceMgtAPIUtils.scheduleTaskService(DeviceMgtAPIUtils.getNotifierFrequency(config));
return Response.status(Response.Status.CREATED).entity("Configuration of device type '" + type + return Response.status(Response.Status.CREATED)
"' has successfully been updated").build(); .entity("Configuration has successfully been updated").build();
} catch (ConfigurationManagementException e) { } catch (ConfigurationManagementException e) {
String msg = "Error occurred while updating the configuration of device type '" + type + "'"; String msg = "Error occurred while updating the configuration.";
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();
} }

@ -39,6 +39,7 @@ import javax.ws.rs.*;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
@Path("/policies")
public class PolicyManagementServiceImpl implements PolicyManagementService { public class PolicyManagementServiceImpl implements PolicyManagementService {
private static final Log log = LogFactory.getLog(PolicyManagementServiceImpl.class); private static final Log log = LogFactory.getLog(PolicyManagementServiceImpl.class);
@ -101,6 +102,9 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
try { try {
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP(); PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
policies = policyAdministratorPoint.getPolicies(); policies = policyAdministratorPoint.getPolicies();
if (policies == null || policies.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No policies found.").build();
}
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {
String msg = "Error occurred while retrieving all available policies"; String msg = "Error occurred while retrieving all available policies";
log.error(msg, e); log.error(msg, e);
@ -118,6 +122,9 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
try { try {
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP(); PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
policy = policyAdministratorPoint.getPolicy(id); policy = policyAdministratorPoint.getPolicy(id);
if (policy == null) {
return Response.status(Response.Status.NOT_FOUND).entity("Policy not found.").build();
}
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {
String msg = "Error occurred while retrieving policy corresponding to the id '" + id + "'"; String msg = "Error occurred while retrieving policy corresponding to the id '" + id + "'";
log.error(msg, e); log.error(msg, e);
@ -168,7 +175,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
return Response.status(Response.Status.OK).entity("Policies have been successfully deleted").build(); return Response.status(Response.Status.OK).entity("Policies have been successfully deleted").build();
} else { } else {
//TODO:Check of this logic is correct //TODO:Check of this logic is correct
return Response.status(Response.Status.BAD_REQUEST).entity("Policy doesn't exist").build(); return Response.status(Response.Status.NOT_FOUND).entity("Policy doesn't exist").build();
} }
} }

@ -48,6 +48,9 @@ public class RoleManagementServiceImpl implements RoleManagementService {
List<String> filteredRoles; List<String> filteredRoles;
try { try {
filteredRoles = getRolesFromUserStore(); filteredRoles = getRolesFromUserStore();
if (filteredRoles == null || filteredRoles.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No roles found.").build();
}
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while retrieving roles from the underlying user stores"; String msg = "Error occurred while retrieving roles from the underlying user stores";
log.error(msg, e); log.error(msg, e);
@ -82,6 +85,9 @@ public class RoleManagementServiceImpl implements RoleManagementService {
filteredRoles.add(role); 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(); return Response.status(Response.Status.OK).entity(filteredRoles).build();
} }
@ -110,6 +116,9 @@ public class RoleManagementServiceImpl implements RoleManagementService {
filteredRoles.add(role); 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(); return Response.status(Response.Status.OK).entity(filteredRoles).build();
} }
@ -126,6 +135,10 @@ public class RoleManagementServiceImpl implements RoleManagementService {
} }
final UserRealmProxy userRealmProxy = new UserRealmProxy(userRealmCore); final UserRealmProxy userRealmProxy = new UserRealmProxy(userRealmCore);
rolePermissions = this.getUIPermissionNode(roleName, userRealmProxy); rolePermissions = this.getUIPermissionNode(roleName, userRealmProxy);
if (rolePermissions == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No permissions found for the role '" +
roleName + "'").build();
}
return Response.status(Response.Status.OK).entity(rolePermissions).build(); return Response.status(Response.Status.OK).entity(rolePermissions).build();
} catch (UserAdminException e) { } catch (UserAdminException e) {
String msg = "Error occurred while retrieving the permissions of role '" + roleName + "'"; String msg = "Error occurred while retrieving the permissions of role '" + roleName + "'";
@ -188,6 +201,10 @@ 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);

@ -175,6 +175,10 @@ 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
@ -182,7 +186,7 @@ public class UserManagementServiceImpl implements UserManagementService {
log.debug("User by username: " + username + " does not exist."); log.debug("User by username: " + username + " does not exist.");
} }
// returning response with bad request state // returning response with bad request state
return Response.status(Response.Status.BAD_REQUEST).entity( return Response.status(Response.Status.NOT_FOUND).entity(
"User by username: " + username + " does not exist").build(); "User by username: " + username + " does not exist").build();
} }
} catch (UserStoreException e) { } catch (UserStoreException e) {
@ -196,7 +200,6 @@ public class UserManagementServiceImpl implements UserManagementService {
@Path("/{username}") @Path("/{username}")
@Override @Override
public Response updateUser(@PathParam("username") String username, UserWrapper userWrapper) { public Response updateUser(@PathParam("username") String username, UserWrapper userWrapper) {
ResponsePayload responsePayload = new ResponsePayload();
try { try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (userStoreManager.isExistingUser(userWrapper.getUsername())) { if (userStoreManager.isExistingUser(userWrapper.getUsername())) {
@ -233,21 +236,16 @@ public class UserManagementServiceImpl implements UserManagementService {
log.debug("User by username: " + userWrapper.getUsername() + " was successfully updated."); log.debug("User by username: " + userWrapper.getUsername() + " was successfully updated.");
} }
// returning response with success state // returning response with success state
responsePayload.setStatusCode(HttpStatus.SC_CREATED); return Response.status(Response.Status.CREATED).entity("User by username '" + userWrapper.getUsername() +
responsePayload.setMessageFromServer("User by username: " + userWrapper.getUsername() + "' was successfully updated.").build();
" was successfully updated.");
return Response.status(Response.Status.CREATED).entity(responsePayload).build();
} else { } else {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("User by username: " + userWrapper.getUsername() + log.debug("User by username: " + userWrapper.getUsername() +
" doesn't exists. Therefore, request made to update user was refused."); " doesn't exists. Therefore, request made to update user was refused.");
} }
// returning response with bad request state return Response.status(Response.Status.CONFLICT).entity("User by username: " +
responsePayload.setStatusCode(HttpStatus.SC_CONFLICT); userWrapper.getUsername() + " doesn't exists. Therefore, request made to update user was " +
responsePayload. "refused.").build();
setMessageFromServer("User by username: " + userWrapper.getUsername() +
" doesn't exists. Therefore, request made to update user was refused.");
return Response.status(Response.Status.CONFLICT).entity(responsePayload).build();
} }
} catch (UserStoreException | UnsupportedEncodingException e) { } catch (UserStoreException | UnsupportedEncodingException e) {
String msg = "Exception in trying to update user by username: " + userWrapper.getUsername(); String msg = "Exception in trying to update user by username: " + userWrapper.getUsername();
@ -294,7 +292,7 @@ public class UserManagementServiceImpl implements UserManagementService {
log.debug("User by username: " + username + " does not exist for removal."); log.debug("User by username: " + username + " does not exist for removal.");
} }
// returning response with bad request state // returning response with bad request state
return Response.status(Response.Status.BAD_REQUEST).entity("User by username: " + username + return Response.status(Response.Status.NOT_FOUND).entity("User by username: " + username +
" does not exist for removal.").build(); " does not exist for removal.").build();
} }
} catch (UserStoreException e) { } catch (UserStoreException e) {
@ -318,7 +316,7 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("User by username: " + username + " does not exist for role retrieval."); log.debug("User by username: " + username + " does not exist for role retrieval.");
} }
return Response.status(Response.Status.BAD_REQUEST).entity("User by username: " + username + return Response.status(Response.Status.NOT_FOUND).entity("User by username: " + username +
" does not exist for role retrieval.").build(); " does not exist for role retrieval.").build();
} }
} catch (UserStoreException e) { } catch (UserStoreException e) {

@ -25,10 +25,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService; import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService;
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.List; import java.util.List;
@ -41,6 +38,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
private static final Log log = LogFactory.getLog(DeviceManagementAdminServiceImpl.class); private static final Log log = LogFactory.getLog(DeviceManagementAdminServiceImpl.class);
@Override @Override
@GET
public Response getDevicesByName(@QueryParam("name") String name, @QueryParam("tenant-domain") String tenantDomain) { public Response getDevicesByName(@QueryParam("name") String name, @QueryParam("tenant-domain") String tenantDomain) {
List<Device> devices; List<Device> devices;
try { try {

@ -64,7 +64,7 @@
</bean> </bean>
<bean id="deviceManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceManagementServiceImpl"/> <bean id="deviceManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceManagementServiceImpl"/>
<bean id="deviceTypeManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceTypeManagementServiceImpl"/> <bean id="deviceTypeManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.ConfigurationServiceImpl"/>
<bean id="activityProviderService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.ActivityProviderServiceImpl"/> <bean id="activityProviderService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.ActivityProviderServiceImpl"/>
<bean id="notificationManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.NotificationManagementServiceImpl"/> <bean id="notificationManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.NotificationManagementServiceImpl"/>
<bean id="policyManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.PolicyManagementServiceImpl"/> <bean id="policyManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.PolicyManagementServiceImpl"/>

Loading…
Cancel
Save