Skip to content

Commit

Permalink
Update the code
Browse files Browse the repository at this point in the history
  • Loading branch information
HelaniUdara committed May 2, 2024
1 parent bd898f3 commit eda7b2a
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3158,9 +3158,12 @@ public static class APILogHandler {

public static class PortalNotifications {
public static final String ACTION = "action";
public static final String ACTION_META = "Action";
public static final String API_NAME = "apiName";
public static final String API_VERSION = "apiVersion";
public static final String API_CONTEXT = "apiContext";
public static final String API_CONTEXT_META = "ApiContext";
public static final String API_PROVIDER = "ApiProvider";
public static final String APPLICATION_NAME = "applicationName";
public static final String REQUESTED_TIER = "requestedTier";
public static final String REVISION_ID = "revisionId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import org.wso2.carbon.apimgt.impl.factory.PersistenceFactory;
import org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder;
import org.wso2.carbon.apimgt.impl.notifier.events.ApplicationEvent;
import org.wso2.carbon.apimgt.impl.portalNotifications.PortalNotificationDAO;
import org.wso2.carbon.apimgt.impl.dao.PortalNotificationDAO;
import org.wso2.carbon.apimgt.impl.utils.*;
import org.wso2.carbon.apimgt.impl.workflow.WorkflowStatus;
import org.wso2.carbon.apimgt.persistence.APIPersistence;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* under the License.
*/

package org.wso2.carbon.apimgt.impl.portalNotifications;
package org.wso2.carbon.apimgt.impl.dao;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand All @@ -29,6 +29,10 @@
import org.wso2.carbon.apimgt.api.model.NotificationList;
import org.wso2.carbon.apimgt.impl.APIConstants;
import org.wso2.carbon.apimgt.impl.dao.constants.SQLConstants;
import org.wso2.carbon.apimgt.impl.dto.portalNotifications.PortalNotificationDTO;
import org.wso2.carbon.apimgt.impl.dto.portalNotifications.PortalNotificationEndUserDTO;
import org.wso2.carbon.apimgt.impl.portalNotifications.PortalNotificationMetaData;
import org.wso2.carbon.apimgt.impl.portalNotifications.PortalNotificationType;
import org.wso2.carbon.apimgt.impl.utils.APIMgtDBUtil;

import java.sql.Connection;
Expand Down Expand Up @@ -79,8 +83,6 @@ public boolean addNotification(PortalNotificationDTO portalNotificationDTO) thro
}

} catch (SQLException e) {
handleException("Error while adding notification - SQL", e);
} catch (APIManagementException e) {
handleException("Error while adding notification", e);
}
return false;
Expand Down Expand Up @@ -292,8 +294,6 @@ public Notification markNotificationAsReadById(String username, String organizat
}
}
} catch (SQLException e) {
handleException("Failed to mark notification as read - SQL", e);
} catch (APIManagementException e) {
handleException("Failed to mark notification as read", e);
}
return null;
Expand Down Expand Up @@ -365,8 +365,6 @@ public NotificationList markAllNotificationsAsRead(String username, String organ
return getNotifications(username, organization, portalToDisplay, "desc", 10, 0);
}
} catch (SQLException e) {
handleException("Failed to mark all notifications as read - SQL", e);
} catch (APIManagementException e) {
handleException("Failed to mark all notifications as read", e);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
* under the License.
*/

package org.wso2.carbon.apimgt.impl.portalNotifications;
package org.wso2.carbon.apimgt.impl.dto.portalNotifications;

import org.wso2.carbon.apimgt.impl.portalNotifications.PortalNotificationMetaData;
import org.wso2.carbon.apimgt.impl.portalNotifications.PortalNotificationType;

import java.sql.Timestamp;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* under the License.
*/

package org.wso2.carbon.apimgt.impl.portalNotifications;
package org.wso2.carbon.apimgt.impl.dto.portalNotifications;

public class PortalNotificationEndUserDTO {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package org.wso2.carbon.apimgt.impl.portalNotifications;

import org.wso2.carbon.apimgt.api.APIManagementException;

public interface PortalNotificationService<T> {

void sendPortalNotifications(T notificationObject, String tenantDomain);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
import org.wso2.carbon.apimgt.impl.APIConstants;
import org.wso2.carbon.apimgt.impl.APIManagerConfiguration;
import org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO;
import org.wso2.carbon.apimgt.impl.dao.PortalNotificationDAO;
import org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO;
import org.wso2.carbon.apimgt.impl.dto.portalNotifications.PortalNotificationDTO;
import org.wso2.carbon.apimgt.impl.dto.portalNotifications.PortalNotificationEndUserDTO;
import org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder;
import org.wso2.carbon.apimgt.impl.utils.APIUtil;
import org.wso2.carbon.apimgt.impl.workflow.WorkflowConstants;
Expand Down Expand Up @@ -156,13 +159,15 @@ private List<PortalNotificationEndUserDTO> getDestinationUser(WorkflowDTO workfl
if (workflowDTO.getWorkflowType()
.equals(WorkflowConstants.WF_TYPE_AM_API_STATE) || workflowDTO.getWorkflowType()
.equals(WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE)) {
if (workflowDTO.getMetadata("Action").equals(APIConstants.BLOCK) || workflowDTO.getMetadata("Action")
.equals(APIConstants.DEPRECATE) || workflowDTO.getMetadata("Action").equals(APIConstants.RETIRE)) {
if (workflowDTO.getMetadata(APIConstants.PortalNotifications.ACTION_META)
.equals(APIConstants.BLOCK) || workflowDTO.getMetadata(APIConstants.PortalNotifications.ACTION_META)
.equals(APIConstants.DEPRECATE) || workflowDTO.getMetadata(
APIConstants.PortalNotifications.ACTION_META).equals(APIConstants.RETIRE)) {
String apiUUID = null;
String apiName = workflowDTO.getProperties("apiName");
String apiContext = workflowDTO.getMetadata("ApiContext");
String apiVersion = workflowDTO.getProperties("apiVersion");
String provider = workflowDTO.getMetadata("ApiProvider");
String apiName = workflowDTO.getProperties(APIConstants.PortalNotifications.API_NAME);
String apiContext = workflowDTO.getMetadata(APIConstants.PortalNotifications.API_CONTEXT_META);
String apiVersion = workflowDTO.getProperties(APIConstants.PortalNotifications.API_VERSION);
String provider = workflowDTO.getMetadata(APIConstants.PortalNotifications.API_PROVIDER);
try {
apiUUID = getAPIUUIDUsingNameContextVersion(apiName, apiContext, apiVersion,
workflowDTO.getTenantDomain());
Expand Down Expand Up @@ -230,7 +235,7 @@ private PortalNotificationMetaData getNotificationMetaData(WorkflowDTO workflowD
if (WorkflowConstants.WF_TYPE_AM_API_STATE.equals(
workflowDTO.getWorkflowType()) || WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE.equals(
workflowDTO.getWorkflowType())) {
portalNotificationMetaData.setApiContext(workflowDTO.getMetadata("ApiContext"));
portalNotificationMetaData.setApiContext(workflowDTO.getMetadata(APIConstants.PortalNotifications.API_CONTEXT_META));
}

return portalNotificationMetaData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import org.wso2.carbon.apimgt.impl.APIManagerConfiguration;
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl;
import org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder;
import org.wso2.carbon.apimgt.impl.portalNotifications.PortalNotificationDAO;
import org.wso2.carbon.apimgt.impl.portalNotifications.PortalNotificationDTO;
import org.wso2.carbon.apimgt.impl.portalNotifications.PortalNotificationEndUserDTO;
import org.wso2.carbon.apimgt.impl.dao.PortalNotificationDAO;
import org.wso2.carbon.apimgt.impl.dto.portalNotifications.PortalNotificationDTO;
import org.wso2.carbon.apimgt.impl.dto.portalNotifications.PortalNotificationEndUserDTO;
import org.wso2.carbon.apimgt.impl.portalNotifications.PortalNotificationMetaData;
import org.wso2.carbon.apimgt.impl.portalNotifications.PortalNotificationType;
import org.wso2.carbon.apimgt.impl.utils.APIMgtDBUtil;
Expand Down Expand Up @@ -218,7 +218,7 @@ public void testAddNotificationFailure() {
portalNotificationDAO.addNotification(portalNotificationDTO);
});

String expectedMessage = "Error while adding notification";
String expectedMessage = "Error while adding end users";
String actualMessage = exception.getMessage();
Assert.assertEquals(expectedMessage, actualMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.impl.dao.PortalNotificationDAO;
import org.wso2.carbon.apimgt.impl.dto.WorkflowDTO;
import org.wso2.carbon.apimgt.impl.dto.portalNotifications.PortalNotificationDTO;
import org.wso2.carbon.apimgt.impl.utils.APIUtil;
import org.wso2.carbon.apimgt.impl.workflow.WorkflowConstants;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public Response workflowsUpdateWorkflowStatusPost(String workflowReferenceId, Wo
}

if (body.getComments() != null) {
System.out.println(body.getComments());
workflowDTO.setComments(body.getComments());
}

Expand Down

0 comments on commit eda7b2a

Please sign in to comment.