fixing error messages not thrown properly.

revert-dabc3590
inoshperera 9 years ago
parent 90747a5579
commit c45400afd0

@ -18,6 +18,7 @@
package org.wso2.carbon.mdm.services.android.exception; package org.wso2.carbon.mdm.services.android.exception;
import org.wso2.carbon.mdm.services.android.bean.ErrorResponse;
import org.wso2.carbon.mdm.services.android.util.Message; import org.wso2.carbon.mdm.services.android.util.Message;
import javax.ws.rs.WebApplicationException; import javax.ws.rs.WebApplicationException;
@ -29,13 +30,8 @@ import javax.ws.rs.core.Response;
*/ */
public class BadRequestException extends WebApplicationException { public class BadRequestException extends WebApplicationException {
public BadRequestException(Message message, MediaType mediaType) { public BadRequestException(ErrorResponse error) {
super(Response.status(Response.Status.BAD_REQUEST).entity(message). super(Response.status(Response.Status.BAD_REQUEST).entity(error).build());
type(mediaType).build());
}
public BadRequestException(Message message) {
super(Response.status(Response.Status.BAD_REQUEST).entity(message).build());
} }
} }

@ -0,0 +1,33 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.mdm.services.android.exception;
import org.wso2.carbon.mdm.services.android.bean.ErrorResponse;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
public class NotFoundException extends WebApplicationException {
private static final long serialVersionUID = 147943572342342340L;
public NotFoundException(ErrorResponse error) {
super(Response.status(Response.Status.NOT_FOUND).entity(error).build());
}
}

