From 69874726baf48ad9085e34419bafd0349a1f50ef Mon Sep 17 00:00:00 2001 From: shamalka Date: Thu, 5 Dec 2019 17:37:30 +0530 Subject: [PATCH] Fix android webapp deployment issue --- .../pom.xml | 6 + .../exception/AndroidOperationException.java | 2 +- .../api}/exception/BadRequestException.java | 2 +- .../api}/exception/ForbiddenException.java | 2 +- .../api/exception/GlobalThrowableMapper.java | 6 +- .../api}/exception/NotFoundException.java | 2 +- .../UnexpectedServerErrorException.java | 2 +- .../api/impl/AndroidEnterpriseAPIImpl.java | 414 ++++++++++++++---- .../impl/DeviceManagementAdminAPIImpl.java | 1 - .../impl/DeviceTypeConfigurationAPIImpl.java | 5 +- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 4 +- .../pom.xml | 1 + .../android/core/impl/AndroidServiceImpl.java | 114 ++--- .../android/core/util/AndroidAPIUtils.java | 8 +- .../android/core/util/AndroidDeviceUtils.java | 12 +- .../core/util/AndroidEnterpriseUtils.java | 10 +- .../DeviceManagementAdminServiceTests.java | 78 ++-- .../core/DeviceManagementServiceTests.java | 61 ++- 18 files changed, 464 insertions(+), 266 deletions(-) rename components/mobile-plugins/android-plugin/{org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common => org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api}/exception/AndroidOperationException.java (94%) rename components/mobile-plugins/android-plugin/{org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common => org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api}/exception/BadRequestException.java (94%) rename components/mobile-plugins/android-plugin/{org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common => org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api}/exception/ForbiddenException.java (95%) rename components/mobile-plugins/android-plugin/{org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common => org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api}/exception/NotFoundException.java (96%) rename components/mobile-plugins/android-plugin/{org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common => org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api}/exception/UnexpectedServerErrorException.java (96%) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml index b0cb54e0c..dc36dd374 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml @@ -224,6 +224,12 @@ + + com.google.apis + google-api-services-androidenterprise + v1-rev186-1.25.0 + + org.hibernate hibernate-validator 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/exception/AndroidOperationException.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/exception/AndroidOperationException.java similarity index 94% rename from components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/exception/AndroidOperationException.java rename to components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/exception/AndroidOperationException.java index 527c1b45e..6cd49eded 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/exception/AndroidOperationException.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/exception/AndroidOperationException.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.mobile.android.common.exception; +package org.wso2.carbon.device.mgt.mobile.android.api.exception; import org.wso2.carbon.device.mgt.mobile.android.common.Message; 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/exception/BadRequestException.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/exception/BadRequestException.java similarity index 94% rename from components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/exception/BadRequestException.java rename to components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/exception/BadRequestException.java index 3213a8ed7..a93e39a8e 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/exception/BadRequestException.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/exception/BadRequestException.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.mobile.android.common.exception; +package org.wso2.carbon.device.mgt.mobile.android.api.exception; import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; 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/exception/ForbiddenException.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/exception/ForbiddenException.java similarity index 95% rename from components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/exception/ForbiddenException.java rename to components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/exception/ForbiddenException.java index 451a3e033..9c0741ded 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/exception/ForbiddenException.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/exception/ForbiddenException.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.mobile.android.common.exception; +package org.wso2.carbon.device.mgt.mobile.android.api.exception; import org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants; import org.wso2.carbon.device.mgt.mobile.android.common.dto.ErrorDTO; 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/exception/GlobalThrowableMapper.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/exception/GlobalThrowableMapper.java index f45df54d3..9d0c7fdc6 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/exception/GlobalThrowableMapper.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/exception/GlobalThrowableMapper.java @@ -21,11 +21,7 @@ package org.wso2.carbon.device.mgt.mobile.android.api.exception; import com.google.gson.JsonParseException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestException; import org.wso2.carbon.device.mgt.mobile.android.common.dto.ErrorDTO; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.ForbiddenException; -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.core.util.AndroidDeviceUtils; import javax.naming.AuthenticationException; @@ -58,7 +54,7 @@ public class GlobalThrowableMapper implements ExceptionMapper { if (log.isDebugEnabled()) { log.debug(errorMessage, e); } - return AndroidDeviceUtils.buildBadRequestException(errorMessage).getResponse(); + return new BadRequestException(AndroidDeviceUtils.buildBadRequestException(errorMessage)).getResponse(); } if (e instanceof NotFoundException) { return ((NotFoundException) e).getResponse(); 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/exception/NotFoundException.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/exception/NotFoundException.java similarity index 96% rename from components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/exception/NotFoundException.java rename to components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/exception/NotFoundException.java index 3f412587d..59367917b 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/exception/NotFoundException.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/exception/NotFoundException.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.mobile.android.common.exception; +package org.wso2.carbon.device.mgt.mobile.android.api.exception; import org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants; import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; 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/exception/UnexpectedServerErrorException.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/exception/UnexpectedServerErrorException.java similarity index 96% rename from components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/exception/UnexpectedServerErrorException.java rename to components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/exception/UnexpectedServerErrorException.java index b00a4e51f..c4390aaa7 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/exception/UnexpectedServerErrorException.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/exception/UnexpectedServerErrorException.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.mobile.android.common.exception; +package org.wso2.carbon.device.mgt.mobile.android.api.exception; import org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants; import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; 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/AndroidEnterpriseAPIImpl.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/AndroidEnterpriseAPIImpl.java index aa195ed56..58ef349f3 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/AndroidEnterpriseAPIImpl.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/AndroidEnterpriseAPIImpl.java @@ -58,7 +58,10 @@ import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EnterpriseU import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.TokenWrapper; import org.wso2.carbon.device.mgt.mobile.android.common.dto.AndroidEnterpriseManagedConfig; import org.wso2.carbon.device.mgt.mobile.android.common.dto.AndroidEnterpriseUser; +import org.wso2.carbon.device.mgt.mobile.android.common.exception.AndroidDeviceMgtPluginException; import org.wso2.carbon.device.mgt.mobile.android.common.exception.EnterpriseServiceException; +import org.wso2.carbon.device.mgt.mobile.android.common.exception.NotFoundExceptionDup; +import org.wso2.carbon.device.mgt.mobile.android.common.exception.UnexpectedServerErrorExceptionDup; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidEnterpriseUtils; @@ -117,11 +120,24 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { } catch (EnterpriseServiceException e) { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Error when saving user").build()).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while adding user"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } return Response.status(Response.Status.OK).entity(token).build(); } - public String insertUser(EnterpriseUser enterpriseUser) throws EnterpriseServiceException { + public String insertUser(EnterpriseUser enterpriseUser) + throws EnterpriseServiceException, AndroidDeviceMgtPluginException { EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); String token; boolean deviceIdExist = false; @@ -171,9 +187,9 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { public Response updateUser(EnterpriseInstallPolicy device) { boolean sentToDevice = false; - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); List enterpriseUserInstances = AndroidAPIUtils.getAndroidPluginService() .getEnterpriseUser(device.getUsername()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); @@ -193,6 +209,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { return Response.status(Response.Status.NOT_FOUND).entity( new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND) .setMessage(errorMessage).build()).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while updating user"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } if (sentToDevice) { return Response.status(Response.Status.OK).build(); @@ -213,23 +241,24 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { @QueryParam("isOrganizeAppPageVisible") boolean isOrganizeAppPageVisible, @QueryParam("isManagedConfigEnabled") boolean isManagedConfigEnabled, @QueryParam("host") String host) { - - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); - EnterpriseTokenUrl enterpriseTokenUrl = new EnterpriseTokenUrl(); - if (enterpriseConfigs == null || enterpriseConfigs.getEnterpriseId() == null) { - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("Not configured for AFW").build()).build(); - } - enterpriseTokenUrl.setEnterpriseId(enterpriseConfigs.getEnterpriseId()); - enterpriseTokenUrl.setApproveApps(approveApps); - enterpriseTokenUrl.setSearchEnabled(searchEnabled); - enterpriseTokenUrl.setPrivateAppsEnabled(isPrivateAppsEnabled); - enterpriseTokenUrl.setWebAppEnabled(isWebAppEnabled); - enterpriseTokenUrl.setOrganizeAppPageVisible(isOrganizeAppPageVisible); - enterpriseTokenUrl.setParentHost(host); - enterpriseTokenUrl.setManagedConfigEnabled(isManagedConfigEnabled); try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + EnterpriseTokenUrl enterpriseTokenUrl = new EnterpriseTokenUrl(); + if (enterpriseConfigs == null || enterpriseConfigs.getEnterpriseId() == null) { + return Response.status(Response.Status.NOT_FOUND).entity( + new ErrorResponse.ErrorResponseBuilder().setMessage("Not configured for AFW").build()).build(); + } + enterpriseTokenUrl.setEnterpriseId(enterpriseConfigs.getEnterpriseId()); + enterpriseTokenUrl.setApproveApps(approveApps); + enterpriseTokenUrl.setSearchEnabled(searchEnabled); + enterpriseTokenUrl.setPrivateAppsEnabled(isPrivateAppsEnabled); + enterpriseTokenUrl.setWebAppEnabled(isWebAppEnabled); + enterpriseTokenUrl.setOrganizeAppPageVisible(isOrganizeAppPageVisible); + enterpriseTokenUrl.setParentHost(host); + enterpriseTokenUrl.setManagedConfigEnabled(isManagedConfigEnabled); + String token = googleAPIInvoker.getAdministratorWebToken(enterpriseTokenUrl); TokenWrapper tokenWrapper = new TokenWrapper(); tokenWrapper.setToken(token); @@ -238,6 +267,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Error when calling get web token").build()) .build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while getting store url"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @@ -245,9 +286,10 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { @GET @Path("/products/sync") public Response syncApps() { - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + ProductsListResponse productsListResponse = googleAPIInvoker .listProduct(enterpriseConfigs.getEnterpriseId(), null); AndroidEnterpriseUtils.persistApp(productsListResponse); @@ -265,6 +307,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Error when persisting app").build()) .build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while syncing apps"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @@ -298,9 +352,10 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { new ErrorResponse.ErrorResponseBuilder().setMessage("Message body is empty or incorrect").build()) .build(); } - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + String id = googleAPIInvoker.insertPage(enterpriseConfigs.getEnterpriseId(), page); page.setPageId(id); return Response.status(Response.Status.OK).entity(page).build(); @@ -312,6 +367,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Error when inserting page " + page.getPageName() + " , due to an error with ESA").build() ).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while adding page"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @@ -325,9 +392,10 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { .build(); } - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + String id = googleAPIInvoker.updatePage(enterpriseConfigs.getEnterpriseId(), page); page.setPageId(id); return Response.status(Response.Status.OK).entity(page).build(); @@ -339,6 +407,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating page " + page.getPageName() + " , due to an error with ESA").build()).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while updating page"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @@ -353,9 +433,10 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { .build(); } - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + googleAPIInvoker.deletePage(enterpriseConfigs.getEnterpriseId(), id); return Response.status(Response.Status.OK).build(); } catch (IOException e) { @@ -366,6 +447,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating page " + id + " , Due to an error with ESA").build()).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while deleting page"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @@ -373,9 +466,10 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { @Path("/store-layout/page") @Override public Response getPages() { - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + StoreLayoutPagesListResponse pages = googleAPIInvoker.listPages(enterpriseConfigs.getEnterpriseId()); return Response.status(Response.Status.OK).entity(pages).build(); } catch (IOException e) { @@ -386,6 +480,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching page " + " , Due to an error with ESA").build()).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while getting pages"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @@ -399,9 +505,10 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { new ErrorResponse.ErrorResponseBuilder().setMessage("Id cannot be empty").build()) .build(); } - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + StoreLayout layout = googleAPIInvoker.setStoreLayout(enterpriseConfigs.getEnterpriseId(), id); return Response.status(Response.Status.OK).entity(layout).build(); } catch (IOException e) { @@ -412,6 +519,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Error when inserting home page " + id + " , due to an error with ESA").build() ).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while setting home"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @@ -419,9 +538,10 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { @Path("/store-layout/home-page") @Override public Response getHome() { - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + StoreLayout layout = googleAPIInvoker.getStoreLayout(enterpriseConfigs.getEnterpriseId()); return Response.status(Response.Status.OK).entity(layout).build(); } catch (IOException e) { @@ -431,6 +551,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching home page.").build() ) .build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while getting home"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @@ -453,9 +585,10 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { new ErrorResponse.ErrorResponseBuilder().setMessage("Cluster order cannot be empty").build()).build(); } - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + String id = googleAPIInvoker.insertCluster(enterpriseConfigs.getEnterpriseId(), storeCluster); storeCluster.setClusterId(id); return Response.status(Response.Status.OK).entity(storeCluster).build(); @@ -467,6 +600,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating cluster " + storeCluster.getName() + " , due to an error with ESA").build()).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while adding cluster"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @@ -489,9 +634,10 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { new ErrorResponse.ErrorResponseBuilder().setMessage("Cluster order cannot be empty").build()).build(); } - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + String id = googleAPIInvoker.updateCluster(enterpriseConfigs.getEnterpriseId(), storeCluster); storeCluster.setClusterId(id); return Response.status(Response.Status.OK).entity(storeCluster).build(); @@ -503,6 +649,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating cluster " + storeCluster.getName() + " , due to an error with ESA").build()).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while updating cluster"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @@ -519,9 +677,10 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { new ErrorResponse.ErrorResponseBuilder().setMessage("Page id cannot be empty").build()).build(); } - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + googleAPIInvoker.deleteCluster(enterpriseConfigs.getEnterpriseId(), pageId, clusterId); return Response.status(Response.Status.OK).build(); } catch (IOException e) { @@ -532,6 +691,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Error when deleting cluster " + clusterId + " , due to an error with ESA").build()).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while deleting cluster"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @@ -544,9 +715,10 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { new ErrorResponse.ErrorResponseBuilder().setMessage("Page id cannot be empty").build()).build(); } - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + StoreLayoutClustersListResponse response = googleAPIInvoker.getClusters(enterpriseConfigs.getEnterpriseId(), pageId); if (response == null || response.getCluster() == null) { return Response.status(Response.Status.NOT_FOUND).entity( @@ -601,6 +773,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching all details in PageId " + pageId).build()).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while getting clusters in page"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @@ -608,9 +792,10 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { @Path("/store-layout/page-link") @Override public Response updateLinks(EnterpriseStorePageLinks link) { - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + googleAPIInvoker.addLinks(enterpriseConfigs.getEnterpriseId(), link.getPageId(), link.getLinks()); return Response.status(Response.Status.OK).build(); @@ -622,6 +807,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching page " + " , Due to an error with ESA").build()).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while updating links"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } } @@ -725,11 +922,12 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { public Response updateUser(ApplicationPolicyDTO applicationPolicyDTO) { boolean sentToDevice = false; - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + for (DeviceIdentifier deviceIdentifier : applicationPolicyDTO.getDeviceIdentifierList()) { try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); AndroidEnterpriseUser userDetail = AndroidAPIUtils.getAndroidPluginService() .getEnterpriseUserByDevice(deviceIdentifier.getId()); @@ -791,7 +989,20 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { log.error(errorMessage); return Response.status(Response.Status.NOT_FOUND).entity( new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND) - .setMessage(errorMessage).build()).build(); } + .setMessage(errorMessage).build()).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while updating user"; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } } if (sentToDevice) { @@ -809,69 +1020,82 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { @Path("/wipe-device") public Response wipeEnterprise() { log.warn("Wiping all devices!!!"); - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - try { - // Take all enterprise devices in the DB. - List androidEnterpriseUsers = AndroidAPIUtils.getAndroidPluginService() - .getAllEnterpriseDevices(enterpriseConfigs.getEnterpriseId()); - - // Extract the device identifiers of enterprise devices. - List deviceID = new ArrayList<>(); - if (androidEnterpriseUsers != null && !androidEnterpriseUsers.isEmpty()) { - for (AndroidEnterpriseUser userDevice: androidEnterpriseUsers) { - deviceID.add(userDevice.getEmmDeviceId()); + try{ + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + try { + // Take all enterprise devices in the DB. + List androidEnterpriseUsers = AndroidAPIUtils.getAndroidPluginService() + .getAllEnterpriseDevices(enterpriseConfigs.getEnterpriseId()); + + // Extract the device identifiers of enterprise devices. + List deviceID = new ArrayList<>(); + if (androidEnterpriseUsers != null && !androidEnterpriseUsers.isEmpty()) { + for (AndroidEnterpriseUser userDevice: androidEnterpriseUsers) { + deviceID.add(userDevice.getEmmDeviceId()); + } } - } - List byodDevices = new ArrayList<>(); - List copeDevices = new ArrayList<>(); - // Get all registered device - List devices = AndroidAPIUtils.getDeviceManagementService(). - getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, false); - for (Device device : devices) { // Go through all enrolled devices - if (deviceID.contains(device.getDeviceIdentifier())) { // Filter out only enterprise enrolled devices. - if (device.getEnrolmentInfo().getOwnership().equals(EnrolmentInfo.OwnerShip.BYOD)) { - byodDevices.add(device.getDeviceIdentifier()); - } else { - copeDevices.add(device.getDeviceIdentifier()); + List byodDevices = new ArrayList<>(); + List copeDevices = new ArrayList<>(); + // Get all registered device + List devices = AndroidAPIUtils.getDeviceManagementService(). + getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, false); + for (Device device : devices) { // Go through all enrolled devices + if (deviceID.contains(device.getDeviceIdentifier())) { // Filter out only enterprise enrolled devices. + if (device.getEnrolmentInfo().getOwnership().equals(EnrolmentInfo.OwnerShip.BYOD)) { + byodDevices.add(device.getDeviceIdentifier()); + } else { + copeDevices.add(device.getDeviceIdentifier()); + } } } - } - CommandOperation operation = new CommandOperation(); - operation.setType(Operation.Type.COMMAND);//TODO: Check if this should be profile - // type when implementing COPE/COSU - if (byodDevices != null && !byodDevices.isEmpty()) { // BYOD devices only needs a data wipe(work profile) - log.warn("Wiping " + byodDevices.size() + " BYOD devices"); - operation.setCode(AndroidConstants.OperationCodes.ENTERPRISE_WIPE); - } else if (copeDevices != null && !copeDevices.isEmpty()) { - log.warn("Wiping " + copeDevices.size() + " COPE/COSU devices"); - operation.setCode(AndroidConstants.OperationCodes.WIPE_DATA); + CommandOperation operation = new CommandOperation(); + operation.setType(Operation.Type.COMMAND);//TODO: Check if this should be profile + // type when implementing COPE/COSU + if (byodDevices != null && !byodDevices.isEmpty()) { // BYOD devices only needs a data wipe(work profile) + log.warn("Wiping " + byodDevices.size() + " BYOD devices"); + operation.setCode(AndroidConstants.OperationCodes.ENTERPRISE_WIPE); + } else if (copeDevices != null && !copeDevices.isEmpty()) { + log.warn("Wiping " + copeDevices.size() + " COPE/COSU devices"); + operation.setCode(AndroidConstants.OperationCodes.WIPE_DATA); + } + AndroidDeviceUtils.getOperationResponse(deviceID, operation); + log.warn("Added wipe to all devices"); + return Response.status(Response.Status.OK).build(); + } catch (EnterpriseServiceException e) { + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage("Error when saving configs").build()).build(); + } catch (OperationManagementException e) { + String errorMessage = "Could not add wipe command to enterprise " + enterpriseConfigs.getEnterpriseId(); + log.error(errorMessage); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (DeviceManagementException e) { + String errorMessage = "Could not add wipe command to enterprise " + enterpriseConfigs.getEnterpriseId() + + " due to an error in device management"; + log.error(errorMessage); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Could not add wipe command to enterprise due to invalid device ids"; + log.error(errorMessage); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } - AndroidDeviceUtils.getOperationResponse(deviceID, operation); - log.warn("Added wipe to all devices"); - return Response.status(Response.Status.OK).build(); - } catch (EnterpriseServiceException e) { - return Response.serverError().entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("Error when saving configs").build()).build(); - } catch (OperationManagementException e) { - String errorMessage = "Could not add wipe command to enterprise " + enterpriseConfigs.getEnterpriseId(); - log.error(errorMessage); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); - } catch (DeviceManagementException e) { - String errorMessage = "Could not add wipe command to enterprise " + enterpriseConfigs.getEnterpriseId() + - " due to an error in device management"; - log.error(errorMessage); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); - } catch (InvalidDeviceException e) { - String errorMessage = "Could not add wipe command to enterprise due to invalid device ids"; - log.error(errorMessage); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing wipe enterprice command"; return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().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 f186cd28b..756c6d24e 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 @@ -88,7 +88,6 @@ import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.WebClipBean 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.spi.AndroidService; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils; 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/DeviceTypeConfigurationAPIImpl.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/DeviceTypeConfigurationAPIImpl.java index 03015fe74..30e27039e 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/DeviceTypeConfigurationAPIImpl.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/DeviceTypeConfigurationAPIImpl.java @@ -44,7 +44,6 @@ import org.wso2.carbon.device.mgt.mobile.android.api.DeviceTypeConfigurationAPI; import org.wso2.carbon.device.mgt.mobile.android.common.bean.AndroidPlatformConfiguration; import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; 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.spi.AndroidService; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils; @@ -95,9 +94,9 @@ public class DeviceTypeConfigurationAPIImpl implements DeviceTypeConfigurationAP } catch (BadRequestExceptionDup e) { String msg = "The payload of the android platform configuration is incorrect."; log.error(msg, e); - throw new BadRequestException( + return Response.status(Response.Status.BAD_REQUEST).entity( new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) - .setMessage(msg).build()); + .setMessage(msg).build()).build(); } catch (AndroidDeviceMgtPluginException e) { String msg = "Error occurred while modifying configuration settings of Android platform"; log.error(msg, e); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 581b918e0..5523186c9 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -34,7 +34,7 @@ - + @@ -44,7 +44,7 @@ - + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/pom.xml index 404950cb4..9ba42d84a 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/pom.xml @@ -161,6 +161,7 @@ org.wso2.carbon.devicemgt-plugins org.wso2.carbon.device.mgt.mobile.android.common + provided org.wso2.carbon.devicemgt 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 a3043f352..e8279628a 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 @@ -849,10 +849,10 @@ public class AndroidServiceImpl implements AndroidService { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); throw new UnexpectedServerErrorExceptionDup(errorMessage); - } catch (DeviceManagementException e) { + } catch (BadRequestExceptionDup e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorExceptionDup(errorMessage, e); + throw new BadRequestExceptionDup(errorMessage, e); } } @@ -1345,89 +1345,100 @@ public class AndroidServiceImpl implements AndroidService { } } - public String insertUser(EnterpriseUser enterpriseUser) throws EnterpriseServiceException { - EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); - String token; - boolean deviceIdExist = false; - - String googleUserId; - List androidEnterpriseUsers = AndroidAPIUtils.getAndroidPluginService() - .getEnterpriseUser(CarbonContext.getThreadLocalCarbonContext().getUsername()); - GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); - if (androidEnterpriseUsers != null && !androidEnterpriseUsers.isEmpty()) { - googleUserId = androidEnterpriseUsers.get(0).getGoogleUserId(); - // If this device is also present, only need to provide a token for this request. - for (AndroidEnterpriseUser enterprise : androidEnterpriseUsers) { - if (enterprise.getEmmDeviceId() != null - && enterprise.getEmmDeviceId().equals(enterpriseUser.getAndroidPlayDeviceId())) { - deviceIdExist = true; + public String insertUser(EnterpriseUser enterpriseUser) + throws EnterpriseServiceException, AndroidDeviceMgtPluginException { + try { + EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); + + String token; + boolean deviceIdExist = false; + + String googleUserId; + List androidEnterpriseUsers = AndroidAPIUtils.getAndroidPluginService() + .getEnterpriseUser(CarbonContext.getThreadLocalCarbonContext().getUsername()); + GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); + if (androidEnterpriseUsers != null && !androidEnterpriseUsers.isEmpty()) { + googleUserId = androidEnterpriseUsers.get(0).getGoogleUserId(); + // If this device is also present, only need to provide a token for this request. + for (AndroidEnterpriseUser enterprise : androidEnterpriseUsers) { + if (enterprise.getEmmDeviceId() != null + && enterprise.getEmmDeviceId().equals(enterpriseUser.getAndroidPlayDeviceId())) { + deviceIdExist = true; + } } + } else { + googleUserId = googleAPIInvoker.insertUser(enterpriseConfigs.getEnterpriseId(), CarbonContext + .getThreadLocalCarbonContext() + .getUsername()); } - } else { - googleUserId = googleAPIInvoker.insertUser(enterpriseConfigs.getEnterpriseId(), CarbonContext - .getThreadLocalCarbonContext() - .getUsername()); - } - // Fetching an auth token from Google EMM API - token = googleAPIInvoker.getToken(enterpriseConfigs.getEnterpriseId(), googleUserId); - - if (!deviceIdExist) { - AndroidEnterpriseUser androidEnterpriseUser = new AndroidEnterpriseUser(); - androidEnterpriseUser.setEmmUsername(CarbonContext.getThreadLocalCarbonContext().getUsername()); - androidEnterpriseUser.setTenantId(CarbonContext.getThreadLocalCarbonContext().getTenantId()); - androidEnterpriseUser.setAndroidPlayDeviceId(enterpriseUser.getAndroidPlayDeviceId()); - androidEnterpriseUser.setEnterpriseId(enterpriseConfigs.getEnterpriseId()); - androidEnterpriseUser.setEmmDeviceId(enterpriseUser.getEmmDeviceIdentifier()); - androidEnterpriseUser.setGoogleUserId(googleUserId); - - AndroidAPIUtils.getAndroidPluginService().addEnterpriseUser(androidEnterpriseUser); + // Fetching an auth token from Google EMM API + token = googleAPIInvoker.getToken(enterpriseConfigs.getEnterpriseId(), googleUserId); + + if (!deviceIdExist) { + AndroidEnterpriseUser androidEnterpriseUser = new AndroidEnterpriseUser(); + androidEnterpriseUser.setEmmUsername(CarbonContext.getThreadLocalCarbonContext().getUsername()); + androidEnterpriseUser.setTenantId(CarbonContext.getThreadLocalCarbonContext().getTenantId()); + androidEnterpriseUser.setAndroidPlayDeviceId(enterpriseUser.getAndroidPlayDeviceId()); + androidEnterpriseUser.setEnterpriseId(enterpriseConfigs.getEnterpriseId()); + androidEnterpriseUser.setEmmDeviceId(enterpriseUser.getEmmDeviceIdentifier()); + androidEnterpriseUser.setGoogleUserId(googleUserId); + + AndroidAPIUtils.getAndroidPluginService().addEnterpriseUser(androidEnterpriseUser); + } + return token; + } catch (NotFoundExceptionDup e) { + String errorMessage = "Not found"; + log.error(errorMessage); + throw new NotFoundExceptionDup(errorMessage); + } catch (UnexpectedServerErrorExceptionDup e) { + String errorMessage = "Unexpected server error"; + log.error(errorMessage); + throw new UnexpectedServerErrorExceptionDup(errorMessage); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing wipe enterprice command"; + log.error(errorMessage); + throw new AndroidDeviceMgtPluginException(errorMessage); } - return token; } - private static void validateApplicationUrl(String apkUrl) { + private static void validateApplicationUrl(String apkUrl) throws BadRequestExceptionDup{ try { URL url = new URL(apkUrl); URLConnection conn = url.openConnection(); if (((HttpURLConnection) conn).getResponseCode() != HttpURLConnection.HTTP_OK) { String errorMessage = "URL is not pointed to a downloadable file."; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } } catch (MalformedURLException e) { String errorMessage = "Malformed application url."; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } catch (IOException e) { String errorMessage = "Invalid application url."; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } } - private static void validateApplicationType(String type) { + private static void validateApplicationType(String type) throws BadRequestExceptionDup{ if (type != null) { if (!"enterprise".equalsIgnoreCase(type) && !"public".equalsIgnoreCase(type) && !"webapp".equalsIgnoreCase(type)) { String errorMessage = "Invalid application type."; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } } else { String errorMessage = "Application type is missing."; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } } - private static void validateScheduleDate(String dateString) { + private static void validateScheduleDate(String dateString) throws BadRequestExceptionDup{ try { if (dateString != null && !dateString.isEmpty()) { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); @@ -1437,8 +1448,7 @@ public class AndroidServiceImpl implements AndroidService { } catch (ParseException e) { String errorMessage = "Issue in validating the schedule date"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } } } 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/util/AndroidAPIUtils.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/util/AndroidAPIUtils.java index 63abcfdf7..9eeced144 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/util/AndroidAPIUtils.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/util/AndroidAPIUtils.java @@ -36,7 +36,8 @@ import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManag import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants; import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestException; +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.spi.AndroidGoogleEnterpriseService; import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; @@ -176,12 +177,11 @@ public class AndroidAPIUtils { } public static Response getOperationResponse(List deviceIDs, Operation operation) - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws AndroidDeviceMgtPluginException, OperationManagementException, InvalidDeviceException { if (deviceIDs == null || deviceIDs.size() == 0) { String errorMessage = "Device identifier list is empty"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } DeviceIdentifier deviceIdentifier; List deviceIdentifiers = new ArrayList<>(); 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/util/AndroidDeviceUtils.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/util/AndroidDeviceUtils.java index 035bfd2d2..2a1d4611f 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/util/AndroidDeviceUtils.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/util/AndroidDeviceUtils.java @@ -94,7 +94,8 @@ import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EnterpriseApp; import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EnterpriseInstallPolicy; import org.wso2.carbon.device.mgt.mobile.android.common.dto.AndroidEnterpriseUser; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestException; +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 org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.policy.mgt.common.FeatureManagementException; @@ -140,12 +141,11 @@ public class AndroidDeviceUtils { } public static Activity getOperationResponse(List deviceIDs, Operation operation) - throws OperationManagementException, InvalidDeviceException { + throws OperationManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException { if (deviceIDs == null || deviceIDs.isEmpty()) { String errorMessage = "Device identifier list is empty"; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } DeviceIdentifier deviceIdentifier; List deviceIdentifiers = new ArrayList<>(); @@ -637,10 +637,10 @@ public class AndroidDeviceUtils { * @param description description of the exception * @return a new BadRequestException with the specified details as a response DTO */ - public static BadRequestException buildBadRequestException(String description) { + public static ErrorResponse buildBadRequestException(String description) { ErrorResponse errorResponse = getErrorResponse(AndroidConstants. ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT, 400l, description); - return new BadRequestException(errorResponse); + return errorResponse; } /** 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/util/AndroidEnterpriseUtils.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/util/AndroidEnterpriseUtils.java index 1fc9549ed..1a10bc538 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/util/AndroidEnterpriseUtils.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/util/AndroidEnterpriseUtils.java @@ -59,9 +59,7 @@ import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EnterpriseA import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EnterpriseInstallPolicy; import org.wso2.carbon.device.mgt.mobile.android.common.dto.AndroidEnterpriseManagedConfig; import org.wso2.carbon.device.mgt.mobile.android.common.dto.AndroidEnterpriseUser; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.EnterpriseServiceException; -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.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.user.core.service.RealmService; @@ -223,13 +221,13 @@ public class AndroidEnterpriseUtils { return userInfo; } - public static EnterpriseConfigs getEnterpriseConfigs() { + public static EnterpriseConfigs getEnterpriseConfigs() throws AndroidDeviceMgtPluginException { EnterpriseConfigs enterpriseConfigs = getEnterpriseConfigsFromGoogle(); if (enterpriseConfigs.getErrorResponse() != null) { if (enterpriseConfigs.getErrorResponse().getCode() == 500l) { - throw new UnexpectedServerErrorException(enterpriseConfigs.getErrorResponse()); + throw new UnexpectedServerErrorExceptionDup(enterpriseConfigs.getErrorResponse().getMessage()); } else if (enterpriseConfigs.getErrorResponse().getCode() == 500l) { - throw new NotFoundException(enterpriseConfigs.getErrorResponse()); + throw new NotFoundExceptionDup(enterpriseConfigs.getErrorResponse().getMessage()); } } return enterpriseConfigs; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/test/java/org/wso2/carbon/device/mgt/mobile/android/core/DeviceManagementAdminServiceTests.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/test/java/org/wso2/carbon/device/mgt/mobile/android/core/DeviceManagementAdminServiceTests.java index 85a6f251f..f2400f153 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/test/java/org/wso2/carbon/device/mgt/mobile/android/core/DeviceManagementAdminServiceTests.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/test/java/org/wso2/carbon/device/mgt/mobile/android/core/DeviceManagementAdminServiceTests.java @@ -70,8 +70,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testConfigureDeviceUnlock() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.configureDeviceUnlock(TestUtils.getDeviceIds()); Assert.assertNotNull(activity); @@ -80,8 +79,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testGetDeviceLocation() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.getDeviceLocation(TestUtils.getDeviceIds()); Assert.assertNotNull(activity); @@ -90,8 +88,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testRemovePassword() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.removePassword(TestUtils.getDeviceIds()); Assert.assertNotNull(activity); @@ -100,8 +97,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testConfigureCamera() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.configureCamera(TestUtils.getCamerabeanWrapper()); Assert.assertNotNull(activity); @@ -110,8 +106,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testGetDeviceInformation() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.getDeviceInformation(TestUtils.getDeviceIds()); Assert.assertNotNull(activity); @@ -120,8 +115,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testGetDeviceLogcat() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.getDeviceLogcat(TestUtils.getDeviceIds()); Assert.assertNotNull(activity); @@ -129,8 +123,7 @@ public class DeviceManagementAdminServiceTests { } @Test - public void testWipeDevice() throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + public void testWipeDevice() throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.wipeDevice(TestUtils.getDeviceIds()); Assert.assertNotNull(activity); @@ -138,8 +131,7 @@ public class DeviceManagementAdminServiceTests { } @Test - public void testWipeData() throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + public void testWipeData() throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.wipeData(TestUtils.getWipeDataBeanWrapper()); Assert.assertNotNull(activity); @@ -148,8 +140,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testGetApplications() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.getApplications(TestUtils.getDeviceIds()); Assert.assertNotNull(activity); @@ -157,8 +148,7 @@ public class DeviceManagementAdminServiceTests { } @Test - public void testRingDevice() throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + public void testRingDevice() throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.ringDevice(TestUtils.getDeviceIds()); Assert.assertNotNull(activity); @@ -167,8 +157,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testRebootDevice() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.rebootDevice(TestUtils.getDeviceIds()); Assert.assertNotNull(activity); @@ -177,8 +166,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testChangeLockTask() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.changeLockTask(TestUtils.getDeviceIds()); Assert.assertNotNull(activity); @@ -186,8 +174,7 @@ public class DeviceManagementAdminServiceTests { } @Test - public void testMuteDevice() throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + public void testMuteDevice() throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.muteDevice(TestUtils.getDeviceIds()); Assert.assertNotNull(activity); @@ -196,8 +183,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testInstallApplication() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService .installApplication(TestUtils.getApplicationInstallationBeanWrapper()); @@ -207,8 +193,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testUpdateApplication() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.updateApplication(TestUtils.getApplicationUpdateBeanWrapper()); Assert.assertNotNull(activity); @@ -217,8 +202,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testUninstallApplicationPublic() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService .uninstallApplication(TestUtils.getApplicationUninstallationBeanWrapperPublic()); @@ -228,8 +212,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testUninstallApplicationWebApp() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService .uninstallApplication(TestUtils.getApplicationUninstallationBeanWrapperWebApp()); @@ -239,8 +222,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testBlacklistApplications() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService .blacklistApplications(TestUtils.getBlacklistApplicationsBeanWrapper()); @@ -250,8 +232,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testUpgradeFirmware() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.upgradeFirmware(TestUtils.getUpgradeFirmwareBeanWrapper()); Assert.assertNotNull(activity); @@ -260,8 +241,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testConfigureVPN() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.configureVPN(TestUtils.getVpnBeanWrapper()); Assert.assertNotNull(activity); @@ -270,8 +250,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testSendNotification() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.sendNotification(TestUtils.getNotificationBeanWrapper()); Assert.assertNotNull(activity); @@ -280,8 +259,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testConfigureWifi() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.configureWifi(TestUtils.getWifiBeanWrapper()); Assert.assertNotNull(activity); @@ -290,8 +268,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testEncryptStorage() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.encryptStorage(TestUtils.getEncryptionBeanWrapper()); Assert.assertNotNull(activity); @@ -300,8 +277,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testChangeLockCode() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.changeLockCode(TestUtils.getLockCodeBeanWrapper()); Assert.assertNotNull(activity); @@ -310,8 +286,7 @@ public class DeviceManagementAdminServiceTests { @Test public void testSetPasswordPolicy() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.setPasswordPolicy(TestUtils.getPasswordPolicyBeanWrapper()); Assert.assertNotNull(activity); @@ -319,8 +294,7 @@ public class DeviceManagementAdminServiceTests { } @Test - public void testSetWebClip() throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + public void testSetWebClip() throws OperationManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); Activity activity = androidService.setWebClip(TestUtils.getWebClipBeanWrapper()); Assert.assertNotNull(activity); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/test/java/org/wso2/carbon/device/mgt/mobile/android/core/DeviceManagementServiceTests.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/test/java/org/wso2/carbon/device/mgt/mobile/android/core/DeviceManagementServiceTests.java index b8c749b63..bea230479 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/test/java/org/wso2/carbon/device/mgt/mobile/android/core/DeviceManagementServiceTests.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/test/java/org/wso2/carbon/device/mgt/mobile/android/core/DeviceManagementServiceTests.java @@ -62,51 +62,44 @@ public class DeviceManagementServiceTests { } @BeforeClass - public void init() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + public void init() { MockitoAnnotations.initMocks(this); androidService = new AndroidServiceImpl(); } - private void mockDeviceManagementService() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + private void mockDeviceManagementService() { PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceManagementService")) .toReturn(new DeviceManagementProviderServiceMock()); } - private void mockApplicationManagerService() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + private void mockApplicationManagerService() { PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getApplicationManagerService")) .toReturn(new ApplicationManagementProviderServiceMock()); } - private void mockPolicyManagerService() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + private void mockPolicyManagerService() { PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getPolicyManagerService")) .toReturn(new PolicyManagerServiceMock()); } - private void mockDeviceInformationManagerService() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + private void mockDeviceInformationManagerService() { PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceInformationManagerService")) .toReturn(new DeviceInformationManagerServiceMock()); } - private void mockNotificationManagementService() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + private void mockNotificationManagementService() { PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getNotificationManagementService")) .toReturn(new NotificationManagementServiceMock()); } - private void mockUser() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + private void mockUser() { PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getAuthenticatedUser")) .toReturn("admin"); } @Test public void testUpdateApplicationList() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - ApplicationManagementException { + throws ApplicationManagementException { mockApplicationManagerService(); Message message = androidService .updateApplicationList(TestUtils.getDeviceId(), TestUtils.getAndroidApplications()); @@ -116,14 +109,14 @@ public class DeviceManagementServiceTests { @Test (expectedExceptions = {InvalidDeviceException.class}) public void testGetPendingOperationsForNullDevice() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException { List resultOperations = new ArrayList<>(); androidService.getPendingOperations(null, resultOperations, true); } @Test (expectedExceptions = {InvalidDeviceException.class}) public void testGetPendingOperationsForInvalidDevice() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); List resultOperations = new ArrayList<>(); androidService.getPendingOperations("1234", resultOperations, true); @@ -131,7 +124,7 @@ public class DeviceManagementServiceTests { @Test public void testGetPendingOperationsNullResponse() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); List pendingOperations = androidService .getPendingOperations(TestUtils.getDeviceId(), null, true); @@ -141,7 +134,7 @@ public class DeviceManagementServiceTests { @Test public void testGetPendingOperationsWithMonitorResponse() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); mockPolicyManagerService(); List pendingOperations = androidService @@ -152,7 +145,7 @@ public class DeviceManagementServiceTests { @Test public void testGetPendingOperationsWithApplicationResponse() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); mockApplicationManagerService(); List pendingOperations = androidService @@ -164,7 +157,7 @@ public class DeviceManagementServiceTests { @Test public void testGetPendingOperationsWithDeviceInfoResponse() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); mockDeviceInformationManagerService(); List pendingOperations = androidService @@ -176,7 +169,7 @@ public class DeviceManagementServiceTests { @Test public void testGetPendingOperationsWithInProgressResponse() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException, OperationManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); List pendingOperations = androidService .getPendingOperations(TestUtils.getDeviceId(), @@ -187,7 +180,7 @@ public class DeviceManagementServiceTests { @Test public void testGetPendingOperationsWithErrorResponse() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); mockNotificationManagementService(); List pendingOperations = androidService @@ -199,7 +192,7 @@ public class DeviceManagementServiceTests { @Test public void testEnrollDeviceWithoutLocationSuccess() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); mockPolicyManagerService(); mockUser(); @@ -210,7 +203,7 @@ public class DeviceManagementServiceTests { @Test public void testEnrollDeviceWithLocationSuccess() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); mockDeviceInformationManagerService(); mockPolicyManagerService(); @@ -251,7 +244,7 @@ public class DeviceManagementServiceTests { @Test public void testEnrollDeviceUnSuccess() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); mockUser(); AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice(); @@ -263,7 +256,7 @@ public class DeviceManagementServiceTests { @Test public void testIsEnrolledExists() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException { mockDeviceManagementService(); Message message = androidService.isEnrolled(TestUtils.getDeviceId(), null); Assert.assertNotNull(message); @@ -272,7 +265,7 @@ public class DeviceManagementServiceTests { @Test public void testIsEnrolledNonExist() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException { mockDeviceManagementService(); Message message = androidService.isEnrolled("1234", null); Assert.assertNotNull(message); @@ -281,7 +274,7 @@ public class DeviceManagementServiceTests { @Test public void testIsEnrolledNull() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException { mockDeviceManagementService(); Message response = androidService.isEnrolled(null, null); Assert.assertNotNull(response); @@ -290,8 +283,7 @@ public class DeviceManagementServiceTests { @Test public void testModifyEnrollmentSuccess() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws DeviceManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); mockUser(); boolean status = androidService.modifyEnrollment(TestUtils.getDeviceId(), TestUtils.getBasicAndroidDevice()); @@ -300,8 +292,7 @@ public class DeviceManagementServiceTests { @Test public void testModifyEnrollmentUnSuccess() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException, - AndroidDeviceMgtPluginException { + throws DeviceManagementException, AndroidDeviceMgtPluginException { mockDeviceManagementService(); mockUser(); AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice(); @@ -313,7 +304,7 @@ public class DeviceManagementServiceTests { @Test public void testDisEnrollDeviceSuccess() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException { mockDeviceManagementService(); boolean status = androidService.disEnrollDevice(TestUtils.getDeviceId()); Assert.assertTrue(status); @@ -321,7 +312,7 @@ public class DeviceManagementServiceTests { @Test public void testDisEnrollUnSuccess() - throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + throws DeviceManagementException { mockDeviceManagementService(); boolean status = androidService.disEnrollDevice("1234"); Assert.assertFalse(status);