Adding more improvements to the JAX-RS APIs of CDM-F

revert-70aa11f8
prabathabey 8 years ago
parent fd7a137b07
commit 5ed982beb4

@ -22,6 +22,7 @@ import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission; import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@ -45,7 +46,6 @@ public interface ConfigurationManagementService {
httpMethod = "GET", httpMethod = "GET",
value = "Get the general platform configurations.", value = "Get the general platform configurations.",
notes = "Get the general platform level configuration details.", notes = "Get the general platform level configuration details.",
response = PlatformConfiguration.class,
tags = "Configuration Management") tags = "Configuration Management")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
@ -74,7 +74,9 @@ public interface ConfigurationManagementService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the general platform configuration.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching the general " +
"platform configuration.",
response = ErrorResponse.class)
}) })
@Permission(scope = "configuration-view", @Permission(scope = "configuration-view",
permissions = {"/permission/admin/device-mgt/admin/platform-configs/view"}) permissions = {"/permission/admin/device-mgt/admin/platform-configs/view"})
@ -115,16 +117,14 @@ public interface ConfigurationManagementService {
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error."), message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@ApiResponse( @ApiResponse(
code = 415, code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while modifying general platform configuration.") "Server error occurred while modifying general platform configuration.",
response = ErrorResponse.class)
}) })
@Permission(scope = "configuration-modify", @Permission(scope = "configuration-modify",
permissions = {"/permission/admin/device-mgt/admin/platform-configs/modify"}) permissions = {"/permission/admin/device-mgt/admin/platform-configs/modify"})

