Skip to content

Commit

Permalink
Call IDataWriteProcessor on all data element mutations and add new PO…
Browse files Browse the repository at this point in the history
…ST endpoint with better response type (#853)

* Remove unused property on DataPatchResult

* Rename CachedInstanceDataAccessor to InstanceDataUnitOfWork

Also take ApplicationMetadata instead of IAppMeatada service in constructor (it is usually already availible)

* Don't throw when a page can't be evaluated because no data elements of the default type exists.

* Add HttpContextExtension method to read request as byte[] efficiently

* Cleanup

* Better errro handling in ModelSerializationService
* make DataModelPairResponse a separate class, instead of a nested class
* Add JsonPropertyName on ValidationSourcePair

* Refactor DataController.Post

* Split into two endpoints (for compatibility)
* Old endpoint with dataType as GET param is unchanged.
* New endpoint returns all app state, the same way PATCH does
* Extend ProblemDetails explicitly so that swagger is correct

* Ensure that we cleanup instances after running tests that create instances

* Rewrite interfaces IDataWriteProcessor and IValidator (Bulk Changes test:fail)

List<DataElementChange> gets wrapped in DataElementChanges to support class hierarchy of Change types

Don't send Instance in addition to IInstanceDataAccessor

* Use IDataWriteProcessor in all apis to mutate data elements.

* Fix sonar issues

* Final clanup for v8.5

* Rename BinaryChange => BinaryDataChange
  • Loading branch information
ivarne authored Oct 28, 2024
1 parent 70517fd commit 6bac8a1
Show file tree
Hide file tree
Showing 62 changed files with 2,436 additions and 1,351 deletions.
18 changes: 10 additions & 8 deletions src/Altinn.App.Api/Controllers/ActionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ public async Task<ActionResult<UserActionResponse>> Perform(
return Forbid();
}

var dataMutator = new CachedInstanceDataAccessor(
var dataMutator = new InstanceDataUnitOfWork(
instance,
_dataClient,
_instanceClient,
_appMetadata,
await _appMetadata.GetApplicationMetadata(),
_modelSerialization
);
UserActionContext userActionContext =
Expand Down Expand Up @@ -179,15 +179,17 @@ public async Task<ActionResult<UserActionResponse>> Perform(
var saveTask = dataMutator.SaveChanges(changes);

var validationIssues = await GetIncrementalValidations(
instance,
dataMutator,
changes,
actionRequest.IgnoredValidators,
language
);
await saveTask;

var updatedDataModels = changes.ToDictionary(c => c.DataElement.Id, c => c.CurrentFormData);
var updatedDataModels = changes.FormDataChanges.ToDictionary(
c => c.DataElementIdentifier.Id,
c => c.CurrentFormData
);

#pragma warning disable CS0618 // Type or member is obsolete
if (result.UpdatedDataModels is { Count: > 0 })
Expand Down Expand Up @@ -216,16 +218,16 @@ private async Task<Dictionary<
string,
Dictionary<string, List<ValidationIssueWithSource>>
>?> GetIncrementalValidations(
Instance instance,
IInstanceDataAccessor dataAccessor,
List<DataElementChange> changes,
DataElementChanges changes,
List<string>? ignoredValidators,
string? language
)
{
var taskId = instance.Process.CurrentTask.ElementId;
var taskId =
dataAccessor.Instance.Process?.CurrentTask?.ElementId
?? throw new Exception("Unable to validate instance without a started process.");
var validationIssues = await _validationService.ValidateIncrementalFormData(
instance,
dataAccessor,
taskId,
changes,
Expand Down
Loading

0 comments on commit 6bac8a1

Please sign in to comment.