From 70c980f46f166a215ed342a3d8ec61bfb00e220a Mon Sep 17 00:00:00 2001 From: shamalka Date: Tue, 3 Dec 2019 11:21:14 +0530 Subject: [PATCH] Replace BadRequestException in Android APIs --- .../api/impl/DeviceManagementAPIImpl.java | 14 + .../impl/DeviceManagementAdminAPIImpl.java | 530 +++++++++++++++--- .../api/impl/EventReceiverAPIImpl.java | 26 +- .../android/common/spi/AndroidService.java | 484 +++++++++++++--- .../android/core/impl/AndroidServiceImpl.java | 283 +++++----- 5 files changed, 1045 insertions(+), 292 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAPIImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAPIImpl.java index f958dd87a1..633d37231e 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAPIImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAPIImpl.java @@ -47,7 +47,9 @@ import org.wso2.carbon.device.mgt.mobile.android.common.Message; import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.AndroidApplication; import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.AndroidDevice; +import org.wso2.carbon.device.mgt.mobile.android.common.exception.AndroidDeviceMgtPluginException; import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestException; +import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestExceptionDup; import org.wso2.carbon.device.mgt.mobile.android.common.exception.UnexpectedServerErrorException; import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils; @@ -193,6 +195,18 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI { log.error(msg, e); throw new UnexpectedServerErrorException( new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAdminAPIImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAdminAPIImpl.java index 6da17c3ed2..a7032677e2 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAdminAPIImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAdminAPIImpl.java @@ -35,6 +35,7 @@ */ package org.wso2.carbon.device.mgt.mobile.android.api.impl; +import com.google.api.client.http.HttpStatusCodes; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.HttpStatus; @@ -86,7 +87,9 @@ import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.VpnBeanWrap import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.WebClipBeanWrapper; import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.WifiBeanWrapper; import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.WipeDataBeanWrapper; +import org.wso2.carbon.device.mgt.mobile.android.common.exception.AndroidDeviceMgtPluginException; import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestException; +import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestExceptionDup; import org.wso2.carbon.device.mgt.mobile.android.common.exception.UnexpectedServerErrorException; import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils; @@ -127,8 +130,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance for file transfer operation"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e) { + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing file tranfer operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -147,8 +163,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing device lock operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -167,8 +196,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing device unlock operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -187,8 +229,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while retrieving device location"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -207,8 +262,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance."; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing remove password operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -227,8 +295,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing control camera operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -248,6 +329,18 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while retrieving device information"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -267,6 +360,18 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while retrieving device logcat"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -285,8 +390,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing enterprice wipe device operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -305,8 +423,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing Android wipe-data device operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -325,8 +456,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing Android getApplicationList device operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -345,8 +489,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing Android ring device operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -365,8 +522,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing Android reboot device operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -385,8 +555,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing Android change LockTask mode operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -405,8 +588,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing mute device operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -426,8 +622,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing install application operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -446,8 +655,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing update application operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -467,8 +689,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing uninstall application operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -487,8 +722,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing blacklist application operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -507,8 +755,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing upgrade firmware operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -527,8 +788,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing configure vpn operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -547,8 +821,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing send notification operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -567,8 +854,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing configure wifi operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -587,8 +887,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing encrypt operation operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -607,8 +920,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing change lock code operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -627,8 +953,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing set password policy operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -647,8 +986,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing set webclip operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -669,8 +1021,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500L).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while applying 'configure-global-proxy' operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @POST @@ -682,35 +1047,22 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { log.debug("Invoking 'send application configuration' operation"); } - try { - if (applicationRestrictionBeanWrapper == null || applicationRestrictionBeanWrapper.getOperation() == null) { - String errorMessage = "The payload of the application configuration operation is incorrect"; - log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); - } - ApplicationRestriction applicationRestriction = applicationRestrictionBeanWrapper.getOperation(); - ProfileOperation operation = new ProfileOperation(); - operation.setCode(AndroidConstants.OperationCodes.REMOTE_APP_CONFIG); - operation.setType(Operation.Type.PROFILE); - operation.setPayLoad(applicationRestriction.toJSON()); - return (Response) AndroidAPIUtils.getOperationResponse(applicationRestrictionBeanWrapper.getDeviceIDs(), - operation); - } catch (InvalidDeviceException e) { - String errorMessage = "Invalid Device Identifiers found."; - log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); - } catch (OperationManagementException e) { - String errorMessage = "Issue in retrieving operation management service instance"; - log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); - } catch (DeviceManagementException e) { - String errorMessage = "Issue in retrieving device management service instance"; + try{ + AndroidService androidService = AndroidAPIUtils.getAndroidService(); + Response response = androidService.sendApplicationConfiguration(applicationRestrictionBeanWrapper); + return Response.status(Response.Status.CREATED).entity(response).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while sending app configuration"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -730,9 +1082,21 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder(). - setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR).setMessage(errorMessage).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing configure-display-message operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/EventReceiverAPIImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/EventReceiverAPIImpl.java index 776ed4fed8..4d55877c7f 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/EventReceiverAPIImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/EventReceiverAPIImpl.java @@ -18,6 +18,7 @@ */ package org.wso2.carbon.device.mgt.mobile.android.api.impl; +import com.google.api.client.http.HttpStatusCodes; import com.google.gson.Gson; import com.google.gson.JsonObject; import org.apache.commons.logging.Log; @@ -35,9 +36,7 @@ import org.wso2.carbon.device.mgt.mobile.android.common.Message; import org.wso2.carbon.device.mgt.mobile.android.common.bean.DeviceState; import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EventBeanWrapper; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestException; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.NotFoundException; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.UnexpectedServerErrorException; +import org.wso2.carbon.device.mgt.mobile.android.common.exception.*; import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils; @@ -133,9 +132,22 @@ public class EventReceiverAPIImpl implements EventReceiverAPI { @Size(min = 2, max = 45) @QueryParam("type") String type, @HeaderParam("If-Modified-Since") String ifModifiedSince) { - - AndroidService androidService = AndroidAPIUtils.getAndroidService(); - Response response = androidService.retrieveAlerts(deviceId, from, to, type, ifModifiedSince); - return response; + try{ + AndroidService androidService = AndroidAPIUtils.getAndroidService(); + Response response = androidService.retrieveAlerts(deviceId, from, to, type, ifModifiedSince); + return response; + } catch (BadRequestExceptionDup e){ + String msg = "Invalid request"; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while retrieving alerts"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); + } } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/spi/AndroidService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/spi/AndroidService.java index 04e5039a3a..b6565ad954 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/spi/AndroidService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/spi/AndroidService.java @@ -35,6 +35,7 @@ import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseTokenUrl; import org.wso2.carbon.device.mgt.mobile.android.common.bean.GoogleAppSyncResponse; import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.*; import org.wso2.carbon.device.mgt.mobile.android.common.exception.AndroidDeviceMgtPluginException; +import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestExceptionDup; import org.wso2.carbon.device.mgt.mobile.android.common.exception.EnterpriseServiceException; import javax.validation.Valid; @@ -47,95 +48,438 @@ import java.util.List; public interface AndroidService { + /** + * Method to retrieve platform configurations + * + * @return {@link PlatformConfiguration} + * @throws {@link DeviceManagementException} + */ PlatformConfiguration getPlatformConfig() throws DeviceManagementException; + /** + * Method to update configurations + * + * @param androidPlatformConfiguration + * @throws {@link AndroidDeviceMgtPluginException} + */ void updateConfiguration(AndroidPlatformConfiguration androidPlatformConfiguration) throws AndroidDeviceMgtPluginException; - Message isEnrolled(String id, DeviceIdentifier deviceIdentifier) throws DeviceManagementException; - - Activity fileTransfer(FileTransferBeanWrapper fileTransferBeanWrapper) throws OperationManagementException; - - Activity configureDeviceLock(DeviceLockBeanWrapper deviceLockBeanWrapper) throws OperationManagementException; - - Activity configureDeviceUnlock(List deviceIDs) throws OperationManagementException; - - Activity getDeviceLocation(List deviceIDs) throws OperationManagementException; - - Activity removePassword(List deviceIDs) throws OperationManagementException; - - Activity configureCamera(CameraBeanWrapper cameraBeanWrapper) throws OperationManagementException; - - Activity getDeviceInformation(List deviceIDs) throws OperationManagementException; - - Activity getDeviceLogcat(List deviceIDs) throws OperationManagementException; - - Activity wipeDevice(List deviceIDs) throws OperationManagementException; - - Activity wipeData(WipeDataBeanWrapper wipeDataBeanWrapper) throws OperationManagementException; - - Activity getApplications(List deviceIDs) throws OperationManagementException; - - Activity ringDevice(List deviceIDs) throws OperationManagementException; - - Activity rebootDevice(List deviceIDs) throws OperationManagementException; - - Activity changeLockTask(List deviceIDs) throws OperationManagementException; - - Activity muteDevice(List deviceIDs) throws OperationManagementException; - + /** + * Method for file transfer operation + * + * @param fileTransferBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity fileTransfer(FileTransferBeanWrapper fileTransferBeanWrapper) + throws AndroidDeviceMgtPluginException, OperationManagementException; + + /** + * Method for device lock operation + * + * @param deviceLockBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity configureDeviceLock(DeviceLockBeanWrapper deviceLockBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for device unlock operation + * + * @param deviceIDs + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity configureDeviceUnlock(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for get device location operation + * + * @param deviceIDs + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity getDeviceLocation(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for remove password operation + * + * @param deviceIDs + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity removePassword(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for configure camera operation + * + * @param cameraBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity configureCamera(CameraBeanWrapper cameraBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method to get device information + * + * @param deviceIDs + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity getDeviceInformation(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method to get device logcat + * + * @param deviceIDs + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity getDeviceLogcat(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for wipe device operation + * + * @param deviceIDs + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity wipeDevice(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for wipe data operation + * + * @param wipeDataBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity wipeData(WipeDataBeanWrapper wipeDataBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for get applications operation + * + * @param deviceIDs + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity getApplications(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for ring device operation + * + * @param deviceIDs + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity ringDevice(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for reboot device operation + * + * @param deviceIDs + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity rebootDevice(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for change lock task operation + * + * @param deviceIDs + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity changeLockTask(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for mute device operation + * + * @param deviceIDs + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity muteDevice(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for install application operation + * + * @param applicationInstallationBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ Activity installApplication(ApplicationInstallationBeanWrapper applicationInstallationBeanWrapper) - throws OperationManagementException; - + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for update application operation + * + * @param applicationUpdateBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ Activity updateApplication(ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper) - throws OperationManagementException; - + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for uninstall application operation + * + * @param applicationUninstallationBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ Activity uninstallApplication(ApplicationUninstallationBeanWrapper applicationUninstallationBeanWrapper) - throws OperationManagementException; - + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for blacklist application operation + * + * @param blacklistApplicationsBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ Activity blacklistApplications(@Valid BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper) - throws OperationManagementException; - + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for upgrade firmware operation + * + * @param upgradeFirmwareBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ Activity upgradeFirmware(UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper) - throws OperationManagementException; - - Activity configureVPN(VpnBeanWrapper vpnConfiguration) throws OperationManagementException; - + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for configure vpn operation + * + * @param vpnConfiguration + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity configureVPN(VpnBeanWrapper vpnConfiguration) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for send notification operation + * + * @param notificationBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ Activity sendNotification(NotificationBeanWrapper notificationBeanWrapper) - throws OperationManagementException; - - Activity configureWifi(WifiBeanWrapper wifiBeanWrapper) throws OperationManagementException; - - Activity encryptStorage(EncryptionBeanWrapper encryptionBeanWrapper) throws OperationManagementException; - - Activity changeLockCode(LockCodeBeanWrapper lockCodeBeanWrapper) throws OperationManagementException; - - Activity setPasswordPolicy(PasswordPolicyBeanWrapper passwordPolicyBeanWrapper) throws OperationManagementException; - - Activity setWebClip(WebClipBeanWrapper webClipBeanWrapper) throws OperationManagementException; - - Activity setRecommendedGlobalProxy(GlobalProxyBeanWrapper globalProxyBeanWrapper) throws OperationManagementException; - - Activity configureDisplayMessage(DisplayMessageBeanWrapper displayMessageBeanWrapper) throws OperationManagementException; - - //DeviceManagementAPIImpl - Message updateApplicationList(String id, List androidApplications) throws ApplicationManagementException; + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for configure wifi operation + * + * @param wifiBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity configureWifi(WifiBeanWrapper wifiBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for encypt storage operation + * + * @param encryptionBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity encryptStorage(EncryptionBeanWrapper encryptionBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for change lock code operation + * + * @param lockCodeBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity changeLockCode(LockCodeBeanWrapper lockCodeBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for set password policy operation + * + * @param passwordPolicyBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity setPasswordPolicy(PasswordPolicyBeanWrapper passwordPolicyBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for set webclip operation + * + * @param webClipBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity setWebClip(WebClipBeanWrapper webClipBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for set recommended global proxy operation + * + * @param globalProxyBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity setRecommendedGlobalProxy(GlobalProxyBeanWrapper globalProxyBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for send application configuration operation + * + * @param applicationRestrictionBeanWrapper + * @return + * @throws {@link AndroidDeviceMgtPluginException} + */ + Response sendApplicationConfiguration( + ApplicationRestrictionBeanWrapper applicationRestrictionBeanWrapper) + throws AndroidDeviceMgtPluginException; - List getPendingOperations(String id, List resultOperations, boolean disableGoogleApps) + /** + * method for configure display message operation + * + * @param displayMessageBeanWrapper + * @return {@link Activity} + * @throws {@link AndroidDeviceMgtPluginException} + * @throws {@link OperationManagementException} + */ + Activity configureDisplayMessage(DisplayMessageBeanWrapper displayMessageBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException; + + /** + * Method for update application list + * + * @param id + * @param androidApplications + * @return {@link Message} + * @throws {@link ApplicationManagementException} + */ + Message updateApplicationList(String id, List androidApplications) + throws ApplicationManagementException; + + /** + * Method for get pending operations + * + * @param id + * @param resultOperations + * @param disableGoogleApps + * @return + * @throws {@link DeviceManagementException} + * @throws {@link InvalidDeviceException} + */ + List getPendingOperations + (String id, List resultOperations, boolean disableGoogleApps) throws DeviceManagementException, InvalidDeviceException; + /** + * Method to enroll device + * + * @param androidDevice + * @return {@link Response} + * @throws {@link DeviceManagementException} + */ Response enrollDevice(AndroidDevice androidDevice) throws DeviceManagementException; - boolean modifyEnrollment(String id, AndroidDevice androidDevice) throws DeviceManagementException; + /** + * Method to check if a device is enrolled + * + * @param id + * @param deviceIdentifier + * @return {@link Message} + * @throws {@link DeviceManagementException} + */ + Message isEnrolled(String id, DeviceIdentifier deviceIdentifier) throws DeviceManagementException; + /** + * Method to modify enrollment + * + * @param id + * @param androidDevice + * @return + * @throws {@link DeviceManagementException} + * @throws {@link AndroidDeviceMgtPluginException} + */ + boolean modifyEnrollment(String id, AndroidDevice androidDevice) + throws DeviceManagementException, AndroidDeviceMgtPluginException; + + /** + * Method to disenroll a device + * + * @param id + * @return + * @throws {@link DeviceManagementException} + */ boolean disEnrollDevice(String id) throws DeviceManagementException; - //EventReceiverAPI + /** + * Method to publish events + * + * @param eventBeanWrapper + * @return {@link Device} + * @throws {@link DeviceManagementException} + */ Device publishEvents(EventBeanWrapper eventBeanWrapper) throws DeviceManagementException; - Response retrieveAlerts(String deviceId, - long from, - long to, - String type, - String ifModifiedSince); + /** + * Method to retrieve alerts + * + * @param deviceId + * @param from + * @param to + * @param type + * @param ifModifiedSince + * @return {@link Response} + * @throws {@link AndroidDeviceMgtPluginException} + */ + Response retrieveAlerts(String deviceId, long from, long to, String type, String ifModifiedSince) + throws AndroidDeviceMgtPluginException; } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/main/java/org/wso2/carbon/device/mgt/mobile/android/core/impl/AndroidServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/main/java/org/wso2/carbon/device/mgt/mobile/android/core/impl/AndroidServiceImpl.java index aed7c41705..041d584426 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/main/java/org/wso2/carbon/device/mgt/mobile/android/core/impl/AndroidServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/main/java/org/wso2/carbon/device/mgt/mobile/android/core/impl/AndroidServiceImpl.java @@ -240,13 +240,13 @@ public class AndroidServiceImpl implements AndroidService { } @Override - public Activity fileTransfer(FileTransferBeanWrapper fileTransferBeanWrapper) throws OperationManagementException { + public Activity fileTransfer(FileTransferBeanWrapper fileTransferBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException { if (fileTransferBeanWrapper == null || fileTransferBeanWrapper.getOperation() == null || fileTransferBeanWrapper.getDeviceIDs() == null) { String errorMessage = "The payload of the file transfer operation is incorrect."; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } if (log.isDebugEnabled()) { log.debug("Invoking Android file transfer operation for " + fileTransferBeanWrapper.getDeviceIDs()); @@ -268,13 +268,13 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers ( " + fileTransferBeanWrapper.getDeviceIDs() + " ) found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity configureDeviceLock(DeviceLockBeanWrapper deviceLockBeanWrapper) throws OperationManagementException { + public Activity configureDeviceLock(DeviceLockBeanWrapper deviceLockBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException { if (deviceLockBeanWrapper == null || deviceLockBeanWrapper.getOperation() == null) { String errorMessage = "Lock bean is empty."; log.error(errorMessage); @@ -293,13 +293,13 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity configureDeviceUnlock(List deviceIDs) throws OperationManagementException { + public Activity configureDeviceUnlock(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_UNLOCK); @@ -309,13 +309,13 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity getDeviceLocation(List deviceIDs) throws OperationManagementException { + public Activity getDeviceLocation(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException{ try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_LOCATION); @@ -324,13 +324,13 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity removePassword(List deviceIDs) throws OperationManagementException { + public Activity removePassword(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.CLEAR_PASSWORD); @@ -339,13 +339,13 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity configureCamera(CameraBeanWrapper cameraBeanWrapper) throws OperationManagementException { + public Activity configureCamera(CameraBeanWrapper cameraBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { if (cameraBeanWrapper == null || cameraBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the configure camera operation is incorrect."; @@ -362,13 +362,13 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity getDeviceInformation(List deviceIDs) throws OperationManagementException { + public Activity getDeviceInformation(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO); @@ -377,13 +377,13 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity getDeviceLogcat(List deviceIDs) throws OperationManagementException { + public Activity getDeviceLogcat(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.LOGCAT); @@ -392,13 +392,13 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity wipeDevice(List deviceIDs) throws OperationManagementException { + public Activity wipeDevice(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.ENTERPRISE_WIPE); @@ -407,19 +407,18 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity wipeData(WipeDataBeanWrapper wipeDataBeanWrapper) throws OperationManagementException { + public Activity wipeData(WipeDataBeanWrapper wipeDataBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { if (wipeDataBeanWrapper == null || wipeDataBeanWrapper.getOperation() == null) { String errorMessage = "WipeData bean is empty."; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } WipeData wipeData = wipeDataBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -430,13 +429,13 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity getApplications(List deviceIDs) throws OperationManagementException { + public Activity getApplications(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.APPLICATION_LIST); @@ -445,13 +444,13 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity ringDevice(List deviceIDs) throws OperationManagementException { + public Activity ringDevice(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_RING); @@ -460,13 +459,13 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity rebootDevice(List deviceIDs) throws OperationManagementException { + public Activity rebootDevice(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_REBOOT); @@ -475,13 +474,13 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity changeLockTask(List deviceIDs) throws OperationManagementException { + public Activity changeLockTask(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.CHANGE_LOCK_TASK_MODE); @@ -490,13 +489,13 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity muteDevice(List deviceIDs) throws OperationManagementException { + public Activity muteDevice(List deviceIDs) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_MUTE); @@ -506,21 +505,19 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override public Activity installApplication(ApplicationInstallationBeanWrapper applicationInstallationBeanWrapper) - throws OperationManagementException { + throws OperationManagementException, AndroidDeviceMgtPluginException { try { if (applicationInstallationBeanWrapper == null || applicationInstallationBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the application installing operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } ApplicationInstallation applicationInstallation = applicationInstallationBeanWrapper.getOperation(); @@ -537,19 +534,18 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity updateApplication(ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper) throws OperationManagementException { + public Activity updateApplication(ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { if (applicationUpdateBeanWrapper == null || applicationUpdateBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the application update operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } ApplicationUpdate applicationUpdate = applicationUpdateBeanWrapper.getOperation(); validateApplicationUrl(applicationUpdate.getUrl()); @@ -566,20 +562,19 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity uninstallApplication(ApplicationUninstallationBeanWrapper applicationUninstallationBeanWrapper) throws OperationManagementException { + public Activity uninstallApplication(ApplicationUninstallationBeanWrapper applicationUninstallationBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { if (applicationUninstallationBeanWrapper == null || applicationUninstallationBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the application uninstalling operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } ApplicationUninstallation applicationUninstallation = applicationUninstallationBeanWrapper.getOperation(); validateApplicationType(applicationUninstallation.getType()); @@ -593,19 +588,18 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity blacklistApplications(BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper) throws OperationManagementException { + public Activity blacklistApplications(BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { if (blacklistApplicationsBeanWrapper == null || blacklistApplicationsBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the blacklisting apps operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } BlacklistApplications blacklistApplications = blacklistApplicationsBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -617,19 +611,18 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity upgradeFirmware(UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper) throws OperationManagementException { + public Activity upgradeFirmware(UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { if (upgradeFirmwareBeanWrapper == null || upgradeFirmwareBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the upgrade firmware operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } UpgradeFirmware upgradeFirmware = upgradeFirmwareBeanWrapper.getOperation(); validateScheduleDate(upgradeFirmware.getSchedule()); @@ -643,19 +636,18 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity configureVPN(VpnBeanWrapper vpnConfiguration) throws OperationManagementException { + public Activity configureVPN(VpnBeanWrapper vpnConfiguration) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { if (vpnConfiguration == null || vpnConfiguration.getOperation() == null) { String errorMessage = "The payload of the VPN operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } Vpn vpn = vpnConfiguration.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -666,19 +658,18 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity sendNotification(NotificationBeanWrapper notificationBeanWrapper) throws OperationManagementException { + public Activity sendNotification(NotificationBeanWrapper notificationBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException{ try { if (notificationBeanWrapper == null || notificationBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the notification operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } Notification notification = notificationBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -689,19 +680,18 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity configureWifi(WifiBeanWrapper wifiBeanWrapper) throws OperationManagementException { + public Activity configureWifi(WifiBeanWrapper wifiBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { if (wifiBeanWrapper == null || wifiBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the wifi operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } Wifi wifi = wifiBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -713,19 +703,18 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity encryptStorage(EncryptionBeanWrapper encryptionBeanWrapper) throws OperationManagementException { + public Activity encryptStorage(EncryptionBeanWrapper encryptionBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException{ try { if (encryptionBeanWrapper == null || encryptionBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the device encryption operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } DeviceEncryption deviceEncryption = encryptionBeanWrapper.getOperation(); CommandOperation operation = new CommandOperation(); @@ -736,19 +725,18 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity changeLockCode(LockCodeBeanWrapper lockCodeBeanWrapper) throws OperationManagementException { + public Activity changeLockCode(LockCodeBeanWrapper lockCodeBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { if (lockCodeBeanWrapper == null || lockCodeBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the change lock code operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } LockCode lockCode = lockCodeBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -759,19 +747,18 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity setPasswordPolicy(PasswordPolicyBeanWrapper passwordPolicyBeanWrapper) throws OperationManagementException { + public Activity setPasswordPolicy(PasswordPolicyBeanWrapper passwordPolicyBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { if (passwordPolicyBeanWrapper == null || passwordPolicyBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the change password policy operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } PasscodePolicy passcodePolicy = passwordPolicyBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -784,20 +771,19 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity setWebClip(WebClipBeanWrapper webClipBeanWrapper) throws OperationManagementException { + public Activity setWebClip(WebClipBeanWrapper webClipBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { if (webClipBeanWrapper == null || webClipBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the add webclip operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } WebClip webClip = webClipBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -809,19 +795,18 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @Override - public Activity setRecommendedGlobalProxy(GlobalProxyBeanWrapper globalProxyBeanWrapper) throws OperationManagementException { + public Activity setRecommendedGlobalProxy(GlobalProxyBeanWrapper globalProxyBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { if (globalProxyBeanWrapper == null || globalProxyBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the global proxy operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400L).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } GlobalProxy globalProxy = globalProxyBeanWrapper.getOperation(); @@ -836,27 +821,62 @@ public class AndroidServiceImpl implements AndroidService { } else { String errorMessage = "The payload of the global proxy operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400L).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400L).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); + } + } + + @Override + public Response sendApplicationConfiguration(ApplicationRestrictionBeanWrapper applicationRestrictionBeanWrapper) + throws AndroidDeviceMgtPluginException { + try { + if (applicationRestrictionBeanWrapper == null || applicationRestrictionBeanWrapper.getOperation() == null) { + String errorMessage = "The payload of the application configuration operation is incorrect"; + log.error(errorMessage); + throw new BadRequestExceptionDup(errorMessage); + } + ApplicationRestriction applicationRestriction = applicationRestrictionBeanWrapper.getOperation(); + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.REMOTE_APP_CONFIG); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(applicationRestriction.toJSON()); + Response response = AndroidAPIUtils.getOperationResponse(applicationRestrictionBeanWrapper.getDeviceIDs(), + operation); + return response; + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestExceptionDup(errorMessage, e); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder() + .setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()); + } catch (DeviceManagementException e) { + String errorMessage = "Issue in retrieving device management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder() + .setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()); } } @Override - public Activity configureDisplayMessage(DisplayMessageBeanWrapper displayMessageBeanWrapper) throws OperationManagementException { + public Activity configureDisplayMessage(DisplayMessageBeanWrapper displayMessageBeanWrapper) + throws OperationManagementException, AndroidDeviceMgtPluginException { try { if (displayMessageBeanWrapper == null || displayMessageBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the display message operation is incorrect"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST). - setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } DisplayMessage configureDisplayMessage = displayMessageBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -870,9 +890,7 @@ public class AndroidServiceImpl implements AndroidService { } catch (InvalidDeviceException e) { String errorMessage = "Invalid Device Identifiers found."; log.error(errorMessage, e); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST). - setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage, e); } } @@ -1107,7 +1125,8 @@ public class AndroidServiceImpl implements AndroidService { } @Override - public boolean modifyEnrollment(String id, AndroidDevice androidDevice) throws DeviceManagementException { + public boolean modifyEnrollment(String id, AndroidDevice androidDevice) + throws DeviceManagementException, AndroidDeviceMgtPluginException { Device device; DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(id); @@ -1125,8 +1144,7 @@ public class AndroidServiceImpl implements AndroidService { if (androidDevice == null) { String errorMessage = "The payload of the android device enrollment is incorrect."; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } if (device == null) { String errorMessage = "The device to be modified doesn't exist."; @@ -1192,18 +1210,19 @@ public class AndroidServiceImpl implements AndroidService { long from, long to, String type, - String ifModifiedSince) { - if (from != 0l && to != 0l && deviceId != null) { + String ifModifiedSince) throws AndroidDeviceMgtPluginException { + if (from != 0l && to != 0l && deviceId != null){ return retrieveAlertFromDate(deviceId, from, to); } else if (deviceId != null && type != null) { return retrieveAlertByType(deviceId, type); } else if (deviceId != null) { return retrieveAlert(deviceId); } else { - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request must contain " + - "the device identifier. Optionally, both from and to value should be present to get " + - "alerts between times.").build()); + String errorMessage = "Request must contain " + + "the device identifier. Optionally, both from and to value should be present to get " + + "alerts between times."; + log.error(errorMessage); + throw new BadRequestExceptionDup(errorMessage); } }