From eda7b2abddef66a3542d105c3bf5a7601dcaeabb Mon Sep 17 00:00:00 2001 From: HelaniUdara Date: Thu, 2 May 2024 11:31:58 +0530 Subject: [PATCH] Update the code --- .../wso2/carbon/apimgt/impl/APIConstants.java | 3 +++ .../apimgt/impl/AbstractAPIManager.java | 2 +- .../PortalNotificationDAO.java | 12 +++++------- .../PortalNotificationDTO.java | 5 ++++- .../PortalNotificationEndUserDTO.java | 2 +- .../PortalNotificationService.java | 2 -- .../WorkflowNotificationServiceImpl.java | 19 ++++++++++++------- .../dao/test/PortalNotificationDAOTest.java | 8 ++++---- .../WorkflowNotificationServiceImplTest.java | 2 ++ .../v1/impl/WorkflowsApiServiceImpl.java | 1 - 10 files changed, 32 insertions(+), 24 deletions(-) rename components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/{portalNotifications => dao}/PortalNotificationDAO.java (97%) rename components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/{ => dto}/portalNotifications/PortalNotificationDTO.java (90%) rename components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/{ => dto}/portalNotifications/PortalNotificationEndUserDTO.java (96%) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java index 64f5514bc799..bc78d5a49e88 100755 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java @@ -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"; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/AbstractAPIManager.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/AbstractAPIManager.java index 7b6edc6adc84..a025db841833 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/AbstractAPIManager.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/AbstractAPIManager.java @@ -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; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/PortalNotificationDAO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/PortalNotificationDAO.java similarity index 97% rename from components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/PortalNotificationDAO.java rename to components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/PortalNotificationDAO.java index adf403cd13db..939e75bda747 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/PortalNotificationDAO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/PortalNotificationDAO.java @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/PortalNotificationDTO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/portalNotifications/PortalNotificationDTO.java similarity index 90% rename from components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/PortalNotificationDTO.java rename to components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/portalNotifications/PortalNotificationDTO.java index 0f84b201f447..dd2fe1424e61 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/PortalNotificationDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/portalNotifications/PortalNotificationDTO.java @@ -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; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/PortalNotificationEndUserDTO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/portalNotifications/PortalNotificationEndUserDTO.java similarity index 96% rename from components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/PortalNotificationEndUserDTO.java rename to components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/portalNotifications/PortalNotificationEndUserDTO.java index be8b6c03e30a..e119954ac077 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/PortalNotificationEndUserDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/portalNotifications/PortalNotificationEndUserDTO.java @@ -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 { diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/PortalNotificationService.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/PortalNotificationService.java index d5fc3e2c3ba8..f6d962c42eea 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/PortalNotificationService.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/PortalNotificationService.java @@ -18,8 +18,6 @@ package org.wso2.carbon.apimgt.impl.portalNotifications; -import org.wso2.carbon.apimgt.api.APIManagementException; - public interface PortalNotificationService { void sendPortalNotifications(T notificationObject, String tenantDomain); diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/WorkflowNotificationServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/WorkflowNotificationServiceImpl.java index d829d2bbdd6b..039ec2089917 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/WorkflowNotificationServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/portalNotifications/WorkflowNotificationServiceImpl.java @@ -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; @@ -156,13 +159,15 @@ private List 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()); @@ -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; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/dao/test/PortalNotificationDAOTest.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/dao/test/PortalNotificationDAOTest.java index d9d2933a01a1..9dc0003766ad 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/dao/test/PortalNotificationDAOTest.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/dao/test/PortalNotificationDAOTest.java @@ -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; @@ -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); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/portalNotifications/WorkflowNotificationServiceImplTest.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/portalNotifications/WorkflowNotificationServiceImplTest.java index f06bc4c4c1ae..de451118de58 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/portalNotifications/WorkflowNotificationServiceImplTest.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/portalNotifications/WorkflowNotificationServiceImplTest.java @@ -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; diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/WorkflowsApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/WorkflowsApiServiceImpl.java index 7c101bb3cb56..1fa1ae1292f6 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/WorkflowsApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/WorkflowsApiServiceImpl.java @@ -189,7 +189,6 @@ public Response workflowsUpdateWorkflowStatusPost(String workflowReferenceId, Wo } if (body.getComments() != null) { - System.out.println(body.getComments()); workflowDTO.setComments(body.getComments()); }