Skip to content

Commit 82cfcbb

Browse files
authored
Update CorrespondenceClient with API changes (#1083)
* Deserialises validation errors if present in reply from API server * WIP * Elevate `OrganisationOrPersonIdentifier` and friends out of Correspondence namespace * Removes Name/DisplayName props and other Correspondence tweaks as required * Fixes tests and refactors for a bit more sanity * Removes CorrespondenceRecipient * Renames Create->Parse for `Party` parsing * Convenience operators * Removes `Experimental` warning for Correspondence Client
1 parent b5a7f58 commit 82cfcbb

File tree

41 files changed

+802
-654
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+802
-654
lines changed

src/Altinn.App.Core/Altinn.App.Core.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
This class library holds all the core features used by a standard Altinn 3 App.
77
</Description>
88
<DebugType>portable</DebugType>
9-
<NoWarn>ALTINNAPP0200</NoWarn>
109
</PropertyGroup>
1110
<ItemGroup>
1211
<FrameworkReference Include="Microsoft.AspNetCore.App" />

src/Altinn.App.Core/Features/Correspondence/Extensions/NationalIdentityNumberExtensions.cs renamed to src/Altinn.App.Core/Extensions/NationalIdentityNumberExtensions.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Altinn.App.Core.Constants;
22
using Altinn.App.Core.Models;
33

4-
namespace Altinn.App.Core.Features.Correspondence.Extensions;
4+
namespace Altinn.App.Core.Extensions;
55

66
internal static class NationalIdentityNumberExtensions
77
{
@@ -12,4 +12,12 @@ public static string ToUrnFormattedString(this NationalIdentityNumber identityNu
1212
{
1313
return $"{AltinnUrns.PersonId}:{identityNumber}";
1414
}
15+
16+
/// <summary>
17+
/// Returns a string representation of the <see cref="NationalIdentityNumber"/>, prefixed with the <see cref="AltinnUrns.PersonId"/> URN value, if the value is not null.
18+
/// </summary>
19+
public static string? ToUrnFormattedString(this NationalIdentityNumber? identityNumber)
20+
{
21+
return identityNumber is null ? null : $"{AltinnUrns.PersonId}:{identityNumber}";
22+
}
1523
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Altinn.App.Core.Constants;
2+
using Altinn.App.Core.Models;
3+
4+
namespace Altinn.App.Core.Extensions;
5+
6+
internal static class OrganisationNumberExtensions
7+
{
8+
/// <summary>
9+
/// Returns a string representation of the <see cref="OrganisationNumber"/>, prefixed with the <see cref="AltinnUrns.OrganisationNumber"/> URN value
10+
/// </summary>
11+
public static string ToUrnFormattedString(this OrganisationNumber organisationNumber)
12+
{
13+
return $"{AltinnUrns.OrganisationNumber}:{organisationNumber.Get(OrganisationNumberFormat.Local)}";
14+
}
15+
16+
/// <summary>
17+
/// Returns a string representation of the <see cref="OrganisationNumber"/>, prefixed with the <see cref="AltinnUrns.OrganisationNumber"/> URN value, if the value is not null.
18+
/// </summary>
19+
public static string? ToUrnFormattedString(this OrganisationNumber? organisationNumber)
20+
{
21+
return organisationNumber is null
22+
? null
23+
: $"{AltinnUrns.OrganisationNumber}:{organisationNumber.Value.Get(OrganisationNumberFormat.Local)}";
24+
}
25+
}

src/Altinn.App.Core/Features/Correspondence/Builder/CorrespondenceAttachmentBuilder.cs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ namespace Altinn.App.Core.Features.Correspondence.Builder;
88
public class CorrespondenceAttachmentBuilder : ICorrespondenceAttachmentBuilder
99
{
1010
private string? _filename;
11-
private string? _name;
1211
private string? _sendersReference;
13-
private string? _dataType;
1412
private ReadOnlyMemory<byte>? _data;
1513
private bool? _isEncrypted;
1614
private CorrespondenceDataLocationType _dataLocationType =
@@ -24,37 +22,21 @@ private CorrespondenceAttachmentBuilder() { }
2422
public static ICorrespondenceAttachmentBuilderFilename Create() => new CorrespondenceAttachmentBuilder();
2523

2624
/// <inheritdoc/>
27-
public ICorrespondenceAttachmentBuilderName WithFilename(string filename)
25+
public ICorrespondenceAttachmentBuilderSendersReference WithFilename(string filename)
2826
{
2927
BuilderUtils.NotNullOrEmpty(filename, "Filename cannot be empty");
3028
_filename = filename;
3129
return this;
3230
}
3331

3432
/// <inheritdoc/>
35-
public ICorrespondenceAttachmentBuilderSendersReference WithName(string name)
36-
{
37-
BuilderUtils.NotNullOrEmpty(name, "Name cannot be empty");
38-
_name = name;
39-
return this;
40-
}
41-
42-
/// <inheritdoc/>
43-
public ICorrespondenceAttachmentBuilderDataType WithSendersReference(string sendersReference)
33+
public ICorrespondenceAttachmentBuilderData WithSendersReference(string sendersReference)
4434
{
4535
BuilderUtils.NotNullOrEmpty(sendersReference, "Senders reference cannot be empty");
4636
_sendersReference = sendersReference;
4737
return this;
4838
}
4939

50-
/// <inheritdoc/>
51-
public ICorrespondenceAttachmentBuilderData WithDataType(string dataType)
52-
{
53-
BuilderUtils.NotNullOrEmpty(dataType, "Data type cannot be empty");
54-
_dataType = dataType;
55-
return this;
56-
}
57-
5840
/// <inheritdoc/>
5941
public ICorrespondenceAttachmentBuilder WithData(ReadOnlyMemory<byte> data)
6042
{
@@ -81,17 +63,13 @@ public ICorrespondenceAttachmentBuilder WithDataLocationType(CorrespondenceDataL
8163
public CorrespondenceAttachment Build()
8264
{
8365
BuilderUtils.NotNullOrEmpty(_filename);
84-
BuilderUtils.NotNullOrEmpty(_name);
8566
BuilderUtils.NotNullOrEmpty(_sendersReference);
86-
BuilderUtils.NotNullOrEmpty(_dataType);
8767
BuilderUtils.NotNullOrEmpty(_data);
8868

8969
return new CorrespondenceAttachment
9070
{
9171
Filename = _filename,
92-
Name = _name,
9372
SendersReference = _sendersReference,
94-
DataType = _dataType,
9573
Data = _data.Value,
9674
IsEncrypted = _isEncrypted,
9775
DataLocationType = _dataLocationType,

src/Altinn.App.Core/Features/Correspondence/Builder/CorrespondenceNotificationOverrideBuilder.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Altinn.App.Core.Features.Correspondence.Models;
2+
using Altinn.App.Core.Models;
23

34
namespace Altinn.App.Core.Features.Correspondence.Builder;
45

@@ -7,7 +8,7 @@ namespace Altinn.App.Core.Features.Correspondence.Builder;
78
/// </summary>
89
public class CorrespondenceNotificationOverrideBuilder : ICorrespondenceNotificationOverrideBuilder
910
{
10-
private string? _recipientToOverride;
11+
private OrganisationOrPersonIdentifier? _recipientToOverride;
1112
private List<CorrespondenceNotificationRecipient>? _correspondenceNotificationRecipients;
1213

1314
private CorrespondenceNotificationOverrideBuilder() { }
@@ -21,6 +22,31 @@ public static ICorrespondenceNotificationOverrideBuilder Create() =>
2122

2223
/// <inheritdoc/>
2324
public ICorrespondenceNotificationOverrideBuilder WithRecipientToOverride(string recipientToOverride)
25+
{
26+
_recipientToOverride = OrganisationOrPersonIdentifier.Parse(recipientToOverride);
27+
return this;
28+
}
29+
30+
/// <inheritdoc />
31+
public ICorrespondenceNotificationOverrideBuilder WithRecipientToOverride(OrganisationNumber recipientToOverride)
32+
{
33+
_recipientToOverride = OrganisationOrPersonIdentifier.Create(recipientToOverride);
34+
return this;
35+
}
36+
37+
/// <inheritdoc />
38+
public ICorrespondenceNotificationOverrideBuilder WithRecipientToOverride(
39+
NationalIdentityNumber recipientToOverride
40+
)
41+
{
42+
_recipientToOverride = OrganisationOrPersonIdentifier.Create(recipientToOverride);
43+
return this;
44+
}
45+
46+
/// <inheritdoc />
47+
public ICorrespondenceNotificationOverrideBuilder WithRecipientToOverride(
48+
OrganisationOrPersonIdentifier recipientToOverride
49+
)
2450
{
2551
_recipientToOverride = recipientToOverride;
2652
return this;

src/Altinn.App.Core/Features/Correspondence/Builder/CorrespondenceRequestBuilder.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,30 +66,42 @@ public ICorrespondenceRequestBuilderRecipients WithSendersReference(string sende
6666
}
6767

6868
/// <inheritdoc/>
69-
public ICorrespondenceRequestBuilderAllowSystemDeleteAfter WithRecipient(OrganisationOrPersonIdentifier recipient)
69+
public ICorrespondenceRequestBuilderContent WithRecipient(OrganisationOrPersonIdentifier recipient)
7070
{
7171
BuilderUtils.NotNullOrEmpty(recipient, "Recipients cannot be empty");
7272
return WithRecipients([recipient]);
7373
}
7474

7575
/// <inheritdoc/>
76-
public ICorrespondenceRequestBuilderAllowSystemDeleteAfter WithRecipient(string recipient)
76+
public ICorrespondenceRequestBuilderContent WithRecipient(OrganisationNumber organisation)
77+
{
78+
BuilderUtils.NotNullOrEmpty(organisation, "Recipients cannot be empty");
79+
return WithRecipients([OrganisationOrPersonIdentifier.Create(organisation)]);
80+
}
81+
82+
/// <inheritdoc/>
83+
public ICorrespondenceRequestBuilderContent WithRecipient(NationalIdentityNumber person)
84+
{
85+
BuilderUtils.NotNullOrEmpty(person, "Recipients cannot be empty");
86+
return WithRecipients([OrganisationOrPersonIdentifier.Create(person)]);
87+
}
88+
89+
/// <inheritdoc/>
90+
public ICorrespondenceRequestBuilderContent WithRecipient(string recipient)
7791
{
7892
BuilderUtils.NotNullOrEmpty(recipient, "Recipients cannot be empty");
7993
return WithRecipients([recipient]);
8094
}
8195

8296
/// <inheritdoc/>
83-
public ICorrespondenceRequestBuilderAllowSystemDeleteAfter WithRecipients(IEnumerable<string> recipients)
97+
public ICorrespondenceRequestBuilderContent WithRecipients(IEnumerable<string> recipients)
8498
{
8599
BuilderUtils.NotNullOrEmpty(recipients);
86100
return WithRecipients(recipients.Select(OrganisationOrPersonIdentifier.Parse));
87101
}
88102

89103
/// <inheritdoc/>
90-
public ICorrespondenceRequestBuilderAllowSystemDeleteAfter WithRecipients(
91-
IEnumerable<OrganisationOrPersonIdentifier> recipients
92-
)
104+
public ICorrespondenceRequestBuilderContent WithRecipients(IEnumerable<OrganisationOrPersonIdentifier> recipients)
93105
{
94106
BuilderUtils.NotNullOrEmpty(recipients, "Recipients cannot be empty");
95107
_recipients ??= [];
@@ -98,7 +110,7 @@ IEnumerable<OrganisationOrPersonIdentifier> recipients
98110
}
99111

100112
/// <inheritdoc/>
101-
public ICorrespondenceRequestBuilderContent WithAllowSystemDeleteAfter(DateTimeOffset allowSystemDeleteAfter)
113+
public ICorrespondenceRequestBuilder WithAllowSystemDeleteAfter(DateTimeOffset allowSystemDeleteAfter)
102114
{
103115
BuilderUtils.NotNullOrEmpty(allowSystemDeleteAfter, "AllowSystemDeleteAfter cannot be empty");
104116
_allowSystemDeleteAfter = allowSystemDeleteAfter;
@@ -244,12 +256,7 @@ public ICorrespondenceRequestBuilder WithNotification(CorrespondenceNotification
244256
/// <inheritdoc/>
245257
public ICorrespondenceRequestBuilder WithNotificationIfConfigured(CorrespondenceNotification? notification)
246258
{
247-
if (notification is not null)
248-
{
249-
return WithNotification(notification);
250-
}
251-
252-
return this;
259+
return notification is not null ? WithNotification(notification) : this;
253260
}
254261

255262
/// <inheritdoc/>
@@ -307,7 +314,6 @@ public CorrespondenceRequest Build()
307314
BuilderUtils.NotNullOrEmpty(_sender);
308315
BuilderUtils.NotNullOrEmpty(_sendersReference);
309316
BuilderUtils.NotNullOrEmpty(_content);
310-
BuilderUtils.NotNullOrEmpty(_allowSystemDeleteAfter);
311317
BuilderUtils.NotNullOrEmpty(_recipients);
312318

313319
return new CorrespondenceRequest
@@ -316,7 +322,7 @@ public CorrespondenceRequest Build()
316322
Sender = _sender.Value,
317323
SendersReference = _sendersReference,
318324
Content = _content with { Attachments = _contentAttachments },
319-
AllowSystemDeleteAfter = _allowSystemDeleteAfter.Value,
325+
AllowSystemDeleteAfter = _allowSystemDeleteAfter,
320326
DueDateTime = _dueDateTime,
321327
Recipients = _recipients,
322328
RequestedPublishTime = _requestedPublishTime,

src/Altinn.App.Core/Features/Correspondence/Builder/ICorrespondenceAttachmentBuilder.cs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Net.Mime;
21
using Altinn.App.Core.Features.Correspondence.Models;
32

43
namespace Altinn.App.Core.Features.Correspondence.Builder;
@@ -12,19 +11,7 @@ public interface ICorrespondenceAttachmentBuilderFilename
1211
/// Sets the filename of the attachment.
1312
/// </summary>
1413
/// <param name="filename">The attachment filename</param>
15-
ICorrespondenceAttachmentBuilderName WithFilename(string filename);
16-
}
17-
18-
/// <summary>
19-
/// Indicates that the <see cref="CorrespondenceAttachmentBuilder"/> instance is on the <see cref="CorrespondenceAttachment.Name"/> step.
20-
/// </summary>
21-
public interface ICorrespondenceAttachmentBuilderName
22-
{
23-
/// <summary>
24-
/// Sets the display name of the attachment.
25-
/// </summary>
26-
/// <param name="name">The display name</param>
27-
ICorrespondenceAttachmentBuilderSendersReference WithName(string name);
14+
ICorrespondenceAttachmentBuilderSendersReference WithFilename(string filename);
2815
}
2916

3017
/// <summary>
@@ -36,20 +23,7 @@ public interface ICorrespondenceAttachmentBuilderSendersReference
3623
/// Sets the senders reference for the attachment.
3724
/// </summary>
3825
/// <param name="sendersReference">The reference value</param>
39-
ICorrespondenceAttachmentBuilderDataType WithSendersReference(string sendersReference);
40-
}
41-
42-
/// <summary>
43-
/// Indicates that the <see cref="CorrespondenceAttachmentBuilder"/> instance is on the <see cref="CorrespondenceAttachment.DataType"/> step.
44-
/// </summary>
45-
public interface ICorrespondenceAttachmentBuilderDataType
46-
{
47-
/// <summary>
48-
/// Sets the data type of the attachment in MIME format.
49-
/// </summary>
50-
/// <remarks>See <see cref="MediaTypeNames"/></remarks>
51-
/// <param name="dataType">The MIME type of the attachment</param>
52-
ICorrespondenceAttachmentBuilderData WithDataType(string dataType);
26+
ICorrespondenceAttachmentBuilderData WithSendersReference(string sendersReference);
5327
}
5428

5529
/// <summary>
@@ -69,9 +43,7 @@ public interface ICorrespondenceAttachmentBuilderData
6943
/// </summary>
7044
public interface ICorrespondenceAttachmentBuilder
7145
: ICorrespondenceAttachmentBuilderFilename,
72-
ICorrespondenceAttachmentBuilderName,
7346
ICorrespondenceAttachmentBuilderSendersReference,
74-
ICorrespondenceAttachmentBuilderDataType,
7547
ICorrespondenceAttachmentBuilderData
7648
{
7749
/// <summary>

src/Altinn.App.Core/Features/Correspondence/Builder/ICorrespondenceNotificationOverrideBuilder.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Altinn.App.Core.Features.Correspondence.Models;
2+
using Altinn.App.Core.Models;
23

34
namespace Altinn.App.Core.Features.Correspondence.Builder;
45

@@ -13,6 +14,28 @@ public interface ICorrespondenceNotificationOverrideBuilder
1314
/// <param name="recipientToOverride">The recipient to override notifications for. Organization number / national identifier</param>
1415
public ICorrespondenceNotificationOverrideBuilder WithRecipientToOverride(string recipientToOverride);
1516

17+
/// <summary>
18+
/// Sets the recipient to override for the correspondence notification.
19+
/// </summary>
20+
/// <param name="recipientToOverride">The recipient to override notifications for.</param>
21+
public ICorrespondenceNotificationOverrideBuilder WithRecipientToOverride(OrganisationNumber recipientToOverride);
22+
23+
/// <summary>
24+
/// Sets the recipient to override for the correspondence notification.
25+
/// </summary>
26+
/// <param name="recipientToOverride">The recipient to override notifications for.</param>
27+
public ICorrespondenceNotificationOverrideBuilder WithRecipientToOverride(
28+
NationalIdentityNumber recipientToOverride
29+
);
30+
31+
/// <summary>
32+
/// Sets the recipient to override for the correspondence notification.
33+
/// </summary>
34+
/// <param name="recipientToOverride">The recipient to override notifications for.</param>
35+
public ICorrespondenceNotificationOverrideBuilder WithRecipientToOverride(
36+
OrganisationOrPersonIdentifier recipientToOverride
37+
);
38+
1639
/// <summary>
1740
/// Sets the custom recipients to override the default recipient.
1841
/// </summary>

0 commit comments

Comments
 (0)