Skip to content
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

Rewrite of process engine to support actions in tasks resolves #205 and #207 #237

Merged
merged 30 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ef1f008
New process engine seems to work.
tjololo May 3, 2023
83106ad
refactored to make class more testable
tjololo May 5, 2023
d9a3a0b
added tests for ProcessEngine
tjololo May 5, 2023
3e59699
Refactor and delete old and unused code
tjololo May 5, 2023
d8a9f5c
added tests for ProcessEventDispatcher
tjololo May 5, 2023
9547df8
Add tests and fix ProcessNavigator
tjololo May 5, 2023
f8d1444
add available actions to currentTask and perform authcheck
tjololo May 5, 2023
edac5cf
action passed along from PUT process/next to gateway filters
tjololo May 5, 2023
e7b4ded
fix bug in AppProcessState ctor
tjololo May 5, 2023
9965885
add fields for read/write and check users permissions
tjololo May 5, 2023
7120616
Fix test stub implementation of IProcessExclusiveGateway
tjololo May 8, 2023
19dea2d
Fixing some reported code smells
tjololo May 8, 2023
ea04c41
Some code smell fixes.
tjololo May 8, 2023
fc627eb
remove unfinished test file
tjololo May 8, 2023
0327a6c
add tests for method in ProcessClient
tjololo May 8, 2023
fd0cf1d
add test for classes extending storage classes
tjololo May 8, 2023
62cee90
add test for null values in extensions
tjololo May 8, 2023
40086cf
revert code changes due to test
tjololo May 8, 2023
f139582
add frontend feature and parse request body on process/next if present
tjololo May 9, 2023
570a14a
add frontend feature and parse request body on process/next if present
tjololo May 9, 2023
711b21e
fix codeql warning
tjololo May 9, 2023
227d916
Merge branch 'v8' into feature/205-actions-on-tasks
tjololo May 9, 2023
e6dd6c5
add v8 as target of github workflows in addition to main
tjololo May 9, 2023
ba8430f
Fix return type of all methods in ProcessController returning Process…
tjololo May 10, 2023
958be06
Authorize action moved to AuthorizationClient
tjololo May 11, 2023
aa71607
Fixed some issues after review and added some more tests
tjololo May 12, 2023
86975f1
fix codeQL warning and improve test
tjololo May 12, 2023
8176158
Fix some code smells
tjololo May 15, 2023
0cf4486
Update src/Altinn.App.Api/Controllers/InstancesController.cs
tjololo May 15, 2023
9af5185
fix build error
tjololo May 15, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: "CodeQL"

