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/configuration/ConfigurationMgtService.java index 3a378d9e7..f47999149 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/configuration/ConfigurationMgtService.java @@ -21,18 +21,15 @@ package org.wso2.carbon.mdm.services.android.services.configuration; import io.swagger.annotations.*; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; -import org.wso2.carbon.mdm.services.android.util.Message; - -import javax.jws.WebService; 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") -@WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) public interface ConfigurationMgtService { @@ -48,7 +45,7 @@ public interface ConfigurationMgtService { @ApiResponse(code = 201, message = "Android platform configuration saved successfully"), @ApiResponse(code = 500, message = "Internal Server Error") }) - Message configureSettings(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") + Response configureSettings(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") TenantConfiguration configuration) throws AndroidAgentException; @GET @@ -62,7 +59,7 @@ public interface ConfigurationMgtService { @ApiResponse(code = 200, message = "Get Android Configurations"), @ApiResponse(code = 500, message = "Server Error") }) - TenantConfiguration getConfiguration() throws AndroidAgentException; + Response getConfiguration() throws AndroidAgentException; @PUT @ApiOperation( @@ -77,6 +74,6 @@ public interface ConfigurationMgtService { @ApiResponse(code = 500, message = "Error occurred while modifying configuration settings of " + "Android platform") }) - Message updateConfiguration(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") + Response updateConfiguration(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") 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/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/configuration/impl/ConfigurationMgtServiceImpl.java index 564ba6247..9517f88e4 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/configuration/impl/ConfigurationMgtServiceImpl.java @@ -30,8 +30,6 @@ import org.wso2.carbon.mdm.services.android.services.configuration.Configuration 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.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.Response; import java.util.ArrayList; @@ -41,14 +39,13 @@ import java.util.List; * Android Platform Configuration REST-API implementation. * All end points supports JSON, XMl with content negotiation. */ -@WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { private static Log log = LogFactory.getLog(ConfigurationMgtServiceImpl.class); @POST - public Message configureSettings(TenantConfiguration configuration) + public Response configureSettings(TenantConfiguration configuration) throws AndroidAgentException { Message responseMsg = new Message(); @@ -82,15 +79,15 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { } catch (DeviceManagementException e) { msg = "Error occurred while configuring the android platform"; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMsg; + return Response.status(Response.Status.CREATED).entity(responseMsg).build(); } @GET - public TenantConfiguration getConfiguration() throws AndroidAgentException { + public Response getConfiguration() throws AndroidAgentException { String msg; - TenantConfiguration tenantConfiguration; + TenantConfiguration tenantConfiguration = null; List configs; try { tenantConfiguration = AndroidAPIUtils.getDeviceManagementService(). @@ -99,7 +96,7 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { configs = tenantConfiguration.getConfiguration(); } else { tenantConfiguration = new TenantConfiguration(); - configs = new ArrayList(); + configs = new ArrayList<>(); } ConfigurationEntry entry = new ConfigurationEntry(); @@ -117,13 +114,13 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { } catch (DeviceManagementException e) { msg = "Error occurred while retrieving the Android tenant configuration"; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return tenantConfiguration; + return Response.status(Response.Status.OK).entity(tenantConfiguration).build(); } @PUT - public Message updateConfiguration(TenantConfiguration configuration) throws AndroidAgentException { + public Response updateConfiguration(TenantConfiguration configuration) throws AndroidAgentException { String msg; Message responseMsg = new Message(); ConfigurationEntry licenseEntry = null; @@ -148,15 +145,16 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { } configuration.setConfiguration(configs); AndroidAPIUtils.getDeviceManagementService().saveConfiguration(configuration); + AndroidAPIUtils.getGCMService().resetTenantConfigCache(); Response.status(Response.Status.ACCEPTED); responseMsg.setResponseMessage("Android platform configuration has updated successfully."); responseMsg.setResponseCode(Response.Status.ACCEPTED.toString()); } catch (DeviceManagementException e) { msg = "Error occurred while modifying configuration settings of Android platform"; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMsg; + return Response.status(Response.Status.CREATED).entity(responseMsg).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/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 index f1b518c45..fc95711a7 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/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 @@ -22,11 +22,9 @@ 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 org.wso2.carbon.mdm.services.android.util.Message; - -import javax.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import java.util.List; /** @@ -35,7 +33,6 @@ import java.util.List; */ @Api(value = "DeviceManagementService", description = "Android Device Management REST-API implementation.") -@WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) public interface DeviceManagementService { @@ -62,7 +59,7 @@ public interface DeviceManagementService { @ApiResponse(code = 200, message = "List of Devices"), @ApiResponse(code = 500, message = "Error occurred while fetching the device list") }) - List getAllDevices() throws AndroidAgentException; + Response getAllDevices() throws AndroidAgentException; /** * Fetch Android device details of a given device Id. @@ -86,7 +83,7 @@ public interface DeviceManagementService { @ApiResponse(code = 200, message = "Information of the given device"), @ApiResponse(code = 500, message = "Error occurred while fetching the device information") }) - org.wso2.carbon.device.mgt.common.Device getDevice(@ApiParam(name = "id", value = "deviceIdentifier") + Response getDevice(@ApiParam(name = "id", value = "deviceIdentifier") @PathParam("id") String id) throws AndroidAgentException; /** @@ -110,7 +107,7 @@ public interface DeviceManagementService { @ApiResponse(code = 304, message = "Device not found for the update") }) @Path("{id}") - Message updateDevice(@ApiParam(name = "id", value = "deviceIdentifier") + Response updateDevice(@ApiParam(name = "id", value = "deviceIdentifier") @PathParam("id") String id, @ApiParam(name = "device", value = "deviceIdentifier") Device device) throws AndroidAgentException; @@ -125,9 +122,9 @@ public interface DeviceManagementService { @ApiResponse(code = 202, message = "Device information has modified successfully"), @ApiResponse(code = 500, message = "Error occurred while modifying the application list") }) - Message updateApplicationList(@ApiParam(name = "id", value = "deviceIdentifier") @PathParam("id") String id, + Response updateApplicationList(@ApiParam(name = "id", value = "deviceIdentifier") @PathParam("id") String id, @ApiParam(name = "applications", value = "updatable applications") - List applications); + List applications) throws AndroidAgentException; @GET @Path("license") @@ -144,5 +141,5 @@ public interface DeviceManagementService { @ApiResponse(code = 500, message = "Error occurred while retrieving the license configured for Android " + "device enrolment") }) - String getLicense() throws AndroidAgentException; + 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 index f1cb678df..06ccdf3e9 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/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 @@ -28,10 +28,9 @@ 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.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.Response; import java.util.List; @@ -40,10 +39,9 @@ import java.util.List; * Android Device Management REST-API implementation. * All end points supports JSON, XMl with content negotiation. */ -@WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) -public class DeviceManagementServiceImpl { +public class DeviceManagementServiceImpl implements DeviceManagementService { private static Log log = LogFactory.getLog(DeviceManagementServiceImpl.class); @@ -54,7 +52,7 @@ public class DeviceManagementServiceImpl { * @throws AndroidAgentException */ @GET - public List getAllDevices() + public Response getAllDevices() throws AndroidAgentException { String msg; List devices; @@ -66,9 +64,9 @@ public class DeviceManagementServiceImpl { } catch (DeviceManagementException e) { msg = "Error occurred while fetching the device list."; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return devices; + return Response.status(Response.Status.OK).entity(devices).build(); } /** @@ -80,7 +78,7 @@ public class DeviceManagementServiceImpl { */ @GET @Path("{id}") - public Device getDevice(@PathParam("id") String id) + public Response getDevice(@PathParam("id") String id) throws AndroidAgentException { String msg; @@ -90,14 +88,14 @@ public class DeviceManagementServiceImpl { DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier); if (device == null) { - Response.status(Response.Status.NOT_FOUND); + return Response.status(Response.Status.NOT_FOUND).build(); } } catch (DeviceManagementException deviceMgtEx) { msg = "Error occurred while fetching the device information."; log.error(msg, deviceMgtEx); - throw new AndroidAgentException(msg, deviceMgtEx); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return device; + return Response.status(Response.Status.OK).entity(device).build(); } /** @@ -110,7 +108,7 @@ public class DeviceManagementServiceImpl { */ @PUT @Path("{id}") - public Message updateDevice(@PathParam("id") String id, Device device) + public Response updateDevice(@PathParam("id") String id, Device device) throws AndroidAgentException { String msg; Message responseMessage = new Message(); @@ -124,23 +122,22 @@ public class DeviceManagementServiceImpl { result = AndroidAPIUtils.getDeviceManagementService() .updateDeviceInfo(deviceIdentifier, device); if (result) { - Response.status(Response.Status.ACCEPTED); responseMessage.setResponseMessage("Device information has modified successfully."); + return Response.status(Response.Status.ACCEPTED).entity(responseMessage).build(); } else { - Response.status(Response.Status.NOT_MODIFIED); 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); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMessage; } @POST @Path("appList/{id}") - public Message updateApplicationList(@PathParam("id") String id, List applications) + public Response updateApplicationList(@PathParam("id") String id, List applications) throws AndroidAgentException { @@ -151,22 +148,20 @@ public class DeviceManagementServiceImpl { try { AndroidAPIUtils.getApplicationManagerService(). updateApplicationListInstalledInDevice(deviceIdentifier, applications); - Response.status(Response.Status.ACCEPTED); 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); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMessage; } @GET @Path("license") @Produces("text/html") - public String getLicense() throws AndroidAgentException { - License license; + public Response getLicense() throws AndroidAgentException { + License license = null; try { license = @@ -176,9 +171,9 @@ public class DeviceManagementServiceImpl { } catch (DeviceManagementException e) { String msg = "Error occurred while retrieving the license configured for Android device enrolment"; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return (license == null) ? null : license.getText(); + 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 index 6c6aa2e37..b150fd19d 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/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 @@ -20,11 +20,9 @@ package org.wso2.carbon.mdm.services.android.services.enrollment; import io.swagger.annotations.*; import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; -import org.wso2.carbon.mdm.services.android.util.Message; - -import javax.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; /** * Android Device Enrollment REST-API implementation. @@ -32,7 +30,6 @@ import javax.ws.rs.core.MediaType; */ @Api(value = "EnrollmentService", description = "Android Device Enrollment REST-API implementation.") -@WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) public interface EnrollmentService { @@ -51,7 +48,7 @@ public interface EnrollmentService { @ApiResponse(code = 201, message = "Device enrollment succeeded"), @ApiResponse(code = 500, message = "Device enrollment failed"), }) - Message enrollDevice(@ApiParam(name = "device", value = "Device Information to be enroll") + Response enrollDevice(@ApiParam(name = "device", value = "Device Information to be enroll") org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException; @GET @@ -65,7 +62,7 @@ public interface EnrollmentService { @ApiResponse(code = 202, message = "Device has already enrolled"), @ApiResponse(code = 404, message = "Device not found") }) - Message isEnrolled(@ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id) + Response isEnrolled(@ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id) throws AndroidAgentException; @PUT @@ -79,7 +76,7 @@ public interface EnrollmentService { @ApiResponse(code = 202, message = "Device enrollment has updated successfully"), @ApiResponse(code = 404, message = "Device not found for enrollment") }) - Message modifyEnrollment(@ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id, + 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; @@ -95,6 +92,6 @@ public interface EnrollmentService { @ApiResponse(code = 404, message = "Device not found") }) @Path("{deviceId}") - Message disEnrollDevice(@ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id) + 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 index 328377047..cf8d295c0 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/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 @@ -27,8 +27,6 @@ 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.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.Response; @@ -36,7 +34,6 @@ import javax.ws.rs.core.Response; * Android Device Enrollment REST-API implementation. * All end points supports JSON, XMl with content negotiation. */ -@WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) public class EnrollmentServiceImpl implements EnrollmentService { @@ -44,7 +41,7 @@ public class EnrollmentServiceImpl implements EnrollmentService { private static Log log = LogFactory.getLog(EnrollmentService.class); @POST - public Message enrollDevice(org.wso2.carbon.device.mgt.common.Device device) + public Response enrollDevice(org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException { Message responseMsg = new Message(); @@ -56,23 +53,22 @@ public class EnrollmentServiceImpl implements EnrollmentService { if (status) { Response.status(Response.Status.CREATED); responseMsg.setResponseMessage("Device enrollment succeeded."); - responseMsg.setResponseCode(Response.Status.CREATED.toString()); + return Response.status(Response.Status.CREATED).entity(responseMsg).build(); } else { Response.status(Response.Status.INTERNAL_SERVER_ERROR); responseMsg.setResponseMessage("Device enrollment failed."); - responseMsg.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()); + 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); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMsg; } @GET @Path("{deviceId}") - public Message isEnrolled(@PathParam("deviceId") String id) throws AndroidAgentException { + public Response isEnrolled(@PathParam("deviceId") String id) throws AndroidAgentException { String msg; boolean result; Message responseMsg = new Message(); @@ -83,11 +79,11 @@ public class EnrollmentServiceImpl implements EnrollmentService { if (result) { responseMsg.setResponseMessage("Device has already enrolled"); responseMsg.setResponseCode(Response.Status.ACCEPTED.toString()); - Response.status(Response.Status.ACCEPTED); + return Response.status(Response.Status.ACCEPTED).entity(responseMsg).build(); } else { responseMsg.setResponseMessage("Device not found"); responseMsg.setResponseCode(Response.Status.NOT_FOUND.toString()); - Response.status(Response.Status.NOT_FOUND); + return Response.status(Response.Status.NOT_FOUND).entity(responseMsg).build(); } } catch (DeviceManagementException e) { msg = "Error occurred while checking enrollment status of the device."; @@ -95,14 +91,13 @@ public class EnrollmentServiceImpl implements EnrollmentService { responseMsg.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()); Response.status(Response.Status.INTERNAL_SERVER_ERROR); log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMsg; } @PUT @Path("{deviceId}") - public Message modifyEnrollment(@PathParam("deviceId") String id, + public Response modifyEnrollment(@PathParam("deviceId") String id, org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException { String msg; @@ -114,23 +109,22 @@ public class EnrollmentServiceImpl implements EnrollmentService { if (result) { responseMsg.setResponseMessage("Device enrollment has updated successfully"); responseMsg.setResponseCode(Response.Status.ACCEPTED.toString()); - Response.status(Response.Status.ACCEPTED); + return Response.status(Response.Status.ACCEPTED).entity(responseMsg).build(); } else { responseMsg.setResponseMessage("Device not found for enrollment"); responseMsg.setResponseCode(Response.Status.NOT_MODIFIED.toString()); - Response.status(Response.Status.NOT_MODIFIED); + 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); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMsg; } @DELETE @Path("{deviceId}") - public Message disEnrollDevice(@PathParam("deviceId") String id) throws AndroidAgentException { + public Response disEnrollDevice(@PathParam("deviceId") String id) throws AndroidAgentException { Message responseMsg = new Message(); boolean result; String msg; @@ -141,18 +135,17 @@ public class EnrollmentServiceImpl implements EnrollmentService { if (result) { responseMsg.setResponseMessage("Device has removed successfully"); responseMsg.setResponseCode(Response.Status.ACCEPTED.toString()); - Response.status(Response.Status.ACCEPTED); + return Response.status(Response.Status.ACCEPTED).entity(responseMsg).build(); } else { responseMsg.setResponseMessage("Device not found"); responseMsg.setResponseCode(Response.Status.NOT_FOUND.toString()); - Response.status(Response.Status.NOT_FOUND); + 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); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMsg; } } 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 index ece87536c..0eec30f25 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/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 @@ -50,7 +50,7 @@ public interface OperationMgtService { @ApiResponse(code = 200, message = "List of pending operations"), @ApiResponse(code = 500, message = "Issue in retrieving operation management service instance") }) - List getPendingOperations( + 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") @@ -62,17 +62,34 @@ public interface OperationMgtService { consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Adding a Device Lock on Android Devices", - responseContainer = "List", notes = "Using this API you have the option of hard locking an Android device, where the Administrator " + - "permanently locks the device or screen locking an Android device", + "permanently locks the device or screen locking an Android device" + ) + @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 configureDeviceLock(@ApiParam(name = "acceptHeader", value = "Accept Header") + Response configureDeviceUnlock(@ApiParam(name = "acceptHeader", value = "Accept Header") @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "deviceIDs", value = - "DeviceIds to be enable device lock operation") + "DeviceIds to be enable device unlock operation") List deviceIDs); @@ -219,6 +236,22 @@ public interface OperationMgtService { @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, @@ -256,6 +289,27 @@ public interface OperationMgtService { 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( @@ -293,6 +347,44 @@ public interface OperationMgtService { 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( 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/operationmgt/impl/OperationMgtServiceImpl.java index f85f218a8..030f96384 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/operationmgt/impl/OperationMgtServiceImpl.java @@ -29,8 +29,8 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept 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.exception.AndroidOperationException; import org.wso2.carbon.mdm.services.android.services.operationmgt.OperationMgtService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.AndroidConstants; @@ -43,7 +43,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; -public class OperationMgtServiceImpl { +public class OperationMgtServiceImpl implements OperationMgtService { private static Log log = LogFactory.getLog(OperationMgtService.class); private static final String ACCEPT = "Accept"; @@ -52,28 +52,31 @@ public class OperationMgtServiceImpl { @PUT @Path("{id}") - public List getPendingOperations + 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()) { - String errorMessage = "Device identifier is null or empty, hence returning device not found"; + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); try { if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) { - String errorMessage = "Device not found for identifier '" + id + "'"; + errorMessage = "Device not found for identifier '" + id + "'"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.BAD_REQUEST.toString()).build(); log.error(errorMessage); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } if (log.isDebugEnabled()) { log.debug("Invoking Android pending operations:" + id); @@ -82,33 +85,51 @@ public class OperationMgtServiceImpl { updateOperations(id, resultOperations); } } catch (OperationManagementException e) { - log.error("Issue in retrieving operation management service instance", 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) { - log.error("Issue in updating Monitoring operation"); + 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) { - log.error("Issue in retrieving device management service instance", 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) { - log.error("Issue in retrieving application management service instance", 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) { - log.error("Issue in retrieving Notification management service instance", 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) { - String errorMessage = "Issue in retrieving operation management service instance"; + errorMessage = "Issue in retrieving operation management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } - return pendingOperations; + return Response.status(Response.Status.CREATED).entity(pendingOperations).type( + responseMediaType).build(); } @POST @Path("lock") - public Response configureDeviceLock(@HeaderParam(ACCEPT) String acceptHeader, List deviceIDs) { + public Response configureDeviceLock(@HeaderParam(ACCEPT) String acceptHeader, + DeviceLockBeanWrapper deviceLockBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking Android device lock operation"); @@ -119,8 +140,56 @@ public class OperationMgtServiceImpl { Response response; try { - CommandOperation operation = new CommandOperation(); + DeviceLock lock = deviceLockBeanWrapper.getOperation(); + + if (lock == null) { + String errorMessage = "Lock bean is empty"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_LOCK); + operation.setType(Operation.Type.PROFILE); + operation.setEnabled(true); + operation.setPayLoad(lock.toJSON()); + response = AndroidAPIUtils.getOperationResponse(deviceLockBeanWrapper.getDeviceIDs(), operation, + message, 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(); + } + return response; + } + + @POST + @Path("unlock") + public Response configureDeviceUnlock(@HeaderParam(ACCEPT) String acceptHeader, List deviceIDs) { + + if (log.isDebugEnabled()) { + log.debug("Invoking Android device unlock operation"); + } + + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + Message message = new Message(); + Response response; + + try { + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.DEVICE_UNLOCK); operation.setType(Operation.Type.COMMAND); operation.setEnabled(true); response = AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message, responseMediaType); @@ -129,13 +198,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } return response; } @@ -161,13 +232,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -194,13 +267,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -239,13 +314,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -265,7 +342,6 @@ public class OperationMgtServiceImpl { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO); operation.setType(Operation.Type.COMMAND); - getApplications(acceptHeader, deviceIDs); return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message, responseMediaType); } catch (OperationManagementException e) { @@ -273,13 +349,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -307,13 +385,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -349,13 +429,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -383,13 +465,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -416,13 +500,50 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + } + + @POST + @Path("reboot-device") + public Response rebootDevice(@HeaderParam(ACCEPT) String acceptHeader, + 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); + } 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(); } } @@ -450,13 +571,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -479,7 +602,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the application installing operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new application installation instance"); + String errorMessage = "Issue in creating a new application installation 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(); } ProfileOperation operation = new ProfileOperation(); @@ -494,13 +622,66 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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("update-application") + public Response updateApplication(@HeaderParam(ACCEPT) String acceptHeader, + ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper) { + + if (log.isDebugEnabled()) { + log.debug("Invoking 'UpdateApplication' operation"); + } + + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + Message message = new Message(); + + try { + ApplicationUpdate applicationUpdate = applicationUpdateBeanWrapper.getOperation(); + + if (applicationUpdate == null) { + if (log.isDebugEnabled()) { + log.debug("The payload of the application update operation is incorrect"); + } + String errorMessage = "Issue in creating a new application update instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.UPDATE_APPLICATION); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(applicationUpdate.toJSON()); + + return AndroidAPIUtils.getOperationResponse(applicationUpdateBeanWrapper.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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -522,7 +703,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the application uninstalling operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new application uninstallation instance"); + String errorMessage = "Issue in creating a new application uninstallation 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(); } ProfileOperation operation = new ProfileOperation(); @@ -537,13 +723,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -565,7 +753,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the blacklisting apps operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new blacklist applications instance"); + String errorMessage = "Issue in creating a new blacklist applications 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(); } ProfileOperation operation = new ProfileOperation(); @@ -581,13 +774,115 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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("upgrade-firmware") + public Response upgradeFirmware(@HeaderParam(ACCEPT) String acceptHeader, + UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper) { + + if (log.isDebugEnabled()) { + log.debug("Invoking Android upgrade-firmware device operation"); + } + + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + Message message = new Message(); + + try { + UpgradeFirmware upgradeFirmware = upgradeFirmwareBeanWrapper.getOperation(); + + if (upgradeFirmware == null) { + if (log.isDebugEnabled()) { + log.debug("The payload of the upgrade firmware operation is incorrect"); + } + String errorMessage = "Issue in creating a new upgrade firmware instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.UPGRADE_FIRMWARE); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(upgradeFirmware.toJSON()); + return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + } + + @POST + @Path("vpn") + public Response configureVPN(@HeaderParam(ACCEPT) String acceptHeader, + VpnBeanWrapper vpnBeanWrapper) { + + if (log.isDebugEnabled()) { + log.debug("Invoking Android VPN device operation"); + } + + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + Message message = new Message(); + + try { + Vpn vpn = vpnBeanWrapper.getOperation(); + + if (vpn == null) { + if (log.isDebugEnabled()) { + log.debug("The payload of the VPN operation is incorrect"); + } + String errorMessage = "Issue in creating a new VPN instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.VPN); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(vpn.toJSON()); + return AndroidAPIUtils.getOperationResponse(vpnBeanWrapper.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(); } } @@ -609,7 +904,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the notification operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new notification instance"); + String errorMessage = "Issue in creating a new notification 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(); } ProfileOperation operation = new ProfileOperation(); @@ -625,13 +925,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -653,7 +955,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the wifi operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new Wifi instance"); + String errorMessage = "Issue in creating a new Wifi 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(); } ProfileOperation operation = new ProfileOperation(); @@ -669,13 +976,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -697,7 +1006,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the device encryption operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new encryption instance"); + String errorMessage = "Issue in creating a new encryption 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(); @@ -713,13 +1027,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -741,7 +1057,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the change lock code operation is incorrect"); } - throw new OperationManagementException("Issue in retrieving a new lock-code instance"); + String errorMessage = "Issue in retrieving a new lock-code 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(); } ProfileOperation operation = new ProfileOperation(); @@ -757,13 +1078,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -785,7 +1108,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the change password policy operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new Password policy instance"); + String errorMessage = "Issue in creating a new Password policy 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(); } ProfileOperation operation = new ProfileOperation(); @@ -801,13 +1129,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -829,7 +1159,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the add webclip operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new web clip instance"); + String errorMessage = "Issue in creating a new web clip 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(); } ProfileOperation operation = new ProfileOperation(); @@ -845,13 +1180,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -874,7 +1211,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the device disenrollment operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new disenrollment instance"); + 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(); @@ -890,13 +1232,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + 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); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).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/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 index e35f08b23..adcb2228f 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/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 @@ -26,6 +26,7 @@ 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.") @@ -47,9 +48,9 @@ public interface PolicyMgtService { @ApiResponse(code = 200, message = "Effective policy added to operation"), @ApiResponse(code = 204, message = "No effective policy found") }) - Message getEffectivePolicy(@ApiParam(name = "acceptHeader", value = "Accept Header") @HeaderParam("Accept") + Response getEffectivePolicy(@ApiParam(name = "acceptHeader", value = "Accept Header") @HeaderParam("Accept") String acceptHeader, - @ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") + @ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id) throws AndroidAgentException; @GET @@ -66,7 +67,7 @@ public interface PolicyMgtService { @ApiResponse(code = 404, message = "Not Found"), @ApiResponse(code = 500, message = "Error occurred while getting the features") }) - List getEffectiveFeatures(@ApiParam(name = "acceptHeader", value = "Accept Header") + 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 index eed862683..33d9c1603 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/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 @@ -35,18 +35,20 @@ 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 { +public class PolicyMgtServiceImpl implements PolicyMgtService { private static Log log = LogFactory.getLog(PolicyMgtService.class); @GET @Path("{deviceId}") - public Message getEffectivePolicy(@HeaderParam("Accept") String acceptHeader, + 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 { @@ -55,35 +57,44 @@ public class PolicyMgtServiceImpl { 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); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type( + responseMediaType).build(); } - return responseMessage; } @GET @Path("/features/{deviceId}") - public List getEffectiveFeatures(@HeaderParam("Accept") String acceptHeader, + 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); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type( + responseMediaType).build(); } - return profileFeatures; + 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 72f4f7965..9730844ed 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 @@ -281,7 +281,7 @@ public class AndroidAPIUtils { deviceInfo.setDeviceIdentifier(deviceIdentifier); updateDeviceInfo(deviceInfo); } catch (DeviceDetailsMgtException e) { - throw new OperationManagementException("Error occurred while updating the device infomation.", e); + throw new OperationManagementException("Error occurred while updating the device information.", e); } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml index 9c6e31a55..1fd0c7c66 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml @@ -46,6 +46,14 @@ emm_admin,emm_user + + Unlock + /device-mgt/android/operations/unlock + /operation/unlock + POST + emm_admin,emm_user + + Mute /device-mgt/android/operations/mute @@ -117,6 +125,30 @@ emm_admin,emm_user + + Reboot + /device-mgt/android/operations/reboot-device + /operation/reboot-device + POST + emm_admin,emm_user + + + + Upgrade Firmware + /device-mgt/android/operations/upgrade-firmware + /operation/upgrade-firmware + POST + emm_admin,emm_user + + + + Configure VPN + /device-mgt/android/operations/vpn + /operation/vpn + POST + emm_admin,emm_user + + Install Application /device-mgt/android/operations/install-application @@ -125,6 +157,14 @@ emm_admin,emm_user + + Update Application + /device-mgt/android/operations/update-application + /operation/update-application + POST + emm_admin,emm_user + + Uninstall Application /device-mgt/android/operations/uninstall-application @@ -312,4 +352,32 @@ PUT emm_admin + + Event Addition + /device-mgt/android/events/add + /events + POST + emm_user,emm_admin + + + Event Retrieve + /device-mgt/android/events/view + /events/* + GET + emm_admin + + + Event Retrieve + /device-mgt/android/events/date + /events/*/date + GET + emm_admin + + + Event Retrieve + /device-mgt/android/events/type + /events/*/type/* + GET + emm_admin + \ No newline at end of file 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 27ff000ae..89e199a7b 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 @@ -68,13 +68,22 @@ + + + + + + + + + - - - - - - + + + + + +