|
|
@ -21,6 +21,8 @@ package org.wso2.carbon.device.mgt.core.notification.mgt;
|
|
|
|
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.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.EntityDoesNotExistException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
|
|
|
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;
|
|
|
@ -51,17 +53,41 @@ public class NotificationManagementServiceImpl implements NotificationManagement
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean addNotification(Notification notification) throws NotificationManagementException {
|
|
|
|
public boolean addNotification(DeviceIdentifier deviceId,
|
|
|
|
boolean status = false;
|
|
|
|
Notification notification) throws NotificationManagementException {
|
|
|
|
int deviceId, tenantId;
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Adding a Notification : [" + notification.toString() + "]");
|
|
|
|
log.debug("Adding a Notification : [" + notification.toString() + "]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int notificationId;
|
|
|
|
|
|
|
|
int tenantId = NotificationDAOUtil.getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Device device = this.getDevice(deviceId, tenantId);
|
|
|
|
|
|
|
|
if (device == null) {
|
|
|
|
|
|
|
|
throw new EntityDoesNotExistException("No device is found with type '" + deviceId.getType() +
|
|
|
|
|
|
|
|
"' and id '" + deviceId.getId() + "'");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
NotificationManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
notificationId = notificationDAO.addNotification(device.getId(), tenantId, notification);
|
|
|
|
|
|
|
|
NotificationManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
|
|
|
NotificationManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new NotificationManagementException("Error occurred while adding notification", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
NotificationManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Notification id : " + notificationId + " was added to the table.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Device getDevice(DeviceIdentifier deviceId, int tenantId) throws NotificationManagementException {
|
|
|
|
|
|
|
|
Device device;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
tenantId = NotificationDAOUtil.getTenantId();
|
|
|
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
Device device = deviceDAO.getDevice(notification.getDeviceIdentifier(), tenantId);
|
|
|
|
device = deviceDAO.getDevice(deviceId, tenantId);
|
|
|
|
deviceId = device.getId();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new NotificationManagementException("Error occurred while opening a connection to" +
|
|
|
|
throw new NotificationManagementException("Error occurred while opening a connection to" +
|
|
|
|
" the data source", e);
|
|
|
|
" the data source", e);
|
|
|
@ -71,80 +97,55 @@ public class NotificationManagementServiceImpl implements NotificationManagement
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
return device;
|
|
|
|
NotificationManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
int notificationId = notificationDAO.addNotification(deviceId, tenantId, notification);
|
|
|
|
|
|
|
|
NotificationManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Notification id : " + notificationId +" was added to the table.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(notificationId > 0) {
|
|
|
|
|
|
|
|
status = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
|
|
|
NotificationManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new NotificationManagementException("Error occurred while adding notification", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
NotificationManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean updateNotification(Notification notification) throws NotificationManagementException {
|
|
|
|
public boolean updateNotification(Notification notification) throws NotificationManagementException {
|
|
|
|
boolean status = false;
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Updating Notification : [" + notification.toString() + "]");
|
|
|
|
log.debug("Updating Notification : [" + notification.toString() + "]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
NotificationManagementDAOFactory.beginTransaction();
|
|
|
|
NotificationManagementDAOFactory.beginTransaction();
|
|
|
|
if(notificationDAO.updateNotification(notification) > 0 ) {
|
|
|
|
notificationDAO.updateNotification(notification);
|
|
|
|
status = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NotificationManagementDAOFactory.commitTransaction();
|
|
|
|
NotificationManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Notification id : " + notification.getNotificationId() +
|
|
|
|
|
|
|
|
" has updated successfully.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
NotificationManagementDAOFactory.rollbackTransaction();
|
|
|
|
NotificationManagementDAOFactory.rollbackTransaction();
|
|
|
|
throw new NotificationManagementException("Error occurred while updating notification ", e);
|
|
|
|
throw new NotificationManagementException("Error occurred while updating notification ", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
NotificationManagementDAOFactory.closeConnection();
|
|
|
|
NotificationManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Notification id : " + notification.getNotificationId() +
|
|
|
|
|
|
|
|
" has updated successfully.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean updateNotificationStatus(int notificationId, Notification.Status status)
|
|
|
|
public boolean updateNotificationStatus(int notificationId, Notification.Status status)
|
|
|
|
throws NotificationManagementException {
|
|
|
|
throws NotificationManagementException {
|
|
|
|
boolean operationStatus = false;
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Updating Notification id : " + notificationId);
|
|
|
|
log.debug("Updating Notification id : " + notificationId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
NotificationManagementDAOFactory.beginTransaction();
|
|
|
|
NotificationManagementDAOFactory.beginTransaction();
|
|
|
|
if(notificationDAO.updateNotificationStatus(notificationId, status) > 0 ) {
|
|
|
|
notificationDAO.updateNotificationStatus(notificationId, status);
|
|
|
|
operationStatus = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NotificationManagementDAOFactory.commitTransaction();
|
|
|
|
NotificationManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Notification id : " + notificationId +" has updated successfully.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
NotificationManagementDAOFactory.rollbackTransaction();
|
|
|
|
NotificationManagementDAOFactory.rollbackTransaction();
|
|
|
|
throw new NotificationManagementException("Error occurred while updating notification", e);
|
|
|
|
throw new NotificationManagementException("Error occurred while updating notification", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
NotificationManagementDAOFactory.closeConnection();
|
|
|
|
NotificationManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return operationStatus;
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Notification id : " + notificationId + " has updated successfully.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Notification> getAllNotifications() throws NotificationManagementException{
|
|
|
|
public List<Notification> getAllNotifications() throws NotificationManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
NotificationManagementDAOFactory.openConnection();
|
|
|
|
NotificationManagementDAOFactory.openConnection();
|
|
|
|
return notificationDAO.getAllNotifications(NotificationDAOUtil.getTenantId());
|
|
|
|
return notificationDAO.getAllNotifications(NotificationDAOUtil.getTenantId());
|
|
|
@ -158,7 +159,7 @@ public class NotificationManagementServiceImpl implements NotificationManagement
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Notification> getNotificationsByStatus(Notification.Status status)
|
|
|
|
public List<Notification> getNotificationsByStatus(Notification.Status status)
|
|
|
|
throws NotificationManagementException{
|
|
|
|
throws NotificationManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
NotificationManagementDAOFactory.openConnection();
|
|
|
|
NotificationManagementDAOFactory.openConnection();
|
|
|
|
return notificationDAO.getNotificationsByStatus(status, NotificationDAOUtil.getTenantId());
|
|
|
|
return notificationDAO.getNotificationsByStatus(status, NotificationDAOUtil.getTenantId());
|
|
|
@ -169,4 +170,5 @@ public class NotificationManagementServiceImpl implements NotificationManagement
|
|
|
|
NotificationManagementDAOFactory.closeConnection();
|
|
|
|
NotificationManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|