@ -30,12 +30,12 @@ import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Policy;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@ -138,7 +138,6 @@ public interface DeviceManagementService {
value = "Retrieve devices information from the supplied device identifier.", value = "Retrieve devices information from the supplied device identifier.",
notes = "This will return device information such as CPU usage, memory usage etc for supplied device " + notes = "This will return device information such as CPU usage, memory usage etc for supplied device " +
"identifier.", "identifier.",
response = DeviceInfo.class,
tags = "Device Management") tags = "Device Management")
@ApiResponses( @ApiResponses(
value = { value = {
@ -172,13 +171,17 @@ public interface DeviceManagementService {
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error."), message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n No device is found under the provided type and id."),
@ApiResponse( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable. \n The requested media type is not supported."), message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while retrieving information of the list of the devices submitted.") "Server error occurred while retrieving information of the list of the devices submitted.",
response = ErrorResponse.class)
}) })
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDeviceInfo( Response getDeviceInfo(
@ -270,7 +273,6 @@ public interface DeviceManagementService {
httpMethod = "GET", httpMethod = "GET",
value = "Get information of the requested device.", value = "Get information of the requested device.",
notes = "Returns information of the requested device.", notes = "Returns information of the requested device.",
response = Device.class,
tags = "Device Management") tags = "Device Management")
@ApiResponses( @ApiResponses(
value = { value = {
@ -301,7 +303,8 @@ public interface DeviceManagementService {
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while retrieving information requested device.") "Server error occurred while retrieving information requested device.",
response = ErrorResponse.class)
}) })
@Permission(scope = "device-view", permissions = { @Permission(scope = "device-view", permissions = {
"/permission/admin/device-mgt/admin/devices/view", "/permission/admin/device-mgt/admin/devices/view",
@ -332,7 +335,6 @@ public interface DeviceManagementService {
value = "Get the device location of a given device and a device type.", value = "Get the device location of a given device and a device type.",
notes = "This will return the device location including latitude and longitude as well the " notes = "This will return the device location including latitude and longitude as well the "
+ "physical address.", + "physical address.",
response = DeviceLocation.class,
tags = "Device Management") tags = "Device Management")
@ApiResponses( @ApiResponses(
value = { value = {
@ -346,10 +348,11 @@ public interface DeviceManagementService {
"Empty body because the client already has the latest version of the requested resource."), "Empty body because the client already has the latest version of the requested resource."),
@ApiResponse( @ApiResponse(
code = 404, code = 404,
message = "Location details are not available for the given device."), message = "Not Found. \n No device is found under the provided type and id."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "ErrorResponse occurred while getting the device location.") message = "ErrorResponse occurred while getting the device location.",
response = ErrorResponse.class)
}) })
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDeviceLocation( Response getDeviceLocation(
@ -379,8 +382,6 @@ public interface DeviceManagementService {
value = "Get the device location of a given devices and a device type.", value = "Get the device location of a given devices and a device type.",
notes = "This will return the device locations including latitude and longitude as well the " notes = "This will return the device locations including latitude and longitude as well the "
+ "physical address of the given devices.", + "physical address of the given devices.",
response = DeviceLocation.class,
responseContainer = "List",
tags = "Device Management") tags = "Device Management")
@ApiResponses( @ApiResponses(
value = { value = {
@ -398,7 +399,8 @@ public interface DeviceManagementService {
message = "Location details are not available for the given devices."), message = "Location details are not available for the given devices."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "ErrorResponse occurred while getting the device location.") message = "ErrorResponse occurred while getting the device location.",
response = ErrorResponse.class)
}) })
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDeviceLocations( Response getDeviceLocations(
@ -422,8 +424,6 @@ public interface DeviceManagementService {
notes = "WSO2 EMM features enable you to carry out many operations on a given device platform. " + notes = "WSO2 EMM features enable you to carry out many operations on a given device platform. " +
"Using this REST API you can get the features that can be carried out on a preferred device type," + "Using this REST API you can get the features that can be carried out on a preferred device type," +
" such as iOS, Android or Windows.", " such as iOS, Android or Windows.",
response = Feature.class,
responseContainer = "List",
tags = "Device Management") tags = "Device Management")
@ApiResponses( @ApiResponses(
value = { value = {
@ -458,7 +458,8 @@ public interface DeviceManagementService {
"Empty body because the client already has the latest version of the requested resource."), "Empty body because the client already has the latest version of the requested resource."),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error."), message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 404, code = 404,
message = "Not Found. \n Device of which the feature list is requested, is not found."), message = "Not Found. \n Device of which the feature list is requested, is not found."),
@ -468,7 +469,8 @@ public interface DeviceManagementService {
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while retrieving feature list of the device.") "Server error occurred while retrieving feature list of the device.",
response = ErrorResponse.class)
}) })
@Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/view", @Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/view",
"/permission/admin/device-mgt/user/devices/view"}) "/permission/admin/device-mgt/user/devices/view"})
@ -497,8 +499,6 @@ public interface DeviceManagementService {
httpMethod = "POST", httpMethod = "POST",
value = "Advanced search for devices.", value = "Advanced search for devices.",
notes = "Carry out an advanced search of devices.", notes = "Carry out an advanced search of devices.",
response = DeviceWrapper.class,
responseContainer = "List",
tags = "Device Management") tags = "Device Management")
@ApiResponses( @ApiResponses(
value = { value = {
@ -526,7 +526,8 @@ public interface DeviceManagementService {
"Empty body because the client already has the latest version of the requested resource."), "Empty body because the client already has the latest version of the requested resource."),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error."), message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ -536,7 +537,8 @@ public interface DeviceManagementService {
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while enrolling the device.") "Server error occurred while enrolling the device.",
response = ErrorResponse.class)
}) })
@Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response searchDevices( Response searchDevices(
@ -562,9 +564,7 @@ public interface DeviceManagementService {
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting installed application details of a device.", value = "Getting installed application details of a device.",
responseContainer = "List",
notes = "Get the list of applications that a device has subscribed.", notes = "Get the list of applications that a device has subscribed.",
response = Application.class,
tags = "Device Management") tags = "Device Management")
@ApiResponses( @ApiResponses(
value = { value = {
@ -599,7 +599,8 @@ public interface DeviceManagementService {
"Empty body because the client already has the latest version of the requested resource."), "Empty body because the client already has the latest version of the requested resource."),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error."), message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 404, code = 404,
message = "Not Found. \n Device of which the application list is requested, is not found."), message = "Not Found. \n Device of which the application list is requested, is not found."),
@ -609,7 +610,8 @@ public interface DeviceManagementService {
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while retrieving installed application list of the device.") "Server error occurred while retrieving installed application list of the device.",
response = ErrorResponse.class)
}) })
@Permission(scope = "operation-view", permissions = { @Permission(scope = "operation-view", permissions = {
"/permission/admin/device-mgt/admin/devices/view", "/permission/admin/device-mgt/admin/devices/view",
@ -651,8 +653,6 @@ public interface DeviceManagementService {
notes = "You will carry out many operations on a device. In a situation where you wish to view the all" + notes = "You will carry out many operations on a device. In a situation where you wish to view the all" +
" the operations carried out on a device it is not feasible to show all the details on one page" + " the operations carried out on a device it is not feasible to show all the details on one page" +
" therefore the details are paginated.", " therefore the details are paginated.",
response = Operation.class,
responseContainer = "List",
tags = "Device Management") tags = "Device Management")
@ApiResponses( @ApiResponses(
value = { value = {
@ -687,7 +687,8 @@ public interface DeviceManagementService {
"Empty body because the client already has the latest version of the requested resource."), "Empty body because the client already has the latest version of the requested resource."),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error."), message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 404, code = 404,
message = "Not Found. \n Device of which the operation list is requested, is not found."), message = "Not Found. \n Device of which the operation list is requested, is not found."),
@ -697,7 +698,8 @@ public interface DeviceManagementService {
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while retrieving operation list scheduled for the device.") "Server error occurred while retrieving operation list scheduled for the device.",
response = ErrorResponse.class)
}) })
@Permission(scope = "operation-view", permissions = { @Permission(scope = "operation-view", permissions = {
"/permission/admin/device-mgt/admin/devices/view", "/permission/admin/device-mgt/admin/devices/view",
@ -739,7 +741,6 @@ public interface DeviceManagementService {
notes = "When a device registers with WSO2 EMM a policy is enforced on the device. Initially the EMM " + notes = "When a device registers with WSO2 EMM a policy is enforced on the device. Initially the EMM " +
"filters the policies based on the Platform (device type), filters based on the device ownership" + "filters the policies based on the Platform (device type), filters based on the device ownership" +
" type , filters based on the user role or name and finally the policy is enforced on the device.", " type , filters based on the user role or name and finally the policy is enforced on the device.",
response = Policy.class,
tags = "Device Management") tags = "Device Management")
@ApiResponses( @ApiResponses(
value = { value = {
@ -773,7 +774,8 @@ public interface DeviceManagementService {
"Empty body because the client already has the latest version of the requested resource."), "Empty body because the client already has the latest version of the requested resource."),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error."), message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 404, code = 404,
message = "Not Found. \n Device of which the effective policy is requested, is not found."), message = "Not Found. \n Device of which the effective policy is requested, is not found."),
@ -783,7 +785,8 @@ public interface DeviceManagementService {
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server ErrorResponse. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while retrieving the effective policy calculated for the device.") "Server error occurred while retrieving the effective policy calculated for the device.",
response = ErrorResponse.class)
}) })
Response getEffectivePolicyOfDevice( Response getEffectivePolicyOfDevice(
@ApiParam( @ApiParam(

@ -23,7 +23,9 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.ConfigurationManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.ConfigurationManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.util.MDMAppConstants; import org.wso2.carbon.device.mgt.jaxrs.util.MDMAppConstants;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
@ -63,7 +65,8 @@ public class ConfigurationServiceImpl implements ConfigurationManagementService
} catch (ConfigurationManagementException | PolicyManagementException e) { } catch (ConfigurationManagementException | PolicyManagementException e) {
msg = "ErrorResponse occurred while retrieving the configurations."; msg = "ErrorResponse occurred while retrieving the configurations.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} }
} }
@ -80,7 +83,8 @@ public class ConfigurationServiceImpl implements ConfigurationManagementService
} catch (ConfigurationManagementException e) { } catch (ConfigurationManagementException e) {
String msg = "ErrorResponse occurred while updating the configuration."; String msg = "ErrorResponse occurred while updating the configuration.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} }
} }

