revert-70aa11f8
madhawap 8 years ago
commit 682b5f81e0

@ -30,379 +30,385 @@
<PermissionConfiguration> <PermissionConfiguration>
<APIVersion></APIVersion> <APIVersion></APIVersion>
<!--Permission Tree Name--> <!--Permission Tree Name-->
<Permission> <Permission>
<name>Device Management</name> <name>Device Management</name>
<path>/device-mgt</path> <path>/device-mgt</path>
<url>/</url> <url>/</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<!-- Admin Permissions --> <!-- Admin Permissions -->
<Permission> <Permission>
<name>Device Management Admin</name> <name>Device Management Admin</name>
<path>/device-mgt/admin</path> <path>/device-mgt/admin</path>
<url>/</url> <url>/</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Devices</name> <name>Devices</name>
<path>/device-mgt/admin/devices</path> <path>/device-mgt/admin/devices</path>
<url>/</url> <url>/</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<!-- Device related APIs --> <!-- Device related APIs -->
<Permission> <Permission>
<name>List devices</name> <name>List devices</name>
<path>/device-mgt/admin/devices/List</path> <path>/device-mgt/admin/devices/List</path>
<url>/devices</url> <url>/devices</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Search devices</name> <name>Search devices</name>
<path>/device-mgt/admin/devices/Search</path> <path>/device-mgt/admin/devices/Search</path>
<url>/devices/search-devices</url> <url>/devices/search-devices</url>
<method>POST</method> <method>POST</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View device</name> <name>View device</name>
<path>/device-mgt/admin/devices/View</path> <path>/device-mgt/admin/devices/View</path>
<url>/devices/*/*</url> <url>/devices/*/*</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View device applications</name> <name>View device info</name>
<path>/device-mgt/admin/devices/View-Applications</path> <path>/device-mgt/admin/devices/View</path>
<url>/devices/*/*/applications</url> <url>/devices/*/*/info</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View device effective-policy</name> <name>View device applications</name>
<path>/device-mgt/admin/devices/View-Active-Policy</path> <path>/device-mgt/admin/devices/View-Applications</path>
<url>/devices/*/*/effective-policy</url> <url>/devices/*/*/applications</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View devices feature</name> <name>View device effective-policy</name>
<path>/device-mgt/admin/devices/View-Features</path> <path>/device-mgt/admin/devices/View-Active-Policy</path>
<url>/devices/*/*/features</url> <url>/devices/*/*/effective-policy</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View device operations</name> <name>View devices feature</name>
<path>/device-mgt/admin/devices/View-Operations</path> <path>/device-mgt/admin/devices/View-Features</path>
<url>/devices/*/*/operations</url> <url>/devices/*/*/features</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View Compliance Data</name> <name>View device operations</name>
<path>/device-mgt/admin/devices/View-Compliance-Data</path> <path>/device-mgt/admin/devices/View-Operations</path>
<url>/devices/*/*/compliance-data</url> <url>/devices/*/*/operations</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>List all devices</name> <name>View Compliance Data</name>
<path>/device-mgt/admin/devices/Admin-View</path> <path>/device-mgt/admin/devices/View-Compliance-Data</path>
<url>/admin/devices</url> <url>/devices/*/*/compliance-data</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View device types</name> <name>List all devices</name>
<path>/device-mgt/admin/devices/Admin-DeviceType-View</path> <path>/device-mgt/admin/devices/Admin-View</path>
<url>/admin/device-types</url> <url>/admin/devices</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<!-- End of Device related APIs --> <Permission>
<Permission> <name>View device types</name>
<name>Policies</name> <path>/device-mgt/admin/devices/Admin-DeviceType-View</path>
<path>/device-mgt/admin/policies</path> <url>/admin/device-types</url>
<url>/</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- End of Device related APIs -->
<!-- Policy related APIs --> <Permission>
<Permission> <name>Policies</name>
<name>List policies</name> <path>/device-mgt/admin/policies</path>
<path>/device-mgt/admin/policies/List</path> <url>/</url>
<url>/policies</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- Policy related APIs -->
<Permission> <Permission>
<name>Add Policy</name> <name>List policies</name>
<path>/device-mgt/admin/policies/Add</path> <path>/device-mgt/admin/policies/List</path>
<url>/policies</url> <url>/policies</url>
<method>POST</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Activate policy</name> <name>Add Policy</name>
<path>/device-mgt/admin/policies/Activate-Policy</path> <path>/device-mgt/admin/policies/Add</path>
<url>/policies/activate-policy</url> <url>/policies</url>
<method>PUT</method> <method>POST</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Deactivate Policy</name> <name>Activate policy</name>
<path>/device-mgt/admin/policies/Deactivate-Policy</path> <path>/device-mgt/admin/policies/Activate-Policy</path>
<url>/policies/deactivate-policy</url> <url>/policies/activate-policy</url>
<method>PUT</method> <method>PUT</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Remove Policy</name> <name>Deactivate Policy</name>
<path>/device-mgt/admin/policies/Remove</path> <path>/device-mgt/admin/policies/Deactivate-Policy</path>
<url>/policies/remove-policy</url> <url>/policies/deactivate-policy</url>
<method>POST</method> <method>PUT</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View Policy</name> <name>Remove Policy</name>
<path>/device-mgt/admin/policies/View</path> <path>/device-mgt/admin/policies/Remove</path>
<url>/policies/*</url> <url>/policies/remove-policy</url>
<method>GET</method> <method>POST</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Update Policy</name> <name>View Policy</name>
<path>/device-mgt/admin/policies/Update</path> <path>/device-mgt/admin/policies/View</path>
<url>/policies/*</url> <url>/policies/*</url>
<method>PUT</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Update Policy</name> <name>Update Policy</name>
<path>/device-mgt/admin/policies/Update</path> <path>/device-mgt/admin/policies/Update</path>
<url>/policies/apply-changes</url> <url>/policies/*</url>
<method>PUT</method> <method>PUT</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Update Policy</name> <name>Update Policy</name>
<path>/device-mgt/admin/policies/Change-Priority</path> <path>/device-mgt/admin/policies/Update</path>
<url>/policies/priorities</url> <url>/policies/apply-changes</url>
<method>PUT</method> <method>PUT</method>
</Permission> </Permission>
<!-- End of Policy related APIs --> <Permission>
<Permission> <name>Update Policy</name>
<name>Notifications</name> <path>/device-mgt/admin/policies/Change-Priority</path>
<path>/device-mgt/admin/notifications</path> <url>/policies/priorities</url>
<url>/</url> <method>PUT</method>
<method>GET</method> </Permission>
</Permission> <!-- End of Policy related APIs -->
<!-- Notification related APIs --> <Permission>
<Permission> <name>Notifications</name>
<name>View notifications</name> <path>/device-mgt/admin/notifications</path>
<path>/device-mgt/admin/notifications/View</path> <url>/</url>
<url>/notifications</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- Notification related APIs -->
<Permission> <Permission>
<name>Mark checked notifications</name> <name>View notifications</name>
<path>/device-mgt/admin/notifications/View</path> <path>/device-mgt/admin/notifications/View</path>
<url>/notifications/*/mark-checked</url> <url>/notifications</url>
<method>PUT</method> <method>GET</method>
</Permission> </Permission>
<!-- End of Notification related APIs --> <Permission>
<Permission> <name>Mark checked notifications</name>
<name>Users</name> <path>/device-mgt/admin/notifications/View</path>
<path>/device-mgt/admin/users</path> <url>/notifications/*/mark-checked</url>
<url>/</url> <method>PUT</method>
<method>GET</method> </Permission>
</Permission> <!-- End of Notification related APIs -->
<!-- User related APIs --> <Permission>
<Permission> <name>Users</name>
<name>List users</name> <path>/device-mgt/admin/users</path>
<path>/device-mgt/admin/users/List</path> <url>/</url>
<url>/users</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- User related APIs -->
<Permission> <Permission>
<name>Add user</name> <name>List users</name>
<path>/device-mgt/admin/users/Add</path> <path>/device-mgt/admin/users/List</path>
<url>/users</url> <url>/users</url>
<method>POST</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>List users</name> <name>Add user</name>
<path>/device-mgt/admin/users/Search</path> <path>/device-mgt/admin/users/Add</path>
<url>/users/search/usernames</url> <url>/users</url>
<method>GET</method> <method>POST</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Remove user</name> <name>List users</name>
<path>/device-mgt/admin/users/Remove</path> <path>/device-mgt/admin/users/Search</path>
<url>/users/*</url> <url>/users/search/usernames</url>
<method>DELETE</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View user</name> <name>Remove user</name>
<path>/device-mgt/admin/users/View</path> <path>/device-mgt/admin/users/Remove</path>
<url>/users/*</url> <url>/users/*</url>
<method>GET</method> <method>DELETE</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Update user</name> <name>View user</name>
<path>/device-mgt/admin/users/Update</path> <path>/device-mgt/admin/users/View</path>
<url>/users/*</url> <url>/users/*</url>
<method>PUT</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Update user credentials</name> <name>Update user</name>
<path>/device-mgt/admin/users/Change-Password</path> <path>/device-mgt/admin/users/Update</path>
<url>/users/*/credentials</url> <url>/users/*</url>
<method>PUT</method> <method>PUT</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View assigned role</name> <name>Update user credentials</name>
<path>/device-mgt/admin/roles/Assigned-Roles</path> <path>/device-mgt/admin/users/Change-Password</path>
<url>/users/*/roles</url> <url>/users/*/credentials</url>
<method>GET</method> <method>PUT</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Change any user credentials</name> <name>View assigned role</name>
<path>/device-mgt/admin/users/Change-Password-Any</path> <path>/device-mgt/admin/roles/Assigned-Roles</path>
<url>/admin/users/*/credentials</url> <url>/users/*/roles</url>
<method>POST</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Send invitation mail</name> <name>Change any user credentials</name>
<path>/device-mgt/admin/users/Send-invitations</path> <path>/device-mgt/admin/users/Change-Password-Any</path>
<url>/users/send-invitation</url> <url>/admin/users/*/credentials</url>
<method>POST</method> <method>POST</method>
</Permission> </Permission>
<!-- End of User related APIs --> <Permission>
<Permission> <name>Send invitation mail</name>
<name>Roles</name> <path>/device-mgt/admin/users/Send-invitations</path>
<path>/device-mgt/admin/roles</path> <url>/users/send-invitation</url>
<url>/</url> <method>POST</method>
<method>GET</method> </Permission>
</Permission> <!-- End of User related APIs -->
<!-- Role related APIs --> <Permission>
<Permission> <name>Roles</name>
<name>List roles</name> <path>/device-mgt/admin/roles</path>
<path>/device-mgt/admin/roles/List</path> <url>/</url>
<url>/roles</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- Role related APIs -->
<Permission> <Permission>
<name>Add role</name> <name>List roles</name>
<path>/device-mgt/admin/roles/Add</path> <path>/device-mgt/admin/roles/List</path>
<url>/roles</url> <url>/roles</url>
<method>POST</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Remove role</name> <name>Add role</name>
<path>/device-mgt/admin/roles/Remove</path> <path>/device-mgt/admin/roles/Add</path>
<url>/roles/*</url> <url>/roles</url>
<method>DELETE</method> <method>POST</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View role</name> <name>Remove role</name>
<path>/device-mgt/admin/roles/View</path> <path>/device-mgt/admin/roles/Remove</path>
<url>/roles/*</url> <url>/roles/*</url>
<method>GET</method> <method>DELETE</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Update role</name> <name>View role</name>
<path>/device-mgt/admin/roles/Update</path> <path>/device-mgt/admin/roles/View</path>
<url>/roles/*</url> <url>/roles/*</url>
<method>PUT</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View role permissions</name> <name>Update role</name>
<path>/device-mgt/admin/roles/View-Permission</path> <path>/device-mgt/admin/roles/Update</path>
<url>/roles/*/permissions</url> <url>/roles/*</url>
<method>GET</method> <method>PUT</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Add Users to role</name> <name>View role permissions</name>
<path>/device-mgt/admin/roles/Add-Users</path> <path>/device-mgt/admin/roles/View-Permission</path>
<url>/roles/*/users</url> <url>/roles/*/permissions</url>
<method>PUT</method> <method>GET</method>
</Permission> </Permission>
<!-- End of Role related APIs --> <Permission>
<Permission> <name>Add Users to role</name>
<name>Configurations</name> <path>/device-mgt/admin/roles/Add-Users</path>
<path>/device-mgt/admin/general-configs</path> <url>/roles/*/users</url>
<url>/</url> <method>PUT</method>
<method>GET</method> </Permission>
</Permission> <!-- End of Role related APIs -->
<!-- Configuration related APIs --> <Permission>
<Permission> <name>Configurations</name>
<name>View configuration</name> <path>/device-mgt/admin/general-configs</path>
<path>/device-mgt/admin/general-configuration/View</path> <url>/</url>
<url>/configuration</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- Configuration related APIs -->
<Permission> <Permission>
<name>Update configuration</name> <name>View configuration</name>
<path>/device-mgt/admin/general-configuration/Update</path> <path>/device-mgt/admin/general-configuration/View</path>
<url>/configuration</url> <url>/configuration</url>
<method>PUT</method> <method>GET</method>
</Permission> </Permission>
<!-- End of Configuration related APIs --> <Permission>
<Permission> <name>Update configuration</name>
<name>Activities</name> <path>/device-mgt/admin/general-configuration/Update</path>
<path>/device-mgt/admin/activities</path> <url>/configuration</url>
<url>/</url> <method>PUT</method>
<method>GET</method> </Permission>
</Permission> <!-- End of Configuration related APIs -->
<!-- Activity related APIs --> <Permission>
<Permission> <name>Activities</name>
<name>View Activities</name> <path>/device-mgt/admin/activities</path>
<path>/device-mgt/admin/activities/View</path> <url>/</url>
<url>/activities</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- Activity related APIs -->
<Permission> <Permission>
<name>View Activity Details</name> <name>View Activities</name>
<path>/device-mgt/admin/activities/View</path> <path>/device-mgt/admin/activities/View</path>
<url>/activities/*</url> <url>/activities</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<!-- End of Activity related APIs --> <Permission>
<Permission> <name>View Activity Details</name>
<name>Applications</name> <path>/device-mgt/admin/activities/View</path>
<path>/device-mgt/admin/applications</path> <url>/activities/*</url>
<url>/</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- End of Activity related APIs -->
<!-- Application related APIs --> <Permission>
<Permission> <name>Applications</name>
<name>Install Applications</name> <path>/device-mgt/admin/applications</path>
<path>/device-mgt/admin/application/Install</path> <url>/</url>
<url>/admin/applications/install-application</url> <method>GET</method>
<method>POST</method> </Permission>
</Permission> <!-- Application related APIs -->
<Permission> <Permission>
<name>Uninstall-Applications</name> <name>Install Applications</name>
<path>/device-mgt/admin/application/Uninstall</path> <path>/device-mgt/admin/application/Install</path>
<url>/admin/applications/uninstall-application</url> <url>/admin/applications/install-application</url>
<method>POST</method> <method>POST</method>
</Permission> </Permission>
<!-- End of Application related APIs --> <Permission>
<!-- End of Admin Permissions --> <name>Uninstall-Applications</name>
<!-- User Permissions --> <path>/device-mgt/admin/application/Uninstall</path>
<Permission> <url>/admin/applications/uninstall-application</url>
<name>Device Management User</name> <method>POST</method>
<path>/device-mgt/user</path> </Permission>
<url>/</url> <!-- End of Application related APIs -->
<method>GET</method> <!-- End of Admin Permissions -->
</Permission> <!-- User Permissions -->
<Permission> <Permission>
<name>User Devices</name> <name>Device Management User</name>
<path>/device-mgt/user/devices</path> <path>/device-mgt/user</path>
<url>/</url> <url>/</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>User Policies</name> <name>User Devices</name>
<path>/device-mgt/user/policies</path> <path>/device-mgt/user/devices</path>
<url>/</url> <url>/</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>User Notifications</name> <name>User Policies</name>
<path>/device-mgt/user/notifications</path> <path>/device-mgt/user/policies</path>
<url>/</url> <url>/</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>User Operations</name> <name>User Notifications</name>
<path>/device-mgt/user/operations</path> <path>/device-mgt/user/notifications</path>
<url>/</url> <url>/</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<!-- End of User Permissions --> <Permission>
<name>User Operations</name>
<path>/device-mgt/user/operations</path>
<url>/</url>
<method>GET</method>
</Permission>
<!-- End of User Permissions -->
<!--End of Permission Tree--> <!--End of Permission Tree-->
</PermissionConfiguration> </PermissionConfiguration>

@ -20,11 +20,13 @@ package org.wso2.carbon.device.mgt.core.notification.mgt.dao;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
import org.wso2.carbon.device.mgt.common.TransactionManagementException; import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.UnsupportedDatabaseEngineException;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl.NotificationDAOImpl; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl.*;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
import javax.sql.DataSource; import javax.sql.DataSource;
@ -39,21 +41,48 @@ import java.util.List;
public class NotificationManagementDAOFactory { public class NotificationManagementDAOFactory {
private static DataSource dataSource; private static DataSource dataSource;
private static String databaseEngine;
private static final Log log = LogFactory.getLog(NotificationManagementDAOFactory.class); private static final Log log = LogFactory.getLog(NotificationManagementDAOFactory.class);
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>(); private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
public static NotificationDAO getNotificationDAO() { public static NotificationDAO getNotificationDAO() {
return new NotificationDAOImpl(); if (databaseEngine != null) {
switch (databaseEngine) {
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE:
return new OracleNotificationDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL:
return new SQLServerNotificationDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL:
return new PostgreSQLNotificationDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2:
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL:
return new GenericNotificationDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
}
}
throw new IllegalStateException("Database engine has not initialized properly.");
} }
public static void init(DataSourceConfig config) { public static void init(DataSourceConfig config) {
dataSource = resolveDataSource(config); dataSource = resolveDataSource(config);
try {
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
} catch (SQLException e) {
log.error("Error occurred while retrieving config.datasource connection", e);
}
} }
public static void init(DataSource dtSource) { public static void init(DataSource dtSource) {
dataSource = dtSource; dataSource = dtSource;
try {
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
} catch (SQLException e) {
log.error("Error occurred while retrieving config.datasource connection", e);
}
} }
public static void beginTransaction() throws TransactionManagementException { public static void beginTransaction() throws TransactionManagementException {
Connection conn = currentConnection.get(); Connection conn = currentConnection.get();
if (conn != null) { if (conn != null) {

@ -35,7 +35,7 @@ import java.util.List;
/** /**
* Implementation of NotificationDAO which includes the methods to do CRUD operations on notification. * Implementation of NotificationDAO which includes the methods to do CRUD operations on notification.
*/ */
public class NotificationDAOImpl implements NotificationDAO { public abstract class AbstractNotificationDAOImpl implements NotificationDAO {
@Override @Override
public int addNotification(int deviceId, int tenantId, public int addNotification(int deviceId, int tenantId,
@ -87,7 +87,7 @@ public class NotificationDAOImpl implements NotificationDAO {
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
notification = this.getNotification(rs); notification = NotificationDAOUtil.getNotification(rs);
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new NotificationManagementException( throw new NotificationManagementException(
@ -165,7 +165,7 @@ public class NotificationDAOImpl implements NotificationDAO {
rs = stmt.executeQuery(); rs = stmt.executeQuery();
notifications = new ArrayList<>(); notifications = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
notifications.add(this.getNotification(rs)); notifications.add(NotificationDAOUtil.getNotification(rs));
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new NotificationManagementException( throw new NotificationManagementException(
@ -176,45 +176,6 @@ public class NotificationDAOImpl implements NotificationDAO {
return notifications; return notifications;
} }
@Override
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws NotificationManagementException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql =
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
sql = sql + " LIMIT ?,?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId);
int paramIdx = 3;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(this.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all notifications", e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
@Override @Override
public int getNotificationCount(int tenantId) throws NotificationManagementException { public int getNotificationCount(int tenantId) throws NotificationManagementException {
int notificationCount = 0; int notificationCount = 0;
@ -277,7 +238,7 @@ public class NotificationDAOImpl implements NotificationDAO {
rs = stmt.executeQuery(); rs = stmt.executeQuery();
notifications = new ArrayList<>(); notifications = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
notifications.add(this.getNotification(rs)); notifications.add(NotificationDAOUtil.getNotification(rs));
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new NotificationManagementException( throw new NotificationManagementException(
@ -322,59 +283,4 @@ public class NotificationDAOImpl implements NotificationDAO {
} }
return notificationCountByStatus; return notificationCountByStatus;
} }
@Override
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
NotificationManagementException{
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
"AND TENANT_ID = ?";
sql = sql + " LIMIT ?,?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, status.toString());
stmt.setInt(3, tenantId);
int paramIdx = 4;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(this.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all " +
"notifications by status : " + status, e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
private Notification getNotification(ResultSet rs) throws SQLException {
Notification notification = new Notification();
notification.setNotificationId(rs.getInt("NOTIFICATION_ID"));
notification.setOperationId(rs.getInt("OPERATION_ID"));
notification.setDescription(rs.getString("DESCRIPTION"));
notification.setStatus(rs.getString("STATUS"));
return notification;
}
} }

@ -0,0 +1,122 @@
/*
* Copyright (c) 2016, 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.notification.mgt.dao.impl;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* This class holds the generic implementation of NotificationDAO which can be used to support ANSI db syntax.
*/
public class GenericNotificationDAOImpl extends AbstractNotificationDAOImpl {
@Override
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
NotificationManagementException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql =
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
sql = sql + " LIMIT ?,?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId);
int paramIdx = 3;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all notifications", e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
@Override
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
NotificationManagementException{
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
"AND TENANT_ID = ?";
sql = sql + " LIMIT ?,?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, status.toString());
stmt.setInt(3, tenantId);
int paramIdx = 4;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all " +
"notifications by status : " + status, e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
}

@ -0,0 +1,122 @@
/*
* Copyright (c) 2016, 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.notification.mgt.dao.impl;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* This class holds the Oracle implementation of NotificationDAO which can be used to support Oracle db syntax.
*/
public class OracleNotificationDAOImpl extends AbstractNotificationDAOImpl {
@Override
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
NotificationManagementException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql =
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
sql = sql + " WHERE OFFSET >= ? AND ROWNUM <= ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId);
int paramIdx = 3;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all notifications", e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
@Override
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
NotificationManagementException{
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
"AND TENANT_ID = ?";
sql = sql + " OFFSET >= ? AND ROWNUM <= ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, status.toString());
stmt.setInt(3, tenantId);
int paramIdx = 4;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all " +
"notifications by status : " + status, e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
}

@ -0,0 +1,122 @@
/*
* Copyright (c) 2016, 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.notification.mgt.dao.impl;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* This class holds the implementation of NotificationDAO which can be used to support PostgreSQL db syntax.
*/
public class PostgreSQLNotificationDAOImpl extends AbstractNotificationDAOImpl {
@Override
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
NotificationManagementException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql =
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
sql = sql + " LIMIT ? OFFSET ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId);
int paramIdx = 3;
stmt.setInt(paramIdx++, request.getRowCount());
stmt.setInt(paramIdx, request.getStartIndex());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all notifications", e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
@Override
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
NotificationManagementException{
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
"AND TENANT_ID = ?";
sql = sql + " LIMIT ? OFFSET ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, status.toString());
stmt.setInt(3, tenantId);
int paramIdx = 4;
stmt.setInt(paramIdx++, request.getRowCount());
stmt.setInt(paramIdx, request.getStartIndex());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all " +
"notifications by status : " + status, e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
}

@ -0,0 +1,122 @@
/*
* Copyright (c) 2016, 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.notification.mgt.dao.impl;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* This class holds the implementation of NotificationDAO which can be used to support SQLServer db syntax.
*/
public class SQLServerNotificationDAOImpl extends AbstractNotificationDAOImpl {
@Override
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
NotificationManagementException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql =
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
sql = sql + " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId);
int paramIdx = 3;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all notifications", e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
@Override
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
NotificationManagementException{
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
"AND TENANT_ID = ?";
sql = sql + " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, status.toString());
stmt.setInt(3, tenantId);
int paramIdx = 4;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all " +
"notifications by status : " + status, e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
}

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.core.notification.mgt.dao.util;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
@ -123,4 +124,13 @@ public class NotificationDAOUtil {
throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e); throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
} }
} }
public static Notification getNotification(ResultSet rs) throws SQLException {
Notification notification = new Notification();
notification.setNotificationId(rs.getInt("NOTIFICATION_ID"));
notification.setOperationId(rs.getInt("OPERATION_ID"));
notification.setDescription(rs.getString("DESCRIPTION"));
notification.setStatus(rs.getString("STATUS"));
return notification;
}
} }

@ -46,8 +46,8 @@ public class PostgreSQLOperationDAOImpl extends GenericOperationDAOImpl {
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
"OPERATION_CODE, om.STATUS FROM DM_OPERATION o " + "o.OPERATION_CODE, om.STATUS FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ? OFFSET ?"; "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ? OFFSET ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
@ -72,7 +72,7 @@ public class PostgreSQLOperationDAOImpl extends GenericOperationDAOImpl {
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
"available for the device'" + enrolmentId + "' with status '", e); "available for the device'" + enrolmentId, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -89,7 +89,7 @@ public class PostgreSQLOperationDAOImpl extends GenericOperationDAOImpl {
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE " +
"FROM DM_OPERATION o " + "FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " +

@ -1,25 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt;
public class EvaluationContext {
}

@ -1,25 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt;
public class PolicyEvaluationException extends Exception {
}

@ -1,25 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt;
public interface PolicyEvaluationStrategy {
Profile execute(EvaluationContext ctx) throws PolicyEvaluationException;
}

@ -1,25 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt;
public class PolicyManagementException extends Exception {
}

@ -1,60 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.policy.mgt.policy.Policy;
import java.util.List;
public interface PolicyManager {
public enum Type {
USER_BASED, ROLE_BASED, PLATFORM_BASED
}
boolean addPolicy(Policy policy) throws PolicyManagementException;
boolean removePolicy(String policyId) throws PolicyManagementException;
boolean updatePolicy(Policy policy) throws PolicyManagementException;
Policy getPolicy(String policyId) throws PolicyManagementException;
List<Policy> getPolicies() throws PolicyManagementException;
List<Policy> getUserBasedPolicies(String user) throws PolicyManagementException;
List<Policy> getRoleBasedPolicies(String role) throws PolicyManagementException;
List<Policy> getPlatformBasedPolicies(String platform) throws PolicyManagementException;
boolean assignRoleBasedPolicy(String policyId, String role) throws PolicyManagementException;
boolean assignRoleBasedPolicy(String policyId, List<String> roles) throws PolicyManagementException;
boolean assignUserBasedPolicy(String policyId, String user) throws PolicyManagementException;
boolean assignUserBasedPolicy(String policyId, List<String> users) throws PolicyManagementException;
boolean assignPlatformBasedPolicy(String policyId, String platform) throws PolicyManagementException;
Profile getEffectiveProfile(DeviceIdentifier deviceId) throws PolicyManagementException;
}

@ -1,35 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt;
import org.wso2.carbon.device.mgt.core.policy.mgt.policy.Policy;
public interface PolicyRepository {
public enum Type {
USER_BASED, ROLE_BASED, PLATFORM_BASED
}
void addPolicy(Policy policy) throws PolicyManagementException;
void remotePolicy(Policy policy) throws PolicyManagementException;
void getPolicy(String id) throws PolicyManagementException;
}

@ -1,22 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt;
public class Profile {
}

@ -1,25 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt;
public class Rule {
}

@ -1,25 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt;
public interface RuleCombiningStrategy {
}

@ -1,25 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt.dao;
public interface PolicyDAO {
}

@ -1,27 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt.dao;
public class PolicyDAOFactory {
public static PolicyDAO getPolicyDAO() {
return new PolicyDAOImpl();
}
}

@ -1,25 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt.dao;
public class PolicyDAOImpl implements PolicyDAO {
}

@ -1,33 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt.policy;
public class PlatformBasedPolicy extends Policy {
private String platform;
public String getPlatform() {
return platform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
}

@ -1,33 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt.policy;
public class Policy {
private String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}

@ -1,33 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt.policy;
public class RoleBasedPolicy extends Policy {
private String role;
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}

@ -1,33 +0,0 @@
/*
* Copyright (c) 2015, 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.policy.mgt.policy;
public class UsedBasedPolicy extends Policy {
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}

@ -2,7 +2,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
ID BIGSERIAL PRIMARY KEY, ID BIGSERIAL PRIMARY KEY,
NAME VARCHAR(300) DEFAULT NULL, NAME VARCHAR(300) DEFAULT NULL,
PROVIDER_TENANT_ID INTEGER DEFAULT 0, PROVIDER_TENANT_ID INTEGER DEFAULT 0,
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
UNIQUE(NAME)
); );
CREATE TABLE IF NOT EXISTS DM_DEVICE ( CREATE TABLE IF NOT EXISTS DM_DEVICE (
@ -272,7 +273,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT (
ID BIGSERIAL NOT NULL PRIMARY KEY, ID BIGSERIAL NOT NULL PRIMARY KEY,
POLICY_ID INTEGER NOT NULL, POLICY_ID INTEGER NOT NULL,
DEVICE_TYPE VARCHAR(300) NOT NULL, DEVICE_TYPE VARCHAR(300) NOT NULL,
TENANT_ID INTEGER NOT NULL TENANT_ID INTEGER NOT NULL
); );
@ -289,18 +290,11 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
ON UPDATE NO ACTION ON UPDATE NO ACTION
); );
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY ( CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
ID BIGSERIAL NOT NULL PRIMARY KEY, ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_GROUP_ID INT NOT NULL, DEVICE_GROUP_ID INT NOT NULL,
POLICY_ID INT NOT NULL, POLICY_ID INT NOT NULL,
TENANT_ID INT NOT NULL, TENANT_ID INT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_GROUP_POLICY
FOREIGN KEY (DEVICE_GROUP_ID)
REFERENCES DM_GROUP (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY
FOREIGN KEY (POLICY_ID) FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID) REFERENCES DM_POLICY (ID)
@ -350,6 +344,52 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING (
-- POLICY RELATED TABLES FINISHED -- -- POLICY RELATED TABLES FINISHED --
-- DEVICE GROUP TABLES --
CREATE TABLE IF NOT EXISTS DM_GROUP (
ID BIGSERIAL NOT NULL PRIMARY KEY,
GROUP_NAME VARCHAR(100) DEFAULT NULL,
DESCRIPTION BYTEA DEFAULT NULL,
DATE_OF_CREATE INTEGER DEFAULT NULL,
DATE_OF_LAST_UPDATE INTEGER DEFAULT NULL,
OWNER VARCHAR(45) DEFAULT NULL,
TENANT_ID INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER DEFAULT NULL,
GROUP_ID INTEGER DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0,
CONSTRAINT fk_DM_DEVICE_GROUP_MAP_DM_DEVICE2 FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_DM_DEVICE_GROUP_MAP_DM_GROUP2 FOREIGN KEY (GROUP_ID)
REFERENCES DM_GROUP (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
-- END OF DEVICE GROUP TABLES --
-- POLICY AND DEVICE GROUP MAPPING --
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_GROUP_ID INTEGER NOT NULL,
POLICY_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
CONSTRAINT FK_DM_DEVICE_GROUP_POLICY
FOREIGN KEY (DEVICE_GROUP_ID)
REFERENCES DM_GROUP (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
-- END OF POLICY AND DEVICE GROUP MAPPING --
-- NOTIFICATION TABLE -- -- NOTIFICATION TABLE --
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
NOTIFICATION_ID BIGSERIAL NOT NULL PRIMARY KEY, NOTIFICATION_ID BIGSERIAL NOT NULL PRIMARY KEY,
@ -420,7 +460,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
CPU_USAGE DECIMAL(5) NULL, CPU_USAGE DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT NULL, PLUGGED_IN BOOLEAN NOT NULL DEFAULT FALSE,
UPDATE_TIMESTAMP BIGINT NOT NULL, UPDATE_TIMESTAMP BIGINT NOT NULL,
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)

Loading…
Cancel
Save