Skip to content

Commit

Permalink
Add new DefinedBy property to authenticator config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Sep 18, 2024
1 parent b7e7c8d commit 6c8ef2e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,37 @@ public ActionExecutionStatus execute(ActionType actionType, Map<String, Object>
* Resolve the actions by given the action id list and execute them.
*
* @param actionType Action Type.
* @param actionIds Lis of action Ids of the actions that need to be executed.
* @param actionIdList Lis of action Ids of the actions that need to be executed.
* @param eventContext The event context of the corresponding flow.
* @param tenantDomain Tenant domain.
* @return Action execution status.
*/
public ActionExecutionStatus execute(ActionType actionType, String[] actionIds, Map<String, Object> eventContext,
public ActionExecutionStatus execute(ActionType actionType, String[] actionIdList, Map<String, Object> eventContext,
String tenantDomain) throws ActionExecutionException {

validateActionIdList(actionType, actionIdList);
Action action = getActionByActionId(actionType, actionIdList[0], tenantDomain);
try {
// As of now only one action is allowed.
if (actionIds.length != 1) {
throw new ActionExecutionException("Only support list with single action Id.");
}
return execute(getActionByActionId(actionType, actionIds[0], tenantDomain), eventContext);
return execute(action, 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);
}
}

private void validateActionIdList(ActionType actionType, String[] actionIdList) throws ActionExecutionException {

// As of now only one action is allowed.
if (actionIdList == null || actionIdList.length == 0) {
throw new ActionExecutionException("No action Ids found for action type: " + actionType.name());
}
if (actionIdList.length > 1) {
throw new ActionExecutionException("Multiple actions found for action type: " + actionType.name() +
". Current implementation doesn't support multiple actions for a single action type.");
}
}

private ActionExecutionStatus execute(Action action, Map<String, Object> eventContext)
throws ActionExecutionException {

Expand All @@ -149,13 +159,13 @@ private ActionExecutionStatus execute(Action action, Map<String, Object> eventCo
}

private Action getActionByActionId(ActionType actionType, String actionId, String tenantDomain)
throws ActionExecutionRuntimeException {
throws ActionExecutionException {

try {
return ActionExecutionServiceComponentHolder.getInstance().getActionManagementService().getActionByActionId(
Action.ActionTypes.valueOf(actionType.name()).getActionType(), actionId, tenantDomain);
} catch (ActionMgtException e) {
throw new ActionExecutionRuntimeException("Error occurred while retrieving action by action Id .", e);
throw new ActionExecutionException("Error occurred while retrieving action by action Id.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void testActionExecuteFailureWhenMultipleActionsAvailableForActionType()
}

@Test(expectedExceptions = ActionExecutionException.class,
expectedExceptionsMessageRegExp = "Only support list with single action Id.")
expectedExceptionsMessageRegExp = "No action Ids found for action type: PRE_ISSUE_ACCESS_TOKEN")
public void testActionExecuteWithActionIdsFailureWhenNotSingleActionIdAvailable() throws Exception {

actionExecutorService.execute(ActionType.PRE_ISSUE_ACCESS_TOKEN, new String[]{}, new HashMap<>(),
Expand Down Expand Up @@ -163,6 +163,16 @@ public void testActionExecuteWithActionIdFailureWhenMultipleActionsAvailableForA
actionExecutorService.execute(ActionType.PRE_ISSUE_ACCESS_TOKEN, new String[]{any()}, any(), any());
}

@Test(expectedExceptions = ActionExecutionException.class,
expectedExceptionsMessageRegExp = "Error occurred while retrieving action by action Id.")
public void testActionExecuteWithActionIdFailureWhenInvalidActionIdGiven() throws Exception {

when(actionManagementService.getActionByActionId(any(), any(), any())).thenThrow(
new ActionMgtException("Error occurred while retrieving action by action Id."));

actionExecutorService.execute(ActionType.PRE_ISSUE_ACCESS_TOKEN, new String[]{any()}, any(), any());
}

@Test
public void testActionExecuteFailureAtExceptionFromRequestBuilderForActionType() throws Exception {

Expand Down

0 comments on commit 6c8ef2e

Please sign in to comment.