-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New validation and partial validation via PATCH endpoint (#393)
* Revert Multipart form data #329 on PUT endpoint * Add JsonPatch and create a new PATCH endpoint for updating form data * Fix a few SonarCloud warnings * Start work on new validation Improve GetJsonPath(Expression) and fix some sonarcloud issues Improve test coverage Full validation rewrite complete and existing tests work Probably still some issues and test coverage was spoty so more tests needs to be written. Make IInstanceValidator obsolete Add DataType as input to validators Fix a few issues to prepare for tests of expressions Add more tests * Fix sonar cloud issues * Rename to get more consistent naming * Clanup DataType/TaskId to allow * Also comment out KeyedService fetching * Fix more sonarcloud issues * Registrer new validators in DI container * Remove dead code * Adjust interface and add a few tests * Add object? previousData to IDataProcessor * Cleanup and more tests * OptionsSource doesn't really need a label to work. In recent fronted versions, this label can also be an expression, so parsing fails when this is expected to be a string. * Removing the requirement for a 'pageRef' property on Summary components. Frontend doesn't use this anymore, and disallows rendering Summary components with it. * Allowing attachments to be deleted (attachments don't have AppLogic) * ValidationIssue.Severity is an int in json Improve handeling of errors in PATCH endpoint code style fixes * Initialize lists for concistency in frontend after patch also add tests * Fix issues with list initialization and prettify tests * Add test to verify that PATCH initializes arrays (as xml serialization does) * Read json configuration file for api tests * Set empty strings to null in patch endpoint xml serializing does always preserve empty string when using attributes and [XmlText]. * Apply suggestions from code review Co-authored-by: Vemund Gaukstad <[email protected]> * Remove caching logic for CanTaskBeEnded * Improve description on validationsource * Rename ShouldRun to HasRelevantChanges fix style issues * Fix dataProcessorRewriter * Add genericDataProcessor * Fix a few codestyle issues * Making some validator sources match those used on the frontend * Fix tests after validator source name change * Adding support for explicit repeating group components (new in frontend v4) --------- Co-authored-by: Ole Martin Handeland <[email protected]> Co-authored-by: Vemund Gaukstad <[email protected]>
- Loading branch information
1 parent
45cfc6d
commit 3bac97d
Showing
81 changed files
with
3,846 additions
and
1,448 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#nullable enable | ||
using System.Text.Json.Serialization; | ||
using Altinn.App.Api.Controllers; | ||
using Json.Patch; | ||
|
||
namespace Altinn.App.Api.Models; | ||
|
||
/// <summary> | ||
/// Represents the request to patch data on the <see cref="DataController"/>. | ||
/// </summary> | ||
public class DataPatchRequest | ||
{ | ||
/// <summary> | ||
/// The Patch operation to perform. | ||
/// </summary> | ||
[JsonPropertyName("patch")] | ||
public required JsonPatch Patch { get; init; } | ||
|
||
/// <summary> | ||
/// List of validators to ignore during the patch operation. | ||
/// Issues from these validators will not be run during the save operation, but the validator will run on process/next | ||
/// </summary> | ||
[JsonPropertyName("ignoredValidators")] | ||
public required List<string>? IgnoredValidators { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Altinn.App.Api.Controllers; | ||
using Altinn.App.Core.Models.Validation; | ||
|
||
namespace Altinn.App.Api.Models; | ||
|
||
/// <summary> | ||
/// Represents the response from a data patch operation on the <see cref="DataController"/>. | ||
/// </summary> | ||
public class DataPatchResponse | ||
{ | ||
/// <summary> | ||
/// The validation issues that were found during the patch operation. | ||
/// </summary> | ||
public required Dictionary<string, List<ValidationIssue>> ValidationIssues { get; init; } | ||
|
||
/// <summary> | ||
/// The current data model after the patch operation. | ||
/// </summary> | ||
public required object NewDataModel { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/Altinn.App.Core/Features/DataProcessing/GenericDataProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Altinn.Platform.Storage.Interface.Models; | ||
|
||
namespace Altinn.App.Core.Features.DataProcessing; | ||
|
||
/// <summary> | ||
/// Convenience class for implementing <see cref="IDataProcessor"/> for a specific model type. | ||
/// </summary> | ||
public abstract class GenericDataProcessor<TModel> : IDataProcessor where TModel : class | ||
{ | ||
/// <summary> | ||
/// Do changes to the model after it has been read from storage, but before it is returned to the app. | ||
/// this only executes on page load and not for subsequent updates. | ||
/// </summary> | ||
public abstract Task ProcessDataRead(Instance instance, Guid? dataId, TModel model); | ||
|
||
/// <summary> | ||
/// Do changes to the model before it is written to storage, and report back to frontend. | ||
/// Tyipically used to add calculated values to the model. | ||
/// </summary> | ||
public abstract Task ProcessDataWrite(Instance instance, Guid? dataId, TModel model, TModel? previousModel); | ||
|
||
/// <inheritdoc /> | ||
public async Task ProcessDataRead(Instance instance, Guid? dataId, object data) | ||
{ | ||
if (data is TModel model) | ||
{ | ||
await ProcessDataRead(instance, dataId, model); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task ProcessDataWrite(Instance instance, Guid? dataId, object data, object? previousData) | ||
{ | ||
if (data is TModel model) | ||
{ | ||
await ProcessDataWrite(instance, dataId, model, previousData as TModel); | ||
} | ||
} | ||
} |
Oops, something went wrong.