From bf0e95fa6c15a141a20667282ec85a47fae59b07 Mon Sep 17 00:00:00 2001 From: harshanl Date: Mon, 7 Sep 2015 18:14:20 +0530 Subject: [PATCH] Fixed notification service issues --- .../DeviceManagementServiceComponent.java | 2 + .../mgt/dao/impl/NotificationDAOImpl.java | 21 +++------- .../src/test/resources/log4j.properties | 32 +++++++++++++++ .../src/test/resources/testng.xml | 41 +++++++++++++++++++ 4 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 components/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extension/src/test/resources/log4j.properties create mode 100644 components/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extension/src/test/resources/testng.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 7b34760c80..bb916522ed 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -42,6 +42,7 @@ import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.tenant.TenantConfigurationManagementServiceImpl; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImpl; +import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; @@ -117,6 +118,7 @@ public class DeviceManagementServiceComponent { DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig(); DeviceManagementDAOFactory.init(dsConfig); + NotificationManagementDAOFactory.init(dsConfig); /*Initialize Operation Manager*/ this.initOperationsManager(); 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/NotificationDAOImpl.java index ab1152dc92..2a1208ff12 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/NotificationDAOImpl.java @@ -42,11 +42,10 @@ public class NotificationDAOImpl implements NotificationDAO { public int addNotification(int deviceId, int tenantId, Notification notification) throws NotificationManagementException { Connection conn; - PreparedStatement stmt; + PreparedStatement stmt = null; ResultSet rs; int notificationId = -1; try { - NotificationManagementDAOFactory.beginTransaction(); conn = NotificationManagementDAOFactory.getConnection(); String sql = "INSERT INTO DM_NOTIFICATION(DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION, TENANT_ID) " + @@ -62,14 +61,12 @@ public class NotificationDAOImpl implements NotificationDAO { if (rs.next()) { notificationId = rs.getInt(1); } - NotificationManagementDAOFactory.commitTransaction(); } catch (Exception e) { - NotificationManagementDAOFactory.rollbackTransaction(); throw new NotificationManagementException("Error occurred while adding the " + "Notification for device id : " + deviceId, e); } finally { - NotificationManagementDAOFactory.closeConnection(); + NotificationDAOUtil.cleanupResources(stmt, null); } return notificationId; } @@ -78,10 +75,9 @@ public class NotificationDAOImpl implements NotificationDAO { public int updateNotification(Notification notification) throws NotificationManagementException { Connection conn; - PreparedStatement stmt; + PreparedStatement stmt = null; int rows; try { - NotificationManagementDAOFactory.beginTransaction(); conn = NotificationManagementDAOFactory.getConnection(); String sql = "UPDATE DM_NOTIFICATION SET OPERATION_ID = ?, STATUS = ?, DESCRIPTION = ? " + "WHERE NOTIFICATION_ID = ?"; @@ -91,13 +87,11 @@ public class NotificationDAOImpl implements NotificationDAO { stmt.setString(3, notification.getDescription()); stmt.setInt(4, notification.getNotificationId()); rows = stmt.executeUpdate(); - NotificationManagementDAOFactory.commitTransaction(); } catch (Exception e) { - NotificationManagementDAOFactory.rollbackTransaction(); throw new NotificationManagementException("Error occurred while updating the " + "Notification id : " + notification.getNotificationId(), e); } finally { - NotificationManagementDAOFactory.closeConnection(); + NotificationDAOUtil.cleanupResources(stmt, null); } return rows; } @@ -106,23 +100,20 @@ public class NotificationDAOImpl implements NotificationDAO { public int updateNotificationStatus(int notificationId, Notification.Status status) throws NotificationManagementException { Connection conn; - PreparedStatement stmt; + PreparedStatement stmt = null; int rows; try { - NotificationManagementDAOFactory.beginTransaction(); conn = NotificationManagementDAOFactory.getConnection(); String sql = "UPDATE DM_NOTIFICATION SET STATUS = ? WHERE NOTIFICATION_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, status.toString()); stmt.setInt(2, notificationId); rows = stmt.executeUpdate(); - NotificationManagementDAOFactory.commitTransaction(); } catch (Exception e) { - NotificationManagementDAOFactory.rollbackTransaction(); throw new NotificationManagementException("Error occurred while updating the status of " + "Notification id : " + notificationId, e); } finally { - NotificationManagementDAOFactory.closeConnection(); + NotificationDAOUtil.cleanupResources(stmt, null); } return rows; } diff --git a/components/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extension/src/test/resources/log4j.properties b/components/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extension/src/test/resources/log4j.properties new file mode 100644 index 0000000000..7da6d6c9e1 --- /dev/null +++ b/components/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extension/src/test/resources/log4j.properties @@ -0,0 +1,32 @@ +# +# Copyright 2009 WSO2, Inc. (http://wso2.com) +# +# Licensed 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. +# + +# +# This is the log4j configuration file used by WSO2 Carbon +# +# IMPORTANT : Please do not remove or change the names of any +# of the Appenders defined here. The layout pattern & log file +# can be changed using the WSO2 Carbon Management Console, and those +# settings will override the settings in this file. +# + +log4j.rootLogger=DEBUG, STD_OUT + +# Redirect log messages to console +log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender +log4j.appender.STD_OUT.Target=System.out +log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout +log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n diff --git a/components/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extension/src/test/resources/testng.xml b/components/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extension/src/test/resources/testng.xml new file mode 100644 index 0000000000..4da53d1247 --- /dev/null +++ b/components/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extension/src/test/resources/testng.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + +