Warning |
---|
|
This page is currently under construction. The content in this page might not be completely accurate. |
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.
...
Adding a New Workflow Template
A workflow template defines a configurable flow. It is an abstract representation of a workflow. You can add a new template by adding a new jar creating a custom bundle as below and copying it to repository/components/dropins folder. You can create a jar as described below.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.
Image Removed
TestWorkflow class should be added by extending AbstractTemplate.
First, you need to create a SampleTemplate class which extends AbstractTemplate class. 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.
TestTemplateSampleTemplate extends AbstractTemplate {
|
|
privatestaticfinalStringDESCRIPTION= "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
publicpublic SampleTemplate(String metaDataXML) throws WorkflowRuntimeException {
super(metaDataXML);
}
@Override
protected InputData getInputData(String parameterName) throws WorkflowException {
return null;
}
@Override
public String getTemplateId() { |
|
return }
@Override
public}
@Override
public String getName() { |
|
return
return APPROVAL_TEMPLATE_NAME;
|
|
}
@Override
public}
@Override
public String getDescription() { |
|
return 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.
Code Block |
---|
<met:MetaData xmlns:met="http://metadata.bean.mgt.workflow.identity.carbon.wso2.org">
<met<met:Template>
<met:TemplateId>TestTemplate<
<met:TemplateId>SampleTemplate</met:TemplateId>
<met:TemplateName>Multi-Step User/Role Approval<
<met:TemplateName>SampleTemplate</met:TemplateName>
<met:TemplateDescription>Multi-Step User/Role Approval<
<met:TemplateDescription>Sample Template</met:TemplateDescription>
<met
<met:ParametersMetaData xmlns:met="http://metadata.bean.mgt.workflow.identity.carbon.wso2.org">
<met
<met:ParameterMetaData Name="UserAndRole" InputType="Multiple_Steps_User_Role" isRequired="true">
<met
<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.
Code Block |
---|
bundleContext.registerService(AbstractTemplate.class, new TestTemplate("TestTemplateMetaData.xml"),SampleTemplate(readFileContent(Constants.TEMPLATE_PARAMETER_METADATA_FILE_NAME)), 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 Optionally you can write this as a separate bundle and copy into repository/components/dropins as a jar filefolder.
The implementations can be written by extending the AbstractWorkflow class. The following methods should be overridden:
Following The following shows a sample class written for a sample template.
Code Block |
---|
public class TestTemplateImplementationSampleTemplateImplementation extends AbstractWorkflow {
private
private static Log log = LogFactory.getLog(ApprovalWorkflow.class);
@Override
protectedSampleTemplateImplementation.class);
public SampleTemplateImplementation(Class<? extends TemplateInitializer> templateInitializerClass,
Class<? extends WorkFlowExecutor> workFlowExecutorClass, String metaDataXML) {
super(templateInitializerClass, workFlowExecutorClass, metaDataXML);
}
@Override
protected InputData getInputData(ParameterMetaData parameterMetaData) throws WorkflowException {
return
InputData inputData = null;
}
public TestTemplateImplementation(Class<? extends TemplateInitializer> templateInitializerClass, Class<? extends WorkFlowExecutor> workFlowExecutorClass, String metaDataXML) {
super(templateInitializerClass, workFlowExecutorClass, metaDataXML);
}
@Override
public
if (parameterMetaData != null && parameterMetaData.getName() != null) {
String parameterName = parameterMetaData.getName();
if ("BPSProfile".equals(parameterName)) {
inputData = new InputData();
MapType mapType = new MapType();
inputData.setMapType(mapType);
Item item = new Item();
item.setKey("embeded_bps");
item.setValue("embeded_bps");
mapType.setItem(new Item[]{item});
} else if ("HTSubject".equals(parameterName)) {
inputData = new InputData();
MapType mapType = new MapType();
inputData.setMapType(mapType);
Item item1 = new Item();
item1.setKey("subject1");
item1.setValue("subject1");
Item item2 = new Item();
item2.setKey("subject2");
item2.setValue("subject2");
mapType.setItem(new Item[]{item1, item2});
}
}
return inputData;
}
@Override
public void deploy(List<Parameter> parameterList) throws WorkflowException {
super
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.
Code Block |
---|
<met:MetaData xmlns:met="http://metadata.bean.mgt.workflow.identity.carbon.wso2.org">
<met:WorkflowImpl>
<met:WorkflowImplId>TestTemplateImplementation<
<met:WorkflowImplId>SampleWorkflow</met:WorkflowImplId>
<met:WorkflowImplName>TestTemplateImplementation<
<met:WorkflowImplName>SampleWorkflow</met:WorkflowImplName>
<met:WorkflowImplDescription>Approval
<met:WorkflowImplDescription>Sample Workflow</met:WorkflowImplDescription>
<met:TemplateId>TestTemplate<
<met:TemplateId>SampleTemplate</met:TemplateId>
<met:ParametersMetaData>
<met
<met:ParametersMetaData>
<met:ParameterMetaData Name="BPSProfile" InputType="Select" isRequired="true" isInputDataRequired="true">
<met:DisplayName>BPS Profile< <met:DisplayName>BPS Profile(Server Profile Name)</met:DisplayName>
<
</met:ParameterMetaData>
<met
<met:ParameterMetaData Name="HTSubject" DataTypeInputType="StringSelect" InputTypeisRequired="Texttrue" isRequiredisInputDataRequired="true">
<met:DisplayName>Task Subject<
<met:DisplayName>Task Subject(Approval task subject to display)</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.
Code Block |
---|
bundleContext.registerService(AbstractWorkflow.class, new TestTemplateImplementationSampleTemplateImplementation(BPELDeployer.class, RequestExecutor.class, readWorkflowImplParamMetaDataXMLreadFileContent("TestTemplateImplementationMetadata2.xml"Constants.WORKFLOW_IMPL_PARAMETER_METADATA_FILE_NAME)), null); |
Now when adding a new workflow, you will get a drop-down menu to select which template to follow in that workflow.
Image Removed
Image Added
Source of the sample which used for this documentation can be found here.