From 2497d7cdd1ca2625c06f2abc575729eff541c482 Mon Sep 17 00:00:00 2001 From: thisarawelmilla Date: Sun, 18 Aug 2024 22:09:56 +0530 Subject: [PATCH] Merge branch 'master' into add-authentication-action --- .../execution/ActionExecutorService.java | 11 ++++++- .../execution/ActionExecutorServiceImpl.java | 33 ++++++++++--------- .../management/ActionManagementService.java | 5 +-- .../dao/impl/ActionManagementDAOImpl.java | 1 + 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/ActionExecutorService.java b/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/ActionExecutorService.java index afdf9fa6e26a..d40dd9e11b8a 100644 --- a/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/ActionExecutorService.java +++ b/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/ActionExecutorService.java @@ -51,7 +51,16 @@ public interface ActionExecutorService { ActionExecutionStatus execute(ActionType actionType, Map eventContext, String tenantDomain) throws ActionExecutionException; - + /** + * Execute the action based on the action id and the event context. + * + * @param actionType Action Type + * @param actionId Action ID + * @param eventContext Context information required for the action execution. + * @param tenantDomain Tenant Domain + * @return {@link ActionExecutionStatus} The status of the action execution and the response context. + * @throws ActionExecutionException If an error occurs while executing the action. + */ ActionExecutionStatus execute(ActionType actionType, String actionId, Map eventContext, String tenantDomain) throws ActionExecutionException; } diff --git a/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/ActionExecutorServiceImpl.java b/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/ActionExecutorServiceImpl.java index a774c9da1507..4fc1e2ee7667 100644 --- a/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/ActionExecutorServiceImpl.java +++ b/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/ActionExecutorServiceImpl.java @@ -22,7 +22,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.action.execution.exception.ActionExecutionException; @@ -86,23 +85,24 @@ public boolean isExecutionEnabled(ActionType actionType) { public ActionExecutionStatus execute(ActionType actionType, Map eventContext, String tenantDomain) throws ActionExecutionException { - return execute(actionType, null, eventContext, tenantDomain); + List actions = getActionsByActionType(actionType, tenantDomain); + validateActions(actions, actionType); + // As of now only one action is allowed. + Action action = actions.get(0); + + return execute(action, actionType, eventContext); } public ActionExecutionStatus execute(ActionType actionType, String actionId, Map eventContext, String tenantDomain) throws ActionExecutionException { - try { - Action action; - if (StringUtils.isBlank(actionId)) { - List actions = getActionsByActionType(actionType, tenantDomain); - validateActions(actions, actionType); - // As of now only one action is allowed. - action = actions.get(0); - } else { - action = getActionByActionId(actionId, tenantDomain); - } + return execute(getActionByActionId(actionType, actionId, tenantDomain), actionType, eventContext); + } + + private ActionExecutionStatus execute(Action action, ActionType actionType, Map eventContext) + throws ActionExecutionException { + try { ActionExecutionRequest actionRequest = buildActionExecutionRequest(actionType, eventContext); ActionExecutionResponseProcessor actionExecutionResponseProcessor = getResponseProcessor(actionType); @@ -130,13 +130,14 @@ private List getActionsByActionType(ActionType actionType, String tenant } } - private Action getActionByActionId(String actionId, String tenantDomain) throws ActionExecutionRuntimeException { + private Action getActionByActionId(ActionType actionType, String actionId, String tenantDomain) + throws ActionExecutionRuntimeException { try { - return ActionExecutionServiceComponentHolder.getInstance().getActionManagementService() - .getActionByActionId(actionId, tenantDomain); + return ActionExecutionServiceComponentHolder.getInstance().getActionManagementService().getActionByActionId( + Action.ActionTypes.valueOf(actionType.name()).getPathParam(), actionId, tenantDomain); } catch (ActionMgtException e) { - throw new ActionExecutionRuntimeException("Error occurred while retrieving actions.", e); + throw new ActionExecutionRuntimeException("Error occurred while retrieving action by action Id .", e); } } diff --git a/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/ActionManagementService.java b/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/ActionManagementService.java index 7c55ce66cf1b..82df3e1eaf12 100644 --- a/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/ActionManagementService.java +++ b/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/ActionManagementService.java @@ -52,12 +52,13 @@ public interface ActionManagementService { List getActionsByActionType(String actionType, String tenantDomain) throws ActionMgtException; /** - * Get Actions of a given Action Type. + * Get Actions of a given Action Id. * * @param actionType Action Type. + * @param actionId Action Id. * @param tenantDomain Tenant domain. * @return List of Actions. - * @throws ActionMgtException If an error occurs while retrieving the Actions of a given Action Type. + * @throws ActionMgtException If an error occurs while retrieving the Actions of a given Action Id. */ Action getActionByActionId(String actionType, String actionId, String tenantDomain) throws ActionMgtException; diff --git a/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/dao/impl/ActionManagementDAOImpl.java b/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/dao/impl/ActionManagementDAOImpl.java index e6142de2dc04..17b32c310506 100644 --- a/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/dao/impl/ActionManagementDAOImpl.java +++ b/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/dao/impl/ActionManagementDAOImpl.java @@ -242,6 +242,7 @@ public Map getActionsCountPerType(Integer tenantId) throws Acti @Override public Action getActionByActionId(String actionType, String actionId, Integer tenantId) throws ActionMgtException { + return getActionByActionId(actionId, tenantId); }