From 35ea88b9dec668148b0f86b8d719b3a521c99c69 Mon Sep 17 00:00:00 2001 From: harshanl Date: Thu, 4 Aug 2016 20:39:31 +0530 Subject: [PATCH] Fixed EMM-1476. --- ....java => AbstractNotificationDAOImpl.java} | 41 +------------ .../resources/dbscripts/cdm/postgresql.sql | 60 +++++++++++++++---- 2 files changed, 51 insertions(+), 50 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/{NotificationDAOImpl.java => AbstractNotificationDAOImpl.java} (89%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/NotificationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java similarity index 89% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/NotificationDAOImpl.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java index 608c5a4f2e..0f16103c6d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/NotificationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java @@ -35,7 +35,7 @@ import java.util.List; /** * Implementation of NotificationDAO which includes the methods to do CRUD operations on notification. */ -public class NotificationDAOImpl implements NotificationDAO { +public abstract class NotificationDAOImpl implements NotificationDAO { @Override public int addNotification(int deviceId, int tenantId, @@ -176,45 +176,6 @@ public class NotificationDAOImpl implements NotificationDAO { return notifications; } - @Override - public List getAllNotifications(PaginationRequest request, int tenantId) throws NotificationManagementException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - List 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 public int getNotificationCount(int tenantId) throws NotificationManagementException { int notificationCount = 0; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index dc3c6229f2..52083e9d8c 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -2,7 +2,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID BIGSERIAL PRIMARY KEY, NAME VARCHAR(300) DEFAULT NULL, 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 ( @@ -272,7 +273,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( ID BIGSERIAL NOT NULL PRIMARY KEY, POLICY_ID INTEGER NOT NULL, - DEVICE_TYPE VARCHAR(300) NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL, TENANT_ID INTEGER NOT NULL ); @@ -289,18 +290,11 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES ( ON UPDATE NO ACTION ); - CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_GROUP_ID INT NOT NULL, POLICY_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 FOREIGN KEY (POLICY_ID) REFERENCES DM_POLICY (ID) @@ -350,6 +344,52 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING ( -- 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 -- CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( NOTIFICATION_ID BIGSERIAL NOT NULL PRIMARY KEY, @@ -420,7 +460,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( CPU_USAGE DECIMAL(5) NULL, TOTAL_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, CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID)