device id detail add for root organizations

pull/238/head
Isuri Mendis 12 months ago
parent ea1ac9555c
commit dd92e5dc4c

@ -42,6 +42,7 @@ import java.util.Set;
import static io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dao.util.DeviceOrganizationDaoUtil.getDeviceFromResultSet;
import static io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dao.util.DeviceOrganizationDaoUtil.loadDeviceOrganization;
import static io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dao.util.DeviceOrganizationDaoUtil.loadDeviceOrganizationWithDeviceDetails;
/**
* Implementation of the DeviceOrganizationDAO interface.
@ -323,9 +324,12 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
List<DeviceOrganization> deviceOrganizations = new ArrayList<>();
try {
Connection conn = ConnectionManagerUtil.getDBConnection();
String sql = "SELECT * FROM DM_DEVICE_ORGANIZATION " +
"WHERE (PARENT_DEVICE_ID IS NULL AND " +
"DEVICE_ID NOT IN " +
String sql = "SELECT D.ID, D.NAME, D.DESCRIPTION, D.DEVICE_IDENTIFICATION, DT.NAME AS DEVICE_TYPE_NAME, " +
"DO.ORGANIZATION_ID, DO.DEVICE_ID, DO.PARENT_DEVICE_ID, DO.DEVICE_ORGANIZATION_META ," +
"DO.LAST_UPDATED_TIMESTAMP FROM DM_DEVICE_ORGANIZATION DO JOIN DM_DEVICE D ON D.ID = DO.DEVICE_ID " +
"JOIN DM_DEVICE_TYPE DT ON D.DEVICE_TYPE_ID = DT.ID " +
"WHERE (DO.PARENT_DEVICE_ID IS NULL AND " +
"DO.DEVICE_ID NOT IN " +
"(SELECT DEVICE_ID FROM DM_DEVICE_ORGANIZATION " +
"WHERE PARENT_DEVICE_ID IS NOT NULL)) " +
"LIMIT ? OFFSET ?";
@ -335,7 +339,7 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
stmt.setInt(2, request.getOffSet());
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
DeviceOrganization deviceOrganization = loadDeviceOrganization(rs);
DeviceOrganization deviceOrganization = loadDeviceOrganizationWithDeviceDetails(rs);
deviceOrganizations.add(deviceOrganization);
}
}

@ -38,6 +38,21 @@ public class DeviceOrganizationDaoUtil {
return deviceOrganization;
}
public static DeviceOrganization loadDeviceOrganizationWithDeviceDetails(ResultSet rs) throws SQLException {
DeviceOrganization deviceOrganization = new DeviceOrganization();
deviceOrganization.setOrganizationId(rs.getInt("ORGANIZATION_ID"));
deviceOrganization.setDeviceId(rs.getInt("DEVICE_ID"));
if (rs.getInt("PARENT_DEVICE_ID") != 0) {
deviceOrganization.setParentDeviceId(rs.getInt("PARENT_DEVICE_ID"));
} else {
deviceOrganization.setParentDeviceId(null);
}
deviceOrganization.setDeviceOrganizationMeta(rs.getString("DEVICE_ORGANIZATION_META"));
deviceOrganization.setUpdateTime(rs.getDate("LAST_UPDATED_TIMESTAMP"));
deviceOrganization.setDevice(getDeviceDetails(rs));
return deviceOrganization;
}
/**
* Helper method to create a DeviceNode object from a ResultSet
*
@ -48,14 +63,18 @@ public class DeviceOrganizationDaoUtil {
public static DeviceNode getDeviceFromResultSet(ResultSet rs) throws SQLException {
DeviceNode node = new DeviceNode();
node.setDeviceId(rs.getInt("ID"));
node.setDevice(getDeviceDetails(rs));
return node;
}
public static Device getDeviceDetails(ResultSet rs) throws SQLException {
Device device = new Device();
device.setId(rs.getInt("ID"));
device.setDescription(rs.getString("DESCRIPTION"));
device.setName(rs.getString("NAME"));
device.setType(rs.getString("DEVICE_TYPE_NAME"));
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
node.setDevice(device);
return node;
return device;
}
}

@ -19,6 +19,8 @@
package io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import java.util.Date;
import java.util.Objects;
@ -30,6 +32,7 @@ public class DeviceOrganization {
private int organizationId;
private int deviceId;
private Device device;
private Integer parentDeviceId;
private String deviceOrganizationMeta;
private Date updateTime;
@ -50,6 +53,13 @@ public class DeviceOrganization {
this.deviceId = deviceId;
}
public Device getDevice() {
return device;
}
public void setDevice(Device device) {
this.device = device;
}
public Integer getParentDeviceId() {
return parentDeviceId;
}

@ -275,6 +275,7 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
log.info("deviceID = " + organization.getDeviceId());
log.info("parentDeviceID = " + organization.getParentDeviceId());
log.info("updateTime = " + organization.getUpdateTime());
log.info("deviceSerial = " + organization.getDevice().getDeviceIdentifier());
log.info("----------------------------------------------");
}
Assert.assertNotNull(organizations, "List of organizations cannot be null");
@ -292,6 +293,7 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
log.info("deviceID = " + organization.getDeviceId());
log.info("parentDeviceID = " + organization.getParentDeviceId());
log.info("updateTime = " + organization.getUpdateTime());
log.info("deviceSerial = " + organization.getDevice().getDeviceIdentifier());
log.info("----------------------------------------------");
}
Assert.assertNotNull(organizations, "List of organizations cannot be null");

Loading…
Cancel
Save