Fix android webapp deployment issue

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

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

@ -16,7 +16,7 @@
* under the License. * 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; import org.wso2.carbon.device.mgt.mobile.android.common.Message;

@ -16,7 +16,7 @@
* under the License. * 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; import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse;

@ -16,7 +16,7 @@
* under the License. * 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.AndroidConstants;
import org.wso2.carbon.device.mgt.mobile.android.common.dto.ErrorDTO; 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 com.google.gson.JsonParseException;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.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 org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils;
import javax.naming.AuthenticationException; import javax.naming.AuthenticationException;
@ -58,7 +54,7 @@ public class GlobalThrowableMapper implements ExceptionMapper {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug(errorMessage, e); log.debug(errorMessage, e);
} }
return AndroidDeviceUtils.buildBadRequestException(errorMessage).getResponse(); return new BadRequestException(AndroidDeviceUtils.buildBadRequestException(errorMessage)).getResponse();
} }
if (e instanceof NotFoundException) { if (e instanceof NotFoundException) {
return ((NotFoundException) e).getResponse(); return ((NotFoundException) e).getResponse();

@ -16,7 +16,7 @@
* under the License. * 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.AndroidConstants;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse;

@ -16,7 +16,7 @@
* under the License. * 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.AndroidConstants;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; 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.bean.wrapper.TokenWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.dto.AndroidEnterpriseManagedConfig; 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.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.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.AndroidAPIUtils;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidEnterpriseUtils; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidEnterpriseUtils;
@ -117,11 +120,24 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
} catch (EnterpriseServiceException e) { } catch (EnterpriseServiceException e) {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when saving user").build()).build(); 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(); 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(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
String token; String token;
boolean deviceIdExist = false; boolean deviceIdExist = false;
@ -171,9 +187,9 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
public Response updateUser(EnterpriseInstallPolicy device) { public Response updateUser(EnterpriseInstallPolicy device) {
boolean sentToDevice = false; boolean sentToDevice = false;
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
try { try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
List<AndroidEnterpriseUser> enterpriseUserInstances = AndroidAPIUtils.getAndroidPluginService() List<AndroidEnterpriseUser> enterpriseUserInstances = AndroidAPIUtils.getAndroidPluginService()
.getEnterpriseUser(device.getUsername()); .getEnterpriseUser(device.getUsername());
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
@ -193,6 +209,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.status(Response.Status.NOT_FOUND).entity( return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND) 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) { if (sentToDevice) {
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
@ -213,8 +241,9 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
@QueryParam("isOrganizeAppPageVisible") boolean isOrganizeAppPageVisible, @QueryParam("isOrganizeAppPageVisible") boolean isOrganizeAppPageVisible,
@QueryParam("isManagedConfigEnabled") boolean isManagedConfigEnabled, @QueryParam("isManagedConfigEnabled") boolean isManagedConfigEnabled,
@QueryParam("host") String host) { @QueryParam("host") String host) {
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
EnterpriseTokenUrl enterpriseTokenUrl = new EnterpriseTokenUrl(); EnterpriseTokenUrl enterpriseTokenUrl = new EnterpriseTokenUrl();
if (enterpriseConfigs == null || enterpriseConfigs.getEnterpriseId() == null) { if (enterpriseConfigs == null || enterpriseConfigs.getEnterpriseId() == null) {
@ -229,7 +258,7 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
enterpriseTokenUrl.setOrganizeAppPageVisible(isOrganizeAppPageVisible); enterpriseTokenUrl.setOrganizeAppPageVisible(isOrganizeAppPageVisible);
enterpriseTokenUrl.setParentHost(host); enterpriseTokenUrl.setParentHost(host);
enterpriseTokenUrl.setManagedConfigEnabled(isManagedConfigEnabled); enterpriseTokenUrl.setManagedConfigEnabled(isManagedConfigEnabled);
try {
String token = googleAPIInvoker.getAdministratorWebToken(enterpriseTokenUrl); String token = googleAPIInvoker.getAdministratorWebToken(enterpriseTokenUrl);
TokenWrapper tokenWrapper = new TokenWrapper(); TokenWrapper tokenWrapper = new TokenWrapper();
tokenWrapper.setToken(token); tokenWrapper.setToken(token);
@ -238,6 +267,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when calling get web token").build()) new ErrorResponse.ErrorResponseBuilder().setMessage("Error when calling get web token").build())
.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 @GET
@Path("/products/sync") @Path("/products/sync")
public Response syncApps() { public Response syncApps() {
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
ProductsListResponse productsListResponse = googleAPIInvoker ProductsListResponse productsListResponse = googleAPIInvoker
.listProduct(enterpriseConfigs.getEnterpriseId(), null); .listProduct(enterpriseConfigs.getEnterpriseId(), null);
AndroidEnterpriseUtils.persistApp(productsListResponse); AndroidEnterpriseUtils.persistApp(productsListResponse);
@ -265,6 +307,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when persisting app").build()) new ErrorResponse.ErrorResponseBuilder().setMessage("Error when persisting app").build())
.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()) new ErrorResponse.ErrorResponseBuilder().setMessage("Message body is empty or incorrect").build())
.build(); .build();
} }
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
String id = googleAPIInvoker.insertPage(enterpriseConfigs.getEnterpriseId(), page); String id = googleAPIInvoker.insertPage(enterpriseConfigs.getEnterpriseId(), page);
page.setPageId(id); page.setPageId(id);
return Response.status(Response.Status.OK).entity(page).build(); return Response.status(Response.Status.OK).entity(page).build();
@ -312,6 +367,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when inserting page " new ErrorResponse.ErrorResponseBuilder().setMessage("Error when inserting page "
+ page.getPageName() + " , due to an error with ESA").build() ).build(); + 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(); .build();
} }
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
String id = googleAPIInvoker.updatePage(enterpriseConfigs.getEnterpriseId(), page); String id = googleAPIInvoker.updatePage(enterpriseConfigs.getEnterpriseId(), page);
page.setPageId(id); page.setPageId(id);
return Response.status(Response.Status.OK).entity(page).build(); return Response.status(Response.Status.OK).entity(page).build();
@ -339,6 +407,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating page " new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating page "
+ page.getPageName() + " , due to an error with ESA").build()).build(); + 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(); .build();
} }
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
googleAPIInvoker.deletePage(enterpriseConfigs.getEnterpriseId(), id); googleAPIInvoker.deletePage(enterpriseConfigs.getEnterpriseId(), id);
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
} catch (IOException e) { } catch (IOException e) {
@ -366,6 +447,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating page " new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating page "
+ id + " , Due to an error with ESA").build()).build(); + 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") @Path("/store-layout/page")
@Override @Override
public Response getPages() { public Response getPages() {
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
StoreLayoutPagesListResponse pages = googleAPIInvoker.listPages(enterpriseConfigs.getEnterpriseId()); StoreLayoutPagesListResponse pages = googleAPIInvoker.listPages(enterpriseConfigs.getEnterpriseId());
return Response.status(Response.Status.OK).entity(pages).build(); return Response.status(Response.Status.OK).entity(pages).build();
} catch (IOException e) { } catch (IOException e) {
@ -386,6 +480,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching page " new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching page "
+ " , Due to an error with ESA").build()).build(); + " , 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()) new ErrorResponse.ErrorResponseBuilder().setMessage("Id cannot be empty").build())
.build(); .build();
} }
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
StoreLayout layout = googleAPIInvoker.setStoreLayout(enterpriseConfigs.getEnterpriseId(), id); StoreLayout layout = googleAPIInvoker.setStoreLayout(enterpriseConfigs.getEnterpriseId(), id);
return Response.status(Response.Status.OK).entity(layout).build(); return Response.status(Response.Status.OK).entity(layout).build();
} catch (IOException e) { } catch (IOException e) {
@ -412,6 +519,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when inserting home page " new ErrorResponse.ErrorResponseBuilder().setMessage("Error when inserting home page "
+ id + " , due to an error with ESA").build() ).build(); + 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") @Path("/store-layout/home-page")
@Override @Override
public Response getHome() { public Response getHome() {
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
StoreLayout layout = googleAPIInvoker.getStoreLayout(enterpriseConfigs.getEnterpriseId()); StoreLayout layout = googleAPIInvoker.getStoreLayout(enterpriseConfigs.getEnterpriseId());
return Response.status(Response.Status.OK).entity(layout).build(); return Response.status(Response.Status.OK).entity(layout).build();
} catch (IOException e) { } catch (IOException e) {
@ -431,6 +551,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching home page.").build() ) new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching home page.").build() )
.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(); new ErrorResponse.ErrorResponseBuilder().setMessage("Cluster order cannot be empty").build()).build();
} }
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
String id = googleAPIInvoker.insertCluster(enterpriseConfigs.getEnterpriseId(), storeCluster); String id = googleAPIInvoker.insertCluster(enterpriseConfigs.getEnterpriseId(), storeCluster);
storeCluster.setClusterId(id); storeCluster.setClusterId(id);
return Response.status(Response.Status.OK).entity(storeCluster).build(); return Response.status(Response.Status.OK).entity(storeCluster).build();
@ -467,6 +600,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating cluster " new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating cluster "
+ storeCluster.getName() + " , due to an error with ESA").build()).build(); + 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(); new ErrorResponse.ErrorResponseBuilder().setMessage("Cluster order cannot be empty").build()).build();
} }
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
String id = googleAPIInvoker.updateCluster(enterpriseConfigs.getEnterpriseId(), storeCluster); String id = googleAPIInvoker.updateCluster(enterpriseConfigs.getEnterpriseId(), storeCluster);
storeCluster.setClusterId(id); storeCluster.setClusterId(id);
return Response.status(Response.Status.OK).entity(storeCluster).build(); return Response.status(Response.Status.OK).entity(storeCluster).build();
@ -503,6 +649,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating cluster " new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating cluster "
+ storeCluster.getName() + " , due to an error with ESA").build()).build(); + 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(); new ErrorResponse.ErrorResponseBuilder().setMessage("Page id cannot be empty").build()).build();
} }
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
googleAPIInvoker.deleteCluster(enterpriseConfigs.getEnterpriseId(), pageId, clusterId); googleAPIInvoker.deleteCluster(enterpriseConfigs.getEnterpriseId(), pageId, clusterId);
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
} catch (IOException e) { } catch (IOException e) {
@ -532,6 +691,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when deleting cluster " new ErrorResponse.ErrorResponseBuilder().setMessage("Error when deleting cluster "
+ clusterId + " , due to an error with ESA").build()).build(); + 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(); new ErrorResponse.ErrorResponseBuilder().setMessage("Page id cannot be empty").build()).build();
} }
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
StoreLayoutClustersListResponse response = googleAPIInvoker.getClusters(enterpriseConfigs.getEnterpriseId(), pageId); StoreLayoutClustersListResponse response = googleAPIInvoker.getClusters(enterpriseConfigs.getEnterpriseId(), pageId);
if (response == null || response.getCluster() == null) { if (response == null || response.getCluster() == null) {
return Response.status(Response.Status.NOT_FOUND).entity( return Response.status(Response.Status.NOT_FOUND).entity(
@ -601,6 +773,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching all details in PageId " new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching all details in PageId "
+ pageId).build()).build(); + 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") @Path("/store-layout/page-link")
@Override @Override
public Response updateLinks(EnterpriseStorePageLinks link) { public Response updateLinks(EnterpriseStorePageLinks link) {
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa()); GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
googleAPIInvoker.addLinks(enterpriseConfigs.getEnterpriseId(), googleAPIInvoker.addLinks(enterpriseConfigs.getEnterpriseId(),
link.getPageId(), link.getLinks()); link.getPageId(), link.getLinks());
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
@ -622,6 +807,18 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching page " new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching page "
+ " , Due to an error with ESA").build()).build(); + " , 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) { public Response updateUser(ApplicationPolicyDTO applicationPolicyDTO) {
boolean sentToDevice = false; boolean sentToDevice = false;
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
for (DeviceIdentifier deviceIdentifier : applicationPolicyDTO.getDeviceIdentifierList()) { for (DeviceIdentifier deviceIdentifier : applicationPolicyDTO.getDeviceIdentifierList()) {
try { try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
AndroidEnterpriseUser userDetail = AndroidAPIUtils.getAndroidPluginService() AndroidEnterpriseUser userDetail = AndroidAPIUtils.getAndroidPluginService()
.getEnterpriseUserByDevice(deviceIdentifier.getId()); .getEnterpriseUserByDevice(deviceIdentifier.getId());
@ -791,7 +989,20 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
log.error(errorMessage); log.error(errorMessage);
return Response.status(Response.Status.NOT_FOUND).entity( return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND) 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) { if (sentToDevice) {
@ -809,6 +1020,7 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
@Path("/wipe-device") @Path("/wipe-device")
public Response wipeEnterprise() { public Response wipeEnterprise() {
log.warn("Wiping all devices!!!"); log.warn("Wiping all devices!!!");
try{
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
try { try {
// Take all enterprise devices in the DB. // Take all enterprise devices in the DB.
@ -871,7 +1083,19 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); new ErrorResponse.ErrorResponseBuilder().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 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.WifiBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.WipeDataBeanWrapper; 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.AndroidDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestException;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestExceptionDup; import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestExceptionDup;
import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService; import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils; import org.wso2.carbon.device.mgt.mobile.android.core.util.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.AndroidPlatformConfiguration;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; 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.AndroidDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestException;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestExceptionDup; import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestExceptionDup;
import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService; import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils;
@ -95,9 +94,9 @@ public class DeviceTypeConfigurationAPIImpl implements DeviceTypeConfigurationAP
} catch (BadRequestExceptionDup e) { } catch (BadRequestExceptionDup e) {
String msg = "The payload of the android platform configuration is incorrect."; String msg = "The payload of the android platform configuration is incorrect.";
log.error(msg, e); log.error(msg, e);
throw new BadRequestException( return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST)
.setMessage(msg).build()); .setMessage(msg).build()).build();
} catch (AndroidDeviceMgtPluginException e) { } catch (AndroidDeviceMgtPluginException e) {
String msg = "Error occurred while modifying configuration settings of Android platform"; String msg = "Error occurred while modifying configuration settings of Android platform";
log.error(msg, e); log.error(msg, e);

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

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

@ -849,10 +849,10 @@ public class AndroidServiceImpl implements AndroidService {
String errorMessage = "Issue in retrieving operation management service instance"; String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e); log.error(errorMessage, e);
throw new UnexpectedServerErrorExceptionDup(errorMessage); throw new UnexpectedServerErrorExceptionDup(errorMessage);
} catch (DeviceManagementException e) { } catch (BadRequestExceptionDup e) {
String errorMessage = "Issue in retrieving device management service instance"; String errorMessage = "Issue in retrieving device management service instance";
log.error(errorMessage, e); log.error(errorMessage, e);
throw new UnexpectedServerErrorExceptionDup(errorMessage, e); throw new BadRequestExceptionDup(errorMessage, e);
} }
} }
@ -1345,8 +1345,11 @@ public class AndroidServiceImpl implements AndroidService {
} }
} }
public String insertUser(EnterpriseUser enterpriseUser) throws EnterpriseServiceException { public String insertUser(EnterpriseUser enterpriseUser)
throws EnterpriseServiceException, AndroidDeviceMgtPluginException {
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs(); EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
String token; String token;
boolean deviceIdExist = false; boolean deviceIdExist = false;
@ -1383,51 +1386,59 @@ public class AndroidServiceImpl implements AndroidService {
AndroidAPIUtils.getAndroidPluginService().addEnterpriseUser(androidEnterpriseUser); AndroidAPIUtils.getAndroidPluginService().addEnterpriseUser(androidEnterpriseUser);
} }
return token; 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);
}
} }
private static void validateApplicationUrl(String apkUrl) { private static void validateApplicationUrl(String apkUrl) throws BadRequestExceptionDup{
try { try {
URL url = new URL(apkUrl); URL url = new URL(apkUrl);
URLConnection conn = url.openConnection(); URLConnection conn = url.openConnection();
if (((HttpURLConnection) conn).getResponseCode() != HttpURLConnection.HTTP_OK) { if (((HttpURLConnection) conn).getResponseCode() != HttpURLConnection.HTTP_OK) {
String errorMessage = "URL is not pointed to a downloadable file."; String errorMessage = "URL is not pointed to a downloadable file.";
log.error(errorMessage); log.error(errorMessage);
throw new BadRequestException( throw new BadRequestExceptionDup(errorMessage);
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
String errorMessage = "Malformed application url."; String errorMessage = "Malformed application url.";
log.error(errorMessage); log.error(errorMessage);
throw new BadRequestException( throw new BadRequestExceptionDup(errorMessage);
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (IOException e) { } catch (IOException e) {
String errorMessage = "Invalid application url."; String errorMessage = "Invalid application url.";
log.error(errorMessage); log.error(errorMessage);
throw new BadRequestException( throw new BadRequestExceptionDup(errorMessage);
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
} }
private static void validateApplicationType(String type) { private static void validateApplicationType(String type) throws BadRequestExceptionDup{
if (type != null) { if (type != null) {
if (!"enterprise".equalsIgnoreCase(type) if (!"enterprise".equalsIgnoreCase(type)
&& !"public".equalsIgnoreCase(type) && !"public".equalsIgnoreCase(type)
&& !"webapp".equalsIgnoreCase(type)) { && !"webapp".equalsIgnoreCase(type)) {
String errorMessage = "Invalid application type."; String errorMessage = "Invalid application type.";
log.error(errorMessage); log.error(errorMessage);
throw new BadRequestException( throw new BadRequestExceptionDup(errorMessage);
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
} else { } else {
String errorMessage = "Application type is missing."; String errorMessage = "Application type is missing.";
log.error(errorMessage); log.error(errorMessage);
throw new BadRequestException( throw new BadRequestExceptionDup(errorMessage);
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
} }
private static void validateScheduleDate(String dateString) { private static void validateScheduleDate(String dateString) throws BadRequestExceptionDup{
try { try {
if (dateString != null && !dateString.isEmpty()) { if (dateString != null && !dateString.isEmpty()) {
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
@ -1437,8 +1448,7 @@ public class AndroidServiceImpl implements AndroidService {
} catch (ParseException e) { } catch (ParseException e) {
String errorMessage = "Issue in validating the schedule date"; String errorMessage = "Issue in validating the schedule date";
log.error(errorMessage); log.error(errorMessage);
throw new BadRequestException( throw new BadRequestExceptionDup(errorMessage);
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
} }
} }

@ -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.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants; 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.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.AndroidGoogleEnterpriseService;
import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService; import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
@ -176,12 +177,11 @@ public class AndroidAPIUtils {
} }
public static Response getOperationResponse(List<String> deviceIDs, Operation operation) public static Response getOperationResponse(List<String> deviceIDs, Operation operation)
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws AndroidDeviceMgtPluginException, OperationManagementException, InvalidDeviceException {
if (deviceIDs == null || deviceIDs.size() == 0) { if (deviceIDs == null || deviceIDs.size() == 0) {
String errorMessage = "Device identifier list is empty"; String errorMessage = "Device identifier list is empty";
log.error(errorMessage); log.error(errorMessage);
throw new BadRequestException( throw new BadRequestExceptionDup(errorMessage);
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
DeviceIdentifier deviceIdentifier; DeviceIdentifier deviceIdentifier;
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>(); 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.EnterpriseApp;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EnterpriseInstallPolicy; 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.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.device.mgt.mobile.android.common.exception.EnterpriseServiceException;
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
import org.wso2.carbon.policy.mgt.common.FeatureManagementException; import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
@ -140,12 +141,11 @@ public class AndroidDeviceUtils {
} }
public static Activity getOperationResponse(List<String> deviceIDs, Operation operation) public static Activity getOperationResponse(List<String> deviceIDs, Operation operation)
throws OperationManagementException, InvalidDeviceException { throws OperationManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException {
if (deviceIDs == null || deviceIDs.isEmpty()) { if (deviceIDs == null || deviceIDs.isEmpty()) {
String errorMessage = "Device identifier list is empty"; String errorMessage = "Device identifier list is empty";
log.error(errorMessage); log.error(errorMessage);
throw new BadRequestException( throw new BadRequestExceptionDup(errorMessage);
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
DeviceIdentifier deviceIdentifier; DeviceIdentifier deviceIdentifier;
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>(); List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
@ -637,10 +637,10 @@ public class AndroidDeviceUtils {
* @param description description of the exception * @param description description of the exception
* @return a new BadRequestException with the specified details as a response DTO * @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. ErrorResponse errorResponse = getErrorResponse(AndroidConstants.
ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT, 400l, description); 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.bean.wrapper.EnterpriseInstallPolicy;
import org.wso2.carbon.device.mgt.mobile.android.common.dto.AndroidEnterpriseManagedConfig; 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.dto.AndroidEnterpriseUser;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.EnterpriseServiceException; import org.wso2.carbon.device.mgt.mobile.android.common.exception.*;
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.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.service.RealmService;
@ -223,13 +221,13 @@ public class AndroidEnterpriseUtils {
return userInfo; return userInfo;
} }
public static EnterpriseConfigs getEnterpriseConfigs() { public static EnterpriseConfigs getEnterpriseConfigs() throws AndroidDeviceMgtPluginException {
EnterpriseConfigs enterpriseConfigs = getEnterpriseConfigsFromGoogle(); EnterpriseConfigs enterpriseConfigs = getEnterpriseConfigsFromGoogle();
if (enterpriseConfigs.getErrorResponse() != null) { if (enterpriseConfigs.getErrorResponse() != null) {
if (enterpriseConfigs.getErrorResponse().getCode() == 500l) { if (enterpriseConfigs.getErrorResponse().getCode() == 500l) {
throw new UnexpectedServerErrorException(enterpriseConfigs.getErrorResponse()); throw new UnexpectedServerErrorExceptionDup(enterpriseConfigs.getErrorResponse().getMessage());
} else if (enterpriseConfigs.getErrorResponse().getCode() == 500l) { } else if (enterpriseConfigs.getErrorResponse().getCode() == 500l) {
throw new NotFoundException(enterpriseConfigs.getErrorResponse()); throw new NotFoundExceptionDup(enterpriseConfigs.getErrorResponse().getMessage());
} }
} }
return enterpriseConfigs; return enterpriseConfigs;

@ -70,8 +70,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testConfigureDeviceUnlock() public void testConfigureDeviceUnlock()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.configureDeviceUnlock(TestUtils.getDeviceIds()); Activity activity = androidService.configureDeviceUnlock(TestUtils.getDeviceIds());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -80,8 +79,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testGetDeviceLocation() public void testGetDeviceLocation()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.getDeviceLocation(TestUtils.getDeviceIds()); Activity activity = androidService.getDeviceLocation(TestUtils.getDeviceIds());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -90,8 +88,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testRemovePassword() public void testRemovePassword()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.removePassword(TestUtils.getDeviceIds()); Activity activity = androidService.removePassword(TestUtils.getDeviceIds());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -100,8 +97,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testConfigureCamera() public void testConfigureCamera()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.configureCamera(TestUtils.getCamerabeanWrapper()); Activity activity = androidService.configureCamera(TestUtils.getCamerabeanWrapper());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -110,8 +106,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testGetDeviceInformation() public void testGetDeviceInformation()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.getDeviceInformation(TestUtils.getDeviceIds()); Activity activity = androidService.getDeviceInformation(TestUtils.getDeviceIds());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -120,8 +115,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testGetDeviceLogcat() public void testGetDeviceLogcat()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.getDeviceLogcat(TestUtils.getDeviceIds()); Activity activity = androidService.getDeviceLogcat(TestUtils.getDeviceIds());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -129,8 +123,7 @@ public class DeviceManagementAdminServiceTests {
} }
@Test @Test
public void testWipeDevice() throws DeviceManagementException, OperationManagementException, InvalidDeviceException, public void testWipeDevice() throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.wipeDevice(TestUtils.getDeviceIds()); Activity activity = androidService.wipeDevice(TestUtils.getDeviceIds());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -138,8 +131,7 @@ public class DeviceManagementAdminServiceTests {
} }
@Test @Test
public void testWipeData() throws DeviceManagementException, OperationManagementException, InvalidDeviceException, public void testWipeData() throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.wipeData(TestUtils.getWipeDataBeanWrapper()); Activity activity = androidService.wipeData(TestUtils.getWipeDataBeanWrapper());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -148,8 +140,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testGetApplications() public void testGetApplications()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.getApplications(TestUtils.getDeviceIds()); Activity activity = androidService.getApplications(TestUtils.getDeviceIds());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -157,8 +148,7 @@ public class DeviceManagementAdminServiceTests {
} }
@Test @Test
public void testRingDevice() throws DeviceManagementException, OperationManagementException, InvalidDeviceException, public void testRingDevice() throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.ringDevice(TestUtils.getDeviceIds()); Activity activity = androidService.ringDevice(TestUtils.getDeviceIds());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -167,8 +157,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testRebootDevice() public void testRebootDevice()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.rebootDevice(TestUtils.getDeviceIds()); Activity activity = androidService.rebootDevice(TestUtils.getDeviceIds());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -177,8 +166,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testChangeLockTask() public void testChangeLockTask()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.changeLockTask(TestUtils.getDeviceIds()); Activity activity = androidService.changeLockTask(TestUtils.getDeviceIds());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -186,8 +174,7 @@ public class DeviceManagementAdminServiceTests {
} }
@Test @Test
public void testMuteDevice() throws DeviceManagementException, OperationManagementException, InvalidDeviceException, public void testMuteDevice() throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.muteDevice(TestUtils.getDeviceIds()); Activity activity = androidService.muteDevice(TestUtils.getDeviceIds());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -196,8 +183,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testInstallApplication() public void testInstallApplication()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService Activity activity = androidService
.installApplication(TestUtils.getApplicationInstallationBeanWrapper()); .installApplication(TestUtils.getApplicationInstallationBeanWrapper());
@ -207,8 +193,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testUpdateApplication() public void testUpdateApplication()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.updateApplication(TestUtils.getApplicationUpdateBeanWrapper()); Activity activity = androidService.updateApplication(TestUtils.getApplicationUpdateBeanWrapper());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -217,8 +202,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testUninstallApplicationPublic() public void testUninstallApplicationPublic()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService Activity activity = androidService
.uninstallApplication(TestUtils.getApplicationUninstallationBeanWrapperPublic()); .uninstallApplication(TestUtils.getApplicationUninstallationBeanWrapperPublic());
@ -228,8 +212,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testUninstallApplicationWebApp() public void testUninstallApplicationWebApp()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService Activity activity = androidService
.uninstallApplication(TestUtils.getApplicationUninstallationBeanWrapperWebApp()); .uninstallApplication(TestUtils.getApplicationUninstallationBeanWrapperWebApp());
@ -239,8 +222,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testBlacklistApplications() public void testBlacklistApplications()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService Activity activity = androidService
.blacklistApplications(TestUtils.getBlacklistApplicationsBeanWrapper()); .blacklistApplications(TestUtils.getBlacklistApplicationsBeanWrapper());
@ -250,8 +232,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testUpgradeFirmware() public void testUpgradeFirmware()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.upgradeFirmware(TestUtils.getUpgradeFirmwareBeanWrapper()); Activity activity = androidService.upgradeFirmware(TestUtils.getUpgradeFirmwareBeanWrapper());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -260,8 +241,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testConfigureVPN() public void testConfigureVPN()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.configureVPN(TestUtils.getVpnBeanWrapper()); Activity activity = androidService.configureVPN(TestUtils.getVpnBeanWrapper());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -270,8 +250,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testSendNotification() public void testSendNotification()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.sendNotification(TestUtils.getNotificationBeanWrapper()); Activity activity = androidService.sendNotification(TestUtils.getNotificationBeanWrapper());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -280,8 +259,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testConfigureWifi() public void testConfigureWifi()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.configureWifi(TestUtils.getWifiBeanWrapper()); Activity activity = androidService.configureWifi(TestUtils.getWifiBeanWrapper());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -290,8 +268,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testEncryptStorage() public void testEncryptStorage()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.encryptStorage(TestUtils.getEncryptionBeanWrapper()); Activity activity = androidService.encryptStorage(TestUtils.getEncryptionBeanWrapper());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -300,8 +277,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testChangeLockCode() public void testChangeLockCode()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.changeLockCode(TestUtils.getLockCodeBeanWrapper()); Activity activity = androidService.changeLockCode(TestUtils.getLockCodeBeanWrapper());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -310,8 +286,7 @@ public class DeviceManagementAdminServiceTests {
@Test @Test
public void testSetPasswordPolicy() public void testSetPasswordPolicy()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.setPasswordPolicy(TestUtils.getPasswordPolicyBeanWrapper()); Activity activity = androidService.setPasswordPolicy(TestUtils.getPasswordPolicyBeanWrapper());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
@ -319,8 +294,7 @@ public class DeviceManagementAdminServiceTests {
} }
@Test @Test
public void testSetWebClip() throws DeviceManagementException, OperationManagementException, InvalidDeviceException, public void testSetWebClip() throws OperationManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
Activity activity = androidService.setWebClip(TestUtils.getWebClipBeanWrapper()); Activity activity = androidService.setWebClip(TestUtils.getWebClipBeanWrapper());
Assert.assertNotNull(activity); Assert.assertNotNull(activity);

@ -62,51 +62,44 @@ public class DeviceManagementServiceTests {
} }
@BeforeClass @BeforeClass
public void init() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { public void init() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
androidService = new AndroidServiceImpl(); androidService = new AndroidServiceImpl();
} }
private void mockDeviceManagementService() private void mockDeviceManagementService() {
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceManagementService")) PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceManagementService"))
.toReturn(new DeviceManagementProviderServiceMock()); .toReturn(new DeviceManagementProviderServiceMock());
} }
private void mockApplicationManagerService() private void mockApplicationManagerService() {
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getApplicationManagerService")) PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getApplicationManagerService"))
.toReturn(new ApplicationManagementProviderServiceMock()); .toReturn(new ApplicationManagementProviderServiceMock());
} }
private void mockPolicyManagerService() private void mockPolicyManagerService() {
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getPolicyManagerService")) PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getPolicyManagerService"))
.toReturn(new PolicyManagerServiceMock()); .toReturn(new PolicyManagerServiceMock());
} }
private void mockDeviceInformationManagerService() private void mockDeviceInformationManagerService() {
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceInformationManagerService")) PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceInformationManagerService"))
.toReturn(new DeviceInformationManagerServiceMock()); .toReturn(new DeviceInformationManagerServiceMock());
} }
private void mockNotificationManagementService() private void mockNotificationManagementService() {
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getNotificationManagementService")) PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getNotificationManagementService"))
.toReturn(new NotificationManagementServiceMock()); .toReturn(new NotificationManagementServiceMock());
} }
private void mockUser() private void mockUser() {
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getAuthenticatedUser")) PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getAuthenticatedUser"))
.toReturn("admin"); .toReturn("admin");
} }
@Test @Test
public void testUpdateApplicationList() public void testUpdateApplicationList()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws ApplicationManagementException {
ApplicationManagementException {
mockApplicationManagerService(); mockApplicationManagerService();
Message message = androidService Message message = androidService
.updateApplicationList(TestUtils.getDeviceId(), TestUtils.getAndroidApplications()); .updateApplicationList(TestUtils.getDeviceId(), TestUtils.getAndroidApplications());
@ -116,14 +109,14 @@ public class DeviceManagementServiceTests {
@Test (expectedExceptions = {InvalidDeviceException.class}) @Test (expectedExceptions = {InvalidDeviceException.class})
public void testGetPendingOperationsForNullDevice() public void testGetPendingOperationsForNullDevice()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException {
List<? extends Operation> resultOperations = new ArrayList<>(); List<? extends Operation> resultOperations = new ArrayList<>();
androidService.getPendingOperations(null, resultOperations, true); androidService.getPendingOperations(null, resultOperations, true);
} }
@Test (expectedExceptions = {InvalidDeviceException.class}) @Test (expectedExceptions = {InvalidDeviceException.class})
public void testGetPendingOperationsForInvalidDevice() public void testGetPendingOperationsForInvalidDevice()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
List<? extends Operation> resultOperations = new ArrayList<>(); List<? extends Operation> resultOperations = new ArrayList<>();
androidService.getPendingOperations("1234", resultOperations, true); androidService.getPendingOperations("1234", resultOperations, true);
@ -131,7 +124,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testGetPendingOperationsNullResponse() public void testGetPendingOperationsNullResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
List<? extends Operation> pendingOperations = androidService List<? extends Operation> pendingOperations = androidService
.getPendingOperations(TestUtils.getDeviceId(), null, true); .getPendingOperations(TestUtils.getDeviceId(), null, true);
@ -141,7 +134,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testGetPendingOperationsWithMonitorResponse() public void testGetPendingOperationsWithMonitorResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
mockPolicyManagerService(); mockPolicyManagerService();
List<? extends Operation> pendingOperations = androidService List<? extends Operation> pendingOperations = androidService
@ -152,7 +145,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testGetPendingOperationsWithApplicationResponse() public void testGetPendingOperationsWithApplicationResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
mockApplicationManagerService(); mockApplicationManagerService();
List<? extends Operation> pendingOperations = androidService List<? extends Operation> pendingOperations = androidService
@ -164,7 +157,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testGetPendingOperationsWithDeviceInfoResponse() public void testGetPendingOperationsWithDeviceInfoResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
mockDeviceInformationManagerService(); mockDeviceInformationManagerService();
List<? extends Operation> pendingOperations = androidService List<? extends Operation> pendingOperations = androidService
@ -176,7 +169,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testGetPendingOperationsWithInProgressResponse() public void testGetPendingOperationsWithInProgressResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
List<? extends Operation> pendingOperations = androidService List<? extends Operation> pendingOperations = androidService
.getPendingOperations(TestUtils.getDeviceId(), .getPendingOperations(TestUtils.getDeviceId(),
@ -187,7 +180,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testGetPendingOperationsWithErrorResponse() public void testGetPendingOperationsWithErrorResponse()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
mockNotificationManagementService(); mockNotificationManagementService();
List<? extends Operation> pendingOperations = androidService List<? extends Operation> pendingOperations = androidService
@ -199,7 +192,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testEnrollDeviceWithoutLocationSuccess() public void testEnrollDeviceWithoutLocationSuccess()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
mockPolicyManagerService(); mockPolicyManagerService();
mockUser(); mockUser();
@ -210,7 +203,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testEnrollDeviceWithLocationSuccess() public void testEnrollDeviceWithLocationSuccess()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
mockDeviceInformationManagerService(); mockDeviceInformationManagerService();
mockPolicyManagerService(); mockPolicyManagerService();
@ -251,7 +244,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testEnrollDeviceUnSuccess() public void testEnrollDeviceUnSuccess()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
mockUser(); mockUser();
AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice(); AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice();
@ -263,7 +256,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testIsEnrolledExists() public void testIsEnrolledExists()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException {
mockDeviceManagementService(); mockDeviceManagementService();
Message message = androidService.isEnrolled(TestUtils.getDeviceId(), null); Message message = androidService.isEnrolled(TestUtils.getDeviceId(), null);
Assert.assertNotNull(message); Assert.assertNotNull(message);
@ -272,7 +265,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testIsEnrolledNonExist() public void testIsEnrolledNonExist()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException {
mockDeviceManagementService(); mockDeviceManagementService();
Message message = androidService.isEnrolled("1234", null); Message message = androidService.isEnrolled("1234", null);
Assert.assertNotNull(message); Assert.assertNotNull(message);
@ -281,7 +274,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testIsEnrolledNull() public void testIsEnrolledNull()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException {
mockDeviceManagementService(); mockDeviceManagementService();
Message response = androidService.isEnrolled(null, null); Message response = androidService.isEnrolled(null, null);
Assert.assertNotNull(response); Assert.assertNotNull(response);
@ -290,8 +283,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testModifyEnrollmentSuccess() public void testModifyEnrollmentSuccess()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws DeviceManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
mockUser(); mockUser();
boolean status = androidService.modifyEnrollment(TestUtils.getDeviceId(), TestUtils.getBasicAndroidDevice()); boolean status = androidService.modifyEnrollment(TestUtils.getDeviceId(), TestUtils.getBasicAndroidDevice());
@ -300,8 +292,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testModifyEnrollmentUnSuccess() public void testModifyEnrollmentUnSuccess()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException, throws DeviceManagementException, AndroidDeviceMgtPluginException {
AndroidDeviceMgtPluginException {
mockDeviceManagementService(); mockDeviceManagementService();
mockUser(); mockUser();
AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice(); AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice();
@ -313,7 +304,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testDisEnrollDeviceSuccess() public void testDisEnrollDeviceSuccess()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException {
mockDeviceManagementService(); mockDeviceManagementService();
boolean status = androidService.disEnrollDevice(TestUtils.getDeviceId()); boolean status = androidService.disEnrollDevice(TestUtils.getDeviceId());
Assert.assertTrue(status); Assert.assertTrue(status);
@ -321,7 +312,7 @@ public class DeviceManagementServiceTests {
@Test @Test
public void testDisEnrollUnSuccess() public void testDisEnrollUnSuccess()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException {
mockDeviceManagementService(); mockDeviceManagementService();
boolean status = androidService.disEnrollDevice("1234"); boolean status = androidService.disEnrollDevice("1234");
Assert.assertFalse(status); Assert.assertFalse(status);

Loading…
Cancel
Save