on:
push:
branches: [ "main" ]
branches: [ "main", "v8" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
branches: [ "main", "v8" ]
schedule:
- cron: '37 20 * * 3'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dotnet-test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Build and Test on windows, macos and ubuntu
on:
push:
branches: [ main ]
branches: [ main, v8 ]
pull_request:
branches: [ main ]
branches: [ main, v8 ]
types: [opened, synchronize, reopened]
workflow_dispatch:
jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-and-analyze-fork.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Code test and analysis (fork)
on:
pull_request:
branches: [ main ]
branches: [ main, v8 ]
types: [opened, synchronize, reopened, ready_for_review]
jobs:
test:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-and-analyze.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Code test and analysis
on:
push:
branches: [ main ]
branches: [ main, v8 ]
pull_request:
branches: [ main ]
branches: [ main, v8 ]
types: [opened, synchronize, reopened]
workflow_dispatch:
jobs:
Expand Down
87 changes: 60 additions & 27 deletions src/Altinn.App.Api/Controllers/InstancesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using System.Net;
using System.Text;

using Altinn.App.Api.Helpers.RequestHandling;
using Altinn.App.Api.Infrastructure.Filters;
using Altinn.App.Api.Mappers;
Expand All @@ -16,6 +15,7 @@
using Altinn.App.Core.Interface;
using Altinn.App.Core.Internal.App;
using Altinn.App.Core.Internal.AppModel;
using Altinn.App.Core.Internal.Process;
using Altinn.App.Core.Models;
using Altinn.App.Core.Models.Validation;
using Altinn.Authorization.ABAC.Xacml.JsonProfile;
Expand All @@ -25,12 +25,10 @@
using Altinn.Platform.Profile.Models;
using Altinn.Platform.Register.Models;
using Altinn.Platform.Storage.Interface.Models;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;

using Newtonsoft.Json;

namespace Altinn.App.Api.Controllers
Expand Down Expand Up @@ -60,8 +58,8 @@ public class InstancesController : ControllerBase
private readonly IInstantiationValidator _instantiationValidator;
private readonly IPDP _pdp;
private readonly IPrefill _prefillService;
private readonly IProcessEngine _processEngine;
private readonly AppSettings _appSettings;
private readonly IProcessEngine _processEngine;

private const long RequestSizeLimit = 2000 * 1024 * 1024;

Expand All @@ -81,7 +79,7 @@ public InstancesController(
IEvents eventsService,
IOptions<AppSettings> appSettings,
IPrefill prefillService,
IProfile profileClient,
IProfile profileClient,
IProcessEngine processEngine)
{
_logger = logger;
Expand Down Expand Up @@ -208,6 +206,7 @@ public async Task<ActionResult<Instance>> Post(
}
else
{
// create minimum instance template
instanceTemplate = new Instance
{
InstanceOwner = new InstanceOwner { PartyId = instanceOwnerPartyId.Value.ToString() }
Expand Down Expand Up @@ -267,12 +266,24 @@ public async Task<ActionResult<Instance>> Post(

Instance instance;
instanceTemplate.Process = null;
ProcessChangeContext processChangeContext = new ProcessChangeContext(instanceTemplate, User);
ProcessStateChange? change = null;

try
{
// start process
processChangeContext.DontUpdateProcessAndDispatchEvents = true;
processChangeContext = await _processEngine.StartProcess(processChangeContext);
// start process and goto next task
ProcessStartRequest processStartRequest = new ProcessStartRequest
{
Instance = instanceTemplate,
User = User,
Dryrun = true
};
var result = await _processEngine.StartProcess(processStartRequest);
RonnyB71 marked this conversation as resolved.
Show resolved Hide resolved
if (!result.Success)
{
return Conflict(result.ErrorMessage);
}

change = result.ProcessStateChange;

// create the instance
instance = await _instanceClient.CreateInstance(org, app, instanceTemplate);
Expand All @@ -290,9 +301,14 @@ public async Task<ActionResult<Instance>> Post(
instance = await _instanceClient.GetInstance(app, org, int.Parse(instance.InstanceOwner.PartyId), Guid.Parse(instance.Id.Split("/")[1]));

// notify app and store events
processChangeContext.Instance = instance;
processChangeContext.DontUpdateProcessAndDispatchEvents = false;
await _processEngine.StartTask(processChangeContext);
var request = new ProcessStartRequest()
{
Instance = instance,
User = User,
Dryrun = false,
};
_logger.LogInformation("Events sent to process engine: {Events}", change?.Events);
await _processEngine.UpdateInstanceAndRerunEvents(request, change?.Events);
}
catch (Exception exception)
{
Expand Down Expand Up @@ -404,15 +420,21 @@ public async Task<ActionResult<Instance>> PostSimplified(
}

Instance instance;
ProcessChangeResult processResult;
try
{
// start process and goto next task
instanceTemplate.Process = null;

// start process
ProcessChangeContext processChangeContext = new ProcessChangeContext(instanceTemplate, User);
processChangeContext.Prefill = instansiationInstance.Prefill;
processChangeContext.DontUpdateProcessAndDispatchEvents = true;
processChangeContext = await _processEngine.StartProcess(processChangeContext);
var request = new ProcessStartRequest()
{
Instance = instanceTemplate,
User = User,
Dryrun = true,
Prefill = instansiationInstance.Prefill
};

processResult = await _processEngine.StartProcess(request);

Instance? source = null;

Expand Down Expand Up @@ -445,9 +467,14 @@ public async Task<ActionResult<Instance>> PostSimplified(

instance = await _instanceClient.GetInstance(instance);

processChangeContext.Instance = instance;
processChangeContext.DontUpdateProcessAndDispatchEvents = false;
await _processEngine.StartTask(processChangeContext);
var updateRequest = new ProcessStartRequest()
{
Instance = instance,
User = User,
Dryrun = false,
Prefill = instansiationInstance.Prefill
};
await _processEngine.UpdateInstanceAndRerunEvents(updateRequest, processResult.ProcessStateChange?.Events);
}
catch (Exception exception)
{
Expand Down Expand Up @@ -535,22 +562,28 @@ public async Task<ActionResult> CopyInstance(
{
return StatusCode((int)HttpStatusCode.Forbidden, validationResult);
}

ProcessChangeContext processChangeContext = new(targetInstance, User)
ProcessStartRequest processStartRequest = new()
{
DontUpdateProcessAndDispatchEvents = true
Instance = targetInstance,
User = User,
Dryrun = true
};
processChangeContext = await _processEngine.StartProcess(processChangeContext);
var startResult = await _processEngine.StartProcess(processStartRequest);

targetInstance = await _instanceClient.CreateInstance(org, app, targetInstance);

await CopyDataFromSourceInstance(application, targetInstance, sourceInstance);

targetInstance = await _instanceClient.GetInstance(targetInstance);

processChangeContext.Instance = targetInstance;
processChangeContext.DontUpdateProcessAndDispatchEvents = false;
await _processEngine.StartTask(processChangeContext);
ProcessStartRequest rerunRequest = new()
{
Instance = targetInstance,
Dryrun = false,
User = User
};
await _processEngine.UpdateInstanceAndRerunEvents(rerunRequest, startResult.ProcessStateChange?.Events);

await RegisterEvent("app.instance.created", targetInstance);
RonnyB71 marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Loading