Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] REST APIs required for the Notification feature #12481

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -27,6 +27,8 @@
import org.wso2.carbon.apimgt.api.model.Application;
import org.wso2.carbon.apimgt.api.model.Documentation;
import org.wso2.carbon.apimgt.api.model.DocumentationContent;
import org.wso2.carbon.apimgt.api.model.Notification;
import org.wso2.carbon.apimgt.api.model.NotificationList;
import org.wso2.carbon.apimgt.api.model.ResourceFile;
import org.wso2.carbon.apimgt.api.model.SubscribedAPI;
import org.wso2.carbon.apimgt.api.model.Subscriber;
@@ -533,4 +535,68 @@ Map<String, Object> searchPaginatedAPIs(String searchQuery, String organization,
*/
Map<String, Object> searchPaginatedContent(String searchQuery, String orgId, int start, int end)
throws APIManagementException;

/**
* Changes the status of a notification for a specific user in a given organization.
*
* @param username The username of the user.
* @param organization The organization to which the user belongs.
* @param notificationUUID The unique identifier of the notification.
* @param isMarkAsRead Whether the notification should be marked as read.
* @param portalToDisplay The portal where the notification is displayed.
* @return The updated Notification object.
* @throws APIManagementException If an error occurs while changing the notification status.
*/
Notification changeNotificationStatus(String username, String organization, String notificationUUID,
boolean isMarkAsRead, String portalToDisplay) throws APIManagementException;

/**
* Deletes a notification for a specific user in a given organization.
*
* @param username The username of the user.
* @param organization The organization to which the user belongs.
* @param notificationUUID The unique identifier of the notification to be deleted.
* @param portalToDisplay The portal where the notification is displayed.
* @throws APIManagementException If an error occurs while deleting the notification.
*/
void deleteNotification(String username, String organization, String notificationUUID, String portalToDisplay)
throws APIManagementException;

/**
* Retrieves a list of notifications for a given user.
*
* @param username the username of the user to retrieve notifications for
* @param organization the organization to which the user belongs
* @param portalToDisplay the portal where the notifications are to be displayed
* @param limit the maximum number of notifications to retrieve
* @param offset the starting point in the list of notifications to retrieve
* @return a list of notifications matching the criteria
* @throws APIManagementException if there is an error while retrieving notifications
*/
NotificationList getNotifications(String username, String organization, String portalToDisplay, int limit,
int offset) throws APIManagementException;

/**
* Marks all notifications as read for a specific user in a given organization.
*
* @param username The username of the user.
* @param organization The organization to which the user belongs.
* @param portalToDisplay The portal where the notifications are displayed.
* @param limit The maximum number of notifications to return after marking as read.
* @param offset The starting point within the list of notifications.
* @return A NotificationList object containing the updated list of notifications.
* @throws APIManagementException If an error occurs while marking the notifications as read.
*/
NotificationList markAllNotificationsAsRead(String username, String organization, String portalToDisplay, int limit,
int offset) throws APIManagementException;

/**
* Deletes all notifications for a specific user in a given organization.
*
* @param username The username of the user.
* @param organization The organization to which the user belongs.
* @param portalToDisplay The portal where the notifications are displayed.
* @throws APIManagementException If an error occurs while deleting the notifications.
*/
void deleteAllNotifications(String username, String organization, String portalToDisplay) throws APIManagementException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com/).
*
* WSO2 LLC. 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.apimgt.api.model;

