|
|
@ -72,7 +72,8 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = GroupManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = GroupManagementDAOFactory.getConnection();
|
|
|
|
String sql = "UPDATE DM_GROUP SET DESCRIPTION = ?, GROUP_NAME = ?, OWNER = ? WHERE ID = ? AND TENANT_ID = ?";
|
|
|
|
String sql =
|
|
|
|
|
|
|
|
"UPDATE DM_GROUP SET DESCRIPTION = ?, GROUP_NAME = ?, OWNER = ? WHERE ID = ? AND TENANT_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setString(1, deviceGroup.getDescription());
|
|
|
|
stmt.setString(1, deviceGroup.getDescription());
|
|
|
|
stmt.setString(2, deviceGroup.getName());
|
|
|
|
stmt.setString(2, deviceGroup.getName());
|
|
|
@ -230,7 +231,8 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<DeviceGroup> getGroups(GroupPaginationRequest request, List<Integer> deviceGroupIds,
|
|
|
|
public List<DeviceGroup> getGroups(GroupPaginationRequest request, List<Integer> deviceGroupIds,
|
|
|
|
int tenantId) throws GroupManagementDAOException {
|
|
|
|
int tenantId) throws GroupManagementDAOException {
|
|
|
|
if (deviceGroupIds.size() == 0) {
|
|
|
|
int deviceGroupIdsCount = deviceGroupIds.size();
|
|
|
|
|
|
|
|
if (deviceGroupIdsCount == 0) {
|
|
|
|
return new ArrayList<>();
|
|
|
|
return new ArrayList<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
@ -255,10 +257,10 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
hasOwner = true;
|
|
|
|
hasOwner = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sql += " AND ID IN (";
|
|
|
|
sql += " AND ID IN (";
|
|
|
|
for (int i = 0; i < deviceGroupIds.size() - 1; i++) {
|
|
|
|
for (int i = 0; i < deviceGroupIdsCount; i++) {
|
|
|
|
sql += "?,";
|
|
|
|
sql += (deviceGroupIdsCount - 1 != i) ? "?," : "?";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sql += "?)";
|
|
|
|
sql += ")";
|
|
|
|
if (hasLimit) {
|
|
|
|
if (hasLimit) {
|
|
|
|
sql += " LIMIT ?, ?";
|
|
|
|
sql += " LIMIT ?, ?";
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -388,7 +390,8 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = GroupManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = GroupManagementDAOFactory.getConnection();
|
|
|
|
String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER FROM DM_GROUP WHERE GROUP_NAME = ? AND TENANT_ID = ?";
|
|
|
|
String sql =
|
|
|
|
|
|
|
|
"SELECT ID, DESCRIPTION, GROUP_NAME, OWNER FROM DM_GROUP WHERE GROUP_NAME = ? AND TENANT_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setString(1, groupName);
|
|
|
|
stmt.setString(1, groupName);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
@ -469,7 +472,8 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = GroupManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = GroupManagementDAOFactory.getConnection();
|
|
|
|
String sql = "SELECT COUNT(ID) AS DEVICE_COUNT FROM DM_DEVICE_GROUP_MAP WHERE GROUP_ID = ? AND TENANT_ID = ?";
|
|
|
|
String sql =
|
|
|
|
|
|
|
|
"SELECT COUNT(ID) AS DEVICE_COUNT FROM DM_DEVICE_GROUP_MAP WHERE GROUP_ID = ? AND TENANT_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, groupId);
|
|
|
|
stmt.setInt(1, groupId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
@ -498,8 +502,10 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
|
|
|
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
|
|
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
|
|
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
|
|
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
|
|
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
|
|
|
"(SELECT gd.DEVICE_ID, gd.DESCRIPTION, gd.NAME, gd.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
|
|
|
"(SELECT gd.DEVICE_ID, gd.DESCRIPTION, gd.NAME, gd.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE " +
|
|
|
|
"(SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, d.DEVICE_TYPE_ID FROM DM_DEVICE d, (" +
|
|
|
|
"FROM " +
|
|
|
|
|
|
|
|
"(SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, d.DEVICE_TYPE_ID FROM" +
|
|
|
|
|
|
|
|
" DM_DEVICE d, (" +
|
|
|
|
"SELECT dgm.DEVICE_ID FROM DM_DEVICE_GROUP_MAP dgm WHERE dgm.GROUP_ID = ?) dgm1 " +
|
|
|
|
"SELECT dgm.DEVICE_ID FROM DM_DEVICE_GROUP_MAP dgm WHERE dgm.GROUP_ID = ?) dgm1 " +
|
|
|
|
"WHERE d.ID = dgm1.DEVICE_ID AND d.TENANT_ID = ?) gd, DM_DEVICE_TYPE t " +
|
|
|
|
"WHERE d.ID = dgm1.DEVICE_ID AND d.TENANT_ID = ?) gd, DM_DEVICE_TYPE t " +
|
|
|
|
"WHERE gd.DEVICE_TYPE_ID = t.ID) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? LIMIT ? , ?";
|
|
|
|
"WHERE gd.DEVICE_TYPE_ID = t.ID) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? LIMIT ? , ?";
|
|
|
@ -589,7 +595,8 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<DeviceGroup> getGroups(String[] roles, int tenantId) throws GroupManagementDAOException {
|
|
|
|
public List<DeviceGroup> getGroups(String[] roles, int tenantId) throws GroupManagementDAOException {
|
|
|
|
if (roles.length == 0) {
|
|
|
|
int rolesCount = roles.length;
|
|
|
|
|
|
|
|
if (rolesCount == 0) {
|
|
|
|
return new ArrayList<>();
|
|
|
|
return new ArrayList<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
@ -600,16 +607,16 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER FROM DM_GROUP g, " +
|
|
|
|
String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER FROM DM_GROUP g, " +
|
|
|
|
"(SELECT GROUP_ID FROM DM_ROLE_GROUP_MAP WHERE ROLE IN (";
|
|
|
|
"(SELECT GROUP_ID FROM DM_ROLE_GROUP_MAP WHERE ROLE IN (";
|
|
|
|
|
|
|
|
|
|
|
|
int index = 1;
|
|
|
|
int index = 0;
|
|
|
|
while (index++ <= roles.length) {
|
|
|
|
while (index++ < rolesCount) {
|
|
|
|
sql += "?";
|
|
|
|
sql += (rolesCount - 1 != index) ? "?," : "?";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sql += ")) gr WHERE g.ID = gr.GROUP_ID AND TENANT_ID = ? GROUP BY g.ID";
|
|
|
|
sql += ")) gr WHERE g.ID = gr.GROUP_ID AND TENANT_ID = ? GROUP BY g.ID";
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
index = 1;
|
|
|
|
index = 0;
|
|
|
|
while (index++ <= roles.length) {
|
|
|
|
while (index++ < rolesCount) {
|
|
|
|
stmt.setString(index, roles[index++]);
|
|
|
|
stmt.setString(index, roles[index - 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stmt.setInt(index, tenantId);
|
|
|
|
stmt.setInt(index, tenantId);
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
@ -637,15 +644,16 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
Connection conn = GroupManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = GroupManagementDAOFactory.getConnection();
|
|
|
|
String sql = "SELECT ID FROM DM_GROUP g, (SELECT GROUP_ID FROM DM_ROLE_GROUP_MAP WHERE ROLE IN (";
|
|
|
|
String sql = "SELECT ID FROM DM_GROUP g, (SELECT GROUP_ID FROM DM_ROLE_GROUP_MAP WHERE ROLE IN (";
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < roles.length - 1; i++) {
|
|
|
|
int rolesCount = roles.length;
|
|
|
|
sql += "?,";
|
|
|
|
for (int i = 0; i < rolesCount; i++) {
|
|
|
|
|
|
|
|
sql += (rolesCount - 1 != i) ? "?," : "?";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sql += "?)) gr WHERE g.ID = gr.GROUP_ID AND TENANT_ID = ? GROUP BY g.ID";
|
|
|
|
sql += ")) gr WHERE g.ID = gr.GROUP_ID AND TENANT_ID = ? GROUP BY g.ID";
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
int index = 1;
|
|
|
|
int index = 0;
|
|
|
|
while (index++ <= roles.length) {
|
|
|
|
while (index++ < rolesCount) {
|
|
|
|
stmt.setString(index, roles[index++]);
|
|
|
|
stmt.setString(index, roles[index - 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stmt.setInt(index, tenantId);
|
|
|
|
stmt.setInt(index, tenantId);
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
@ -663,7 +671,8 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getGroupsCount(String[] roles, int tenantId) throws GroupManagementDAOException {
|
|
|
|
public int getGroupsCount(String[] roles, int tenantId) throws GroupManagementDAOException {
|
|
|
|
if (roles.length == 0) {
|
|
|
|
int rolesCount = roles.length;
|
|
|
|
|
|
|
|
if (rolesCount == 0) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
@ -672,17 +681,15 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
Connection conn = GroupManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = GroupManagementDAOFactory.getConnection();
|
|
|
|
String sql = "SELECT COUNT(ID) AS GROUP_COUNT FROM DM_GROUP g, " +
|
|
|
|
String sql = "SELECT COUNT(ID) AS GROUP_COUNT FROM DM_GROUP g, " +
|
|
|
|
"(SELECT GROUP_ID FROM DM_ROLE_GROUP_MAP WHERE ROLE IN (";
|
|
|
|
"(SELECT GROUP_ID FROM DM_ROLE_GROUP_MAP WHERE ROLE IN (";
|
|
|
|
|
|
|
|
for (int i = 0; i < rolesCount; i++) {
|
|
|
|
int index = 1;
|
|
|
|
sql += (rolesCount - 1 != i) ? "?," : "?";
|
|
|
|
while (index++ <= roles.length) {
|
|
|
|
|
|
|
|
sql += "?";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sql += ")) gr WHERE g.ID = gr.GROUP_ID AND TENANT_ID = ? GROUP BY g.ID";
|
|
|
|
sql += ")) gr WHERE g.ID = gr.GROUP_ID AND TENANT_ID = ? GROUP BY g.ID";
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
index = 1;
|
|
|
|
int index = 0;
|
|
|
|
while (index++ <= roles.length) {
|
|
|
|
while (index++ < rolesCount) {
|
|
|
|
stmt.setString(index, roles[index++]);
|
|
|
|
stmt.setString(index, roles[index - 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stmt.setInt(index, tenantId);
|
|
|
|
stmt.setInt(index, tenantId);
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|