Merge branch 'rest-api-improvements' of https://github.com/wso2/carbon-device-mgt into rest-api-improvements

revert-70aa11f8
inoshperera 9 years ago
commit d71f0c6e6d

@ -153,13 +153,8 @@ public interface ActivityInfoProviderService {
name = "timestamp", name = "timestamp",
value = "Validates if the requested variant has not been modified since the time specified, this " + value = "Validates if the requested variant has not been modified since the time specified, this " +
"should be provided in unix format in seconds.", "should be provided in unix format in seconds.",
required = true)
@QueryParam("timestamp") long timestamp,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false) required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("timestamp") long timestamp,
@ApiParam( @ApiParam(
name = "offset", name = "offset",
value = "Starting point within the complete list of items qualified.", value = "Starting point within the complete list of items qualified.",

@ -30,6 +30,7 @@ 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.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; 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;
@ -56,13 +57,10 @@ public interface DeviceManagementService {
httpMethod = "GET", httpMethod = "GET",
value = "Get the list of devices enrolled with the system.", value = "Get the list of devices enrolled with the system.",
notes = "Returns all devices enrolled with the system.", notes = "Returns all devices enrolled with the system.",
response = Device.class,
responseContainer = "List",
tags = "Device Management") tags = "Device Management")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.", @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.",
response = Device.class, response = DeviceList.class,
responseContainer = "List",
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
@ -140,149 +138,6 @@ public interface DeviceManagementService {
required = false) required = false)
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
@GET
@Path("{type}/{id}/info")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
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 " +
"identifier.",
tags = "Device Management")
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Information of the submitted list of devices is returned",
response = DeviceInfo.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests.")}),
@ApiResponse(
code = 303,
message = "See Other. \n Source can be retrieved from the URL specified at the Location header.",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The Source URL of the document.")}),
@ApiResponse(
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n No device is found under the provided type and id.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
"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"})
Response getDeviceInfo(
@ApiParam(
name = "type",
value = "The device type, such as ios, android or windows.",
required = true)
@PathParam("type") String type,
@ApiParam(
name = "id",
value = "The device identifier of the device.",
required = true)
@PathParam("id") String id,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@POST
@Path("/get-info")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Retrieve devices information from the supplied device identifies.",
notes = "This will return device information such as CPU usage, memory usage etc for supplied device " +
"identifiers.",
tags = "Device Management")
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Information of the submitted list of devices is returned",
response = DeviceInfo.class,
responseContainer = "List",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests.")}),
@ApiResponse(
code = 303,
message = "See Other. \n Source can be retrieved from the URL specified at the Location header.",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The Source URL of the document.")}),
@ApiResponse(
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n No device information is available for the device list submitted.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. 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"})
Response getDevicesInfo(
@ApiParam(
name = "If-Modified-Since",
value = "Timestamp of the last modified date",
required = false)
@HeaderParam("If-Modified-Since") String timestamp,
@ApiParam(
name = "deviceIds",
value = "List of device identifiers",
required = true) List<DeviceIdentifier> deviceIds);
@GET @GET
@Path("/{type}/{id}") @Path("/{type}/{id}")
@ -349,104 +204,6 @@ public interface DeviceManagementService {
required = false) required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince); @HeaderParam("If-Modified-Since") String ifModifiedSince);
@GET
@Path("/{type}/{id}/location")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
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 "
+ "physical address.",
tags = "Device Management")
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "Successfully fetched the device location.",
response = DeviceLocation.class),
@ApiResponse(
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n No device is found under the provided type and id.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "ErrorResponse occurred while getting the device location.",
response = ErrorResponse.class)
})
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDeviceLocation(
@ApiParam(
name = "type",
value = "The device type, such as ios, android or windows.",
required = true)
@PathParam("type") String type,
@ApiParam(
name = "id",
value = "The device identifier of the device.",
required = true)
@PathParam("id") String id,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@POST
@Path("/locations")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
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 "
+ "physical address of the given devices.",
tags = "Device Management")
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "Successfully fetched the device location.",
response = DeviceLocation.class,
responseContainer = "List"),
@ApiResponse(
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Location details are not available for the given devices.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "ErrorResponse occurred while getting the device location.",
response = ErrorResponse.class)
})
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDeviceLocations(
@ApiParam(
name = "deviceIds",
value = "List of device identifiers",
required = true) List<DeviceIdentifier> deviceIds,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@GET @GET
@Path("/{type}/{id}/features") @Path("/{type}/{id}/features")
@ApiOperation( @ApiOperation(

@ -72,10 +72,9 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
@Override @Override
public Response getActivities( public Response getActivities(
@QueryParam("timestamp") long timestamp, @QueryParam("timestamp") long timestamp,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@QueryParam("limit") int limit) { @QueryParam("limit") int limit) {
List<Activity> activities = null; List<Activity> activities;
DeviceManagementProviderService dmService; DeviceManagementProviderService dmService;
try { try {
dmService = DeviceMgtAPIUtils.getDeviceManagementService(); dmService = DeviceMgtAPIUtils.getDeviceManagementService();

@ -110,58 +110,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
} }
} }
@GET
@Path("{type}/{id}/info")
public Response getDeviceInfo(@PathParam("type") String type, @NotNull @PathParam("id") String id,
@HeaderParam("If-Modified-Since") String timestamp) {
DeviceInformationManager informationManager;
DeviceInfo deviceInfo;
try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(id);
deviceIdentifier.setType(type);
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceInfo = informationManager.getDeviceInfo(deviceIdentifier);
if (deviceInfo == null) {
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("It is likely that no " +
"device is found upon the give type '" + type + "' and id '" + id + "'").build());
}
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device information.";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
}
return Response.status(Response.Status.OK).entity(deviceInfo).build();
}
@POST
@Path("/get-info")
@Override
public Response getDevicesInfo(
@HeaderParam("If-Modified-Since") String timestamp,
List<DeviceIdentifier> deviceIds) {
DeviceInformationManager informationManager;
List<DeviceInfo> deviceInfo;
try {
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceInfo = informationManager.getDevicesInfo(deviceIds);
if (deviceInfo == null) {
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No device information " +
"is available for the device list submitted").build());
}
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device information.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(deviceInfo).build();
}
@GET @GET
@Path("/{type}/{id}") @Path("/{type}/{id}")
@Override @Override
@ -189,60 +137,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
return Response.status(Response.Status.OK).entity(device).build(); return Response.status(Response.Status.OK).entity(device).build();
} }
@GET
@Path("/{type}/{id}/location")
@Override
public Response getDeviceLocation(
@PathParam("type") String type,
@PathParam("id") String id,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
DeviceInformationManager informationManager;
DeviceLocation deviceLocation;
try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceLocation = informationManager.getDeviceLocation(new DeviceIdentifier(id, type));
if (deviceLocation == null || deviceLocation.getLatitude() == null ||
deviceLocation.getLongitude() == null) {
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("Location details " +
"are not available for the given device id '" + id + "'").build());
}
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the last updated location of the '" + type + "' device, " +
"which carries the id '" + id + "'";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
}
return Response.status(Response.Status.OK).entity(deviceLocation).build();
}
@POST
@Path("/locations")
public Response getDeviceLocations(List<DeviceIdentifier> deviceIdentifiers,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
DeviceInformationManager informationManager;
List<DeviceLocation> deviceLocations;
RequestValidationUtil.validateDeviceIdentifiers(deviceIdentifiers);
try {
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceLocations = informationManager.getDeviceLocations(deviceIdentifiers);
if (deviceLocations == null || deviceLocations.size() == 0) {
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No location related " +
"details were found.").build());
}
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device location.";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
}
return Response.status(Response.Status.OK).entity(deviceLocations).build();
}
@GET @GET
@Path("/{type}/{id}/features") @Path("/{type}/{id}/features")
@Override @Override

