From de08da07797ebbd9bb7cc60b5bb6e80253df555f Mon Sep 17 00:00:00 2001 From: thisarawelmilla Date: Tue, 27 Aug 2024 15:15:56 +0530 Subject: [PATCH] Improve action execution framework. --- .../action/execution/EventContextBuilder.java | 39 ++++++++++++++ .../execution/EventContextBuilderFactory.java | 53 +++++++++++++++++++ .../action/execution/model/EventContext.java | 52 ++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/EventContextBuilder.java create mode 100644 components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/EventContextBuilderFactory.java create mode 100644 components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/model/EventContext.java diff --git a/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/EventContextBuilder.java b/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/EventContextBuilder.java new file mode 100644 index 000000000000..a2b28565497a --- /dev/null +++ b/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/EventContextBuilder.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.action.execution; + +import org.wso2.carbon.identity.action.execution.exception.ActionExecutionRequestBuilderException; +import org.wso2.carbon.identity.action.execution.model.ActionType; +import org.wso2.carbon.identity.action.execution.model.EventContext; + +import java.util.Map; + +/** + * This interface defines the Action Execution Builder. + * Action Execution Builder is the component that is responsible for building the Action Execution based on the + * action type and the event context. + */ +public interface EventContextBuilder { + + ActionType getSupportedActionType(); + + EventContext builEventContext(Map eventContext) throws + ActionExecutionRequestBuilderException; + +} diff --git a/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/EventContextBuilderFactory.java b/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/EventContextBuilderFactory.java new file mode 100644 index 000000000000..88ae1ce6e80f --- /dev/null +++ b/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/EventContextBuilderFactory.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.action.execution; + +import org.wso2.carbon.identity.action.execution.model.ActionExecutionRequest; +import org.wso2.carbon.identity.action.execution.model.ActionType; + +import java.util.HashMap; +import java.util.Map; + +/** + * This class defines the Action Execution Request Builder Factory. + * Action Execution Request Builder Factory is the component that is responsible for building + * {@link ActionExecutionRequest} + * based on the action type and the event context. + */ +public class EventContextBuilderFactory { + + private static final Map actionInvocationBuilders = + new HashMap<>(); + + public static EventContextBuilder getActionExecutionBuilder(ActionType actionType) { + + return actionInvocationBuilders.get(actionType); + } + + public static void registerActionExecutionBuilder(EventContextBuilder actionExecutionBuilder) { + + actionInvocationBuilders.put(actionExecutionBuilder.getSupportedActionType(), actionExecutionBuilder); + } + + public static void unregisterActionExecutionBuilder(ActionExecutionRequestBuilder actionExecutionBuilder) { + + actionInvocationBuilders.remove(actionExecutionBuilder.getSupportedActionType()); + } + +} diff --git a/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/model/EventContext.java b/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/model/EventContext.java new file mode 100644 index 000000000000..b6bfc3bcf1ff --- /dev/null +++ b/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/model/EventContext.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.action.execution.model; + +import java.util.Map; + +public class EventContext { + + private String actionId; + Map eventContext; + + public EventContext(Map eventContext) { + + this.eventContext = eventContext; + } + + public void setEventContext(Map eventContext) { + + this.eventContext = eventContext; + } + + public Map getEventContext() { + + return eventContext; + } + + public void setAction(String actionId) { + + this.actionId = actionId; + } + + public String getAction() { + + return actionId; + } +}