mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Replace custom exceptions
This commit is contained in:
parent
47e569fa08
commit
49d518805e
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.mobile.android.api.impl;
|
package org.wso2.carbon.device.mgt.mobile.android.api.impl;
|
||||||
|
|
||||||
|
import com.google.api.client.http.HttpStatusCodes;
|
||||||
import com.google.api.services.androidenterprise.model.ProductsListResponse;
|
import com.google.api.services.androidenterprise.model.ProductsListResponse;
|
||||||
import com.google.api.services.androidenterprise.model.StoreCluster;
|
import com.google.api.services.androidenterprise.model.StoreCluster;
|
||||||
import com.google.api.services.androidenterprise.model.StoreLayout;
|
import com.google.api.services.androidenterprise.model.StoreLayout;
|
||||||
@ -57,9 +58,7 @@ 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.BadRequestException;
|
|
||||||
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.NotFoundException;
|
|
||||||
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;
|
||||||
@ -191,8 +190,9 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
|
|||||||
} catch (EnterpriseServiceException e) {
|
} catch (EnterpriseServiceException e) {
|
||||||
String errorMessage = "App install failed. No user found for name " + device.getUsername();
|
String errorMessage = "App install failed. No user found for name " + device.getUsername();
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
throw new NotFoundException(
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND)
|
||||||
|
.setMessage(errorMessage).build()).build();
|
||||||
}
|
}
|
||||||
if (sentToDevice) {
|
if (sentToDevice) {
|
||||||
return Response.status(Response.Status.OK).build();
|
return Response.status(Response.Status.OK).build();
|
||||||
@ -759,9 +759,9 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
|
|||||||
String errorMessage = "App: " + applicationPolicyDTO.getApplicationDTO()
|
String errorMessage = "App: " + applicationPolicyDTO.getApplicationDTO()
|
||||||
.getPackageName() + " for device " + deviceIdentifier.getId();
|
.getPackageName() + " for device " + deviceIdentifier.getId();
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
throw new BadRequestException(
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(Response.Status.BAD_REQUEST
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST)
|
||||||
.getStatusCode()).setMessage(errorMessage).build());
|
.setMessage(errorMessage).build()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
googleAPIInvoker.installApps(enterpriseConfigs.getEnterpriseId(), userDetail
|
googleAPIInvoker.installApps(enterpriseConfigs.getEnterpriseId(), userDetail
|
||||||
@ -783,15 +783,15 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
|
|||||||
} catch (EnterpriseServiceException e) {
|
} catch (EnterpriseServiceException e) {
|
||||||
String errorMessage = "App install failed for device " + deviceIdentifier.getId();
|
String errorMessage = "App install failed for device " + deviceIdentifier.getId();
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
throw new NotFoundException(
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(Response.Status.NOT_FOUND
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND)
|
||||||
.getStatusCode()).setMessage(errorMessage).build());
|
.setMessage(errorMessage).build()).build();
|
||||||
} catch (FeatureManagementException e) {
|
} catch (FeatureManagementException e) {
|
||||||
String errorMessage = "Could not fetch effective policy for device " + deviceIdentifier.getId();
|
String errorMessage = "Could not fetch effective policy for device " + deviceIdentifier.getId();
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
throw new NotFoundException(
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(Response.Status.INTERNAL_SERVER_ERROR
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND)
|
||||||
.getStatusCode()).setMessage(errorMessage).build()); }
|
.setMessage(errorMessage).build()).build(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sentToDevice) {
|
if (sentToDevice) {
|
||||||
|
|||||||
@ -47,10 +47,7 @@ import org.wso2.carbon.device.mgt.mobile.android.common.Message;
|
|||||||
import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse;
|
import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse;
|
||||||
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.AndroidApplication;
|
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.AndroidApplication;
|
||||||
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.AndroidDevice;
|
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.AndroidDevice;
|
||||||
import org.wso2.carbon.device.mgt.mobile.android.common.exception.AndroidDeviceMgtPluginException;
|
import org.wso2.carbon.device.mgt.mobile.android.common.exception.*;
|
||||||
import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestException;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestExceptionDup;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.android.common.exception.UnexpectedServerErrorException;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService;
|
import org.wso2.carbon.device.mgt.mobile.android.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;
|
||||||
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils;
|
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils;
|
||||||
@ -95,8 +92,9 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI {
|
|||||||
} catch (ApplicationManagementException e) {
|
} catch (ApplicationManagementException e) {
|
||||||
String msg = "Error occurred while modifying the application list.";
|
String msg = "Error occurred while modifying the application list.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
||||||
|
.setMessage(msg).build()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,9 +122,15 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI {
|
|||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while getting pending operations of the device.";
|
String msg = "Error occurred while getting pending operations of the device.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
||||||
.setMessage(msg).build());
|
.setMessage(msg).build()).build();
|
||||||
|
} catch (AndroidDeviceMgtPluginException e) {
|
||||||
|
String errorMessage = "Error occured while executing get pending operations";
|
||||||
|
log.error(errorMessage, e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
||||||
|
.setMessage(errorMessage).build()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,8 +140,9 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI {
|
|||||||
if (androidDevice == null) {
|
if (androidDevice == null) {
|
||||||
String errorMessage = "The payload of the android device enrollment is incorrect.";
|
String errorMessage = "The payload of the android device enrollment is incorrect.";
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
throw new BadRequestException(
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST)
|
||||||
|
.setMessage(errorMessage).build()).build();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
AndroidService androidService = AndroidAPIUtils.getAndroidService();
|
AndroidService androidService = AndroidAPIUtils.getAndroidService();
|
||||||
@ -147,8 +152,15 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI {
|
|||||||
String msg = "Error occurred while enrolling the android, which carries the id '" +
|
String msg = "Error occurred while enrolling the android, which carries the id '" +
|
||||||
androidDevice.getDeviceIdentifier() + "'";
|
androidDevice.getDeviceIdentifier() + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
||||||
|
.setMessage(msg).build()).build();
|
||||||
|
} catch (AndroidDeviceMgtPluginException e) {
|
||||||
|
String errorMessage = "Error occured while enrolling device";
|
||||||
|
log.error(errorMessage, e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
||||||
|
.setMessage(errorMessage).build()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,9 +176,9 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI {
|
|||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while checking enrollment status of the device.";
|
String msg = "Error occurred while checking enrollment status of the device.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
||||||
.setMessage(msg).build());
|
.setMessage(msg).build()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,14 +205,21 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI {
|
|||||||
String msg = "Error occurred while modifying enrollment of the Android device that carries the id '" +
|
String msg = "Error occurred while modifying enrollment of the Android device that carries the id '" +
|
||||||
id + "'";
|
id + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
||||||
|
.setMessage(msg).build()).build();
|
||||||
} catch (BadRequestExceptionDup e){
|
} catch (BadRequestExceptionDup e){
|
||||||
String msg = "Invalid request";
|
String msg = "Invalid request";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(
|
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()).build();
|
.setMessage(msg).build()).build();
|
||||||
|
} catch (NotFoundExceptionDup e) {
|
||||||
|
String errorMessage = "Class not found";
|
||||||
|
log.error(errorMessage, e);
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND)
|
||||||
|
.setMessage(errorMessage).build()).build();
|
||||||
} catch (AndroidDeviceMgtPluginException e) {
|
} catch (AndroidDeviceMgtPluginException e) {
|
||||||
String errorMessage = "Error occured";
|
String errorMessage = "Error occured";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -232,8 +251,9 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI {
|
|||||||
String msg = "Error occurred while %s the Android device that carries the id '" + id + "'";
|
String msg = "Error occurred while %s the Android device that carries the id '" + id + "'";
|
||||||
msg = String.format(msg, "dis-enrolling");
|
msg = String.format(msg, "dis-enrolling");
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
||||||
|
.setMessage(msg).build()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -90,7 +90,6 @@ import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.WipeDataBea
|
|||||||
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.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.exception.UnexpectedServerErrorException;
|
|
||||||
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;
|
||||||
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils;
|
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils;
|
||||||
|
|||||||
@ -46,7 +46,6 @@ 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.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.exception.UnexpectedServerErrorException;
|
|
||||||
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;
|
||||||
|
|
||||||
@ -78,9 +77,9 @@ public class DeviceTypeConfigurationAPIImpl implements DeviceTypeConfigurationAP
|
|||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while retrieving the Android tenant configuration";
|
String msg = "Error occurred while retrieving the Android tenant configuration";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
||||||
.setMessage(msg).build());
|
.setMessage(msg).build()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,9 +101,9 @@ public class DeviceTypeConfigurationAPIImpl implements DeviceTypeConfigurationAP
|
|||||||
} 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);
|
||||||
throw new UnexpectedServerErrorException(
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
||||||
.setMessage(msg).build());
|
.setMessage(msg).build()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -122,9 +121,9 @@ public class DeviceTypeConfigurationAPIImpl implements DeviceTypeConfigurationAP
|
|||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while retrieving the license configured for Android device enrolment";
|
String msg = "Error occurred while retrieving the license configured for Android device enrolment";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
||||||
.setMessage(msg).build());
|
.setMessage(msg).build()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -110,15 +110,18 @@ public class EventReceiverAPIImpl implements EventReceiverAPI {
|
|||||||
log.warn("Error occurred while trying to publish the event. This could be due to unavailability " +
|
log.warn("Error occurred while trying to publish the event. This could be due to unavailability " +
|
||||||
"of the publishing service. Please make sure that analytics server is running and accessible " +
|
"of the publishing service. Please make sure that analytics server is running and accessible " +
|
||||||
"by this server");
|
"by this server");
|
||||||
throw new UnexpectedServerErrorException(
|
String msg = "Error occurred due to " +
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(503l).setMessage("Error occurred due to " +
|
"unavailability of the publishing service.";
|
||||||
"unavailability of the publishing service.").build());
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
||||||
|
.setMessage(msg).build()).build();
|
||||||
}
|
}
|
||||||
} catch (DataPublisherConfigurationException e) {
|
} catch (DataPublisherConfigurationException e) {
|
||||||
String msg = "Error occurred while getting the Data publisher Service instance.";
|
String msg = "Error occurred while getting the Data publisher Service instance.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
||||||
|
.setMessage(msg).build()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,6 +145,12 @@ public class EventReceiverAPIImpl implements EventReceiverAPI {
|
|||||||
return Response.status(Response.Status.BAD_REQUEST).entity(
|
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()).build();
|
.setMessage(msg).build()).build();
|
||||||
|
} catch (NotFoundExceptionDup e) {
|
||||||
|
String errorMessage = "Class not found";
|
||||||
|
log.error(errorMessage, e);
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND)
|
||||||
|
.setMessage(errorMessage).build()).build();
|
||||||
} catch (AndroidDeviceMgtPluginException e) {
|
} catch (AndroidDeviceMgtPluginException e) {
|
||||||
String errorMessage = "Error occured while retrieving alerts";
|
String errorMessage = "Error occured while retrieving alerts";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
|
|||||||
@ -0,0 +1,12 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.mobile.android.common.exception;
|
||||||
|
|
||||||
|
public class UnexpectedServerErrorExceptionDup extends AndroidDeviceMgtPluginException{
|
||||||
|
|
||||||
|
public UnexpectedServerErrorExceptionDup(String message, Throwable ex) {
|
||||||
|
super(message, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnexpectedServerErrorExceptionDup(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -418,7 +418,7 @@ public interface AndroidService {
|
|||||||
*/
|
*/
|
||||||
List<? extends Operation> getPendingOperations
|
List<? extends Operation> getPendingOperations
|
||||||
(String id, List<? extends Operation> resultOperations, boolean disableGoogleApps)
|
(String id, List<? extends Operation> resultOperations, boolean disableGoogleApps)
|
||||||
throws DeviceManagementException, InvalidDeviceException;
|
throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to enroll device
|
* Method to enroll device
|
||||||
@ -427,7 +427,7 @@ public interface AndroidService {
|
|||||||
* @return {@link Response}
|
* @return {@link Response}
|
||||||
* @throws {@link DeviceManagementException}
|
* @throws {@link DeviceManagementException}
|
||||||
*/
|
*/
|
||||||
Response enrollDevice(AndroidDevice androidDevice) throws DeviceManagementException;
|
Response enrollDevice(AndroidDevice androidDevice) throws DeviceManagementException, AndroidDeviceMgtPluginException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to check if a device is enrolled
|
* Method to check if a device is enrolled
|
||||||
|
|||||||
@ -274,8 +274,7 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
if (deviceLockBeanWrapper == null || deviceLockBeanWrapper.getOperation() == null) {
|
if (deviceLockBeanWrapper == null || deviceLockBeanWrapper.getOperation() == null) {
|
||||||
String errorMessage = "Lock bean is empty.";
|
String errorMessage = "Lock bean is empty.";
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
throw new BadRequestException(
|
throw new BadRequestExceptionDup(errorMessage);
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
DeviceLock lock = deviceLockBeanWrapper.getOperation();
|
DeviceLock lock = deviceLockBeanWrapper.getOperation();
|
||||||
ProfileOperation operation = new ProfileOperation();
|
ProfileOperation operation = new ProfileOperation();
|
||||||
@ -346,8 +345,7 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
if (cameraBeanWrapper == null || cameraBeanWrapper.getOperation() == null) {
|
if (cameraBeanWrapper == null || cameraBeanWrapper.getOperation() == null) {
|
||||||
String errorMessage = "The payload of the configure camera operation is incorrect.";
|
String errorMessage = "The payload of the configure camera operation is incorrect.";
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
throw new BadRequestException(
|
throw new BadRequestExceptionDup(errorMessage);
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
Camera camera = cameraBeanWrapper.getOperation();
|
Camera camera = cameraBeanWrapper.getOperation();
|
||||||
CommandOperation operation = new CommandOperation();
|
CommandOperation operation = new CommandOperation();
|
||||||
@ -850,17 +848,11 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
} catch (OperationManagementException e) {
|
} catch (OperationManagementException e) {
|
||||||
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 UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorExceptionDup(errorMessage);
|
||||||
new ErrorResponse.ErrorResponseBuilder()
|
|
||||||
.setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
|
||||||
.setMessage(errorMessage).build());
|
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException 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 UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorExceptionDup(errorMessage, e);
|
||||||
new ErrorResponse.ErrorResponseBuilder()
|
|
||||||
.setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
|
||||||
.setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -923,7 +915,8 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends Operation> getPendingOperations(String deviceId, List<? extends Operation> resultOperations,
|
public List<? extends Operation> getPendingOperations(String deviceId, List<? extends Operation> resultOperations,
|
||||||
boolean disableGoogleApps) throws DeviceManagementException, InvalidDeviceException {
|
boolean disableGoogleApps)
|
||||||
|
throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException {
|
||||||
DeviceIdentifier deviceIdentifier = AndroidDeviceUtils.convertToDeviceIdentifierObject(deviceId);
|
DeviceIdentifier deviceIdentifier = AndroidDeviceUtils.convertToDeviceIdentifierObject(deviceId);
|
||||||
if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) {
|
if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) {
|
||||||
String msg = "Device not found for identifier '" + deviceId + "'";
|
String msg = "Device not found for identifier '" + deviceId + "'";
|
||||||
@ -979,14 +972,13 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
} catch (OperationManagementException e) {
|
} catch (OperationManagementException e) {
|
||||||
String msg = "Issue in retrieving operation management service instance";
|
String msg = "Issue in retrieving operation management service instance";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorExceptionDup(msg, e);
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
|
|
||||||
.setMessage(msg).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response enrollDevice(AndroidDevice androidDevice) throws DeviceManagementException {
|
public Response enrollDevice(AndroidDevice androidDevice)
|
||||||
|
throws DeviceManagementException, AndroidDeviceMgtPluginException {
|
||||||
try {
|
try {
|
||||||
String token = null;
|
String token = null;
|
||||||
Device device = new Device();
|
Device device = new Device();
|
||||||
@ -1040,8 +1032,7 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
String msg = "Error occurred while updating the device location upon android " +
|
String msg = "Error occurred while updating the device location upon android " +
|
||||||
"', which carries the id '" + androidDevice.getDeviceIdentifier() + "'";
|
"', which carries the id '" + androidDevice.getDeviceIdentifier() + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorExceptionDup(msg, e);
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1096,27 +1087,12 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
androidDevice.getDeviceIdentifier() + "'");
|
androidDevice.getDeviceIdentifier() + "'");
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(responseMessage).build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(responseMessage).build();
|
||||||
}
|
}
|
||||||
} catch (PolicyManagementException e) {
|
} catch (PolicyManagementException | InvalidDeviceException | OperationManagementException e) {
|
||||||
String msg = "Error occurred while enforcing default enrollment policy upon android " +
|
String msg = "Error occurred while enforcing default enrollment policy upon android " +
|
||||||
"', which carries the id '" +
|
"', which carries the id '" +
|
||||||
androidDevice.getDeviceIdentifier() + "'";
|
androidDevice.getDeviceIdentifier() + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorExceptionDup(msg, e);
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
||||||
} catch (OperationManagementException e) {
|
|
||||||
String msg = "Error occurred while enforcing default enrollment policy upon android " +
|
|
||||||
"', which carries the id '" +
|
|
||||||
androidDevice.getDeviceIdentifier() + "'";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
||||||
} catch (InvalidDeviceException e) {
|
|
||||||
String msg = "Error occurred while enforcing default enrollment policy upon android " +
|
|
||||||
"', which carries the id '" +
|
|
||||||
androidDevice.getDeviceIdentifier() + "'";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1133,8 +1109,7 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
String msg = "Error occurred while getting enrollment details of the Android device that carries the id '" +
|
String msg = "Error occurred while getting enrollment details of the Android device that carries the id '" +
|
||||||
id + "'";
|
id + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorExceptionDup(msg, e);
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (androidDevice == null) {
|
if (androidDevice == null) {
|
||||||
@ -1145,8 +1120,7 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
if (device == null) {
|
if (device == null) {
|
||||||
String errorMessage = "The device to be modified doesn't exist.";
|
String errorMessage = "The device to be modified doesn't exist.";
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
throw new NotFoundException(
|
throw new NotFoundExceptionDup(errorMessage);
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
if(androidDevice.getEnrolmentInfo() != null){
|
if(androidDevice.getEnrolmentInfo() != null){
|
||||||
device.setEnrolmentInfo(device.getEnrolmentInfo());
|
device.setEnrolmentInfo(device.getEnrolmentInfo());
|
||||||
@ -1222,7 +1196,7 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response retrieveAlert(String deviceId) {
|
private Response retrieveAlert(String deviceId) throws NotFoundExceptionDup, UnexpectedServerErrorExceptionDup {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Retrieving events for given device Identifier.");
|
log.debug("Retrieving events for given device Identifier.");
|
||||||
}
|
}
|
||||||
@ -1231,21 +1205,20 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
try {
|
try {
|
||||||
deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
|
deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
|
||||||
if (deviceStates == null) {
|
if (deviceStates == null) {
|
||||||
throw new NotFoundException(
|
String errorMessage = "No any alerts are " +
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " +
|
"published for Device: " + deviceId + ".";
|
||||||
"published for Device: " + deviceId + ".").build());
|
throw new NotFoundExceptionDup(errorMessage);
|
||||||
} else {
|
} else {
|
||||||
return Response.status(Response.Status.OK).entity(deviceStates).build();
|
return Response.status(Response.Status.OK).entity(deviceStates).build();
|
||||||
}
|
}
|
||||||
} catch (AnalyticsException e) {
|
} catch (AnalyticsException e) {
|
||||||
String msg = "Error occurred while getting published events for specific device: " + deviceId + ".";
|
String msg = "Error occurred while getting published events for specific device: " + deviceId + ".";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorExceptionDup(msg, e);
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response retrieveAlertFromDate(String deviceId, long from, long to) {
|
private Response retrieveAlertFromDate(String deviceId, long from, long to) throws NotFoundExceptionDup, UnexpectedServerErrorExceptionDup {
|
||||||
String fromDate = String.valueOf(from);
|
String fromDate = String.valueOf(from);
|
||||||
String toDate = String.valueOf(to);
|
String toDate = String.valueOf(to);
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
@ -1257,9 +1230,9 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
try {
|
try {
|
||||||
deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
|
deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
|
||||||
if (deviceStates == null) {
|
if (deviceStates == null) {
|
||||||
throw new NotFoundException(
|
String errorMessage = "No any alerts are " +
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " +
|
"published on given date for given Device: " + deviceId + ".";
|
||||||
"published on given date for given Device: " + deviceId + ".").build());
|
throw new NotFoundExceptionDup(errorMessage);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return Response.status(Response.Status.OK).entity(deviceStates).build();
|
return Response.status(Response.Status.OK).entity(deviceStates).build();
|
||||||
@ -1268,12 +1241,11 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
String msg = "Error occurred while getting published events for specific " +
|
String msg = "Error occurred while getting published events for specific " +
|
||||||
"Device: " + deviceId + " on given Date.";
|
"Device: " + deviceId + " on given Date.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorExceptionDup(msg, e);
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response retrieveAlertByType(String deviceId, String type) {
|
private Response retrieveAlertByType(String deviceId, String type) throws NotFoundExceptionDup, UnexpectedServerErrorExceptionDup {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Retrieving events for given device identifier and type.");
|
log.debug("Retrieving events for given device identifier and type.");
|
||||||
}
|
}
|
||||||
@ -1282,9 +1254,9 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
try {
|
try {
|
||||||
deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
|
deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
|
||||||
if (deviceStates == null) {
|
if (deviceStates == null) {
|
||||||
throw new NotFoundException(
|
String errorMessage = "No any alerts are " +
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " +
|
"published for given Device: '" + deviceId + "' and given specific Type.";
|
||||||
"published for given Device: '" + deviceId + "' and given specific Type.").build());
|
throw new NotFoundExceptionDup(errorMessage);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return Response.status(Response.Status.OK).entity(deviceStates).build();
|
return Response.status(Response.Status.OK).entity(deviceStates).build();
|
||||||
@ -1293,8 +1265,7 @@ public class AndroidServiceImpl implements AndroidService {
|
|||||||
String msg = "Error occurred while getting published events for specific " +
|
String msg = "Error occurred while getting published events for specific " +
|
||||||
"Device: " + deviceId + "and given specific Type.";
|
"Device: " + deviceId + "and given specific Type.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorExceptionDup(msg, e);
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user