diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml
index 6439eab85e..050e9089cf 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml
@@ -30,379 +30,385 @@
-
- Device Management
- /device-mgt
- /
- GET
-
-
-
- Device Management Admin
- /device-mgt/admin
- /
- GET
-
-
- Devices
- /device-mgt/admin/devices
- /
- GET
-
-
-
- List devices
- /device-mgt/admin/devices/List
- /devices
- GET
-
-
- Search devices
- /device-mgt/admin/devices/Search
- /devices/search-devices
- POST
-
-
- View device
- /device-mgt/admin/devices/View
- /devices/*/*
- GET
-
-
- View device applications
- /device-mgt/admin/devices/View-Applications
- /devices/*/*/applications
- GET
-
-
- View device effective-policy
- /device-mgt/admin/devices/View-Active-Policy
- /devices/*/*/effective-policy
- GET
-
-
- View devices feature
- /device-mgt/admin/devices/View-Features
- /devices/*/*/features
- GET
-
-
- View device operations
- /device-mgt/admin/devices/View-Operations
- /devices/*/*/operations
- GET
-
-
- View Compliance Data
- /device-mgt/admin/devices/View-Compliance-Data
- /devices/*/*/compliance-data
- GET
-
-
- List all devices
- /device-mgt/admin/devices/Admin-View
- /admin/devices
- GET
-
-
- View device types
- /device-mgt/admin/devices/Admin-DeviceType-View
- /admin/device-types
- GET
-
-
-
- Policies
- /device-mgt/admin/policies
- /
- GET
-
-
-
- List policies
- /device-mgt/admin/policies/List
- /policies
- GET
-
-
- Add Policy
- /device-mgt/admin/policies/Add
- /policies
- POST
-
-
- Activate policy
- /device-mgt/admin/policies/Activate-Policy
- /policies/activate-policy
- PUT
-
-
- Deactivate Policy
- /device-mgt/admin/policies/Deactivate-Policy
- /policies/deactivate-policy
- PUT
-
-
- Remove Policy
- /device-mgt/admin/policies/Remove
- /policies/remove-policy
- POST
-
-
- View Policy
- /device-mgt/admin/policies/View
- /policies/*
- GET
-
-
- Update Policy
- /device-mgt/admin/policies/Update
- /policies/*
- PUT
-
-
- Update Policy
- /device-mgt/admin/policies/Update
- /policies/apply-changes
- PUT
-
-
- Update Policy
- /device-mgt/admin/policies/Change-Priority
- /policies/priorities
- PUT
-
-
-
- Notifications
- /device-mgt/admin/notifications
- /
- GET
-
-
-
- View notifications
- /device-mgt/admin/notifications/View
- /notifications
- GET
-
-
- Mark checked notifications
- /device-mgt/admin/notifications/View
- /notifications/*/mark-checked
- PUT
-
-
-
- Users
- /device-mgt/admin/users
- /
- GET
-
-
-
- List users
- /device-mgt/admin/users/List
- /users
- GET
-
-
- Add user
- /device-mgt/admin/users/Add
- /users
- POST
-
-
- List users
- /device-mgt/admin/users/Search
- /users/search/usernames
- GET
-
-
- Remove user
- /device-mgt/admin/users/Remove
- /users/*
- DELETE
-
-
- View user
- /device-mgt/admin/users/View
- /users/*
- GET
-
-
- Update user
- /device-mgt/admin/users/Update
- /users/*
- PUT
-
-
- Update user credentials
- /device-mgt/admin/users/Change-Password
- /users/*/credentials
- PUT
-
-
- View assigned role
- /device-mgt/admin/roles/Assigned-Roles
- /users/*/roles
- GET
-
-
- Change any user credentials
- /device-mgt/admin/users/Change-Password-Any
- /admin/users/*/credentials
- POST
-
-
- Send invitation mail
- /device-mgt/admin/users/Send-invitations
- /users/send-invitation
- POST
-
-
-
- Roles
- /device-mgt/admin/roles
- /
- GET
-
-
-
- List roles
- /device-mgt/admin/roles/List
- /roles
- GET
-
-
- Add role
- /device-mgt/admin/roles/Add
- /roles
- POST
-
-
- Remove role
- /device-mgt/admin/roles/Remove
- /roles/*
- DELETE
-
-
- View role
- /device-mgt/admin/roles/View
- /roles/*
- GET
-
-
- Update role
- /device-mgt/admin/roles/Update
- /roles/*
- PUT
-
-
- View role permissions
- /device-mgt/admin/roles/View-Permission
- /roles/*/permissions
- GET
-
-
- Add Users to role
- /device-mgt/admin/roles/Add-Users
- /roles/*/users
- PUT
-
-
-
- Configurations
- /device-mgt/admin/general-configs
- /
- GET
-
-
-
- View configuration
- /device-mgt/admin/general-configuration/View
- /configuration
- GET
-
-
- Update configuration
- /device-mgt/admin/general-configuration/Update
- /configuration
- PUT
-
-
-
- Activities
- /device-mgt/admin/activities
- /
- GET
-
-
-
- View Activities
- /device-mgt/admin/activities/View
- /activities
- GET
-
-
- View Activity Details
- /device-mgt/admin/activities/View
- /activities/*
- GET
-
-
-
- Applications
- /device-mgt/admin/applications
- /
- GET
-
-
-
- Install Applications
- /device-mgt/admin/application/Install
- /admin/applications/install-application
- POST
-
-
- Uninstall-Applications
- /device-mgt/admin/application/Uninstall
- /admin/applications/uninstall-application
- POST
-
-
-
-
-
- Device Management User
- /device-mgt/user
- /
- GET
-
-
- User Devices
- /device-mgt/user/devices
- /
- GET
-
-
- User Policies
- /device-mgt/user/policies
- /
- GET
-
-
- User Notifications
- /device-mgt/user/notifications
- /
- GET
-
-
- User Operations
- /device-mgt/user/operations
- /
- GET
-
-
+
+ Device Management
+ /device-mgt
+ /
+ GET
+
+
+
+ Device Management Admin
+ /device-mgt/admin
+ /
+ GET
+
+
+ Devices
+ /device-mgt/admin/devices
+ /
+ GET
+
+
+
+ List devices
+ /device-mgt/admin/devices/List
+ /devices
+ GET
+
+
+ Search devices
+ /device-mgt/admin/devices/Search
+ /devices/search-devices
+ POST
+
+
+ View device
+ /device-mgt/admin/devices/View
+ /devices/*/*
+ GET
+
+
+ View device info
+ /device-mgt/admin/devices/View
+ /devices/*/*/info
+ GET
+
+
+ View device applications
+ /device-mgt/admin/devices/View-Applications
+ /devices/*/*/applications
+ GET
+
+
+ View device effective-policy
+ /device-mgt/admin/devices/View-Active-Policy
+ /devices/*/*/effective-policy
+ GET
+
+
+ View devices feature
+ /device-mgt/admin/devices/View-Features
+ /devices/*/*/features
+ GET
+
+
+ View device operations
+ /device-mgt/admin/devices/View-Operations
+ /devices/*/*/operations
+ GET
+
+
+ View Compliance Data
+ /device-mgt/admin/devices/View-Compliance-Data
+ /devices/*/*/compliance-data
+ GET
+
+
+ List all devices
+ /device-mgt/admin/devices/Admin-View
+ /admin/devices
+ GET
+
+
+ View device types
+ /device-mgt/admin/devices/Admin-DeviceType-View
+ /admin/device-types
+ GET
+
+
+
+ Policies
+ /device-mgt/admin/policies
+ /
+ GET
+
+
+
+ List policies
+ /device-mgt/admin/policies/List
+ /policies
+ GET
+
+
+ Add Policy
+ /device-mgt/admin/policies/Add
+ /policies
+ POST
+
+
+ Activate policy
+ /device-mgt/admin/policies/Activate-Policy
+ /policies/activate-policy
+ PUT
+
+
+ Deactivate Policy
+ /device-mgt/admin/policies/Deactivate-Policy
+ /policies/deactivate-policy
+ PUT
+
+
+ Remove Policy
+ /device-mgt/admin/policies/Remove
+ /policies/remove-policy
+ POST
+
+
+ View Policy
+ /device-mgt/admin/policies/View
+ /policies/*
+ GET
+
+
+ Update Policy
+ /device-mgt/admin/policies/Update
+ /policies/*
+ PUT
+
+
+ Update Policy
+ /device-mgt/admin/policies/Update
+ /policies/apply-changes
+ PUT
+
+
+ Update Policy
+ /device-mgt/admin/policies/Change-Priority
+ /policies/priorities
+ PUT
+
+
+
+ Notifications
+ /device-mgt/admin/notifications
+ /
+ GET
+
+
+
+ View notifications
+ /device-mgt/admin/notifications/View
+ /notifications
+ GET
+
+
+ Mark checked notifications
+ /device-mgt/admin/notifications/View
+ /notifications/*/mark-checked
+ PUT
+
+
+
+ Users
+ /device-mgt/admin/users
+ /
+ GET
+
+
+
+ List users
+ /device-mgt/admin/users/List
+ /users
+ GET
+
+
+ Add user
+ /device-mgt/admin/users/Add
+ /users
+ POST
+
+
+ List users
+ /device-mgt/admin/users/Search
+ /users/search/usernames
+ GET
+
+
+ Remove user
+ /device-mgt/admin/users/Remove
+ /users/*
+ DELETE
+
+
+ View user
+ /device-mgt/admin/users/View
+ /users/*
+ GET
+
+
+ Update user
+ /device-mgt/admin/users/Update
+ /users/*
+ PUT
+
+
+ Update user credentials
+ /device-mgt/admin/users/Change-Password
+ /users/*/credentials
+ PUT
+
+
+ View assigned role
+ /device-mgt/admin/roles/Assigned-Roles
+ /users/*/roles
+ GET
+
+
+ Change any user credentials
+ /device-mgt/admin/users/Change-Password-Any
+ /admin/users/*/credentials
+ POST
+
+
+ Send invitation mail
+ /device-mgt/admin/users/Send-invitations
+ /users/send-invitation
+ POST
+
+
+
+ Roles
+ /device-mgt/admin/roles
+ /
+ GET
+
+
+
+ List roles
+ /device-mgt/admin/roles/List
+ /roles
+ GET
+
+
+ Add role
+ /device-mgt/admin/roles/Add
+ /roles
+ POST
+
+
+ Remove role
+ /device-mgt/admin/roles/Remove
+ /roles/*
+ DELETE
+
+
+ View role
+ /device-mgt/admin/roles/View
+ /roles/*
+ GET
+
+
+ Update role
+ /device-mgt/admin/roles/Update
+ /roles/*
+ PUT
+
+
+ View role permissions
+ /device-mgt/admin/roles/View-Permission
+ /roles/*/permissions
+ GET
+
+
+ Add Users to role
+ /device-mgt/admin/roles/Add-Users
+ /roles/*/users
+ PUT
+
+
+
+ Configurations
+ /device-mgt/admin/general-configs
+ /
+ GET
+
+
+
+ View configuration
+ /device-mgt/admin/general-configuration/View
+ /configuration
+ GET
+
+
+ Update configuration
+ /device-mgt/admin/general-configuration/Update
+ /configuration
+ PUT
+
+
+
+ Activities
+ /device-mgt/admin/activities
+ /
+ GET
+
+
+
+ View Activities
+ /device-mgt/admin/activities/View
+ /activities
+ GET
+
+
+ View Activity Details
+ /device-mgt/admin/activities/View
+ /activities/*
+ GET
+
+
+
+ Applications
+ /device-mgt/admin/applications
+ /
+ GET
+
+
+
+ Install Applications
+ /device-mgt/admin/application/Install
+ /admin/applications/install-application
+ POST
+
+
+ Uninstall-Applications
+ /device-mgt/admin/application/Uninstall
+ /admin/applications/uninstall-application
+ POST
+
+
+
+
+
+ Device Management User
+ /device-mgt/user
+ /
+ GET
+
+
+ User Devices
+ /device-mgt/user/devices
+ /
+ GET
+
+
+ User Policies
+ /device-mgt/user/policies
+ /
+ GET
+
+
+ User Notifications
+ /device-mgt/user/notifications
+ /
+ GET
+
+
+ User Operations
+ /device-mgt/user/operations
+ /
+ GET
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationManagementDAOFactory.java
index 20e8543cb4..d280dd643e 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationManagementDAOFactory.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationManagementDAOFactory.java
@@ -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.LogFactory;
+import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
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.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 javax.sql.DataSource;
@@ -39,21 +41,48 @@ import java.util.List;
public class NotificationManagementDAOFactory {
private static DataSource dataSource;
+ private static String databaseEngine;
private static final Log log = LogFactory.getLog(NotificationManagementDAOFactory.class);
private static ThreadLocal currentConnection = new ThreadLocal();
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) {
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) {
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 {
Connection conn = currentConnection.get();
if (conn != null) {
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 74%
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..96c47cf0d2 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 AbstractNotificationDAOImpl implements NotificationDAO {
@Override
public int addNotification(int deviceId, int tenantId,
@@ -87,7 +87,7 @@ public class NotificationDAOImpl implements NotificationDAO {
rs = stmt.executeQuery();
while (rs.next()) {
- notification = this.getNotification(rs);
+ notification = NotificationDAOUtil.getNotification(rs);
}
} catch (SQLException e) {
throw new NotificationManagementException(
@@ -165,7 +165,7 @@ public class NotificationDAOImpl implements NotificationDAO {
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
- notifications.add(this.getNotification(rs));
+ notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
@@ -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;
@@ -277,7 +238,7 @@ public class NotificationDAOImpl implements NotificationDAO {
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
- notifications.add(this.getNotification(rs));
+ notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
@@ -322,59 +283,4 @@ public class NotificationDAOImpl implements NotificationDAO {
}
return notificationCountByStatus;
}
-
- @Override
- public List getNotificationsByStatus(PaginationRequest request, Notification.Status status, 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 = ? 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;
- }
-
}
\ No newline at end of file
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/GenericNotificationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/GenericNotificationDAOImpl.java
new file mode 100644
index 0000000000..0653ec3029
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/GenericNotificationDAOImpl.java
@@ -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 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(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 getNotificationsByStatus(PaginationRequest request, Notification.Status status, 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 = ? 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;
+ }
+}
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/OracleNotificationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/OracleNotificationDAOImpl.java
new file mode 100644
index 0000000000..829e586d79
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/OracleNotificationDAOImpl.java
@@ -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 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 + " 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 getNotificationsByStatus(PaginationRequest request, Notification.Status status, 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 = ? 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;
+ }
+}
\ No newline at end of file
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/PostgreSQLNotificationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/PostgreSQLNotificationDAOImpl.java
new file mode 100644
index 0000000000..2039c04cbc
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/PostgreSQLNotificationDAOImpl.java
@@ -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 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 ? 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 getNotificationsByStatus(PaginationRequest request, Notification.Status status, 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 = ? 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;
+ }
+}
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/SQLServerNotificationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/SQLServerNotificationDAOImpl.java
new file mode 100644
index 0000000000..e03a220ed1
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/SQLServerNotificationDAOImpl.java
@@ -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 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 + " 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 getNotificationsByStatus(PaginationRequest request, Notification.Status status, 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 = ? 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;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/util/NotificationDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/util/NotificationDAOUtil.java
index 5c87e1b311..36f7df6be0 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/util/NotificationDAOUtil.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/util/NotificationDAOUtil.java
@@ -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.LogFactory;
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.core.internal.DeviceManagementDataHolder;
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);
}
}
+
+ 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;
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/PostgreSQLOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/PostgreSQLOperationDAOImpl.java
index 0d107ead1d..c9ddcb3d91 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/PostgreSQLOperationDAOImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/operation/PostgreSQLOperationDAOImpl.java
@@ -46,8 +46,8 @@ public class PostgreSQLOperationDAOImpl extends GenericOperationDAOImpl {
List operations = new ArrayList();
try {
Connection conn = OperationManagementDAOFactory.getConnection();
- String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
- "OPERATION_CODE, om.STATUS FROM DM_OPERATION o " +
+ String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
+ "o.OPERATION_CODE, om.STATUS FROM DM_OPERATION o " +
"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 ?";
stmt = conn.prepareStatement(sql);
@@ -72,7 +72,7 @@ public class PostgreSQLOperationDAOImpl extends GenericOperationDAOImpl {
}
} catch (SQLException e) {
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 {
OperationManagementDAOUtil.cleanupResources(stmt, rs);
}
@@ -89,7 +89,7 @@ public class PostgreSQLOperationDAOImpl extends GenericOperationDAOImpl {
List operations = new ArrayList();
try {
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 " +
"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 " +
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/EvaluationContext.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/EvaluationContext.java
deleted file mode 100644
index fb62730082..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/EvaluationContext.java
+++ /dev/null
@@ -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 {
-
-
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyEvaluationException.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyEvaluationException.java
deleted file mode 100644
index 569f311aa6..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyEvaluationException.java
+++ /dev/null
@@ -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 {
-
-
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyEvaluationStrategy.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyEvaluationStrategy.java
deleted file mode 100644
index bd4557eeb0..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyEvaluationStrategy.java
+++ /dev/null
@@ -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;
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyManagementException.java
deleted file mode 100644
index a36bd28fda..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyManagementException.java
+++ /dev/null
@@ -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 {
-
-
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyManager.java
deleted file mode 100644
index a69068a003..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyManager.java
+++ /dev/null
@@ -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 getPolicies() throws PolicyManagementException;
-
- List getUserBasedPolicies(String user) throws PolicyManagementException;
-
- List getRoleBasedPolicies(String role) throws PolicyManagementException;
-
- List getPlatformBasedPolicies(String platform) throws PolicyManagementException;
-
- boolean assignRoleBasedPolicy(String policyId, String role) throws PolicyManagementException;
-
- boolean assignRoleBasedPolicy(String policyId, List roles) throws PolicyManagementException;
-
- boolean assignUserBasedPolicy(String policyId, String user) throws PolicyManagementException;
-
- boolean assignUserBasedPolicy(String policyId, List users) throws PolicyManagementException;
-
- boolean assignPlatformBasedPolicy(String policyId, String platform) throws PolicyManagementException;
-
- Profile getEffectiveProfile(DeviceIdentifier deviceId) throws PolicyManagementException;
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyRepository.java
deleted file mode 100644
index 1e16c2a58f..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/PolicyRepository.java
+++ /dev/null
@@ -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;
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/Profile.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/Profile.java
deleted file mode 100644
index 70f1b4269f..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/Profile.java
+++ /dev/null
@@ -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 {
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/Rule.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/Rule.java
deleted file mode 100644
index ad40cff1af..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/Rule.java
+++ /dev/null
@@ -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 {
-
-
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/RuleCombiningStrategy.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/RuleCombiningStrategy.java
deleted file mode 100644
index 862089c135..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/RuleCombiningStrategy.java
+++ /dev/null
@@ -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 {
-
-
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/dao/PolicyDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/dao/PolicyDAO.java
deleted file mode 100644
index db6354b008..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/dao/PolicyDAO.java
+++ /dev/null
@@ -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 {
-
-
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/dao/PolicyDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/dao/PolicyDAOFactory.java
deleted file mode 100644
index 5e5c570e62..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/dao/PolicyDAOFactory.java
+++ /dev/null
@@ -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();
- }
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/dao/PolicyDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/dao/PolicyDAOImpl.java
deleted file mode 100644
index de2de21bd7..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/dao/PolicyDAOImpl.java
+++ /dev/null
@@ -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 {
-
-
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/policy/PlatformBasedPolicy.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/policy/PlatformBasedPolicy.java
deleted file mode 100644
index 4914a33f26..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/policy/PlatformBasedPolicy.java
+++ /dev/null
@@ -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;
- }
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/policy/Policy.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/policy/Policy.java
deleted file mode 100644
index a528c09eed..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/policy/Policy.java
+++ /dev/null
@@ -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;
- }
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/policy/RoleBasedPolicy.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/policy/RoleBasedPolicy.java
deleted file mode 100644
index c08544f125..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/policy/RoleBasedPolicy.java
+++ /dev/null
@@ -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;
- }
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/policy/UsedBasedPolicy.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/policy/UsedBasedPolicy.java
deleted file mode 100644
index 0eb9417826..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/policy/mgt/policy/UsedBasedPolicy.java
+++ /dev/null
@@ -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;
- }
-
-}
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)