From 695fdc1cad4cdb6f724313682ecdec76faa277a0 Mon Sep 17 00:00:00 2001 From: mharindu Date: Mon, 15 Aug 2016 15:48:31 +0530 Subject: [PATCH 1/2] Fixed confusing error messages issue --- .../services/EventReceiverService.java | 3 + .../impl/DeviceManagementServiceImpl.java | 55 +++++++++++++------ 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java index cc77bb42f..ff675e1b9 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java @@ -19,6 +19,7 @@ package org.wso2.carbon.mdm.services.android.services; import io.swagger.annotations.*; +import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.mdm.services.android.bean.DeviceState; import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; @@ -85,6 +86,8 @@ public interface EventReceiverService { message = "Internal Server Error. \n " + "Server error occurred while publishing events.") }) + + @Scope(key = "device:android:event:manage", name = "Publish events to DAS", description = "") Response publishEvents( @ApiParam( name = "eventBeanWrapper", diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java index dad6393e0..fc88819ee 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java @@ -209,12 +209,18 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { PolicyManagerService policyManagerService = AndroidAPIUtils.getPolicyManagerService(); policyManagerService.getEffectivePolicy(new DeviceIdentifier(androidDevice.getDeviceIdentifier(), device.getType())); if (status) { - return Response.status(Response.Status.OK).entity("Android device, which carries the id '" + - androidDevice.getDeviceIdentifier() + "' has successfully been enrolled").build(); + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.OK.toString()); + responseMessage.setResponseMessage("Android device, which carries the id '" + + androidDevice.getDeviceIdentifier() + "' has successfully been enrolled"); + return Response.status(Response.Status.OK).entity(responseMessage).build(); } else { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Failed to enroll '" + + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()); + responseMessage.setResponseMessage("Failed to enroll '" + device.getType() + "' device, which carries the id '" + - androidDevice.getDeviceIdentifier() + "'").build(); + androidDevice.getDeviceIdentifier() + "'"); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(responseMessage).build(); } } catch (DeviceManagementException e) { String msg = "Error occurred while enrolling the android, which carries the id '" + @@ -241,11 +247,16 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { 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(); + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.OK.toString()); + responseMessage.setResponseMessage("Android device that carries the id '" + + id + "' is enrolled"); + return Response.status(Response.Status.OK).entity(responseMessage).build(); } else { - return Response.status(Response.Status.NOT_FOUND).entity("No Android device is found upon the id '" + - id + "'").build(); + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.NOT_FOUND.toString()); + responseMessage.setResponseMessage("No Android device is found upon the id '" + id + "'"); + return Response.status(Response.Status.NOT_FOUND).entity(responseMessage).build(); } } catch (DeviceManagementException e) { String msg = "Error occurred while checking enrollment status of the device."; @@ -283,11 +294,17 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { 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(); + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.ACCEPTED.toString()); + responseMessage.setResponseMessage("Enrollment of Android device that " + + "carries the id '" + id + "' has successfully updated"); + return Response.status(Response.Status.ACCEPTED).entity(responseMessage).build(); } else { - return Response.status(Response.Status.NOT_MODIFIED).entity("Enrollment of Android device that " + - "carries the id '" + id + "' has not been updated").build(); + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.NOT_MODIFIED.toString()); + responseMessage.setResponseMessage("Enrollment of Android device that " + + "carries the id '" + id + "' has not been updated"); + return Response.status(Response.Status.NOT_MODIFIED).entity(responseMessage).build(); } } catch (DeviceManagementException e) { msg = "Error occurred while modifying enrollment of the Android device that carries the id '" + @@ -307,11 +324,17 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { 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(); + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.OK.toString()); + responseMessage.setResponseMessage("Android device that carries id '" + id + + "' has successfully dis-enrolled"); + return Response.status(Response.Status.OK).entity(responseMessage).build(); } else { - return Response.status(Response.Status.NOT_FOUND).entity("Android device that carries id '" + id + - "' has not been dis-enrolled").build(); + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.NOT_FOUND.toString()); + responseMessage.setResponseMessage("Android device that carries id '" + id + + "' has not been dis-enrolled"); + return Response.status(Response.Status.NOT_FOUND).entity(responseMessage).build(); } } catch (DeviceManagementException e) { String msg = "Error occurred while dis-enrolling the Android device that carries the id '" + id + "'"; From caf73209b956433d626439a018ec22dbe89ee30d Mon Sep 17 00:00:00 2001 From: mharindu Date: Mon, 15 Aug 2016 15:58:58 +0530 Subject: [PATCH 2/2] Removed unrelevant changes --- .../mdm/services/android/services/EventReceiverService.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java index ff675e1b9..cc77bb42f 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java @@ -19,7 +19,6 @@ package org.wso2.carbon.mdm.services.android.services; import io.swagger.annotations.*; -import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.mdm.services.android.bean.DeviceState; import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; @@ -86,8 +85,6 @@ public interface EventReceiverService { message = "Internal Server Error. \n " + "Server error occurred while publishing events.") }) - - @Scope(key = "device:android:event:manage", name = "Publish events to DAS", description = "") Response publishEvents( @ApiParam( name = "eventBeanWrapper",