@ -36,8 +36,10 @@ import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException; import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
@ -98,7 +100,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred while fetching all enrolled devices"; String msg = "Error occurred while fetching all enrolled devices";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} }
} }
@ -116,10 +119,15 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
deviceIdentifier.setType(type); deviceIdentifier.setType(type);
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService(); informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceInfo = informationManager.getDeviceInfo(deviceIdentifier); deviceInfo = informationManager.getDeviceInfo(deviceIdentifier);
if (deviceInfo == null) {
return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is " +
"found upon the give type '" + type + "' and id '" + id + "'").build();
}
} catch (DeviceDetailsMgtException e) { } catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device information."; String msg = "Error occurred while getting the device information.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} }
return Response.status(Response.Status.OK).entity(deviceInfo).build(); return Response.status(Response.Status.OK).entity(deviceInfo).build();
} }
@ -162,7 +170,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred while fetching the device information."; String msg = "Error occurred while fetching the device information.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} }
if (device == null) { if (device == null) {
return Response.status(Response.Status.NOT_FOUND).entity("Requested device of type '" + type + return Response.status(Response.Status.NOT_FOUND).entity("Requested device of type '" + type +
@ -194,7 +203,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
String msg = "Error occurred while getting the last updated location of the '" + type + "' device, " + String msg = "Error occurred while getting the last updated location of the '" + type + "' device, " +
"which carries the id '" + id + "'"; "which carries the id '" + id + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} }
return Response.status(Response.Status.OK).entity(deviceLocation).build(); return Response.status(Response.Status.OK).entity(deviceLocation).build();
} }
@ -211,7 +221,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
} catch (DeviceDetailsMgtException e) { } catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device location."; String msg = "Error occurred while getting the device location.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} }
return Response.status(Response.Status.OK).entity(deviceLocations).build(); return Response.status(Response.Status.OK).entity(deviceLocations).build();
} }
@ -229,16 +240,18 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
RequestValidationUtil.validateDeviceIdentifier(type, id); RequestValidationUtil.validateDeviceIdentifier(type, id);
dms = DeviceMgtAPIUtils.getDeviceManagementService(); dms = DeviceMgtAPIUtils.getDeviceManagementService();
features = dms.getFeatureManager(type).getFeatures(); FeatureManager fm = dms.getFeatureManager(type);
if (fm == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No feature manager is registered with " +
"the given type '" + type + "'").build();
}
features = fm.getFeatures();
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred while retrieving the list of features of '" + type + "' device, which " + String msg = "Error occurred while retrieving the list of features of '" + type + "' device, which " +
"carries the id '" + id + "'"; "carries the id '" + id + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); throw new UnexpectedServerErrorException(
} new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
if (features == null) {
return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " +
"the provided type and id").build();
} }
return Response.status(Response.Status.OK).entity(features).build(); return Response.status(Response.Status.OK).entity(features).build();
} }
@ -256,7 +269,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
} catch (SearchMgtException e) { } catch (SearchMgtException e) {
String msg = "Error occurred while searching for devices that matches the provided selection criteria"; String msg = "Error occurred while searching for devices that matches the provided selection criteria";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} }
if (devices == null) { if (devices == null) {
return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " + return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " +
@ -283,13 +297,14 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
applications = amc.getApplicationListForDevice(new DeviceIdentifier(id, type)); applications = amc.getApplicationListForDevice(new DeviceIdentifier(id, type));
if (applications == null) { if (applications == null) {
return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon" + return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon" +
"the provided type and id").build(); " the provided type and id").build();
} }
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while fetching the apps of the '" + type + "' device, which carries " + String msg = "Error occurred while fetching the apps of the '" + type + "' device, which carries " +
"the id '" + id + "'"; "the id '" + id + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} }
return Response.status(Response.Status.OK).entity(applications).build(); return Response.status(Response.Status.OK).entity(applications).build();
} }
@ -318,7 +333,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
String msg = "Error occurred while fetching the operations for the '" + type + "' device, which " + String msg = "Error occurred while fetching the operations for the '" + type + "' device, which " +
"carries the id '" + id + "'"; "carries the id '" + id + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} }
return Response.status(Response.Status.OK).entity(operations).build(); return Response.status(Response.Status.OK).entity(operations).build();
} }
@ -343,7 +359,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
String msg = "Error occurred while retrieving the current policy associated with the '" + type + String msg = "Error occurred while retrieving the current policy associated with the '" + type +
"' device, which carries the id '" + id + "'"; "' device, which carries the id '" + id + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} }
} }

