Fix issue in initial device info persistence

feature/appm-store/pbac
Charitha Goonetilleke 5 years ago
parent 52b45abb16
commit 50a7721926

@ -156,7 +156,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
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();
@ -169,6 +169,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
if (rs.next()) { if (rs.next()) {
// deviceInfo.setIMEI(rs.getString("IMEI")); // deviceInfo.setIMEI(rs.getString("IMEI"));
// deviceInfo.setIMSI(rs.getString("IMSI")); // deviceInfo.setIMSI(rs.getString("IMSI"));
deviceInfo = new DeviceInfo();
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
deviceInfo.setVendor(rs.getString("VENDOR")); deviceInfo.setVendor(rs.getString("VENDOR"));
deviceInfo.setOsVersion(rs.getString("OS_VERSION")); deviceInfo.setOsVersion(rs.getString("OS_VERSION"));

@ -92,7 +92,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
deviceDetailsDAO.addDeviceInformation(device.getId(), device.getEnrolmentInfo().getId(), deviceInfo); deviceDetailsDAO.addDeviceInformation(device.getId(), device.getEnrolmentInfo().getId(), deviceInfo);
newDeviceInfo = deviceInfo; newDeviceInfo = deviceInfo;
} }
if (previousDeviceProperties == null) { if (previousDeviceProperties.isEmpty()) {
deviceDetailsDAO.addDeviceProperties(newDeviceInfo.getDeviceDetailsMap(), device.getId(), deviceDetailsDAO.addDeviceProperties(newDeviceInfo.getDeviceDetailsMap(), device.getId(),
device.getEnrolmentInfo().getId()); device.getEnrolmentInfo().getId());
} else { } else {

@ -116,6 +116,7 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dao.EnrollmentDAO; import org.wso2.carbon.device.mgt.core.dao.EnrollmentDAO;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
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.dao.DeviceDetailsDAO; 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.device.details.mgt.dao.DeviceDetailsMgtDAOException;
@ -169,9 +170,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
private EnrollmentDAO enrollmentDAO; private EnrollmentDAO enrollmentDAO;
private ApplicationDAO applicationDAO; private ApplicationDAO applicationDAO;
private DeviceManagementPluginRepository pluginRepository; private DeviceManagementPluginRepository pluginRepository;
private DeviceInformationManager deviceInformationManager;
public DeviceManagementProviderServiceImpl() { public DeviceManagementProviderServiceImpl() {
this.pluginRepository = new DeviceManagementPluginRepository(); this.pluginRepository = new DeviceManagementPluginRepository();
this.deviceInformationManager = new DeviceInformationManagerImpl();
initDataAccessObjects(); initDataAccessObjects();
/* Registering a listener to retrieve events when some device management service plugin is installed after /* Registering a listener to retrieve events when some device management service plugin is installed after
* the component is done getting initialized */ * the component is done getting initialized */
@ -386,6 +389,16 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
sendNotification(device); sendNotification(device);
} }
extractDeviceLocationToUpdate(device); extractDeviceLocationToUpdate(device);
try {
if (device.getDeviceInfo() != null) {
deviceInformationManager.addDeviceInfo(device, device.getDeviceInfo());
}
} catch (DeviceDetailsMgtException e) {
//This is not logging as error, neither throwing an exception as this is not an exception in main
// business logic.
String msg = "Error occurred while adding device info";
log.warn(msg, e);
}
return status; return status;
} }
@ -3414,7 +3427,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
deviceLocation.setDistance(Double.parseDouble(distance)); deviceLocation.setDistance(Double.parseDouble(distance));
deviceLocation.setSpeed(Float.parseFloat(speed)); deviceLocation.setSpeed(Float.parseFloat(speed));
deviceLocation.setBearing(Float.parseFloat(bearing)); deviceLocation.setBearing(Float.parseFloat(bearing));
DeviceInformationManager deviceInformationManager = new DeviceInformationManagerImpl();
deviceInformationManager.addDeviceLocation(device, deviceLocation); deviceInformationManager.addDeviceLocation(device, deviceLocation);
} catch (Exception e) { } catch (Exception e) {
//We are not failing the execution since this is not critical for the functionality. But logging as //We are not failing the execution since this is not critical for the functionality. But logging as

@ -88,7 +88,7 @@ public class ProcessorImplTest extends BaseDeviceManagementTest {
context.setConditions(conditions); context.setConditions(conditions);
ProcessorImpl processor = new ProcessorImpl(); ProcessorImpl processor = new ProcessorImpl();
List<Device> devices = processor.execute(context); List<Device> devices = processor.execute(context);
Assert.assertEquals(5, devices.size(), "There should be exactly 5 devices with matching search criteria"); Assert.assertEquals(devices.size(), 5, "There should be exactly 5 devices with matching search criteria");
} }
@Test (description = "Search for device with or condition") @Test (description = "Search for device with or condition")
@ -106,7 +106,7 @@ public class ProcessorImplTest extends BaseDeviceManagementTest {
context.setConditions(conditions); context.setConditions(conditions);
ProcessorImpl processor = new ProcessorImpl(); ProcessorImpl processor = new ProcessorImpl();
List<Device> devices = processor.execute(context); List<Device> devices = processor.execute(context);
Assert.assertEquals(5, devices.size(), "There should be exactly 5 devices with matching search criteria"); Assert.assertEquals(devices.size(), 5, "There should be exactly 5 devices with matching search criteria");
} }
@Test (description = "Search for device with wrong condition") @Test (description = "Search for device with wrong condition")

Loading…
Cancel
Save