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 b2e8fe9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 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,37 +85,36 @@ public boolean isExecutionEnabled(ActionType actionType) {
public ActionExecutionStatus execute(ActionType actionType, Map<String, Object> eventContext, String tenantDomain)
throws ActionExecutionException {

return execute(actionType, null, eventContext, tenantDomain);
try {
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);
} catch (ActionExecutionRuntimeException e) {
// todo: add to diagnostics
LOG.debug("Skip executing actions for action type: " + actionType.name(), e);
return new ActionExecutionStatus(ActionExecutionStatus.Status.FAILED, 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);
}

ActionExecutionRequest actionRequest = buildActionExecutionRequest(actionType, eventContext);
ActionExecutionResponseProcessor actionExecutionResponseProcessor = getResponseProcessor(actionType);
private ActionExecutionStatus execute(Action action, ActionType actionType, Map<String, Object> eventContext)
throws ActionExecutionException {

return Optional.ofNullable(action)
.filter(activeAction -> activeAction.getStatus() == Action.Status.ACTIVE)
.map(activeAction -> executeAction(activeAction, actionRequest, eventContext,
actionExecutionResponseProcessor))
.orElse(new ActionExecutionStatus(ActionExecutionStatus.Status.FAILED, eventContext));
} catch (ActionExecutionRuntimeException e) {
// todo: add to diagnostics
LOG.debug("Skip executing actions for action type: " + actionType.name(), e);
return new ActionExecutionStatus(ActionExecutionStatus.Status.FAILED, eventContext);
ActionExecutionRequest actionRequest = buildActionExecutionRequest(actionType, eventContext);
ActionExecutionResponseProcessor actionExecutionResponseProcessor = getResponseProcessor(actionType);

}
return Optional.ofNullable(action)
.filter(activeAction -> activeAction.getStatus() == Action.Status.ACTIVE)
.map(activeAction -> executeAction(activeAction, actionRequest, eventContext,
actionExecutionResponseProcessor))
.orElse(new ActionExecutionStatus(ActionExecutionStatus.Status.FAILED, eventContext));
}

private List<Action> getActionsByActionType(ActionType actionType, String tenantDomain) throws
Expand All @@ -130,13 +128,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 b2e8fe9

Please sign in to comment.