Under Construction
You may have already tried out workflow support for user store operations where you can configure user store operations to get approved at one or more steps.
Multi step approval is a very simple example of flows that can be used with IS workflow feature, but users are allowed define different types of configurable flows by adding a new workflow template.
The component for the jar that we are going to create contains of 4 main files. Following is the hierarchy where we need to structure those files.
TestWorkflow class should be added by extending AbstractTemplate. The following methods should be overridden:
getInputData() : Provides the parameter definition required by the template.
getTemplateId() : Should return the template Id which should be unique
getName() : Returns a user friendly name for the template. This will be the name shown at the admin UI
getDescription(): Returns a description about this template
Following is a sample class written for a multi step approval template.
public class TestTemplate extends AbstractTemplate { private static final String DESCRIPTION = "The operation should be approved by an authorized person with given role, to complete."; private static final String APPROVAL_TEMPLATE_NAME = "Multi-Step User/Role Approval"; private static final String TEMPLATE_ID = "TestTemplate"; public TestTemplate(String metaDataXML) throws WorkflowRuntimeException { super(metaDataXML); } @Override protected InputData getInputData(String parameterName) throws WorkflowException { return inputData; } @Override public String getTemplateId() { return TEMPLATE_ID; } @Override public String getName() { return APPROVAL_TEMPLATE_NAME; } @Override public String getDescription() { return DESCRIPTION; } } |
The configurable details of the template such as “Template ID”, “Template Name”, “Template Meta Data”, etc. should be separately defined in xml file like below.
<met:MetaData xmlns:met="http://metadata.bean.mgt.workflow.identity.carbon.wso2.org"> <met:Template> <met:TemplateId>TestTemplate</met:TemplateId> <met:TemplateName>Multi-Step User/Role Approval</met:TemplateName> <met:TemplateDescription>Multi-Step User/Role Approval</met:TemplateDescription> <met:ParametersMetaData xmlns:met="http://metadata.bean.mgt.workflow.identity.carbon.wso2.org"> <met:ParameterMetaData Name="UserAndRole" InputType="Multiple_Steps_User_Role" isRequired="true"> <met:DisplayName>User and Role</met:DisplayName> </met:ParameterMetaData> </met:ParametersMetaData> </met:Template> </met:MetaData>
The finally in the service component, we need to register this template at activation. We can do this as follows.
bundleContext.registerService(AbstractTemplate.class, new TestTemplate("TestTemplateMetaData.xml"),null);
Now we need to add a concrete implementation of this template.
Adding a Workflow Template Implementation
The template implementation defines how the template should be deployed and executed. This should be also written separately and put into repository/components/dropins as a jar file.
The implementations can be written by extending the AbstractWorkflow class. The following methods should be overridden:
getInputData() : Returns a parameter definition required by the template implementation
Following shows a sample class written for a sample template.
public class TestTemplateImplementation extends AbstractWorkflow { private static Log log = LogFactory.getLog(ApprovalWorkflow.class); @Override protected InputData getInputData(ParameterMetaData parameterMetaData) throws WorkflowException { return inputData; } public TestTemplateImplementation(Class<? extends TemplateInitializer> templateInitializerClass, Class<? extends WorkFlowExecutor> workFlowExecutorClass, String metaDataXML) { super(templateInitializerClass, workFlowExecutorClass, metaDataXML); } @Override public void deploy(List<Parameter> parameterList) throws WorkflowException { super.deploy(parameterList); } }
The configurable details of the template implementation such as “Template ID”, “Template Implementation ID”, “Template Implementation Meta Data”, etc. should be separately defined in xml file like below.
<met:MetaData xmlns:met="http://metadata.bean.mgt.workflow.identity.carbon.wso2.org"> <met:WorkflowImpl> <met:WorkflowImplId>TestTemplateImplementation</met:WorkflowImplId> <met:WorkflowImplName>TestTemplateImplementation</met:WorkflowImplName> <met:WorkflowImplDescription>Approval Workflow</met:WorkflowImplDescription> <met:TemplateId>TestTemplate</met:TemplateId> <met:ParametersMetaData> <met:ParameterMetaData Name="BPSProfile" InputType="Select" isRequired="true" isInputDataRequired="true"> <met:DisplayName>BPS Profile</met:DisplayName> </met:ParameterMetaData> <met:ParameterMetaData Name="HTSubject" DataType="String" InputType="Text" isRequired="true"> <met:DisplayName>Task Subject</met:DisplayName> </met:ParameterMetaData> <met:ParameterMetaData Name="HTDescription" DataType="String" InputType="TextArea"> <met:DisplayName>Task Detail</met:DisplayName> </met:ParameterMetaData> </met:ParametersMetaData> </met:WorkflowImpl> </met:MetaData>
Finally in the service component, we need to register this template at activation as follows.
bundleContext.registerService(AbstractWorkflow.class, new TestTemplateImplementation(BPELDeployer.class, RequestExecutor.class, readWorkflowImplParamMetaDataXML("TestTemplateImplementationMetadata2.xml")), null);
Now when adding a new workflow, you will get a drop down menu to select which template to follow in that workflow.