diff --git a/src/Altinn.Correspondence.API/Mappers/LegacyCorrespondenceOverviewMapper.cs b/src/Altinn.Correspondence.API/Mappers/LegacyCorrespondenceOverviewMapper.cs
index 85f734ef..456c3b63 100644
--- a/src/Altinn.Correspondence.API/Mappers/LegacyCorrespondenceOverviewMapper.cs
+++ b/src/Altinn.Correspondence.API/Mappers/LegacyCorrespondenceOverviewMapper.cs
@@ -20,7 +20,12 @@ internal static LegacyCorrespondenceOverviewExt MapToExternal(LegacyGetCorrespon
Created = correspondenceOverview.Created,
Notifications = correspondenceOverview.Notifications,
Recipient = correspondenceOverview.Recipient,
- Content = CorrespondenceContentMapper.MapToExternal(correspondenceOverview.Content),
+ Content = null,
+ Attachments = CorrespondenceAttachmentMapper.MapListToExternal(correspondenceOverview.Attachments),
+ Language = correspondenceOverview.Language,
+ MessageTitle = correspondenceOverview.MessageTitle,
+ MessageSummary = correspondenceOverview.MessageSummary,
+ MessageBody = correspondenceOverview.MessageBody,
ReplyOptions = CorrespondenceReplyOptionsMapper.MapListToExternal(correspondenceOverview.ReplyOptions),
ExternalReferences = ExternalReferenceMapper.MapListToExternal(correspondenceOverview.ExternalReferences),
ResourceId = correspondenceOverview.ResourceId.ToString(),
@@ -36,6 +41,7 @@ internal static LegacyCorrespondenceOverviewExt MapToExternal(LegacyGetCorrespon
Archived = correspondenceOverview.Archived,
MinimumAuthenticationLevel = correspondenceOverview.MinimumAuthenticationLevel,
AuthorizedForSign = correspondenceOverview.AuthorizedForSign,
+ InstanceOwnerPartyId = correspondenceOverview.InstanceOwnerPartyId
};
return Correspondence;
}
diff --git a/src/Altinn.Correspondence.API/Models/LegacyCorrespondenceOverviewExt.cs b/src/Altinn.Correspondence.API/Models/LegacyCorrespondenceOverviewExt.cs
index 853dadd6..90e4afd6 100644
--- a/src/Altinn.Correspondence.API/Models/LegacyCorrespondenceOverviewExt.cs
+++ b/src/Altinn.Correspondence.API/Models/LegacyCorrespondenceOverviewExt.cs
@@ -38,5 +38,45 @@ public class LegacyCorrespondenceOverviewExt : CorrespondenceOverviewExt
///
[JsonPropertyName("archived")]
public DateTimeOffset? Archived { get; set; }
+
+ ///
+ /// Gets or sets the language of the correspondence, specified according to ISO 639-1
+ ///
+ [JsonPropertyName("language")]
+ [ISO6391]
+ public required string Language { get; set; }
+
+ ///
+ /// Gets or sets the correspondence message title. Subject.
+ ///
+ ///
+ /// TODO: Length restriction?
+ ///
+ [JsonPropertyName("messageTitle")]
+ public required string MessageTitle { get; set; }
+
+ ///
+ /// Gets or sets a summary text of the correspondence.
+ ///
+ ///
+ /// TODO: Length restriction?
+ ///
+ [JsonPropertyName("messageSummary")]
+ public required string MessageSummary { get; set; }
+
+ ///
+ /// Gets or sets the main body of the correspondence.
+ ///
+ [JsonPropertyName("messageBody")]
+ public required string MessageBody { get; set; }
+
+ [JsonPropertyName("attachments")]
+ public required new List Attachments { get; set; }
+
+ ///
+ /// Instance owner party id
+ ///
+ [JsonPropertyName("instanceOwnerPartyId")]
+ public int InstanceOwnerPartyId { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Altinn.Correspondence.Application/GetCorespondences/LegacyGetCorrespondencesHandler.cs b/src/Altinn.Correspondence.Application/GetCorespondences/LegacyGetCorrespondencesHandler.cs
index 3878e242..8802a10e 100644
--- a/src/Altinn.Correspondence.Application/GetCorespondences/LegacyGetCorrespondencesHandler.cs
+++ b/src/Altinn.Correspondence.Application/GetCorespondences/LegacyGetCorrespondencesHandler.cs
@@ -6,6 +6,8 @@
using Altinn.Correspondence.Repositories;
using OneOf;
+using Microsoft.Extensions.Logging;
+
namespace Altinn.Correspondence.Application.GetCorrespondences;
public class LegacyGetCorrespondencesHandler : IHandler
@@ -16,10 +18,11 @@ public class LegacyGetCorrespondencesHandler : IHandler _logger;
private record ResourceOwner(string OrgNumber, Party? Party);
- public LegacyGetCorrespondencesHandler(IAltinnAuthorizationService altinnAuthorizationService, IAltinnAccessManagementService altinnAccessManagement, ICorrespondenceRepository correspondenceRepository, UserClaimsHelper userClaimsHelper, IAltinnRegisterService altinnRegisterService, IResourceRightsService resourceRightsService)
+ public LegacyGetCorrespondencesHandler(IAltinnAuthorizationService altinnAuthorizationService, IAltinnAccessManagementService altinnAccessManagement, ICorrespondenceRepository correspondenceRepository, UserClaimsHelper userClaimsHelper, IAltinnRegisterService altinnRegisterService, IResourceRightsService resourceRightsService, ILogger logger)
{
_altinnAuthorizationService = altinnAuthorizationService;
_altinnAccessManagementService = altinnAccessManagement;
@@ -27,6 +30,7 @@ public LegacyGetCorrespondencesHandler(IAltinnAuthorizationService altinnAuthori
_userClaimsHelper = userClaimsHelper;
_altinnRegisterService = altinnRegisterService;
_resourceRightsService = resourceRightsService;
+ _logger = logger;
}
public async Task> Process(LegacyGetCorrespondencesRequest request, CancellationToken cancellationToken)
@@ -79,6 +83,7 @@ public async Task> Process(Legacy
List correspondenceItems = new List();
var resourceOwners = new List();
+
foreach (var orgNr in correspondences.Item1.Select(c => c.Sender).Distinct().ToList())
{
try
@@ -91,16 +96,31 @@ public async Task> Process(Legacy
resourceOwners.Add(new ResourceOwner(orgNr, null));
}
}
+ var recipientDetails = new List();
+ foreach (var orgNr in correspondences.Item1.Select(c => c.Recipient).Distinct().ToList())
+ {
+ try
+ {
+ var recipientParty = await _altinnRegisterService.LookUpPartyById(orgNr, cancellationToken);
+ recipientDetails.Add(new ResourceOwner(orgNr, recipientParty));
+ }
+ catch (Exception e)
+ {
+ _logger.LogError(e, "Failed to lookup recipient party for orgNr: {OrgNr}", orgNr);
+ recipientDetails.Add(new ResourceOwner(orgNr, null));
+ }
+ }
foreach (var correspondence in correspondences.Item1)
{
var purgedStatus = correspondence.GetPurgedStatus();
var owner = resourceOwners.SingleOrDefault(r => r.OrgNumber == correspondence.Sender)?.Party;
+ var recipient = recipientDetails.SingleOrDefault(r => r.OrgNumber == correspondence.Recipient)?.Party;
correspondenceItems.Add(
new LegacyCorrespondenceItem()
{
Altinn2CorrespondenceId = correspondence.Altinn2CorrespondenceId,
ServiceOwnerName = owner.Name,
- InstanceOwnerPartyId = owner.PartyId,
+ InstanceOwnerPartyId = recipient?.PartyId ?? 0,
MessageTitle = correspondence.Content.MessageTitle,
Status = correspondence.GetLatestStatusWithoutPurged().Status,
CorrespondenceId = correspondence.Id,
@@ -108,8 +128,9 @@ public async Task> Process(Legacy
Published = correspondence.Published,
PurgedStatus = purgedStatus?.Status,
Purged = purgedStatus?.StatusChanged,
- DueDate = correspondence.DueDateTime,
+ DueDateTime = correspondence.DueDateTime,
Archived = correspondence.Statuses?.FirstOrDefault(s => s.Status == CorrespondenceStatus.Archived)?.StatusChanged,
+ Confirmed = correspondence.Statuses?.FirstOrDefault(s => s.Status == CorrespondenceStatus.Confirmed)?.StatusChanged,
MessageSender = correspondence.MessageSender
}
);
diff --git a/src/Altinn.Correspondence.Application/GetCorespondences/LegacyGetCorrespondencesResponse.cs b/src/Altinn.Correspondence.Application/GetCorespondences/LegacyGetCorrespondencesResponse.cs
index 6e72e734..f26afe5e 100644
--- a/src/Altinn.Correspondence.Application/GetCorespondences/LegacyGetCorrespondencesResponse.cs
+++ b/src/Altinn.Correspondence.Application/GetCorespondences/LegacyGetCorrespondencesResponse.cs
@@ -22,8 +22,9 @@ public class LegacyCorrespondenceItem
public CorrespondenceStatus? PurgedStatus { get; set; }
public DateTimeOffset? Purged { get; set; }
public int InstanceOwnerPartyId { get; set; }
- public DateTimeOffset? DueDate { get; set; }
+ public DateTimeOffset? DueDateTime { get; set; }
public DateTimeOffset? Archived { get; set; }
public string? MessageSender { get; set; }
+ public DateTimeOffset? Confirmed { get; set; }
}
}
diff --git a/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/LegacyGetCorrespondenceOverviewHandler.cs b/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/LegacyGetCorrespondenceOverviewHandler.cs
index f515af68..c49327e7 100644
--- a/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/LegacyGetCorrespondenceOverviewHandler.cs
+++ b/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/LegacyGetCorrespondenceOverviewHandler.cs
@@ -16,7 +16,6 @@ public class LegacyGetCorrespondenceOverviewHandler : IHandler _logger;
public LegacyGetCorrespondenceOverviewHandler(IAltinnAccessManagementService altinnAccessManagementService, IAltinnAuthorizationService altinnAuthorizationService, IAltinnRegisterService altinnRegisterService, ICorrespondenceRepository CorrespondenceRepository, ICorrespondenceStatusRepository correspondenceStatusRepository, UserClaimsHelper userClaimsHelper, ILogger logger)
@@ -26,7 +25,6 @@ public LegacyGetCorrespondenceOverviewHandler(IAltinnAccessManagementService alt
_altinnRegisterService = altinnRegisterService;
_correspondenceRepository = CorrespondenceRepository;
_correspondenceStatusRepository = correspondenceStatusRepository;
- _userClaimsHelper = userClaimsHelper;
_logger = logger;
}
@@ -100,18 +98,26 @@ await _correspondenceStatusRepository.AddCorrespondenceStatus(new Correspondence
});
}
}
-
+ var resourceOwnerParty = await _altinnRegisterService.LookUpPartyById(correspondence.Sender, cancellationToken);
+ if (resourceOwnerParty == null)
+ {
+ return Errors.CouldNotFindOrgNo;
+ }
var response = new LegacyGetCorrespondenceOverviewResponse
{
CorrespondenceId = correspondence.Id,
- Content = correspondence.Content,
+ Attachments = correspondence.Content!.Attachments ?? new List(),
+ Language = correspondence.Content!.Language,
+ MessageTitle = correspondence.Content!.MessageTitle,
+ MessageSummary = correspondence.Content!.MessageSummary,
+ MessageBody = correspondence.Content!.MessageBody,
Status = latestStatus.Status,
StatusText = latestStatus.StatusText,
StatusChanged = latestStatus.StatusChanged,
ResourceId = correspondence.ResourceId,
Sender = correspondence.Sender,
SendersReference = correspondence.SendersReference,
- MessageSender = correspondence.MessageSender ?? string.Empty,
+ MessageSender = String.IsNullOrWhiteSpace(correspondence.MessageSender) ? resourceOwnerParty.Name : correspondence.MessageSender,
Created = correspondence.Created,
Recipient = correspondence.Recipient,
ReplyOptions = correspondence.ReplyOptions ?? new List(),
@@ -124,11 +130,14 @@ await _correspondenceStatusRepository.AddCorrespondenceStatus(new Correspondence
Published = correspondence.Published,
IsConfirmationNeeded = correspondence.IsConfirmationNeeded,
MinimumAuthenticationLevel = (int)minimumAuthLevel,
+ AuthorizedForWrite = true,
AuthorizedForSign = true,
DueDateTime = correspondence.DueDateTime,
AllowDelete = true,
Archived = correspondence.Statuses?.FirstOrDefault(s => s.Status == CorrespondenceStatus.Archived)?.StatusChanged,
- PropertyList = correspondence.PropertyList ?? new Dictionary()
+ Confirmed = correspondence.Statuses?.FirstOrDefault(s => s.Status == CorrespondenceStatus.Confirmed)?.StatusChanged,
+ PropertyList = correspondence.PropertyList ?? new Dictionary(),
+ InstanceOwnerPartyId = resourceOwnerParty.PartyId
};
return response;
}
diff --git a/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/LegacyGetCorrespondenceOverviewResponse.cs b/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/LegacyGetCorrespondenceOverviewResponse.cs
index df98e8e6..5e61a02c 100644
--- a/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/LegacyGetCorrespondenceOverviewResponse.cs
+++ b/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/LegacyGetCorrespondenceOverviewResponse.cs
@@ -3,12 +3,64 @@
namespace Altinn.Correspondence.Application.GetCorrespondenceOverview;
-public class LegacyGetCorrespondenceOverviewResponse : GetCorrespondenceOverviewResponse
+public class LegacyGetCorrespondenceOverviewResponse
{
public bool AllowDelete { get; set; }
public bool AuthorizedForWrite { get; set; }
public bool AuthorizedForSign { get; set; }
public DateTimeOffset? Archived { get; set; }
+ public DateTimeOffset? Confirmed { get; set; }
public int MinimumAuthenticationLevel { get; set; }
-}
+ public int InstanceOwnerPartyId { get; set; }
+ public required Guid CorrespondenceId { get; set; }
+ public required CorrespondenceStatus Status { get; set; }
+
+ public required string StatusText { get; set; }
+
+ public required DateTimeOffset StatusChanged { get; set; }
+
+ public string SendersReference { get; set; } = string.Empty;
+
+ public string Sender { get; set; } = string.Empty;
+
+ public string MessageSender { get; set; } = string.Empty;
+
+ public DateTimeOffset Created { get; set; }
+
+ public string Recipient { get; set; } = string.Empty;
+
+ public required string Language { get; set; }
+
+ public required string MessageTitle { get; set; }
+
+ public required string MessageSummary { get; set; }
+
+ public required string MessageBody { get; set; }
+
+ public required List Attachments { get; set; }
+
+ public List ReplyOptions { get; set; } = new List();
+
+ public List Notifications { get; set; } = new List();
+
+ public List ExternalReferences { get; set; } = new List();
+
+ public string ResourceId { get; set; }
+
+ public DateTimeOffset RequestedPublishTime { get; set; }
+
+ public bool IgnoreReservation { get; set; }
+
+ public bool? MarkedUnread { get; set; }
+
+ public DateTimeOffset? AllowSystemDeleteAfter { get; set; }
+
+ public DateTimeOffset? DueDateTime { get; set; }
+
+ public Dictionary PropertyList { get; set; } = new Dictionary();
+
+ public DateTimeOffset? Published { get; set; }
+
+ public bool IsConfirmationNeeded { get; set; }
+}
\ No newline at end of file