Fixing the issue where Enrollment ID is not inclueded in some tables.

Fixing the issue where enrolment id is not included in the device-info, device-details, device-location, device-application-mapping tables. This fixes the https://github.com/wso2/product-iots/issues/1707
revert-70aa11f8
geethkokila 7 years ago
parent 8895d0f94d
commit 1d605d0921

@ -222,7 +222,8 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
}
}
DeviceManagementDAOFactory.beginTransaction();
applicationMappingDAO.removeApplicationMapping(device.getId(), appIdsToRemove, tenantId);
applicationMappingDAO.removeApplicationMapping(device.getId(), device.getEnrolmentInfo().getId(),
appIdsToRemove, tenantId);
Application installedApp;
List<Integer> applicationIds = new ArrayList<>();
List<Application> applicationsToMap = new ArrayList<>();
@ -263,7 +264,8 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
if (log.isDebugEnabled()) {
log.debug("num of app Ids:" + applicationIds.size());
}
applicationMappingDAO.addApplicationMappingsWithApps(device.getId(), applicationsToMap, tenantId);
applicationMappingDAO.addApplicationMappingsWithApps(device.getId(), device.getEnrolmentInfo().getId(),
applicationsToMap, tenantId);
if (log.isDebugEnabled()) {
log.debug("num of remove app Ids:" + appIdsToRemove.size());
@ -312,7 +314,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
}
try {
DeviceManagementDAOFactory.openConnection();
return applicationDAO.getInstalledApplications(device.getId());
return applicationDAO.getInstalledApplications(device.getId(), device.getEnrolmentInfo().getId());
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while fetching the Application List of device " + deviceId.toString();
log.error(msg, e);

@ -34,7 +34,8 @@ public interface ApplicationDAO {
Application getApplication(String identifier, String version,int tenantId) throws DeviceManagementDAOException;
Application getApplication(String identifier, String version, int deviceId, int tenantId) throws DeviceManagementDAOException;
Application getApplication(String identifier, String version, int deviceId, int enrolmentId, int tenantId)
throws DeviceManagementDAOException;
List<Application> getInstalledApplications(int deviceId) throws DeviceManagementDAOException;
List<Application> getInstalledApplications(int deviceId, int enrolmentId) throws DeviceManagementDAOException;
}

@ -29,9 +29,9 @@ public interface ApplicationMappingDAO {
void addApplicationMappings(int deviceId, List<Integer> applicationIds, int tenantId)
throws DeviceManagementDAOException;
void addApplicationMappingsWithApps(int deviceId, List<Application> applications, int tenantId)
void addApplicationMappingsWithApps(int deviceId, int enrolmentId, List<Application> applications, int tenantId)
throws DeviceManagementDAOException;
void removeApplicationMapping(int deviceId, List<Integer> appIdList, int tenantId)
void removeApplicationMapping(int deviceId, int enrolmentId, List<Integer> appIdList, int tenantId)
throws DeviceManagementDAOException;
}

@ -152,8 +152,8 @@ public abstract class AbstractApplicationDAOImpl implements ApplicationDAO {
try {
conn = this.getConnection();
stmt = conn.prepareStatement("SELECT ID, NAME, APP_IDENTIFIER, PLATFORM, CATEGORY, VERSION, TYPE, " +
"LOCATION_URL, IMAGE_URL, APP_PROPERTIES, MEMORY_USAGE, IS_ACTIVE, TENANT_ID FROM DM_APPLICATION WHERE APP_IDENTIFIER = ? " +
"AND TENANT_ID = ?");
"LOCATION_URL, IMAGE_URL, APP_PROPERTIES, MEMORY_USAGE, IS_ACTIVE, TENANT_ID FROM " +
"DM_APPLICATION WHERE APP_IDENTIFIER = ? AND TENANT_ID = ?");
stmt.setString(1, identifier);
stmt.setInt(2, tenantId);
rs = stmt.executeQuery();
@ -171,7 +171,8 @@ public abstract class AbstractApplicationDAOImpl implements ApplicationDAO {
}
@Override
public Application getApplication(String identifier, String version, int tenantId) throws DeviceManagementDAOException {
public Application getApplication(String identifier, String version, int tenantId)
throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
@ -179,8 +180,8 @@ public abstract class AbstractApplicationDAOImpl implements ApplicationDAO {
try {
conn = this.getConnection();
stmt = conn.prepareStatement("SELECT ID, NAME, APP_IDENTIFIER, PLATFORM, CATEGORY, VERSION, TYPE, " +
"LOCATION_URL, IMAGE_URL, APP_PROPERTIES, MEMORY_USAGE, IS_ACTIVE, TENANT_ID FROM DM_APPLICATION WHERE APP_IDENTIFIER = ? " +
"AND VERSION = ? AND TENANT_ID = ?");
"LOCATION_URL, IMAGE_URL, APP_PROPERTIES, MEMORY_USAGE, IS_ACTIVE, TENANT_ID FROM " +
"DM_APPLICATION WHERE APP_IDENTIFIER = ? AND VERSION = ? AND TENANT_ID = ?");
stmt.setString(1, identifier);
stmt.setString(2, version);
stmt.setInt(3, tenantId);
@ -199,7 +200,8 @@ public abstract class AbstractApplicationDAOImpl implements ApplicationDAO {
}
@Override
public Application getApplication(String identifier, String version, int deviceId, int tenantId) throws DeviceManagementDAOException {
public Application getApplication(String identifier, String version, int deviceId, int enrolmentId, int tenantId)
throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
@ -208,14 +210,15 @@ public abstract class AbstractApplicationDAOImpl implements ApplicationDAO {
conn = this.getConnection();
stmt = conn.prepareStatement("SELECT ID, NAME, APP_IDENTIFIER, PLATFORM, CATEGORY, VERSION, TYPE, " +
"LOCATION_URL, IMAGE_URL, appmap.APP_PROPERTIES, appmap.MEMORY_USAGE, appmap.IS_ACTIVE, TENANT_ID " +
"FROM DM_APPLICATION app INNER JOIN " +
"(SELECT APPLICATION_ID, APP_PROPERTIES, MEMORY_USAGE, IS_ACTIVE FROM DM_DEVICE_APPLICATION_MAPPING W" +
"HERE DEVICE_ID = ?) appmap WHERE app.APP_IDENTIFIER = ? AND app.VERSION = ? AND " +
"FROM DM_APPLICATION app INNER JOIN (SELECT APPLICATION_ID, APP_PROPERTIES, MEMORY_USAGE, " +
"IS_ACTIVE FROM DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ? AND ENROLMENT_ID = ?) appmap " +
"WHERE app.APP_IDENTIFIER = ? AND app.VERSION = ? AND " +
"appmap.APPLICATION_ID = app.id AND TENANT_ID = ?");
stmt.setInt(1, deviceId);
stmt.setString(2, identifier);
stmt.setString(3, version);
stmt.setInt(4, tenantId);
stmt.setInt(2, enrolmentId);
stmt.setString(3, identifier);
stmt.setString(4, version);
stmt.setInt(5, tenantId);
rs = stmt.executeQuery();
if (rs.next()) {
@ -235,7 +238,7 @@ public abstract class AbstractApplicationDAOImpl implements ApplicationDAO {
}
@Override
public List<Application> getInstalledApplications(int deviceId) throws DeviceManagementDAOException {
public List<Application> getInstalledApplications(int deviceId, int enrolmentId) throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
List<Application> applications = new ArrayList<>();
@ -247,11 +250,12 @@ public abstract class AbstractApplicationDAOImpl implements ApplicationDAO {
"LOCATION_URL, IMAGE_URL, APPMAP.APP_PROPERTIES, APPMAP.MEMORY_USAGE, APPMAP.IS_ACTIVE, " +
"TENANT_ID From DM_APPLICATION app INNER JOIN " +
"(Select APPLICATION_ID, APP_PROPERTIES, MEMORY_USAGE, IS_ACTIVE" +
" From DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID=?) APPMAP " +
" From DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID=? AND ENROLMENT_ID = ?) APPMAP " +
"ON " +
"app.ID = APPMAP.APPLICATION_ID ");
stmt.setInt(1, deviceId);
stmt.setInt(2, enrolmentId);
rs = stmt.executeQuery();
while (rs.next()) {

@ -97,7 +97,7 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
}
@Override
public void addApplicationMappingsWithApps(int deviceId, List<Application> applications, int tenantId)
public void addApplicationMappingsWithApps(int deviceId, int enrolmentId, List<Application> applications, int tenantId)
throws DeviceManagementDAOException {
Connection conn;
@ -108,25 +108,26 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
try {
conn = this.getConnection();
String sql = "INSERT INTO DM_DEVICE_APPLICATION_MAPPING (DEVICE_ID, APPLICATION_ID, APP_PROPERTIES, " +
"MEMORY_USAGE, IS_ACTIVE, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?)";
String sql = "INSERT INTO DM_DEVICE_APPLICATION_MAPPING (DEVICE_ID, ENROLMENT_ID, APPLICATION_ID, " +
"APP_PROPERTIES, MEMORY_USAGE, IS_ACTIVE, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?)";
conn.setAutoCommit(false);
stmt = conn.prepareStatement(sql);
for (Application application : applications) {
stmt.setInt(1, deviceId);
stmt.setInt(2, application.getId());
stmt.setInt(2, enrolmentId);
stmt.setInt(3, application.getId());
bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao);
oos.writeObject(application.getAppProperties());
stmt.setBytes(3, bao.toByteArray());
stmt.setBytes(4, bao.toByteArray());
stmt.setInt(4, application.getMemoryUsage());
stmt.setBoolean(5, application.isActive());
stmt.setInt(5, application.getMemoryUsage());
stmt.setBoolean(6, application.isActive());
stmt.setInt(6, tenantId);
stmt.setInt(7, tenantId);
stmt.addBatch();
}
stmt.executeBatch();
@ -155,13 +156,13 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
}
@Override
public void removeApplicationMapping(int deviceId, List<Integer> appIdList,
public void removeApplicationMapping(int deviceId, int enrolmentId, List<Integer> appIdList,
int tenantId) throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
try {
String sql = "DELETE FROM DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ? AND " +
"APPLICATION_ID = ? AND TENANT_ID = ?";
"APPLICATION_ID = ? AND TENANT_ID = ? AND ENROLMENT_ID = ?";
conn = this.getConnection();
for (int appId : appIdList) {
@ -169,6 +170,7 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
stmt.setInt(1, deviceId);
stmt.setInt(2, appId);
stmt.setInt(3, tenantId);
stmt.setInt(4, enrolmentId);
stmt.execute();
}
} catch (SQLException e) {

@ -38,14 +38,15 @@ public interface DeviceDetailsDAO {
* @param deviceInfo - Device information object.
* @throws DeviceDetailsMgtDAOException
*/
void addDeviceInformation(int deviceId, DeviceInfo deviceInfo) throws DeviceDetailsMgtDAOException;
void addDeviceInformation(int deviceId, int enrolmentId, DeviceInfo deviceInfo) throws DeviceDetailsMgtDAOException;
/**
* This method will add the device properties to the database.
* @param propertyMap - device properties.
* @throws DeviceDetailsMgtDAOException
*/
void addDeviceProperties(Map<String, String> propertyMap, int deviceId) throws DeviceDetailsMgtDAOException;
void addDeviceProperties(Map<String, String> propertyMap, int deviceId, int enrolmentId)
throws DeviceDetailsMgtDAOException;
/**
* This method will return the device information when device id is provided.
@ -53,7 +54,7 @@ public interface DeviceDetailsDAO {
* @return DeviceInfo
* @throws DeviceDetailsMgtDAOException
*/
DeviceInfo getDeviceInformation(int deviceId) throws DeviceDetailsMgtDAOException;
DeviceInfo getDeviceInformation(int deviceId, int enrolmentId) throws DeviceDetailsMgtDAOException;
/**
* This method will return the device properties from database.
@ -61,28 +62,28 @@ public interface DeviceDetailsDAO {
* @return - device properties map.
* @throws DeviceDetailsMgtDAOException
*/
Map<String, String> getDeviceProperties(int deviceId) throws DeviceDetailsMgtDAOException;
Map<String, String> getDeviceProperties(int deviceId, int enrolmentId) throws DeviceDetailsMgtDAOException;
/**
* This method will delete the device information from the database.
* @param deviceId - Integer.
* @throws DeviceDetailsMgtDAOException
*/
void deleteDeviceInformation(int deviceId) throws DeviceDetailsMgtDAOException;
void deleteDeviceInformation(int deviceId, int enrollmentId) throws DeviceDetailsMgtDAOException;
/**
* This method will delete the device properties from database.
* @param deviceId - Integer.
* @throws DeviceDetailsMgtDAOException
*/
void deleteDeviceProperties(int deviceId) throws DeviceDetailsMgtDAOException;
void deleteDeviceProperties(int deviceId, int enrollmentId) throws DeviceDetailsMgtDAOException;
/**
* This method will add device location to database.
* @param deviceLocation - Device location with latitude and longitude.
* @throws DeviceDetailsMgtDAOException
*/
void addDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtDAOException;
void addDeviceLocation(DeviceLocation deviceLocation, int enrollmentId) throws DeviceDetailsMgtDAOException;
/**
* This method will return the device location object when the device id is provided.
@ -90,14 +91,14 @@ public interface DeviceDetailsDAO {
* @return - Device location object.
* @throws DeviceDetailsMgtDAOException
*/
DeviceLocation getDeviceLocation(int deviceId) throws DeviceDetailsMgtDAOException;
DeviceLocation getDeviceLocation(int deviceId, int enrollmentId) throws DeviceDetailsMgtDAOException;
/**
* This method will delete the device location from the database.
* @param deviceId
* @throws DeviceDetailsMgtDAOException
*/
void deleteDeviceLocation(int deviceId) throws DeviceDetailsMgtDAOException;
void deleteDeviceLocation(int deviceId, int enrollmentId) throws DeviceDetailsMgtDAOException;
// /**
// * This method will add device application to database.

@ -41,7 +41,8 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
private static Log log = LogFactory.getLog(DeviceDetailsDAOImpl.class);
@Override
public void addDeviceInformation(int deviceId, DeviceInfo deviceInfo) throws DeviceDetailsMgtDAOException {
public void addDeviceInformation(int deviceId, int enrolmentId, DeviceInfo deviceInfo)
throws DeviceDetailsMgtDAOException {
Connection conn;
PreparedStatement stmt = null;
@ -51,8 +52,8 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_DETAIL (DEVICE_ID, DEVICE_MODEL, " +
"VENDOR, OS_VERSION, OS_BUILD_DATE, BATTERY_LEVEL, INTERNAL_TOTAL_MEMORY, INTERNAL_AVAILABLE_MEMORY, " +
"EXTERNAL_TOTAL_MEMORY, EXTERNAL_AVAILABLE_MEMORY, CONNECTION_TYPE, " +
"SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN, UPDATE_TIMESTAMP) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
"SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN, UPDATE_TIMESTAMP, ENROLMENT_ID) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
stmt.setInt(1, deviceId);
stmt.setString(2, deviceInfo.getDeviceModel());
@ -71,6 +72,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
stmt.setDouble(15, deviceInfo.getAvailableRAMMemory());
stmt.setBoolean(16, deviceInfo.isPluggedIn());
stmt.setLong(17, System.currentTimeMillis());
stmt.setInt(18, enrolmentId);
stmt.execute();
@ -83,7 +85,8 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
}
@Override
public void addDeviceProperties(Map<String, String> propertyMap, int deviceId) throws DeviceDetailsMgtDAOException {
public void addDeviceProperties(Map<String, String> propertyMap, int deviceId, int enrolmentId)
throws DeviceDetailsMgtDAOException {
if (propertyMap.isEmpty()) {
if(log.isDebugEnabled()) {
@ -95,12 +98,14 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
PreparedStatement stmt = null;
try {
conn = this.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_INFO (DEVICE_ID, KEY_FIELD, VALUE_FIELD) VALUES (?, ?, ?)");
stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_INFO (DEVICE_ID, KEY_FIELD, VALUE_FIELD, ENROLMENT_ID) " +
"VALUES (?, ?, ?, ?)");
for (Map.Entry<String, String> entry : propertyMap.entrySet()) {
stmt.setInt(1, deviceId);
stmt.setString(2, entry.getKey());
stmt.setString(3, entry.getValue());
stmt.setInt(4, enrolmentId);
stmt.addBatch();
}
stmt.executeBatch();
@ -113,7 +118,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
}
@Override
public DeviceInfo getDeviceInformation(int deviceId) throws DeviceDetailsMgtDAOException {
public DeviceInfo getDeviceInformation(int deviceId, int enrolmentId) throws DeviceDetailsMgtDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
@ -121,9 +126,10 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
try {
conn = this.getConnection();
String sql = "SELECT * FROM DM_DEVICE_DETAIL WHERE DEVICE_ID = ?";
String sql = "SELECT * FROM DM_DEVICE_DETAIL WHERE DEVICE_ID = ? AND ENROLMENT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, deviceId);
stmt.setInt(2, enrolmentId);
rs = stmt.executeQuery();
if (rs.next()) {
@ -159,7 +165,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
}
@Override
public Map<String, String> getDeviceProperties(int deviceId) throws DeviceDetailsMgtDAOException {
public Map<String, String> getDeviceProperties(int deviceId, int enrolmentId) throws DeviceDetailsMgtDAOException {
Connection conn;
PreparedStatement stmt = null;
@ -167,9 +173,10 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
Map<String, String> map = new HashMap<>();
try {
conn = this.getConnection();
String sql = "SELECT * FROM DM_DEVICE_INFO WHERE DEVICE_ID = ?";
String sql = "SELECT * FROM DM_DEVICE_INFO WHERE DEVICE_ID = ? AND ENROLMENT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, deviceId);
stmt.setInt(2, enrolmentId);
rs = stmt.executeQuery();
while (rs.next()) {
@ -184,15 +191,16 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
}
@Override
public void deleteDeviceInformation(int deviceId) throws DeviceDetailsMgtDAOException {
public void deleteDeviceInformation(int deviceId, int enrollmentId) throws DeviceDetailsMgtDAOException {
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String query = "DELETE FROM DM_DEVICE_DETAIL WHERE DEVICE_ID = ?";
String query = "DELETE FROM DM_DEVICE_DETAIL WHERE DEVICE_ID = ? AND ENROLMENT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId);
stmt.setInt(2, enrollmentId);
stmt.executeUpdate();
} catch (SQLException e) {
@ -203,15 +211,16 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
}
@Override
public void deleteDeviceProperties(int deviceId) throws DeviceDetailsMgtDAOException {
public void deleteDeviceProperties(int deviceId, int enrollmentId) throws DeviceDetailsMgtDAOException {
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String query = "DELETE FROM DM_DEVICE_INFO WHERE DEVICE_ID = ?";
String query = "DELETE FROM DM_DEVICE_INFO WHERE DEVICE_ID = ? AND ENROLMENT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId);
stmt.setInt(2, enrollmentId);
stmt.executeUpdate();
} catch (SQLException e) {
@ -222,14 +231,15 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
}
@Override
public void addDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtDAOException {
public void addDeviceLocation(DeviceLocation deviceLocation, int enrollmentId) throws DeviceDetailsMgtDAOException {
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_LOCATION (DEVICE_ID, LATITUDE, LONGITUDE, STREET1, " +
"STREET2, CITY, ZIP, STATE, COUNTRY, GEO_HASH, UPDATE_TIMESTAMP) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)");
"STREET2, CITY, ZIP, STATE, COUNTRY, GEO_HASH, UPDATE_TIMESTAMP, ENROLMENT_ID) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
stmt.setInt(1, deviceLocation.getDeviceId());
stmt.setDouble(2, deviceLocation.getLatitude());
stmt.setDouble(3, deviceLocation.getLongitude());
@ -241,6 +251,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
stmt.setString(9, deviceLocation.getCountry());
stmt.setString(10, GeoHashGenerator.encodeGeohash(deviceLocation));
stmt.setLong(11, System.currentTimeMillis());
stmt.setInt(12, enrollmentId);
stmt.execute();
} catch (SQLException e) {
throw new DeviceDetailsMgtDAOException("Error occurred while adding the device location to database.", e);
@ -250,7 +261,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
}
@Override
public DeviceLocation getDeviceLocation(int deviceId) throws DeviceDetailsMgtDAOException {
public DeviceLocation getDeviceLocation(int deviceId, int enrollmentId) throws DeviceDetailsMgtDAOException {
Connection conn;
PreparedStatement stmt = null;
@ -258,9 +269,10 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
DeviceLocation location = new DeviceLocation();
try {
conn = this.getConnection();
String sql = "SELECT * FROM DM_DEVICE_LOCATION WHERE DEVICE_ID = ?";
String sql = "SELECT * FROM DM_DEVICE_LOCATION WHERE DEVICE_ID = ? AND ENROLMENT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, deviceId);
stmt.setInt(2, enrollmentId);
rs = stmt.executeQuery();
while (rs.next()) {
@ -286,15 +298,16 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
}
@Override
public void deleteDeviceLocation(int deviceId) throws DeviceDetailsMgtDAOException {
public void deleteDeviceLocation(int deviceId, int enrollmentId) throws DeviceDetailsMgtDAOException {
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String query = "DELETE FROM DM_DEVICE_LOCATION WHERE DEVICE_ID = ?";
String query = "DELETE FROM DM_DEVICE_LOCATION WHERE DEVICE_ID = ? AND ENROLMENT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId);
stmt.setInt(2, enrollmentId);
stmt.executeUpdate();
} catch (SQLException e) {

@ -68,12 +68,14 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
DeviceManagementDAOFactory.beginTransaction();
deviceDAO.updateDevice(device, CarbonContext.getThreadLocalCarbonContext().getTenantId());
deviceDetailsDAO.deleteDeviceInformation(device.getId());
deviceDetailsDAO.deleteDeviceProperties(device.getId());
deviceDetailsDAO.addDeviceInformation(device.getId(), deviceInfo);
deviceDetailsDAO.addDeviceProperties(deviceInfo.getDeviceDetailsMap(), device.getId());
deviceDetailsDAO.deleteDeviceInformation(device.getId(), device.getEnrolmentInfo().getId());
deviceDetailsDAO.deleteDeviceProperties(device.getId(), device.getEnrolmentInfo().getId());
deviceDetailsDAO.addDeviceInformation(device.getId(), device.getEnrolmentInfo().getId(), deviceInfo);
deviceDetailsDAO.addDeviceProperties(deviceInfo.getDeviceDetailsMap(), device.getId(),
device.getEnrolmentInfo().getId());
DeviceManagementDAOFactory.commitTransaction();
//TODO :: This has to be fixed by adding the enrollment ID.
if (DeviceManagerUtil.isPublishDeviceInfoResponseEnabled()) {
Object[] metaData = {device.getDeviceIdentifier(), device.getType()};
Object[] payload = new Object[]{
@ -131,8 +133,10 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
}
try {
DeviceManagementDAOFactory.openConnection();
DeviceInfo deviceInfo = deviceDetailsDAO.getDeviceInformation(device.getId());
deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(device.getId()));
DeviceInfo deviceInfo = deviceDetailsDAO.getDeviceInformation(device.getId(),
device.getEnrolmentInfo().getId());
deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(device.getId(),
device.getEnrolmentInfo().getId()));
return deviceInfo;
} catch (SQLException e) {
@ -154,19 +158,21 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
identifierMap.put(identifier.getId(), identifier);
}
try {
List<Integer> deviceIds = new ArrayList<>();
List<Device> deviceIds = new ArrayList<>();
List<Device> devices = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
getAllDevices(false);
for (Device device : devices) {
if (identifierMap.containsKey(device.getDeviceIdentifier()) &&
device.getType().equals(identifierMap.get(device.getDeviceIdentifier()).getType())) {
deviceIds.add(device.getId());
deviceIds.add(device);
}
}
DeviceManagementDAOFactory.openConnection();
for (Integer id : deviceIds) {
DeviceInfo deviceInfo = deviceDetailsDAO.getDeviceInformation(id);
deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(id));
for (Device device : deviceIds) {
DeviceInfo deviceInfo = deviceDetailsDAO.getDeviceInformation(device.getId(),
device.getEnrolmentInfo().getId());
deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(device.getId(),
device.getEnrolmentInfo().getId()));
deviceInfos.add(deviceInfo);
}
} catch (SQLException e) {
@ -190,8 +196,9 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
deviceLocation.setDeviceId(device.getId());
DeviceManagementDAOFactory.beginTransaction();
deviceDAO.updateDevice(device, CarbonContext.getThreadLocalCarbonContext().getTenantId());
deviceDetailsDAO.deleteDeviceLocation(deviceLocation.getDeviceId());
deviceDetailsDAO.addDeviceLocation(deviceLocation);
deviceDetailsDAO.deleteDeviceLocation(deviceLocation.getDeviceId(), device.getEnrolmentInfo().getId());
deviceDetailsDAO.addDeviceLocation(deviceLocation, device.getEnrolmentInfo().getId());
//TODO: This has to be fixed with enrollment id or username should include in the stream def.
if (DeviceManagerUtil.isPublishLocationResponseEnabled()) {
Object[] metaData = {device.getDeviceIdentifier(), device.getType()};
Object[] payload = new Object[]{
@ -233,7 +240,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
}
try {
DeviceManagementDAOFactory.openConnection();
return deviceDetailsDAO.getDeviceLocation(device.getId());
return deviceDetailsDAO.getDeviceLocation(device.getId(), device.getEnrolmentInfo().getId());
} catch (SQLException e) {
throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e);
} catch (DeviceDetailsMgtDAOException e) {
@ -270,7 +277,8 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
List<DeviceLocation> deviceLocations = new ArrayList<>();
DeviceManagementDAOFactory.openConnection();
for (Device device : devices) {
deviceLocations.add(deviceDetailsDAO.getDeviceLocation(device.getId()));
deviceLocations.add(deviceDetailsDAO.getDeviceLocation(device.getId(),
device.getEnrolmentInfo().getId()));
}
return deviceLocations;
} catch (DeviceManagementException e) {

@ -0,0 +1,34 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.core.privacy;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.PrivacyComplianceException;
public interface PrivacyComplianceProvider {
void deleteDevicesOfUser(String username) throws PrivacyComplianceException;
void deleteDeviceDetails(DeviceIdentifier deviceIdentifier) throws PrivacyComplianceException;
void deleteArchivedDataOfDevice(DeviceIdentifier deviceIdentifier) throws PrivacyComplianceException;
}

@ -236,7 +236,8 @@ public class ProcessorImpl implements Processor {
try {
DeviceManagementDAOFactory.openConnection();
for (Device device : devices) {
device.setApplications(applicationDAO.getInstalledApplications(device.getId()));
device.setApplications(applicationDAO.getInstalledApplications(device.getId(),
device.getEnrolmentInfo().getId()));
}
} catch (DeviceManagementDAOException e) {
throw new SearchMgtException("Error occurred while fetching the Application List of devices ", e);

@ -2475,8 +2475,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceInfo info = null;
try {
DeviceManagementDAOFactory.openConnection();
info = deviceInfoDAO.getDeviceInformation(device.getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId());
info = deviceInfoDAO.getDeviceInformation(device.getId(), device.getEnrolmentInfo().getId());
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId(),
device.getEnrolmentInfo().getId());
if (location != null) {
//There are some cases where the device-info is not updated properly. Hence returning a null value.
if (info != null) {
@ -2507,23 +2508,28 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
/**
* Returns all the installed apps of the given device.
*/
private List<Application> getInstalledApplications(Device device) {
private List<Application> getInstalledApplications(Device device) throws DeviceManagementException {
if (log.isDebugEnabled()) {
log.debug("Get installed applications of device: " + device.getId() + " of type '" + device.getType() + "'");
}
List<Application> applications = new ArrayList<>();
try {
DeviceManagementDAOFactory.openConnection();
applications = applicationDAO.getInstalledApplications(device.getId());
applications = applicationDAO.getInstalledApplications(device.getId(), device.getEnrolmentInfo().getId());
device.setApplications(applications);
} catch (DeviceManagementDAOException e) {
log.error("Error occurred while retrieving the application list of '" + device.getType() + "', " +
"which carries the id '" + device.getId() + "'", e);
String msg = "Error occurred while retrieving the application list of '" + device.getType() + "', " +
"which carries the id '" + device.getId() + "'";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (SQLException e) {
log.error("Error occurred while opening a connection to the data source", e);
String msg = "Error occurred while opening a connection to the data source";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred in getInstalledApplications";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}

@ -506,7 +506,8 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
//Device details table will be reffered when looking for last updated time
//This dao entry is to mimic a device info operation
deviceDetailsDAO.addDeviceInformation(initialDevice.getId(), TestDataHolder
deviceDetailsDAO.addDeviceInformation(initialDevice.getId(), initialDevice.getEnrolmentInfo().getId(),
TestDataHolder
.generateDummyDeviceInfo());
DeviceManagementDAOFactory.closeConnection();

@ -301,7 +301,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
POLICY_CRITERION_ID INT NOT NULL,
PROP_KEY VARCHAR(45) NULL,
PROP_VALUE VARCHAR(100) NULL,
CONTENT BLOB NULL COMMENT 'This is used to ',
CONTENT BLOB NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_POLICY_CRITERIA_PROPERTIES
FOREIGN KEY (POLICY_CRITERION_ID)
@ -363,19 +363,32 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
APPLICATION_ID INTEGER NOT NULL,
APP_PROPERTIES BLOB NULL,
MEMORY_USAGE INTEGER(10) NULL,
IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
CONSTRAINT fk_dm_device
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_dm_application
FOREIGN KEY (APPLICATION_ID)
REFERENCES DM_APPLICATION (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_APP_MAP_DM_ENROL
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
-- POLICY RELATED TABLES FINISHED --
@ -400,6 +413,7 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INT NULL,
ENROLMENT_ID INT NOT NULL,
KEY_FIELD VARCHAR(45) NULL,
VALUE_FIELD VARCHAR(100) NULL,
PRIMARY KEY (ID),
@ -407,12 +421,18 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT DM_DEVICE_INFO_DEVICE_ENROLLMENT
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INT NULL,
ENROLMENT_ID INT NOT NULL,
LATITUDE DOUBLE NULL,
LONGITUDE DOUBLE NULL,
STREET1 VARCHAR(255) NULL,
@ -428,14 +448,19 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT DM_DEVICE_LOCATION_DM_ENROLLMENT
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE INDEX DM_DEVICE_LOCATION_GEO_hashx ON DM_DEVICE_LOCATION(GEO_HASH ASC);
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT NOT NULL,
DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL,
@ -457,6 +482,11 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_ENROLMENT_DEVICE_DETAILS
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);

@ -414,19 +414,32 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
);
DROP TABLE IF EXISTS DM_DEVICE_APPLICATION_MAPPING;
CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
APPLICATION_ID INTEGER NOT NULL,
APP_PROPERTIES BLOB NULL,
MEMORY_USAGE INTEGER(10) NULL,
IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
CONSTRAINT fk_dm_device
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_dm_application
FOREIGN KEY (APPLICATION_ID)
REFERENCES DM_APPLICATION (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_APP_MAP_DM_ENROL
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
-- POLICY RELATED TABLES FINISHED --
@ -448,10 +461,10 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
);
-- NOTIFICATION TABLE END --
DROP TABLE IF EXISTS DM_DEVICE_INFO;
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INT NULL,
ENROLMENT_ID INT NOT NULL,
KEY_FIELD VARCHAR(45) NULL,
VALUE_FIELD VARCHAR(100) NULL,
PRIMARY KEY (ID),
@ -459,35 +472,46 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT DM_DEVICE_INFO_DEVICE_ENROLLMENT
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_DEVICE_LOCATION;
CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INT NULL,
ENROLMENT_ID INT NOT NULL,
LATITUDE DOUBLE NULL,
LONGITUDE DOUBLE NULL,
STREET1 VARCHAR(45) NULL,
STREET1 VARCHAR(255) NULL,
STREET2 VARCHAR(45) NULL,
CITY VARCHAR(45) NULL,
ZIP VARCHAR(10) NULL,
STATE VARCHAR(45) NULL,
COUNTRY VARCHAR(45) NULL,
GEO_HASH VARCHAR(45) NULL,
UPDATE_TIMESTAMP BIGINT(15) NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT DM_DEVICE_LOCATION_DEVICE
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT DM_DEVICE_LOCATION_DM_ENROLLMENT
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_DEVICE_DETAIL;
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT NOT NULL,
DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL,
@ -497,7 +521,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
CONNECTION_TYPE VARCHAR(10) NULL,
CONNECTION_TYPE VARCHAR(50) NULL,
SSID VARCHAR(45) NULL,
CPU_USAGE DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
@ -509,10 +533,16 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_ENROLMENT_DEVICE_DETAILS
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
-- POLICY AND DEVICE GROUP MAPPING --
DROP TABLE IF EXISTS DM_DEVICE_GROUP_POLICY;
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (

@ -366,16 +366,28 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
APPLICATION_ID INTEGER NOT NULL,
APP_PROPERTIES BLOB NULL,
MEMORY_USAGE INTEGER(10) NULL,
IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
CONSTRAINT fk_dm_device
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_dm_application
FOREIGN KEY (APPLICATION_ID)
REFERENCES DM_APPLICATION (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_APP_MAP_DM_ENROL
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
-- POLICY RELATED TABLES FINISHED --
@ -400,6 +412,7 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INT NULL,
ENROLMENT_ID INT NOT NULL,
KEY_FIELD VARCHAR(45) NULL,
VALUE_FIELD VARCHAR(100) NULL,
PRIMARY KEY (ID),
@ -407,12 +420,18 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT DM_DEVICE_INFO_DEVICE_ENROLLMENT
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INT NULL,
ENROLMENT_ID INT NOT NULL,
LATITUDE DOUBLE NULL,
LONGITUDE DOUBLE NULL,
STREET1 VARCHAR(255) NULL,
@ -428,6 +447,11 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT DM_DEVICE_LOCATION_DM_ENROLLMENT
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE INDEX DM_DEVICE_LOCATION_GEO_hashx ON DM_DEVICE_LOCATION(GEO_HASH ASC);
@ -435,6 +459,7 @@ CREATE INDEX DM_DEVICE_LOCATION_GEO_hashx ON DM_DEVICE_LOCATION(GEO_HASH ASC);
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT NOT NULL,
DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL,
@ -456,6 +481,11 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_ENROLMENT_DEVICE_DETAILS
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);

@ -395,6 +395,7 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[D
CREATE TABLE DM_DEVICE_APPLICATION_MAPPING (
ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_ID INTEGER NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
APPLICATION_ID INTEGER NOT NULL,
APP_PROPERTIES VARBINARY(MAX) NULL,
MEMORY_USAGE INTEGER NULL,
@ -404,7 +405,9 @@ CREATE TABLE DM_DEVICE_APPLICATION_MAPPING (
CONSTRAINT FK_DM_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT FK_DM_APPLICATION FOREIGN KEY (APPLICATION_ID) REFERENCES
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT FK_DM_APP_MAP_DM_ENROL FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
-- POLICY RELATED TABLES FINISHED --
@ -453,18 +456,29 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[D
CREATE TABLE DM_DEVICE_INFO (
ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_ID INTEGER NULL,
ENROLMENT_ID INTEGER NOT NULL,
KEY_FIELD VARCHAR(45) NULL,
VALUE_FIELD VARCHAR(100) NULL,
PRIMARY KEY (ID),
INDEX DM_DEVICE_INFO_DEVICE_idx (DEVICE_ID ASC),
CONSTRAINT DM_DEVICE_INFO_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION
ON UPDATE NO ACTION
INDEX DM_DEVICE_INFO_DEVICE_ENROLLMENT_idx (ENROLMENT_ID ASC)
CONSTRAINT DM_DEVICE_INFO_DEVICE
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT DM_DEVICE_INFO_DEVICE_ENROLLMENT
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_LOCATION]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_LOCATION (
ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_ID INTEGER NULL,
ENROLMENT_ID INTEGER NOT NULL,
LATITUDE FLOAT NULL,
LONGITUDE FLOAT NULL,
STREET1 VARCHAR(255) NULL,
@ -478,10 +492,16 @@ CREATE TABLE DM_DEVICE_LOCATION (
PRIMARY KEY (ID),
INDEX DM_DEVICE_LOCATION_DEVICE_idx (DEVICE_ID ASC),
INDEX DM_DEVICE_LOCATION_GEO_hashx (GEO_HASH ASC),
INDEX DM_DEVICE_LOCATION_DM_ENROLLMENT_idx (ENROLMENT_ID ASC),
CONSTRAINT DM_DEVICE_LOCATION_DEVICE
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT DM_DEVICE_LOCATION_DM_ENROLLMENT
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
@ -489,6 +509,7 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[D
CREATE TABLE DM_DEVICE_DETAIL (
ID INTEGER IDENTITY(1,1) NOT NULL,
DEVICE_ID INTEGER NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL,
@ -507,11 +528,17 @@ CREATE TABLE DM_DEVICE_DETAIL (
UPDATE_TIMESTAMP BIGINT NOT NULL,
PRIMARY KEY (ID),
INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC),
INDEX FK_DM_ENROLMENT_DEVICE_DETAILS_idx (ENROLMENT_ID ASC),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_ENROLMENT_DEVICE_DETAILS
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
-- DASHBOARD RELATED VIEWS --

@ -410,6 +410,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
APPLICATION_ID INTEGER NOT NULL,
APP_PROPERTIES BLOB NULL,
MEMORY_USAGE INTEGER(10) NULL,
@ -419,7 +420,9 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING (
CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT FK_DM_APP_MAP_DM_ENROL FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB;
-- END OF POLICY RELATED TABLES --
@ -468,14 +471,21 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INT NULL,
ENROLMENT_ID INT NOT NULL,
KEY_FIELD VARCHAR(45) NULL,
VALUE_FIELD VARCHAR(100) NULL,
PRIMARY KEY (ID),
INDEX DM_DEVICE_INFO_DEVICE_idx (DEVICE_ID ASC),
INDEX DM_DEVICE_INFO_DEVICE_ENROLLMENT_idx (ENROLMENT_ID ASC),
CONSTRAINT DM_DEVICE_INFO_DEVICE
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT DM_DEVICE_INFO_DEVICE_ENROLLMENT
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)
ENGINE = InnoDB;
@ -483,6 +493,7 @@ ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INT NULL,
ENROLMENT_ID INT NOT NULL,
LATITUDE DOUBLE NULL,
LONGITUDE DOUBLE NULL,
STREET1 VARCHAR(255) NULL,
@ -496,10 +507,16 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
PRIMARY KEY (ID),
INDEX DM_DEVICE_LOCATION_DEVICE_idx (DEVICE_ID ASC),
INDEX DM_DEVICE_LOCATION_GEO_hashx (GEO_HASH ASC),
INDEX DM_DEVICE_LOCATION_DM_ENROLLMENT_idx (ENROLMENT_ID ASC),
CONSTRAINT DM_DEVICE_LOCATION_DEVICE
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT DM_DEVICE_LOCATION_DM_ENROLLMENT
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)
ENGINE = InnoDB;
@ -507,6 +524,7 @@ ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT NOT NULL,
DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL,
@ -525,11 +543,18 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
UPDATE_TIMESTAMP BIGINT(15) NOT NULL,
PRIMARY KEY (ID),
INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC),
INDEX FK_DM_ENROLMENT_DEVICE_DETAILS_idx (ENROLMENT_ID ASC),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_ENROLMENT_DEVICE_DETAILS
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)
ENGINE = InnoDB;
-- DASHBOARD RELATED VIEWS --

@ -714,6 +714,7 @@ WHEN (NEW.ID IS NULL)
CREATE TABLE DM_DEVICE_APPLICATION_MAPPING (
ID NUMBER(10) NOT NULL,
DEVICE_ID NUMBER(10) NOT NULL,
ENROLMENT_ID NUMBER(10 NOT NULL,
APPLICATION_ID NUMBER(10) NOT NULL,
APP_PROPERTIES BLOB NULL,
MEMORY_USAGE NUMBER(10) NULL,
@ -723,7 +724,9 @@ CREATE TABLE DM_DEVICE_APPLICATION_MAPPING (
CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID),
CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES
DM_APPLICATION (ID)
DM_APPLICATION (ID),
CONSTRAINT FK_DM_APP_MAP_DM_ENROL FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID)
)
/
-- Generate ID using sequence and trigger
@ -786,14 +789,17 @@ END;
CREATE TABLE DM_DEVICE_INFO (
ID NUMBER(10) NOT NULL,
DEVICE_ID NUMBER(10) NULL,
DEVICE_ID NUMBER(10) NOT NULL,
ENROLMENT_ID NUMBER(10) NOT NULL,
KEY_FIELD VARCHAR2(45) NULL,
VALUE_FIELD VARCHAR2(100) NULL,
PRIMARY KEY (ID)
,
PRIMARY KEY (ID),
CONSTRAINT DM_DEVICE_INFO_DEVICE
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
REFERENCES DM_DEVICE (ID),
CONSTRAINT DM_DEVICE_INFO_DEVICE_ENROLLMENT
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
)
/
@ -810,7 +816,8 @@ WHEN (NEW.ID IS NULL)
CREATE TABLE DM_DEVICE_LOCATION (
ID NUMBER(10) NOT NULL,
DEVICE_ID NUMBER(10) NULL,
DEVICE_ID NUMBER(10) NOT NULL,
ENROLMENT_ID NUMBER(10) NOT NULL,
LATITUDE BINARY_DOUBLE NULL,
LONGITUDE BINARY_DOUBLE NULL,
STREET1 VARCHAR2(255) NULL,
@ -824,7 +831,10 @@ CREATE TABLE DM_DEVICE_LOCATION (
PRIMARY KEY (ID),
CONSTRAINT DM_DEVICE_LOCATION_DEVICE
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
REFERENCES DM_DEVICE (ID),
CONSTRAINT DM_DEVICE_LOCATION_DM_ENROLLMENT
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
)
/
@ -845,6 +855,7 @@ WHEN (NEW.ID IS NULL)
CREATE TABLE DM_DEVICE_DETAIL (
ID NUMBER(10) NOT NULL,
DEVICE_ID NUMBER(10) NOT NULL,
ENROLMENT_ID NUMBER(10) NOT NULL,
DEVICE_MODEL VARCHAR2(45) NULL,
VENDOR VARCHAR2(45) NULL,
OS_VERSION VARCHAR2(45) NULL,
@ -864,7 +875,10 @@ CREATE TABLE DM_DEVICE_DETAIL (
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
REFERENCES DM_DEVICE (ID),
CONSTRAINT FK_DM_ENROLMENT_DEVICE_DETAILS
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
)
/
-- Generate ID using sequence and trigger

@ -356,6 +356,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
APPLICATION_ID INTEGER NOT NULL,
APP_PROPERTIES BYTEA NULL,
MEMORY_USAGE INTEGER NULL,
@ -364,7 +365,9 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING (
CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT FK_DM_APP_MAP_DM_ENROL FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
-- POLICY RELATED TABLES FINISHED --
@ -412,20 +415,27 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INT NULL,
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT NOT NULL,
KEY_FIELD VARCHAR(45) NULL,
VALUE_FIELD VARCHAR(100) NULL,
CONSTRAINT DM_DEVICE_INFO_DEVICE
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT DM_DEVICE_INFO_DEVICE_ENROLLMENT
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INT NULL,
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT NOT NULL,
LATITUDE DOUBLE PRECISION NULL,
LONGITUDE DOUBLE PRECISION NULL,
STREET1 VARCHAR(255) NULL,
@ -440,6 +450,11 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT DM_DEVICE_LOCATION_DM_ENROLLMENT
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
@ -448,6 +463,7 @@ CREATE INDEX DM_DEVICE_LOCATION_GEO_hashx ON DM_DEVICE_LOCATION(GEO_HASH ASC);
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT NOT NULL,
DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL,
@ -468,6 +484,11 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_ENROLMENT_DEVICE_DETAILS
FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);

Loading…
Cancel
Save