Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to legacy response models #435

Merged
merged 11 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -36,6 +41,7 @@ internal static LegacyCorrespondenceOverviewExt MapToExternal(LegacyGetCorrespon
Archived = correspondenceOverview.Archived,
MinimumAuthenticationLevel = correspondenceOverview.MinimumAuthenticationLevel,
AuthorizedForSign = correspondenceOverview.AuthorizedForSign,
InstanceOwnerPartyId = correspondenceOverview.InstanceOwnerPartyId
};
return Correspondence;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,44 @@ public class LegacyCorrespondenceOverviewExt : CorrespondenceOverviewExt
/// </summary>
[JsonPropertyName("archived")]
public DateTimeOffset? Archived { get; set; }

/// <summary>
/// Gets or sets the language of the correspondence, specified according to ISO 639-1
/// </summary>
[JsonPropertyName("language")]
[ISO6391]
public required string Language { get; set; }

/// <summary>
/// Gets or sets the correspondence message title. Subject.
/// </summary>
/// <remarks>
/// TODO: Length restriction?
/// </remarks>
[JsonPropertyName("messageTitle")]
public required string MessageTitle { get; set; }
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets or sets a summary text of the correspondence.
/// </summary>
/// <remarks>
/// TODO: Length restriction?
/// </remarks>
[JsonPropertyName("messageSummary")]
public required string MessageSummary { get; set; }
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets or sets the main body of the correspondence.
/// </summary>
public required string MessageBody { get; set; }
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved

[JsonPropertyName("attachments")]
public required new List<CorrespondenceAttachmentExt> Attachments { get; set; }
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Instance owner party id
/// </summary>
[JsonPropertyName("instanceOwnerPartyId")]
public int InstanceOwnerPartyId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public async Task<OneOf<LegacyGetCorrespondencesResponse, Error>> Process(Legacy
List<LegacyCorrespondenceItem> correspondenceItems = new List<LegacyCorrespondenceItem>();

var resourceOwners = new List<ResourceOwner>();

foreach (var orgNr in correspondences.Item1.Select(c => c.Sender).Distinct().ToList())
{
try
Expand All @@ -91,25 +92,40 @@ public async Task<OneOf<LegacyGetCorrespondencesResponse, Error>> Process(Legacy
resourceOwners.Add(new ResourceOwner(orgNr, null));
}
}
var recipientDetails = new List<ResourceOwner>();
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)
{
recipientDetails.Add(new ResourceOwner(orgNr, null));
}
}
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved
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;
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved
correspondenceItems.Add(
new LegacyCorrespondenceItem()
{
Altinn2CorrespondenceId = correspondence.Altinn2CorrespondenceId,
ServiceOwnerName = owner.Name,
InstanceOwnerPartyId = owner.PartyId,
InstanceOwnerPartyId = recipient.PartyId,
MessageTitle = correspondence.Content.MessageTitle,
Status = correspondence.GetLatestStatusWithoutPurged().Status,
CorrespondenceId = correspondence.Id,
MinimumAuthenticationLevel = 0, // Insert from response from PDP multirequest
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
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class LegacyGetCorrespondenceOverviewHandler : IHandler<LegacyGetCorrespo
private readonly IAltinnRegisterService _altinnRegisterService;
private readonly ICorrespondenceRepository _correspondenceRepository;
private readonly ICorrespondenceStatusRepository _correspondenceStatusRepository;
private readonly UserClaimsHelper _userClaimsHelper;
private readonly ILogger<LegacyGetCorrespondenceOverviewHandler> _logger;

public LegacyGetCorrespondenceOverviewHandler(IAltinnAccessManagementService altinnAccessManagementService, IAltinnAuthorizationService altinnAuthorizationService, IAltinnRegisterService altinnRegisterService, ICorrespondenceRepository CorrespondenceRepository, ICorrespondenceStatusRepository correspondenceStatusRepository, UserClaimsHelper userClaimsHelper, ILogger<LegacyGetCorrespondenceOverviewHandler> logger)
Expand All @@ -26,7 +25,6 @@ public LegacyGetCorrespondenceOverviewHandler(IAltinnAccessManagementService alt
_altinnRegisterService = altinnRegisterService;
_correspondenceRepository = CorrespondenceRepository;
_correspondenceStatusRepository = correspondenceStatusRepository;
_userClaimsHelper = userClaimsHelper;
_logger = logger;
}

Expand Down Expand Up @@ -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<CorrespondenceAttachmentEntity>(),
Language = correspondence.Content!.Language,
MessageTitle = correspondence.Content!.MessageTitle,
MessageSummary = correspondence.Content!.MessageSummary,
MessageBody = correspondence.Content!.MessageBody,
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved
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<CorrespondenceReplyOptionEntity>(),
Expand All @@ -124,11 +130,14 @@ await _correspondenceStatusRepository.AddCorrespondenceStatus(new Correspondence
Published = correspondence.Published,
IsConfirmationNeeded = correspondence.IsConfirmationNeeded,
MinimumAuthenticationLevel = (int)minimumAuthLevel,
AuthorizedForWrite = true,
AuthorizedForSign = true,
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved
DueDateTime = correspondence.DueDateTime,
AllowDelete = true,
Archived = correspondence.Statuses?.FirstOrDefault(s => s.Status == CorrespondenceStatus.Archived)?.StatusChanged,
PropertyList = correspondence.PropertyList ?? new Dictionary<string, string>()
Confirmed = correspondence.Statuses?.FirstOrDefault(s => s.Status == CorrespondenceStatus.Confirmed)?.StatusChanged,
PropertyList = correspondence.PropertyList ?? new Dictionary<string, string>(),
InstanceOwnerPartyId = resourceOwnerParty.PartyId
};
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,64 @@

namespace Altinn.Correspondence.Application.GetCorrespondenceOverview;

public class LegacyGetCorrespondenceOverviewResponse : GetCorrespondenceOverviewResponse
public class LegacyGetCorrespondenceOverviewResponse
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved
{
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<CorrespondenceAttachmentEntity> Attachments { get; set; }

public List<CorrespondenceReplyOptionEntity> ReplyOptions { get; set; } = new List<CorrespondenceReplyOptionEntity>();

public List<CorrespondenceNotificationOverview> Notifications { get; set; } = new List<CorrespondenceNotificationOverview>();

public List<ExternalReferenceEntity> ExternalReferences { get; set; } = new List<ExternalReferenceEntity>();

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<string, string> PropertyList { get; set; } = new Dictionary<string, string>();

public DateTimeOffset? Published { get; set; }

public bool IsConfirmationNeeded { get; set; }
}
Loading