@ -27,6 +27,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.mdm.services.android.bean.*; import org.wso2.carbon.mdm.services.android.bean.*;
import org.wso2.carbon.mdm.services.android.bean.wrapper.*; import org.wso2.carbon.mdm.services.android.bean.wrapper.*;
import org.wso2.carbon.mdm.services.android.exception.BadRequestException;
import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException;
import org.wso2.carbon.mdm.services.android.services.DeviceManagementAdminService; import org.wso2.carbon.mdm.services.android.services.DeviceManagementAdminService;
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
@ -59,7 +60,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
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);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
DeviceLock lock = deviceLockBeanWrapper.getOperation(); DeviceLock lock = deviceLockBeanWrapper.getOperation();
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
@ -172,7 +174,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
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);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
Camera camera = cameraBeanWrapper.getOperation(); Camera camera = cameraBeanWrapper.getOperation();
CommandOperation operation = new CommandOperation(); CommandOperation operation = new CommandOperation();
@ -256,7 +259,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
if (wipeDataBeanWrapper == null || wipeDataBeanWrapper.getOperation() == null) { if (wipeDataBeanWrapper == null || wipeDataBeanWrapper.getOperation() == null) {
String errorMessage = "WipeData bean is empty."; String errorMessage = "WipeData bean is empty.";
log.error(errorMessage); log.error(errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
WipeData wipeData = wipeDataBeanWrapper.getOperation(); WipeData wipeData = wipeDataBeanWrapper.getOperation();
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
@ -395,7 +399,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
null) { null) {
String errorMessage = "The payload of the application installing operation is incorrect"; String errorMessage = "The payload of the application installing operation is incorrect";
log.error(errorMessage); log.error(errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
ApplicationInstallation applicationInstallation = applicationInstallationBeanWrapper.getOperation(); ApplicationInstallation applicationInstallation = applicationInstallationBeanWrapper.getOperation();
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
@ -429,7 +434,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
if (applicationUpdateBeanWrapper == null || applicationUpdateBeanWrapper.getOperation() == null) { if (applicationUpdateBeanWrapper == null || applicationUpdateBeanWrapper.getOperation() == null) {
String errorMessage = "The payload of the application update operation is incorrect"; String errorMessage = "The payload of the application update operation is incorrect";
log.error(errorMessage); log.error(errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
ApplicationUpdate applicationUpdate = applicationUpdateBeanWrapper.getOperation(); ApplicationUpdate applicationUpdate = applicationUpdateBeanWrapper.getOperation();
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
@ -465,7 +471,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
applicationUninstallationBeanWrapper.getOperation() == null) { applicationUninstallationBeanWrapper.getOperation() == null) {
String errorMessage = "The payload of the application uninstalling operation is incorrect"; String errorMessage = "The payload of the application uninstalling operation is incorrect";
log.error(errorMessage); log.error(errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
ApplicationUninstallation applicationUninstallation = applicationUninstallationBeanWrapper.getOperation(); ApplicationUninstallation applicationUninstallation = applicationUninstallationBeanWrapper.getOperation();
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
@ -500,14 +507,14 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
if (blacklistApplicationsBeanWrapper == null || blacklistApplicationsBeanWrapper.getOperation() == null) { if (blacklistApplicationsBeanWrapper == null || blacklistApplicationsBeanWrapper.getOperation() == null) {
String errorMessage = "The payload of the blacklisting apps operation is incorrect"; String errorMessage = "The payload of the blacklisting apps operation is incorrect";
log.error(errorMessage); log.error(errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
BlacklistApplications blacklistApplications = blacklistApplicationsBeanWrapper.getOperation(); BlacklistApplications blacklistApplications = blacklistApplicationsBeanWrapper.getOperation();
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
operation.setCode(AndroidConstants.OperationCodes.BLACKLIST_APPLICATIONS); operation.setCode(AndroidConstants.OperationCodes.BLACKLIST_APPLICATIONS);
operation.setType(Operation.Type.PROFILE); operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(blacklistApplications.toJSON()); operation.setPayLoad(blacklistApplications.toJSON());
return AndroidAPIUtils.getOperationResponse(blacklistApplicationsBeanWrapper.getDeviceIDs(), return AndroidAPIUtils.getOperationResponse(blacklistApplicationsBeanWrapper.getDeviceIDs(),
operation); operation);
@ -536,7 +543,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
if (upgradeFirmwareBeanWrapper == null || upgradeFirmwareBeanWrapper.getOperation() == null) { if (upgradeFirmwareBeanWrapper == null || upgradeFirmwareBeanWrapper.getOperation() == null) {
String errorMessage = "The payload of the upgrade firmware operation is incorrect"; String errorMessage = "The payload of the upgrade firmware operation is incorrect";
log.error(errorMessage); log.error(errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
UpgradeFirmware upgradeFirmware = upgradeFirmwareBeanWrapper.getOperation(); UpgradeFirmware upgradeFirmware = upgradeFirmwareBeanWrapper.getOperation();
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
@ -569,7 +577,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
if (vpnBeanWrapper == null || vpnBeanWrapper.getOperation() == null) { if (vpnBeanWrapper == null || vpnBeanWrapper.getOperation() == null) {
String errorMessage = "The payload of the VPN operation is incorrect"; String errorMessage = "The payload of the VPN operation is incorrect";
log.error(errorMessage); log.error(errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
Vpn vpn = vpnBeanWrapper.getOperation(); Vpn vpn = vpnBeanWrapper.getOperation();
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
@ -603,7 +612,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
if (notificationBeanWrapper == null || notificationBeanWrapper.getOperation() == null) { if (notificationBeanWrapper == null || notificationBeanWrapper.getOperation() == null) {
String errorMessage = "The payload of the notification operation is incorrect"; String errorMessage = "The payload of the notification operation is incorrect";
log.error(errorMessage); log.error(errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
Notification notification = notificationBeanWrapper.getOperation(); Notification notification = notificationBeanWrapper.getOperation();
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
@ -638,7 +648,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
if (wifiBeanWrapper == null || wifiBeanWrapper.getOperation() == null) { if (wifiBeanWrapper == null || wifiBeanWrapper.getOperation() == null) {
String errorMessage = "The payload of the wifi operation is incorrect"; String errorMessage = "The payload of the wifi operation is incorrect";
log.error(errorMessage); log.error(errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
Wifi wifi = wifiBeanWrapper.getOperation(); Wifi wifi = wifiBeanWrapper.getOperation();
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
@ -674,7 +685,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
if (encryptionBeanWrapper == null || encryptionBeanWrapper.getOperation() == null) { if (encryptionBeanWrapper == null || encryptionBeanWrapper.getOperation() == null) {
String errorMessage = "The payload of the device encryption operation is incorrect"; String errorMessage = "The payload of the device encryption operation is incorrect";
log.error(errorMessage); log.error(errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
DeviceEncryption deviceEncryption = encryptionBeanWrapper.getOperation(); DeviceEncryption deviceEncryption = encryptionBeanWrapper.getOperation();
CommandOperation operation = new CommandOperation(); CommandOperation operation = new CommandOperation();
@ -709,7 +721,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
if (lockCodeBeanWrapper == null || lockCodeBeanWrapper.getOperation() == null) { if (lockCodeBeanWrapper == null || lockCodeBeanWrapper.getOperation() == null) {
String errorMessage = "The payload of the change lock code operation is incorrect"; String errorMessage = "The payload of the change lock code operation is incorrect";
log.error(errorMessage); log.error(errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
LockCode lockCode = lockCodeBeanWrapper.getOperation(); LockCode lockCode = lockCodeBeanWrapper.getOperation();
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
@ -744,7 +757,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
if (passwordPolicyBeanWrapper == null || passwordPolicyBeanWrapper.getOperation() == null) { if (passwordPolicyBeanWrapper == null || passwordPolicyBeanWrapper.getOperation() == null) {
String errorMessage = "The payload of the change password policy operation is incorrect"; String errorMessage = "The payload of the change password policy operation is incorrect";
log.error(errorMessage); log.error(errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
PasscodePolicy passcodePolicy = passwordPolicyBeanWrapper.getOperation(); PasscodePolicy passcodePolicy = passwordPolicyBeanWrapper.getOperation();
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
@ -782,7 +796,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
if (webClipBeanWrapper == null || webClipBeanWrapper.getOperation() == null) { if (webClipBeanWrapper == null || webClipBeanWrapper.getOperation() == null) {
String errorMessage = "The payload of the add webclip operation is incorrect"; String errorMessage = "The payload of the add webclip operation is incorrect";
log.error(errorMessage); log.error(errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
WebClip webClip = webClipBeanWrapper.getOperation(); WebClip webClip = webClipBeanWrapper.getOperation();
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();

@ -25,6 +25,8 @@ import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublish
import org.wso2.carbon.mdm.services.android.bean.DeviceState; import org.wso2.carbon.mdm.services.android.bean.DeviceState;
import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; import org.wso2.carbon.mdm.services.android.bean.ErrorResponse;
import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper;
import org.wso2.carbon.mdm.services.android.exception.BadRequestException;
import org.wso2.carbon.mdm.services.android.exception.NotFoundException;
import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException;
import org.wso2.carbon.mdm.services.android.services.EventReceiverService; import org.wso2.carbon.mdm.services.android.services.EventReceiverService;
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
@ -57,9 +59,9 @@ public class EventReceiverServiceImpl implements EventReceiverService {
message.setResponseCode("Event is published successfully."); message.setResponseCode("Event is published successfully.");
return Response.status(Response.Status.CREATED).entity(message).build(); return Response.status(Response.Status.CREATED).entity(message).build();
} else { } else {
message.setResponseCode("Error occurred while publishing the event."); throw new UnexpectedServerErrorException(
return Response.status(Response.Status.INTERNAL_SERVER_ERROR). new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage("Error occurred while " +
entity(message).build(); "publishing the event.").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.";
@ -82,8 +84,10 @@ public class EventReceiverServiceImpl implements EventReceiverService {
} else if (deviceId != null) { } else if (deviceId != null) {
return retrieveAlert(deviceId); return retrieveAlert(deviceId);
} else { } else {
return Response.status(Response.Status.BAD_REQUEST).entity("Request must contain the device identifier. " + throw new BadRequestException(
"Optionally, both from and to value should be present to get alerts between times.").build(); new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request must contain " +
"the device identifier. Optionally, both from and to value should be present to get " +
"alerts between times.").build());
} }
} }
@ -91,14 +95,14 @@ public class EventReceiverServiceImpl implements EventReceiverService {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Retrieving events for given device Identifier."); log.debug("Retrieving events for given device Identifier.");
} }
Message message = new Message();
String query = "deviceIdentifier:" + deviceId; String query = "deviceIdentifier:" + deviceId;
List<DeviceState> deviceStates; List<DeviceState> deviceStates;
try { try {
deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
if (deviceStates == null) { if (deviceStates == null) {
message.setResponseCode("No any alerts are published for Device: " + deviceId + "."); throw new NotFoundException(
return Response.status(Response.Status.NOT_FOUND).entity(message).build(); new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " +
"published for Device: " + deviceId + ".").build());
} else { } else {
return Response.status(Response.Status.OK).entity(deviceStates).build(); return Response.status(Response.Status.OK).entity(deviceStates).build();
} }
@ -116,16 +120,15 @@ public class EventReceiverServiceImpl implements EventReceiverService {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Retrieving events for given device Identifier and time period."); log.debug("Retrieving events for given device Identifier and time period.");
} }
Message message = new Message();
String query = "deviceIdentifier:" + deviceId + " AND _timestamp: [" + fromDate + " TO " + toDate + "]"; String query = "deviceIdentifier:" + deviceId + " AND _timestamp: [" + fromDate + " TO " + toDate + "]";
List<DeviceState> deviceStates; List<DeviceState> deviceStates;
try { try {
deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
if (deviceStates == null) { if (deviceStates == null) {
message. throw new NotFoundException(
setResponseCode("No any alerts are published on given date for given Device: " + deviceId + "."); new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " +
return Response.status(Response.Status.NOT_FOUND).entity(message).build(); "published on given date for given Device: " + deviceId + ".").build());
} else { } else {
return Response.status(Response.Status.OK).entity(deviceStates).build(); return Response.status(Response.Status.OK).entity(deviceStates).build();
@ -143,15 +146,14 @@ public class EventReceiverServiceImpl implements EventReceiverService {
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.");
} }
Message message = new Message();
String query = "deviceIdentifier:" + deviceId + " AND type:" + type; String query = "deviceIdentifier:" + deviceId + " AND type:" + type;
List<DeviceState> deviceStates; List<DeviceState> deviceStates;
try { try {
deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
if (deviceStates == null) { if (deviceStates == null) {
message.setResponseCode("No any alerts are published for given Device: " + throw new NotFoundException(
"" + deviceId + "and given specific Type."); new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " +
return Response.status(Response.Status.NOT_FOUND).entity(message).build(); "published for given Device: '" + deviceId + "' and given specific Type.").build());
} else { } else {
return Response.status(Response.Status.OK).entity(deviceStates).build(); return Response.status(Response.Status.OK).entity(deviceStates).build();

@ -48,6 +48,8 @@ import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManag
import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils; import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.mdm.services.android.bean.DeviceState; import org.wso2.carbon.mdm.services.android.bean.DeviceState;
import org.wso2.carbon.mdm.services.android.bean.ErrorResponse;
import org.wso2.carbon.mdm.services.android.exception.BadRequestException;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
@ -120,7 +122,8 @@ public class AndroidAPIUtils {
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);
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} }
AndroidDeviceUtils deviceUtils = new AndroidDeviceUtils(); AndroidDeviceUtils deviceUtils = new AndroidDeviceUtils();
DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs); DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs);
@ -140,8 +143,9 @@ public class AndroidAPIUtils {
// } // }
// } // }
if (!deviceIDHolder.getErrorDeviceIdList().isEmpty()) { if (!deviceIDHolder.getErrorDeviceIdList().isEmpty()) {
return javax.ws.rs.core.Response.status(Response.Status.BAD_REQUEST).entity(deviceUtils. throw new BadRequestException(
convertErrorMapIntoErrorMessage(deviceIDHolder.getErrorDeviceIdList())).build(); new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(deviceUtils.
convertErrorMapIntoErrorMessage(deviceIDHolder.getErrorDeviceIdList())).build());
} }
return Response.status(Response.Status.CREATED).entity(activity).build(); return Response.status(Response.Status.CREATED).entity(activity).build();
} }

Loading…
Cancel
Save