@ -19,6 +19,8 @@ package org.wso2.carbon.device.mgt.common;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ -31,13 +33,17 @@ public class Device implements Serializable {
@ApiModelProperty(name = "id", value = "ID of the device in the WSO2 EMM device information database.", @ApiModelProperty(name = "id", value = "ID of the device in the WSO2 EMM device information database.",
required = true) required = true)
private int id; private int id;
@ApiModelProperty(name = "name", value = "The device name that can be set on the device by the device user.", @ApiModelProperty(name = "name", value = "The device name that can be set on the device by the device user.",
required = true) required = true)
private String name; private String name;
@ApiModelProperty(name = "type", value = "The OS type of the device.", required = true) @ApiModelProperty(name = "type", value = "The OS type of the device.", required = true)
private String type; private String type;
@ApiModelProperty(name = "description", value = "Additional information on the device.", required = true) @ApiModelProperty(name = "description", value = "Additional information on the device.", required = true)
private String description; private String description;
@ApiModelProperty(name = "deviceIdentifier", value = "This is a 64-bit number (as a hex string) that is randomly" + @ApiModelProperty(name = "deviceIdentifier", value = "This is a 64-bit number (as a hex string) that is randomly" +
" generated when the user first sets up the device and should" + " generated when the user first sets up the device and should" +
" remain constant for the lifetime of the user's device." + " remain constant for the lifetime of the user's device." +
@ -45,13 +51,24 @@ public class Device implements Serializable {
"the device.", "the device.",
required = true) required = true)
private String deviceIdentifier; private String deviceIdentifier;
@ApiModelProperty(name = "enrolmentInfo", value = "This defines the device registration related information. " + @ApiModelProperty(name = "enrolmentInfo", value = "This defines the device registration related information. " +
"It is mandatory to define this information.", required = true) "It is mandatory to define this information.", required = true)
private EnrolmentInfo enrolmentInfo; private EnrolmentInfo enrolmentInfo;
@ApiModelProperty(name = "features", value = "List of features.", required = true) @ApiModelProperty(name = "features", value = "List of features.", required = true)
private List<Feature> features; private List<Feature> features;
private List<Device.Property> properties; private List<Device.Property> properties;
@ApiModelProperty(name = "advanceInfo", value = "This defines the device registration related information. " +
"It is mandatory to define this information.", required = false)
private DeviceInfo deviceInfo;
@ApiModelProperty(name = "applications", value = "This represents the application list installed into the device",
required = false)
private List<Application> applications;
public Device() { public Device() {
} }
@ -130,6 +147,22 @@ public class Device implements Serializable {
this.properties = properties; this.properties = properties;
} }
public DeviceInfo getDeviceInfo() {
return deviceInfo;
}
public void setDeviceInfo(DeviceInfo deviceInfo) {
this.deviceInfo = deviceInfo;
}
public List<Application> getApplications() {
return applications;
}
public void setApplications(List<Application> applications) {
this.applications = applications;
}
public static class Property { public static class Property {
private String name; private String name;

@ -21,7 +21,6 @@ package org.wso2.carbon.device.mgt.common.device.details;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
@ -34,78 +33,112 @@ public class DeviceInfo implements Serializable {
private static final long serialVersionUID = 1998101733L; private static final long serialVersionUID = 1998101733L;
@ApiModelProperty(name = "deviceId", value = "Device Id.", required = true) // @ApiModelProperty(name = "deviceId", value = "Device Id.", required = false)
private int deviceId; // private int deviceId;
@ApiModelProperty(name = "deviceType", value = "Type of the device.", required = true) //
private String deviceType; // @ApiModelProperty(name = "deviceType", value = "Type of the device.", required = true)
@ApiModelProperty(name = "deviceId", value = "Device identifier.", required = true) // private String deviceType;
private DeviceIdentifier deviceIdentifier; //
// @ApiModelProperty(name = "deviceId", value = "Device identifier.", required = true)
// private DeviceIdentifier deviceIdentifier;
@ApiModelProperty(name = "IMEI", value = "IMEI number of the device.", required = true) @ApiModelProperty(name = "IMEI", value = "IMEI number of the device.", required = true)
private String IMEI; private String IMEI;
@ApiModelProperty(name = "IMSI", value = "IMSI number of the device.", required = true) @ApiModelProperty(name = "IMSI", value = "IMSI number of the device.", required = true)
private String IMSI; private String IMSI;
@ApiModelProperty(name = "deviceModel", value = "Model of the device.", required = true) @ApiModelProperty(name = "deviceModel", value = "Model of the device.", required = true)
private String deviceModel; private String deviceModel;
@ApiModelProperty(name = "vendor", value = "Vendor of the device.", required = true) @ApiModelProperty(name = "vendor", value = "Vendor of the device.", required = true)
private String vendor; private String vendor;
@ApiModelProperty(name = "osVersion", value = "Operating system version.", required = true) @ApiModelProperty(name = "osVersion", value = "Operating system version.", required = true)
private String osVersion; private String osVersion;
@ApiModelProperty(name = "batteryLevel", value = "Battery level of the device.", required = true) @ApiModelProperty(name = "batteryLevel", value = "Battery level of the device.", required = true)
private Double batteryLevel; private Double batteryLevel;
@ApiModelProperty(name = "internalTotalMemory", value = "Total internal memory of the device.", required = true) @ApiModelProperty(name = "internalTotalMemory", value = "Total internal memory of the device.", required = true)
private Double internalTotalMemory; private Double internalTotalMemory;
@ApiModelProperty(name = "internalAvailableMemory", value = "Total available memory of the device.", @ApiModelProperty(name = "internalAvailableMemory", value = "Total available memory of the device.",
required = true) required = true)
private Double internalAvailableMemory; private Double internalAvailableMemory;
@ApiModelProperty(name = "externalTotalMemory", value = "Total external memory of the device.", required = true) @ApiModelProperty(name = "externalTotalMemory", value = "Total external memory of the device.", required = true)
private Double externalTotalMemory; private Double externalTotalMemory;
@ApiModelProperty(name = "externalAvailableMemory", value = "Total external memory avilable of the device.", @ApiModelProperty(name = "externalAvailableMemory", value = "Total external memory avilable of the device.",
required = true) required = true)
private Double externalAvailableMemory; private Double externalAvailableMemory;
@ApiModelProperty(name = "operator", value = "Mobile operator of the device.", required = true) @ApiModelProperty(name = "operator", value = "Mobile operator of the device.", required = true)
private String operator; private String operator;
@ApiModelProperty(name = "connectionType", value = "How the device is connected to the network.", required = true) @ApiModelProperty(name = "connectionType", value = "How the device is connected to the network.", required = true)
private String connectionType; private String connectionType;
@ApiModelProperty(name = "mobileSignalStrength", value = "Current mobile signal strength.", required = true) @ApiModelProperty(name = "mobileSignalStrength", value = "Current mobile signal strength.", required = true)
private Double mobileSignalStrength; private Double mobileSignalStrength;
@ApiModelProperty(name = "ssid", value = "ssid of the connected WiFi.", required = true) @ApiModelProperty(name = "ssid", value = "ssid of the connected WiFi.", required = true)
private String ssid; private String ssid;
@ApiModelProperty(name = "cpuUsage", value = "Current total cpu usage.", required = true) @ApiModelProperty(name = "cpuUsage", value = "Current total cpu usage.", required = true)
private Double cpuUsage; private Double cpuUsage;
@ApiModelProperty(name = "totalRAMMemory", value = "Total Ram memory size.", required = true) @ApiModelProperty(name = "totalRAMMemory", value = "Total Ram memory size.", required = true)
private Double totalRAMMemory; private Double totalRAMMemory;
@ApiModelProperty(name = "availableRAMMemory", value = "Available total memory of RAM.", required = true) @ApiModelProperty(name = "availableRAMMemory", value = "Available total memory of RAM.", required = true)
private Double availableRAMMemory; private Double availableRAMMemory;
@ApiModelProperty(name = "pluggedIn", value = "Whether the device is plugged into power or not.", @ApiModelProperty(name = "pluggedIn", value = "Whether the device is plugged into power or not.",
required = true) required = true)
private boolean pluggedIn; private boolean pluggedIn;
@ApiModelProperty(name = "updatedTime", value = "Device updated time.", required = true) @ApiModelProperty(name = "updatedTime", value = "Device updated time.", required = true)
private Date updatedTime; private Date updatedTime;
@ApiModelProperty(name = "deviceDetailsMap", value = ".", required = true)
private Map<String, String> deviceDetailsMap = new HashMap<>();
public int getDeviceId() {
return deviceId;
}
public void setDeviceId(int deviceId) { @ApiModelProperty(name = "location", value = "Last updated location of the device", required = false)
this.deviceId = deviceId; private DeviceLocation location;
}
public String getDeviceType() { @ApiModelProperty(name = "deviceDetailsMap", value = ".", required = true)
return deviceType; private Map<String, String> deviceDetailsMap = new HashMap<>();
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public DeviceIdentifier getDeviceIdentifier() {
return deviceIdentifier;
}
public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) { // public int getDeviceId() {
this.deviceIdentifier = deviceIdentifier; // return deviceId;
// }
//
// public void setDeviceId(int deviceId) {
// this.deviceId = deviceId;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType;
// }
//
// public DeviceIdentifier getDeviceIdentifier() {
// return deviceIdentifier;
// }
//
// public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) {
// this.deviceIdentifier = deviceIdentifier;
// }
public DeviceLocation getLocation() {
return location;
}
public void setLocation(DeviceLocation location) {
this.location = location;
} }
public String getIMEI() { public String getIMEI() {

@ -40,13 +40,13 @@ import java.nio.charset.Charset;
* Main usage of this module is saving/retrieving tenant configurations to the registry. * Main usage of this module is saving/retrieving tenant configurations to the registry.
* *
*/ */
public class TenantConfigurationManagementServiceImpl public class PlatformConfigurationManagementServiceImpl
implements PlatformConfigurationManagementService { implements PlatformConfigurationManagementService {
private static final Log log = LogFactory.getLog(TenantConfigurationManagementServiceImpl.class); private static final Log log = LogFactory.getLog(PlatformConfigurationManagementServiceImpl.class);
@Override @Override
public boolean saveConfiguration(PlatformConfiguration tenantConfiguration, String resourcePath) public boolean saveConfiguration(PlatformConfiguration platformConfiguration, String resourcePath)
throws ConfigurationManagementException { throws ConfigurationManagementException {
boolean status; boolean status;
try { try {
@ -56,7 +56,7 @@ public class TenantConfigurationManagementServiceImpl
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class); JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
Marshaller marshaller = context.createMarshaller(); Marshaller marshaller = context.createMarshaller();
marshaller.marshal(tenantConfiguration, writer); marshaller.marshal(platformConfiguration, writer);
Resource resource = ConfigurationManagerUtil.getConfigurationRegistry().newResource(); Resource resource = ConfigurationManagerUtil.getConfigurationRegistry().newResource();
resource.setContent(writer.toString()); resource.setContent(writer.toString());
@ -65,10 +65,10 @@ public class TenantConfigurationManagementServiceImpl
status = true; status = true;
} catch (RegistryException e) { } catch (RegistryException e) {
throw new ConfigurationManagementException( throw new ConfigurationManagementException(
"Error occurred while persisting the Registry resource of Tenant Configuration : " + e.getMessage(), e); "Error occurred while persisting the Registry resource of Platform Configuration", e);
} catch (JAXBException e) { } catch (JAXBException e) {
throw new ConfigurationManagementException( throw new ConfigurationManagementException(
"Error occurred while parsing the Tenant configuration : " + e.getMessage(), e); "Error occurred while parsing the Platform configuration", e);
} }
return status; return status;
} }

@ -22,6 +22,7 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
@ -200,4 +201,29 @@ public final class DeviceManagementDAOUtil {
deviceType.setName(rs.getString("NAME")); deviceType.setName(rs.getString("NAME"));
return deviceType; return deviceType;
} }
public static DeviceInfo loadDeviceInfo(ResultSet rs) throws SQLException {
DeviceInfo deviceInfo = new DeviceInfo();
// deviceInfo.setIMEI(rs.getString("IMEI"));
// deviceInfo.setIMSI(rs.getString("IMSI"));
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
deviceInfo.setVendor(rs.getString("VENDOR"));
deviceInfo.setOsVersion(rs.getString("OS_VERSION"));
deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL"));
deviceInfo.setInternalTotalMemory(rs.getDouble("INTERNAL_TOTAL_MEMORY"));
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY"));
// deviceInfo.setOperator(rs.getString("OPERATOR"));
deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE"));
// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH"));
deviceInfo.setSsid(rs.getString("SSID"));
deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE"));
deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY"));
deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY"));
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN"));
deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP")));
return deviceInfo;
}
} }

@ -39,7 +39,8 @@ public interface DeviceInformationManager {
* @param deviceInfo - Device info object. * @param deviceInfo - Device info object.
* @throws DeviceDetailsMgtException * @throws DeviceDetailsMgtException
*/ */
void addDeviceInfo(DeviceInfo deviceInfo) throws DeviceDetailsMgtException; //void addDeviceInfo(DeviceInfo deviceInfo) throws DeviceDetailsMgtException;
void addDeviceInfo(DeviceIdentifier deviceId, DeviceInfo deviceInfo) throws DeviceDetailsMgtException;
/** /**
* This method will return the device information. * This method will return the device information.

@ -38,7 +38,7 @@ public interface DeviceDetailsDAO {
* @param deviceInfo - Device information object. * @param deviceInfo - Device information object.
* @throws DeviceDetailsMgtDAOException * @throws DeviceDetailsMgtDAOException
*/ */
void addDeviceInformation(DeviceInfo deviceInfo) throws DeviceDetailsMgtDAOException; void addDeviceInformation(int deviceId, DeviceInfo deviceInfo) throws DeviceDetailsMgtDAOException;
/** /**
* This method will add the device properties to the database. * This method will add the device properties to the database.

@ -40,7 +40,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
private static Log log = LogFactory.getLog(DeviceDetailsDAOImpl.class); private static Log log = LogFactory.getLog(DeviceDetailsDAOImpl.class);
@Override @Override
public void addDeviceInformation(DeviceInfo deviceInfo) throws DeviceDetailsMgtDAOException { public void addDeviceInformation(int deviceId, DeviceInfo deviceInfo) throws DeviceDetailsMgtDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -53,7 +53,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
"SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN, UPDATE_TIMESTAMP) " + "SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN, UPDATE_TIMESTAMP) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
stmt.setInt(1, deviceInfo.getDeviceId()); stmt.setInt(1, deviceId);
stmt.setString(2, deviceInfo.getDeviceModel()); stmt.setString(2, deviceInfo.getDeviceModel());
stmt.setString(3, deviceInfo.getVendor()); stmt.setString(3, deviceInfo.getVendor());
stmt.setString(4, deviceInfo.getOsVersion()); stmt.setString(4, deviceInfo.getOsVersion());
@ -126,7 +126,6 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
if (rs.next()) { if (rs.next()) {
deviceInfo = new DeviceInfo(); deviceInfo = new DeviceInfo();
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"));
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));

@ -47,18 +47,16 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
} }
@Override @Override
public void addDeviceInfo(DeviceInfo deviceInfo) throws DeviceDetailsMgtException { public void addDeviceInfo(DeviceIdentifier deviceId, DeviceInfo deviceInfo) throws DeviceDetailsMgtException {
try { try {
Device device = DeviceManagementDataHolder.getInstance(). Device device = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider().getDevice(deviceInfo.getDeviceIdentifier()); getDeviceManagementProvider().getDevice(deviceId);
deviceInfo.setDeviceId(device.getId());
DeviceManagementDAOFactory.beginTransaction(); DeviceManagementDAOFactory.beginTransaction();
deviceDetailsDAO.deleteDeviceInformation(deviceInfo.getDeviceId()); deviceDetailsDAO.deleteDeviceInformation(device.getId());
deviceDetailsDAO.deleteDeviceProperties(deviceInfo.getDeviceId()); deviceDetailsDAO.deleteDeviceProperties(device.getId());
deviceDetailsDAO.addDeviceInformation(deviceInfo); deviceDetailsDAO.addDeviceInformation(device.getId(), deviceInfo);
deviceDetailsDAO.addDeviceProperties(deviceInfo.getDeviceDetailsMap(), deviceInfo.getDeviceId()); deviceDetailsDAO.addDeviceProperties(deviceInfo.getDeviceDetailsMap(), device.getId());
DeviceManagementDAOFactory.commitTransaction(); DeviceManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
DeviceManagementDAOFactory.rollbackTransaction(); DeviceManagementDAOFactory.rollbackTransaction();

@ -41,7 +41,7 @@ import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationSe
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.tenant.TenantConfigurationManagementServiceImpl; import org.wso2.carbon.device.mgt.core.config.tenant.PlatformConfigurationManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.group.mgt.dao.GroupManagementDAOFactory; import org.wso2.carbon.device.mgt.core.group.mgt.dao.GroupManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImpl; import org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImpl;
@ -219,7 +219,7 @@ public class DeviceManagementServiceComponent {
/* Registering Tenant Configuration Management Service */ /* Registering Tenant Configuration Management Service */
PlatformConfigurationManagementService PlatformConfigurationManagementService
tenantConfiguration = new TenantConfigurationManagementServiceImpl(); tenantConfiguration = new PlatformConfigurationManagementServiceImpl();
bundleContext.registerService(PlatformConfigurationManagementService.class.getName(), tenantConfiguration, null); bundleContext.registerService(PlatformConfigurationManagementService.class.getName(), tenantConfiguration, null);
/* Registering Notification Service */ /* Registering Notification Service */

@ -282,9 +282,9 @@ public class GenericOperationDAOImpl implements OperationDAO {
int enrolmentId = 0; int enrolmentId = 0;
ActivityStatus activityStatus = null; ActivityStatus activityStatus = null;
if (rs.next()) { while (rs.next()) {
activity = new Activity();
if (enrolmentId == 0) { if (enrolmentId == 0) {
activity = new Activity();
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP"))).toString()); activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP"))).toString());
activity.setCode(rs.getString("OPERATION_CODE")); activity.setCode(rs.getString("OPERATION_CODE"));

@ -73,7 +73,6 @@ public class SearchDAOImpl implements SearchDAO {
identifier.setId(rs.getString("DEVICE_IDENTIFICATION")); identifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
DeviceInfo deviceInfo = new DeviceInfo(); DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setDeviceId(rs.getInt("ID"));
deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY"));
deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL")); deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL"));
deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE")); deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE"));
@ -156,7 +155,6 @@ public class SearchDAOImpl implements SearchDAO {
identifier.setId(rs.getString("DEVICE_IDENTIFICATION")); identifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
DeviceInfo deviceInfo = new DeviceInfo(); DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setDeviceId(rs.getInt("ID"));
deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY"));
deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL")); deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL"));
deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE")); deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE"));

