Skip to content

WFS-468 Vacation request sample #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Callback API Sample

This is a sample of a Web Api server for working with the WorkflowServer Callback API.
Callback API allows hosting your code of Actions, Conditions or Rules on third-party servers.
Callback server should be connected in the admin panel on the Callback API page.
More details on the [workflowserver.io](https://workflowserver.io/documentation/callback-api).

## What's inside

- **ApiController** – controller that implements all possible requests from Callback API of WFS 3.0.0.
- **ActionProvider, ConditionProvider, IdentityProvider** – a sample of the implementation of API functions.
- **VacationRequest** is a schema that implements this API.

## How to start

- Download, deploy and start WorkflowServer. More details on the [workflowserver.io](https://workflowserver.io/documentation/how-to-launch)
- Deploy and start this Web Api Server.
- Go to the WorkflowServer, in the sidebar go to "Api" -> "Callback API". Set up a connection properties to this API.
More details on the [workflowserver.io](https://workflowserver.io/documentation/callback-api)
- In the sidebar, go to "Workflow" -> "Scheme Management" -> "Create".
Create a scheme, name it "VacationRequest" and upload the `Schemes/VacationRequest.xml` file from API project to the Scheme.
- You can now test this sample with the WorkflowApi.
Just create an instance, you can change the initial parameters if you like. Use the Workflow API to execute commands.
Learn more about [workflowserver.io](https://workflowserver.io/documentation/workflow-api)
59 changes: 58 additions & 1 deletion WorkflowServer.CallbackApi/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace WorkflowServer.CallbackApi.Controllers;

/// <summary>
/// This controller implements all possible requests from Callback API of WFS 3.0.0.
/// This controller implements all possible requests from Callback API of Workflow Server 3.0.0.
/// Callback API allows hosting your code of Actions, Conditions or Rules on third-party servers.
/// Callback server should be connected in the admin panel on the Callback API page.
/// More details on the <see href="https://workflowserver.io/documentation/callback-api">workflowserver.io</see>
Expand All @@ -23,17 +23,28 @@ public ApiController(ILogger<ApiController> logger)
_actionProvider = new ActionProvider();
_conditionProvider = new ConditionProvider();
_identityProvider = new IdentityProvider();

//The parameters will not be saved, this is an example. You should add the provider as a dependency injection.
_parameterProvider = new ParameterProvider();
}

#region Actions & Conditions Execution

/// <summary>
/// Returns a list of actions that can be executed on the callback server.
/// When the Workflow Server should execute an Action with a certain name,
/// it calls the action execution method on the server that has returned this
/// name in response to the request for the list of actions.
/// </summary>
[HttpGet]
public Task<IActionResult> GetActions(string schemeCode, string token)
{
return Task.FromResult<IActionResult>(Ok(ApiResponse.Ok(_actionProvider.ActionNames)));
}

/// <summary>
/// Request to execute the action. Which of callback servers is called to execute this method, depends on the list of actions returned.
/// </summary>
[HttpPost]
public async Task<IActionResult> ExecuteAction(InstanceRequest request)
{
Expand All @@ -42,12 +53,22 @@ public async Task<IActionResult> ExecuteAction(InstanceRequest request)
return Ok(ApiResponse.Ok());
}

/// <summary>
/// Returns a list of conditions that can be executed on the callback server.
/// When the Workflow Server should execute a condition with a certain name,
/// it calls the condition execution method on the server that has returned
/// this name in response to the request for the list of conditions.
/// </summary>
[HttpGet]
public Task<IActionResult> GetConditions(string schemeCode, string token)
{
return Task.FromResult<IActionResult>(Ok(ApiResponse.Ok(_conditionProvider.ConditionNames)));
}

/// <summary>
/// Request to execute the condition. Which of the callback servers
/// is called to execute this method, depends on the list of conditions returned.
/// </summary>
[HttpPost]
public async Task<IActionResult> ExecuteCondition(InstanceRequest request)
{
Expand All @@ -63,19 +84,31 @@ public async Task<IActionResult> ExecuteCondition(InstanceRequest request)

#region Authorization Rules Execution

/// <summary>
/// Returns a list of Authorization Rules that can be executed on the callback server.
/// When the Workflow Server should execute an Authorization Rule with a certain name,
/// it calls the Authorization Rule execution method on the server that has returned
/// this name in response to the request for the list of Authorization Rules.
/// </summary>
[HttpGet]
public Task<IActionResult> GetRules(string schemeCode, string token)
{
return Task.FromResult<IActionResult>(Ok(ApiResponse.Ok(_identityProvider.RuleNames)));
}

/// <summary>
/// Check if the User has the access to the command.
/// </summary>
[HttpPost]
public async Task<IActionResult> CheckRule(CheckRuleRequest request)
{
var result = await _identityProvider.RuleCheck(request.Name, request.IdentityId, request.Parameter, request.ProcessInstance);
return Ok(ApiResponse.Ok(result));
}

/// <summary>
/// Returns the list of all Users who have the access.
/// </summary>
[HttpPost]
public async Task<IActionResult> GetIdentities(InstanceRequest request)
{
Expand All @@ -89,6 +122,11 @@ public async Task<IActionResult> GetIdentities(InstanceRequest request)

#region Remote Scheme Generation

/// <summary>
/// Workflow Engine (is a part of WorkflowServer) supports scheme generation. If you include this method, then,
/// to initialize a new scheme, the Workflow Server calls it on all the connected
/// servers with the settings containing the address of this method.
/// </summary>
[HttpPost]
public Task<IActionResult> Generate(GenerateRequest request)
{
Expand All @@ -103,6 +141,10 @@ public Task<IActionResult> Generate(GenerateRequest request)

#region Event Handlers

/// <summary>
/// The ProcessStatusChanged event is called only after switching to
/// the statuses of Idled and Finalized. It is not called for subprocesses.
/// </summary>
[HttpPost]
public Task<IActionResult> ProcessStatusChanged(StatusChangedRequest request)
{
Expand All @@ -114,6 +156,9 @@ public Task<IActionResult> ProcessStatusChanged(StatusChangedRequest request)
return Task.FromResult<IActionResult>(Ok(ApiResponse.Ok()));
}

/// <summary>
/// The ProcessActivityChanged event.
/// </summary>
[HttpPost]
public Task<IActionResult> ProcessActivityChanged(ActivityChangedRequest request)
{
Expand All @@ -125,6 +170,9 @@ public Task<IActionResult> ProcessActivityChanged(ActivityChangedRequest request
return Task.FromResult<IActionResult>(Ok(ApiResponse.Ok()));
}

/// <summary>
/// The processLogs event.
/// </summary>
[HttpPost]
public Task<IActionResult> ProcessLog(LogRequest request)
{
Expand All @@ -137,19 +185,28 @@ public Task<IActionResult> ProcessLog(LogRequest request)

#region Parameters Providing

/// <summary>
/// Used to get parameters list.
/// </summary>
[HttpGet]
public Task<IActionResult> GetParameterNames(string schemeCode, string token)
{
return Task.FromResult<IActionResult>(Ok(ApiResponse.Ok(_parameterProvider.GetNames)));
}

/// <summary>
/// The method returns a JSON serialized parameter value.
/// </summary>
[HttpPost]
public Task<IActionResult> GetParameter(ParameterRequest request)
{
var result = _parameterProvider.GetParameter(request.Name);
return Task.FromResult<IActionResult>(Ok(ApiResponse.Ok(result)));
}

/// <summary>
/// Used for set parameter value.
/// </summary>
[HttpPost]
public Task<IActionResult> SetParameter(ParameterRequest request)
{
Expand Down
184 changes: 184 additions & 0 deletions WorkflowServer.CallbackApi/Schemes/VacationRequest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<Process Name="VacationRequest" CanBeInlined="false" Tags="" LogEnabled="true">
<Designer X="-110" Y="-60" />
<Actors>
<Actor Name="Manager" Rule="isUser" Value="@Manager" />
<Actor Name="Author" Rule="isUser" Value="@Author" />
<Actor Name="BigBoss" Rule="InRole" Value="Big Boss" />
<Actor Name="Accountant" Rule="InRole" Value="Accountant" />
</Actors>
<Parameters>
<Parameter Name="Comment" Type="String" Purpose="Temporary" />
<Parameter Name="Author" Type="String" Purpose="Persistence" InitialValue="John" />
<Parameter Name="Manager" Type="String" Purpose="Persistence" InitialValue="Margo" />
<Parameter Name="Sum" Type="Int32" Purpose="Persistence" InitialValue="100" />
</Parameters>
<Commands>
<Command Name="StartSigning">
<InputParameters>
<ParameterRef Name="Comment" IsRequired="false" DefaultValue="" NameRef="Comment" />
</InputParameters>
</Command>
<Command Name="Approve">
<InputParameters>
<ParameterRef Name="Comment" IsRequired="false" DefaultValue="" NameRef="Comment" />
</InputParameters>
</Command>
<Command Name="Reject">
<InputParameters>
<ParameterRef Name="Comment" IsRequired="false" DefaultValue="" NameRef="Comment" />
</InputParameters>
</Command>
<Command Name="Paid">
<InputParameters>
<ParameterRef Name="Comment" IsRequired="false" DefaultValue="" NameRef="Comment" />
</InputParameters>
</Command>
</Commands>
<Timers>
<Timer Name="SendToBigBoss" Type="Interval" Value="10minutes" NotOverrideIfExists="false" />
</Timers>
<Activities>
<Activity Name="VacationRequestCreated" State="VacationRequestCreated" IsInitial="true" IsFinal="false" IsForSetState="true" IsAutoSchemeUpdate="true">
<Implementation>
<ActionRef Order="1" NameRef="JsonBackup">
<ActionParameter><![CDATA[StartBackup]]></ActionParameter>
</ActionRef>
</Implementation>
<Designer X="20" Y="160" Hidden="false" />
</Activity>
<Activity Name="ManagerSigning" State="ManagerSigning" IsInitial="false" IsFinal="false" IsForSetState="true" IsAutoSchemeUpdate="true">
<Designer X="360" Y="160" Hidden="false" />
</Activity>
<Activity Name="BigBossSigning" State="BigBossSigning" IsInitial="false" IsFinal="false" IsForSetState="true" IsAutoSchemeUpdate="true">
<Designer X="640" Y="160" Hidden="false" />
</Activity>
<Activity Name="AccountingReview" State="AccountingReview" IsInitial="false" IsFinal="false" IsForSetState="true" IsAutoSchemeUpdate="true">
<Designer X="630" Y="320" Hidden="false" />
</Activity>
<Activity Name="RequestApproved" State="RequestApproved" IsInitial="false" IsFinal="true" IsForSetState="true" IsAutoSchemeUpdate="true">
<Implementation>
<ActionRef Order="1" NameRef="JsonBackup">
<ActionParameter><![CDATA[FinalBackup]]></ActionParameter>
</ActionRef>
</Implementation>
<Designer X="900" Y="320" Hidden="false" />
</Activity>
</Activities>
<Transitions>
<Transition Name="ManagerSigning_Draft_1" To="VacationRequestCreated" From="ManagerSigning" Classifier="Reverse" AllowConcatenationType="And" RestrictConcatenationType="And" ConditionsConcatenationType="And" DisableParentStateControl="false">
<Restrictions>
<Restriction Type="Allow" NameRef="Manager" />
</Restrictions>
<Triggers>
<Trigger Type="Command" NameRef="Reject" />
</Triggers>
<Conditions>
<Condition Type="Always" />
</Conditions>
<Designer X="269" Y="205" Hidden="false" />
</Transition>
<Transition Name="BigBossSigning_Activity_1_1" To="AccountingReview" From="BigBossSigning" Classifier="Direct" AllowConcatenationType="And" RestrictConcatenationType="And" ConditionsConcatenationType="And" DisableParentStateControl="false">
<Restrictions>
<Restriction Type="Allow" NameRef="BigBoss" />
</Restrictions>
<Triggers>
<Trigger Type="Command" NameRef="Approve" />
</Triggers>
<Conditions>
<Condition Type="Always" />
</Conditions>
<Designer Hidden="false" />
</Transition>
<Transition Name="ManagerSigning_Approved_1" To="AccountingReview" From="ManagerSigning" Classifier="Direct" AllowConcatenationType="And" RestrictConcatenationType="And" ConditionsConcatenationType="And" DisableParentStateControl="false">
<Restrictions>
<Restriction Type="Allow" NameRef="Manager" />
</Restrictions>
<Triggers>
<Trigger Type="Command" NameRef="Approve" />
</Triggers>
<Conditions>
<Condition Type="Otherwise" />
</Conditions>
<Designer X="453" Y="271" Hidden="false" />
</Transition>
<Transition Name="ManagerSigning_BigBossSigning_1" To="BigBossSigning" From="ManagerSigning" Classifier="Direct" AllowConcatenationType="And" RestrictConcatenationType="And" ConditionsConcatenationType="And" DisableParentStateControl="false">
<Restrictions>
<Restriction Type="Allow" NameRef="Manager" />
</Restrictions>
<Triggers>
<Trigger Type="Command" NameRef="Approve" />
</Triggers>
<Conditions>
<Condition Type="Expression" ConditionInversion="false">
<Expression><![CDATA[@Sum > 100]]></Expression>
</Condition>
</Conditions>
<Designer X="562" Y="177" Hidden="false" />
</Transition>
<Transition Name="Draft_ManagerSigning_1" To="ManagerSigning" From="VacationRequestCreated" Classifier="Direct" AllowConcatenationType="And" RestrictConcatenationType="And" ConditionsConcatenationType="And" DisableParentStateControl="false">
<Restrictions>
<Restriction Type="Allow" NameRef="Author" />
</Restrictions>
<Triggers>
<Trigger Type="Command" NameRef="StartSigning" />
</Triggers>
<Conditions>
<Condition Type="Always" />
</Conditions>
<Designer X="269" Y="170" Hidden="false" />
</Transition>
<Transition Name="BigBossSigning_ManagerSigning_1" To="ManagerSigning" From="BigBossSigning" Classifier="Reverse" AllowConcatenationType="And" RestrictConcatenationType="And" ConditionsConcatenationType="And" DisableParentStateControl="false">
<Restrictions>
<Restriction Type="Allow" NameRef="BigBoss" />
</Restrictions>
<Triggers>
<Trigger Type="Command" NameRef="Reject" />
</Triggers>
<Conditions>
<Condition Type="Always" />
</Conditions>
<Designer X="563" Y="204" Hidden="false" />
</Transition>
<Transition Name="ManagerSigning_BigBossSigning_2" To="BigBossSigning" From="ManagerSigning" Classifier="NotSpecified" AllowConcatenationType="And" RestrictConcatenationType="And" ConditionsConcatenationType="And" DisableParentStateControl="false">
<Triggers>
<Trigger Type="Timer" NameRef="SendToBigBoss" />
</Triggers>
<Conditions>
<Condition Type="Always" />
</Conditions>
<Designer X="557" Y="120" Hidden="false" />
</Transition>
<Transition Name="Accountant_Activity_1_1" To="RequestApproved" From="AccountingReview" Classifier="Direct" AllowConcatenationType="And" RestrictConcatenationType="And" ConditionsConcatenationType="And" DisableParentStateControl="false">
<Restrictions>
<Restriction Type="Allow" NameRef="Accountant" />
</Restrictions>
<Triggers>
<Trigger Type="Command" NameRef="Paid" />
</Triggers>
<Conditions>
<Condition Type="Always" />
</Conditions>
<Designer Hidden="false" />
</Transition>
<Transition Name="Accountant_ManagerSigning_1" To="ManagerSigning" From="AccountingReview" Classifier="Reverse" AllowConcatenationType="And" RestrictConcatenationType="And" ConditionsConcatenationType="And" DisableParentStateControl="false">
<Restrictions>
<Restriction Type="Allow" NameRef="Accountant" />
</Restrictions>
<Triggers>
<Trigger Type="Command" NameRef="Reject" />
</Triggers>
<Conditions>
<Condition Type="Always" />
</Conditions>
<Designer X="395" Y="343" Hidden="false" />
</Transition>
</Transitions>
<Localization>
<Localize Type="State" IsDefault="True" Culture="en-US" ObjectName="ManagerSigning" Value="Manager signing" />
<Localize Type="State" IsDefault="True" Culture="en-US" ObjectName="BigBossSigning" Value="BigBoss signing" />
<Localize Type="Command" IsDefault="True" Culture="en-US" ObjectName="StartSigning" Value="Start signing" />
<Localize Type="State" IsDefault="True" Culture="en-US" ObjectName="AccountingReview" Value="Accounting review" />
<Localize Type="State" IsDefault="True" Culture="en-US" ObjectName="VacationRequestCreated" Value="Vacation request created" />
<Localize Type="State" IsDefault="True" Culture="en-US" ObjectName="RequestApproved" Value="Request approved" />
</Localization>
</Process>
15 changes: 15 additions & 0 deletions WorkflowServer.CallbackApi/VacationRequest/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace WorkflowServer.CallbackApi.VacationRequest;

public class User
{
public User(string id, string name, params string[] roles)
{
Id = id;
Name = name;
Roles = roles;
}

public string Id { get; }
public string Name { get; }
public string[] Roles { get; }
}
Loading