@ -71,7 +71,7 @@ public class DeviceMgtAPIUtils {
"frequency.").build() "frequency.").build()
); );
} }
return Integer.parseInt(entry.getValue().toString()); return (int) (Double.parseDouble(entry.getValue().toString()) + 0.5d);
} }
} }
} }

@ -42,5 +42,4 @@ public class IllegalTransactionStateException extends RuntimeException {
super(cause); super(cause);
} }
} }

@ -0,0 +1,45 @@
/*
* 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.device.mgt.common;
public class UnauthorizedDeviceAccessException extends RuntimeException {
private static final long serialVersionUID = -3151289331929070297L;
public UnauthorizedDeviceAccessException(String msg, Exception nestedEx) {
super(msg, nestedEx);
}
public UnauthorizedDeviceAccessException(String message, Throwable cause) {
super(message, cause);
}
public UnauthorizedDeviceAccessException(String msg) {
super(msg);
}
public UnauthorizedDeviceAccessException() {
super();
}
public UnauthorizedDeviceAccessException(Throwable cause) {
super(cause);
}
}

@ -264,6 +264,13 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
device = deviceDAO.getDevice(deviceId, tenantId); device = deviceDAO.getDevice(deviceId, tenantId);
if (device == null) {
if (log.isDebugEnabled()) {
log.debug("No device is found upon the device identifier '" + deviceId.getId() +
"' and type '" + deviceId.getType() + "'. Therefore returning null");
}
return null;
}
return applicationDAO.getInstalledApplications(device.getId()); return applicationDAO.getInstalledApplications(device.getId());
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new ApplicationManagementException("Error occurred while fetching the Application List of '" + throw new ApplicationManagementException("Error occurred while fetching the Application List of '" +

@ -112,20 +112,20 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
@Override @Override
public DeviceInfo getDeviceInformation(int deviceId) throws DeviceDetailsMgtDAOException { public DeviceInfo getDeviceInformation(int deviceId) throws DeviceDetailsMgtDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
DeviceInfo deviceInfo = new DeviceInfo(); DeviceInfo deviceInfo = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = "SELECT * FROM DM_DEVICE_DETAIL WHERE DEVICE_ID = ?"; String sql = "SELECT * FROM DM_DEVICE_DETAIL WHERE DEVICE_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, deviceId); stmt.setInt(1, deviceId);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { if (rs.next()) {
deviceInfo = new DeviceInfo();
deviceInfo.setDeviceId(rs.getInt("DEVICE_ID")); deviceInfo.setDeviceId(rs.getInt("DEVICE_ID"));
// deviceInfo.setIMEI(rs.getString("IMEI")); // deviceInfo.setIMEI(rs.getString("IMEI"));
// deviceInfo.setIMSI(rs.getString("IMSI")); // deviceInfo.setIMSI(rs.getString("IMSI"));
@ -148,7 +148,6 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP")));
} }
deviceInfo.setDeviceId(deviceId);
return deviceInfo; return deviceInfo;
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceDetailsMgtDAOException("Error occurred while fetching the details of the registered devices.", e); throw new DeviceDetailsMgtDAOException("Error occurred while fetching the details of the registered devices.", e);

@ -19,6 +19,8 @@
package org.wso2.carbon.device.mgt.core.device.details.mgt.impl; package org.wso2.carbon.device.mgt.core.device.details.mgt.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
@ -38,6 +40,7 @@ import java.util.Map;
public class DeviceInformationManagerImpl implements DeviceInformationManager { public class DeviceInformationManagerImpl implements DeviceInformationManager {
private DeviceDetailsDAO deviceDetailsDAO; private DeviceDetailsDAO deviceDetailsDAO;
private static final Log log = LogFactory.getLog(DeviceInformationManagerImpl.class);
public DeviceInformationManagerImpl() { public DeviceInformationManagerImpl() {
this.deviceDetailsDAO = DeviceManagementDAOFactory.getDeviceDetailsDAO(); this.deviceDetailsDAO = DeviceManagementDAOFactory.getDeviceDetailsDAO();
@ -72,13 +75,22 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
} }
@Override @Override
public DeviceInfo getDeviceInfo( public DeviceInfo getDeviceInfo(DeviceIdentifier deviceId) throws DeviceDetailsMgtException {
DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException { Device device;
try {
device = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider().getDevice(deviceId);
if (device == null) {
if (log.isDebugEnabled()) {
log.debug("No device is found upon the device identifier '" + deviceId.getId() +
"' and type '" + deviceId.getType() + "'. Therefore returning null");
}
return null;
}
} catch (DeviceManagementException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving the device.", e);
}
try { try {
Device device = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider().getDevice(deviceIdentifier);
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
DeviceInfo deviceInfo = deviceDetailsDAO.getDeviceInformation(device.getId()); DeviceInfo deviceInfo = deviceDetailsDAO.getDeviceInformation(device.getId());
deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(device.getId())); deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(device.getId()));
@ -86,8 +98,6 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e); throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e);
} catch (DeviceManagementException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving the device.", e);
} catch (DeviceDetailsMgtDAOException e) { } catch (DeviceDetailsMgtDAOException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving device details.", e); throw new DeviceDetailsMgtException("Exception occurred while retrieving device details.", e);
} finally { } finally {
@ -114,7 +124,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
} }
} }
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
for(Integer id : deviceIds) { for (Integer id : deviceIds) {
DeviceInfo deviceInfo = deviceDetailsDAO.getDeviceInformation(id); DeviceInfo deviceInfo = deviceDetailsDAO.getDeviceInformation(id);
deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(id)); deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(id));
deviceInfos.add(deviceInfo); deviceInfos.add(deviceInfo);
@ -157,18 +167,25 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
} }
@Override @Override
public DeviceLocation getDeviceLocation(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException { public DeviceLocation getDeviceLocation(DeviceIdentifier deviceId) throws DeviceDetailsMgtException {
Device device;
try {
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId);
if (device == null) {
if (log.isDebugEnabled()) {
log.debug("No device is found upon the device identifier '" + deviceId.getId() +
"' and type '" + deviceId.getType() + "'. Therefore returning null");
}
return null;
}
} catch (DeviceManagementException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving the device.", e);
}
try { try {
Device device = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider().getDevice(deviceIdentifier);
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
return deviceDetailsDAO.getDeviceLocation(device.getId()); return deviceDetailsDAO.getDeviceLocation(device.getId());
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e); throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e);
} catch (DeviceManagementException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving the device.", e);
} catch (DeviceDetailsMgtDAOException e) { } catch (DeviceDetailsMgtDAOException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving device location.", e); throw new DeviceDetailsMgtException("Exception occurred while retrieving device location.", e);
} finally { } finally {

@ -185,49 +185,49 @@ public class OperationManagerImpl implements OperationManager {
} }
@Override @Override
public List<? extends Operation> getOperations( public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
DeviceIdentifier deviceId) throws OperationManagementException {
int enrolmentId; int enrolmentId;
List<Operation> operations = new ArrayList<>(); List<Operation> operations = null;
try { try {
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService(). boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
isUserAuthorized(deviceId, DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS); isUserAuthorized(deviceId, DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS);
if (isUserAuthorized) { if (!isUserAuthorized) {
throw new UnauthorizedDeviceAccessException("User '" + getUser() + "' is not authorized to " +
"fetch operations on device '" + deviceId.getId() + "'");
}
try {
try { try {
try { DeviceManagementDAOFactory.openConnection();
DeviceManagementDAOFactory.openConnection(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
if (enrolmentId < 0) {
return null;
}
OperationManagementDAOFactory.openConnection();
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
operationDAO.getOperationsForDevice(enrolmentId);
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : operationList) {
Operation operation = OperationDAOUtil.convertOperation(dtoOperation);
operations.add(operation);
}
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " +
"operations assigned for '" + deviceId.getType() +
"' device '" + deviceId.getId() + "'", e);
} catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving metadata of '" +
deviceId.getType() + "' device carrying the identifier '" +
deviceId.getId() + "'");
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
} finally { } finally {
OperationManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
} else { if (enrolmentId < 0) {
log.info("User : " + getUser() + " is not authorized to fetch operations on device : " + deviceId.getId()); return null;
}
OperationManagementDAOFactory.openConnection();
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
operationDAO.getOperationsForDevice(enrolmentId);
operations = new ArrayList<>();
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : operationList) {
Operation operation = OperationDAOUtil.convertOperation(dtoOperation);
operations.add(operation);
}
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " +
"operations assigned for '" + deviceId.getType() +
"' device '" + deviceId.getId() + "'", e);
} catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving metadata of '" +
deviceId.getType() + "' device carrying the identifier '" +
deviceId.getId() + "'");
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
} finally {
OperationManagementDAOFactory.closeConnection();
} }
} catch (DeviceAccessAuthorizationException e) { } catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " + throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
@ -757,7 +757,7 @@ public class OperationManagerImpl implements OperationManager {
// This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer. // This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer.
int operationId = Integer.parseInt( int operationId = Integer.parseInt(
activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "")); activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, ""));
if (operationId == 0){ if (operationId == 0) {
throw new IllegalArgumentException("Operation ID cannot be null or zero (0)."); throw new IllegalArgumentException("Operation ID cannot be null or zero (0).");
} }
try { try {

@ -607,7 +607,7 @@ public class PolicyManagerImpl implements PolicyManager {
policy.setPolicyCriterias(policyDAO.getPolicyCriteria(policy.getId())); policy.setPolicyCriterias(policyDAO.getPolicyCriteria(policy.getId()));
List<DeviceGroupWrapper> deviceGroupWrappers = policyDAO.getDeviceGroupsOfPolicy(policy.getId()); List<DeviceGroupWrapper> deviceGroupWrappers = policyDAO.getDeviceGroupsOfPolicy(policy.getId());
if(!deviceGroupWrappers.isEmpty()){ if (!deviceGroupWrappers.isEmpty()) {
deviceGroupWrappers = this.getDeviceGroupNames(deviceGroupWrappers); deviceGroupWrappers = this.getDeviceGroupNames(deviceGroupWrappers);
} }
policy.setDeviceGroups(deviceGroupWrappers); policy.setDeviceGroups(deviceGroupWrappers);
@ -977,17 +977,26 @@ public class PolicyManagerImpl implements PolicyManager {
} }
@Override @Override
public Policy getAppliedPolicyToDevice( public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceId) throws PolicyManagementException {
DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
Policy policy; Policy policy;
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
Device device;
try {
device = service.getDevice(deviceId);
if (device == null) {
if (log.isDebugEnabled()) {
log.debug("No device is found upon the device identifier '" + deviceId.getId() +
"' and type '" + deviceId.getType() + "'. Therefore returning null");
}
return null;
}
} catch (DeviceManagementException e) {
throw new PolicyManagementException("Error occurred while getting device id.", e);
}
try { try {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
Device device = service.getDevice(deviceIdentifier);
//int policyId = policyDAO.getAppliedPolicyId(device.getId()); //int policyId = policyDAO.getAppliedPolicyId(device.getId());
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();
policy = policyDAO.getAppliedPolicy(device.getId(), device.getEnrolmentInfo().getId()); policy = policyDAO.getAppliedPolicy(device.getId(), device.getEnrolmentInfo().getId());
} catch (DeviceManagementException e) {
throw new PolicyManagementException("Error occurred while getting device id.", e);
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
throw new PolicyManagementException("Error occurred while getting policy id or policy.", e); throw new PolicyManagementException("Error occurred while getting policy id or policy.", e);
} catch (SQLException e) { } catch (SQLException e) {

@ -212,7 +212,7 @@ public class PolicyManagerUtil {
throw new PolicyManagementException("Invalid value, i.e. '" + cEntry.getValue() + throw new PolicyManagementException("Invalid value, i.e. '" + cEntry.getValue() +
"', is configured as the monitoring frequency"); "', is configured as the monitoring frequency");
} }
monitoringFrequency = Integer.parseInt(cEntry.getValue().toString()); monitoringFrequency = (int) (Double.parseDouble(cEntry.getValue().toString()) + 0.5d);
} }
} }
} }

Loading…
Cancel
Save