From fd1d62454ae10e334a3493c9b42d5daa1ed0a78e Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 26 May 2016 18:01:14 +0530 Subject: [PATCH 01/41] Improving Android JAX-RS API definitions --- .../pom.xml | 2 +- .../bean/wrapper/DeviceLockBeanWrapper.java | 2 + .../wrapper/DisenrollmentBeanWrapper.java | 1 + .../bean/wrapper/EventBeanWrapper.java | 1 + .../bean/wrapper/NotificationBeanWrapper.java | 1 + .../exception/BadRequestException.java | 5 + .../DeviceManagementAdminService.java | 451 +++++++++++++ .../services/DeviceManagementService.java | 131 ++++ ...va => DeviceTypeConfigurationService.java} | 57 +- .../services/EventReceiverService.java | 115 ++++ .../devicemgt/DeviceManagementService.java | 145 ---- .../impl/DeviceManagementServiceImpl.java | 179 ----- .../enrollment/EnrollmentService.java | 97 --- .../impl/EnrollmentServiceImpl.java | 151 ----- .../android/services/event/EventService.java | 124 ---- .../DeviceManagementAdminServiceImpl.java} | 638 +++++------------- .../impl/DeviceManagementServiceImpl.java | 254 +++++++ .../DeviceTypeConfigurationServiceImpl.java} | 57 +- .../EventReceiverServiceImpl.java} | 91 ++- .../operationmgt/OperationMgtService.java | 506 -------------- .../services/policymgt/PolicyMgtService.java | 74 -- .../policymgt/impl/PolicyMgtServiceImpl.java | 100 --- .../android/util/AndroidAPIUtils.java | 35 +- .../android/util/AndroidConstants.java | 180 ++--- .../android/util/AndroidDeviceUtils.java | 4 +- .../android/util/ApiOriginFilter.java | 44 ++ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 79 +-- .../src/main/webapp/WEB-INF/web.xml | 14 + 28 files changed, 1426 insertions(+), 2112 deletions(-) create mode 100644 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 create mode 100644 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 rename components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/{configuration/ConfigurationMgtService.java => DeviceTypeConfigurationService.java} (54%) create mode 100644 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 delete mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/devicemgt/DeviceManagementService.java delete mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/devicemgt/impl/DeviceManagementServiceImpl.java delete mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/enrollment/EnrollmentService.java delete mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/enrollment/impl/EnrollmentServiceImpl.java delete mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/EventService.java rename components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/{operationmgt/impl/OperationMgtServiceImpl.java => impl/DeviceManagementAdminServiceImpl.java} (64%) create mode 100644 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 rename components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/{configuration/impl/ConfigurationMgtServiceImpl.java => impl/DeviceTypeConfigurationServiceImpl.java} (81%) rename components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/{event/impl/EventServiceImpl.java => impl/EventReceiverServiceImpl.java} (64%) delete mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/operationmgt/OperationMgtService.java delete mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/policymgt/PolicyMgtService.java delete mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/policymgt/impl/PolicyMgtServiceImpl.java create mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/ApiOriginFilter.java diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml index 943612caf..adf03b22c 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml @@ -46,7 +46,7 @@ 2.2 WEB-INF/lib/*cxf*.jar - ${project.artifactId} + api#device-mgt#android#v2.1 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/bean/wrapper/DeviceLockBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceLockBeanWrapper.java index 5811c3102..bd668faba 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceLockBeanWrapper.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceLockBeanWrapper.java @@ -30,6 +30,7 @@ import java.util.List; @ApiModel(value = "DeviceLockBeanWrapper", description = "DeviceLock related Information.") public class DeviceLockBeanWrapper { + @ApiModelProperty(name = "deviceIDs", value = "Device id list of the operation to be executed.", required = true) private List deviceIDs; @ApiModelProperty(name = "operation", value = "Information of the Device lock operation.", required = true) @@ -50,4 +51,5 @@ public class DeviceLockBeanWrapper { public void setOperation(DeviceLock operation) { this.operation = operation; } + } 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/bean/wrapper/DisenrollmentBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DisenrollmentBeanWrapper.java index 86e7fb3af..fdcab0120 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DisenrollmentBeanWrapper.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DisenrollmentBeanWrapper.java @@ -46,4 +46,5 @@ public class DisenrollmentBeanWrapper { public void setDeviceIDs(List deviceIDs) { this.deviceIDs = deviceIDs; } + } 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/bean/wrapper/EventBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EventBeanWrapper.java index d8e21c8d4..d05cb58f8 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EventBeanWrapper.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EventBeanWrapper.java @@ -27,6 +27,7 @@ import io.swagger.annotations.ApiModelProperty; @ApiModel(value = "EventBeanWrapper", description = "Android agent's event related Information.") public class EventBeanWrapper { + @ApiModelProperty(name = "deviceIdentifier", value = "DeviceIdentifier to be need to retrieve/publish Event.", required = true) private String deviceIdentifier; @ApiModelProperty(name = "payload", value = "Event payload.", required = true) 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/bean/wrapper/NotificationBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/NotificationBeanWrapper.java index 573e2affc..eb82e49ee 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/NotificationBeanWrapper.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/NotificationBeanWrapper.java @@ -51,4 +51,5 @@ public class NotificationBeanWrapper { public void setOperation(Notification operation) { this.operation = operation; } + } 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/exception/BadRequestException.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/BadRequestException.java index 894bcc402..53ea4e99e 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/BadRequestException.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/BadRequestException.java @@ -33,4 +33,9 @@ public class BadRequestException extends WebApplicationException { super(Response.status(Response.Status.BAD_REQUEST).entity(message). type(mediaType).build()); } + + public BadRequestException(Message message) { + super(Response.status(Response.Status.BAD_REQUEST).entity(message).build()); + } + } \ No newline at end of file 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 new file mode 100644 index 000000000..ee2f51d27 --- /dev/null +++ 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 @@ -0,0 +1,451 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.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 org.wso2.carbon.mdm.services.android.bean.wrapper.*; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; + +@Path("/devices") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public interface DeviceManagementAdminService { + + @POST + @Path("/lock-devices") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + 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" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Lock operation has successfully been scheduled"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response configureDeviceLock( + @ApiParam(name = "cameraBeanWrapper", + value = "Device lock configurations with device IDs") DeviceLockBeanWrapper deviceLockBeanWrapper); + + @POST + @Path("/unlock-devices") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Adding a Device Unlock on Android Devices", + responseContainer = "List", + notes = "Using this API you have the option of unlocking an Android device, where the Administrator " + + "unlocks the device", + response = String.class) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response configureDeviceUnlock( + @ApiParam(name = "deviceIDs", value = "DeviceIds to be enable device unlock operation") + List deviceIDs); + + + @POST + @Path("/get-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) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Requested Device Coordinates"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance")}) + Response getDeviceLocation( + @ApiParam(name = "deviceIDs", value = "DeviceIDs to be requested to get device location") + List deviceIDs); + + @POST + @Path("/clear-password") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Clearing the Password on Android Devices", + notes = "Clear the password on Android devices" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response removePassword( + @ApiParam(name = "deviceIDs", + value = "DeviceIds to be requested to remove password") List deviceIDs); + + @POST + @Path("/control-camera") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Enabling or Disabling the Camera on Android Devices", + notes = "Enable or disable the camera on Android devices" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "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") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + 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" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Device Information"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response getDeviceInformation( + @ApiParam(name = "deviceIds", value = "Device IDs to be requested to get device information") + List deviceIDs); + + @POST + @Path("/enterprise-wipe") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + 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" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance" + )}) + Response wipeDevice(@ApiParam(name = "deviceIDs", value = "Device IDs to be requested to done enterprise-wipe") + List deviceIDs); + + @POST + @Path("/wipe-devices") + @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" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance")}) + Response wipeData( + @ApiParam(name = "wipeDataBeanWrapper", value = "Configurations and DeviceIds to be need to done wipe-data") + WipeDataBeanWrapper wipeDataBeanWrapper); + + @POST + @Path("/get-applications") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Requesting the List of Installed Applications on Android Devices", + 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" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "List of applications for specific deviceIdentifier"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response getApplications( + @ApiParam(name = "deviceIDs", value = "Device Ids to be need to get applications which already installed") + List deviceIDs); + + @POST + @Path("/ring-devices") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Ringing Android Devices", + notes = "Ring Android devices" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response ringDevice( + @ApiParam(name = "deviceIDs", value = "Device Ids needs to be ring") List deviceIDs); + + @POST + @Path("/reboot-devices") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Rebooting Android Devices", + notes = "Reboot Android devices" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response rebootDevice( + @ApiParam(name = "deviceIDs", value = "Device Ids needs to be rebooted") List deviceIDs); + + @POST + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Muting Android Devices", + notes = "Mute Android devices" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + @Path("/mute-devices") + Response muteDevice( + @ApiParam(name = "deviceIDs", value = "DeviceIDs need to be muted") List deviceIDs); + + @POST + @Path("/install-application") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + 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" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response installApplication( + @ApiParam(name = "applicationInstallationBeanWrapper", value = "Properties of installed apps and device IDs") + ApplicationInstallationBeanWrapper applicationInstallationBeanWrapper); + + @POST + @Path("/update-application") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + 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" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response updateApplication( + @ApiParam(name = "applicationUpdateBeanWrapper", value = "Properties of updated apps and device IDs") + ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper); + + @POST + @Path("/uninstall-application") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Uninstalling an Application from Android Devices", + notes = "Uninstall an application from Android devices" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response uninstallApplication( + @ApiParam(name = "applicationUninstallationBeanWrapper", + value = "applicationUninstallationConfigs and Device Ids") + ApplicationUninstallationBeanWrapper applicationUninstallationBeanWrapper); + + @POST + @Path("/blacklist-applications") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Get BlackListed Applications", + notes = "Getting BlackListed Applications" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response blacklistApplications( + @ApiParam(name = "blacklistApplicationsBeanWrapper", value = "BlacklistApplications Configuration and DeviceIds") + BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper); + + @POST + @Path("/upgrade-firmware") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Upgrading device firmware", + notes = "Device firmware upgrade" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response upgradeFirmware( + @ApiParam(name = "upgradeFirmwareBeanWrapper", + value = "Firmware upgrade configuration and DeviceIds") + UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper); + + @POST + @Path("/configure-vpn") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Configuring VPN on Android devices", + notes = "Configure VPN on Android devices" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response configureVPN( + @ApiParam(name = "vpnBeanWrapper", + value = "VPN configuration and DeviceIds") + VpnBeanWrapper vpnBeanWrapper); + + @POST + @Path("/send-notification") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Sending a Notification to Android Devices", + notes = "Send a notification to Android devices" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response sendNotification( + @ApiParam(name = "notificationBeanWrapper", + value = "Notification Configurations and device Ids") + NotificationBeanWrapper notificationBeanWrapper); + + @POST + @Path("/configure-wifi") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Configuring Wi-Fi on Android Devices", + notes = "Configure Wi-Fi on Android devices" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response configureWifi( + @ApiParam(name = "wifiBeanWrapper", + value = "WifiConfigurations and Device Ids") WifiBeanWrapper wifiBeanWrapper); + + @POST + @Path("/encrypt-storage") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Encrypting Storage on Android Devices", + notes = "Encrypt the data stored on Android devices" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response encryptStorage( + @ApiParam(name = "encryptionBeanWrapper", + value = "Configurations and deviceIds need to be done data encryption") + EncryptionBeanWrapper encryptionBeanWrapper); + + @POST + @Path("/change-lock-code") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Changing the Lock Code on Android Devices", + notes = "Change the lock code on Android devices" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response changeLockCode( + @ApiParam(name = "lockCodeBeanWrapper", + value = "Configurations and device Ids need to be done change lock code") + LockCodeBeanWrapper lockCodeBeanWrapper); + + @POST + @Path("/set-password-policy") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Setting a Passcode Policy on Android Devices", + notes = "Set a password policy on Android devices" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response setPasswordPolicy( + @ApiParam(name = "passwordPolicyBeanWrapper", + value = "Password Policy Configurations and Device Ids") + PasswordPolicyBeanWrapper passwordPolicyBeanWrapper); + + @POST + @Path("set-webclip") + @ApiOperation( + 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" + ) + @ApiResponses(value = { + @ApiResponse(code = 202, message = "Accepted"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response setWebClip( + @ApiParam(name = "webClipBeanWrapper", + value = "Configurations to need set web clip on device and device Ids") + WebClipBeanWrapper 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 new file mode 100644 index 000000000..4af066fde --- /dev/null +++ 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 @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.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 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; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; + +@Path("/devices") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public interface DeviceManagementService { + + @PUT + @Path("/{id}/applications") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Updating an ApplicationList", + notes = "Update application list in server side." + ) + @ApiResponses(value = { + @ApiResponse(code = 202, message = "Device information has modified successfully"), + @ApiResponse(code = 500, message = "Error occurred while modifying the application list") + }) + Response updateApplicationList(@ApiParam(name = "id", value = "deviceIdentifier") @PathParam("id") String id, + @ApiParam(name = "applications", value = "updatable applications") + List applications); + + @GET + @Path("/{id}/pending-operations") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Getting Pending Android Device Operations", + responseContainer = "List", + notes = "The Android agent communicates with the server to get the operations that are queued up " + + "at the server end for a given device using this REST API", + response = Operation.class) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "List of pending operations"), + @ApiResponse(code = 500, message = "Issue in retrieving operation management service instance") + }) + Response getPendingOperations( + @ApiParam(name = "id", value = "DeviceIdentifier") @PathParam("id") String id, + @ApiParam(name = "resultOperations", value = "Device Operation Status") + List resultOperations); + + @POST + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Registering an Android Device", + notes = "When carrying out device registration via an Android device, you need to initially install" + + " an Android Agent on the device, before being able to register the device with WSO2 EMM. Instead," + + " you can use this REST API to register an Android device with WSO2 EMM, without having to install" + + " an Android Agent on the respective device" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Device enrollment succeeded"), + @ApiResponse(code = 500, message = "Device enrollment failed"), + }) + Response enrollDevice(@ApiParam(name = "device", value = "Device Information to be enroll") Device device); + + @GET + @Path("/{id}/status") + @ApiOperation( + httpMethod = "GET", + value = "Getting the Registration Status of an Android Device", + notes = "Use this REST API to retrieve the registration status of an Android device" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Device has already enrolled"), + @ApiResponse(code = 404, message = "Device not found") + }) + Response isEnrolled(@ApiParam(name = "id", value = "DeviceIdentifier") @PathParam("id") String id); + + @PUT + @Path("/{id}") + @ApiOperation( + httpMethod = "PUT", + value = "Updating the Registration Details of an Android Device", + notes = "Use this REST API to update the registration details of an Android device" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Device enrollment has updated successfully"), + @ApiResponse(code = 404, message = "Device not found for enrollment") + }) + Response modifyEnrollment(@ApiParam(name = "id", value = "DeviceIdentifier") @PathParam("id") String id, + @ApiParam(name = "device", value = "Device information to be modify") Device device); + + @DELETE + @Path("/{id}") + @ApiOperation( + httpMethod = "DELETE", + value = "Un-registering an Android Device", + notes = "Use this REST API to unregister a specific Android device" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Device has removed successfully"), + @ApiResponse(code = 404, message = "Device not found") + }) + Response disEnrollDevice(@ApiParam(name = "id", value = "DeviceIdentifier") @PathParam("id") String id); + +} 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/configuration/ConfigurationMgtService.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 similarity index 54% rename from components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/configuration/ConfigurationMgtService.java rename to 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 f47999149..e26d9e2a5 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/configuration/ConfigurationMgtService.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 @@ -1,38 +1,38 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. */ +package org.wso2.carbon.mdm.services.android.services; -package org.wso2.carbon.mdm.services.android.services.configuration; - -import io.swagger.annotations.*; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; + import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -/** - * Android Platform Configuration REST-API implementation. - * All end points supports JSON, XMl with content negotiation. - */ -@Api(value = "ConfigurationMgtService") -@Produces({"application/json", "application/xml"}) -@Consumes({"application/json", "application/xml"}) -public interface ConfigurationMgtService { +@Path("/configuration") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public interface DeviceTypeConfigurationService { @POST @ApiOperation( @@ -42,11 +42,11 @@ public interface ConfigurationMgtService { notes = "Configure the Android platform settings using this REST API" ) @ApiResponses(value = { - @ApiResponse(code = 201, message = "Android platform configuration saved successfully"), + @ApiResponse(code = 200, message = "Android platform configuration saved successfully"), @ApiResponse(code = 500, message = "Internal Server Error") }) - Response configureSettings(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") - TenantConfiguration configuration) throws AndroidAgentException; + Response addConfiguration(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") + TenantConfiguration configuration) throws AndroidAgentException; @GET @ApiOperation( @@ -70,10 +70,11 @@ public interface ConfigurationMgtService { notes = "Update the Android platform configurations using this REST API" ) @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), + @ApiResponse(code = 200, message = "Created"), @ApiResponse(code = 500, message = "Error occurred while modifying configuration settings of " + "Android platform") }) Response updateConfiguration(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") - TenantConfiguration configuration) throws AndroidAgentException; + TenantConfiguration 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 new file mode 100644 index 000000000..5cf9be7cc --- /dev/null +++ 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 @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.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 org.wso2.carbon.mdm.services.android.bean.DeviceState; +import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@Path("/events") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public interface EventReceiverService { + + @POST + @Path("/publish-event") + @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." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Event is published successfully."), + @ApiResponse(code = 500, message = "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.") + 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.", + 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.") + }) + 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.") + @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, + @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/devicemgt/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/devicemgt/DeviceManagementService.java deleted file mode 100644 index fc95711a7..000000000 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/devicemgt/DeviceManagementService.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.mdm.services.android.services.devicemgt; - -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.mdm.services.android.exception.AndroidAgentException; -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.List; - -/** - * Android Device Management REST-API implementation. - * All end points supports JSON, XMl with content negotiation. - */ - -@Api(value = "DeviceManagementService", description = "Android Device Management REST-API implementation.") -@Produces({"application/json", "application/xml"}) -@Consumes({"application/json", "application/xml"}) -public interface DeviceManagementService { - - - /** - * Get all devices.Returns list of Android devices registered in MDM. - * - * @return Device List - * @throws org.wso2.carbon.mdm.services.android.exception.AndroidAgentException - */ - @GET - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Getting Details of All Android Devices", - notes = "Use this REST API to retrieve the details " + - "(e.g., the Android device type, serial number, International Mobile Station Equipment Identity " + - "(IMEI), owner, version, model etc.) of all Android devices that are registered with WSO2 EMM.", - response = Device.class, - responseContainer = "List" - ) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "List of Devices"), - @ApiResponse(code = 500, message = "Error occurred while fetching the device list") - }) - Response getAllDevices() throws AndroidAgentException; - - /** - * Fetch Android device details of a given device Id. - * - * @param id Device Id - * @return Device - * @throws org.wso2.carbon.mdm.services.android.exception.AndroidAgentException - */ - @GET - @Path("{id}") - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Getting Details of an Android Device", - notes = "Use this REST API to retrieve the details " + - "(e.g., the Android device type, serial number, International Mobile Station Equipment Identity " + - "(IMEI), owner, version, model etc.) of a specific Android device that is registered with WSO2 EMM", - response = Device.class - ) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "Information of the given device"), - @ApiResponse(code = 500, message = "Error occurred while fetching the device information") - }) - Response getDevice(@ApiParam(name = "id", value = "deviceIdentifier") - @PathParam("id") String id) throws AndroidAgentException; - - /** - * Update Android device details of given device id. - * - * @param id Device Id - * @param device Device Details - * @return Message - * @throws AndroidAgentException - */ - @PUT - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "PUT", - value = "Updating the Details of an Android Device", - notes = "Use this REST API to update the details of an Android device" - ) - @ApiResponses(value = { - @ApiResponse(code = 202, message = "The device enrollment details has been updated successfully"), - @ApiResponse(code = 500, message = "Error occurred while modifying the device information"), - @ApiResponse(code = 304, message = "Device not found for the update") - }) - @Path("{id}") - Response updateDevice(@ApiParam(name = "id", value = "deviceIdentifier") - @PathParam("id") String id, @ApiParam(name = "device", value = "deviceIdentifier") - Device device) throws AndroidAgentException; - - @POST - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Updating an ApplicationList", - notes = "Update application list in server side." - ) - @ApiResponses(value = { - @ApiResponse(code = 202, message = "Device information has modified successfully"), - @ApiResponse(code = 500, message = "Error occurred while modifying the application list") - }) - Response updateApplicationList(@ApiParam(name = "id", value = "deviceIdentifier") @PathParam("id") String id, - @ApiParam(name = "applications", value = "updatable applications") - List applications) 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/devicemgt/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/devicemgt/impl/DeviceManagementServiceImpl.java deleted file mode 100644 index 06ccdf3e9..000000000 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/devicemgt/impl/DeviceManagementServiceImpl.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.mdm.services.android.services.devicemgt.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.app.mgt.Application; -import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; -import org.wso2.carbon.device.mgt.common.license.mgt.License; -import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; -import org.wso2.carbon.mdm.services.android.services.devicemgt.DeviceManagementService; -import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; -import org.wso2.carbon.mdm.services.android.util.Message; -import javax.ws.rs.*; -import javax.ws.rs.core.Response; -import java.util.List; - -/** - * Android Device Management REST-API implementation. - * All end points supports JSON, XMl with content negotiation. - */ -@Produces({"application/json", "application/xml"}) -@Consumes({"application/json", "application/xml"}) -public class DeviceManagementServiceImpl implements DeviceManagementService { - - private static Log log = LogFactory.getLog(DeviceManagementServiceImpl.class); - - /** - * Get all devices.Returns list of Android devices registered in MDM. - * - * @return Device List - * @throws AndroidAgentException - */ - @GET - public Response getAllDevices() - throws AndroidAgentException { - String msg; - List devices; - - try { - devices = AndroidAPIUtils.getDeviceManagementService(). - getAllDevices(DeviceManagementConstants.MobileDeviceTypes. - MOBILE_DEVICE_TYPE_ANDROID); - } catch (DeviceManagementException e) { - msg = "Error occurred while fetching the device list."; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } - return Response.status(Response.Status.OK).entity(devices).build(); - } - - /** - * Fetch Android device details of a given device Id. - * - * @param id Device Id - * @return Device - * @throws AndroidAgentException - */ - @GET - @Path("{id}") - public Response getDevice(@PathParam("id") String id) - throws AndroidAgentException { - - String msg; - Device device; - - try { - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier); - if (device == null) { - return Response.status(Response.Status.NOT_FOUND).build(); - } - } catch (DeviceManagementException deviceMgtEx) { - msg = "Error occurred while fetching the device information."; - log.error(msg, deviceMgtEx); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } - return Response.status(Response.Status.OK).entity(device).build(); - } - - /** - * Update Android device details of given device id. - * - * @param id Device Id - * @param device Device Details - * @return Message - * @throws AndroidAgentException - */ - @PUT - @Path("{id}") - public Response updateDevice(@PathParam("id") String id, Device device) - throws AndroidAgentException { - String msg; - Message responseMessage = new Message(); - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(id); - deviceIdentifier - .setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - boolean result; - try { - device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - result = AndroidAPIUtils.getDeviceManagementService() - .updateDeviceInfo(deviceIdentifier, device); - if (result) { - responseMessage.setResponseMessage("Device information has modified successfully."); - return Response.status(Response.Status.ACCEPTED).entity(responseMessage).build(); - } else { - responseMessage.setResponseMessage("Device not found for the update."); - return Response.status(Response.Status.NOT_MODIFIED).entity(responseMessage).build(); - } - } catch (DeviceManagementException e) { - msg = "Error occurred while modifying the device information."; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } - } - - @POST - @Path("appList/{id}") - public Response updateApplicationList(@PathParam("id") String id, List applications) - throws - AndroidAgentException { - - Message responseMessage = new Message(); - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(id); - deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - try { - AndroidAPIUtils.getApplicationManagerService(). - updateApplicationListInstalledInDevice(deviceIdentifier, applications); - responseMessage.setResponseMessage("Device information has modified successfully."); - return Response.status(Response.Status.ACCEPTED).entity(responseMessage).build(); - } catch (ApplicationManagementException e) { - String msg = "Error occurred while modifying the application list."; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).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/java/org/wso2/carbon/mdm/services/android/services/enrollment/EnrollmentService.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/enrollment/EnrollmentService.java deleted file mode 100644 index b150fd19d..000000000 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/enrollment/EnrollmentService.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.mdm.services.android.services.enrollment; - -import io.swagger.annotations.*; -import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -/** - * Android Device Enrollment REST-API implementation. - * All end points supports JSON, XMl with content negotiation. - */ - -@Api(value = "EnrollmentService", description = "Android Device Enrollment REST-API implementation.") -@Produces({"application/json", "application/xml"}) -@Consumes({"application/json", "application/xml"}) -public interface EnrollmentService { - - @POST - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Registering an Android Device", - notes = "When carrying out device registration via an Android device, you need to initially install" + - " an Android Agent on the device, before being able to register the device with WSO2 EMM. Instead," + - " you can use this REST API to register an Android device with WSO2 EMM, without having to install" + - " an Android Agent on the respective device" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Device enrollment succeeded"), - @ApiResponse(code = 500, message = "Device enrollment failed"), - }) - Response enrollDevice(@ApiParam(name = "device", value = "Device Information to be enroll") - org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException; - - @GET - @Path("{deviceId}") - @ApiOperation( - httpMethod = "GET", - value = "Getting the Registration Status of an Android Device", - notes = "Use this REST API to retrieve the registration status of an Android device" - ) - @ApiResponses(value = { - @ApiResponse(code = 202, message = "Device has already enrolled"), - @ApiResponse(code = 404, message = "Device not found") - }) - Response isEnrolled(@ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id) - throws AndroidAgentException; - - @PUT - @Path("{deviceId}") - @ApiOperation( - httpMethod = "PUT", - value = "Updating the Registration Details of an Android Device", - notes = "Use this REST API to update the registration details of an Android device" - ) - @ApiResponses(value = { - @ApiResponse(code = 202, message = "Device enrollment has updated successfully"), - @ApiResponse(code = 404, message = "Device not found for enrollment") - }) - Response modifyEnrollment(@ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id, - @ApiParam(name = "device", value = "Device information to be modify") - org.wso2.carbon.device.mgt.common.Device device) - throws AndroidAgentException; - - @DELETE - @ApiOperation( - httpMethod = "DELETE", - value = "Un-registering an Android Device", - notes = "Use this REST API to unregister a specific Android device" - ) - @ApiResponses(value = { - @ApiResponse(code = 202, message = "Device has removed successfully"), - @ApiResponse(code = 404, message = "Device not found") - }) - @Path("{deviceId}") - Response disEnrollDevice(@ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id) - 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/enrollment/impl/EnrollmentServiceImpl.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/enrollment/impl/EnrollmentServiceImpl.java deleted file mode 100644 index cf8d295c0..000000000 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/enrollment/impl/EnrollmentServiceImpl.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.mdm.services.android.services.enrollment.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; -import org.wso2.carbon.mdm.services.android.services.enrollment.EnrollmentService; -import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; -import org.wso2.carbon.mdm.services.android.util.Message; -import javax.ws.rs.*; -import javax.ws.rs.core.Response; - -/** - * Android Device Enrollment REST-API implementation. - * All end points supports JSON, XMl with content negotiation. - */ -@Produces({"application/json", "application/xml"}) -@Consumes({"application/json", "application/xml"}) -public class EnrollmentServiceImpl implements EnrollmentService { - - private static Log log = LogFactory.getLog(EnrollmentService.class); - - @POST - public Response enrollDevice(org.wso2.carbon.device.mgt.common.Device device) - throws AndroidAgentException { - - Message responseMsg = new Message(); - String msg; - try { - device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - device.getEnrolmentInfo().setOwner(AndroidAPIUtils.getAuthenticatedUser()); - boolean status = AndroidAPIUtils.getDeviceManagementService().enrollDevice(device); - if (status) { - Response.status(Response.Status.CREATED); - responseMsg.setResponseMessage("Device enrollment succeeded."); - return Response.status(Response.Status.CREATED).entity(responseMsg).build(); - } else { - Response.status(Response.Status.INTERNAL_SERVER_ERROR); - responseMsg.setResponseMessage("Device enrollment failed."); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(responseMsg).build(); - } - } catch (DeviceManagementException e) { - msg = "Error occurred while enrolling the device"; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } - } - - @GET - @Path("{deviceId}") - public Response isEnrolled(@PathParam("deviceId") String id) throws AndroidAgentException { - String msg; - boolean result; - Message responseMsg = new Message(); - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - - try { - result = AndroidAPIUtils.getDeviceManagementService().isEnrolled(deviceIdentifier); - if (result) { - responseMsg.setResponseMessage("Device has already enrolled"); - responseMsg.setResponseCode(Response.Status.ACCEPTED.toString()); - return Response.status(Response.Status.ACCEPTED).entity(responseMsg).build(); - } else { - responseMsg.setResponseMessage("Device not found"); - responseMsg.setResponseCode(Response.Status.NOT_FOUND.toString()); - return Response.status(Response.Status.NOT_FOUND).entity(responseMsg).build(); - } - } catch (DeviceManagementException e) { - msg = "Error occurred while checking enrollment status of the device."; - responseMsg.setResponseMessage(msg); - responseMsg.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()); - Response.status(Response.Status.INTERNAL_SERVER_ERROR); - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } - } - - @PUT - @Path("{deviceId}") - public Response modifyEnrollment(@PathParam("deviceId") String id, - org.wso2.carbon.device.mgt.common.Device device) - throws AndroidAgentException { - String msg; - boolean result; - Message responseMsg = new Message(); - try { - device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - result = AndroidAPIUtils.getDeviceManagementService().modifyEnrollment(device); - if (result) { - responseMsg.setResponseMessage("Device enrollment has updated successfully"); - responseMsg.setResponseCode(Response.Status.ACCEPTED.toString()); - return Response.status(Response.Status.ACCEPTED).entity(responseMsg).build(); - } else { - responseMsg.setResponseMessage("Device not found for enrollment"); - responseMsg.setResponseCode(Response.Status.NOT_MODIFIED.toString()); - return Response.status(Response.Status.NOT_MODIFIED).entity(responseMsg).build(); - } - } catch (DeviceManagementException e) { - msg = "Error occurred while modifying enrollment of the device"; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } - } - - @DELETE - @Path("{deviceId}") - public Response disEnrollDevice(@PathParam("deviceId") String id) throws AndroidAgentException { - Message responseMsg = new Message(); - boolean result; - String msg; - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - - try { - result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier); - if (result) { - responseMsg.setResponseMessage("Device has removed successfully"); - responseMsg.setResponseCode(Response.Status.ACCEPTED.toString()); - return Response.status(Response.Status.ACCEPTED).entity(responseMsg).build(); - } else { - responseMsg.setResponseMessage("Device not found"); - responseMsg.setResponseCode(Response.Status.NOT_FOUND.toString()); - return Response.status(Response.Status.NOT_FOUND).entity(responseMsg).build(); - } - } catch (DeviceManagementException e) { - msg = "Error occurred while dis enrolling the device"; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).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/event/EventService.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/event/EventService.java deleted file mode 100644 index 30ce612d6..000000000 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/EventService.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.mdm.services.android.services.event; - -import io.swagger.annotations.*; -import org.wso2.carbon.mdm.services.android.bean.DeviceState; -import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; -import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; - -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -/** - * APIs related to events published from Android agent are implemented here. - */ -@Api(value = "EventService", description = "Android Device Management REST-API implementation.") -public interface EventService { - String ACCEPT = "Accept"; - - @POST - @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." - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Event is published successfully."), - @ApiResponse(code = 500, message = "Error occurred while publishing the events from Android agent.") - }) - Response publishEvents(@ApiParam(name = "acceptHeader", value = "Accept Header.") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "eventBeanWrapper", - value = "Information of the agent event to be published on DAS.") - EventBeanWrapper eventBeanWrapper) throws AndroidAgentException; - @GET - @Path("{deviceId}") - @Produces("application/json") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - 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.", - 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.") - }) - Response retrieveAlert(@ApiParam(name = "acceptHeader", value = "Accept Header.") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "deviceId", value = "DeviceId which need to retrieve published events.") - @PathParam("deviceId") String deviceId) throws AndroidAgentException; - - @GET - @Path("{deviceId}/date") - @Produces("application/json") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - 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 = "acceptHeader", value = "Accept Header.") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "deviceId", - value = "Device Identifier to be need to retrieve events.") - @PathParam("deviceId") String deviceId, - @ApiParam(name = "from", value = "From Date.") - @QueryParam("from") long from, - @ApiParam(name = "to", value = "To Date.") - @QueryParam("to") long to) throws AndroidAgentException; - - @GET - @Path("{deviceId}/type/{type}") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - 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 retrieveAlertType(@ApiParam(name = "acceptHeader", value = "Accept Header.") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "deviceId", value = "Device Identifier to be need to retrieve events.") - @PathParam("deviceId") String deviceId, - @ApiParam(name = "type", value = "Type of the Alert to be need to retrieve events.") - @PathParam("type") String type) 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/operationmgt/impl/OperationMgtServiceImpl.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 similarity index 64% rename from components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/operationmgt/impl/OperationMgtServiceImpl.java rename to 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 030f96384..53e77400c 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/operationmgt/impl/OperationMgtServiceImpl.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 @@ -1,141 +1,59 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. */ - -package org.wso2.carbon.mdm.services.android.services.operationmgt.impl; +package org.wso2.carbon.mdm.services.android.services.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; -import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; import org.wso2.carbon.mdm.services.android.bean.*; -import org.wso2.carbon.mdm.services.android.bean.Notification; import org.wso2.carbon.mdm.services.android.bean.wrapper.*; -import org.wso2.carbon.mdm.services.android.services.operationmgt.OperationMgtService; +import org.wso2.carbon.mdm.services.android.services.DeviceManagementAdminService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.AndroidConstants; -import org.wso2.carbon.mdm.services.android.util.AndroidDeviceUtils; import org.wso2.carbon.mdm.services.android.util.Message; -import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; -public class OperationMgtServiceImpl implements OperationMgtService { - - private static Log log = LogFactory.getLog(OperationMgtService.class); - private static final String ACCEPT = "Accept"; - private static final String OPERATION_ERROR_STATUS = "ERROR"; - private static final String DEVICE_TYPE_ANDROID = "android"; - - @PUT - @Path("{id}") - public Response getPendingOperations - (@HeaderParam(ACCEPT) String acceptHeader, @PathParam("id") String id, - List resultOperations) { - Message message; - String errorMessage; - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); - - if (id == null || id.isEmpty()) { - errorMessage = "Device identifier is null or empty, hence returning device not found"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.BAD_REQUEST.toString()).build(); - log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); - } +@Path("/devices") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminService { - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - try { - if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) { - errorMessage = "Device not found for identifier '" + id + "'"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.BAD_REQUEST.toString()).build(); - log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); - } - if (log.isDebugEnabled()) { - log.debug("Invoking Android pending operations:" + id); - } - if (resultOperations != null && !resultOperations.isEmpty()) { - updateOperations(id, resultOperations); - } - } catch (OperationManagementException e) { - errorMessage = "Issue in retrieving operation management service instance"; - log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).type( - responseMediaType).build(); - } catch (PolicyComplianceException e) { - errorMessage = "Issue in updating Monitoring operation"; - log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).type( - responseMediaType).build(); - } catch (DeviceManagementException e) { - errorMessage = "Issue in retrieving device management service instance"; - log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).type( - responseMediaType).build(); - } catch (ApplicationManagementException e) { - errorMessage = "Issue in retrieving application management service instance"; - log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).type( - responseMediaType).build(); - } catch (NotificationManagementException e) { - errorMessage = "Issue in retrieving Notification management service instance"; - log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).type( - responseMediaType).build(); - } - - List pendingOperations; - try { - pendingOperations = AndroidAPIUtils.getPendingOperations(deviceIdentifier); - } catch (OperationManagementException e) { - 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).type( - responseMediaType).build(); - } - return Response.status(Response.Status.CREATED).entity(pendingOperations).type( - responseMediaType).build(); - } + private static final Log log = LogFactory.getLog(DeviceManagementAdminServiceImpl.class); @POST - @Path("lock") - public Response configureDeviceLock(@HeaderParam(ACCEPT) String acceptHeader, - DeviceLockBeanWrapper deviceLockBeanWrapper) { - + @Path("/lock-devices") + @Override + public Response configureDeviceLock(DeviceLockBeanWrapper deviceLockBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking Android device lock operation"); } - - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); Response response; @@ -147,8 +65,7 @@ public class OperationMgtServiceImpl implements OperationMgtService { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_LOCK); @@ -156,34 +73,31 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setEnabled(true); operation.setPayLoad(lock.toJSON()); response = AndroidAPIUtils.getOperationResponse(deviceLockBeanWrapper.getDeviceIDs(), operation, - message, responseMediaType); + message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } return response; } @POST - @Path("unlock") - public Response configureDeviceUnlock(@HeaderParam(ACCEPT) String acceptHeader, List deviceIDs) { - + @Path("/unlock-devices") + @Override + public Response configureDeviceUnlock(List deviceIDs) { if (log.isDebugEnabled()) { log.debug("Invoking Android device unlock operation"); } - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); Response response; @@ -192,66 +106,59 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setCode(AndroidConstants.OperationCodes.DEVICE_UNLOCK); operation.setType(Operation.Type.COMMAND); operation.setEnabled(true); - response = AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message, responseMediaType); + response = AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } return response; } @POST - @Path("location") - public Response getDeviceLocation(@HeaderParam(ACCEPT) String acceptHeader, - List deviceIDs) { + @Path("/get-location") + @Override + public Response getDeviceLocation(List deviceIDs) { if (log.isDebugEnabled()) { log.debug("Invoking Android device location operation"); } - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); 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, responseMediaType); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("clear-password") - public Response removePassword(@HeaderParam(ACCEPT) String acceptHeader, - List deviceIDs) { + @Path("/clear-password") + @Override + public Response removePassword(List deviceIDs) { if (log.isDebugEnabled()) { log.debug("Invoking Android clear password operation"); } - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -259,36 +166,30 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setCode(AndroidConstants.OperationCodes.CLEAR_PASSWORD); operation.setType(Operation.Type.COMMAND); - return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, - message, responseMediaType); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("camera") - public Response configureCamera(@HeaderParam(ACCEPT) String acceptHeader, - CameraBeanWrapper cameraBeanWrapper) { - + @Path("/control-camera") + @Override + public Response configureCamera(CameraBeanWrapper cameraBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking Android Camera operation"); } - - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -306,71 +207,60 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setType(Operation.Type.COMMAND); operation.setEnabled(camera.isEnabled()); - return AndroidAPIUtils.getOperationResponse(cameraBeanWrapper.getDeviceIDs(), operation, message, - responseMediaType); + return AndroidAPIUtils.getOperationResponse(cameraBeanWrapper.getDeviceIDs(), operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("device-info") - public Response getDeviceInformation(@HeaderParam(ACCEPT) String acceptHeader, - List deviceIDs) { - + @Path("/get-device-info") + @Override + public Response getDeviceInformation(List deviceIDs) { if (log.isDebugEnabled()) { log.debug("Invoking get Android device information operation"); } - - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); 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, - responseMediaType); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("enterprise-wipe") - public Response wipeDevice(@HeaderParam(ACCEPT) String acceptHeader, - List deviceIDs) { - + @Path("/enterprise-wipe") + @Override + public Response wipeDevice(List deviceIDs) { if (log.isDebugEnabled()) { log.debug("Invoking enterprise-wipe device operation"); } - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -378,35 +268,30 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setCode(AndroidConstants.OperationCodes.ENTERPRISE_WIPE); operation.setType(Operation.Type.COMMAND); - return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message, - responseMediaType); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("wipe-data") - public Response wipeData(@HeaderParam(ACCEPT) String acceptHeader, - WipeDataBeanWrapper wipeDataBeanWrapper) { - + @Path("/wipe-devices") + @Override + public Response wipeData(WipeDataBeanWrapper wipeDataBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking Android wipe-data device operation"); } - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -421,36 +306,30 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setType(Operation.Type.PROFILE); operation.setPayLoad(wipeData.toJSON()); - return AndroidAPIUtils.getOperationResponse(wipeDataBeanWrapper.getDeviceIDs(), operation, message, - responseMediaType); + return AndroidAPIUtils.getOperationResponse(wipeDataBeanWrapper.getDeviceIDs(), operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("application-list") - public Response getApplications(@HeaderParam(ACCEPT) String acceptHeader, - List deviceIDs) { - + @Path("/get-applications") + @Override + public Response getApplications(List deviceIDs) { if (log.isDebugEnabled()) { log.debug("Invoking Android getApplicationList device operation"); } - - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -458,105 +337,90 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setCode(AndroidConstants.OperationCodes.APPLICATION_LIST); operation.setType(Operation.Type.COMMAND); - return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message, - responseMediaType); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("ring-device") - public Response ringDevice(@HeaderParam(ACCEPT) String acceptHeader, - List deviceIDs) { - + @Path("/ring-devices") + @Override + public Response ringDevice(List deviceIDs) { if (log.isDebugEnabled()) { log.debug("Invoking Android ring-device device operation"); } - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); 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, - responseMediaType); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("reboot-device") - public Response rebootDevice(@HeaderParam(ACCEPT) String acceptHeader, - List deviceIDs) { - + @Path("/reboot-devices") + @Override + public Response rebootDevice(List deviceIDs) { if (log.isDebugEnabled()) { log.debug("Invoking Android reboot-device device operation"); } - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); 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, - responseMediaType); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("mute") - public Response muteDevice(@HeaderParam(ACCEPT) String acceptHeader, - List deviceIDs) { - + @Path("/mute-devices") + @Override + public Response muteDevice(List deviceIDs) { if (log.isDebugEnabled()) { log.debug("Invoking mute device operation"); } - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -564,35 +428,29 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setCode(AndroidConstants.OperationCodes.DEVICE_MUTE); operation.setType(Operation.Type.COMMAND); operation.setEnabled(true); - return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message, - responseMediaType); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("install-application") - public Response installApplication(@HeaderParam(ACCEPT) String acceptHeader, - ApplicationInstallationBeanWrapper applicationInstallationBeanWrapper) { - + @Path("/install-application") + @Override + public Response installApplication(ApplicationInstallationBeanWrapper applicationInstallationBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking 'InstallApplication' operation"); } - - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -606,8 +464,7 @@ public class OperationMgtServiceImpl implements OperationMgtService { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } ProfileOperation operation = new ProfileOperation(); @@ -616,34 +473,30 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setPayLoad(applicationInstallation.toJSON()); return AndroidAPIUtils.getOperationResponse(applicationInstallationBeanWrapper.getDeviceIDs(), - operation, message, responseMediaType); + operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("update-application") - public Response updateApplication(@HeaderParam(ACCEPT) String acceptHeader, - ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper) { - + @Path("/update-application") + @Override + public Response updateApplication(ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking 'UpdateApplication' operation"); } - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -657,8 +510,7 @@ public class OperationMgtServiceImpl implements OperationMgtService { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } ProfileOperation operation = new ProfileOperation(); @@ -667,33 +519,30 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setPayLoad(applicationUpdate.toJSON()); return AndroidAPIUtils.getOperationResponse(applicationUpdateBeanWrapper.getDeviceIDs(), - operation, message, responseMediaType); + operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("uninstall-application") - public Response uninstallApplication(@HeaderParam(ACCEPT) String acceptHeader, - ApplicationUninstallationBeanWrapper applicationUninstallationBeanWrapper) { + @Path("/uninstall-application") + @Override + public Response uninstallApplication(ApplicationUninstallationBeanWrapper applicationUninstallationBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking 'UninstallApplication' operation"); } - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -707,8 +556,7 @@ public class OperationMgtServiceImpl implements OperationMgtService { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } ProfileOperation operation = new ProfileOperation(); @@ -717,33 +565,30 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setPayLoad(applicationUninstallation.toJSON()); return AndroidAPIUtils.getOperationResponse(applicationUninstallationBeanWrapper.getDeviceIDs(), - operation, message, responseMediaType); + operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("blacklist-applications") - public Response blacklistApplications(@HeaderParam(ACCEPT) String acceptHeader, - BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper) { + @Path("/blacklist-applications") + @Override + public Response blacklistApplications(BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking 'Blacklist-Applications' operation"); } - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -757,8 +602,7 @@ public class OperationMgtServiceImpl implements OperationMgtService { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } ProfileOperation operation = new ProfileOperation(); @@ -767,35 +611,30 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setPayLoad(blacklistApplications.toJSON()); return AndroidAPIUtils.getOperationResponse(blacklistApplicationsBeanWrapper.getDeviceIDs(), - operation, message, responseMediaType); + operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("upgrade-firmware") - public Response upgradeFirmware(@HeaderParam(ACCEPT) String acceptHeader, - UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper) { - + @Path("/upgrade-firmware") + @Override + public Response upgradeFirmware(UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking Android upgrade-firmware device operation"); } - - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -809,8 +648,7 @@ public class OperationMgtServiceImpl implements OperationMgtService { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } ProfileOperation operation = new ProfileOperation(); @@ -818,34 +656,29 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setType(Operation.Type.PROFILE); operation.setPayLoad(upgradeFirmware.toJSON()); return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), - operation, message, responseMediaType); + operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("vpn") - public Response configureVPN(@HeaderParam(ACCEPT) String acceptHeader, - VpnBeanWrapper vpnBeanWrapper) { - + @Path("/configure-vpn") + @Override + public Response configureVPN(VpnBeanWrapper vpnBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking Android VPN device operation"); } - - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -859,8 +692,7 @@ public class OperationMgtServiceImpl implements OperationMgtService { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } ProfileOperation operation = new ProfileOperation(); @@ -868,33 +700,29 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setType(Operation.Type.PROFILE); operation.setPayLoad(vpn.toJSON()); return AndroidAPIUtils.getOperationResponse(vpnBeanWrapper.getDeviceIDs(), - operation, message, responseMediaType); + operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("notification") - public Response sendNotification(@HeaderParam(ACCEPT) String acceptHeader, - NotificationBeanWrapper notificationBeanWrapper) { + @Path("/send-notification") + @Override + public Response sendNotification(NotificationBeanWrapper notificationBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking 'notification' operation"); } - - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -908,8 +736,7 @@ public class OperationMgtServiceImpl implements OperationMgtService { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } ProfileOperation operation = new ProfileOperation(); @@ -918,34 +745,30 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setPayLoad(notification.toJSON()); return AndroidAPIUtils.getOperationResponse(notificationBeanWrapper.getDeviceIDs(), - operation, message, responseMediaType); + operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("wifi") - public Response configureWifi(@HeaderParam(ACCEPT) String acceptHeader, - WifiBeanWrapper wifiBeanWrapper) { + @Path("/configure-wifi") + @Override + public Response configureWifi(WifiBeanWrapper wifiBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking 'configure wifi' operation"); } - - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -959,8 +782,7 @@ public class OperationMgtServiceImpl implements OperationMgtService { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } ProfileOperation operation = new ProfileOperation(); @@ -969,34 +791,30 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setPayLoad(wifi.toJSON()); return AndroidAPIUtils.getOperationResponse(wifiBeanWrapper.getDeviceIDs(), - operation, message, responseMediaType); + operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("encrypt") - public Response encryptStorage(@HeaderParam(ACCEPT) String acceptHeader, - EncryptionBeanWrapper encryptionBeanWrapper) { + @Path("/encrypt-storage") + @Override + public Response encryptStorage(EncryptionBeanWrapper encryptionBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking 'encrypt' operation"); } - - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -1010,8 +828,7 @@ public class OperationMgtServiceImpl implements OperationMgtService { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } CommandOperation operation = new CommandOperation(); @@ -1020,34 +837,31 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setEnabled(deviceEncryption.isEncrypted()); return AndroidAPIUtils.getOperationResponse(encryptionBeanWrapper.getDeviceIDs(), - operation, message, responseMediaType); + operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("change-lock-code") - public Response changeLockCode(@HeaderParam(ACCEPT) String acceptHeader, - LockCodeBeanWrapper lockCodeBeanWrapper) { + @Path("/change-lock-code") + @Override + public Response changeLockCode(LockCodeBeanWrapper lockCodeBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking 'change lock code' operation"); } - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -1061,8 +875,7 @@ public class OperationMgtServiceImpl implements OperationMgtService { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } ProfileOperation operation = new ProfileOperation(); @@ -1071,34 +884,30 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setPayLoad(lockCode.toJSON()); return AndroidAPIUtils.getOperationResponse(lockCodeBeanWrapper.getDeviceIDs(), - operation, message, responseMediaType); + operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("password-policy") - public Response setPasswordPolicy(@HeaderParam(ACCEPT) String acceptHeader, - PasswordPolicyBeanWrapper passwordPolicyBeanWrapper) { + @Path("/set-password-policy") + @Override + public Response setPasswordPolicy(PasswordPolicyBeanWrapper passwordPolicyBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking 'password policy' operation"); } - - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -1112,8 +921,7 @@ public class OperationMgtServiceImpl implements OperationMgtService { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } ProfileOperation operation = new ProfileOperation(); @@ -1122,34 +930,30 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setPayLoad(passcodePolicy.toJSON()); return AndroidAPIUtils.getOperationResponse(passwordPolicyBeanWrapper.getDeviceIDs(), - operation, message, responseMediaType); + operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } @POST - @Path("webclip") - public Response setWebClip(@HeaderParam(ACCEPT) String acceptHeader, - WebClipBeanWrapper webClipBeanWrapper) { + @Path("set-webclip") + @Override + public Response setWebClip(WebClipBeanWrapper webClipBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking 'webclip' operation"); } - - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message message = new Message(); try { @@ -1163,8 +967,7 @@ public class OperationMgtServiceImpl implements OperationMgtService { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } ProfileOperation operation = new ProfileOperation(); @@ -1173,100 +976,21 @@ public class OperationMgtServiceImpl implements OperationMgtService { operation.setPayLoad(webClip.toJSON()); return AndroidAPIUtils.getOperationResponse(webClipBeanWrapper.getDeviceIDs(), - operation, message, responseMediaType); - - } 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).type( - responseMediaType).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).type( - responseMediaType).build(); - } - } - - @POST - @Path("disenroll") - public Response setDisenrollment(@HeaderParam(ACCEPT) String acceptHeader, - DisenrollmentBeanWrapper disenrollmentBeanWrapper) { - - if (log.isDebugEnabled()) { - log.debug("Invoking Android device disenrollment operation"); - } - - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); - Message message = new Message(); - - try { - Disenrollment disenrollment = disenrollmentBeanWrapper.getOperation(); - - if (disenrollment == null) { - if (log.isDebugEnabled()) { - log.debug("The payload of the device disenrollment operation is incorrect"); - } - String errorMessage = "Issue in creating a new disenrollment instance"; - message = Message.responseMessage(errorMessage). - responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); - log.error(errorMessage); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( - responseMediaType).build(); - } - - CommandOperation operation = new CommandOperation(); - operation.setCode(AndroidConstants.OperationCodes.DISENROLL); - operation.setType(Operation.Type.COMMAND); - operation.setEnabled(disenrollment.isEnabled()); - - return AndroidAPIUtils.getOperationResponse(disenrollmentBeanWrapper.getDeviceIDs(), operation, - message, responseMediaType); + operation, message); } 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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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).type( - responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); } } - private void updateOperations(String deviceId, List operations) - throws OperationManagementException, PolicyComplianceException, - ApplicationManagementException, NotificationManagementException, DeviceManagementException { - for (org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation : operations) { - AndroidAPIUtils.updateOperation(deviceId, operation); - if (operation.getStatus().equals(OPERATION_ERROR_STATUS)) { - org.wso2.carbon.device.mgt.common.notification.mgt.Notification notification = new - org.wso2.carbon.device.mgt.common.notification.mgt.Notification(); - DeviceIdentifier id = new DeviceIdentifier(); - id.setId(deviceId); - id.setType(DEVICE_TYPE_ANDROID); - String deviceName = AndroidAPIUtils.getDeviceManagementService().getDevice(id).getName(); - notification.setOperationId(operation.getId()); - notification.setStatus(org.wso2.carbon.device.mgt.common.notification.mgt.Notification. - Status.NEW.toString()); - notification.setDeviceIdentifier(id); - notification.setDescription("Operation " + operation.getCode() + " failed to execute on device " + - deviceName + ". Device ID : " + deviceId); - AndroidAPIUtils.getNotificationManagementService().addNotification(notification); - } - if (log.isDebugEnabled()) { - log.debug("Updating operation '" + operation.toString() + "'"); - } - } - } } 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 new file mode 100644 index 000000000..c7111459c --- /dev/null +++ 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 @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.mdm.services.android.services.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; +import org.wso2.carbon.mdm.services.android.services.DeviceManagementService; +import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; +import org.wso2.carbon.mdm.services.android.util.AndroidConstants; +import org.wso2.carbon.mdm.services.android.util.AndroidDeviceUtils; +import org.wso2.carbon.mdm.services.android.util.Message; +import org.wso2.carbon.policy.mgt.common.PolicyManagementException; +import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; +import org.wso2.carbon.policy.mgt.core.PolicyManagerService; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; + +@Path("/devices") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class DeviceManagementServiceImpl implements DeviceManagementService { + + private static final String OPERATION_ERROR_STATUS = "ERROR"; + private static final Log log = LogFactory.getLog(DeviceManagementServiceImpl.class); + + @PUT + @Path("/{id}/applications") + @Override + public Response updateApplicationList(@PathParam("id") String id, List applications) { + Message responseMessage = new Message(); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(id); + deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + try { + AndroidAPIUtils.getApplicationManagerService(). + updateApplicationListInstalledInDevice(deviceIdentifier, applications); + responseMessage.setResponseMessage("Device information has modified successfully."); + return Response.status(Response.Status.ACCEPTED).entity(responseMessage).build(); + } catch (ApplicationManagementException e) { + String msg = "Error occurred while modifying the application list."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } + + @GET + @Path("/{id}/pending-operations") + @Override + public Response getPendingOperations(@PathParam("id") String id, List resultOperations) { + if (id == null || id.isEmpty()) { + String msg = "Device identifier is null or empty, hence returning device not found"; + log.error(msg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + try { + if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) { + String msg = "Device not found for identifier '" + id + "'"; + log.error(msg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + if (log.isDebugEnabled()) { + log.debug("Invoking Android pending operations:" + id); + } + if (resultOperations != null && !resultOperations.isEmpty()) { + updateOperations(id, resultOperations); + } + } catch (OperationManagementException e) { + String msg = "Issue in retrieving operation management service instance"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (PolicyComplianceException e) { + String msg = "Issue in updating Monitoring operation"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (DeviceManagementException e) { + String msg = "Issue in retrieving device management service instance"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (ApplicationManagementException e) { + String msg = "Issue in retrieving application management service instance"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (NotificationManagementException e) { + String msg = "Issue in retrieving Notification management service instance"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + + List pendingOperations; + try { + pendingOperations = AndroidAPIUtils.getPendingOperations(deviceIdentifier); + } catch (OperationManagementException e) { + String msg = "Issue in retrieving operation management service instance"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + return Response.status(Response.Status.CREATED).entity(pendingOperations).build(); + } + + private void updateOperations(String deviceId, List operations) + throws OperationManagementException, PolicyComplianceException, + ApplicationManagementException, NotificationManagementException, DeviceManagementException { + for (org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation : operations) { + AndroidAPIUtils.updateOperation(deviceId, operation); + if (OPERATION_ERROR_STATUS.equals(operation.getStatus().toString())) { + org.wso2.carbon.device.mgt.common.notification.mgt.Notification notification = new + org.wso2.carbon.device.mgt.common.notification.mgt.Notification(); + DeviceIdentifier id = new DeviceIdentifier(); + id.setId(deviceId); + id.setType(AndroidConstants.DEVICE_TYPE_ANDROID); + String deviceName = AndroidAPIUtils.getDeviceManagementService().getDevice(id).getName(); + notification.setOperationId(operation.getId()); + notification.setStatus(org.wso2.carbon.device.mgt.common.notification.mgt.Notification. + Status.NEW.toString()); + notification.setDeviceIdentifier(id); + notification.setDescription("Operation " + operation.getCode() + " failed to execute on device " + + deviceName + ". Device ID : " + deviceId); + AndroidAPIUtils.getNotificationManagementService().addNotification(notification); + } + if (log.isDebugEnabled()) { + log.debug("Updating operation '" + operation.toString() + "'"); + } + } + } + + @POST + @Override + public Response enrollDevice(Device device) { + try { + device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + device.getEnrolmentInfo().setOwner(AndroidAPIUtils.getAuthenticatedUser()); + boolean status = AndroidAPIUtils.getDeviceManagementService().enrollDevice(device); + + PolicyManagerService policyManagerService = AndroidAPIUtils.getPolicyManagerService(); + policyManagerService.getEffectivePolicy(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); + if (status) { + return Response.status(Response.Status.OK).entity("Android device, which carries the id '" + + device.getDeviceIdentifier() + "' has successfully been enrolled").build(); + } else { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Failed to enroll '" + + device.getType() + "' device, which carries the id '" + + device.getDeviceIdentifier() + "'").build(); + } + } catch (DeviceManagementException e) { + String msg = "Error occurred while enrolling the '" + device.getType() + "', which carries the id '" + + device.getDeviceIdentifier() + "'"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (PolicyManagementException e) { + String msg = "Error occurred while enforcing default enrollment policy upon '" + device.getType() + + "', which carries the id '" + + device.getDeviceIdentifier() + "'"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } + + @GET + @Path("/{id}/status") + @Override + public Response isEnrolled(@PathParam("id") String id) { + boolean result; + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + try { + result = AndroidAPIUtils.getDeviceManagementService().isEnrolled(deviceIdentifier); + if (result) { + return Response.status(Response.Status.OK).entity("Android device that carries the id '" + + id + "' is enrolled").build(); + } else { + return Response.status(Response.Status.NOT_FOUND).entity("No Android device is found upon the id '" + + id + "'").build(); + } + } catch (DeviceManagementException e) { + String msg = "Error occurred while checking enrollment status of the device."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } + + @PUT + @Path("/{id}") + @Override + public Response modifyEnrollment(@PathParam("id") String id, Device device) { + boolean result; + try { + device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + result = AndroidAPIUtils.getDeviceManagementService().modifyEnrollment(device); + if (result) { + return Response.status(Response.Status.ACCEPTED).entity("Enrollment of Android device that " + + "carries the id '" + id + "' has successfully updated").build(); + } else { + return Response.status(Response.Status.NOT_MODIFIED).entity("Enrollment of Android device that " + + "carries the id '" + id + "' has not been updated").build(); + } + } catch (DeviceManagementException e) { + String msg = "Error occurred while modifying enrollment of the Android device that carries the id '" + + id + "'"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } + + @DELETE + @Path("/{id}") + @Override + public Response disEnrollDevice(@PathParam("id") String id) { + boolean result; + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + try { + result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier); + if (result) { + return Response.status(Response.Status.OK).entity("Android device that carries id '" + id + + "' has successfully dis-enrolled").build(); + } else { + return Response.status(Response.Status.NOT_FOUND).entity("Android device that carries id '" + id + + "' has not been dis-enrolled").build(); + } + } catch (DeviceManagementException e) { + String msg = "Error occurred while dis-enrolling the Android device that carries the id '" + id + "'"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).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/configuration/impl/ConfigurationMgtServiceImpl.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 similarity index 81% rename from components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/configuration/impl/ConfigurationMgtServiceImpl.java rename to 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 9517f88e4..3b944b33b 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/configuration/impl/ConfigurationMgtServiceImpl.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 @@ -1,22 +1,22 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. */ - -package org.wso2.carbon.mdm.services.android.services.configuration.impl; +package org.wso2.carbon.mdm.services.android.services.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -26,28 +26,27 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; -import org.wso2.carbon.mdm.services.android.services.configuration.ConfigurationMgtService; +import org.wso2.carbon.mdm.services.android.services.DeviceTypeConfigurationService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.AndroidConstants; import org.wso2.carbon.mdm.services.android.util.Message; + import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.ArrayList; import java.util.List; -/** - * Android Platform Configuration REST-API implementation. - * All end points supports JSON, XMl with content negotiation. - */ -@Produces({"application/json", "application/xml"}) -@Consumes({"application/json", "application/xml"}) -public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { - private static Log log = LogFactory.getLog(ConfigurationMgtServiceImpl.class); +@Path("/configuration") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurationService { - @POST - public Response configureSettings(TenantConfiguration configuration) - throws AndroidAgentException { + private static final Log log = LogFactory.getLog(DeviceTypeConfigurationServiceImpl.class); + @POST + @Override + public Response addConfiguration(TenantConfiguration configuration) throws AndroidAgentException { Message responseMsg = new Message(); String msg; ConfigurationEntry licenseEntry = null; @@ -85,6 +84,7 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { } @GET + @Override public Response getConfiguration() throws AndroidAgentException { String msg; TenantConfiguration tenantConfiguration = null; @@ -102,7 +102,7 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { ConfigurationEntry entry = new ConfigurationEntry(); License license = AndroidAPIUtils.getDeviceManagementService().getLicense( DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, AndroidConstants. - TenantConfigProperties.LANGUAGE_US); + TenantConfigProperties.LANGUAGE_US); if (license != null && configs != null) { entry.setContentType(AndroidConstants.TenantConfigProperties.CONTENT_TYPE_TEXT); @@ -120,6 +120,7 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { } @PUT + @Override public Response updateConfiguration(TenantConfiguration configuration) throws AndroidAgentException { String msg; Message responseMsg = new Message(); @@ -145,7 +146,7 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { } configuration.setConfiguration(configs); AndroidAPIUtils.getDeviceManagementService().saveConfiguration(configuration); - AndroidAPIUtils.getGCMService().resetTenantConfigCache(); + //AndroidAPIUtils.getGCMService().resetTenantConfigCache(); Response.status(Response.Status.ACCEPTED); responseMsg.setResponseMessage("Android platform configuration has updated successfully."); responseMsg.setResponseCode(Response.Status.ACCEPTED.toString()); 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/event/impl/EventServiceImpl.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 similarity index 64% rename from components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/impl/EventServiceImpl.java rename to 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 16d80297d..177875a1c 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/event/impl/EventServiceImpl.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 @@ -1,22 +1,22 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. */ - -package org.wso2.carbon.mdm.services.android.services.event.impl; +package org.wso2.carbon.mdm.services.android.services.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -24,8 +24,7 @@ import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; import org.wso2.carbon.mdm.services.android.bean.DeviceState; import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; -import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; -import org.wso2.carbon.mdm.services.android.services.event.EventService; +import org.wso2.carbon.mdm.services.android.services.EventReceiverService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.Message; @@ -34,21 +33,22 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; -public class EventServiceImpl implements EventService { +@Path("/events") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class EventReceiverServiceImpl implements EventReceiverService { - private static final String ACCEPT = "Accept"; - private static Log log = LogFactory.getLog(EventService.class); private static final String EVENT_STREAM_DEFINITION = "android_agent"; + private static final Log log = LogFactory.getLog(EventReceiverServiceImpl.class); @POST - public Response publishEvents(@HeaderParam(ACCEPT) String acceptHeader, - EventBeanWrapper eventBeanWrapper) throws AndroidAgentException { - + @Path("/publish-event") + @Override + public Response publishEvents(EventBeanWrapper eventBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking Android device even logging."); } Message message = new Message(); - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Object payload[] = {eventBeanWrapper.getDeviceIdentifier(), eventBeanWrapper.getPayload(), eventBeanWrapper.getType()}; @@ -56,37 +56,33 @@ public class EventServiceImpl implements EventService { if (AndroidAPIUtils.getEventPublisherService().publishEvent( EVENT_STREAM_DEFINITION, "1.0.0", new Object[0], new Object[0], payload)) { message.setResponseCode("Event is published successfully."); - return Response.status(Response.Status.CREATED).entity(message).type(responseMediaType).build(); + return Response.status(Response.Status.CREATED).entity(message).build(); } else { message.setResponseCode("Error occurred while publishing the event."); return Response.status(Response.Status.INTERNAL_SERVER_ERROR). - entity(message).type(responseMediaType).build(); + entity(message).build(); } } catch (DataPublisherConfigurationException e) { String msg = "Error occurred while publishing the events from Android agent."; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } - @Path("{deviceId}") - @Produces("application/json") @GET - public Response retrieveAlert(@HeaderParam(ACCEPT) String acceptHeader, - @PathParam("deviceId") String deviceId) throws AndroidAgentException { - + @Override + public Response retrieveAlert(@QueryParam("id") String deviceId) { if (log.isDebugEnabled()) { log.debug("Retrieving events for given device Identifier."); } Message message = new Message(); - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); String query = "deviceIdentifier:" + deviceId; List deviceStates; try { 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).type(responseMediaType).build(); + return Response.status(Response.Status.OK).entity(message).build(); } else { return Response.status(Response.Status.OK).entity(deviceStates).build(); @@ -95,23 +91,20 @@ public class EventServiceImpl implements EventService { 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).type(responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } - @Path("{deviceId}/date") - @Produces("application/json") @GET - public Response retrieveAlertFromDate(@HeaderParam(ACCEPT) String acceptHeader, - @PathParam("deviceId") String deviceId, @QueryParam("from") long from, - @QueryParam("to") long to) throws AndroidAgentException { + @Override + public Response retrieveAlertFromDate(@QueryParam("id") String deviceId, @QueryParam("from") long from, + @QueryParam("to") long to) { String fromDate = String.valueOf(from); String toDate = String.valueOf(to); if (log.isDebugEnabled()) { log.debug("Retrieving events for given device Identifier and time period."); } Message message = new Message(); - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); String query = "deviceIdentifier:" + deviceId + " AND _timestamp: [" + fromDate + " TO " + toDate + "]"; List deviceStates; @@ -123,27 +116,23 @@ public class EventServiceImpl implements EventService { return Response.status(Response.Status.OK).entity(message).build(); } else { - return Response.status(Response.Status.OK).entity(deviceStates).type(responseMediaType).build(); + return Response.status(Response.Status.OK).entity(deviceStates).build(); } } catch (AnalyticsException e) { String msg = "Error occurred while getting published events for specific " + "Device: " + deviceId + " on given Date."; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } - @Path("{deviceId}/type/{type}") @GET - public Response retrieveAlertType(@HeaderParam(ACCEPT) String acceptHeader, - @PathParam("deviceId") String deviceId, @PathParam("type") String type) - throws AndroidAgentException { - + @Override + public Response retrieveAlertByType(@QueryParam("id") String deviceId, @QueryParam("type") String type) { if (log.isDebugEnabled()) { log.debug("Retrieving events for given device identifier and type."); } Message message = new Message(); - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); String query = "deviceIdentifier:" + deviceId + " AND type:" + type; List deviceStates; try { @@ -154,14 +143,14 @@ public class EventServiceImpl implements EventService { return Response.status(Response.Status.OK).entity(message).build(); } else { - return Response.status(Response.Status.OK).entity(deviceStates).type(responseMediaType).build(); + return Response.status(Response.Status.OK).entity(deviceStates).build(); } } catch (AnalyticsException e) { String msg = "Error occurred while getting published events for specific " + "Device: " + deviceId + "and given device Type."; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).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/operationmgt/OperationMgtService.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/operationmgt/OperationMgtService.java deleted file mode 100644 index 0eec30f25..000000000 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/operationmgt/OperationMgtService.java +++ /dev/null @@ -1,506 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.mdm.services.android.services.operationmgt; - -import io.swagger.annotations.*; -import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; -import org.wso2.carbon.mdm.services.android.bean.wrapper.*; - -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.List; - -/** - * Android Device Operation REST-API implementation. - */ - -@Api(value = "OperationMgtService", description = "Android Device Operation REST-API implementation.") -public interface OperationMgtService { - String ACCEPT = "Accept"; - - @PUT - @Path("{id}") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "PUT", - value = "Getting Pending Android Device Operations", - responseContainer = "List", - notes = "The Android agent communicates with the server to get the operations that are queued up " + - "at the server end for a given device using this REST API", - response = Operation.class) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "List of pending operations"), - @ApiResponse(code = 500, message = "Issue in retrieving operation management service instance") - }) - Response getPendingOperations( - @ApiParam(name = "acceptHeader", value = "Accept Header") @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "id", value = "DeviceIdentifier") @PathParam("id") String id, - @ApiParam(name = "resultOperations", value = "Device Operation Status") - List resultOperations); - - @POST - @Path("lock") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - 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" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response configureDeviceLock(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "cameraBeanWrapper", - value = "Device lock configurations with device IDs") DeviceLockBeanWrapper deviceLockBeanWrapper); - - @POST - @Path("unlock") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Adding a Device Unlock on Android Devices", - responseContainer = "List", - notes = "Using this API you have the option of unlocking an Android device, where the Administrator " + - "unlocks the device", - response = String.class) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response configureDeviceUnlock(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "deviceIDs", value = - "DeviceIds to be enable device unlock operation") - List deviceIDs); - - - @POST - @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) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "Requested Device Coordinates"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance")}) - Response getDeviceLocation(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "deviceIDs", - value = "DeviceIDs to be requested to get device location") - List deviceIDs); - - @POST - @Path("clear-password") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Clearing the Password on Android Devices", - notes = "Clear the password on Android devices" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response removePassword(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "deviceIDs", - value = "DeviceIds to be requested to remove password") - List deviceIDs); - - @POST - @Path("camera") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Enabling or Disabling the Camera on Android Devices", - notes = "Enable or disable the camera on Android devices" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in creating a new camera instance") - }) - Response configureCamera(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "cameraBeanWrapper", - value = "Camera enable/disable configurations with device IDs") CameraBeanWrapper cameraBeanWrapper); - - @POST - @Path("device-info") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - 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" - ) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "Device Information"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response getDeviceInformation(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "deviceIds", - value = "Device IDs to be requested to get device information") - List deviceIDs); - - @POST - @Path("enterprise-wipe") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - 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" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance" - )}) - Response wipeDevice(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "deviceIDs", - value = "Device IDs to be requested to done enterprise-wipe") - List deviceIDs); - - @POST - @Path("wipe-data") - @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" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance")}) - Response wipeData(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "wipeDataBeanWrapper", - value = "Configurations and DeviceIds to be need to done wipe-data") - WipeDataBeanWrapper wipeDataBeanWrapper); - - @POST - @Path("application-list") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Requesting the List of Installed Applications on Android Devices", - 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" - ) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "List of applications for specific deviceIdentifier"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response getApplications(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "deviceIDs", - value = "Device Ids to be need to get applications which already installed") - List deviceIDs); - - @POST - @Path("ring-device") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Ringing Android Devices", - notes = "Ring Android devices" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response ringDevice(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "deviceIDs", - value = "Device Ids needs to be ring") List deviceIDs); - - @POST - @Path("reboot-device") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Rebooting Android Devices", - notes = "Reboot Android devices" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response rebootDevice(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "deviceIDs", - value = "Device Ids needs to be rebooted") List deviceIDs); - - @POST - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Muting Android Devices", - notes = "Mute Android devices" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - @Path("mute") - Response muteDevice(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "deviceIDs", value = "DeviceIDs need to be muted") List deviceIDs); - - @POST - @Path("install-application") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - 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" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response installApplication(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "applicationInstallationBeanWrapper", - value = "Properties of installed apps and device IDs") - ApplicationInstallationBeanWrapper applicationInstallationBeanWrapper); - - @POST - @Path("update-application") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - 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" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response updateApplication(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "applicationUpdateBeanWrapper", - value = "Properties of updated apps and device IDs") - ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper); - - @POST - @Path("uninstall-application") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Uninstalling an Application from Android Devices", - notes = "Uninstall an application from Android devices" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response uninstallApplication(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "applicationUninstallationBeanWrapper", - value = "applicationUninstallationConfigs and Device Ids") - ApplicationUninstallationBeanWrapper applicationUninstallationBeanWrapper); - - @POST - @Path("blacklist-applications") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Get BlackListed Applications", - notes = "Getting BlackListed Applications" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response blacklistApplications(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "blacklistApplicationsBeanWrapper", - value = "BlacklistApplications Configuration and DeviceIds") - BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper); - - @POST - @Path("upgrade-firmware") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Upgrading device firmware", - notes = "Device firmware upgrade" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response upgradeFirmware(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "upgradeFirmwareBeanWrapper", - value = "Firmware upgrade configuration and DeviceIds") - UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper); - - @POST - @Path("vpn") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Configuring VPN on Android devices", - notes = "Configure VPN on Android devices" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response configureVPN(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "vpnBeanWrapper", - value = "VPN configuration and DeviceIds") - VpnBeanWrapper vpnBeanWrapper); - - @POST - @Path("notification") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Sending a Notification to Android Devices", - notes = "Send a notification to Android devices" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response sendNotification(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "notificationBeanWrapper", - value = "Notification Configurations and device Ids") - NotificationBeanWrapper notificationBeanWrapper); - - @POST - @Path("wifi") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Configuring Wi-Fi on Android Devices", - notes = "Configure Wi-Fi on Android devices" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response configureWifi(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "wifiBeanWrapper", - value = "WifiConfigurations and Device Ids") WifiBeanWrapper wifiBeanWrapper); - - @POST - @Path("encrypt") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Encrypting Storage on Android Devices", - notes = "Encrypt the data stored on Android devices" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response encryptStorage(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "encryptionBeanWrapper", - value = "Configurations and deviceIds need to be done data encryption") - EncryptionBeanWrapper encryptionBeanWrapper); - - @POST - @Path("change-lock-code") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Changing the Lock Code on Android Devices", - notes = "Change the lock code on Android devices" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response changeLockCode(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "lockCodeBeanWrapper", - value = "Configurations and device Ids need to be done change lock code") - LockCodeBeanWrapper lockCodeBeanWrapper); - - @POST - @Path("password-policy") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Setting a Passcode Policy on Android Devices", - notes = "Set a password policy on Android devices" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "created"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response setPasswordPolicy(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "passwordPolicyBeanWrapper", - value = "Password Policy Configurations and Device Ids") - PasswordPolicyBeanWrapper passwordPolicyBeanWrapper); - - @POST - @Path("webclip") - @ApiOperation( - 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" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Accepted"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response setWebClip(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "webClipBeanWrapper", - value = "Configurations to need set web clip on device and device Ids") - WebClipBeanWrapper webClipBeanWrapper); - - @POST - @Path("disenroll") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Un-Register The Device from the EMM server", - notes = "unregister the given device" - ) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "Accepted"), - @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") - }) - Response setDisenrollment(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam(ACCEPT) String acceptHeader, - @ApiParam(name = "disenrollmentBeanWrapper", value = "Dis-enrollment configurations") - DisenrollmentBeanWrapper disenrollmentBeanWrapper); -} 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/policymgt/PolicyMgtService.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/policymgt/PolicyMgtService.java deleted file mode 100644 index adcb2228f..000000000 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/policymgt/PolicyMgtService.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.mdm.services.android.services.policymgt; - -import io.swagger.annotations.*; -import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; -import org.wso2.carbon.mdm.services.android.util.Message; -import org.wso2.carbon.policy.mgt.common.ProfileFeature; - -import javax.jws.WebService; -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.List; - -@Api(value = "PolicyMgtService", description = "Policy management related REST-API implementation.") -@WebService -@Produces({"application/json", "application/xml"}) -@Consumes({"application/json", "application/xml"}) -public interface PolicyMgtService { - - @GET - @Path("{deviceId}") - @ApiOperation( - httpMethod = "GET", - value = "Identifying whether a Policy is Enforced on an Android Device", - notes = "When a device registers with WSO2 EMM, a policy is enforced on the device based on the policy " + - "enforcement criteria. Using this API you are able to identify if a specific device has a policy " + - "enforced or if no policy is enforced on the device." - ) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "Effective policy added to operation"), - @ApiResponse(code = 204, message = "No effective policy found") - }) - Response getEffectivePolicy(@ApiParam(name = "acceptHeader", value = "Accept Header") @HeaderParam("Accept") - String acceptHeader, - @ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") - String id) throws AndroidAgentException; - - @GET - @Path("/features/{deviceId}") - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Get Effective Features", - responseContainer = "List", - notes = "Get already applied features for given device Identifier", - response = ProfileFeature.class) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "Effective Feature List"), - @ApiResponse(code = 404, message = "Not Found"), - @ApiResponse(code = 500, message = "Error occurred while getting the features") - }) - Response getEffectiveFeatures(@ApiParam(name = "acceptHeader", value = "Accept Header") - @HeaderParam("Accept") String acceptHeader, - @ApiParam(name = "deviceId", value = "DeviceIdentifier") - @PathParam("deviceId") String id) 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/policymgt/impl/PolicyMgtServiceImpl.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/policymgt/impl/PolicyMgtServiceImpl.java deleted file mode 100644 index 33d9c1603..000000000 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/policymgt/impl/PolicyMgtServiceImpl.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.mdm.services.android.services.policymgt.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; -import org.wso2.carbon.mdm.services.android.services.policymgt.PolicyMgtService; -import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; -import org.wso2.carbon.mdm.services.android.util.Message; -import org.wso2.carbon.policy.mgt.common.FeatureManagementException; -import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.PolicyManagementException; -import org.wso2.carbon.policy.mgt.common.ProfileFeature; -import org.wso2.carbon.policy.mgt.core.PolicyManagerService; - -import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.List; - -public class PolicyMgtServiceImpl implements PolicyMgtService { - private static Log log = LogFactory.getLog(PolicyMgtService.class); - - @GET - @Path("{deviceId}") - public Response getEffectivePolicy(@HeaderParam("Accept") String acceptHeader, - @PathParam("deviceId") String id) throws AndroidAgentException { - - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); - Message responseMessage = new Message(); - Policy policy; - try { - PolicyManagerService policyManagerService = AndroidAPIUtils.getPolicyManagerService(); - policy = policyManagerService.getEffectivePolicy(deviceIdentifier); - if (policy == null) { - responseMessage = Message.responseMessage("No effective policy found"). - responseCode(Response.Status.NO_CONTENT.toString()).build(); - return Response.status(Response.Status.NO_CONTENT).entity(responseMessage).type( - responseMediaType).build(); - } else { - responseMessage = Message.responseMessage("Effective policy added to operation"). - responseCode(Response.Status.OK.toString()).build(); - return Response.status(Response.Status.OK).entity(responseMessage).type( - responseMediaType).build(); - } - } catch (PolicyManagementException e) { - String msg = "Error occurred while getting the policy."; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type( - responseMediaType).build(); - } - } - - @GET - @Path("/features/{deviceId}") - public Response getEffectiveFeatures(@HeaderParam("Accept") String acceptHeader, - @PathParam("deviceId") String id) throws AndroidAgentException { - List profileFeatures; - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); - try { - PolicyManagerService policyManagerService = AndroidAPIUtils.getPolicyManagerService(); - profileFeatures = policyManagerService.getEffectiveFeatures(deviceIdentifier); - if (profileFeatures == null) { - Response.status(Response.Status.NOT_FOUND); - return Response.status(Response.Status.NOT_FOUND).type( - responseMediaType).build(); - } - } catch (FeatureManagementException e) { - String msg = "Error occurred while getting the features."; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type( - responseMediaType).build(); - } - return Response.status(Response.Status.OK).entity(profileFeatures).type( - responseMediaType).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 778d1d80b..81e1941dc 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 @@ -46,7 +46,6 @@ import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtExcept import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; -import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService; import org.wso2.carbon.mdm.services.android.bean.DeviceState; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; @@ -94,17 +93,6 @@ public class AndroidAPIUtils { return deviceManagementProviderService; } - public static GCMService getGCMService() { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - GCMService gcmService = (GCMService) ctx.getOSGiService(GCMService.class, null); - if (gcmService == null) { - String msg = "GCM service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - return gcmService; - } - public static MediaType getResponseMediaType(String acceptHeader) { MediaType responseMediaType; if (MediaType.WILDCARD.equals(acceptHeader)) { @@ -116,35 +104,21 @@ public class AndroidAPIUtils { } public static Response getOperationResponse(List deviceIDs, Operation operation, - Message message, MediaType responseMediaType) + Message message) throws DeviceManagementException, OperationManagementException { AndroidDeviceUtils deviceUtils = new AndroidDeviceUtils(); - DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs, - message, responseMediaType); + DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs, message); List validDeviceIds = deviceIDHolder.getValidDeviceIDList(); Activity activity = getDeviceManagementService().addOperation( DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, operation, validDeviceIds); - if (activity != null) { - GCMService gcmService = getGCMService(); - if (gcmService.isGCMEnabled()) { - List deviceIDList = deviceIDHolder.getValidDeviceIDList(); - List devices = new ArrayList(deviceIDList.size()); - for (DeviceIdentifier deviceIdentifier : deviceIDList) { - devices.add(getDeviceManagementService().getDevice(deviceIdentifier)); - } - getGCMService().sendNotification(operation.getCode(), devices); - } - } if (!deviceIDHolder.getErrorDeviceIdList().isEmpty()) { return javax.ws.rs.core.Response.status(AndroidConstants.StatusCodes. - MULTI_STATUS_HTTP_CODE).type( - responseMediaType).entity(deviceUtils. + MULTI_STATUS_HTTP_CODE).entity(deviceUtils. convertErrorMapIntoErrorMessage(deviceIDHolder.getErrorDeviceIdList())).build(); } - return javax.ws.rs.core.Response.status(javax.ws.rs.core.Response.Status.CREATED).entity(activity). - type(responseMediaType).build(); + return Response.status(Response.Status.CREATED).entity(activity).build(); } @@ -336,7 +310,6 @@ public class AndroidAPIUtils { private static void updateDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtException { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); DeviceInformationManager informationManager = (DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, 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/util/AndroidConstants.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/AndroidConstants.java index 8ba454da3..beb8c010b 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/AndroidConstants.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/AndroidConstants.java @@ -23,101 +23,111 @@ package org.wso2.carbon.mdm.services.android.util; */ public final class AndroidConstants { - public final class DeviceProperties{ - private DeviceProperties() { - throw new AssertionError(); - } - public static final String PROPERTY_USER_KEY = "username"; - public static final String PROPERTY_DEVICE_KEY = "device"; - } - - public final class DeviceFeatures{ - private DeviceFeatures() { - throw new AssertionError(); - } - } - - public final class DeviceConstants{ - private DeviceConstants() { - throw new AssertionError(); - } - public static final String DEVICE_MAC_KEY = "mac"; - public static final String DEVICE_DESCRIPTION_KEY = "description"; - public static final String DEVICE_OWNERSHIP_KEY = "ownership"; - public static final String DEVICE_PROPERTIES_KEY = "properties"; - public static final String DEVICE_FEATURES_KEY = "features"; - public static final String DEVICE_DATA = "data"; - public static final String DEVICE_ID_NOT_FOUND = "Device Id not found for device found at %s"; - public static final String DEVICE_ID_SERVICE_NOT_FOUND = - "Issue in retrieving device management service instance for device found at %s"; - } - - public final class Messages{ - private Messages(){ - throw new AssertionError(); - } - public static final String DEVICE_MANAGER_SERVICE_NOT_AVAILABLE = - "Device Manager service not available"; - } - - public final class OperationCodes{ - private OperationCodes(){ - throw new AssertionError(); - } - public static final String DEVICE_LOCK = "DEVICE_LOCK"; - public static final String DEVICE_UNLOCK = "DEVICE_UNLOCK"; - public static final String DEVICE_LOCATION = "DEVICE_LOCATION"; - public static final String WIFI = "WIFI"; - public static final String CAMERA = "CAMERA"; - public static final String DEVICE_MUTE = "DEVICE_MUTE"; - public static final String PASSCODE_POLICY = "PASSCODE_POLICY"; - public static final String DEVICE_INFO = "DEVICE_INFO"; - public static final String ENTERPRISE_WIPE = "ENTERPRISE_WIPE"; - public static final String CLEAR_PASSWORD = "CLEAR_PASSWORD"; - public static final String WIPE_DATA = "WIPE_DATA"; - public static final String APPLICATION_LIST = "APPLICATION_LIST"; - public static final String CHANGE_LOCK_CODE = "CHANGE_LOCK_CODE"; - public static final String INSTALL_APPLICATION = "INSTALL_APPLICATION"; - public static final String UPDATE_APPLICATION = "UPDATE_APPLICATION"; - public static final String UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION"; - public static final String BLACKLIST_APPLICATIONS = "BLACKLIST_APPLICATIONS"; - public static final String ENCRYPT_STORAGE = "ENCRYPT_STORAGE"; - public static final String DEVICE_RING = "DEVICE_RING"; - public static final String DEVICE_REBOOT = "REBOOT"; - public static final String UPGRADE_FIRMWARE = "UPGRADE_FIRMWARE"; - public static final String NOTIFICATION = "NOTIFICATION"; - public static final String WEBCLIP = "WEBCLIP"; - public static final String DISENROLL = "DISENROLL"; - public static final String MONITOR = "MONITOR"; - public static final String VPN = "VPN"; - public static final String APP_RESTRICTION = "APP-RESTRICTION"; - public static final String WORK_PROFILE = "WORK_PROFILE"; + public static final String DEVICE_TYPE_ANDROID = "android"; + + public final class DeviceProperties { + private DeviceProperties() { + throw new AssertionError(); + } + + public static final String PROPERTY_USER_KEY = "username"; + public static final String PROPERTY_DEVICE_KEY = "device"; + } + + public final class DeviceFeatures { + private DeviceFeatures() { + throw new AssertionError(); + } + } + + public final class DeviceConstants { + private DeviceConstants() { + throw new AssertionError(); + } + + public static final String DEVICE_MAC_KEY = "mac"; + public static final String DEVICE_DESCRIPTION_KEY = "description"; + public static final String DEVICE_OWNERSHIP_KEY = "ownership"; + public static final String DEVICE_PROPERTIES_KEY = "properties"; + public static final String DEVICE_FEATURES_KEY = "features"; + public static final String DEVICE_DATA = "data"; + public static final String DEVICE_ID_NOT_FOUND = "Device Id not found for device found at %s"; + public static final String DEVICE_ID_SERVICE_NOT_FOUND = + "Issue in retrieving device management service instance for device found at %s"; + } + + public final class Messages { + private Messages() { + throw new AssertionError(); + } + + public static final String DEVICE_MANAGER_SERVICE_NOT_AVAILABLE = + "Device Manager service not available"; } - public final class StatusCodes{ - private StatusCodes(){ - throw new AssertionError(); - } - public static final int MULTI_STATUS_HTTP_CODE = 207; - } - - public final class TenantConfigProperties{ - private TenantConfigProperties(){ - throw new AssertionError(); - } - public static final String LICENSE_KEY = "androidEula"; - public static final String LANGUAGE_US = "en_US"; - public static final String CONTENT_TYPE_TEXT = "text"; - } + public final class OperationCodes { + private OperationCodes() { + throw new AssertionError(); + } + + public static final String DEVICE_LOCK = "DEVICE_LOCK"; + public static final String DEVICE_UNLOCK = "DEVICE_UNLOCK"; + public static final String DEVICE_LOCATION = "DEVICE_LOCATION"; + public static final String WIFI = "WIFI"; + public static final String CAMERA = "CAMERA"; + public static final String DEVICE_MUTE = "DEVICE_MUTE"; + public static final String PASSCODE_POLICY = "PASSCODE_POLICY"; + public static final String DEVICE_INFO = "DEVICE_INFO"; + public static final String ENTERPRISE_WIPE = "ENTERPRISE_WIPE"; + public static final String CLEAR_PASSWORD = "CLEAR_PASSWORD"; + public static final String WIPE_DATA = "WIPE_DATA"; + public static final String APPLICATION_LIST = "APPLICATION_LIST"; + public static final String CHANGE_LOCK_CODE = "CHANGE_LOCK_CODE"; + public static final String INSTALL_APPLICATION = "INSTALL_APPLICATION"; + public static final String UPDATE_APPLICATION = "UPDATE_APPLICATION"; + public static final String UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION"; + public static final String BLACKLIST_APPLICATIONS = "BLACKLIST_APPLICATIONS"; + public static final String ENCRYPT_STORAGE = "ENCRYPT_STORAGE"; + public static final String DEVICE_RING = "DEVICE_RING"; + public static final String DEVICE_REBOOT = "REBOOT"; + public static final String UPGRADE_FIRMWARE = "UPGRADE_FIRMWARE"; + public static final String NOTIFICATION = "NOTIFICATION"; + public static final String WEBCLIP = "WEBCLIP"; + public static final String DISENROLL = "DISENROLL"; + public static final String MONITOR = "MONITOR"; + public static final String VPN = "VPN"; + public static final String APP_RESTRICTION = "APP-RESTRICTION"; + public static final String WORK_PROFILE = "WORK_PROFILE"; + } + + public final class StatusCodes { + private StatusCodes() { + throw new AssertionError(); + } + + public static final int MULTI_STATUS_HTTP_CODE = 207; + } + + public final class TenantConfigProperties { + private TenantConfigProperties() { + throw new AssertionError(); + } + + public static final String LICENSE_KEY = "androidEula"; + public static final String LANGUAGE_US = "en_US"; + public static final String CONTENT_TYPE_TEXT = "text"; + } public final class ApplicationProperties { - private ApplicationProperties(){ + private ApplicationProperties() { throw new AssertionError(); } + public static final String NAME = "name"; public static final String IDENTIFIER = "package"; public static final String USS = "USS"; public static final String VERSION = "version"; public static final String ICON = "icon"; } + } 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 f8733cf10..de4c6dde1 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 @@ -34,11 +34,11 @@ public class AndroidDeviceUtils { private static final String COMMA_SEPARATION_PATTERN = ", "; public DeviceIDHolder validateDeviceIdentifiers(List deviceIDs, - Message message, MediaType responseMediaType) { + Message message) { if (deviceIDs == null || deviceIDs.isEmpty()) { message.setResponseMessage("Device identifier list is empty"); - throw new BadRequestException(message, responseMediaType); + throw new BadRequestException(message); } List errorDeviceIdList = new ArrayList(); 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/ApiOriginFilter.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/ApiOriginFilter.java new file mode 100644 index 000000000..455d582bb --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/ApiOriginFilter.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.mdm.services.android.util; + +import javax.servlet.*; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class ApiOriginFilter implements Filter { + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + HttpServletResponse res = (HttpServletResponse) response; + res.addHeader("Access-Control-Allow-Origin", "*"); + res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); + res.addHeader("Access-Control-Allow-Headers", "Content-Type"); + chain.doFilter(request, response); + } + + public void destroy() { + //do nothing + } + + public void init(FilterConfig filterConfig) throws ServletException { + //do nothing + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 89e199a7b..c92b50a8c 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -23,67 +23,40 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/web.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/web.xml index ad42bfafd..48eeb393e 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/web.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/web.xml @@ -28,6 +28,11 @@ org.apache.cxf.transport.servlet.CXFServlet + + + swagger.security.filter + ApiAuthorizationFilterImpl + 1 @@ -74,4 +79,13 @@ + + ApiOriginFilter + org.wso2.carbon.mdm.services.android.util.ApiOriginFilter + + + ApiOriginFilter + /* + + From 9a01df5d55138e502f864cb88f6bba9e607b247a Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 27 May 2016 14:58:19 +0530 Subject: [PATCH 02/41] Renaming android agent webapp --- .../org.wso2.carbon.device.mgt.mobile.android.api/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml | 2 +- .../src/main/resources/p2.inf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml index adf03b22c..808df07e5 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml @@ -72,7 +72,7 @@ - + diff --git a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml index 55d061f83..c13fa8396 100644 --- a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml +++ b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml @@ -118,7 +118,7 @@ true ${project.build.directory}/maven-shared-archive-resources/webapps/ - mdm-android-agent.war + api#device-mgt#android#v2.1.war diff --git a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf index 349c09785..04b5ce97f 100644 --- a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf +++ b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf @@ -1,5 +1,5 @@ instructions.configure = \ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/webapps/mdm-android-agent.war,target:${installFolder}/../../deployment/server/webapps/mdm-android-agent.war,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/webapps/api#device-mgt#android#v2.1.war,target:${installFolder}/../../deployment/server/webapps/api#device-mgt#android#v2.1.war,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/jaggeryapps/,target:${installFolder}/../../deployment/server/jaggeryapps/,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/conf/mobile-config.xml,target:${installFolder}/../../conf/mobile-config.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/dbscripts/plugins/,target:${installFolder}/../../../dbscripts/cdm/plugins/android,overwrite:true);\ From aa4a4889a55e6e0e1dec5f53c00d911d39e9dfac Mon Sep 17 00:00:00 2001 From: inoshperera Date: Fri, 27 May 2016 15:36:22 +0530 Subject: [PATCH 03/41] 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 ba9d85b065ec5d81aeef80c3d39d06eaf0c3e88a Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 27 May 2016 18:26:34 +0530 Subject: [PATCH 04/41] Adding swagger related dependencies to android agent webapp --- .../pom.xml | 29 +++++++++++++++---- pom.xml | 24 +++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml index 808df07e5..505c051ef 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml @@ -168,12 +168,6 @@ commons-httpclient provided - - io.swagger - swagger-annotations - provided - - com.google.code.gson gson @@ -188,5 +182,28 @@ org.wso2.carbon.analytics.api provided + + io.swagger + swagger-annotations + + + io.swagger + swagger-core + + + org.slf4j + slf4j-api + + + + + io.swagger + swagger-jaxrs + + + javax.servlet + servlet-api + provided + diff --git a/pom.xml b/pom.xml index 458950867..df3853bec 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,28 @@ swagger-annotations ${swagger.version} + + io.swagger + swagger-core + ${swagger.version} + + + org.slf4j + slf4j-api + + + + + io.swagger + swagger-jaxrs + ${swagger.version} + + + javax.servlet + servlet-api + ${servlet-api.version} + provided + @@ -1180,6 +1202,8 @@ github-scm + + 2.5 From 479acf3b45e91c1e36f097129ae3630da347b3b2 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 27 May 2016 19:38:12 +0530 Subject: [PATCH 05/41] Improving swagger annotations of device management admin API --- .../services/DeviceManagementService.java | 103 +++++++++++++----- 1 file changed, 75 insertions(+), 28 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/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..81f2d4af0 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; @@ -31,6 +28,8 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; +@Api(value = "Android Device Management API", + description = "This carries all the resources related to Android device management functionalities") @Path("/devices") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @@ -41,15 +40,18 @@ public interface DeviceManagementService { @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "PUT", - value = "Updating an ApplicationList", - notes = "Update application list in server side." + value = "Update the application list of a device" ) @ApiResponses(value = { - @ApiResponse(code = 202, message = "Device information has modified successfully"), - @ApiResponse(code = 500, message = "Error occurred while modifying the application list") + @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") }) - Response updateApplicationList(@ApiParam(name = "id", value = "deviceIdentifier") @PathParam("id") String id, - @ApiParam(name = "applications", value = "updatable applications") + Response updateApplicationList(@ApiParam(name = "id", value = "Device Identifier") @PathParam("id") String id, + @ApiParam(name = "applications", value = "List of applications that need to be " + + "persisted against the device") List applications); @GET @@ -58,17 +60,34 @@ public interface DeviceManagementService { consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, httpMethod = "PUT", - value = "Getting Pending Android Device Operations", + value = "Get the operation list pending for the device", responseContainer = "List", notes = "The Android agent communicates with the server to get the operations that are queued up " + - "at the server end for a given device using this REST API", + "at the server end for a given device using via this particular resource", response = Operation.class) @ApiResponses(value = { - @ApiResponse(code = 200, message = "List of pending operations"), - @ApiResponse(code = 500, message = "Issue in retrieving operation management service instance") + @ApiResponse(code = 200, message = "OK. \n List of pending operations of the device is returned", + responseHeaders = { + @ResponseHeader(name = "Content-Type", description = "The content type of the body"), + @ResponseHeader(name = "ETag", description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader(name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse(code = 303, message = "See Other. \n " + + "Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader(name = "Location", description = "The Source URL of the document.")}), + @ApiResponse(code = 304, message = "Not Modified. \n " + + "Empty body because the client already has the latest version of the requested resource."), + @ApiResponse(code = 400, message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse(code = 404, message = "Not Found. \n Requested device not found."), + @ApiResponse(code = 406, message = "Not Acceptable. \n The requested media type is not supported."), + @ApiResponse(code = 500, message = "Internal Server Error. \n " + + "Server error occurred while retrieving the pending operation list of the device.") }) Response getPendingOperations( - @ApiParam(name = "id", value = "DeviceIdentifier") @PathParam("id") String id, + @ApiParam(name = "id", value = "Device Identifier") @PathParam("id") String id, @ApiParam(name = "resultOperations", value = "Device Operation Status") List resultOperations); @@ -76,15 +95,20 @@ public interface DeviceManagementService { @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", - value = "Registering an Android Device", + value = "Register an Android Device", notes = "When carrying out device registration via an Android device, you need to initially install" + " an Android Agent on the device, before being able to register the device with WSO2 EMM. Instead," + " you can use this REST API to register an Android device with WSO2 EMM, without having to install" + " an Android Agent on the respective device" ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Device enrollment succeeded"), - @ApiResponse(code = 500, message = "Device enrollment failed"), + @ApiResponse(code = 201, message = "Created. \n Device has successfully been enrolled. Location header " + + "contains URL of newly enrolled device", + responseHeaders = { + @ResponseHeader(name = "Location", description = "URL of the device enrolled")}), + @ApiResponse(code = 400, message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse(code = 500, message = "Internal Server Error. \n " + + "Server error occurred while enrolling the device."), }) Response enrollDevice(@ApiParam(name = "device", value = "Device Information to be enroll") Device device); @@ -96,10 +120,19 @@ public interface DeviceManagementService { notes = "Use this REST API to retrieve the registration status of an Android device" ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Device has already enrolled"), - @ApiResponse(code = 404, message = "Device not found") + @ApiResponse(code = 200, message = "Device has already enrolled", + responseHeaders = { + @ResponseHeader(name = "Content-Type", description = "The content type of the body"), + @ResponseHeader(name = "ETag", description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader(name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse(code = 404, message = "Not Found. \n Requested device not found."), + @ApiResponse(code = 500, message = "Internal Server Error. \n " + + "Server error occurred while retrieving the enrollment status of the device."), }) - Response isEnrolled(@ApiParam(name = "id", value = "DeviceIdentifier") @PathParam("id") String id); + Response isEnrolled(@ApiParam(name = "id", value = "Device Identifier") @PathParam("id") String id); @PUT @Path("/{id}") @@ -109,10 +142,22 @@ public interface DeviceManagementService { notes = "Use this REST API to update the registration details of an Android device" ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Device enrollment has updated successfully"), - @ApiResponse(code = 404, message = "Device not found for enrollment") + @ApiResponse(code = 200, message = "OK. \n Device enrollment has been updated successfully", + responseHeaders = { + @ResponseHeader(name = "Location", description = "The URL of the updated device."), + @ResponseHeader(name = "Content-Type", description = "The content type of the body"), + @ResponseHeader(name = "ETag", description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader(name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse(code = 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 = 500, message = "Internal Server Error. \n " + + "Server error occurred while modifying the current enrollment of the device.") }) - Response modifyEnrollment(@ApiParam(name = "id", value = "DeviceIdentifier") @PathParam("id") String id, + Response modifyEnrollment(@ApiParam(name = "id", value = "Device Identifier") @PathParam("id") String id, @ApiParam(name = "device", value = "Device information to be modify") Device device); @DELETE @@ -120,12 +165,14 @@ public interface DeviceManagementService { @ApiOperation( httpMethod = "DELETE", value = "Un-registering an Android Device", - notes = "Use this REST API to unregister a specific Android device" + notes = "Use this REST API to un-register a specific Android device" ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Device has removed successfully"), - @ApiResponse(code = 404, message = "Device not found") + @ApiResponse(code = 200, message = "OK. \n Device has successfully been dis-enrolled"), + @ApiResponse(code = 404, message = "Not Found. \n Device requested to be dis-enrolled does not exist."), + @ApiResponse(code = 500, message = "Internal Server Error. \n " + + "Server error occurred while dis-enrolling the the device."), }) - Response disEnrollDevice(@ApiParam(name = "id", value = "DeviceIdentifier") @PathParam("id") String id); + Response disEnrollDevice(@ApiParam(name = "id", value = "Device Identifier") @PathParam("id") String id); } From d25e1b2421c4786a3e74ed5d411c8e8c929ae5a8 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Fri, 27 May 2016 22:43:03 +0530 Subject: [PATCH 06/41] 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 07/41] 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 08/41] 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(); From 44aa3a93a9e470aecbad9c5e6d4d97007d1b636a Mon Sep 17 00:00:00 2001 From: prabathabey Date: Sat, 28 May 2016 02:07:17 +0530 Subject: [PATCH 09/41] Adding more improvements to swagger annotations --- .../DeviceManagementAdminService.java | 2 +- .../services/DeviceManagementService.java | 20 +++++++++++++------ .../DeviceTypeConfigurationService.java | 9 ++++----- 3 files changed, 19 insertions(+), 12 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..a343596c0 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 @@ -42,7 +42,7 @@ public interface DeviceManagementAdminService { @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", - value = "Adding a Device Lock on Android Devices", + value = "Adds 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" ) 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 81f2d4af0..8bd6de7b8 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 @@ -108,7 +108,7 @@ public interface DeviceManagementService { @ResponseHeader(name = "Location", description = "URL of the device enrolled")}), @ApiResponse(code = 400, message = "Bad Request. \n Invalid request or validation error."), @ApiResponse(code = 500, message = "Internal Server Error. \n " + - "Server error occurred while enrolling the device."), + "Server error occurred while enrolling the device.") }) Response enrollDevice(@ApiParam(name = "device", value = "Device Information to be enroll") Device device); @@ -144,17 +144,25 @@ public interface DeviceManagementService { @ApiResponses(value = { @ApiResponse(code = 200, message = "OK. \n Device enrollment has been updated successfully", responseHeaders = { - @ResponseHeader(name = "Location", description = "The URL of the updated device."), + @ResponseHeader(name = "Content-Location", description = "The URL of the updated device."), @ResponseHeader(name = "Content-Type", description = "The content type of the body"), @ResponseHeader(name = "ETag", description = "Entity Tag of the response resource.\n" + "Used by caches, or in conditional requests."), @ResponseHeader(name = "Last-Modified", description = "Date and time the resource has been modified the last time.\n" + "Used by caches, or in conditional requests.")}), - @ApiResponse(code = 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 = 500, message = "Internal Server Error. \n " + + @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 = 500, + message = "Internal Server Error. \n " + "Server error occurred while modifying the current enrollment of the device.") }) Response modifyEnrollment(@ApiParam(name = "id", value = "Device Identifier") @PathParam("id") String id, 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..02a4ac76e 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; @@ -29,6 +26,8 @@ import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +@Api(value = "Android Configuration Management API", description = "This API carries all resource associated with " + + "manipulating the general configurations of Android platform") @Path("/configuration") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @@ -69,7 +68,7 @@ public interface DeviceTypeConfigurationService { notes = "Update the Android platform configurations using this REST API" ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Created"), + @ApiResponse(code = 200, message = "OK. \n Platform configuration has successfully been updated"), @ApiResponse(code = 500, message = "Error occurred while modifying configuration settings of " + "Android platform") }) From 63bb616e9c929ada50d9e9901121514a906244ae Mon Sep 17 00:00:00 2001 From: prabathabey Date: Sat, 28 May 2016 08:12:10 +0530 Subject: [PATCH 10/41] Improving swagger annotations --- .../DeviceManagementAdminService.java | 956 ++++++++++++++++-- .../services/DeviceManagementService.java | 284 ++++-- .../DeviceTypeConfigurationService.java | 150 ++- .../services/EventReceiverService.java | 122 ++- .../impl/DeviceManagementServiceImpl.java | 6 +- .../DeviceTypeConfigurationServiceImpl.java | 53 +- .../impl/EventReceiverServiceImpl.java | 7 +- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 +- 8 files changed, 1281 insertions(+), 299 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 ad473d8d7..3e504e52c 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 @@ -48,10 +48,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Device lock operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new lock operation.") }) Response configureDeviceLock( @ApiParam(name = "deviceLockBeanWrapper", @@ -69,9 +101,42 @@ public interface DeviceManagementAdminService { response = Activity.class, tags = "Android Device Management Administrative Service") @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Device un-lock operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new un-lock operation.") }) Response configureDeviceUnlock( @ApiParam(name = "deviceIDs", value = "DeviceIds to be enable device unlock operation") @@ -89,9 +154,42 @@ public interface DeviceManagementAdminService { response = Activity.class, tags = "Android Device Management Administrative Service") @ApiResponses(value = { - @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.")}) + @ApiResponse( + code = 201, + message = "Created. \n Get-location operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new get-location operation.")}) Response getDeviceLocation( @ApiParam(name = "deviceIDs", value = "DeviceIDs to be requested to get device location") List deviceIDs); @@ -107,9 +205,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Clear password operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new clear password operation.") }) Response removePassword( @ApiParam(name = "deviceIDs", @@ -126,10 +257,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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") + @ApiResponse( + code = 201, + message = "Created. \n Control camera operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new control camera operation.") }) Response configureCamera( @ApiParam(name = "cameraBeanWrapper", value = "Camera enable/disable configurations with device IDs") @@ -149,10 +312,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Device info operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new device info operation.") }) Response getDeviceInformation( @ApiParam(name = "deviceIds", value = "Device IDs to be requested to get device information") @@ -171,11 +366,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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." - )}) + @ApiResponse( + code = 201, + message = "Created. \n Enterprise wipe operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a enterprise wipe operation.")}) Response wipeDevice(@ApiParam(name = "deviceIDs", value = "Device IDs to be requested to do enterprise-wipe") List deviceIDs); @@ -191,9 +417,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.")}) + @ApiResponse( + code = 201, + message = "Created. \n Device wipe operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a device wipe operation.")}) Response wipeData( @ApiParam(name = "wipeDataBeanWrapper", value = "Configurations and DeviceIds needed to do wipe-data") WipeDataBeanWrapper wipeDataBeanWrapper); @@ -213,10 +472,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Get-applications operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new get-applications operation.") }) Response getApplications( @ApiParam(name = "deviceIDs", value = "Device Ids needed to get applications that are already installed") @@ -233,10 +524,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Device ring operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new device ring operation.") }) Response ringDevice( @ApiParam(name = "deviceIDs", value = "Device Ids needed for ring") List deviceIDs); @@ -252,10 +575,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Device reboot operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new device reboot operation.") }) Response rebootDevice( @ApiParam(name = "deviceIDs", value = "Device Ids needed for reboot.") List deviceIDs); @@ -270,10 +625,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Device mute operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new device mute operation.") }) @Path("/mute") Response muteDevice( @@ -293,10 +680,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Install application operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new install-application operation.") }) Response installApplication( @ApiParam(name = "applicationInstallationBeanWrapper", value = "Properties of installed apps and device IDs") @@ -316,10 +735,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Update-application operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new update-application operation.") }) Response updateApplication( @ApiParam(name = "applicationUpdateBeanWrapper", value = "Properties of updated apps and device IDs") @@ -336,10 +787,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Uninstall-application operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new uninstall-application operation.") }) Response uninstallApplication( @ApiParam(name = "applicationUninstallationBeanWrapper", @@ -358,10 +841,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Blacklist-applications operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new blacklist-applications operation.") }) Response blacklistApplications( @ApiParam(name = "blacklistApplicationsBeanWrapper", value = "BlacklistApplications " + @@ -380,10 +895,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Upgrade firmware operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new upgrade firmware operation.") }) Response upgradeFirmware( @ApiParam(name = "upgradeFirmwareBeanWrapper", @@ -402,10 +949,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Configure VPN operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new configure VPN operation.") }) Response configureVPN( @ApiParam(name = "vpnBeanWrapper", @@ -423,10 +1002,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Send notification operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new send notification operation.") }) Response sendNotification( @ApiParam(name = "notificationBeanWrapper", @@ -444,10 +1055,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Configure wifi operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new configure wifi operation.") }) Response configureWifi( @ApiParam(name = "wifiBeanWrapper", @@ -464,10 +1107,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Encrypt storage operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new encrypt storage operation.") }) Response encryptStorage( @ApiParam(name = "encryptionBeanWrapper", @@ -485,10 +1160,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Change lock code operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new change lock code operation.") }) Response changeLockCode( @ApiParam(name = "lockCodeBeanWrapper", @@ -506,10 +1213,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Set password policy operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new set password policy operation.") }) Response setPasswordPolicy( @ApiParam(name = "passwordPolicyBeanWrapper", @@ -527,9 +1266,42 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 201, + message = "Created. \n Set webclip operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new set webclip 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 fb80be7b1..d403581b9 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 @@ -45,15 +45,47 @@ public interface DeviceManagementService { tags = "Android Device Management" ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "OK. \n " + - "Application list of the device has successfully been updated"), - @ApiResponse(code = 500, message = "Internal Server Error. \n " + - "Sever error occurred while modifying the application list") + @ApiResponse( + code = 200, + message = "OK. \n Application list has been updated successfully", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The URL of the updated application list."), + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 404, + message = "Not Found. \n Resource to be deleted does not exist."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while updating the application list.") }) - Response updateApplicationList(@ApiParam(name = "id", value = "Device Identifier") @PathParam("id") String id, - @ApiParam(name = "applications", value = "List of applications that need to be " + - "persisted against the device") - List applications); + Response updateApplicationList( + @ApiParam( + name = "id", + value = "Device Identifier") + @PathParam("id") String id, + @ApiParam( + name = "applications", + value = "List of applications that need to be persisted against the device") + List applications); @GET @Path("/{id}/pending-operations") @@ -67,33 +99,52 @@ public interface DeviceManagementService { response = Operation.class, tags = "Android Device Management") @ApiResponses(value = { - @ApiResponse(code = 200, message = "OK. \n List of pending operations of the device is returned", + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the pending application list of the Android device.", + response = Operation.class, + responseContainer = "List", responseHeaders = { - @ResponseHeader(name = "Content-Type", description = "The content type of the body"), - @ResponseHeader(name = "ETag", description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader(name = "Last-Modified", + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", description = "Date and time the resource has been modified the last time.\n" + - "Used by caches, or in conditional requests.")}), - @ApiResponse(code = 303, message = "See Other. \n " + - "Source can be retrieved from the URL specified at the Location header.", - responseHeaders = { - @ResponseHeader(name = "Location", description = "The Source URL of the document.")}), - @ApiResponse(code = 304, message = "Not Modified. \n " + - "Empty body because the client already has the latest version of the requested resource."), - @ApiResponse(code = 400, message = "Bad Request. \n Invalid request or validation error."), - @ApiResponse(code = 404, message = "Not Found. \n Requested device not found."), - @ApiResponse(code = 406, message = "Not Acceptable. \n The requested media type is not supported."), - @ApiResponse(code = 500, message = "Internal Server Error. \n " + - "Server error occurred while retrieving the pending operation list of the device.") + "Used by caches, or in conditional requests.") + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while fetching policies.") }) Response getPendingOperations( - @ApiParam(name = "id", value = "Device Identifier") @PathParam("id") String id, - @ApiParam(name = "resultOperations", value = "Device Operation Status") + @ApiParam( + name = "id", + value = "Device Identifier") + @PathParam("id") String id, + @ApiParam( + name = "If-Modified-Since", + value = "Validates if the requested variant has not been modified since the time specified", + required = false) + @HeaderParam("If-Modified-Since") String ifModifiedSince, + @ApiParam( + name = "resultOperations", + value = "Device Operation Status") List resultOperations); @POST @ApiOperation( + produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Register an Android Device", @@ -104,13 +155,41 @@ public interface DeviceManagementService { tags = "Android Device Management" ) @ApiResponses(value = { - @ApiResponse(code = 201, message = "Created. \n Device has successfully been enrolled. Location header " + - "contains URL of newly enrolled device", + @ApiResponse( + code = 201, + message = "Created. \n Device enrollment has successfully been created", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the added device enrollment."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", responseHeaders = { - @ResponseHeader(name = "Location", description = "URL of the device enrolled")}), - @ApiResponse(code = 400, message = "Bad Request. \n Invalid request or validation error."), - @ApiResponse(code = 500, message = "Internal Server Error. \n " + - "Server error occurred while enrolling the device.") + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new policy.") }) Response enrollDevice(@ApiParam(name = "device", value = "Device Information to be enroll") Device device); @@ -123,25 +202,42 @@ public interface DeviceManagementService { tags = "Android Device Management" ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "Device has already enrolled", + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the status of the Android device enrollment.", responseHeaders = { - @ResponseHeader(name = "Content-Type", description = "The content type of the body"), - @ResponseHeader(name = "ETag", description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader(name = "Last-Modified", + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", description = "Date and time the resource has been modified the last time.\n" + - "Used by caches, or in conditional requests.")}), - @ApiResponse(code = 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."), + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while fetching the enrollment status of the Android device.") }) - Response isEnrolled(@ApiParam(name = "id", value = "Device Identifier") @PathParam("id") String id); + Response isEnrolled( + @ApiParam( + name = "id", + value = "Device Identifier") + @PathParam("id") String id, + @ApiParam( + name = "If-Modified-Since", + value = "Validates if the requested variant has not been modified since the time specified", + required = false) + @HeaderParam("If-Modified-Since") String ifModifiedSince); @PUT @Path("/{id}") @@ -151,47 +247,73 @@ public interface DeviceManagementService { notes = "Use this REST API to update the registration details of an Android device", tags = "Android Device Management" ) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "OK. \n Device enrollment has been updated successfully", - responseHeaders = { - @ResponseHeader(name = "Content-Location", description = "The URL of the updated device."), - @ResponseHeader(name = "Content-Type", description = "The content type of the body"), - @ResponseHeader(name = "ETag", description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader(name = "Last-Modified", - description = "Date and time the resource has been modified the last time.\n" + - "Used by caches, or in conditional requests.")}), - @ApiResponse( - code = 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 = 500, - message = "Internal Server Error. \n " + - "Server error occurred while modifying the current enrollment of the device.") - }) - Response modifyEnrollment(@ApiParam(name = "id", value = "Device Identifier") @PathParam("id") String id, - @ApiParam(name = "device", value = "Device information to be modify") Device device); + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Device enrollment has been updated successfully", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the updated device enrollment."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 404, + message = "Not Found. \n Resource to be deleted does not exist."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while updating the device enrollment.") + }) + Response modifyEnrollment( + @ApiParam( + name = "id", + value = "Device Identifier") + @PathParam("id") String id, + @ApiParam( + name = "device", + value = "Device information to be modify") Device device); @DELETE @Path("/{id}") @ApiOperation( httpMethod = "DELETE", - value = "Un-registering an Android Device", + value = "Un-register an Android Device", notes = "Use this REST API to un-register a specific Android device", tags = "Android Device Management" ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "OK. \n Device has successfully been dis-enrolled"), - @ApiResponse(code = 404, message = "Not Found. \n Device requested to be dis-enrolled does not exist."), - @ApiResponse(code = 500, message = "Internal Server Error. \n " + - "Server error occurred while dis-enrolling the the device."), + @ApiResponse( + code = 200, + message = "OK. \n Device has successfully been dis-enrolled"), + @ApiResponse( + code = 404, + message = "Not Found. \n Resource to be deleted does not exist."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while dis-enrolling the device.") }) - Response disEnrollDevice(@ApiParam(name = "id", value = "Device Identifier") @PathParam("id") String id); + Response disEnrollDevice( + @ApiParam( + name = "id", + value = "Device Identifier") + @PathParam("id") String id); } 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 f13b4a4a3..7d74b700d 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 @@ -33,28 +33,9 @@ import javax.ws.rs.core.Response; @Consumes(MediaType.APPLICATION_JSON) public interface DeviceTypeConfigurationService { - @POST - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Configuring Android platform settings.", - notes = "Configure the Android platform settings using this REST API.", - tags = "Android Configuration Management" - ) - @ApiResponses(value = { - @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 = "Android platform related configurations that must be added.") - PlatformConfiguration configuration); @GET @ApiOperation( + produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Getting Android Platform Configurations", notes = "Get the Android platform configuration details using this REST API", @@ -62,18 +43,42 @@ public interface DeviceTypeConfigurationService { tags = "Android Configuration Management" ) @ApiResponses(value = { - @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.", + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched Android platform configuration.", + response = PlatformConfiguration.class, 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.") + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."), + @ApiResponse( + code = 404, + message = "Not Found. \n Resource to be deleted does not exist."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while fetching Android platform configuration.") }) - Response getConfiguration() throws AndroidAgentException; + Response getConfiguration( + @ApiParam( + name = "If-Modified-Since", + value = "Validates if the requested variant has not been modified since the time specified", + required = false) + @HeaderParam("If-Modified-Since") String ifModifiedSince); @PUT @ApiOperation( @@ -85,20 +90,48 @@ public interface DeviceTypeConfigurationService { tags = "Android Configuration Management" ) @ApiResponses(value = { - @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.") + @ApiResponse( + code = 200, + message = "OK. \n Android platform configuration has been updated successfully", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the updated Android platform configuration."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 404, + message = "Not Found. \n Resource to be deleted does not exist."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while modifying Android platform configuration.") }) - Response updateConfiguration(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") - PlatformConfiguration configuration) throws AndroidAgentException; + Response updateConfiguration( + @ApiParam(name = "configuration", + value = "AndroidPlatformConfiguration") + PlatformConfiguration configuration); @GET @Path("license") - @Produces("text/plain") + @Produces(MediaType.TEXT_PLAIN) @ApiOperation( - produces = MediaType.APPLICATION_JSON, + produces = MediaType.TEXT_PLAIN, 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 " + @@ -106,10 +139,41 @@ public interface DeviceTypeConfigurationService { response = String.class, tags = "Android Configuration Management") @ApiResponses(value = { - @ApiResponse(code = 200, message = "Licence agreement"), - @ApiResponse(code = 500, message = "Error occurred while retrieving the license configured for Android " + - "device enrolment") + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched Android license configuration.", + response = PlatformConfiguration.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."), + @ApiResponse( + code = 404, + message = "Not Found. \n Resource to be deleted does not exist."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while fetching Android license configuration.") }) - Response getLicense() throws AndroidAgentException; + Response getLicense( + @ApiParam( + name = "If-Modified-Since", + value = "Validates if the requested variant has not been modified since the time specified", + required = false) + @HeaderParam("If-Modified-Since") String ifModifiedSince) 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 a86e69a12..7dc619cd8 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 @@ -35,24 +35,55 @@ public interface EventReceiverService { @POST @Path("/publish") @ApiOperation( + produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Event publishing via REST API.", notes = "Publish events received by the EMM Android client to WSO2 DAS using this API.", tags = "Event Receiver" ) - @ApiResponses(value = { - @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.") - }) + @ApiResponses( + value = { + @ApiResponse(code = 201, message = "Created. \n Event is published successfully. Location header " + + "contains URL of newly enrolled device", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The URL of the added policy."), + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.") + }), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while publishing events.") + }) 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 @@ -68,30 +99,57 @@ public interface EventReceiverService { responseContainer = "List", tags = "Event Receiver" ) - @ApiResponses(value = { - @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.") - }) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Event details of a device for a given time duration have been successfully fetched", + 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 = "Content-Location", description = "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 retrieveAlerts( - @ApiParam(name = "id", value = "Device Identifier to be need to retrieve events.", required = true) + @ApiParam( + name = "id", + value = "Device Identifier to be need to retrieve events.", + required = true) @QueryParam("id") String deviceId, - @ApiParam(name = "from", value = "From Date.") + @ApiParam( + name = "from", + value = "From Date.") @QueryParam("from") long from, - @ApiParam(name = "to", value = "To Date.") + @ApiParam( + name = "to", + value = "To Date.") @QueryParam("to") long to, - @ApiParam(name = "type", value = "Type of the Alert to be need to retrieve events.") - @QueryParam("type") String type); + @ApiParam( + name = "type", + value = "Type of the Alert to be need to retrieve events.") + @QueryParam("type") String type, + @ApiParam( + name = "If-Modified-Since", + value = "Validates if the requested variant has not been modified since the time specified", + required = false) + @HeaderParam("If-Modified-Since") String ifModifiedSince); } 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 35a03a399..3c5f4a5f3 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 @@ -76,7 +76,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @PUT @Path("/{id}/pending-operations") @Override - public Response getPendingOperations(@PathParam("id") String id, List resultOperations) { + public Response getPendingOperations(@PathParam("id") String id, + @HeaderParam("If-Modified-Since") String ifModifiedSince, + List resultOperations) { if (id == null || id.isEmpty()) { String msg = "Device identifier is null or empty, hence returning device not found"; log.error(msg); @@ -189,7 +191,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @GET @Path("/{id}/status") @Override - public Response isEnrolled(@PathParam("id") String id) { + public Response isEnrolled(@PathParam("id") String id, @HeaderParam("If-Modified-Since") String ifModifiedSince) { boolean result; DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); try { 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 4cc359456..f20e31f4d 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 @@ -43,51 +43,13 @@ import java.util.List; public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurationService { private static final Log log = LogFactory.getLog(DeviceTypeConfigurationServiceImpl.class); - - @POST - @Override - public Response addConfiguration(PlatformConfiguration configuration){ - Message responseMsg = new Message(); - String msg; - ConfigurationEntry licenseEntry = null; - try { - configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - List configs = configuration.getConfiguration(); - for (ConfigurationEntry entry : configs) { - if (AndroidConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) { - License license = new License(); - license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - license.setLanguage(AndroidConstants.TenantConfigProperties.LANGUAGE_US); - license.setVersion("1.0.0"); - license.setText(entry.getValue().toString()); - AndroidAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants. - MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, license); - licenseEntry = entry; - break; - } - } - - if (licenseEntry != null) { - configs.remove(licenseEntry); - } - configuration.setConfiguration(configs); - AndroidAPIUtils.getDeviceManagementService().saveConfiguration(configuration); - Response.status(Response.Status.CREATED); - responseMsg.setResponseMessage("Android platform configuration saved successfully."); - responseMsg.setResponseCode(Response.Status.CREATED.toString()); - } catch (DeviceManagementException e) { - msg = "Error occurred while configuring the android platform"; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } - return Response.status(Response.Status.CREATED).entity(responseMsg).build(); - } @GET @Override - public Response getConfiguration() throws AndroidAgentException { + public Response getConfiguration( + @HeaderParam("If-Modified-Since") String ifModifiedSince) { String msg; - PlatformConfiguration PlatformConfiguration = null; + PlatformConfiguration PlatformConfiguration; List configs; try { PlatformConfiguration = AndroidAPIUtils.getDeviceManagementService(). @@ -121,7 +83,7 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati @PUT @Override - public Response updateConfiguration(PlatformConfiguration configuration) throws AndroidAgentException { + public Response updateConfiguration(PlatformConfiguration configuration) { String msg; Message responseMsg = new Message(); ConfigurationEntry licenseEntry = null; @@ -161,9 +123,10 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati @GET @Path("license") - @Produces("text/plain") - public Response getLicense() throws AndroidAgentException { - License license = null; + @Produces(MediaType.TEXT_PLAIN) + public Response getLicense( + @HeaderParam("If-Modified-Since") String ifModifiedSince) { + License license; try { license = 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 e1015ca6d..e93dfbee9 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,10 +71,11 @@ public class EventReceiverServiceImpl implements EventReceiverService { @GET @Override - public Response retrieveAlerts(@QueryParam("id") String deviceId, @QueryParam ("from") long from, - @QueryParam ("to") long to, @QueryParam("type") String type) { + public Response retrieveAlerts(@QueryParam("id") String deviceId, @QueryParam("from") long from, + @QueryParam("to") long to, @QueryParam("type") String type, + @HeaderParam("If-Modified-Since") String ifModifiedSince) { - if(from != 0l && to != 0l && deviceId != null) { + if (from != 0l && to != 0l && deviceId != null) { return retrieveAlertFromDate(deviceId, from, to); } else if (deviceId != null && type != null) { return retrieveAlertByType(deviceId, type); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 20b48f434..3abaca367 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -45,7 +45,7 @@ - + From 4dbf699b66b9e0353f688646e7a4b5e755978779 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Mon, 30 May 2016 08:33:55 +0530 Subject: [PATCH 11/41] Fixing issues in android sense plugin which were caused by refactoring done in cdm-f --- .../iot/androidsense/service/impl/AndroidSenseServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseServiceImpl.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseServiceImpl.java index 15ec090c1..996c7e564 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseServiceImpl.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseServiceImpl.java @@ -249,7 +249,7 @@ public class AndroidSenseServiceImpl implements AndroidSenseService { return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).entity(false).build(); } } catch (DeviceManagementException e) { - log.error(e.getErrorMessage(), e); + log.error(e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(false).build(); } } From 18257b87295463cee1e3e53d711b16382b854810 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Mon, 30 May 2016 12:08:44 +0530 Subject: [PATCH 12/41] Changing the name of the android API webapp --- .../org.wso2.carbon.device.mgt.mobile.android.api/pom.xml | 4 ++-- .../org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml | 2 +- .../src/main/resources/p2.inf | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml index 505c051ef..1258094d9 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml @@ -46,7 +46,7 @@ 2.2 WEB-INF/lib/*cxf*.jar - api#device-mgt#android#v2.1 + api#device-mgt#android#v1.0 @@ -72,7 +72,7 @@ - + diff --git a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml index c13fa8396..f04d3976d 100644 --- a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml +++ b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml @@ -118,7 +118,7 @@ true ${project.build.directory}/maven-shared-archive-resources/webapps/ - api#device-mgt#android#v2.1.war + api#device-mgt#android#v1.0.war diff --git a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf index 04b5ce97f..3b9d91aec 100644 --- a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf +++ b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf @@ -1,5 +1,5 @@ instructions.configure = \ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/webapps/api#device-mgt#android#v2.1.war,target:${installFolder}/../../deployment/server/webapps/api#device-mgt#android#v2.1.war,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/webapps/api#device-mgt#android#v1.0.war,target:${installFolder}/../../deployment/server/webapps/api#device-mgt#android#v1.0.war,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/jaggeryapps/,target:${installFolder}/../../deployment/server/jaggeryapps/,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/conf/mobile-config.xml,target:${installFolder}/../../conf/mobile-config.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/dbscripts/plugins/,target:${installFolder}/../../../dbscripts/cdm/plugins/android,overwrite:true);\ From eb025c42f745dec2d440994c9688b6a8e187d145 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Mon, 30 May 2016 12:30:12 +0530 Subject: [PATCH 13/41] Fixing issues encountered while deploying the agent webapp of windows --- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 168cb1c53..b19ad6fa7 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -197,11 +197,11 @@ class="org.wso2.carbon.mdm.mobileservices.windows.services.wstep.util.MessageHandler"/> + class="org.wso2.carbon.mdm.mobileservices.windows.services.configurationmgtservice.impl.ConfigurationMgtServiceImpl"/> + class="org.wso2.carbon.mdm.mobileservices.windows.services.policymgtservice.impl.PolicyMgtServiceImpl"/> + class="org.wso2.carbon.mdm.mobileservices.windows.services.devicemgtservice.impl.DeviceManagementServiceImpl"/> From bf1e00f47223249830ec9fd8bb9cc588870e9ee7 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Mon, 30 May 2016 17:07:04 +0530 Subject: [PATCH 14/41] Fixed the host name of Android API --- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 3abaca367..b27d32735 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -44,7 +44,7 @@ - + From 6d14133bab84528a18d46addab453bf3f1b5ce6b Mon Sep 17 00:00:00 2001 From: inoshperera Date: Tue, 31 May 2016 14:45:05 +0530 Subject: [PATCH 15/41] fixing the mismatch of swagger annotation and implementation --- .../services/android/services/DeviceManagementService.java | 4 ++-- 1 file 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/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 d403581b9..4464d6c73 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 @@ -87,11 +87,11 @@ public interface DeviceManagementService { value = "List of applications that need to be persisted against the device") List applications); - @GET + @PUT @Path("/{id}/pending-operations") @ApiOperation( produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", + httpMethod = "PUT", value = "Get the operation list pending for the device", responseContainer = "List", notes = "The Android agent communicates with the server to get the operations that are queued up " + From 61d88f77b6b2d83a1493454d889a038becc00c43 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Tue, 31 May 2016 14:48:23 +0530 Subject: [PATCH 16/41] removed device Id from notification bean --- .../services/impl/DeviceManagementServiceImpl.java | 3 +-- .../windows/operations/util/OperationUtils.java | 9 +++------ 2 files changed, 4 insertions(+), 8 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/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 3c5f4a5f3..987d14f6d 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 @@ -145,10 +145,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { notification.setOperationId(operation.getId()); notification.setStatus(org.wso2.carbon.device.mgt.common.notification.mgt.Notification. Status.NEW.toString()); - notification.setDeviceIdentifier(id); notification.setDescription("Operation " + operation.getCode() + " failed to execute on device " + deviceName + ". Device ID : " + deviceId); - AndroidAPIUtils.getNotificationManagementService().addNotification(notification); + AndroidAPIUtils.getNotificationManagementService().addNotification(id, notification); } if (log.isDebugEnabled()) { log.debug("Updating operation '" + operation.toString() + "'"); diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/util/OperationUtils.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/util/OperationUtils.java index f9140826e..4ff0475af 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/util/OperationUtils.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/operations/util/OperationUtils.java @@ -87,10 +87,9 @@ public class OperationUtils { Notification lockResetNotification = new Notification(); lockResetNotification.setOperationId(status.getCommandReference()); lockResetNotification.setStatus(String.valueOf(Notification.Status.NEW)); - lockResetNotification.setDeviceIdentifier(deviceIdentifier); lockResetNotification.setDescription( Constants.SyncMLResponseCodes.LOCKRESET_NOTIFICATION); - nmService.addNotification(lockResetNotification); + nmService.addNotification(deviceIdentifier, lockResetNotification); } catch (NotificationManagementException e) { throw new WindowsOperationException("Failure occurred in getting notification service", e); } @@ -156,10 +155,9 @@ public class OperationUtils { Notification lockResetNotification = new Notification(); lockResetNotification.setOperationId(status.getCommandReference()); lockResetNotification.setStatus(String.valueOf(Notification.Status.NEW)); - lockResetNotification.setDeviceIdentifier(deviceIdentifier); lockResetNotification.setDescription(Constants.SyncMLResponseCodes.LOCKRESET_NOTIFICATION); - nmService.addNotification(lockResetNotification); + nmService.addNotification(deviceIdentifier, lockResetNotification); } catch (NotificationManagementException e) { String msg = "Failure occurred in getting notification service"; log.error(msg, e); @@ -404,10 +402,9 @@ public class OperationUtils { Notification notification = new Notification(); notification.setDescription("Auto generated DevicePin : " + pinValue); notification.setOperationId(result.getCommandReference()); - notification.setDeviceIdentifier(deviceIdentifier); notification.setStatus(String.valueOf(Notification.Status.NEW)); try { - nmService.addNotification(notification); + nmService.addNotification(deviceIdentifier, notification); } catch (NotificationManagementException e) { String msg = "Failure Occurred in getting notification service."; log.error(msg, e); From 212c11750c06503d1ad825a2915941e5da545b42 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Tue, 31 May 2016 16:13:20 +0530 Subject: [PATCH 17/41] Added http schem supported by the API --- .../services/impl/DeviceTypeConfigurationServiceImpl.java | 3 +-- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 3 ++- 2 files changed, 3 insertions(+), 3 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/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 f20e31f4d..e1a4f7fcd 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 @@ -60,7 +60,6 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati PlatformConfiguration = new PlatformConfiguration(); configs = new ArrayList<>(); } - ConfigurationEntry entry = new ConfigurationEntry(); License license = AndroidAPIUtils.getDeviceManagementService().getLicense( DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, AndroidConstants. @@ -110,7 +109,7 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati AndroidAPIUtils.getDeviceManagementService().saveConfiguration(configuration); //AndroidAPIUtils.getGCMService().resetTenantConfigCache(); Response.status(Response.Status.ACCEPTED); - responseMsg.setResponseMessage("Android platform configuration has updated successfully."); + responseMsg.setResponseMessage("Android platform configuration has been updated successfully."); responseMsg.setResponseCode(Response.Status.ACCEPTED.toString()); } catch (DeviceManagementException e) { msg = "Error occurred while modifying configuration settings of Android platform"; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml index b27d32735..cc020be21 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -45,7 +45,8 @@ - + + From 3fd56b56c41ac38c730bf07444f4645412344d45 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Tue, 31 May 2016 16:21:42 +0530 Subject: [PATCH 18/41] Fix cxf servelt issues --- .../src/main/webapp/META-INF/permissions.xml | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) 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 4ce7a039b..0cbe6c728 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 @@ -35,7 +35,7 @@ Lock /device-mgt/android/operations/lock - /operation/lock + /admin/devices/lock-devices POST emm_admin,emm_user @@ -51,7 +51,7 @@ Mute /device-mgt/android/operations/mute - /operation/mute + /admin/devices/mute POST emm_admin,emm_user @@ -59,14 +59,14 @@ Location /device-mgt/android/operations/location - /operation/location + /admin/devices/location POST emm_admin,emm_user Clear Passcode - /operation/clear-password/ + /admin/devices/clear-password POST emm_admin @@ -74,7 +74,7 @@ Camera /device-mgt/android/operations/camera - /operation/camera + /admin/devices/control-camera POST emm_admin,emm_user @@ -82,7 +82,7 @@ Device Info /device-mgt/android/operations/device-info - /operation/device-info + /admin/devices/info POST emm_admin,emm_user @@ -90,7 +90,7 @@ Enterprise Wipe /device-mgt/android/operations/enterprise-wipe - /operation/enterprise-wipe + /admin/devices/enterprise-wipe POST emm_admin @@ -98,7 +98,7 @@ Wipe Data /device-mgt/android/operations/wipe-data - /operation/wipe-data + /admin/devices/wipe POST emm_admin @@ -106,7 +106,7 @@ Application List /device-mgt/android/operations/application-list - /operation/application-list + /admin/devices/applications POST emm_admin,emm_user @@ -114,7 +114,7 @@ Ring /device-mgt/android/operations/ring-device - /operation/ring-device + /admin/devices/ring POST emm_admin,emm_user @@ -122,7 +122,7 @@ Reboot /device-mgt/android/operations/reboot-device - /operation/reboot-device + /admin/devices/reboot POST emm_admin,emm_user @@ -130,15 +130,14 @@ Upgrade Firmware /device-mgt/android/operations/upgrade-firmware - /operation/upgrade-firmware - POST - emm_admin,emm_user + /admin/devices/upgrade-firmware + /admin/devices/upgrade-firmware Configure VPN /device-mgt/android/operations/vpn - /operation/vpn + /admin/devices/configure-vpn POST emm_admin,emm_user @@ -154,7 +153,7 @@ Update Application /device-mgt/android/operations/update-application - /operation/update-application + /admin/devices/update-application POST emm_admin,emm_user @@ -162,7 +161,7 @@ Uninstall Application /device-mgt/android/operations/uninstall-application - /operation/uninstall-application + /admin/devices/uninstall-application POST emm_admin,emm_user @@ -170,7 +169,7 @@ Blacklist Applications /device-mgt/android/operations/blacklist-applications - /operation/blacklist-applications + /admin/devices/blacklist-applications POST emm_admin @@ -178,7 +177,7 @@ Notification /device-mgt/android/operations/notification - /operation/notification + /admin/devices/send-notification POST emm_admin,emm_user @@ -186,7 +185,7 @@ Wifi /device-mgt/android/operations/wifi - /operation/wifi + /admin/devices/configure-wifi POST emm_admin @@ -194,7 +193,7 @@ Encryption /device-mgt/android/operations/encrypt - /operation/encrypt + /admin/devices/encrypt-storage POST emm_admin @@ -202,7 +201,7 @@ Change lock code /device-mgt/android/operations/change-lock-code - /operation/change-lock-code + /admin/devices/change-lock-code POST emm_admin @@ -210,7 +209,7 @@ Password Policy /device-mgt/android/operations/password-policy - /operation/password-policy + /admin/devices/set-password-policy POST emm_admin @@ -218,7 +217,7 @@ Webclip /device-mgt/android/operations/webclip - /operation/webclip + /admin/devices/set-webclip POST emm_admin From 56a2ca0aa07281ba7243b95ad2d2efac6bd4120a Mon Sep 17 00:00:00 2001 From: mharindu Date: Tue, 31 May 2016 17:21:31 +0530 Subject: [PATCH 19/41] Added missing HTTP method attribute in permissions.xml in android webapp --- .../src/main/webapp/META-INF/permissions.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 0cbe6c728..f1b5ca435 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 @@ -131,7 +131,8 @@ Upgrade Firmware /device-mgt/android/operations/upgrade-firmware /admin/devices/upgrade-firmware - /admin/devices/upgrade-firmware + POST + emm_admin From d7b4b834247f524b0791fd747ccb8cca6389e545 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Tue, 31 May 2016 18:02:04 +0530 Subject: [PATCH 20/41] Fixing path of license resource --- .../services/impl/DeviceTypeConfigurationServiceImpl.java | 3 +-- 1 file changed, 1 insertion(+), 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/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 e1a4f7fcd..e52f00764 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 @@ -121,12 +121,11 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati @GET - @Path("license") + @Path("/license") @Produces(MediaType.TEXT_PLAIN) public Response getLicense( @HeaderParam("If-Modified-Since") String ifModifiedSince) { License license; - try { license = AndroidAPIUtils.getDeviceManagementService().getLicense( From d01e176933432d49bb5232ac060f782ae36d611a Mon Sep 17 00:00:00 2001 From: hasuniea Date: Tue, 31 May 2016 18:08:16 +0530 Subject: [PATCH 21/41] add eventreceiver fix --- .../android/services/impl/EventReceiverServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e93dfbee9..5b9d0c592 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 @@ -63,7 +63,7 @@ public class EventReceiverServiceImpl implements EventReceiverService { entity(message).build(); } } catch (DataPublisherConfigurationException e) { - String msg = "Error occurred while publishing the events from Android agent."; + String msg = "Error occurred while getting the Data publisher Service."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } From ba1f3bbbcc51ef30ebbc5bf3cbdfcb912dd2c1e1 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Tue, 31 May 2016 18:42:37 +0530 Subject: [PATCH 22/41] fixed issue in unlock devices permissions --- .../src/main/webapp/META-INF/permissions.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f1b5ca435..b4ec4343d 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 @@ -43,7 +43,7 @@ Unlock /device-mgt/android/operations/unlock - /operation/unlock + /admin/devices/unlock-devices POST emm_admin,emm_user From daee6109cc26e8195b64d47439b92a3a2784c7a1 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Tue, 31 May 2016 18:48:49 +0530 Subject: [PATCH 23/41] fixing code issues --- .../services/android/bean/ErrorListItem.java | 77 +++++++ .../services/android/bean/ErrorResponse.java | 193 ++++++++++++++++++ .../UnexpectedServerErrorException.java | 35 ++++ .../DeviceManagementAdminServiceImpl.java | 145 ++++++++----- .../impl/DeviceManagementServiceImpl.java | 35 +++- .../DeviceTypeConfigurationServiceImpl.java | 12 +- .../impl/EventReceiverServiceImpl.java | 19 +- .../android/util/AndroidAPIUtils.java | 4 +- .../android/util/AndroidDeviceUtils.java | 3 - 9 files changed, 444 insertions(+), 79 deletions(-) create mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ErrorListItem.java create mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ErrorResponse.java create mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/UnexpectedServerErrorException.java 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/bean/ErrorListItem.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ErrorListItem.java new file mode 100644 index 000000000..1e48b0183 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ErrorListItem.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.mdm.services.android.bean; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotNull; + +@ApiModel(description = "") +public class ErrorListItem { + + @NotNull + private String code = null; + @NotNull + private String message = null; + + @ApiModelProperty(required = true, value = "") + @JsonProperty("code") + public String getCode() { + return code; + } + public void setCode(String code) { + this.code = code; + } + + public ErrorListItem() {} + + public ErrorListItem(String code, String msg) { + this.code = code; + this.message = msg; + } + + + /** + * Description about individual errors occurred + **/ + @ApiModelProperty(required = true, value = "Description about individual errors occurred") + @JsonProperty("message") + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("errorItem {\n"); + + sb.append(" code: ").append(code).append("\n"); + sb.append(" message: ").append(message).append("\n"); + sb.append("}\n"); + return sb.toString(); + } + +} 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/bean/ErrorResponse.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ErrorResponse.java new file mode 100644 index 000000000..7680e3664 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ErrorResponse.java @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.mdm.services.android.bean; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.ArrayList; +import java.util.List; + +@ApiModel(description = "") +public class ErrorResponse { + + private Long code = null; + private String message = null; + private String description = null; + private String moreInfo = null; + private List errorItems = new ArrayList<>(); + + private ErrorResponse() { + } + + @JsonProperty(value = "code") + @ApiModelProperty(required = true, value = "") + public Long getCode() { + return code; + } + + public void setCode(Long code) { + this.code = code; + } + + @JsonProperty(value = "message") + @ApiModelProperty(required = true, value = "ErrorResponse message.") + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @JsonProperty(value = "description") + @ApiModelProperty(value = "A detail description about the error message.") + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @JsonProperty(value = "moreInfo") + @ApiModelProperty(value = "Preferably an url with more details about the error.") + public String getMoreInfo() { + return moreInfo; + } + + public void setMoreInfo(String moreInfo) { + this.moreInfo = moreInfo; + } + + public void addErrorListItem(ErrorListItem item) { + this.errorItems.add(item); + } + + /** + * If there are more than one error list them out. \nFor example, list out validation errors by each field. + */ + @JsonProperty(value = "errorItems") + @ApiModelProperty(value = "If there are more than one error list them out. \n" + + "For example, list out validation errors by each field.") + public List getErrorItems() { + return errorItems; + } + + public void setErrorItems(List error) { + this.errorItems = error; + } + + @Override + public String toString() { +// StringBuilder sb = new StringBuilder(); +// sb.append("{"); +// boolean cont = false; +// if (code != null) { +// cont = true; +// sb.append(" \"code\": ").append(code); +// } +// if (message != null) { +// if (cont) { +// sb.append(","); +// } +// cont = true; +// sb.append(" \"message\": \"").append(message).append("\""); +// } +// if (description != null) { +// if (cont) { +// sb.append(","); +// } +// cont = true; +// sb.append(" \"description\": ").append(description).append("\""); +// } +// if (moreInfo != null) { +// if (cont) { +// sb.append(","); +// } +// cont = true; +// sb.append(" \"moreInfo\": \"").append(moreInfo).append("\""); +// } +// if (error != null && error.size() > 0) { +// if (cont) { +// sb.append(","); +// } +// sb.append(" \"errorItems\": ").append(error); +// } +// sb.append("}"); +// return sb.toString(); + return null; + } + + public static class ErrorResponseBuilder { + + private Long code = null; + private String message = null; + private String description = null; + private String moreInfo = null; + private List error; + + + public ErrorResponseBuilder() { + this.error = new ArrayList<>(); + } + + public ErrorResponseBuilder setCode(long code) { + this.code = code; + return this; + } + + public ErrorResponseBuilder setMessage(String message) { + this.message = message; + return this; + } + + public ErrorResponseBuilder setDescription(String description) { + this.description = description; + return this; + } + + public ErrorResponseBuilder setMoreInfo(String moreInfo) { + this.moreInfo = moreInfo; + return this; + } + + public ErrorResponseBuilder addErrorItem(String code, String msg) { + ErrorListItem item = new ErrorListItem(); + item.setCode(code); + item.setMessage(msg); + this.error.add(item); + return this; + } + + public ErrorResponse build() { + ErrorResponse errorResponse = new ErrorResponse(); + errorResponse.setCode(code); + errorResponse.setMessage(message); + errorResponse.setErrorItems(error); + errorResponse.setDescription(description); + errorResponse.setMoreInfo(moreInfo); + return errorResponse; + } + } + +} + + 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/exception/UnexpectedServerErrorException.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/UnexpectedServerErrorException.java new file mode 100644 index 000000000..6db5b0e69 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/UnexpectedServerErrorException.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.mdm.services.android.exception; + + +import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; + +public class UnexpectedServerErrorException extends WebApplicationException { + + private static final long serialVersionUID = 147943579458906890L; + + public UnexpectedServerErrorException(ErrorResponse error) { + super(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).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/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 f4fb1ed25..2c24cbc02 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 @@ -27,10 +27,10 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; import org.wso2.carbon.mdm.services.android.bean.*; import org.wso2.carbon.mdm.services.android.bean.wrapper.*; +import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; import org.wso2.carbon.mdm.services.android.services.DeviceManagementAdminService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.AndroidConstants; -import org.wso2.carbon.mdm.services.android.util.Message; import javax.ws.rs.Consumes; import javax.ws.rs.POST; @@ -72,11 +72,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -97,11 +99,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -121,11 +125,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -145,11 +151,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance."; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -176,11 +184,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -203,10 +213,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; - - log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -226,11 +235,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -259,11 +270,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -283,11 +296,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -307,11 +322,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -331,11 +348,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -356,11 +375,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -390,11 +411,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -425,11 +448,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -460,11 +485,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -496,11 +523,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -530,11 +559,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -564,11 +595,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -599,11 +632,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -635,11 +670,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -670,11 +707,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -705,11 +744,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -740,11 +781,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } } @@ -774,11 +817,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(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/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 987d14f6d..746e61d77 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 @@ -29,6 +29,8 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; +import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; +import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; import org.wso2.carbon.mdm.services.android.services.DeviceManagementService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.AndroidConstants; @@ -67,7 +69,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } catch (ApplicationManagementException e) { String msg = "Error occurred while modifying the application list."; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } } @@ -100,23 +103,28 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } catch (OperationManagementException e) { String msg = "Issue in retrieving operation management service instance"; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } catch (PolicyComplianceException e) { String msg = "Issue in updating Monitoring operation"; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } catch (DeviceManagementException e) { String msg = "Issue in retrieving device management service instance"; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } catch (ApplicationManagementException e) { String msg = "Issue in retrieving application management service instance"; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } catch (NotificationManagementException e) { String msg = "Issue in retrieving Notification management service instance"; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } List pendingOperations; @@ -177,13 +185,15 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { String msg = "Error occurred while enrolling the '" + device.getType() + "', which carries the id '" + device.getDeviceIdentifier() + "'"; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } catch (PolicyManagementException e) { String msg = "Error occurred while enforcing default enrollment policy upon '" + device.getType() + "', which carries the id '" + device.getDeviceIdentifier() + "'"; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } } @@ -205,7 +215,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } catch (DeviceManagementException e) { String msg = "Error occurred while checking enrollment status of the device."; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } } @@ -228,7 +239,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { String msg = "Error occurred while modifying enrollment of the Android device that carries the id '" + id + "'"; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } } @@ -250,7 +262,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } catch (DeviceManagementException e) { String msg = "Error occurred while dis-enrolling the Android device that carries the id '" + id + "'"; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).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 e52f00764..6ec2c470b 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 @@ -25,7 +25,8 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; -import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; +import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; +import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; import org.wso2.carbon.mdm.services.android.services.DeviceTypeConfigurationService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.AndroidConstants; @@ -75,7 +76,8 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati } catch (DeviceManagementException e) { msg = "Error occurred while retrieving the Android tenant configuration"; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } return Response.status(Response.Status.OK).entity(PlatformConfiguration).build(); } @@ -114,7 +116,8 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati } catch (DeviceManagementException e) { msg = "Error occurred while modifying configuration settings of Android platform"; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } return Response.status(Response.Status.CREATED).entity(responseMsg).build(); } @@ -134,7 +137,8 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati } 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(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(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/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 5b9d0c592..b7bb1e5dc 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 @@ -23,19 +23,18 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; import org.wso2.carbon.mdm.services.android.bean.DeviceState; +import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; +import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; import org.wso2.carbon.mdm.services.android.services.EventReceiverService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.Message; import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; @Path("/events") -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) public class EventReceiverServiceImpl implements EventReceiverService { private static final String EVENT_STREAM_DEFINITION = "android_agent"; @@ -44,7 +43,7 @@ public class EventReceiverServiceImpl implements EventReceiverService { @POST @Path("/publish") @Override - public Response publishEvents(EventBeanWrapper eventBeanWrapper) { + public Response publishEvents(EventBeanWrapper eventBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking Android device even logging."); } @@ -65,7 +64,8 @@ public class EventReceiverServiceImpl implements EventReceiverService { } catch (DataPublisherConfigurationException e) { String msg = "Error occurred while getting the Data publisher Service."; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } } @@ -105,7 +105,8 @@ public class EventReceiverServiceImpl implements EventReceiverService { } catch (AnalyticsException e) { 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(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } } @@ -133,7 +134,8 @@ public class EventReceiverServiceImpl implements EventReceiverService { String msg = "Error occurred while getting published events for specific " + "Device: " + deviceId + " on given Date."; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } } @@ -158,7 +160,8 @@ public class EventReceiverServiceImpl implements EventReceiverService { String msg = "Error occurred while getting published events for specific " + "Device: " + deviceId + "and given device Type."; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).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 6cbb5645c..6b55b844f 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,7 +47,6 @@ 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; @@ -140,8 +139,7 @@ public class AndroidAPIUtils { // } // } if (!deviceIDHolder.getErrorDeviceIdList().isEmpty()) { - return javax.ws.rs.core.Response.status(AndroidConstants.StatusCodes. - MULTI_STATUS_HTTP_CODE).entity(deviceUtils. + return javax.ws.rs.core.Response.status(Response.Status.BAD_REQUEST).entity(deviceUtils. convertErrorMapIntoErrorMessage(deviceIDHolder.getErrorDeviceIdList())).build(); } return Response.status(Response.Status.CREATED).entity(activity).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/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 acfdf83a5..f2ed96cdd 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 @@ -20,9 +20,6 @@ package org.wso2.carbon.mdm.services.android.util; import org.apache.commons.lang.StringUtils; import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.mdm.services.android.exception.BadRequestException; - -import javax.ws.rs.core.MediaType; import java.util.ArrayList; import java.util.List; From d3a0fc3f1271a28d0e78c1654069a921a9591640 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Tue, 31 May 2016 18:50:26 +0530 Subject: [PATCH 24/41] Added install application permissions --- .../src/main/webapp/META-INF/permissions.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b4ec4343d..451cdf4c1 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 @@ -146,7 +146,7 @@ Install Application /device-mgt/android/operations/install-application - /operation/install-application + /admin/devices/install-application POST emm_admin,emm_user From 198b3c67dce00a282636eb018ab4355d358f0484 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Tue, 31 May 2016 19:16:52 +0530 Subject: [PATCH 25/41] add entry in permission xml --- .../src/main/webapp/META-INF/permissions.xml | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) 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 451cdf4c1..9c6bded30 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 @@ -381,7 +381,7 @@ Event Addition /device-mgt/android/events/add - /events + /events/publish POST emm_user,emm_admin @@ -392,18 +392,4 @@ GET emm_admin - - Event Retrieve - /device-mgt/android/events/date - /events/*/date - GET - emm_admin - - - Event Retrieve - /device-mgt/android/events/type - /events/*/type/* - GET - emm_admin - \ No newline at end of file From ec91b0a539fcf99061ea2d6758c0fb9e82b56a05 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Thu, 2 Jun 2016 15:30:09 +0530 Subject: [PATCH 26/41] fixing eventReceiver --- .../android/services/impl/EventReceiverServiceImpl.java | 4 ++-- .../src/main/webapp/META-INF/permissions.xml | 2 +- 2 files changed, 3 insertions(+), 3 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/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 b7bb1e5dc..9afe00057 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 @@ -43,7 +43,7 @@ public class EventReceiverServiceImpl implements EventReceiverService { @POST @Path("/publish") @Override - public Response publishEvents(EventBeanWrapper eventBeanWrapper) { + public Response publishEvents(EventBeanWrapper eventBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking Android device even logging."); } @@ -62,7 +62,7 @@ public class EventReceiverServiceImpl implements EventReceiverService { entity(message).build(); } } catch (DataPublisherConfigurationException e) { - String msg = "Error occurred while getting the Data publisher Service."; + String msg = "Error occurred while getting the Data publisher Service instance."; log.error(msg, e); throw new UnexpectedServerErrorException( new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).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 9c6bded30..325171927 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 @@ -388,7 +388,7 @@ Event Retrieve /device-mgt/android/events/view - /events/* + /events GET emm_admin From c170373aced71e4048691dd239507085d1039168 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Thu, 2 Jun 2016 15:57:00 +0530 Subject: [PATCH 27/41] fix responce code --- .../android/services/impl/EventReceiverServiceImpl.java | 4 ++-- 1 file 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/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 9afe00057..d80b3606c 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 @@ -150,7 +150,7 @@ public class EventReceiverServiceImpl implements EventReceiverService { deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); if (deviceStates == null) { message.setResponseCode("No any alerts are published for given Device: " + - "" + deviceId + " on specific date."); + "" + deviceId + "and given specific Type."); return Response.status(Response.Status.NOT_FOUND).entity(message).build(); } else { @@ -158,7 +158,7 @@ public class EventReceiverServiceImpl implements EventReceiverService { } } catch (AnalyticsException e) { String msg = "Error occurred while getting published events for specific " + - "Device: " + deviceId + "and given device Type."; + "Device: " + deviceId + "and given specific Type."; log.error(msg, e); throw new UnexpectedServerErrorException( new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); From 2b89b692a42d7565880c22e65880cf02822e1910 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Thu, 2 Jun 2016 16:37:50 +0530 Subject: [PATCH 28/41] adding event configuration refference --- .../mdm/services/android/services/EventReceiverService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 7dc619cd8..c48844090 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 @@ -26,7 +26,9 @@ import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -@Api(value = "Event Receiver", description = "Event publishing/retrieving related APIs.") +@Api(value = "Event Receiver", description = "Event publishing/retrieving related APIs.To enable Eventing need to" + + " configure as ref-https://docs.wso2.com/display/EMM210/Managing+Event+Publishing+with+WSO2+Data+Analytics+Server, " + + "https://docs.wso2.com/display/EMM210/Creating+a+New+Event+Stream+and+Receiver") @Path("/events") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) From c5d1eaa21bf77f977215574739d92f0606271f07 Mon Sep 17 00:00:00 2001 From: mharindu Date: Thu, 2 Jun 2016 17:11:05 +0530 Subject: [PATCH 29/41] Fixed issue in location service --- .../carbon/mdm/services/android/util/AndroidAPIUtils.java | 6 ++++-- 1 file changed, 4 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/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 6b55b844f..98ab67adc 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 @@ -287,7 +287,10 @@ public class AndroidAPIUtils { } else if (AndroidConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) { try { DeviceLocation location = new Gson().fromJson(operation.getOperationResponse(), DeviceLocation.class); - if (location != null) { + // reason for checking "location.getLatitude() != null" because when device fails to provide + // device location and send status instead, above Gson converter create new location object + // with null attributes + if (location != null && location.getLatitude() != null) { location.setDeviceIdentifier(deviceIdentifier); updateDeviceLocation(location); } @@ -295,7 +298,6 @@ public class AndroidAPIUtils { throw new OperationManagementException("Error occurred while updating the device location.", e); } } - getDeviceManagementService().updateOperation(deviceIdentifier, operation); } From 55aa1c811340676518bffd7fc3443a931a149846 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 2 Jun 2016 21:07:33 +0530 Subject: [PATCH 30/41] Fixing compilation issues --- .../carbon/mdm/services/android/util/AndroidAPIUtils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 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/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 98ab67adc..99063feb4 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 @@ -36,6 +36,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; @@ -277,8 +278,7 @@ public class AndroidAPIUtils { try { Device device = new Gson().fromJson(operation.getOperationResponse(), Device.class); org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo = convertDeviceToInfo(device); - deviceInfo.setDeviceIdentifier(deviceIdentifier); - updateDeviceInfo(deviceInfo); + updateDeviceInfo(deviceIdentifier, deviceInfo); } catch (DeviceDetailsMgtException e) { throw new OperationManagementException("Error occurred while updating the device information.", e); } @@ -344,14 +344,14 @@ public class AndroidAPIUtils { } - private static void updateDeviceInfo(org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo) + private static void updateDeviceInfo(DeviceIdentifier deviceId, DeviceInfo deviceInfo) throws DeviceDetailsMgtException { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); DeviceInformationManager informationManager = (DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null); - informationManager.addDeviceInfo(deviceInfo); + informationManager.addDeviceInfo(deviceId, deviceInfo); } From 9237fed74ed3a3205973ff5a78d1b3bf74c2ad19 Mon Sep 17 00:00:00 2001 From: mharindu Date: Fri, 3 Jun 2016 19:22:44 +0530 Subject: [PATCH 31/41] Added notification title --- .../services/android/bean/Notification.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 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/bean/Notification.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Notification.java index e7cdb5788..7cc4d4627 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Notification.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Notification.java @@ -30,14 +30,25 @@ import java.io.Serializable; description = "Details related to notifications passed to device.") public class Notification extends AndroidOperation implements Serializable { - @ApiModelProperty(name = "message", value = "The message to be sent to the device.", required = true) - private String message; + @ApiModelProperty(name = "messageText", value = "The message text to be sent to the device.", required = true) + private String messageText; - public String getMessage() { - return message; + @ApiModelProperty(name = "messageTitle", value = "The message title to be sent to the device.", required = true) + private String messageTitle; + + public String getMessageText() { + return messageText; + } + + public void setMessageText(String messageText) { + this.messageText = messageText; + } + + public String getMessageTitle() { + return messageTitle; } - public void setMessage(String message) { - this.message = message; + public void setMessageTitle(String messageTitle) { + this.messageTitle = messageTitle; } } From 6425d6ab1a847e3164194e612f4a9eca6b8414eb Mon Sep 17 00:00:00 2001 From: Ace Date: Fri, 3 Jun 2016 19:27:20 +0530 Subject: [PATCH 32/41] Adding null check for operations response --- .../android/util/AndroidAPIUtils.java | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 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/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 99063feb4..3635bae73 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 @@ -312,26 +312,31 @@ public class AndroidAPIUtils { private static void updateApplicationList(Operation operation, DeviceIdentifier deviceIdentifier) throws ApplicationManagementException { // Parsing json string to get applications list. - JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse()); - JsonArray jsonArray = jsonElement.getAsJsonArray(); - Application app; - List applications = new ArrayList(jsonArray.size()); - for (JsonElement element : jsonArray) { - app = new Application(); - app.setName(element.getAsJsonObject(). - get(AndroidConstants.ApplicationProperties.NAME).getAsString()); - app.setApplicationIdentifier(element.getAsJsonObject(). - get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString()); - app.setPlatform(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS) != null) { - app.setMemoryUsage(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS).getAsInt()); - } - if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION) != null) { - app.setVersion(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION).getAsString()); + if (operation.getOperationResponse() != null) { + JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse()); + JsonArray jsonArray = jsonElement.getAsJsonArray(); + Application app; + List applications = new ArrayList(jsonArray.size()); + for (JsonElement element : jsonArray) { + app = new Application(); + app.setName(element.getAsJsonObject(). + get(AndroidConstants.ApplicationProperties.NAME).getAsString()); + app.setApplicationIdentifier(element.getAsJsonObject(). + get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString()); + app.setPlatform(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS) != null) { + app.setMemoryUsage(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS).getAsInt()); + } + if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION) != null) { + app.setVersion(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION).getAsString()); + } + applications.add(app); } - applications.add(app); + getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications); + } else { + log.error("Operation Response is null."); } - getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications); + } From 9ac7ffe828b089652653e9aebedd6b927de52295 Mon Sep 17 00:00:00 2001 From: dilanua Date: Fri, 3 Jun 2016 20:47:44 +0530 Subject: [PATCH 33/41] Update UpgradeFirmware operation with server properties --- .../services/android/bean/UpgradeFirmware.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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/bean/UpgradeFirmware.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java index ae1dad869..1b2152325 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java @@ -29,15 +29,31 @@ import java.io.Serializable; @ApiModel(value = "UpgradeFirmware", description = "This class carries all information related to UpgradeFirmware.") public class UpgradeFirmware extends AndroidOperation implements Serializable { + @ApiModelProperty(name = "schedule", value = "Schedule of the UpgradeFirmware.", required = true) private String schedule; + @ApiModelProperty(name = "server", value = "Firmware package server.") + private String server; + + @SuppressWarnings("unused") public String getSchedule() { return schedule; } + @SuppressWarnings("unused") public void setSchedule(String schedule) { this.schedule = schedule; } + @SuppressWarnings("unused") + public String getServer() { + return server; + } + + @SuppressWarnings("unused") + public void setServer(String server) { + this.server = server; + } + } From bcba6216c019ea3b2bf09f979be7e72b56e5a19f Mon Sep 17 00:00:00 2001 From: dilanua Date: Fri, 3 Jun 2016 20:51:54 +0530 Subject: [PATCH 34/41] Update UpgradeFirmware operation with server properties --- .../services/impl/DeviceManagementAdminServiceImpl.java | 3 +-- 1 file changed, 1 insertion(+), 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/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 2c24cbc02..e2bf52e45 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 @@ -554,8 +554,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe operation.setCode(AndroidConstants.OperationCodes.UPGRADE_FIRMWARE); operation.setType(Operation.Type.PROFILE); operation.setPayLoad(upgradeFirmware.toJSON()); - return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), - operation); + return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); From 741bb0ac161a5ac90f4ff174363408eb4cc94607 Mon Sep 17 00:00:00 2001 From: dilanua Date: Fri, 3 Jun 2016 23:49:19 +0530 Subject: [PATCH 35/41] Updating Responces in pending-operations api --- .../services/impl/DeviceManagementServiceImpl.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 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/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 746e61d77..f8c0980d7 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 @@ -74,8 +74,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } } - - @PUT @Path("/{id}/pending-operations") @Override @@ -85,14 +83,14 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { if (id == null || id.isEmpty()) { String msg = "Device identifier is null or empty, hence returning device not found"; log.error(msg); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); try { if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) { String msg = "Device not found for identifier '" + id + "'"; log.error(msg); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } if (log.isDebugEnabled()) { log.debug("Invoking Android pending operations:" + id); @@ -133,7 +131,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } catch (OperationManagementException e) { String msg = "Issue in retrieving operation management service instance"; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } return Response.status(Response.Status.CREATED).entity(pendingOperations).build(); } From c9a07df91a749da8e3431edab91be4bac75a9d78 Mon Sep 17 00:00:00 2001 From: dilanua Date: Sat, 4 Jun 2016 00:27:19 +0530 Subject: [PATCH 36/41] Fixing wrong device id shown for OTA-UPGRADE operation --- .../carbon/mdm/services/android/util/AndroidConstants.java | 2 +- .../carbon/mdm/services/android/util/AndroidDeviceUtils.java | 4 ++-- 2 files changed, 3 insertions(+), 3 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/util/AndroidConstants.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/AndroidConstants.java index beb8c010b..7aad2f7b1 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/AndroidConstants.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/AndroidConstants.java @@ -51,7 +51,7 @@ public final class AndroidConstants { public static final String DEVICE_PROPERTIES_KEY = "properties"; public static final String DEVICE_FEATURES_KEY = "features"; public static final String DEVICE_DATA = "data"; - public static final String DEVICE_ID_NOT_FOUND = "Device Id not found for device found at %s"; + public static final String DEVICE_ID_NOT_FOUND = "Device not found for device id: %s"; public static final String DEVICE_ID_SERVICE_NOT_FOUND = "Issue in retrieving device management service instance for device found at %s"; } 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 f2ed96cdd..9c4c660a7 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 @@ -55,8 +55,8 @@ public class AndroidDeviceUtils { if (isValidDeviceIdentifier(deviceIdentifier)) { validDeviceIDList.add(deviceIdentifier); } else { - errorDeviceIdList.add(String.format(AndroidConstants.DeviceConstants.DEVICE_ID_NOT_FOUND, - deviceIDCounter)); + errorDeviceIdList.add(String.format(AndroidConstants.DeviceConstants. + DEVICE_ID_NOT_FOUND, deviceID)); } } catch (DeviceManagementException e) { errorDeviceIdList.add(String.format(AndroidConstants.DeviceConstants.DEVICE_ID_SERVICE_NOT_FOUND, From 486e2f48ed54d41f245a0fa295fbf3f21d867784 Mon Sep 17 00:00:00 2001 From: inoshperera Date: Wed, 8 Jun 2016 16:55:42 +0530 Subject: [PATCH 37/41] adding validation --- .../mdm/services/android/bean/DeviceLock.java | 2 +- .../DeviceManagementAdminServiceImpl.java | 88 +++++++------------ 2 files changed, 34 insertions(+), 56 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/bean/DeviceLock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceLock.java index 5dc8b7904..e76ff6f1a 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceLock.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceLock.java @@ -26,7 +26,7 @@ import java.io.Serializable; description = "This class carries all information related to device lock operation.") public class DeviceLock extends AndroidOperation implements Serializable { - @ApiModelProperty(name = "message", value = "Pop up message of the lock operation.", required = true) + @ApiModelProperty(name = "message", value = "Pop up message of the lock operation.", required = false) private String message; @ApiModelProperty(name = "isHardLockEnabled", value = "Hard lock enable status of the Device", required = true) private boolean isHardLockEnabled; 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 2c24cbc02..82717aba2 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 @@ -56,13 +56,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - DeviceLock lock = deviceLockBeanWrapper.getOperation(); - - if (lock == null) { + if (deviceLockBeanWrapper == null || deviceLockBeanWrapper.getOperation() == null) { String errorMessage = "Lock bean is empty."; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } + DeviceLock lock = deviceLockBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_LOCK); operation.setType(Operation.Type.PROFILE); @@ -170,12 +169,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - Camera camera = cameraBeanWrapper.getOperation(); - if (camera == null) { + if (cameraBeanWrapper == null || cameraBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the configure camera operation is incorrect."; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } + Camera camera = cameraBeanWrapper.getOperation(); CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.CAMERA); operation.setType(Operation.Type.COMMAND); @@ -254,14 +253,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - WipeData wipeData = wipeDataBeanWrapper.getOperation(); - - if (wipeData == null) { + if (wipeDataBeanWrapper == null || wipeDataBeanWrapper.getOperation() == null) { String errorMessage = "WipeData bean is empty."; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } - + WipeData wipeData = wipeDataBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.WIPE_DATA); operation.setType(Operation.Type.PROFILE); @@ -394,14 +391,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - ApplicationInstallation applicationInstallation = applicationInstallationBeanWrapper.getOperation(); - - if (applicationInstallation == null) { + if (applicationInstallationBeanWrapper == null || applicationInstallationBeanWrapper.getOperation() == + null) { String errorMessage = "The payload of the application installing operation is incorrect"; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } - + ApplicationInstallation applicationInstallation = applicationInstallationBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.INSTALL_APPLICATION); operation.setType(Operation.Type.PROFILE); @@ -430,14 +426,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - ApplicationUpdate applicationUpdate = applicationUpdateBeanWrapper.getOperation(); - - if (applicationUpdate == null) { + if (applicationUpdateBeanWrapper == null || applicationUpdateBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the application update operation is incorrect"; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } - + ApplicationUpdate applicationUpdate = applicationUpdateBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.UPDATE_APPLICATION); operation.setType(Operation.Type.PROFILE); @@ -467,14 +461,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - ApplicationUninstallation applicationUninstallation = applicationUninstallationBeanWrapper.getOperation(); - - if (applicationUninstallation == null) { + if (applicationUninstallationBeanWrapper == null || + applicationUninstallationBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the application uninstalling operation is incorrect"; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } - + ApplicationUninstallation applicationUninstallation = applicationUninstallationBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.UNINSTALL_APPLICATION); operation.setType(Operation.Type.PROFILE); @@ -504,14 +497,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - BlacklistApplications blacklistApplications = blacklistApplicationsBeanWrapper.getOperation(); - - if (blacklistApplications == null) { + if (blacklistApplicationsBeanWrapper == null || blacklistApplicationsBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the blacklisting apps operation is incorrect"; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } - + BlacklistApplications blacklistApplications = blacklistApplicationsBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.BLACKLIST_APPLICATIONS); operation.setType(Operation.Type.PROFILE); @@ -542,14 +533,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - UpgradeFirmware upgradeFirmware = upgradeFirmwareBeanWrapper.getOperation(); - - if (upgradeFirmware == null) { + if (upgradeFirmwareBeanWrapper == null || upgradeFirmwareBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the upgrade firmware operation is incorrect"; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } - + UpgradeFirmware upgradeFirmware = upgradeFirmwareBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.UPGRADE_FIRMWARE); operation.setType(Operation.Type.PROFILE); @@ -578,14 +567,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - Vpn vpn = vpnBeanWrapper.getOperation(); - - if (vpn == null) { + if (vpnBeanWrapper == null || vpnBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the VPN operation is incorrect"; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } - + Vpn vpn = vpnBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.VPN); operation.setType(Operation.Type.PROFILE); @@ -614,14 +601,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - Notification notification = notificationBeanWrapper.getOperation(); - - if (notification == null) { + if (notificationBeanWrapper == null || notificationBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the notification operation is incorrect"; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } - + Notification notification = notificationBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.NOTIFICATION); operation.setType(Operation.Type.PROFILE); @@ -651,14 +636,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - Wifi wifi = wifiBeanWrapper.getOperation(); - - if (wifi == null) { + if (wifiBeanWrapper == null || wifiBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the wifi operation is incorrect"; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } - + Wifi wifi = wifiBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.WIFI); operation.setType(Operation.Type.PROFILE); @@ -689,14 +672,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - DeviceEncryption deviceEncryption = encryptionBeanWrapper.getOperation(); - - if (deviceEncryption == null) { + if (encryptionBeanWrapper == null || encryptionBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the device encryption operation is incorrect"; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } - + DeviceEncryption deviceEncryption = encryptionBeanWrapper.getOperation(); CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.ENCRYPT_STORAGE); operation.setType(Operation.Type.COMMAND); @@ -726,14 +707,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - LockCode lockCode = lockCodeBeanWrapper.getOperation(); - - if (lockCode == null) { + if (lockCodeBeanWrapper == null || lockCodeBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the change lock code operation is incorrect"; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } - + LockCode lockCode = lockCodeBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.CHANGE_LOCK_CODE); operation.setType(Operation.Type.PROFILE); @@ -763,13 +742,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - PasscodePolicy passcodePolicy = passwordPolicyBeanWrapper.getOperation(); - if (passcodePolicy == null) { + if (passwordPolicyBeanWrapper == null || passwordPolicyBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the change password policy operation is incorrect"; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } - + PasscodePolicy passcodePolicy = passwordPolicyBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.PASSCODE_POLICY); operation.setType(Operation.Type.PROFILE); @@ -800,14 +778,14 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } try { - WebClip webClip = webClipBeanWrapper.getOperation(); - if (webClip == null) { + + if (webClipBeanWrapper == null || webClipBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the add webclip operation is incorrect"; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); } - + WebClip webClip = webClipBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.WEBCLIP); operation.setType(Operation.Type.PROFILE); From ef281e1524fd1772a977ae9df16f97600b402387 Mon Sep 17 00:00:00 2001 From: Kasun Delgolla Date: Wed, 15 Jun 2016 13:51:08 -0700 Subject: [PATCH 38/41] Fixing operation response ERROR state exception --- .../mdm/services/android/util/AndroidAPIUtils.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 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/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 3635bae73..6c12740e3 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 @@ -262,18 +262,21 @@ public class AndroidAPIUtils { deviceIdentifier.setId(deviceId); deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - if (AndroidConstants.OperationCodes.MONITOR.equals(operation.getCode())) { + if (!Operation.Status.ERROR.equals(operation.getStatus()) && + AndroidConstants.OperationCodes.MONITOR.equals(operation.getCode())) { if (log.isDebugEnabled()) { log.info("Received compliance status from MONITOR operation ID: " + operation.getId()); } getPolicyManagerService().checkPolicyCompliance(deviceIdentifier, operation.getPayLoad()); - } else if (AndroidConstants.OperationCodes.APPLICATION_LIST.equals(operation.getCode())) { + } else if (!Operation.Status.ERROR.equals(operation.getStatus()) && AndroidConstants. + OperationCodes.APPLICATION_LIST.equals(operation.getCode())) { if (log.isDebugEnabled()) { log.info("Received applications list from device '" + deviceId + "'"); } updateApplicationList(operation, deviceIdentifier); - } else if (AndroidConstants.OperationCodes.DEVICE_INFO.equals(operation.getCode())) { + } else if (!Operation.Status.ERROR.equals(operation.getStatus()) && AndroidConstants. + OperationCodes.DEVICE_INFO.equals(operation.getCode())) { try { Device device = new Gson().fromJson(operation.getOperationResponse(), Device.class); @@ -284,7 +287,8 @@ public class AndroidAPIUtils { } - } else if (AndroidConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) { + } else if (!Operation.Status.ERROR.equals(operation.getStatus()) && + AndroidConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) { try { DeviceLocation location = new Gson().fromJson(operation.getOperationResponse(), DeviceLocation.class); // reason for checking "location.getLatitude() != null" because when device fails to provide From c45400afd099c9c6704724eb7ee57ce4d2653e10 Mon Sep 17 00:00:00 2001 From: inoshperera Date: Thu, 16 Jun 2016 07:57:40 +0530 Subject: [PATCH 39/41] fixing error messages not thrown properly. --- .../exception/BadRequestException.java | 10 ++-- .../android/exception/NotFoundException.java | 33 +++++++++++++ .../DeviceManagementAdminServiceImpl.java | 47 ++++++++++++------- .../impl/EventReceiverServiceImpl.java | 34 +++++++------- .../android/util/AndroidAPIUtils.java | 10 ++-- 5 files changed, 92 insertions(+), 42 deletions(-) create mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/NotFoundException.java 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/exception/BadRequestException.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/BadRequestException.java index 53ea4e99e..741f24b31 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/BadRequestException.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/BadRequestException.java @@ -18,6 +18,7 @@ package org.wso2.carbon.mdm.services.android.exception; +import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; import org.wso2.carbon.mdm.services.android.util.Message; import javax.ws.rs.WebApplicationException; @@ -29,13 +30,8 @@ import javax.ws.rs.core.Response; */ public class BadRequestException extends WebApplicationException { - public BadRequestException(Message message, MediaType mediaType) { - super(Response.status(Response.Status.BAD_REQUEST).entity(message). - type(mediaType).build()); + public BadRequestException(ErrorResponse error) { + super(Response.status(Response.Status.BAD_REQUEST).entity(error).build()); } - public BadRequestException(Message message) { - super(Response.status(Response.Status.BAD_REQUEST).entity(message).build()); - } - } \ No newline at end of file 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/exception/NotFoundException.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/NotFoundException.java new file mode 100644 index 000000000..bda2219bf --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/NotFoundException.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.mdm.services.android.exception; + +import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; + +public class NotFoundException extends WebApplicationException { + + private static final long serialVersionUID = 147943572342342340L; + + public NotFoundException(ErrorResponse error) { + super(Response.status(Response.Status.NOT_FOUND).entity(error).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/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 bd09d30cc..468882aa9 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 @@ -27,6 +27,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; import org.wso2.carbon.mdm.services.android.bean.*; import org.wso2.carbon.mdm.services.android.bean.wrapper.*; +import org.wso2.carbon.mdm.services.android.exception.BadRequestException; import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; import org.wso2.carbon.mdm.services.android.services.DeviceManagementAdminService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; @@ -59,7 +60,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (deviceLockBeanWrapper == null || deviceLockBeanWrapper.getOperation() == null) { String errorMessage = "Lock bean is empty."; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } DeviceLock lock = deviceLockBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -172,7 +174,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (cameraBeanWrapper == null || cameraBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the configure camera operation is incorrect."; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } Camera camera = cameraBeanWrapper.getOperation(); CommandOperation operation = new CommandOperation(); @@ -256,7 +259,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (wipeDataBeanWrapper == null || wipeDataBeanWrapper.getOperation() == null) { String errorMessage = "WipeData bean is empty."; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } WipeData wipeData = wipeDataBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -395,7 +399,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe null) { String errorMessage = "The payload of the application installing operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } ApplicationInstallation applicationInstallation = applicationInstallationBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -429,7 +434,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (applicationUpdateBeanWrapper == null || applicationUpdateBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the application update operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } ApplicationUpdate applicationUpdate = applicationUpdateBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -465,7 +471,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe applicationUninstallationBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the application uninstalling operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } ApplicationUninstallation applicationUninstallation = applicationUninstallationBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -500,14 +507,14 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (blacklistApplicationsBeanWrapper == null || blacklistApplicationsBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the blacklisting apps operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } BlacklistApplications blacklistApplications = blacklistApplicationsBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.BLACKLIST_APPLICATIONS); operation.setType(Operation.Type.PROFILE); operation.setPayLoad(blacklistApplications.toJSON()); - return AndroidAPIUtils.getOperationResponse(blacklistApplicationsBeanWrapper.getDeviceIDs(), operation); @@ -536,7 +543,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (upgradeFirmwareBeanWrapper == null || upgradeFirmwareBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the upgrade firmware operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } UpgradeFirmware upgradeFirmware = upgradeFirmwareBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -569,7 +577,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (vpnBeanWrapper == null || vpnBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the VPN operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } Vpn vpn = vpnBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -603,7 +612,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (notificationBeanWrapper == null || notificationBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the notification operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } Notification notification = notificationBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -638,7 +648,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (wifiBeanWrapper == null || wifiBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the wifi operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } Wifi wifi = wifiBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -674,7 +685,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (encryptionBeanWrapper == null || encryptionBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the device encryption operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } DeviceEncryption deviceEncryption = encryptionBeanWrapper.getOperation(); CommandOperation operation = new CommandOperation(); @@ -709,7 +721,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (lockCodeBeanWrapper == null || lockCodeBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the change lock code operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } LockCode lockCode = lockCodeBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -744,7 +757,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (passwordPolicyBeanWrapper == null || passwordPolicyBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the change password policy operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } PasscodePolicy passcodePolicy = passwordPolicyBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -782,7 +796,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe if (webClipBeanWrapper == null || webClipBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the add webclip operation is incorrect"; log.error(errorMessage); - return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } WebClip webClip = webClipBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); 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 d80b3606c..cdbcab310 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 @@ -25,6 +25,8 @@ import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublish import org.wso2.carbon.mdm.services.android.bean.DeviceState; import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; +import org.wso2.carbon.mdm.services.android.exception.BadRequestException; +import org.wso2.carbon.mdm.services.android.exception.NotFoundException; import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; import org.wso2.carbon.mdm.services.android.services.EventReceiverService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; @@ -57,9 +59,9 @@ public class EventReceiverServiceImpl implements EventReceiverService { message.setResponseCode("Event is published successfully."); return Response.status(Response.Status.CREATED).entity(message).build(); } else { - message.setResponseCode("Error occurred while publishing the event."); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR). - entity(message).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage("Error occurred while " + + "publishing the event.").build()); } } catch (DataPublisherConfigurationException e) { String msg = "Error occurred while getting the Data publisher Service instance."; @@ -82,8 +84,10 @@ public class EventReceiverServiceImpl implements EventReceiverService { } 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(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request must contain " + + "the device identifier. Optionally, both from and to value should be present to get " + + "alerts between times.").build()); } } @@ -91,14 +95,14 @@ public class EventReceiverServiceImpl implements EventReceiverService { if (log.isDebugEnabled()) { log.debug("Retrieving events for given device Identifier."); } - Message message = new Message(); String query = "deviceIdentifier:" + deviceId; List deviceStates; try { 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.NOT_FOUND).entity(message).build(); + throw new NotFoundException( + new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + + "published for Device: " + deviceId + ".").build()); } else { return Response.status(Response.Status.OK).entity(deviceStates).build(); } @@ -116,16 +120,15 @@ public class EventReceiverServiceImpl implements EventReceiverService { if (log.isDebugEnabled()) { log.debug("Retrieving events for given device Identifier and time period."); } - Message message = new Message(); String query = "deviceIdentifier:" + deviceId + " AND _timestamp: [" + fromDate + " TO " + toDate + "]"; List deviceStates; try { deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); if (deviceStates == null) { - message. - setResponseCode("No any alerts are published on given date for given Device: " + deviceId + "."); - return Response.status(Response.Status.NOT_FOUND).entity(message).build(); + throw new NotFoundException( + new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + + "published on given date for given Device: " + deviceId + ".").build()); } else { return Response.status(Response.Status.OK).entity(deviceStates).build(); @@ -143,15 +146,14 @@ public class EventReceiverServiceImpl implements EventReceiverService { if (log.isDebugEnabled()) { log.debug("Retrieving events for given device identifier and type."); } - Message message = new Message(); String query = "deviceIdentifier:" + deviceId + " AND type:" + type; List deviceStates; try { deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); if (deviceStates == null) { - message.setResponseCode("No any alerts are published for given Device: " + - "" + deviceId + "and given specific Type."); - return Response.status(Response.Status.NOT_FOUND).entity(message).build(); + throw new NotFoundException( + new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + + "published for given Device: '" + deviceId + "' and given specific Type.").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 3635bae73..c69d8973f 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 @@ -48,6 +48,8 @@ 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.bean.ErrorResponse; +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; @@ -120,7 +122,8 @@ public class AndroidAPIUtils { 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(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } AndroidDeviceUtils deviceUtils = new AndroidDeviceUtils(); DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs); @@ -140,8 +143,9 @@ public class AndroidAPIUtils { // } // } if (!deviceIDHolder.getErrorDeviceIdList().isEmpty()) { - return javax.ws.rs.core.Response.status(Response.Status.BAD_REQUEST).entity(deviceUtils. - convertErrorMapIntoErrorMessage(deviceIDHolder.getErrorDeviceIdList())).build(); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(deviceUtils. + convertErrorMapIntoErrorMessage(deviceIDHolder.getErrorDeviceIdList())).build()); } return Response.status(Response.Status.CREATED).entity(activity).build(); } From 529c828b817752c2f0897214c8cf237ec72a233b Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Tue, 21 Jun 2016 11:32:01 +0530 Subject: [PATCH 40/41] Fixed paths in Android related permissions.xml --- .../src/main/webapp/META-INF/permissions.xml | 79 ++++++++++--------- 1 file changed, 40 insertions(+), 39 deletions(-) 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 325171927..2839966fb 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 @@ -34,7 +34,7 @@ Lock - /device-mgt/android/operations/lock + /device-mgt/emm-admin/operations/android/lock /admin/devices/lock-devices POST emm_admin,emm_user @@ -42,7 +42,7 @@ Unlock - /device-mgt/android/operations/unlock + /device-mgt/emm-admin/operations/android/unlock /admin/devices/unlock-devices POST emm_admin,emm_user @@ -50,7 +50,7 @@ Mute - /device-mgt/android/operations/mute + /device-mgt/emm-admin/operations/android/mute /admin/devices/mute POST emm_admin,emm_user @@ -58,7 +58,7 @@ Location - /device-mgt/android/operations/location + /device-mgt/emm-admin/operations/android/location /admin/devices/location POST emm_admin,emm_user @@ -66,6 +66,7 @@ Clear Passcode + /device-mgt/emm-admin/operations/android/clear-password /admin/devices/clear-password POST emm_admin @@ -73,7 +74,7 @@ Camera - /device-mgt/android/operations/camera + /device-mgt/emm-admin/operations/android/camera /admin/devices/control-camera POST emm_admin,emm_user @@ -81,7 +82,7 @@ Device Info - /device-mgt/android/operations/device-info + /device-mgt/emm-admin/operations/android/device-info /admin/devices/info POST emm_admin,emm_user @@ -89,7 +90,7 @@ Enterprise Wipe - /device-mgt/android/operations/enterprise-wipe + /device-mgt/emm-admin/operations/android/enterprise-wipe /admin/devices/enterprise-wipe POST emm_admin @@ -97,7 +98,7 @@ Wipe Data - /device-mgt/android/operations/wipe-data + /device-mgt/emm-admin/operations/android/wipe-data /admin/devices/wipe POST emm_admin @@ -105,7 +106,7 @@ Application List - /device-mgt/android/operations/application-list + /device-mgt/emm-admin/operations/android/application-list /admin/devices/applications POST emm_admin,emm_user @@ -113,7 +114,7 @@ Ring - /device-mgt/android/operations/ring-device + /device-mgt/emm-admin/operations/android/ring-device /admin/devices/ring POST emm_admin,emm_user @@ -121,7 +122,7 @@ Reboot - /device-mgt/android/operations/reboot-device + /device-mgt/emm-admin/operations/android/reboot-device /admin/devices/reboot POST emm_admin,emm_user @@ -129,7 +130,7 @@ Upgrade Firmware - /device-mgt/android/operations/upgrade-firmware + /device-mgt/emm-admin/operations/android/upgrade-firmware /admin/devices/upgrade-firmware POST emm_admin @@ -137,7 +138,7 @@ Configure VPN - /device-mgt/android/operations/vpn + /device-mgt/emm-admin/operations/android/vpn /admin/devices/configure-vpn POST emm_admin,emm_user @@ -153,7 +154,7 @@ Update Application - /device-mgt/android/operations/update-application + /device-mgt/emm-admin/operations/android/install-application /admin/devices/update-application POST emm_admin,emm_user @@ -161,7 +162,7 @@ Uninstall Application - /device-mgt/android/operations/uninstall-application + /device-mgt/emm-admin/operations/android/uninstall-application /admin/devices/uninstall-application POST emm_admin,emm_user @@ -169,7 +170,7 @@ Blacklist Applications - /device-mgt/android/operations/blacklist-applications + /device-mgt/emm-admin/operations/android/blacklist-applications /admin/devices/blacklist-applications POST emm_admin @@ -177,7 +178,7 @@ Notification - /device-mgt/android/operations/notification + /device-mgt/emm-admin/operations/android/notification /admin/devices/send-notification POST emm_admin,emm_user @@ -185,7 +186,7 @@ Wifi - /device-mgt/android/operations/wifi + /device-mgt/emm-admin/operations/android/wifi /admin/devices/configure-wifi POST emm_admin @@ -193,7 +194,7 @@ Encryption - /device-mgt/android/operations/encrypt + /device-mgt/emm-admin/operations/android/encrypt /admin/devices/encrypt-storage POST emm_admin @@ -201,7 +202,7 @@ Change lock code - /device-mgt/android/operations/change-lock-code + /device-mgt/emm-admin/operations/android/change-lock-code /admin/devices/change-lock-code POST emm_admin @@ -209,7 +210,7 @@ Password Policy - /device-mgt/android/operations/password-policy + /device-mgt/emm-admin/operations/android/password-policy /admin/devices/set-password-policy POST emm_admin @@ -217,7 +218,7 @@ Webclip - /device-mgt/android/operations/webclip + /device-mgt/emm-admin/operations/android/webclip /admin/devices/set-webclip POST emm_admin @@ -225,7 +226,7 @@ Disenroll - /device-mgt/android/operations/disenroll + /device-mgt/emm-admin/operations/android/disenroll /operation/disenroll POST emm_android_agent @@ -234,7 +235,7 @@ View devices - /device-mgt/android/devices/list + /device-mgt/emm-admin/devices/view /device GET emm_admin @@ -242,7 +243,7 @@ View device - /device-mgt/android/devices/view + /device-mgt/emm-admin/devices/view /device/* GET emm_admin,emm_user @@ -250,7 +251,7 @@ Update device - /device-mgt/android/devices/update + /device-mgt/emm-admin/devices/update /device/* PUT emm_admin,emm_user @@ -258,7 +259,7 @@ Update application list - /device-mgt/android/devices/update-app + /device-mgt/emm-admin/operations/android/update-applist /device/appList/* POST emm_admin @@ -266,7 +267,7 @@ View license - /device-mgt/android/license/view + /device-mgt/user/enroll/android /configuration/license GET emm_android_agent @@ -275,7 +276,7 @@ Enroll device - /device-mgt/android/devices/enroll + /device-mgt/user/enroll/android /devices POST emm_android_agent @@ -283,7 +284,7 @@ Devices related Operations - /device-mgt/android/devices + /device-mgt/user/enroll/android /devices/* GET emm_android_agent @@ -291,7 +292,7 @@ Device is enrolled - /device-mgt/android/devices + /device-mgt/user/enroll/android /devices/*/status GET emm_android_agent @@ -299,7 +300,7 @@ Devices related Operations - /device-mgt/android/devices/operations + /device-mgt/user/enroll/android /devices/*/pending-operations PUT emm_android_agent @@ -307,7 +308,7 @@ Modify devices - /device-mgt/android/devices/operations + /device-mgt/user/enroll/android /devices/* PUT emm_android_agent @@ -315,7 +316,7 @@ Delete devices - /device-mgt/android/devices/operations + /device-mgt/user/enroll/android /devices/* DELETE emm_android_agent @@ -340,7 +341,7 @@ View Policies - /device-mgt/android/policies/view + /device-mgt/user/enroll/android /policy/* GET emm_admin @@ -348,7 +349,7 @@ View Policy Features - /device-mgt/android/policies/view + /device-mgt/user/enroll/android /policy/features/* GET emm_admin @@ -357,7 +358,7 @@ View Tenant configuration - /device-mgt/android/tenant/configuration + /device-mgt/emm-admin/platform-configs/view /configuration GET emm_admin @@ -365,7 +366,7 @@ Add Tenant configuration - /device-mgt/android/tenant/configuration + /device-mgt/emm-admin/platform-configs/add /configuration POST emm_admin @@ -373,7 +374,7 @@ Update Tenant configuration - /device-mgt/android/tenant/configuration + /device-mgt/emm-admin/platform-configs/modify /configuration PUT emm_admin From 6a702adaa320096b248619cda56d7ece64cd2d28 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Tue, 21 Jun 2016 15:51:35 +0530 Subject: [PATCH 41/41] Change emm_admin to admin --- .../src/main/webapp/META-INF/permissions.xml | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) 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 2839966fb..89527545a 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 @@ -34,7 +34,7 @@ Lock - /device-mgt/emm-admin/operations/android/lock + /device-mgt/admin/operations/android/lock /admin/devices/lock-devices POST emm_admin,emm_user @@ -42,7 +42,7 @@ Unlock - /device-mgt/emm-admin/operations/android/unlock + /device-mgt/admin/operations/android/unlock /admin/devices/unlock-devices POST emm_admin,emm_user @@ -50,7 +50,7 @@ Mute - /device-mgt/emm-admin/operations/android/mute + /device-mgt/admin/operations/android/mute /admin/devices/mute POST emm_admin,emm_user @@ -58,7 +58,7 @@ Location - /device-mgt/emm-admin/operations/android/location + /device-mgt/admin/operations/android/location /admin/devices/location POST emm_admin,emm_user @@ -66,7 +66,7 @@ Clear Passcode - /device-mgt/emm-admin/operations/android/clear-password + /device-mgt/admin/operations/android/clear-password /admin/devices/clear-password POST emm_admin @@ -74,7 +74,7 @@ Camera - /device-mgt/emm-admin/operations/android/camera + /device-mgt/admin/operations/android/camera /admin/devices/control-camera POST emm_admin,emm_user @@ -82,7 +82,7 @@ Device Info - /device-mgt/emm-admin/operations/android/device-info + /device-mgt/admin/operations/android/device-info /admin/devices/info POST emm_admin,emm_user @@ -90,7 +90,7 @@ Enterprise Wipe - /device-mgt/emm-admin/operations/android/enterprise-wipe + /device-mgt/admin/operations/android/enterprise-wipe /admin/devices/enterprise-wipe POST emm_admin @@ -98,7 +98,7 @@ Wipe Data - /device-mgt/emm-admin/operations/android/wipe-data + /device-mgt/admin/operations/android/wipe-data /admin/devices/wipe POST emm_admin @@ -106,7 +106,7 @@ Application List - /device-mgt/emm-admin/operations/android/application-list + /device-mgt/admin/operations/android/application-list /admin/devices/applications POST emm_admin,emm_user @@ -114,7 +114,7 @@ Ring - /device-mgt/emm-admin/operations/android/ring-device + /device-mgt/admin/operations/android/ring-device /admin/devices/ring POST emm_admin,emm_user @@ -122,7 +122,7 @@ Reboot - /device-mgt/emm-admin/operations/android/reboot-device + /device-mgt/admin/operations/android/reboot-device /admin/devices/reboot POST emm_admin,emm_user @@ -130,7 +130,7 @@ Upgrade Firmware - /device-mgt/emm-admin/operations/android/upgrade-firmware + /device-mgt/admin/operations/android/upgrade-firmware /admin/devices/upgrade-firmware POST emm_admin @@ -138,7 +138,7 @@ Configure VPN - /device-mgt/emm-admin/operations/android/vpn + /device-mgt/admin/operations/android/vpn /admin/devices/configure-vpn POST emm_admin,emm_user @@ -154,7 +154,7 @@ Update Application - /device-mgt/emm-admin/operations/android/install-application + /device-mgt/admin/operations/android/install-application /admin/devices/update-application POST emm_admin,emm_user @@ -162,7 +162,7 @@ Uninstall Application - /device-mgt/emm-admin/operations/android/uninstall-application + /device-mgt/admin/operations/android/uninstall-application /admin/devices/uninstall-application POST emm_admin,emm_user @@ -170,7 +170,7 @@ Blacklist Applications - /device-mgt/emm-admin/operations/android/blacklist-applications + /device-mgt/admin/operations/android/blacklist-applications /admin/devices/blacklist-applications POST emm_admin @@ -178,7 +178,7 @@ Notification - /device-mgt/emm-admin/operations/android/notification + /device-mgt/admin/operations/android/notification /admin/devices/send-notification POST emm_admin,emm_user @@ -186,7 +186,7 @@ Wifi - /device-mgt/emm-admin/operations/android/wifi + /device-mgt/admin/operations/android/wifi /admin/devices/configure-wifi POST emm_admin @@ -194,7 +194,7 @@ Encryption - /device-mgt/emm-admin/operations/android/encrypt + /device-mgt/admin/operations/android/encrypt /admin/devices/encrypt-storage POST emm_admin @@ -202,7 +202,7 @@ Change lock code - /device-mgt/emm-admin/operations/android/change-lock-code + /device-mgt/admin/operations/android/change-lock-code /admin/devices/change-lock-code POST emm_admin @@ -210,7 +210,7 @@ Password Policy - /device-mgt/emm-admin/operations/android/password-policy + /device-mgt/admin/operations/android/password-policy /admin/devices/set-password-policy POST emm_admin @@ -218,7 +218,7 @@ Webclip - /device-mgt/emm-admin/operations/android/webclip + /device-mgt/admin/operations/android/webclip /admin/devices/set-webclip POST emm_admin @@ -226,7 +226,7 @@ Disenroll - /device-mgt/emm-admin/operations/android/disenroll + /device-mgt/admin/operations/android/disenroll /operation/disenroll POST emm_android_agent @@ -235,7 +235,7 @@ View devices - /device-mgt/emm-admin/devices/view + /device-mgt/admin/devices/view /device GET emm_admin @@ -243,7 +243,7 @@ View device - /device-mgt/emm-admin/devices/view + /device-mgt/admin/devices/view /device/* GET emm_admin,emm_user @@ -251,7 +251,7 @@ Update device - /device-mgt/emm-admin/devices/update + /device-mgt/admin/devices/update /device/* PUT emm_admin,emm_user @@ -259,7 +259,7 @@ Update application list - /device-mgt/emm-admin/operations/android/update-applist + /device-mgt/admin/operations/android/update-applist /device/appList/* POST emm_admin @@ -358,7 +358,7 @@ View Tenant configuration - /device-mgt/emm-admin/platform-configs/view + /device-mgt/admin/platform-configs/view /configuration GET emm_admin @@ -366,7 +366,7 @@ Add Tenant configuration - /device-mgt/emm-admin/platform-configs/add + /device-mgt/admin/platform-configs/add /configuration POST emm_admin @@ -374,7 +374,7 @@ Update Tenant configuration - /device-mgt/emm-admin/platform-configs/modify + /device-mgt/admin/platform-configs/modify /configuration PUT emm_admin