Skip to content

Commit 351ad4f

Browse files
committed
Revert "Experiment to use REST instead of Form endpoints"
This reverts commit dbd86ab.
1 parent dc7485a commit 351ad4f

File tree

5 files changed

+2
-188
lines changed

5 files changed

+2
-188
lines changed

src/Altinn.App.Core/Features/Correspondence/CorrespondenceClient.cs

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
using System.Diagnostics;
22
using System.Net;
33
using System.Net.Http.Headers;
4-
using System.Net.Http.Json;
54
using System.Text.Json;
65
using Altinn.App.Core.Configuration;
76
using Altinn.App.Core.Constants;
87
using Altinn.App.Core.Features.Correspondence.Exceptions;
98
using Altinn.App.Core.Features.Correspondence.Models;
10-
using Altinn.App.Core.Features.Correspondence.Models.Response;
119
using Altinn.App.Core.Models;
1210
using Microsoft.AspNetCore.Mvc;
1311
using Microsoft.Extensions.Logging;
@@ -52,57 +50,6 @@ public async Task<SendCorrespondenceResponse> Send(
5250

5351
try
5452
{
55-
if (
56-
payload.CorrespondenceRequest.Content.Attachments.Count > 0
57-
&& payload.CorrespondenceRequest.Content.Attachments.All(a => a is CorrespondenceStreamedAttachment)
58-
)
59-
{
60-
var pollingJobs = new List<Task>();
61-
var premadeAttachments = new List<Guid>();
62-
foreach (
63-
CorrespondenceStreamedAttachment attachment in payload.CorrespondenceRequest.Content.Attachments
64-
)
65-
{
66-
var initializeAttachmentPayload = new AttachmentPayload
67-
{
68-
DisplayName = attachment.Filename,
69-
FileName = attachment.Filename,
70-
IsEncrypted = attachment.IsEncrypted ?? false,
71-
ResourceId = payload.CorrespondenceRequest.ResourceId,
72-
SendersReference = payload.CorrespondenceRequest.SendersReference + " - " + attachment.Filename,
73-
};
74-
var initializeAttachmentRequest = await AuthenticatedHttpRequestFactory(
75-
method: HttpMethod.Post,
76-
uri: GetUri("attachment"),
77-
content: JsonContent.Create(initializeAttachmentPayload),
78-
payload: payload
79-
);
80-
var initializeAttachmentResponse = await HandleServerCommunication<SendCorrespondenceResponse>(
81-
initializeAttachmentRequest,
82-
cancellationToken
83-
);
84-
var attachmentId = await initializeAttachmentRequest.Content.ReadAsStringAsync(cancellationToken);
85-
attachmentId = attachmentId.Trim('"');
86-
var attachmentDataContent = new StreamContent(attachment.Data);
87-
attachmentDataContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
88-
var uploadAttachmentRequest = await AuthenticatedHttpRequestFactory(
89-
method: HttpMethod.Post,
90-
uri: GetUri("attachment/upload"),
91-
content: attachmentDataContent,
92-
payload: payload
93-
);
94-
var uploadAttachmentResponse = await HandleServerCommunication<SendCorrespondenceResponse>(
95-
uploadAttachmentRequest,
96-
cancellationToken
97-
);
98-
if (Guid.TryParse(attachmentId, out var guidId))
99-
{
100-
pollingJobs.Add(PollAttachmentStatus(guidId, payload, cancellationToken));
101-
}
102-
}
103-
await Task.WhenAll(pollingJobs);
104-
payload.CorrespondenceRequest.ExistingAttachments = premadeAttachments;
105-
}
10653
using MultipartFormDataContent content = payload.CorrespondenceRequest.Serialise();
10754
using HttpRequestMessage request = await AuthenticatedHttpRequestFactory(
10855
method: HttpMethod.Post,
@@ -141,55 +88,6 @@ CorrespondenceStreamedAttachment attachment in payload.CorrespondenceRequest.Con
14188
}
14289
}
14390

144-
/// <inheritdoc />
145-
private async Task PollAttachmentStatus(
146-
Guid attachmentId,
147-
CorrespondencePayloadBase payload,
148-
CancellationToken cancellationToken
149-
)
150-
{
151-
const int maxAttempts = 3;
152-
const int delaySeconds = 5;
153-
154-
for (int attempt = 1; attempt <= maxAttempts; attempt++)
155-
{
156-
await Task.Delay(TimeSpan.FromSeconds(delaySeconds), cancellationToken);
157-
158-
try
159-
{
160-
var statusResponse = await AuthenticatedHttpRequestFactory(
161-
method: HttpMethod.Get,
162-
uri: GetUri($"attachment/{attachmentId}"),
163-
content: null,
164-
payload: payload
165-
);
166-
167-
var statusContent = await statusResponse.Content.ReadFromJsonAsync<AttachmentOverview>(
168-
cancellationToken
169-
);
170-
if (statusContent.Status == "Published")
171-
{
172-
break;
173-
}
174-
}
175-
catch (Exception ex)
176-
{
177-
// Log the exception
178-
if (attempt == maxAttempts)
179-
{
180-
// Handle or rethrow the exception after all attempts failed
181-
throw;
182-
}
183-
}
184-
throw new CorrespondenceRequestException(
185-
$"Failure when uploading attachment. Attachment was not published in time. ",
186-
null,
187-
HttpStatusCode.InternalServerError,
188-
"Polling failed"
189-
);
190-
}
191-
}
192-
19391
/// <inheritdoc/>
19492
public async Task<GetCorrespondenceStatusResponse> GetStatus(
19593
GetCorrespondenceStatusPayload payload,

src/Altinn.App.Core/Features/Correspondence/Models/AttachmentPayload.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Altinn.App.Core/Features/Correspondence/Models/CorrespondenceRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public sealed record CorrespondenceRequest : MultipartCorrespondenceItem
308308
/// <summary>
309309
/// Existing attachments that should be added to the correspondence.
310310
/// </summary>
311-
public IReadOnlyList<Guid>? ExistingAttachments { get; set; }
311+
public IReadOnlyList<Guid>? ExistingAttachments { get; init; }
312312

313313
/// <summary>
314314
/// Serialises the entire <see cref="CorrespondenceRequest"/> object to a provided <see cref="MultipartFormDataContent"/> instance.

src/Altinn.App.Core/Features/Correspondence/Models/Response/AttachmentOverview.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -724,14 +724,6 @@ namespace Altinn.App.Core.Features.Correspondence
724724
}
725725
namespace Altinn.App.Core.Features.Correspondence.Models
726726
{
727-
public sealed class AttachmentPayload : System.IEquatable<Altinn.App.Core.Features.Correspondence.Models.AttachmentPayload>
728-
{
729-
public AttachmentPayload() { }
730-
public string? DisplayName { get; set; }
731-
public string? FileName { get; set; }
732-
public bool IsEncrypted { get; set; }
733-
public string SendersReference { get; set; }
734-
}
735727
public abstract class CorrespondenceAttachment : Altinn.App.Core.Features.Correspondence.Models.MultipartCorrespondenceItem, System.IEquatable<Altinn.App.Core.Features.Correspondence.Models.CorrespondenceAttachment>
736728
{
737729
protected CorrespondenceAttachment() { }
@@ -1017,7 +1009,7 @@ namespace Altinn.App.Core.Features.Correspondence.Models
10171009
public required System.DateTimeOffset? AllowSystemDeleteAfter { get; init; }
10181010
public required Altinn.App.Core.Features.Correspondence.Models.CorrespondenceContent Content { get; init; }
10191011
public System.DateTimeOffset? DueDateTime { get; init; }
1020-
public System.Collections.Generic.IReadOnlyList<System.Guid>? ExistingAttachments { get; set; }
1012+
public System.Collections.Generic.IReadOnlyList<System.Guid>? ExistingAttachments { get; init; }
10211013
public System.Collections.Generic.IReadOnlyList<Altinn.App.Core.Features.Correspondence.Models.CorrespondenceExternalReference>? ExternalReferences { get; init; }
10221014
public bool? IgnoreReservation { get; init; }
10231015
public bool? IsConfirmationNeeded { get; init; }
@@ -1139,19 +1131,6 @@ namespace Altinn.App.Core.Features.Correspondence.Models
11391131
public required System.Collections.Generic.IReadOnlyList<Altinn.App.Core.Features.Correspondence.Models.CorrespondenceDetailsResponse> Correspondences { get; init; }
11401132
}
11411133
}
1142-
namespace Altinn.App.Core.Features.Correspondence.Models.Response
1143-
{
1144-
public class AttachmentOverview
1145-
{
1146-
public AttachmentOverview() { }
1147-
public System.Guid AttachmentId { get; set; }
1148-
public System.Collections.Generic.List<System.Guid> CorrespondenceIds { get; set; }
1149-
public string DataType { get; set; }
1150-
public string Status { get; set; }
1151-
public System.DateTimeOffset StatusChanged { get; set; }
1152-
public string StatusText { get; set; }
1153-
}
1154-
}
11551134
namespace Altinn.App.Core.Features.DataLists
11561135
{
11571136
public class DataListsFactory

0 commit comments

Comments
 (0)