@ -21,7 +21,10 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
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.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
@ -32,6 +35,8 @@ import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfi
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
import org.wso2.carbon.device.mgt.core.dao.*; import org.wso2.carbon.device.mgt.core.dao.*;
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO;
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
@ -53,8 +58,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class); private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class);
private DeviceDAO deviceDAO; private DeviceDAO deviceDAO;
private DeviceDetailsDAO deviceInfoDAO;
private DeviceTypeDAO deviceTypeDAO; private DeviceTypeDAO deviceTypeDAO;
private EnrollmentDAO enrollmentDAO; private EnrollmentDAO enrollmentDAO;
private ApplicationDAO applicationDAO;
private DeviceManagementPluginRepository pluginRepository; private DeviceManagementPluginRepository pluginRepository;
private OperationManagerRepository operationManagerRepository; private OperationManagerRepository operationManagerRepository;
@ -69,6 +76,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
private void initDataAccessObjects() { private void initDataAccessObjects() {
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.deviceInfoDAO = DeviceManagementDAOFactory.getDeviceDetailsDAO();
this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
this.enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO(); this.enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
} }
@ -379,6 +388,37 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
for (Device device : allDevices) { for (Device device : allDevices) {
DeviceInfo info = null;
try {
DeviceManagementDAOFactory.openConnection();
info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
if (info != null) {
info.setLocation(location);
}
} catch (DeviceDetailsMgtDAOException e) {
log.error("Error occurred while retrieving advance info of '" + device.getType() +
"' that carries the id '" + device.getDeviceIdentifier() + "'");
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
device.setDeviceInfo(info);
try {
DeviceManagementDAOFactory.openConnection();
List<Application> applications = applicationDAO.getInstalledApplications(device.getId());
device.setApplications(applications);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while retrieving the application list of '" + device.getType() + "', " +
"which carries the id '" + device.getId() + "'", e);
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
DeviceManager deviceManager = this.getDeviceManager(device.getType()); DeviceManager deviceManager = this.getDeviceManager(device.getType());
if (deviceManager == null) { if (deviceManager == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -420,6 +460,24 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
for (Device device : allDevices) { for (Device device : allDevices) {
DeviceInfo info = null;
try {
DeviceManagementDAOFactory.openConnection();
info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
if (info != null) {
info.setLocation(location);
}
device.setDeviceInfo(info);
} catch (DeviceDetailsMgtDAOException e) {
log.error("Error occurred while retrieving advance info of '" + device.getType() +
"' that carries the id '" + device.getDeviceIdentifier() + "'");
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
device.setDeviceInfo(info);
DeviceManager deviceManager = this.getDeviceManager(device.getType()); DeviceManager deviceManager = this.getDeviceManager(device.getType());
if (deviceManager == null) { if (deviceManager == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -463,6 +521,38 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
for (Device device : allDevices) { for (Device device : allDevices) {
DeviceInfo info = null;
try {
DeviceManagementDAOFactory.openConnection();
info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
if (info != null) {
info.setLocation(location);
}
device.setDeviceInfo(info);
} catch (DeviceDetailsMgtDAOException e) {
log.error("Error occurred while retrieving advance info of '" + device.getType() +
"' that carries the id '" + device.getDeviceIdentifier() + "'");
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
device.setDeviceInfo(info);
try {
DeviceManagementDAOFactory.openConnection();
List<Application> applications = applicationDAO.getInstalledApplications(device.getId());
device.setApplications(applications);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while retrieving the application list of '" + device.getType() + "', " +
"which carries the id '" + device.getId() + "'", e);
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
DeviceManager deviceManager = this.getDeviceManager(device.getType()); DeviceManager deviceManager = this.getDeviceManager(device.getType());
if (deviceManager == null) { if (deviceManager == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -493,6 +583,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try { try {
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
allDevices = deviceDAO.getDevices(deviceType, this.getTenantId()); allDevices = deviceDAO.getDevices(deviceType, this.getTenantId());
if (allDevices == null) {
if (log.isDebugEnabled()) {
log.debug("No device is found upon the type '" + deviceType + "'");
}
return null;
}
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while retrieving all devices of type '" + throw new DeviceManagementException("Error occurred while retrieving all devices of type '" +
deviceType + "' that are being managed within the scope of current tenant", e); deviceType + "' that are being managed within the scope of current tenant", e);
@ -503,6 +599,37 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
for (Device device : allDevices) { for (Device device : allDevices) {
DeviceInfo info = null;
try {
DeviceManagementDAOFactory.openConnection();
info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
if (info != null) {
info.setLocation(location);
}
} catch (DeviceDetailsMgtDAOException e) {
log.error("Error occurred while retrieving advance info of '" + device.getType() +
"' that carries the id '" + device.getDeviceIdentifier() + "'");
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
device.setDeviceInfo(info);
try {
DeviceManagementDAOFactory.openConnection();
List<Application> applications = applicationDAO.getInstalledApplications(device.getId());
device.setApplications(applications);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while retrieving the application list of '" + device.getType() + "', " +
"which carries the id '" + device.getId() + "'", e);
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
DeviceManager deviceManager = this.getDeviceManager(deviceType); DeviceManager deviceManager = this.getDeviceManager(deviceType);
if (deviceManager == null) { if (deviceManager == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -573,30 +700,46 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try { try {
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
device = deviceDAO.getDevice(deviceId, this.getTenantId()); device = deviceDAO.getDevice(deviceId, this.getTenantId());
if (device == null) {
if (log.isDebugEnabled()) {
log.debug("No device is found upon the type '" + deviceId.getType() + "' and id '" +
deviceId.getId() + "'");
}
return null;
}
DeviceInfo info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
if (info != null) {
info.setLocation(location);
}
device.setDeviceInfo(info);
List<Application> applications = applicationDAO.getInstalledApplications(device.getId());
device.setApplications(applications);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining the device for id " + throw new DeviceManagementException("Error occurred while obtaining the device for id " +
"'" + deviceId.getId() + "'", e); "'" + deviceId.getId() + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} catch (DeviceDetailsMgtDAOException e) {
throw new DeviceManagementException("Error occurred while fetching advanced device information", e);
} finally { } finally {
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
if (device != null) { // The changes made here to prevent unit tests getting failed. They failed because when running the unit
// The changes made here to prevent unit tests getting failed. They failed because when running the unit // tests there is no osgi services. So getDeviceManager() returns a null.
// tests there is no osgi services. So getDeviceManager() returns a null. DeviceManager deviceManager = this.getDeviceManager(deviceId.getType());
DeviceManager deviceManager = this.getDeviceManager(deviceId.getType()); if (deviceManager == null) {
if (deviceManager == null) { if (log.isDebugEnabled()) {
if (log.isDebugEnabled()) { log.debug("Device Manager associated with the device type '" + deviceId.getType() + "' is null. " +
log.debug("Device Manager associated with the device type '" + deviceId.getType() + "' is null. " + "Therefore, not attempting method 'getDevice'");
"Therefore, not attempting method 'getDevice'");
}
return device;
}
Device pluginSpecificInfo = deviceManager.getDevice(deviceId);
if (pluginSpecificInfo != null) {
device.setFeatures(pluginSpecificInfo.getFeatures());
device.setProperties(pluginSpecificInfo.getProperties());
} }
return device;
}
Device pluginSpecificInfo = deviceManager.getDevice(deviceId);
if (pluginSpecificInfo != null) {
device.setFeatures(pluginSpecificInfo.getFeatures());
device.setProperties(pluginSpecificInfo.getProperties());
} }
return device; return device;
} }
@ -607,30 +750,47 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try { try {
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
device = deviceDAO.getDevice(deviceId, status, this.getTenantId()); device = deviceDAO.getDevice(deviceId, status, this.getTenantId());
if (device == null) {
if (log.isDebugEnabled()) {
log.debug("No device is found upon the type '" + deviceId.getType() + "' and id '" +
deviceId.getId() + "'");
}
return null;
}
DeviceInfo info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
if (info != null) {
info.setLocation(location);
}
device.setDeviceInfo(info);
List<Application> applications = applicationDAO.getInstalledApplications(device.getId());
device.setApplications(applications);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining the device for id " + throw new DeviceManagementException("Error occurred while obtaining the device for id " +
"'" + deviceId.getId() + "'", e); "'" + deviceId.getId() + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} catch (DeviceDetailsMgtDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining information of the device with id " +
"'" + deviceId.getId() + "'", e);
} finally { } finally {
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
if (device != null) { // The changes made here to prevent unit tests getting failed. They failed because when running the unit
// The changes made here to prevent unit tests getting failed. They failed because when running the unit // tests there is no osgi services. So getDeviceManager() returns a null.
// tests there is no osgi services. So getDeviceManager() returns a null. DeviceManager deviceManager = this.getDeviceManager(deviceId.getType());
DeviceManager deviceManager = this.getDeviceManager(deviceId.getType()); if (deviceManager == null) {
if (deviceManager == null) { if (log.isDebugEnabled()) {
if (log.isDebugEnabled()) { log.debug("Device Manager associated with the device type '" + deviceId.getType() + "' is null. " +
log.debug("Device Manager associated with the device type '" + deviceId.getType() + "' is null. " + "Therefore, not attempting method 'getDevice'");
"Therefore, not attempting method 'getDevice'");
}
return device;
}
Device pluginSpecificInfo = deviceManager.getDevice(deviceId);
if (pluginSpecificInfo != null) {
device.setFeatures(pluginSpecificInfo.getFeatures());
device.setProperties(pluginSpecificInfo.getProperties());
} }
return device;
}
Device pluginSpecificInfo = deviceManager.getDevice(deviceId);
if (pluginSpecificInfo != null) {
device.setFeatures(pluginSpecificInfo.getFeatures());
device.setProperties(pluginSpecificInfo.getProperties());
} }
return device; return device;
} }
@ -883,6 +1043,37 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
for (Device device : userDevices) { for (Device device : userDevices) {
DeviceInfo info = null;
try {
DeviceManagementDAOFactory.openConnection();
info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
if (info != null) {
info.setLocation(location);
}
} catch (DeviceDetailsMgtDAOException e) {
log.error("Error occurred while retrieving advance info of '" + device.getType() +
"' that carries the id '" + device.getDeviceIdentifier() + "'");
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
device.setDeviceInfo(info);
try {
DeviceManagementDAOFactory.openConnection();
List<Application> applications = applicationDAO.getInstalledApplications(device.getId());
device.setApplications(applications);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while retrieving the application list of '" + device.getType() + "', " +
"which carries the id '" + device.getId() + "'", e);
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
DeviceManager deviceManager = this.getDeviceManager(device.getType()); DeviceManager deviceManager = this.getDeviceManager(device.getType());
if (deviceManager == null) { if (deviceManager == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -926,6 +1117,37 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
for (Device device : userDevices) { for (Device device : userDevices) {
DeviceInfo info = null;
try {
DeviceManagementDAOFactory.openConnection();
info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
if (info != null) {
info.setLocation(location);
}
} catch (DeviceDetailsMgtDAOException e) {
log.error("Error occurred while retrieving advance info of '" + device.getType() +
"' that carries the id '" + device.getDeviceIdentifier() + "'");
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
device.setDeviceInfo(info);
try {
DeviceManagementDAOFactory.openConnection();
List<Application> applications = applicationDAO.getInstalledApplications(device.getId());
device.setApplications(applications);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while retrieving the application list of '" + device.getType() + "', " +
"which carries the id '" + device.getId() + "'", e);
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
DeviceManager deviceManager = this.getDeviceManager(device.getType()); DeviceManager deviceManager = this.getDeviceManager(device.getType());
if (deviceManager == null) { if (deviceManager == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -971,6 +1193,37 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
for (Device device : allDevices) { for (Device device : allDevices) {
DeviceInfo info = null;
try {
DeviceManagementDAOFactory.openConnection();
info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
if (info != null) {
info.setLocation(location);
}
} catch (DeviceDetailsMgtDAOException e) {
log.error("Error occurred while retrieving advance info of '" + device.getType() +
"' that carries the id '" + device.getDeviceIdentifier() + "'");
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
device.setDeviceInfo(info);
try {
DeviceManagementDAOFactory.openConnection();
List<Application> applications = applicationDAO.getInstalledApplications(device.getId());
device.setApplications(applications);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while retrieving the application list of '" + device.getType() + "', " +
"which carries the id '" + device.getId() + "'", e);
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
Device dmsDevice = this.getDeviceManager(device.getType()). Device dmsDevice = this.getDeviceManager(device.getType()).
getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) { if (dmsDevice != null) {
@ -1010,6 +1263,37 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
for (Device device : userDevices) { for (Device device : userDevices) {
DeviceInfo info = null;
try {
DeviceManagementDAOFactory.openConnection();
info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
if (info != null) {
info.setLocation(location);
}
} catch (DeviceDetailsMgtDAOException e) {
log.error("Error occurred while retrieving advance info of '" + device.getType() +
"' that carries the id '" + device.getDeviceIdentifier() + "'");
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
device.setDeviceInfo(info);
try {
DeviceManagementDAOFactory.openConnection();
List<Application> applications = applicationDAO.getInstalledApplications(device.getId());
device.setApplications(applications);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while retrieving the application list of '" + device.getType() + "', " +
"which carries the id '" + device.getId() + "'", e);
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
Device dmsDevice = this.getDeviceManager(device.getType()). Device dmsDevice = this.getDeviceManager(device.getType()).
getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) { if (dmsDevice != null) {
@ -1067,6 +1351,37 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
for (Device device : allDevices) { for (Device device : allDevices) {
DeviceInfo info = null;
try {
DeviceManagementDAOFactory.openConnection();
info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
if (info != null) {
info.setLocation(location);
}
} catch (DeviceDetailsMgtDAOException e) {
log.error("Error occurred while retrieving advance info of '" + device.getType() +
"' that carries the id '" + device.getDeviceIdentifier() + "'");
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
device.setDeviceInfo(info);
try {
DeviceManagementDAOFactory.openConnection();
List<Application> applications = applicationDAO.getInstalledApplications(device.getId());
device.setApplications(applications);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while retrieving the application list of '" + device.getType() + "', " +
"which carries the id '" + device.getId() + "'", e);
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
Device dmsDevice = this.getDeviceManager(device.getType()). Device dmsDevice = this.getDeviceManager(device.getType()).
getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) { if (dmsDevice != null) {
@ -1101,6 +1416,37 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
for (Device device : allDevices) { for (Device device : allDevices) {
DeviceInfo info = null;
try {
DeviceManagementDAOFactory.openConnection();
info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
if (info != null) {
info.setLocation(location);
}
} catch (DeviceDetailsMgtDAOException e) {
log.error("Error occurred while retrieving advance info of '" + device.getType() +
"' that carries the id '" + device.getDeviceIdentifier() + "'");
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
device.setDeviceInfo(info);
try {
DeviceManagementDAOFactory.openConnection();
List<Application> applications = applicationDAO.getInstalledApplications(device.getId());
device.setApplications(applications);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while retrieving the application list of '" + device.getType() + "', " +
"which carries the id '" + device.getId() + "'", e);
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
Device dmsDevice = this.getDeviceManager(device.getType()). Device dmsDevice = this.getDeviceManager(device.getType()).
getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) { if (dmsDevice != null) {
@ -1180,6 +1526,37 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
for (Device device : allDevices) { for (Device device : allDevices) {
DeviceInfo info = null;
try {
DeviceManagementDAOFactory.openConnection();
info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
if (info != null) {
info.setLocation(location);
}
} catch (DeviceDetailsMgtDAOException e) {
log.error("Error occurred while retrieving advance info of '" + device.getType() +
"' that carries the id '" + device.getDeviceIdentifier() + "'");
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
device.setDeviceInfo(info);
try {
DeviceManagementDAOFactory.openConnection();
List<Application> applications = applicationDAO.getInstalledApplications(device.getId());
device.setApplications(applications);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while retrieving the application list of '" + device.getType() + "', " +
"which carries the id '" + device.getId() + "'", e);
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
Device dmsDevice = this.getDeviceManager(device.getType()). Device dmsDevice = this.getDeviceManager(device.getType()).
getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) { if (dmsDevice != null) {
@ -1214,6 +1591,37 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
for (Device device : allDevices) { for (Device device : allDevices) {
DeviceInfo info = null;
try {
DeviceManagementDAOFactory.openConnection();
info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
if (info != null) {
info.setLocation(location);
}
} catch (DeviceDetailsMgtDAOException e) {
log.error("Error occurred while retrieving advance info of '" + device.getType() +
"' that carries the id '" + device.getDeviceIdentifier() + "'");
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
device.setDeviceInfo(info);
try {
DeviceManagementDAOFactory.openConnection();
List<Application> applications = applicationDAO.getInstalledApplications(device.getId());
device.setApplications(applications);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while retrieving the application list of '" + device.getType() + "', " +
"which carries the id '" + device.getId() + "'", e);
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
Device dmsDevice = this.getDeviceManager(device.getType()). Device dmsDevice = this.getDeviceManager(device.getType()).
getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) { if (dmsDevice != null) {

@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest; import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl; import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl;
@ -49,8 +50,8 @@ public class DeviceDetails extends BaseDeviceManagementTest {
log.debug("Adding the device details to database.....!"); log.debug("Adding the device details to database.....!");
DeviceInformationManager deviceInformationManager = new DeviceInformationManagerImpl(); DeviceInformationManager deviceInformationManager = new DeviceInformationManagerImpl();
deviceInformationManager.addDeviceInfo(Utils.getDeviceInfo()); // deviceInformationManager.addDeviceInfo(Utils.getDeviceIdentifier(), Utils.getDeviceInfo());
deviceInformationManager.addDeviceLocation(Utils.getSampleDeviceLocation()); // deviceInformationManager.addDeviceLocation(Utils.getSampleDeviceLocation());
log.debug("Device details added to database.....!"); log.debug("Device details added to database.....!");
} }

@ -34,14 +34,10 @@ public class Utils {
DeviceInfo deviceInfo = new DeviceInfo(); DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setDeviceIdentifier(Utils.getDeviceIdentifier());
deviceInfo.setDeviceId(1);
deviceInfo.setIMSI("e6f236ac82537a8e"); deviceInfo.setIMSI("e6f236ac82537a8e");
deviceInfo.setSsid("FAFDA"); deviceInfo.setSsid("FAFDA");
deviceInfo.setDeviceId(1);
deviceInfo.setAvailableRAMMemory(1.24); deviceInfo.setAvailableRAMMemory(1.24);
deviceInfo.setBatteryLevel(27.3); deviceInfo.setBatteryLevel(27.3);
deviceInfo.setConnectionType("GSM"); deviceInfo.setConnectionType("GSM");
@ -96,13 +92,14 @@ public class Utils {
return deviceLocation; return deviceLocation;
} }
private static DeviceIdentifier getDeviceIdentifier(){ public static DeviceIdentifier getDeviceIdentifier(){
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setType(TestDataHolder.TEST_DEVICE_TYPE); deviceIdentifier.setType(TestDataHolder.TEST_DEVICE_TYPE);
deviceIdentifier.setId("12345"); deviceIdentifier.setId("12345");
return deviceIdentifier; return deviceIdentifier;
} }
} }

@ -81,13 +81,13 @@ public class ApplicationManagementProviderServiceTest {
ApplicationManagementProviderService appMgtProvider = new ApplicationManagerProviderServiceImpl(); ApplicationManagementProviderService appMgtProvider = new ApplicationManagerProviderServiceImpl();
try { // try {
appMgtProvider.updateApplicationListInstalledInDevice(deviceId, applications); // appMgtProvider.updateApplicationListInstalledInDevice(deviceId, applications);
} catch (ApplicationManagementException appMgtEx) { // } catch (ApplicationManagementException appMgtEx) {
String msg = "Error occurred while updating app list '" + TestDataHolder.TEST_DEVICE_TYPE + "'"; // String msg = "Error occurred while updating app list '" + TestDataHolder.TEST_DEVICE_TYPE + "'";
log.error(msg, appMgtEx); // log.error(msg, appMgtEx);
Assert.fail(msg, appMgtEx); // Assert.fail(msg, appMgtEx);
} // }
Application application5 = TestDataHolder.generateApplicationDummyData("org.wso2.app5"); Application application5 = TestDataHolder.generateApplicationDummyData("org.wso2.app5");
applications = new ArrayList<>(); applications = new ArrayList<>();
@ -95,16 +95,16 @@ public class ApplicationManagementProviderServiceTest {
applications.add(application3); applications.add(application3);
applications.add(application5); applications.add(application5);
try { // try {
appMgtProvider.updateApplicationListInstalledInDevice(deviceId, applications); // appMgtProvider.updateApplicationListInstalledInDevice(deviceId, applications);
List<Application> installedApps = appMgtProvider.getApplicationListForDevice(deviceId); // List<Application> installedApps = appMgtProvider.getApplicationListForDevice(deviceId);
log.info("Number of installed applications:" + installedApps.size()); // log.info("Number of installed applications:" + installedApps.size());
Assert.assertEquals(installedApps.size(), 3, "Num of installed applications should be two"); // Assert.assertEquals(installedApps.size(), 3, "Num of installed applications should be two");
} catch (ApplicationManagementException appMgtEx) { // } catch (ApplicationManagementException appMgtEx) {
String msg = "Error occurred while updating app list '" + TestDataHolder.TEST_DEVICE_TYPE + "'"; // String msg = "Error occurred while updating app list '" + TestDataHolder.TEST_DEVICE_TYPE + "'";
log.error(msg, appMgtEx); // log.error(msg, appMgtEx);
Assert.fail(msg, appMgtEx); // Assert.fail(msg, appMgtEx);
} // }
} }

@ -30,7 +30,7 @@ import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
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.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration; import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
import org.wso2.carbon.device.mgt.core.config.tenant.TenantConfigurationManagementServiceImpl; import org.wso2.carbon.device.mgt.core.config.tenant.PlatformConfigurationManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Policy;
@ -198,7 +198,7 @@ public class PolicyManagerUtil {
public static int getMonitoringFequency() throws PolicyManagementException { public static int getMonitoringFequency() throws PolicyManagementException {
PlatformConfigurationManagementService configMgtService = new TenantConfigurationManagementServiceImpl(); PlatformConfigurationManagementService configMgtService = new PlatformConfigurationManagementServiceImpl();
PlatformConfiguration tenantConfiguration; PlatformConfiguration tenantConfiguration;
int monitoringFrequency = 0; int monitoringFrequency = 0;
try { try {

Loading…
Cancel
Save