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

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

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

@ -67,7 +67,8 @@ public interface NotificationDAO {
* @return returns the no of updated records. * @return returns the no of updated records.
* @throws NotificationManagementException * @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. * This method is used to get all notifications based on tenant-id.

@ -143,16 +143,17 @@ public abstract class AbstractNotificationDAOImpl implements NotificationDAO {
} }
@Override @Override
public int updateAllNotifications(Notification.Status status) public int updateAllNotifications(Notification.Status status, int tenantID)
throws NotificationManagementException { throws NotificationManagementException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
int rows; int rows;
try { try {
conn = NotificationManagementDAOFactory.getConnection(); 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 = conn.prepareStatement(sql);
stmt.setString(1, status.toString()); stmt.setString(1, status.toString());
stmt.setInt(2, tenantID);
rows = stmt.executeUpdate(); rows = stmt.executeUpdate();
} catch (Exception e) { } catch (Exception e) {
throw new NotificationManagementException("Error while trying to clear all " + throw new NotificationManagementException("Error while trying to clear all " +

Loading…
Cancel
Save