Restricting clear notifications to tenant domain only

revert-70aa11f8
Ace 7 years ago
parent 15991f626d
commit fb6c98b969

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl;
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.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
@ -106,7 +107,9 @@ public class NotificationManagementServiceImpl implements NotificationManagement
public Response clearAllNotifications() {
Notification.Status status = Notification.Status.CHECKED;
try {
DeviceMgtAPIUtils.getNotificationManagementService().updateAllNotifications(status);
int loggedinUserTenantId = CarbonContext.getThreadLocalCarbonContext()
.getTenantId();
DeviceMgtAPIUtils.getNotificationManagementService().updateAllNotifications(status, loggedinUserTenantId);
return Response.status(Response.Status.OK).build();
} catch (NotificationManagementException e) {
log.error("Error encountered while trying to clear all notifications.", e);

@ -70,7 +70,7 @@ public interface NotificationManagementService {
* @throws NotificationManagementException
* if something goes wrong while updating the Notification.
*/
boolean updateAllNotifications(Notification.Status status) throws
boolean updateAllNotifications(Notification.Status status, int tenantID) throws
NotificationManagementException;
/**

@ -142,13 +142,14 @@ public class NotificationManagementServiceImpl implements NotificationManagement
}
@Override
public boolean updateAllNotifications(Notification.Status status) throws NotificationManagementException {
public boolean updateAllNotifications(Notification.Status status, int tenantID) throws
NotificationManagementException {
if (log.isDebugEnabled()) {
log.debug("Attempting to clear all notifications");
}
try {
NotificationManagementDAOFactory.beginTransaction();
notificationDAO.updateAllNotifications(status);
notificationDAO.updateAllNotifications(status, tenantID);
NotificationManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
NotificationManagementDAOFactory.rollbackTransaction();

@ -67,7 +67,8 @@ public interface NotificationDAO {
* @return returns the no of updated records.
* @throws NotificationManagementException
*/
int updateAllNotifications(Notification.Status status) throws NotificationManagementException;
int updateAllNotifications(Notification.Status status, int tenantID) throws
NotificationManagementException;
/**
* This method is used to get all notifications based on tenant-id.

@ -143,16 +143,17 @@ public abstract class AbstractNotificationDAOImpl implements NotificationDAO {
}
@Override
public int updateAllNotifications(Notification.Status status)
public int updateAllNotifications(Notification.Status status, int tenantID)
throws NotificationManagementException {
Connection conn;
PreparedStatement stmt = null;
int rows;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql = "UPDATE DM_NOTIFICATION SET STATUS = ?";
String sql = "UPDATE DM_NOTIFICATION SET STATUS = ? WHERE TENANT_ID= ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, status.toString());
stmt.setInt(2, tenantID);
rows = stmt.executeUpdate();
} catch (Exception e) {
throw new NotificationManagementException("Error while trying to clear all " +

Loading…
Cancel
Save