From aa4a4889a55e6e0e1dec5f53c00d911d39e9dfac Mon Sep 17 00:00:00 2001 From: inoshperera Date: Fri, 27 May 2016 15:36:22 +0530 Subject: [PATCH 1/4] adding API header --- .../android/services/DeviceManagementAdminService.java | 7 +++---- .../services/android/services/DeviceManagementService.java | 7 +++---- .../android/services/DeviceTypeConfigurationService.java | 7 +++---- .../services/android/services/EventReceiverService.java | 6 ++---- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java index ee2f51d27..b3ef05ab1 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java @@ -18,10 +18,7 @@ */ package org.wso2.carbon.mdm.services.android.services; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.*; import org.wso2.carbon.mdm.services.android.bean.wrapper.*; import javax.ws.rs.Consumes; @@ -33,6 +30,8 @@ import javax.ws.rs.core.Response; import java.util.List; @Path("/devices") + +@Api(value = "DeviceManagementAdmin", description = "Device management related admin APIs.") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public interface DeviceManagementAdminService { diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java index 4af066fde..a46f49259 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java @@ -18,10 +18,7 @@ */ package org.wso2.carbon.mdm.services.android.services; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.*; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; @@ -32,6 +29,8 @@ import javax.ws.rs.core.Response; import java.util.List; @Path("/devices") +@Api(value = "DeviceManagement", description = "Device management related APIs that is used by mainly by the Android " + + "agent.") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public interface DeviceManagementService { diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java index 46b38d30a..fb458c24a 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java @@ -18,10 +18,7 @@ */ package org.wso2.carbon.mdm.services.android.services; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.*; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; @@ -30,6 +27,8 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @Path("/configuration") + +@Api(value = "DeviceTypeConfiguration", description = "Device type specific configuration APIs.") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public interface DeviceTypeConfigurationService { diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java index 5cf9be7cc..fc3502e72 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java @@ -18,10 +18,7 @@ */ package org.wso2.carbon.mdm.services.android.services; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.*; import org.wso2.carbon.mdm.services.android.bean.DeviceState; import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; @@ -29,6 +26,7 @@ import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +@Api(value = "EventReceiver", description = "Event publishing/retrieving related APIs.") @Path("/events") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) From d25e1b2421c4786a3e74ed5d411c8e8c929ae5a8 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Fri, 27 May 2016 22:43:03 +0530 Subject: [PATCH 2/4] Fixed Android APIs --- .../DeviceTypeConfigurationService.java | 17 +++++++ .../impl/DeviceManagementServiceImpl.java | 4 +- .../DeviceTypeConfigurationServiceImpl.java | 20 ++++++++ .../src/main/webapp/META-INF/permissions.xml | 50 ++++++++++++++----- 4 files changed, 78 insertions(+), 13 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java index 46b38d30a..74b22065a 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java @@ -76,4 +76,21 @@ public interface DeviceTypeConfigurationService { Response updateConfiguration(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") PlatformConfiguration configuration) throws AndroidAgentException; + @GET + @Path("license") + @Produces("text/html") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting the License Agreement for Android Device Registration", + notes = "Use this REST API to retrieve the license agreement that is used for the Android device " + + "registration process", + response = String.class) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Licence agreement"), + @ApiResponse(code = 500, message = "Error occurred while retrieving the license configured for Android " + + "device enrolment") + }) + Response getLicense() throws AndroidAgentException; + } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java index c7111459c..35a03a399 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java @@ -71,7 +71,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } } - @GET + + + @PUT @Path("/{id}/pending-operations") @Override public Response getPendingOperations(@PathParam("id") String id, List resultOperations) { diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java index 3b4a24f80..4de171d9b 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java @@ -158,4 +158,24 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati return Response.status(Response.Status.CREATED).entity(responseMsg).build(); } + + @GET + @Path("license") + @Produces("text/html") + public Response getLicense() throws AndroidAgentException { + License license = null; + + try { + license = + AndroidAPIUtils.getDeviceManagementService().getLicense( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, + DeviceManagementConstants.LanguageCodes.LANGUAGE_CODE_ENGLISH_US); + } catch (DeviceManagementException e) { + String msg = "Error occurred while retrieving the license configured for Android device enrolment"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + return Response.status(Response.Status.OK).entity((license == null) ? null : license.getText()).build(); + } + } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml index 1fd0c7c66..4ce7a039b 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml @@ -30,13 +30,7 @@ - - Get Pending Operation - /device-mgt/android/operations/poll - /operation/* - PUT - emm_android_agent - + Lock @@ -273,7 +267,7 @@ View license /device-mgt/android/license/view - /device/license + /configuration/license GET emm_android_agent @@ -282,19 +276,51 @@ Enroll device /device-mgt/android/devices/enroll - /enrollment + /devices POST emm_android_agent - Get Enrollment Status - /device-mgt/android/devices/enroll - /enrollment/* + Devices related Operations + /device-mgt/android/devices + /devices/* GET emm_android_agent + + Device is enrolled + /device-mgt/android/devices + /devices/*/status + GET + emm_android_agent + + + + Devices related Operations + /device-mgt/android/devices/operations + /devices/*/pending-operations + PUT + emm_android_agent + + + + Modify devices + /device-mgt/android/devices/operations + /devices/* + PUT + emm_android_agent + + + + Delete devices + /device-mgt/android/devices/operations + /devices/* + DELETE + emm_android_agent + + Update Enrollment /device-mgt/android/devices/enroll From b8cfcf4413b74bb7a6c97b4a0d255bd335708b85 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Fri, 27 May 2016 23:18:11 +0530 Subject: [PATCH 3/4] Fixed Enrollment issue --- .../android/services/DeviceTypeConfigurationService.java | 2 +- .../services/impl/DeviceTypeConfigurationServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java index 74b22065a..418e03b85 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java @@ -78,7 +78,7 @@ public interface DeviceTypeConfigurationService { @GET @Path("license") - @Produces("text/html") + @Produces("text/plain") @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = "GET", diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java index 4de171d9b..6d75af648 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java @@ -161,7 +161,7 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati @GET @Path("license") - @Produces("text/html") + @Produces("text/plain") public Response getLicense() throws AndroidAgentException { License license = null; From 4dbf1bdc2fbbe925acfb5bee5eae556f8e2791aa Mon Sep 17 00:00:00 2001 From: inoshperera Date: Sat, 28 May 2016 01:50:14 +0530 Subject: [PATCH 4/4] adding swagger annotation and making APIs standerdize --- .../DeviceManagementAdminService.java | 239 ++++++---- .../services/DeviceManagementService.java | 12 +- .../DeviceTypeConfigurationService.java | 42 +- .../services/EventReceiverService.java | 86 ++-- .../DeviceManagementAdminServiceImpl.java | 443 +++++------------- .../DeviceTypeConfigurationServiceImpl.java | 2 +- .../impl/EventReceiverServiceImpl.java | 36 +- .../android/util/AndroidAPIUtils.java | 12 +- .../android/util/AndroidDeviceUtils.java | 8 +- 9 files changed, 371 insertions(+), 509 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java index b3ef05ab1..d11d0ce4d 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java @@ -19,6 +19,7 @@ package org.wso2.carbon.mdm.services.android.services; import io.swagger.annotations.*; +import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.mdm.services.android.bean.wrapper.*; import javax.ws.rs.Consumes; @@ -43,14 +44,17 @@ public interface DeviceManagementAdminService { httpMethod = "POST", value = "Adding a Device Lock on Android Devices", notes = "Using this API you have the option of hard locking an Android device, where the Administrator " + - "permanently locks the device or screen locking an Android device" + "permanently locks the device or screen locking an Android device", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Lock operation has successfully been scheduled"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Lock operation has successfully been scheduled", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response configureDeviceLock( - @ApiParam(name = "cameraBeanWrapper", + @ApiParam(name = "deviceLockBeanWrapper", value = "Device lock configurations with device IDs") DeviceLockBeanWrapper deviceLockBeanWrapper); @POST @@ -62,10 +66,11 @@ public interface DeviceManagementAdminService { responseContainer = "List", notes = "Using this API you have the option of unlocking an Android device, where the Administrator " + "unlocks the device", - response = String.class) + response = Activity.class) @ApiResponses(value = { - @ApiResponse(code = 200, message = "created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added unlock.", response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n Device identifier list is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response configureDeviceUnlock( @ApiParam(name = "deviceIDs", value = "DeviceIds to be enable device unlock operation") @@ -73,17 +78,18 @@ public interface DeviceManagementAdminService { @POST - @Path("/get-location") + @Path("/location") @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Requesting Location Coordinates of Android Devices", responseContainer = "List", notes = "Request location coordinates of Android devices", - response = String.class) + response = Activity.class) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Requested Device Coordinates"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance")}) + @ApiResponse(code = 201, message = "Created \n Requested Device Coordinates", response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n Device identifier list is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.")}) Response getDeviceLocation( @ApiParam(name = "deviceIDs", value = "DeviceIDs to be requested to get device location") List deviceIDs); @@ -94,11 +100,13 @@ public interface DeviceManagementAdminService { consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Clearing the Password on Android Devices", - notes = "Clear the password on Android devices" + notes = "Clear the password on Android devices", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully cleared password.", response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n Device identifier list is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response removePassword( @ApiParam(name = "deviceIDs", @@ -110,18 +118,21 @@ public interface DeviceManagementAdminService { consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Enabling or Disabling the Camera on Android Devices", - notes = "Enable or disable the camera on Android devices" + notes = "Enable or disable the camera on Android devices", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in creating a new camera instance") + @ApiResponse(code = 201, message = "Created \n Camera operation performed successfully.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Issue in creating a new camera instance") }) Response configureCamera( @ApiParam(name = "cameraBeanWrapper", value = "Camera enable/disable configurations with device IDs") CameraBeanWrapper cameraBeanWrapper); @POST - @Path("/get-device-info") + @Path("/info") @ApiOperation( consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, @@ -129,11 +140,14 @@ public interface DeviceManagementAdminService { value = "Requesting Information from Android Devices", notes = "Using this REST API you are able to request for Android device details. Once this REST API is" + " executed it will be in the Android operation queue until the device calls the server to retrieve " + - "the list of operations that needs to be executed on the device" + "the list of operations that needs to be executed on the device", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Device Information"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Device information request operation added.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n Device identifier list is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response getDeviceInformation( @ApiParam(name = "deviceIds", value = "Device IDs to be requested to get device information") @@ -147,33 +161,38 @@ public interface DeviceManagementAdminService { httpMethod = "POST", value = "Enterprise Wiping Android Devices", notes = "Enterprise wipe is the process of deleting enterprise related data on a device while keeping the " + - "personal data intact. You are able to enterprise wipe Android devices using this REST API" + "personal data intact. You are able to enterprise wipe Android devices using this REST API", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance" + @ApiResponse(code = 201, message = "Created \n Enterprise wipe operation added.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n Device identifier list is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation." )}) - Response wipeDevice(@ApiParam(name = "deviceIDs", value = "Device IDs to be requested to done enterprise-wipe") + Response wipeDevice(@ApiParam(name = "deviceIDs", value = "Device IDs to be requested to do enterprise-wipe") List deviceIDs); @POST - @Path("/wipe-devices") + @Path("/wipe") @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Factory Resetting an Android Device", notes = "Factory rest or erases all the data stored in the Android devices " + - "to restore them back to the original system" + "to restore them back to the original system", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance")}) + @ApiResponse(code = 201, message = "Created \n Added wipe operation", response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n WipeData bean is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.")}) Response wipeData( - @ApiParam(name = "wipeDataBeanWrapper", value = "Configurations and DeviceIds to be need to done wipe-data") + @ApiParam(name = "wipeDataBeanWrapper", value = "Configurations and DeviceIds needed to do wipe-data") WipeDataBeanWrapper wipeDataBeanWrapper); @POST - @Path("/get-applications") + @Path("/applications") @ApiOperation( consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, @@ -182,58 +201,70 @@ public interface DeviceManagementAdminService { notes = "Using this REST API the server requests for the list of applications that are installed on" + " the Android devices. Once this REST API is executed it will be in the Android operation queue " + "until the device calls the server to retrieve the list of operations that needs to be executed " + - "on the device" + "on the device", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "List of applications for specific deviceIdentifier"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n List of applications for specific deviceIdentifier", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n Device identifier list is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response getApplications( - @ApiParam(name = "deviceIDs", value = "Device Ids to be need to get applications which already installed") + @ApiParam(name = "deviceIDs", value = "Device Ids needed to get applications that are already installed") List deviceIDs); @POST - @Path("/ring-devices") + @Path("/ring") @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Ringing Android Devices", - notes = "Ring Android devices" + notes = "Ring Android devices", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added ring operation.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n Device identifier list is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response ringDevice( - @ApiParam(name = "deviceIDs", value = "Device Ids needs to be ring") List deviceIDs); + @ApiParam(name = "deviceIDs", value = "Device Ids needed for ring") List deviceIDs); @POST - @Path("/reboot-devices") + @Path("/reboot") @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Rebooting Android Devices", - notes = "Reboot Android devices" + notes = "Reboot Android devices", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added reboot operation.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n Device identifier list is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response rebootDevice( - @ApiParam(name = "deviceIDs", value = "Device Ids needs to be rebooted") List deviceIDs); + @ApiParam(name = "deviceIDs", value = "Device Ids needed for reboot.") List deviceIDs); @POST @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Muting Android Devices", - notes = "Mute Android devices" + notes = "Mute Android devices", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added mute operation.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n Device identifier list is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) - @Path("/mute-devices") + @Path("/mute") Response muteDevice( @ApiParam(name = "deviceIDs", value = "DeviceIDs need to be muted") List deviceIDs); @@ -246,11 +277,14 @@ public interface DeviceManagementAdminService { value = "Installing an Application on Android Devices", notes = "Install an application on an Android device. If the device you are installing the application" + " on has the WSO2 system service installed, the application installation will happen in silent " + - "mode, else the device user's consent will be required" + "mode, else the device user's consent will be required", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added install application operation.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n applicationInstallationBeanWrapper is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response installApplication( @ApiParam(name = "applicationInstallationBeanWrapper", value = "Properties of installed apps and device IDs") @@ -265,11 +299,14 @@ public interface DeviceManagementAdminService { value = "Updating an Application on Android Devices", notes = "Update an application on an Android device. If the device you are updating the application" + " has the WSO2 system service installed, the application update will happen in silent " + - "mode, else the device user's consent will be required" + "mode, else the device user's consent will be required", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added update application operation.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n applicationInstallationBeanWrapper is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response updateApplication( @ApiParam(name = "applicationUpdateBeanWrapper", value = "Properties of updated apps and device IDs") @@ -281,11 +318,14 @@ public interface DeviceManagementAdminService { consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Uninstalling an Application from Android Devices", - notes = "Uninstall an application from Android devices" + notes = "Uninstall an application from Android devices", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added uninstall application operation.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n applicationInstallationBeanWrapper is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response uninstallApplication( @ApiParam(name = "applicationUninstallationBeanWrapper", @@ -299,14 +339,18 @@ public interface DeviceManagementAdminService { produces = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Get BlackListed Applications", - notes = "Getting BlackListed Applications" + notes = "Getting BlackListed Applications", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added blacklist application operation.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n blacklistApplicationsBeanWrapper is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response blacklistApplications( - @ApiParam(name = "blacklistApplicationsBeanWrapper", value = "BlacklistApplications Configuration and DeviceIds") + @ApiParam(name = "blacklistApplicationsBeanWrapper", value = "BlacklistApplications " + + "Configuration and DeviceIds") BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper); @POST @@ -316,11 +360,14 @@ public interface DeviceManagementAdminService { produces = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Upgrading device firmware", - notes = "Device firmware upgrade" + notes = "Device firmware upgrade", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added firmware upgrade operation.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n upgradeFirmwareBeanWrapper is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response upgradeFirmware( @ApiParam(name = "upgradeFirmwareBeanWrapper", @@ -334,11 +381,14 @@ public interface DeviceManagementAdminService { produces = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Configuring VPN on Android devices", - notes = "Configure VPN on Android devices" + notes = "Configure VPN on Android devices", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added configure vpn operation.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n vpnBeanWrapper is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response configureVPN( @ApiParam(name = "vpnBeanWrapper", @@ -351,11 +401,14 @@ public interface DeviceManagementAdminService { consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Sending a Notification to Android Devices", - notes = "Send a notification to Android devices" + notes = "Send a notification to Android devices", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added send notification operation.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n notificationBeanWrapper is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response sendNotification( @ApiParam(name = "notificationBeanWrapper", @@ -368,11 +421,14 @@ public interface DeviceManagementAdminService { consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Configuring Wi-Fi on Android Devices", - notes = "Configure Wi-Fi on Android devices" + notes = "Configure Wi-Fi on Android devices", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added configure wifi operation.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n WifiConfigurations is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response configureWifi( @ApiParam(name = "wifiBeanWrapper", @@ -384,11 +440,14 @@ public interface DeviceManagementAdminService { consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Encrypting Storage on Android Devices", - notes = "Encrypt the data stored on Android devices" + notes = "Encrypt the data stored on Android devices", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added encrypt storage operation.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n encryptionBeanWrapper is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response encryptStorage( @ApiParam(name = "encryptionBeanWrapper", @@ -401,11 +460,14 @@ public interface DeviceManagementAdminService { consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Changing the Lock Code on Android Devices", - notes = "Change the lock code on Android devices" + notes = "Change the lock code on Android devices", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added change lock code operation.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n lockCodeBeanWrapper is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response changeLockCode( @ApiParam(name = "lockCodeBeanWrapper", @@ -418,11 +480,14 @@ public interface DeviceManagementAdminService { consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Setting a Passcode Policy on Android Devices", - notes = "Set a password policy on Android devices" + notes = "Set a password policy on Android devices", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added set passcode policy operation.", + response = Activity.class), + @ApiResponse(code = 400, message = "Bad Request. \n passwordPolicyBeanWrapper is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response setPasswordPolicy( @ApiParam(name = "passwordPolicyBeanWrapper", @@ -435,11 +500,13 @@ public interface DeviceManagementAdminService { consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Setting a Web Clip on Android Devices", - notes = "Set a web clip on Android devices. A web clip is used to add a bookmark to a web application" + notes = "Set a web clip on Android devices. A web clip is used to add a bookmark to a web application", + response = Activity.class ) @ApiResponses(value = { - @ApiResponse(code = 202, message = "Accepted"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + @ApiResponse(code = 201, message = "Created \n Successfully added web clip operation."), + @ApiResponse(code = 400, message = "Bad Request. \n webClipBeanWrapper is empty."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred when adding operation.") }) Response setWebClip( @ApiParam(name = "webClipBeanWrapper", diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java index a5b8167f8..6ccb55787 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java @@ -31,8 +31,6 @@ import java.util.List; @Api(value = "Android Device Management API", description = "This carries all the resources related to Android device management functionalities") @Path("/devices") -@Api(value = "DeviceManagement", description = "Device management related APIs that is used by mainly by the Android " + - "agent.") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public interface DeviceManagementService { @@ -47,7 +45,6 @@ public interface DeviceManagementService { @ApiResponses(value = { @ApiResponse(code = 200, message = "OK. \n " + "Application list of the device has successfully been updated"), - @ApiResponse(code = 204, message = "No Content. \n Application list of the device has not been updated"), @ApiResponse(code = 500, message = "Internal Server Error. \n " + "Sever error occurred while modifying the application list") }) @@ -131,6 +128,12 @@ public interface DeviceManagementService { description = "Date and time the resource has been modified the last time.\n" + "Used by caches, or in conditional requests.")}), @ApiResponse(code = 404, message = "Not Found. \n Requested device not found."), + @ApiResponse(code = 303, message = "See Other. \n " + + "Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader(name = "Location", description = "The Source URL of the document.")}), + @ApiResponse(code = 304, message = "Not Modified. \n " + + "Empty body because the client already has the latest version of the requested resource."), @ApiResponse(code = 500, message = "Internal Server Error. \n " + "Server error occurred while retrieving the enrollment status of the device."), }) @@ -153,9 +156,8 @@ public interface DeviceManagementService { @ResponseHeader(name = "Last-Modified", description = "Date and time the resource has been modified the last time.\n" + "Used by caches, or in conditional requests.")}), - @ApiResponse(code = 204, message = "No Content. \n Enrollment of the device has not been updated"), @ApiResponse(code = 400, message = "Bad Request. \n Invalid request or validation error."), - @ApiResponse(code = 404, message = "Not Found. \n Resource to be deleted does not exist."), + @ApiResponse(code = 404, message = "Not Found. \n Resource to be changed does not exist."), @ApiResponse(code = 500, message = "Internal Server Error. \n " + "Server error occurred while modifying the current enrollment of the device.") }) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java index fb458c24a..56a180988 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java @@ -37,15 +37,21 @@ public interface DeviceTypeConfigurationService { @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", - value = "Configuring Android Platform Settings", - notes = "Configure the Android platform settings using this REST API" + value = "Configuring Android platform settings.", + notes = "Configure the Android platform settings using this REST API." ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Android platform configuration saved successfully"), - @ApiResponse(code = 500, message = "Internal Server Error") + @ApiResponse(code = 201, message = "Created. \n Android platform configuration saved successfully", + responseHeaders = { + @ResponseHeader(name = "Location", description = "URL of the configuration added.") + }), + @ApiResponse(code = 400, message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse(code = 500, message = "Internal Server Error. \n" + + " Error occurred while saving configurations for the android platform.") }) - Response addConfiguration(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") - PlatformConfiguration configuration) throws AndroidAgentException; + Response addConfiguration(@ApiParam(name = "configuration", + value = "Android platform related configurations that must be added.") + PlatformConfiguration configuration); @GET @ApiOperation( httpMethod = "GET", @@ -54,8 +60,16 @@ public interface DeviceTypeConfigurationService { response = PlatformConfiguration.class ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Get Android Configurations"), - @ApiResponse(code = 500, message = "Server Error") + @ApiResponse(code = 200, message = "Get Android Configuration."), + @ApiResponse(code = 303, message = "See Other. \n " + + "Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader(name = "Location", description = "The Source URL of the document.")}), + @ApiResponse(code = 304, message = "Not Modified. \n " + + "Empty body because the client already has the latest version of the requested resource."), + @ApiResponse(code = 404, message = "Not Found. \n Resource requested does not exist."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred while fetching " + + "configuration settings of Android platform.") }) Response getConfiguration() throws AndroidAgentException; @@ -64,13 +78,15 @@ public interface DeviceTypeConfigurationService { consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, httpMethod = "PUT", - value = "Updating Android Platform Configurations", - notes = "Update the Android platform configurations using this REST API" + value = "Updating Android Platform Configuration.", + notes = "Update the Android platform configurations using this REST API." ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), - @ApiResponse(code = 500, message = "Error occurred while modifying configuration settings of " + - "Android platform") + @ApiResponse(code = 200, message = "Created. \n Configurations was updated successfully."), + @ApiResponse(code = 400, message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse(code = 404, message = "Not Found. \n Resource to be changed does not exist."), + @ApiResponse(code = 500, message = "Internal Server Error. \n Error occurred while modifying " + + "configuration settings of Android platform.") }) Response updateConfiguration(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") PlatformConfiguration configuration) throws AndroidAgentException; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java index fc3502e72..0821d0513 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java @@ -33,80 +33,62 @@ import javax.ws.rs.core.Response; public interface EventReceiverService { @POST - @Path("/publish-event") + @Path("/publish") @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", - value = "Event Publishing via REST API.", - notes = "Publish events received by the WSO2 EMM Android client to WSO2 DAS using this API." + value = "Event publishing via REST API.", + notes = "Publish events received by the EMM Android client to WSO2 DAS using this API." ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Event is published successfully."), - @ApiResponse(code = 500, message = "Error occurred while publishing the events from Android agent.") + @ApiResponse(code = 201, message = "Created. \n Event is published successfully. Location header " + + "contains URL of newly enrolled device", + responseHeaders = { + @ResponseHeader(name = "Location", description = "URL of the newly published event.") + }), + @ApiResponse(code = 400, message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse(code = 500, message = "Internal Server Error. \n" + + " Error occurred while publishing the events from Android agent.") }) Response publishEvents( - @ApiParam(name = "eventBeanWrapper", - value = "Information of the agent event to be published on DAS.") + @ApiParam(name = "eventBeanWrapper", value = "Information of the agent event to be published on DAS.") EventBeanWrapper eventBeanWrapper); @GET @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = "GET", - value = "Getting Event Details of a Device.", - notes = "Get the event details received by an Android device using this API.", + value = "Getting event details for a given time period.", + notes = "Get the event details of a device for a given time duration using this API.Request must contain " + + "the device identifier. Optionally, both, date from and date to value should be present to get " + + "alerts between times. Based on device type and the device identifier also filtering can be done" + + "(This cannot be combined with to and from parameters).", response = DeviceState.class, responseContainer = "List" ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "List of Device statuses."), - @ApiResponse(code = 500, - message = "Error occurred while getting published events for specific given device.") + @ApiResponse(code = 200, message = "Created \n Event details of a device for a given time duration", + response = DeviceState.class, responseContainer = "List"), + @ApiResponse(code = 303, message = "See Other. \n Source can be retrieved from the URL specified at" + + " the Location header.", + responseHeaders = { + @ResponseHeader(name = "Location", description = "The Source URL of the document.") + }), + @ApiResponse(code = 304, message = "Not Modified. \n " + + "Empty body because the client already has the latest version of the requested resource."), + @ApiResponse(code = 400, message = "Bad Request. \n Invalid request or validation error. You must provide" + + " the device identifier. Additionally, the device identifier can be combined with either the type" + + " OR date from and to."), + @ApiResponse(code = 404, message = "Not Found. \n Resource requested does not exist."), + @ApiResponse(code = 500, message = "Error occurred while getting published events for specific device.") }) - Response retrieveAlert( - @ApiParam(name = "deviceId", value = "DeviceId which need to retrieve published events.") - @QueryParam("id") String deviceId); - - @GET - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Getting Event Details for a Given Time Period.", - notes = "Get the event details of a device for a given time duration using this API.", - response = DeviceState.class, - responseContainer = "List" - ) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "event details of a device for a given time duration"), - @ApiResponse(code = 500, message = "Error occurred while getting published events for" + - " specific device on given Date.") - }) - Response retrieveAlertFromDate( - @ApiParam(name = "id", - value = "Device Identifier to be need to retrieve events.") + Response retrieveAlerts( + @ApiParam(name = "id", value = "Device Identifier to be need to retrieve events.", required = true) @QueryParam("id") String deviceId, @ApiParam(name = "from", value = "From Date.") @QueryParam("from") long from, @ApiParam(name = "to", value = "To Date.") - @QueryParam("to") long to); - - @GET - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Retrieves event details by type", - notes = "Get the event details of a device for a given time duration using this API.", - response = DeviceState.class, - responseContainer = "List" - ) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "event details of a device for a given time duration"), - @ApiResponse(code = 500, message = "Error occurred while getting published events for" + - " specific device on given Date.") - }) - Response retrieveAlertByType( - @ApiParam(name = "id", value = "Device Identifier to be need to retrieve events.") - @QueryParam("id") String deviceId, + @QueryParam("to") long to, @ApiParam(name = "type", value = "Type of the Alert to be need to retrieve events.") @QueryParam("type") String type); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java index 53e77400c..cdc3d42e4 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java @@ -54,40 +54,30 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (log.isDebugEnabled()) { log.debug("Invoking Android device lock operation"); } - Message message = new Message(); - Response response; try { DeviceLock lock = deviceLockBeanWrapper.getOperation(); if (lock == null) { - String errorMessage = "Lock bean is empty"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + String errorMessage = "Lock bean is empty."; log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_LOCK); operation.setType(Operation.Type.PROFILE); operation.setEnabled(true); operation.setPayLoad(lock.toJSON()); - response = AndroidAPIUtils.getOperationResponse(deviceLockBeanWrapper.getDeviceIDs(), operation, - message); + return AndroidAPIUtils.getOperationResponse(deviceLockBeanWrapper.getDeviceIDs(), operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } - return response; } @POST @@ -95,32 +85,24 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe @Override public Response configureDeviceUnlock(List deviceIDs) { if (log.isDebugEnabled()) { - log.debug("Invoking Android device unlock operation"); + log.debug("Invoking Android device unlock operation."); } - Message message = new Message(); - Response response; - try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_UNLOCK); operation.setType(Operation.Type.COMMAND); operation.setEnabled(true); - response = AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } - return response; } @POST @@ -128,27 +110,22 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe @Override public Response getDeviceLocation(List deviceIDs) { if (log.isDebugEnabled()) { - log.debug("Invoking Android device location operation"); + log.debug("Invoking Android device location operation."); } - Message message = new Message(); try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_LOCATION); operation.setType(Operation.Type.COMMAND); - return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -157,29 +134,22 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe @Override public Response removePassword(List deviceIDs) { if (log.isDebugEnabled()) { - log.debug("Invoking Android clear password operation"); + log.debug("Invoking Android clear password operation."); } - Message message = new Message(); try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.CLEAR_PASSWORD); operation.setType(Operation.Type.COMMAND); - - return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); - + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation); } catch (OperationManagementException e) { - String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + String errorMessage = "Issue in retrieving operation management service instance."; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -190,66 +160,53 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (log.isDebugEnabled()) { log.debug("Invoking Android Camera operation"); } - Message message = new Message(); try { Camera camera = cameraBeanWrapper.getOperation(); - if (camera == null) { - if (log.isDebugEnabled()) { - log.debug("The payload of the configure camera operation is incorrect"); - } - throw new OperationManagementException("Issue in creating a new camera instance"); + String errorMessage = "The payload of the configure camera operation is incorrect."; + log.error(errorMessage); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } - CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.CAMERA); operation.setType(Operation.Type.COMMAND); operation.setEnabled(camera.isEnabled()); - - return AndroidAPIUtils.getOperationResponse(cameraBeanWrapper.getDeviceIDs(), operation, message); - + return AndroidAPIUtils.getOperationResponse(cameraBeanWrapper.getDeviceIDs(), operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @POST - @Path("/get-device-info") + @Path("/info") @Override public Response getDeviceInformation(List deviceIDs) { if (log.isDebugEnabled()) { log.debug("Invoking get Android device information operation"); } - Message message = new Message(); try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO); operation.setType(Operation.Type.COMMAND); - return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + + log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -261,186 +218,149 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe log.debug("Invoking enterprise-wipe device operation"); } - Message message = new Message(); - try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.ENTERPRISE_WIPE); operation.setType(Operation.Type.COMMAND); - - return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @POST - @Path("/wipe-devices") + @Path("/wipe") @Override public Response wipeData(WipeDataBeanWrapper wipeDataBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking Android wipe-data device operation"); } - Message message = new Message(); - try { WipeData wipeData = wipeDataBeanWrapper.getOperation(); if (wipeData == null) { - throw new OperationManagementException("WipeData bean is empty"); + String errorMessage = "WipeData bean is empty."; + log.error(errorMessage); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.WIPE_DATA); operation.setType(Operation.Type.PROFILE); operation.setPayLoad(wipeData.toJSON()); - - return AndroidAPIUtils.getOperationResponse(wipeDataBeanWrapper.getDeviceIDs(), operation, message); - + return AndroidAPIUtils.getOperationResponse(wipeDataBeanWrapper.getDeviceIDs(), operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @POST - @Path("/get-applications") + @Path("/applications") @Override public Response getApplications(List deviceIDs) { if (log.isDebugEnabled()) { log.debug("Invoking Android getApplicationList device operation"); } - Message message = new Message(); try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.APPLICATION_LIST); operation.setType(Operation.Type.COMMAND); - - return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @POST - @Path("/ring-devices") + @Path("/ring") @Override public Response ringDevice(List deviceIDs) { if (log.isDebugEnabled()) { log.debug("Invoking Android ring-device device operation"); } - Message message = new Message(); - try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_RING); operation.setType(Operation.Type.COMMAND); - return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @POST - @Path("/reboot-devices") + @Path("/reboot") @Override public Response rebootDevice(List deviceIDs) { if (log.isDebugEnabled()) { log.debug("Invoking Android reboot-device device operation"); } - Message message = new Message(); - try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_REBOOT); operation.setType(Operation.Type.COMMAND); - return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @POST - @Path("/mute-devices") + @Path("/mute") @Override public Response muteDevice(List deviceIDs) { if (log.isDebugEnabled()) { log.debug("Invoking mute device operation"); } - Message message = new Message(); - try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_MUTE); operation.setType(Operation.Type.COMMAND); operation.setEnabled(true); - return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -451,41 +371,30 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (log.isDebugEnabled()) { log.debug("Invoking 'InstallApplication' operation"); } - Message message = new Message(); try { ApplicationInstallation applicationInstallation = applicationInstallationBeanWrapper.getOperation(); if (applicationInstallation == null) { - if (log.isDebugEnabled()) { - log.debug("The payload of the application installing operation is incorrect"); - } - String errorMessage = "Issue in creating a new application installation instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + String errorMessage = "The payload of the application installing operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.INSTALL_APPLICATION); operation.setType(Operation.Type.PROFILE); operation.setPayLoad(applicationInstallation.toJSON()); - return AndroidAPIUtils.getOperationResponse(applicationInstallationBeanWrapper.getDeviceIDs(), - operation, message); + operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -497,20 +406,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe log.debug("Invoking 'UpdateApplication' operation"); } - Message message = new Message(); - try { ApplicationUpdate applicationUpdate = applicationUpdateBeanWrapper.getOperation(); if (applicationUpdate == null) { - if (log.isDebugEnabled()) { - log.debug("The payload of the application update operation is incorrect"); - } - String errorMessage = "Issue in creating a new application update instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + String errorMessage = "The payload of the application update operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } ProfileOperation operation = new ProfileOperation(); @@ -519,19 +421,15 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe operation.setPayLoad(applicationUpdate.toJSON()); return AndroidAPIUtils.getOperationResponse(applicationUpdateBeanWrapper.getDeviceIDs(), - operation, message); + operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -543,20 +441,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe log.debug("Invoking 'UninstallApplication' operation"); } - Message message = new Message(); - try { ApplicationUninstallation applicationUninstallation = applicationUninstallationBeanWrapper.getOperation(); if (applicationUninstallation == null) { - if (log.isDebugEnabled()) { - log.debug("The payload of the application uninstalling operation is incorrect"); - } - String errorMessage = "Issue in creating a new application uninstallation instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + String errorMessage = "The payload of the application uninstalling operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } ProfileOperation operation = new ProfileOperation(); @@ -565,19 +456,15 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe operation.setPayLoad(applicationUninstallation.toJSON()); return AndroidAPIUtils.getOperationResponse(applicationUninstallationBeanWrapper.getDeviceIDs(), - operation, message); + operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -589,20 +476,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe log.debug("Invoking 'Blacklist-Applications' operation"); } - Message message = new Message(); - try { BlacklistApplications blacklistApplications = blacklistApplicationsBeanWrapper.getOperation(); if (blacklistApplications == null) { - if (log.isDebugEnabled()) { - log.debug("The payload of the blacklisting apps operation is incorrect"); - } - String errorMessage = "Issue in creating a new blacklist applications instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + String errorMessage = "The payload of the blacklisting apps operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } ProfileOperation operation = new ProfileOperation(); @@ -611,20 +491,16 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe operation.setPayLoad(blacklistApplications.toJSON()); return AndroidAPIUtils.getOperationResponse(blacklistApplicationsBeanWrapper.getDeviceIDs(), - operation, message); + operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -635,20 +511,14 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (log.isDebugEnabled()) { log.debug("Invoking Android upgrade-firmware device operation"); } - Message message = new Message(); try { UpgradeFirmware upgradeFirmware = upgradeFirmwareBeanWrapper.getOperation(); if (upgradeFirmware == null) { - if (log.isDebugEnabled()) { - log.debug("The payload of the upgrade firmware operation is incorrect"); - } - String errorMessage = "Issue in creating a new upgrade firmware instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + String errorMessage = "The payload of the upgrade firmware operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } ProfileOperation operation = new ProfileOperation(); @@ -656,19 +526,15 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe operation.setType(Operation.Type.PROFILE); operation.setPayLoad(upgradeFirmware.toJSON()); return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), - operation, message); + operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -679,20 +545,14 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (log.isDebugEnabled()) { log.debug("Invoking Android VPN device operation"); } - Message message = new Message(); try { Vpn vpn = vpnBeanWrapper.getOperation(); if (vpn == null) { - if (log.isDebugEnabled()) { - log.debug("The payload of the VPN operation is incorrect"); - } - String errorMessage = "Issue in creating a new VPN instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + String errorMessage = "The payload of the VPN operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } ProfileOperation operation = new ProfileOperation(); @@ -700,19 +560,15 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe operation.setType(Operation.Type.PROFILE); operation.setPayLoad(vpn.toJSON()); return AndroidAPIUtils.getOperationResponse(vpnBeanWrapper.getDeviceIDs(), - operation, message); + operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -723,42 +579,31 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (log.isDebugEnabled()) { log.debug("Invoking 'notification' operation"); } - Message message = new Message(); try { Notification notification = notificationBeanWrapper.getOperation(); if (notification == null) { - if (log.isDebugEnabled()) { - log.debug("The payload of the notification operation is incorrect"); - } - String errorMessage = "Issue in creating a new notification instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + String errorMessage = "The payload of the notification operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.NOTIFICATION); operation.setType(Operation.Type.PROFILE); operation.setPayLoad(notification.toJSON()); - return AndroidAPIUtils.getOperationResponse(notificationBeanWrapper.getDeviceIDs(), - operation, message); + operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -769,20 +614,14 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (log.isDebugEnabled()) { log.debug("Invoking 'configure wifi' operation"); } - Message message = new Message(); try { Wifi wifi = wifiBeanWrapper.getOperation(); if (wifi == null) { - if (log.isDebugEnabled()) { - log.debug("The payload of the wifi operation is incorrect"); - } - String errorMessage = "Issue in creating a new Wifi instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + String errorMessage = "The payload of the wifi operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } ProfileOperation operation = new ProfileOperation(); @@ -791,20 +630,16 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe operation.setPayLoad(wifi.toJSON()); return AndroidAPIUtils.getOperationResponse(wifiBeanWrapper.getDeviceIDs(), - operation, message); + operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -815,42 +650,31 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (log.isDebugEnabled()) { log.debug("Invoking 'encrypt' operation"); } - Message message = new Message(); try { DeviceEncryption deviceEncryption = encryptionBeanWrapper.getOperation(); if (deviceEncryption == null) { - if (log.isDebugEnabled()) { - log.debug("The payload of the device encryption operation is incorrect"); - } - String errorMessage = "Issue in creating a new encryption instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + String errorMessage = "The payload of the device encryption operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.ENCRYPT_STORAGE); operation.setType(Operation.Type.COMMAND); operation.setEnabled(deviceEncryption.isEncrypted()); - return AndroidAPIUtils.getOperationResponse(encryptionBeanWrapper.getDeviceIDs(), - operation, message); + operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -862,42 +686,30 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe log.debug("Invoking 'change lock code' operation"); } - Message message = new Message(); - try { LockCode lockCode = lockCodeBeanWrapper.getOperation(); if (lockCode == null) { - if (log.isDebugEnabled()) { - log.debug("The payload of the change lock code operation is incorrect"); - } - String errorMessage = "Issue in retrieving a new lock-code instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + String errorMessage = "The payload of the change lock code operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.CHANGE_LOCK_CODE); operation.setType(Operation.Type.PROFILE); operation.setPayLoad(lockCode.toJSON()); - return AndroidAPIUtils.getOperationResponse(lockCodeBeanWrapper.getDeviceIDs(), - operation, message); + operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -908,20 +720,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (log.isDebugEnabled()) { log.debug("Invoking 'password policy' operation"); } - Message message = new Message(); try { PasscodePolicy passcodePolicy = passwordPolicyBeanWrapper.getOperation(); - if (passcodePolicy == null) { - if (log.isDebugEnabled()) { - log.debug("The payload of the change password policy operation is incorrect"); - } - String errorMessage = "Issue in creating a new Password policy instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + String errorMessage = "The payload of the change password policy operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } ProfileOperation operation = new ProfileOperation(); @@ -930,20 +735,16 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe operation.setPayLoad(passcodePolicy.toJSON()); return AndroidAPIUtils.getOperationResponse(passwordPolicyBeanWrapper.getDeviceIDs(), - operation, message); + operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } @@ -954,42 +755,30 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (log.isDebugEnabled()) { log.debug("Invoking 'webclip' operation"); } - Message message = new Message(); try { WebClip webClip = webClipBeanWrapper.getOperation(); if (webClip == null) { - if (log.isDebugEnabled()) { - log.debug("The payload of the add webclip operation is incorrect"); - } - String errorMessage = "Issue in creating a new web clip instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + String errorMessage = "The payload of the add webclip operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.WEBCLIP); operation.setType(Operation.Type.PROFILE); operation.setPayLoad(webClip.toJSON()); - - return AndroidAPIUtils.getOperationResponse(webClipBeanWrapper.getDeviceIDs(), - operation, message); + return AndroidAPIUtils.getOperationResponse(webClipBeanWrapper.getDeviceIDs(), operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java index 3b4a24f80..e63ca1486 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java @@ -46,7 +46,7 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati @POST @Override - public Response addConfiguration(PlatformConfiguration configuration) throws AndroidAgentException { + public Response addConfiguration(PlatformConfiguration configuration){ Message responseMsg = new Message(); String msg; ConfigurationEntry licenseEntry = null; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java index 177875a1c..d93efb158 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java @@ -71,7 +71,22 @@ public class EventReceiverServiceImpl implements EventReceiverService { @GET @Override - public Response retrieveAlert(@QueryParam("id") String deviceId) { + public Response retrieveAlerts(@QueryParam("id") String deviceId, @QueryParam ("from") long from, + @QueryParam ("to") long to, @QueryParam("type") String type) { + + if(from != 0l && to != 0l && deviceId != null) { + return retrieveAlertFromDate(deviceId, from, to); + } else if (deviceId != null && type != null) { + return retrieveAlertByType(deviceId, type); + } else if (deviceId != null) { + return retrieveAlert(deviceId); + } else { + return Response.status(Response.Status.BAD_REQUEST).entity("Request must contain the device identifier. " + + "Optionally, both from and to value should be present to get alerts between times.").build(); + } + } + + private Response retrieveAlert(String deviceId) { if (log.isDebugEnabled()) { log.debug("Retrieving events for given device Identifier."); } @@ -82,23 +97,18 @@ public class EventReceiverServiceImpl implements EventReceiverService { deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); if (deviceStates == null) { message.setResponseCode("No any alerts are published for Device: " + deviceId + "."); - return Response.status(Response.Status.OK).entity(message).build(); - + return Response.status(Response.Status.NOT_FOUND).entity(message).build(); } else { return Response.status(Response.Status.OK).entity(deviceStates).build(); } } catch (AnalyticsException e) { - String msg = "Error occurred while getting published events for specific " + - "Device: " + deviceId + "."; + String msg = "Error occurred while getting published events for specific device: " + deviceId + "."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } - @GET - @Override - public Response retrieveAlertFromDate(@QueryParam("id") String deviceId, @QueryParam("from") long from, - @QueryParam("to") long to) { + private Response retrieveAlertFromDate(String deviceId, long from, long to) { String fromDate = String.valueOf(from); String toDate = String.valueOf(to); if (log.isDebugEnabled()) { @@ -113,7 +123,7 @@ public class EventReceiverServiceImpl implements EventReceiverService { if (deviceStates == null) { message. setResponseCode("No any alerts are published on given date for given Device: " + deviceId + "."); - return Response.status(Response.Status.OK).entity(message).build(); + return Response.status(Response.Status.NOT_FOUND).entity(message).build(); } else { return Response.status(Response.Status.OK).entity(deviceStates).build(); @@ -126,9 +136,7 @@ public class EventReceiverServiceImpl implements EventReceiverService { } } - @GET - @Override - public Response retrieveAlertByType(@QueryParam("id") String deviceId, @QueryParam("type") String type) { + private Response retrieveAlertByType(String deviceId, String type) { if (log.isDebugEnabled()) { log.debug("Retrieving events for given device identifier and type."); } @@ -140,7 +148,7 @@ public class EventReceiverServiceImpl implements EventReceiverService { if (deviceStates == null) { message.setResponseCode("No any alerts are published for given Device: " + "" + deviceId + " on specific date."); - return Response.status(Response.Status.OK).entity(message).build(); + return Response.status(Response.Status.NOT_FOUND).entity(message).build(); } else { return Response.status(Response.Status.OK).entity(deviceStates).build(); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java index 9afc14f6f..6cbb5645c 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java @@ -47,6 +47,7 @@ import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManag import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.mdm.services.android.bean.DeviceState; +import org.wso2.carbon.mdm.services.android.exception.BadRequestException; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; @@ -114,12 +115,15 @@ public class AndroidAPIUtils { return responseMediaType; } - public static Response getOperationResponse(List deviceIDs, Operation operation, - Message message) + public static Response getOperationResponse(List deviceIDs, Operation operation) throws DeviceManagementException, OperationManagementException { - + if (deviceIDs == null || deviceIDs.size() == 0) { + String errorMessage = "Device identifier list is empty"; + log.error(errorMessage); + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + } AndroidDeviceUtils deviceUtils = new AndroidDeviceUtils(); - DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs, message); + DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs); List validDeviceIds = deviceIDHolder.getValidDeviceIDList(); Activity activity = getDeviceManagementService().addOperation( diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java index de4c6dde1..acfdf83a5 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java @@ -33,13 +33,7 @@ public class AndroidDeviceUtils { private static final String COMMA_SEPARATION_PATTERN = ", "; - public DeviceIDHolder validateDeviceIdentifiers(List deviceIDs, - Message message) { - - if (deviceIDs == null || deviceIDs.isEmpty()) { - message.setResponseMessage("Device identifier list is empty"); - throw new BadRequestException(message); - } + public DeviceIDHolder validateDeviceIdentifiers(List deviceIDs) { List errorDeviceIdList = new ArrayList(); List validDeviceIDList = new ArrayList();