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

v8 #247

Closed
wants to merge 1 commit into from
Closed

v8 #247

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
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);
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);

Expand Down
Loading