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

Ct/legacy/history/separate user and notification #516

Merged
merged 2 commits into from
Nov 22, 2024

Conversation

CelineTrammi
Copy link
Collaborator

@CelineTrammi CelineTrammi commented Nov 22, 2024

Description

Separate fields related user and notification into their own objects.

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

Summary by CodeRabbit

  • New Features

    • Enhanced asynchronous processing for retrieving correspondence and notification histories.
    • Introduced a new LegacyNotification class to provide detailed recipient information, including email and mobile number.
  • Improvements

    • Updated data model to include additional user details such as National Identity Number and Name.
  • Bug Fixes

    • Streamlined logic for retrieving party information to improve clarity and efficiency.

@CelineTrammi CelineTrammi added kind/bug Something isn't working ignore-for-release pull request wont be included in release notes labels Nov 22, 2024
Copy link
Contributor

coderabbitai bot commented Nov 22, 2024

📝 Walkthrough

Walkthrough

The pull request introduces significant changes to the LegacyGetCorrespondenceHistoryHandler and related classes. Key modifications include the restructuring of methods for retrieving correspondence and notification histories, with a shift from LINQ to explicit loops, and the incorporation of asynchronous processing with CancellationToken support. Additionally, the data model has been updated to include a new LegacyNotification class and modifications to existing properties in LegacyGetCorrespondenceHistoryResponse and LegacyUser, enhancing the clarity and structure of the correspondence and notification handling.

Changes

File Change Summary
src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs - Updated GetCorrespondenceStatus and GetNotificationStatus methods to include CancellationToken and changed their signatures.
- Removed GetPartyIdForNotfication method and integrated its logic into GetNotificationStatus.
src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs - Added nullable Notification property to LegacyGetCorrespondenceHistoryResponse.
- Removed Recipient property from LegacyUser and added NationalIdentityNumber and Name properties.
- Introduced LegacyNotification class with properties for notification details.

Possibly related PRs

Suggested labels

kind/feature-request

Suggested reviewers

  • Andreass2

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@CelineTrammi CelineTrammi marked this pull request as ready for review November 22, 2024 12:10
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs (1)

Line range hint 1-24: Document the legacy data structure transition

The separation of user and notification data is well-structured. Consider:

  1. Adding XML documentation to clarify the purpose and lifecycle of these legacy classes
  2. Creating a migration guide for teams consuming this API
  3. Planning for eventual removal of the "Legacy" prefix when the transition is complete
src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs (1)

50-57: Optimize asynchronous calls within the loop for better performance

Currently, GetCorrespondenceStatus is awaited inside a foreach loop, processing each status sequentially. To improve performance, consider processing the tasks concurrently using Task.WhenAll. This can reduce the total processing time when handling multiple correspondence statuses.

Here is a suggested refactor:

var correspondenceHistory = new List<LegacyGetCorrespondenceHistoryResponse>();
- foreach (var correspondenceStatus in correspondence.Statuses)
- {
-     if (correspondenceStatus.Status.IsAvailableForRecipient())
-     {
-         correspondenceHistory.Add(await GetCorrespondenceStatus(correspondenceStatus, recipientParty, senderParty, cancellationToken));
-     }
- }
+ var tasks = correspondence.Statuses
+     .Where(status => status.Status.IsAvailableForRecipient())
+     .Select(status => GetCorrespondenceStatus(status, recipientParty, senderParty, cancellationToken));
+ correspondenceHistory.AddRange(await Task.WhenAll(tasks));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 78f958e and ea4ce69.

📒 Files selected for processing (2)
  • src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs (2 hunks)
  • src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs (1 hunks)
🧰 Additional context used
📓 Learnings (1)
src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs (1)
Learnt from: CelineTrammi
PR: Altinn/altinn-correspondence#413
File: src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs:17-21
Timestamp: 2024-11-12T05:02:53.065Z
Learning: The `PartyId` and `AuthenticationLevel` properties in the `LegacyUser` class (in `src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs`) are still under development, and the correct validation has not been determined yet.
🔇 Additional comments (6)
src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs (2)

11-11: LGTM! Good separation of notification data

The addition of the nullable Notification property effectively separates notification-specific data from the main response object, improving the overall structure.


14-18: Verify data migration for user identification fields

The restructuring of user fields looks good, but please ensure:

  1. Data migration handles the transition from the old Recipient property to the new structure
  2. All consuming code is updated to handle the nullable fields
✅ Verification successful

Let me gather more specific information about the usage of these properties.


Based on the search results, I can now generate the final response:

Property changes are properly handled in the codebase

The changes to the user fields are properly integrated:

  1. The LegacyGetCorrespondenceHistoryHandler correctly maps the new nullable properties:

    • Name is populated from party?.Name
    • NationalIdentityNumber is populated from party?.SSN or recipient.NationalIdentityNumber
    • All properties are properly handled as nullable
  2. The old Recipient property references in the codebase are part of different contexts (notifications, dialogporten integration) and not related to this response model.

  3. No data migration is needed as this is just a response model restructuring, with data being mapped from existing sources.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of the old Recipient property to ensure complete migration
rg -l "Recipient" --type cs

# Search for direct access to the new properties to verify proper null handling
ast-grep --pattern 'NationalIdentityNumber' --lang cs
ast-grep --pattern 'Name' --lang cs

Length of output: 9037


Script:

#!/bin/bash
# Search for direct references to the new properties with context
rg -A 3 -B 3 "NationalIdentityNumber\s*[{=}]" --type cs
rg -A 3 -B 3 "Name\s*[{=}]" --type cs

# Look for the migration file that might handle this change
fd ".*Migration.*\.cs$" -x grep -l "LegacyGetCorrespondenceHistoryResponse"

# Check for any mapping or transformation of these properties
rg -A 3 -B 3 "LegacyGetCorrespondenceHistoryResponse" --type cs

Length of output: 74518

src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs (4)

96-98: LGTM: Party ID selection logic is clear and appropriate

The logic for selecting the partyId based on the status is well implemented and correctly determines whether to use the sender or recipient party.


101-108: LGTM: User information mapping is correctly handled

The mapping of party information to LegacyUser accommodates potential null values using the null-conditional operator, ensuring that the properties are assigned safely.


115-127: LGTM: Constructing 'LegacyGetCorrespondenceHistoryResponse' with notification details

The initialization of the response object with notification details, including the new LegacyNotification object, is appropriately structured and enhances clarity.


130-139: LGTM: Party lookup and 'User' assignment in 'GetNotificationStatus' method

The logic for looking up the party based on recipient information and assigning it to response.User is correct and accounts for cases where the party may not be found.

@CelineTrammi CelineTrammi merged commit 768e57a into main Nov 22, 2024
10 checks passed
@CelineTrammi CelineTrammi deleted the ct/legacy/history/separate-user-and-notification branch November 22, 2024 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignore-for-release pull request wont be included in release notes kind/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants