Skip to content

Commit

Permalink
Improve action execution framework.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Aug 27, 2024
1 parent a33b657 commit de08da0
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<String, Object> eventContext) throws
ActionExecutionRequestBuilderException;

}
Original file line number Diff line number Diff line change
@@ -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<ActionType, EventContextBuilder> 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());
}

}
Original file line number Diff line number Diff line change
@@ -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<String, Object> eventContext;

public EventContext(Map<String, Object> eventContext) {

this.eventContext = eventContext;
}

public void setEventContext(Map<String, Object> eventContext) {

this.eventContext = eventContext;
}

public Map<String, Object> getEventContext() {

return eventContext;
}

public void setAction(String actionId) {

this.actionId = actionId;
}

public String getAction() {

return actionId;
}
}

0 comments on commit de08da0

Please sign in to comment.