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 943612caf4..adf03b22c6 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 5811c31022..bd668fabaf 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 86e7fb3afa..fdcab01203 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 d8e21c8d4d..d05cb58f8e 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 573e2affc8..eb82e49ee7 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 894bcc4026..53ea4e99e1 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 0000000000..ee2f51d275 --- /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 0000000000..4af066fde1 --- /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 f47999149b..e26d9e2a5c 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 0000000000..5cf9be7ccb --- /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 fc95711a70..0000000000 --- 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 06ccdf3e91..0000000000 --- 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 b150fd19d6..0000000000 --- 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 cf8d295c04..0000000000 --- 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 30ce612d6f..0000000000 --- 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 030f96384c..53e77400c2 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 0000000000..c7111459c7 --- /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 9517f88e43..3b944b33b7 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 16d80297d8..177875a1cf 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 0eec30f256..0000000000 --- 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 adcb2228f2..0000000000 --- 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 33d9c1603c..0000000000 --- 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 778d1d80b2..81e1941dc6 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 8ba454da3d..beb8c010bf 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 f8733cf10c..de4c6dde1e 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 0000000000..455d582bb2 --- /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 89e199a7bd..c92b50a8c4 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 ad42bfafd6..48eeb393eb 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 + /* + +