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

Conversation

tjololo
Copy link
Member

@tjololo tjololo commented May 8, 2023

Description

Resolves #205
Resolves #207
Rewrite of process engine and process definition (BPMN). Process navigation is now decided based on actions defined on a process task.
This requires a small rewrite of the proces.bpmn file in apps as we are moving altinn specific properties to bpmn:extensionProperties.
This also introduces additional properties in the GET /process endpoint listing available actions for the current task

POST /process/next has an additional query parameter action to make migration to v8 easier elementId param is still available and act as a alias for action.
Applications leveraging elementId to perform gateway navigation would need to change some parts of the frontend to support v8.

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

@tjololo tjololo added the breaking-change Label Pull requests with breaking changes. Used when generating releasenotes label May 8, 2023
Comment on lines +73 to +76
catch (Exception exception)
{
_logger.LogWarning(exception, "Exception when sending event with the Events component");
}

Check notice

Code scanning / CodeQL

Generic catch clause

Generic catch clause.
tjololo added 2 commits May 8, 2023 12:34
Added logic to dispatch abandon event if action is reject
@tjololo tjololo changed the base branch from main to v8 May 9, 2023 08:32
@tjololo tjololo changed the title Rewrite of process engine to support actions in tasks resolves #205 Rewrite of process engine to support actions in tasks resolves #205 and #207 May 11, 2023
@RonnyB71 RonnyB71 self-requested a review May 12, 2023 05:32
return await _processChangeHandler.HandleStart(processChange);
if (string.IsNullOrEmpty(instanceEvent.User.OrgId) && userId != null)
{
UserProfile up = await _profileService.GetUserProfile((int)userId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a http call that should have been done outside of this method, ideally done once for the entire user request and just passed in as a dependency.

@tjololo tjololo linked an issue May 12, 2023 that may be closed by this pull request
/// <param name="startRequest"></param>
/// <param name="events"></param>
/// <returns></returns>
Task<Instance> UpdateInstanceAndRerunEvents(ProcessStartRequest startRequest, List<InstanceEvent>? events);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit misplaced compared to the other two and the name causes me to think of side effects and why we need to re-run events.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an issue for tracking this: #240

/// <summary>
/// Interface used to descipt the process navigator
/// </summary>
public interface IProcessNavigator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is IProcessEngine considered as a home for this method since this has process navigation methods already?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is whats left of the IFlowHydration interface. I didn't want to merge it with the processengine yet as that code really still needs alot of cleanup.
Leaving it for now until the IProcessEngine is more clean

/// <returns></returns>
public Task<List<SequenceFlow>> FilterAsync(List<SequenceFlow> outgoingFlows, Instance instance);
public Task<List<SequenceFlow>> FilterAsync(List<SequenceFlow> outgoingFlows, Instance instance, string? action);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct that an exclusive gateway returns a list of sequence flows?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had the same thought. We need to decide if it should be possible to return more than one flow from a gateway and then choose the default (if defined), or if a gateway always needs to return one flow

Comment on lines +105 to +130
foreach (InstanceEvent instanceEvent in events)
{
if (Enum.TryParse<InstanceEventType>(instanceEvent.EventType, true, out InstanceEventType eventType))
{
string? elementId = instanceEvent.ProcessInfo?.CurrentTask?.ElementId;
ITask task = GetProcessTask(instanceEvent.ProcessInfo?.CurrentTask?.AltinnTaskType);
switch (eventType)
{
case InstanceEventType.process_StartEvent:
break;
case InstanceEventType.process_StartTask:
await task.HandleTaskStart(elementId, instance, prefill);
break;
case InstanceEventType.process_EndTask:
await task.HandleTaskComplete(elementId, instance);
break;
case InstanceEventType.process_AbandonTask:
await task.HandleTaskAbandon(elementId, instance);
await _instanceService.UpdateProcess(instance);
break;
case InstanceEventType.process_EndEvent:
await _appEvents.OnEndAppEvent(instanceEvent.ProcessInfo?.EndEvent, instance);
break;
}
}
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Where

This foreach loop [implicitly filters its target sequence](1) - consider filtering the sequence explicitly using '.Where(...)'.
/// <summary>
/// The process change was not allowed due to the current state of the process
/// </summary>
Conflict
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this being used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only possible return today is Conflict so not really used. If error results emerges we would need to use it

tjololo and others added 2 commits May 15, 2023 14:09
Co-authored-by: Ronny Birkeli <ronny.birkeli@gmail.com>
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 19 Code Smells

72.0% 72.0% Coverage
0.0% 0.0% Duplication

@tjololo tjololo merged commit 6ab302e into v8 May 15, 2023
@tjololo tjololo deleted the feature/205-actions-on-tasks branch May 15, 2023 13:10
@tjololo tjololo mentioned this pull request May 30, 2023
Closed
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Label Pull requests with breaking changes. Used when generating releasenotes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Authorize actiontype Endpoint providing information what actions a user has access to
2 participants