|
|
|
@ -18,9 +18,12 @@
|
|
|
|
|
|
|
|
|
|
package org.wso2.carbon.device.mgt.core.dao.impl;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.apache.solr.common.StringUtils;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.GroupDAO;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOException;
|
|
|
|
@ -36,12 +39,15 @@ import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.StringJoiner;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class represents implementation of GroupDAO
|
|
|
|
|
*/
|
|
|
|
|
public abstract class AbstractGroupDAOImpl implements GroupDAO {
|
|
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(AbstractGroupDAOImpl.class);
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int addGroup(DeviceGroup deviceGroup, int tenantId) throws GroupManagementDAOException {
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
@ -809,4 +815,52 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
|
|
|
|
|
}
|
|
|
|
|
return devices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Device> getGroupUnassignedDevices(PaginationRequest paginationRequest,
|
|
|
|
|
List<String> groupNames)
|
|
|
|
|
throws GroupManagementDAOException {
|
|
|
|
|
List<Device> groupUnassignedDeviceList;
|
|
|
|
|
try {
|
|
|
|
|
Connection connection = GroupManagementDAOFactory.getConnection();
|
|
|
|
|
StringJoiner sql = new StringJoiner(",",
|
|
|
|
|
"SELECT DEVICE.ID AS DEVICE_ID, " +
|
|
|
|
|
"DEVICE.NAME AS DEVICE_NAME, " +
|
|
|
|
|
"DEVICE_TYPE.NAME AS DEVICE_TYPE, " +
|
|
|
|
|
"DEVICE.DESCRIPTION, " +
|
|
|
|
|
"DEVICE.DEVICE_IDENTIFICATION, " +
|
|
|
|
|
"ENROLMENT.ID AS ENROLMENT_ID, " +
|
|
|
|
|
"ENROLMENT.OWNER, " +
|
|
|
|
|
"ENROLMENT.OWNERSHIP, " +
|
|
|
|
|
"ENROLMENT.DATE_OF_ENROLMENT, " +
|
|
|
|
|
"ENROLMENT.DATE_OF_LAST_UPDATE, " +
|
|
|
|
|
"ENROLMENT.STATUS " +
|
|
|
|
|
"FROM DM_DEVICE AS DEVICE, DM_DEVICE_TYPE AS DEVICE_TYPE, DM_ENROLMENT " +
|
|
|
|
|
"AS ENROLMENT " +
|
|
|
|
|
"WHERE DEVICE.ID NOT IN " +
|
|
|
|
|
"(SELECT DEVICE_ID " +
|
|
|
|
|
"FROM DM_DEVICE_GROUP_MAP " +
|
|
|
|
|
"WHERE GROUP_ID IN (SELECT ID FROM DM_GROUP WHERE GROUP_NAME NOT IN (",
|
|
|
|
|
")) GROUP BY DEVICE_ID)");
|
|
|
|
|
|
|
|
|
|
groupNames.stream().map(e -> "?").forEach(sql::add);
|
|
|
|
|
try (PreparedStatement stmt = connection.prepareStatement(String.valueOf(sql))) {
|
|
|
|
|
int index = 1;
|
|
|
|
|
for (String groupName : groupNames) {
|
|
|
|
|
stmt.setString(index++, groupName);
|
|
|
|
|
}
|
|
|
|
|
try (ResultSet resultSet = stmt.executeQuery()) {
|
|
|
|
|
groupUnassignedDeviceList = new ArrayList<>();
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
|
groupUnassignedDeviceList.add(DeviceManagementDAOUtil.loadDevice(resultSet));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
String msg = "Error occurred while retrieving information of group unassigned devices";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new GroupManagementDAOException(msg,e);
|
|
|
|
|
}
|
|
|
|
|
return groupUnassignedDeviceList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|