|
|
@ -25,8 +25,6 @@ import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
|
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
|
|
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
|
|
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
|
|
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
|
|
|
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
|
|
@ -34,11 +32,21 @@ import org.wso2.carbon.device.mgt.core.dao.ApplicationDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
|
|
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.internal.DeviceManagementDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.Constants;
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.*;
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.InvalidOperatorException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.Processor;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.QueryBuilder;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.QueryHolder;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.ResultSetAggregator;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.ValueType;
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.dao.SearchDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.dao.SearchDAOException;
|
|
|
|
|
|
|
|
|
|
|
|
import java.sql.*;
|
|
|
|
import java.sql.Array;
|
|
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -47,17 +55,9 @@ import java.util.Map;
|
|
|
|
public class ProcessorImpl implements Processor {
|
|
|
|
public class ProcessorImpl implements Processor {
|
|
|
|
private ApplicationDAO applicationDAO;
|
|
|
|
private ApplicationDAO applicationDAO;
|
|
|
|
private static final Log log = LogFactory.getLog(ProcessorImpl.class);
|
|
|
|
private static final Log log = LogFactory.getLog(ProcessorImpl.class);
|
|
|
|
private DeviceAccessAuthorizationService deviceAccessAuthorizationService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ProcessorImpl() {
|
|
|
|
public ProcessorImpl() {
|
|
|
|
applicationDAO = DeviceManagementDAOFactory.getApplicationDAO();
|
|
|
|
applicationDAO = DeviceManagementDAOFactory.getApplicationDAO();
|
|
|
|
deviceAccessAuthorizationService = DeviceManagementDataHolder.getInstance()
|
|
|
|
|
|
|
|
.getDeviceAccessAuthorizationService();
|
|
|
|
|
|
|
|
if (deviceAccessAuthorizationService == null) {
|
|
|
|
|
|
|
|
String msg = "DeviceAccessAuthorization service has not initialized.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new IllegalStateException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -115,35 +115,10 @@ public class ProcessorImpl implements Processor {
|
|
|
|
devices.put(Constants.LOCATION, locationDevices);
|
|
|
|
devices.put(Constants.LOCATION, locationDevices);
|
|
|
|
|
|
|
|
|
|
|
|
List<Device> finalDevices = aggregator.aggregate(devices);
|
|
|
|
List<Device> finalDevices = aggregator.aggregate(devices);
|
|
|
|
finalDevices = authorizedDevices(finalDevices);
|
|
|
|
|
|
|
|
this.setApplicationListOfDevices(finalDevices);
|
|
|
|
this.setApplicationListOfDevices(finalDevices);
|
|
|
|
return finalDevices;
|
|
|
|
return finalDevices;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* To get the authorized devices for a particular user
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param devices Devices that satisfy search results
|
|
|
|
|
|
|
|
* @return Devices that satisfy search results and authorized to be viewed by particular user
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private List<Device> authorizedDevices(List<Device> devices) throws SearchMgtException {
|
|
|
|
|
|
|
|
List<Device> filteredList = new ArrayList<>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
for (Device device : devices) {
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(),
|
|
|
|
|
|
|
|
device.getType());
|
|
|
|
|
|
|
|
if (deviceAccessAuthorizationService != null && deviceAccessAuthorizationService
|
|
|
|
|
|
|
|
.isUserAuthorized(deviceIdentifier)) {
|
|
|
|
|
|
|
|
filteredList.add(device);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return filteredList;
|
|
|
|
|
|
|
|
} catch (DeviceAccessAuthorizationException e) {
|
|
|
|
|
|
|
|
log.error("Error getting authorized search results for logged in user");
|
|
|
|
|
|
|
|
throw new SearchMgtException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Device> getUpdatedDevices(long epochTime) throws SearchMgtException {
|
|
|
|
public List<Device> getUpdatedDevices(long epochTime) throws SearchMgtException {
|
|
|
|
|
|
|
|
|
|
|
@ -256,7 +231,6 @@ public class ProcessorImpl implements Processor {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
List<Device> devices = new ArrayList<>();
|
|
|
|
List<Device> devices = new ArrayList<>();
|
|
|
|
Map<Integer, Integer> devs = new HashMap<>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
stmt = conn.prepareStatement(queryHolder.getQuery());
|
|
|
|
stmt = conn.prepareStatement(queryHolder.getQuery());
|
|
|
@ -281,59 +255,57 @@ public class ProcessorImpl implements Processor {
|
|
|
|
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
if (!devs.containsKey(rs.getInt("ID"))) {
|
|
|
|
Device device = new Device();
|
|
|
|
Device device = new Device();
|
|
|
|
device.setId(rs.getInt("ID"));
|
|
|
|
device.setId(rs.getInt("ID"));
|
|
|
|
device.setDescription(rs.getString("DESCRIPTION"));
|
|
|
|
device.setDescription(rs.getString("DESCRIPTION"));
|
|
|
|
device.setName(rs.getString("NAME"));
|
|
|
|
device.setName(rs.getString("NAME"));
|
|
|
|
device.setType(rs.getString("DEVICE_TYPE_NAME"));
|
|
|
|
device.setType(rs.getString("DEVICE_TYPE_NAME"));
|
|
|
|
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
|
|
|
|
|
|
|
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
|
|
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
|
|
|
enrolmentInfo.setId(rs.getInt("ENROLLMENT_ID"));
|
|
|
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.valueOf(rs.getString("DE_STATUS")));
|
|
|
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.valueOf(rs.getString("DE_STATUS")));
|
|
|
|
enrolmentInfo.setOwner(rs.getString("OWNER"));
|
|
|
|
enrolmentInfo.setOwner(rs.getString("OWNER"));
|
|
|
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.valueOf(rs.getString("OWNERSHIP")));
|
|
|
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.valueOf(rs.getString("OWNERSHIP")));
|
|
|
|
device.setEnrolmentInfo(enrolmentInfo);
|
|
|
|
device.setEnrolmentInfo(enrolmentInfo);
|
|
|
|
|
|
|
|
|
|
|
|
DeviceIdentifier identifier = new DeviceIdentifier();
|
|
|
|
DeviceIdentifier identifier = new DeviceIdentifier();
|
|
|
|
identifier.setType(rs.getString("DEVICE_TYPE_NAME"));
|
|
|
|
identifier.setType(rs.getString("DEVICE_TYPE_NAME"));
|
|
|
|
identifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
identifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
|
|
|
|
|
|
|
|
DeviceInfo deviceInfo = new DeviceInfo();
|
|
|
|
DeviceInfo deviceInfo = new DeviceInfo();
|
|
|
|
deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY"));
|
|
|
|
deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY"));
|
|
|
|
deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL"));
|
|
|
|
deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL"));
|
|
|
|
deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE"));
|
|
|
|
deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE"));
|
|
|
|
deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE"));
|
|
|
|
deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE"));
|
|
|
|
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
|
|
|
|
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
|
|
|
|
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY"));
|
|
|
|
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY"));
|
|
|
|
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
|
|
|
|
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
|
|
|
|
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
|
|
|
|
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
|
|
|
|
deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
|
|
|
|
deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
|
|
|
|
deviceInfo.setOsVersion(rs.getString("OS_VERSION"));
|
|
|
|
deviceInfo.setOsVersion(rs.getString("OS_VERSION"));
|
|
|
|
deviceInfo.setOsBuildDate(rs.getString("OS_BUILD_DATE"));
|
|
|
|
deviceInfo.setOsBuildDate(rs.getString("OS_BUILD_DATE"));
|
|
|
|
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN"));
|
|
|
|
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN"));
|
|
|
|
deviceInfo.setSsid(rs.getString("SSID"));
|
|
|
|
deviceInfo.setSsid(rs.getString("SSID"));
|
|
|
|
deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY"));
|
|
|
|
deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY"));
|
|
|
|
deviceInfo.setVendor(rs.getString("VENDOR"));
|
|
|
|
deviceInfo.setVendor(rs.getString("VENDOR"));
|
|
|
|
deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP")));
|
|
|
|
deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP")));
|
|
|
|
|
|
|
|
|
|
|
|
DeviceLocation deviceLocation = new DeviceLocation();
|
|
|
|
DeviceLocation deviceLocation = new DeviceLocation();
|
|
|
|
deviceLocation.setLatitude(rs.getDouble("LATITUDE"));
|
|
|
|
deviceLocation.setLatitude(rs.getDouble("LATITUDE"));
|
|
|
|
deviceLocation.setLongitude(rs.getDouble("LONGITUDE"));
|
|
|
|
deviceLocation.setLongitude(rs.getDouble("LONGITUDE"));
|
|
|
|
deviceLocation.setStreet1(rs.getString("STREET1"));
|
|
|
|
deviceLocation.setStreet1(rs.getString("STREET1"));
|
|
|
|
deviceLocation.setStreet2(rs.getString("STREET2"));
|
|
|
|
deviceLocation.setStreet2(rs.getString("STREET2"));
|
|
|
|
deviceLocation.setCity(rs.getString("CITY"));
|
|
|
|
deviceLocation.setCity(rs.getString("CITY"));
|
|
|
|
deviceLocation.setState(rs.getString("STATE"));
|
|
|
|
deviceLocation.setState(rs.getString("STATE"));
|
|
|
|
deviceLocation.setZip(rs.getString("ZIP"));
|
|
|
|
deviceLocation.setZip(rs.getString("ZIP"));
|
|
|
|
deviceLocation.setCountry(rs.getString("COUNTRY"));
|
|
|
|
deviceLocation.setCountry(rs.getString("COUNTRY"));
|
|
|
|
deviceLocation.setDeviceId(rs.getInt("ID"));
|
|
|
|
deviceLocation.setDeviceId(rs.getInt("ID"));
|
|
|
|
deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP")));
|
|
|
|
deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP")));
|
|
|
|
|
|
|
|
|
|
|
|
deviceInfo.setLocation(deviceLocation);
|
|
|
|
deviceInfo.setLocation(deviceLocation);
|
|
|
|
device.setDeviceInfo(deviceInfo);
|
|
|
|
device.setDeviceInfo(deviceInfo);
|
|
|
|
devices.add(device);
|
|
|
|
devices.add(device);
|
|
|
|
devs.put(device.getId(), device.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new SearchDAOException("Error occurred while aquiring the device details.", e);
|
|
|
|
throw new SearchDAOException("Error occurred while aquiring the device details.", e);
|
|
|
|