Fix android webapp deployment issue

revert-dabc3590
shamalka 5 years ago
parent 49d518805e
commit 69874726ba

@ -224,6 +224,12 @@
</exclusions>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-androidenterprise</artifactId>
<version>v1-rev186-1.25.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>

@ -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;

@ -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();

@ -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;

@ -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;

@ -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<AndroidEnterpriseUser> 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<AndroidEnterpriseUser> androidEnterpriseUsers = AndroidAPIUtils.getAndroidPluginService()
.getAllEnterpriseDevices(enterpriseConfigs.getEnterpriseId());
// Extract the device identifiers of enterprise devices.
List<String> 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<AndroidEnterpriseUser> androidEnterpriseUsers = AndroidAPIUtils.getAndroidPluginService()
.getAllEnterpriseDevices(enterpriseConfigs.getEnterpriseId());
// Extract the device identifiers of enterprise devices.
List<String> deviceID = new ArrayList<>();
if (androidEnterpriseUsers != null && !androidEnterpriseUsers.isEmpty()) {
for (AndroidEnterpriseUser userDevice: androidEnterpriseUsers) {
deviceID.add(userDevice.getEmmDeviceId());
}
}
}
List<String> byodDevices = new ArrayList<>();
List<String> copeDevices = new ArrayList<>();
// Get all registered device
List<Device> 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<String> byodDevices = new ArrayList<>();
List<String> copeDevices = new ArrayList<>();
// Get all registered device
List<Device> 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();
}
}
}

@ -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;

@ -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);

@ -34,7 +34,7 @@
<ref bean="jsonProvider"/>
<ref bean="errorHandler"/>
<ref bean="swaggerWriter"/>
<ref bean="GlobalExceptionMapper"/>
<!-- <ref bean="GlobalExceptionMapper"/>-->
</jaxrs:providers>
<jaxrs:properties>
<!-- This is added to catch interceptor level exceptions in GlobalThrowableMapper. -->
@ -44,7 +44,7 @@
<bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers" />
<bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource" />
<bean id="GlobalExceptionMapper" class="org.wso2.carbon.device.mgt.mobile.android.api.exception.GlobalThrowableMapper"/>
<!-- <bean id="GlobalExceptionMapper" class="org.wso2.carbon.device.mgt.mobile.android.api.exception.GlobalThrowableMapper"/>-->
<bean id="ValidationInterceptor" class="org.wso2.carbon.device.mgt.mobile.android.addons.ValidationInterceptor"/>
<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">

@ -161,6 +161,7 @@
<dependency>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>org.wso2.carbon.device.mgt.mobile.android.common</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>

@ -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<AndroidEnterpriseUser> 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<AndroidEnterpriseUser> 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);
}
}
}

@ -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<String> 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<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();

@ -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<String> 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<DeviceIdentifier> 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;
}
/**

@ -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;

@ -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);

@ -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<? extends Operation> 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<? extends Operation> 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<? extends Operation> 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<? extends Operation> pendingOperations = androidService
@ -152,7 +145,7 @@ public class DeviceManagementServiceTests {
@Test
public void testGetPendingOperationsWithApplicationResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException {
mockDeviceManagementService();
mockApplicationManagerService();
List<? extends Operation> pendingOperations = androidService
@ -164,7 +157,7 @@ public class DeviceManagementServiceTests {
@Test
public void testGetPendingOperationsWithDeviceInfoResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException {
mockDeviceManagementService();
mockDeviceInformationManagerService();
List<? extends Operation> pendingOperations = androidService
@ -176,7 +169,7 @@ public class DeviceManagementServiceTests {
@Test
public void testGetPendingOperationsWithInProgressResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException {
mockDeviceManagementService();
List<? extends Operation> 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<? extends Operation> 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);

Loading…
Cancel
Save