Skip to content

Commit

Permalink
Merge branch 'master' into add-authentication-action
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Aug 18, 2024
1 parent bf6c13e commit 2497d7c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ public interface ActionExecutorService {
ActionExecutionStatus execute(ActionType actionType, Map<String, Object> 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<String, Object> eventContext,
String tenantDomain) throws ActionExecutionException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,23 +85,24 @@ public boolean isExecutionEnabled(ActionType actionType) {
public ActionExecutionStatus execute(ActionType actionType, Map<String, Object> eventContext, String tenantDomain)
throws ActionExecutionException {

return execute(actionType, null, eventContext, tenantDomain);
List<Action> 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<String, Object> eventContext,
String tenantDomain) throws ActionExecutionException {

try {
Action action;
if (StringUtils.isBlank(actionId)) {
List<Action> 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<String, Object> eventContext)
throws ActionExecutionException {

try {
ActionExecutionRequest actionRequest = buildActionExecutionRequest(actionType, eventContext);
ActionExecutionResponseProcessor actionExecutionResponseProcessor = getResponseProcessor(actionType);

Expand Down Expand Up @@ -130,13 +130,14 @@ private List<Action> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ public interface ActionManagementService {
List<Action> 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public Map<String, Integer> getActionsCountPerType(Integer tenantId) throws Acti

@Override
public Action getActionByActionId(String actionType, String actionId, Integer tenantId) throws ActionMgtException {

return getActionByActionId(actionId, tenantId);
}

Expand Down

0 comments on commit 2497d7c

Please sign in to comment.