public class Notification {
private String notificationId;
private String notificationType;
private String comments;
private String createdTime;
private Boolean isRead;

public String getNotificationId() {
return notificationId;
}

public void setNotificationId(String notificationId) {
this.notificationId = notificationId;
}

public String getNotificationType() {
return notificationType;
}

public void setNotificationType(String notificationType) {
this.notificationType = notificationType;
}

public String getComments() {
return comments;
}

public void setComments(String comments) {
this.comments = comments;
}

public String getCreatedTime() {
return createdTime;
}

public void setCreatedTime(String createdTime) {
this.createdTime = createdTime;
}

public Boolean getIsRead() {
return isRead;
}

public void setIsRead(Boolean read) {
this.isRead = read;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com/).
*
* WSO2 LLC. 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.apimgt.api.model;

import java.util.ArrayList;
import java.util.List;

public class NotificationList {

private Integer count = null;
private List<Notification> list = new ArrayList<Notification>();
private Pagination pagination = null;

private Integer unreadCount = null;

public Integer getCount() {
return count;
}

public void setCount(Integer count) {
this.count = count;
}

public List<Notification> getList() {
return list;
}

public void setList(List<Notification> list) {
this.list = list;
}

public Pagination getPagination() {
return pagination;
}

public void setPagination(Pagination pagination) {
this.pagination = pagination;
}

public Integer getUnreadCount() { return unreadCount; }

public void setUnreadCount(Integer unreadCount) { this.unreadCount = unreadCount; }

}
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@
import org.wso2.carbon.apimgt.api.model.policy.PolicyConstants;
import org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO;
import org.wso2.carbon.apimgt.impl.dao.EnvironmentSpecificAPIPropertyDAO;
import org.wso2.carbon.apimgt.impl.dao.NotificationDAO;
import org.wso2.carbon.apimgt.impl.dao.ScopesDAO;
import org.wso2.carbon.apimgt.impl.dto.ThrottleProperties;
import org.wso2.carbon.apimgt.impl.dto.WorkflowDTO;
@@ -82,6 +83,7 @@ public abstract class AbstractAPIManager implements APIManager {
// API definitions from swagger v2.0
protected Log log = LogFactory.getLog(getClass());
protected ApiMgtDAO apiMgtDAO;
protected NotificationDAO notificationDAO;
protected EnvironmentSpecificAPIPropertyDAO environmentSpecificAPIPropertyDAO;
protected ScopesDAO scopesDAO;
protected int tenantId = MultitenantConstants.INVALID_TENANT_ID; //-1 the issue does not occur.;
@@ -105,6 +107,7 @@ public AbstractAPIManager(String username) throws APIManagementException {
public AbstractAPIManager(String username, String organization) throws APIManagementException {

apiMgtDAO = ApiMgtDAO.getInstance();
notificationDAO = NotificationDAO.getInstance();
scopesDAO = ScopesDAO.getInstance();
environmentSpecificAPIPropertyDAO = EnvironmentSpecificAPIPropertyDAO.getInstance();

@@ -1673,4 +1676,86 @@ protected boolean isOauthAppValidation() {
}
return true;
}

/**
* Changes the status of a notification for a specific user in a given organization.
*
* @param username The username of the user.
* @param organization The organization to which the user belongs.
* @param notificationUUID The unique identifier of the notification.
* @param isMarkAsRead Whether the notification should be marked as read.
* @param portalToDisplay The portal where the notification is displayed.
* @return The updated Notification object.
* @throws APIManagementException If an error occurs while changing the notification status.
*/
@Override
public Notification changeNotificationStatus(String username, String organization, String notificationUUID,
boolean isMarkAsRead, String portalToDisplay) throws APIManagementException {
notificationDAO.changeNotificationStatus(username, organization, notificationUUID, isMarkAsRead, portalToDisplay);
return notificationDAO.getNotification(notificationUUID, username, organization, portalToDisplay);
}

/**
* Deletes a notification for a specific user in a given organization.
*
* @param username The username of the user.
* @param organization The organization to which the user belongs.
* @param notificationUUID The unique identifier of the notification to be deleted.
* @param portalToDisplay The portal where the notification is displayed.
* @throws APIManagementException If an error occurs while deleting the notification.
*/
@Override
public void deleteNotification(String username, String organization, String notificationUUID, String portalToDisplay)
throws APIManagementException {
notificationDAO.deleteNotification(username, organization, notificationUUID, portalToDisplay);
}

/**
* Retrieves a list of notifications for a given user.
*
* @param username the username of the user to retrieve notifications for
* @param organization the organization to which the user belongs
* @param portalToDisplay the portal where the notifications are to be displayed
* @param limit the maximum number of notifications to retrieve
* @param offset the starting point in the list of notifications to retrieve
* @return a list of notifications matching the criteria
* @throws APIManagementException if there is an error while retrieving notifications
*/
@Override
public NotificationList getNotifications(String username, String organization, String portalToDisplay, int limit,
int offset) throws APIManagementException {
return notificationDAO.getNotifications(username, organization, portalToDisplay, limit, offset);
}

/**
* Marks all notifications as read for a specific user in a given organization.
*
* @param username The username of the user.
* @param organization The organization to which the user belongs.
* @param portalToDisplay The portal where the notifications are displayed.
* @param limit The maximum number of notifications to return after marking as read.
* @param offset The starting point within the list of notifications.
* @return A NotificationList object containing the updated list of notifications.
* @throws APIManagementException If an error occurs while marking the notifications as read.
*/
@Override
public NotificationList markAllNotificationsAsRead(String username, String organization, String portalToDisplay,
int limit, int offset) throws APIManagementException {
notificationDAO.markAllNotificationsAsRead(username, organization, portalToDisplay);
return notificationDAO.getNotifications(username, organization, portalToDisplay, limit, offset);
}

/**
* Deletes all notifications for a specific user in a given organization.
*
* @param username The username of the user.
* @param organization The organization to which the user belongs.
* @param portalToDisplay The portal where the notifications are displayed.
* @throws APIManagementException If an error occurs while deleting the notifications.
*/
@Override
public void deleteAllNotifications(String username, String organization, String portalToDisplay)
throws APIManagementException {
notificationDAO.deleteAllNotifications(username, organization, portalToDisplay);
}
}
Loading