|
|
|
@ -43,6 +43,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocationHistory;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.DevicePropertyInfo;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceData;
|
|
|
|
@ -53,6 +54,7 @@ import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.geo.GeoCluster;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.report.mgt.Constants;
|
|
|
|
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
@ -1791,6 +1793,107 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Device> getDevicesExpiredByOSVersion(PaginationRequest request, int tenantId)
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
try {
|
|
|
|
|
Long osBuildDate = (Long) request.getProperty(Constants.OS_BUILD_DATE);
|
|
|
|
|
Connection conn = getConnection();
|
|
|
|
|
String sql = "SELECT " +
|
|
|
|
|
"dt.NAME AS DEVICE_TYPE, " +
|
|
|
|
|
"d.ID AS DEVICE_ID, " +
|
|
|
|
|
"d.NAME AS DEVICE_NAME, " +
|
|
|
|
|
"d.DESCRIPTION, " +
|
|
|
|
|
"d.DEVICE_IDENTIFICATION, " +
|
|
|
|
|
"dd.OS_VERSION, " +
|
|
|
|
|
"dd.OS_BUILD_DATE, " +
|
|
|
|
|
"e.ID AS ENROLMENT_ID, " +
|
|
|
|
|
"e.OWNER, " +
|
|
|
|
|
"e.OWNERSHIP, " +
|
|
|
|
|
"e.STATUS, " +
|
|
|
|
|
"e.DATE_OF_LAST_UPDATE, " +
|
|
|
|
|
"e.DATE_OF_ENROLMENT " +
|
|
|
|
|
"FROM DM_DEVICE d, " +
|
|
|
|
|
"DM_DEVICE_DETAIL dd, " +
|
|
|
|
|
"DM_ENROLMENT e, " +
|
|
|
|
|
"(SELECT ID, NAME " +
|
|
|
|
|
"FROM DM_DEVICE_TYPE " +
|
|
|
|
|
"WHERE NAME = ? " +
|
|
|
|
|
"AND PROVIDER_TENANT_ID = ?) dt " +
|
|
|
|
|
"WHERE dt.ID = d.DEVICE_TYPE_ID " +
|
|
|
|
|
"AND d.ID = e.DEVICE_ID " +
|
|
|
|
|
"AND d.ID = dd.DEVICE_ID " +
|
|
|
|
|
"AND dd.OS_BUILD_DATE < ? " +
|
|
|
|
|
"LIMIT ? OFFSET ?";
|
|
|
|
|
|
|
|
|
|
try (PreparedStatement ps = conn.prepareStatement(sql)) {
|
|
|
|
|
int paramIDx = 1;
|
|
|
|
|
ps.setString(paramIDx++, request.getDeviceType());
|
|
|
|
|
ps.setInt(paramIDx++, tenantId);
|
|
|
|
|
ps.setLong(paramIDx++, osBuildDate);
|
|
|
|
|
ps.setInt(paramIDx++, request.getRowCount());
|
|
|
|
|
ps.setInt(paramIDx, request.getStartIndex());
|
|
|
|
|
|
|
|
|
|
try (ResultSet rs = ps.executeQuery()) {
|
|
|
|
|
List<Device> devices = new ArrayList<>();
|
|
|
|
|
DeviceInfo deviceInfo = new DeviceInfo();
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
|
|
|
|
deviceInfo.setOsVersion(rs.getString(Constants.OS_VERSION));
|
|
|
|
|
deviceInfo.setOsBuildDate(rs.getString(Constants.OS_BUILD_DATE));
|
|
|
|
|
device.setDeviceInfo(deviceInfo);
|
|
|
|
|
devices.add(device);
|
|
|
|
|
}
|
|
|
|
|
return devices;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
String msg = "Error occurred while building or executing queries to retrieve information " +
|
|
|
|
|
"of devices with an older OS build date";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getCountOfDeviceExpiredByOSVersion(String deviceType, long osBuildDate, int tenantId)
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
try {
|
|
|
|
|
Connection conn = getConnection();
|
|
|
|
|
String sql = "SELECT " +
|
|
|
|
|
"COUNT(dd.DEVICE_ID) AS DEVICE_COUNT " +
|
|
|
|
|
"FROM DM_DEVICE d, " +
|
|
|
|
|
"DM_DEVICE_DETAIL dd, " +
|
|
|
|
|
"(SELECT ID " +
|
|
|
|
|
"FROM DM_DEVICE_TYPE " +
|
|
|
|
|
"WHERE NAME = ? " +
|
|
|
|
|
"AND PROVIDER_TENANT_ID = ?) dt " +
|
|
|
|
|
"WHERE d.DEVICE_TYPE_ID = dt.ID " +
|
|
|
|
|
"AND d.ID = dd.DEVICE_ID " +
|
|
|
|
|
"AND dd.OS_BUILD_DATE < ?";
|
|
|
|
|
|
|
|
|
|
try (PreparedStatement ps = conn.prepareStatement(sql)) {
|
|
|
|
|
int paramIdx = 1;
|
|
|
|
|
ps.setString(paramIdx++, deviceType);
|
|
|
|
|
ps.setInt(paramIdx++, tenantId);
|
|
|
|
|
ps.setLong(paramIdx, osBuildDate);
|
|
|
|
|
|
|
|
|
|
try (ResultSet rs = ps.executeQuery()) {
|
|
|
|
|
int deviceCount = 0;
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
deviceCount = rs.getInt("DEVICE_COUNT");
|
|
|
|
|
}
|
|
|
|
|
return deviceCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
String msg = "Error occurred while building or executing queries to retrieve the count " +
|
|
|
|
|
"of devices with an older OS build date";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
* This method removes records of a given list of devices from the DM_DEVICE_DETAIL table
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|