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

functionality for sbl bridge #547

Merged
merged 12 commits into from
Jan 8, 2025
Merged

functionality for sbl bridge #547

merged 12 commits into from
Jan 8, 2025

Conversation

Andreass2
Copy link
Collaborator

@Andreass2 Andreass2 commented Dec 9, 2024

Description

When a correspondence is published, we mark it in sbl bridge as having Altinn3Messages.
Occurs only the first time for a given org or SSN

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

Release Notes

  • New Features

    • Added support for processing legacy party information.
    • Introduced configuration for SBL Bridge Base URL.
    • Enhanced deployment workflows with new environment support.
  • Infrastructure

    • Updated dependency injection and service configurations.
    • Added new database migration for legacy party tracking.
    • Expanded GitHub Actions deployment workflows.
  • Configuration

    • Added new environment-specific settings for SBL Bridge Base URL.
    • Introduced new configuration parameters across multiple environments.
  • Development

    • Implemented new services for party lookup and registration.
    • Added repository and entity support for legacy party management.

Copy link
Contributor

coderabbitai bot commented Dec 9, 2024

📝 Walkthrough

Walkthrough

This pull request introduces a comprehensive set of changes to enhance the Altinn Correspondence system's functionality, focusing on legacy party processing and configuration management. The changes span multiple components, including Bicep templates, GitHub Actions workflows, application settings, and core services. A new mechanism for processing legacy parties has been implemented, involving the addition of new interfaces, services, repositories, and handlers to manage party information across different system components. Additionally, new parameters and properties have been introduced to improve deployment configurations.

Changes

File Change Summary
.azure/applications/api/main.bicep Added secure parameter sblBridgeBaseUrl
.azure/applications/api/params.bicepparam Added parameter sblBridgeBaseUrl from environment variable
.azure/modules/containerApp/main.bicep Added secure parameter sblBridgeBaseUrl and corresponding environment variable
.github/actions/deploy-to-environment/action.yml Added input parameter SBL_BRIDGE_BASE_URL
.github/actions/release-version/action.yml Added input parameter SBL_BRIDGE_BASE_URL
.github/workflows/ci-cd.yaml Added new deployment job deploy-at22 and included SBL_BRIDGE_BASE_URL secret in existing jobs
.github/workflows/deploy-to-environment.yml Added secret variable SBL_BRIDGE_BASE_URL in deploy job
.github/workflows/publish-branch.yml Added input parameter SBL_BRIDGE_BASE_URL in release version step
src/Altinn.Correspondence.API/appsettings.Development.json Added property AltinnSblBridgeBaseUrl
src/Altinn.Correspondence.Core/Options/GeneralSettings.cs Added AltinnSblBridgeBaseUrl property
src/Altinn.Correspondence.Core/Services/IAltinnSblBridgeService.cs Added new interface for SBL Bridge service
src/Altinn.Correspondence.Persistence/Repositories/LegacyPartyRepository.cs Added new repository for managing legacy party entities
src/Altinn.Correspondence.Persistence/Data/ApplicationDbContext.cs Added property LegacyParties for legacy party entities
src/Altinn.Correspondence.Persistence/Migrations/20241209072946_LegacyPartyId.cs Added migration for creating LegacyParties table
src/Altinn.Correspondence.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs Updated model snapshot to include LegacyPartyEntity

Possibly related PRs

  • Use appsettings.local.json for local development #368: The addition of the sblBridgeBaseUrl parameter in the main PR relates to the changes in the .github/actions/deploy-to-environment/action.yml, which introduces a new input parameter SBL_BRIDGE_BASE_URL.
  • Legacy now support other envs #536: The introduction of the legacy_base_url parameter in the main PR is directly related to the changes in the .azure/applications/api/main.bicep file, which enhances the configuration options for the deployment.
  • Fix deployments to at23 to be automatic #555: The introduction of the maskinporten_token_exchange_environment parameter in the main PR is relevant to the changes in the .azure/applications/api/main.bicep file, which enhances the configuration options for the deployment.
  • fix new scope and scheme for legacy #576: The modifications in the DependencyInjection class regarding the new JWT Bearer authentication scheme may connect to the new sblBridgeBaseUrl parameter, as both involve enhancing the authentication and authorization processes.

Suggested labels

kind/feature

Suggested reviewers

  • CelineTrammi

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@Andreass2 Andreass2 marked this pull request as ready for review January 7, 2025 16:12
@Andreass2 Andreass2 added kind/feature-request New feature or request ignore-for-release pull request wont be included in release notes labels Jan 7, 2025
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: 13

🧹 Nitpick comments (11)
src/Altinn.Correspondence.Application/ProcessLegacyParty/ProcessLegacyPartyHandler.cs (2)

33-33: Use 'LogInformation' for consistency

For consistency and clarity, use logger.LogInformation instead of logger.Log(LogLevel.Information, ...).

Apply this diff to update the logging statement:

-logger.Log(LogLevel.Information, "Party {partyId} added to SBL", partyId);
+logger.LogInformation("Party {partyId} added to SBL", partyId);

21-22: Use specific exception types

Using specific exception types instead of the generic Exception improves error handling and debugging.

Apply this diff to use more specific exceptions:

-throw new Exception("Failed to look up party in Altinn Register");
+throw new InvalidOperationException("Failed to look up party in Altinn Register");

-throw new Exception("Failed to send party to SBL");
+throw new InvalidOperationException("Failed to send party to SBL");

Also applies to: 31-32

src/Altinn.Correspondence.Core/Models/Entities/LegacyPartyEntity.cs (1)

7-12: Add XML documentation to explain the purpose of this entity

Consider adding XML documentation to explain:

  • The purpose of this entity
  • The relationship between Id and PartyId
  • Any business rules or constraints that apply
+    /// <summary>
+    /// Represents a legacy party entity in the system.
+    /// </summary>
     public class LegacyPartyEntity
     {
+        /// <summary>
+        /// Gets or sets the unique identifier for the legacy party entity.
+        /// </summary>
         [Key]
         public Guid Id { get; set; }
+        /// <summary>
+        /// Gets or sets the party identifier from the legacy system.
+        /// </summary>
         public int PartyId { get; set; }
     }
src/Altinn.Correspondence.Core/Options/GeneralSettings.cs (1)

9-9: Add URL validation and consider required value handling

The AltinnSblBridgeBaseUrl property should:

  1. Include URL format validation
  2. Consider using Uri type instead of string
  3. Handle the case when the URL is not provided (empty string might not be appropriate)
-    public string AltinnSblBridgeBaseUrl { get; set; } = string.Empty;
+    private Uri? _altinnSblBridgeBaseUrl;
+    public string AltinnSblBridgeBaseUrl
+    {
+        get => _altinnSblBridgeBaseUrl?.ToString() ?? string.Empty;
+        set => _altinnSblBridgeBaseUrl = !string.IsNullOrEmpty(value) ? new Uri(value) : null;
+    }
src/Altinn.Correspondence.Persistence/Repositories/LegacyPartyRepository.cs (1)

11-15: Consider adding transaction handling

The AddLegacyPartyId method should use a transaction to ensure data consistency, especially since it involves multiple database operations.

         public async Task AddLegacyPartyId(int id, CancellationToken cancellationToken)
         {
+            await using var transaction = await _context.Database.BeginTransactionAsync(cancellationToken);
+            try
+            {
                 await _context.LegacyParties.AddAsync(new LegacyPartyEntity { PartyId = id }, cancellationToken);
                 await _context.SaveChangesAsync(cancellationToken);
+                await transaction.CommitAsync(cancellationToken);
+            }
+            catch
+            {
+                await transaction.RollbackAsync(cancellationToken);
+                throw;
+            }
         }
src/Altinn.Correspondence.Integrations/Altinn/SblBridge/AltinnSblBridgeService.cs (2)

24-24: Consider extracting API path to configuration

The API endpoint path is hardcoded. Consider moving it to configuration for better maintainability.


11-15: Consider adding retry policy

For better resilience, consider adding a retry policy for transient failures using Polly.

Example implementation:

using Polly;
using Polly.Extensions.Http;

public class AltinnSblBridgeService : IAltinnSblBridgeService
{
    private static readonly IAsyncPolicy<HttpResponseMessage> RetryPolicy = HttpPolicyExtensions
        .HandleTransientHttpError()
        .WaitAndRetryAsync(3, retryAttempt => 
            TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));

    // ... rest of the implementation
}
src/Altinn.Correspondence.Application/PublishCorrespondence/PublishCorrespondenceHandler.cs (1)

97-97: Consider error handling for the background job.

While the fire-and-forget pattern is appropriate here (similar to the Dialogporten activity creation), consider:

  1. Adding error handling in the ProcessLegacyPartyHandler
  2. Implementing retry policies for transient failures
  3. Adding monitoring for failed jobs
src/Altinn.Correspondence.Integrations/DependencyInjection.cs (1)

62-66: LGTM! Consider improving readability.

The service registration follows the established pattern and properly handles both production and development scenarios.

Consider reformatting the else clause for better readability:

-        else services.AddHttpClient<IAltinnSblBridgeService, AltinnSblBridgeService>(client => client.BaseAddress = new Uri(generalSettings.AltinnSblBridgeBaseUrl));
+        else
+        {
+            services.AddHttpClient<IAltinnSblBridgeService, AltinnSblBridgeService>(client => 
+                client.BaseAddress = new Uri(generalSettings.AltinnSblBridgeBaseUrl));
+        }
src/Altinn.Correspondence.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs (1)

349-361: Consider adding an index on PartyId for better query performance.

The LegacyPartyEntity table will likely be queried using the PartyId field. Adding an index on this column would improve query performance.

Apply this diff to add an index:

             modelBuilder.Entity("Altinn.Correspondence.Core.Models.Entities.LegacyPartyEntity", b =>
                 {
                     b.Property<Guid>("Id")
                         .ValueGeneratedOnAdd()
                         .HasColumnType("uuid");

                     b.Property<int>("PartyId")
                         .HasColumnType("integer");

                     b.HasKey("Id");

+                    b.HasIndex("PartyId");

                     b.ToTable("LegacyParties", "correspondence");
                 });
.github/workflows/ci-cd.yaml (1)

87-87: Remove trailing spaces.

There are trailing spaces on lines 87 and 89. While this is a minor issue, it's good practice to maintain clean formatting.

-    if: always() && !failure() && !cancelled() 
+    if: always() && !failure() && !cancelled()
-    permissions: 
+    permissions:

Also applies to: 89-89

🧰 Tools
🪛 yamllint (1.35.1)

[error] 87-87: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 78f1efc and 7a74ffc.

📒 Files selected for processing (30)
  • .azure/applications/api/main.bicep (2 hunks)
  • .azure/applications/api/params.bicepparam (1 hunks)
  • .azure/modules/containerApp/main.bicep (2 hunks)
  • .github/actions/deploy-to-environment/action.yml (2 hunks)
  • .github/actions/release-version/action.yml (2 hunks)
  • .github/workflows/ci-cd.yaml (3 hunks)
  • .github/workflows/deploy-to-environment.yml (1 hunks)
  • .github/workflows/publish-branch.yml (1 hunks)
  • src/Altinn.Correspondence.API/appsettings.Development.json (1 hunks)
  • src/Altinn.Correspondence.API/appsettings.json (1 hunks)
  • src/Altinn.Correspondence.Application/DependencyInjection.cs (2 hunks)
  • src/Altinn.Correspondence.Application/ProcessLegacyParty/ProcessLegacyPartyHandler.cs (1 hunks)
  • src/Altinn.Correspondence.Application/PublishCorrespondence/PublishCorrespondenceHandler.cs (2 hunks)
  • src/Altinn.Correspondence.Core/Models/Entities/LegacyPartyEntity.cs (1 hunks)
  • src/Altinn.Correspondence.Core/Options/GeneralSettings.cs (1 hunks)
  • src/Altinn.Correspondence.Core/Repositories/ILegacyPartyRepository.cs (1 hunks)
  • src/Altinn.Correspondence.Core/Services/IAltinnRegisterService.cs (1 hunks)
  • src/Altinn.Correspondence.Core/Services/IAltinnSblBridgeService.cs (1 hunks)
  • src/Altinn.Correspondence.Integrations/Altinn/Events/AltinnEventBus.cs (1 hunks)
  • src/Altinn.Correspondence.Integrations/Altinn/Register/AltinnRegisterDevService.cs (1 hunks)
  • src/Altinn.Correspondence.Integrations/Altinn/Register/AltinnRegisterService.cs (1 hunks)
  • src/Altinn.Correspondence.Integrations/Altinn/SblBridge/AltinnSblBridgeDevService.cs (1 hunks)
  • src/Altinn.Correspondence.Integrations/Altinn/SblBridge/AltinnSblBridgeService.cs (1 hunks)
  • src/Altinn.Correspondence.Integrations/DependencyInjection.cs (1 hunks)
  • src/Altinn.Correspondence.Persistence/Data/ApplicationDbContext.cs (1 hunks)
  • src/Altinn.Correspondence.Persistence/DependencyInjection.cs (1 hunks)
  • src/Altinn.Correspondence.Persistence/Migrations/20241209072946_LegacyPartyId.Designer.cs (1 hunks)
  • src/Altinn.Correspondence.Persistence/Migrations/20241209072946_LegacyPartyId.cs (1 hunks)
  • src/Altinn.Correspondence.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs (1 hunks)
  • src/Altinn.Correspondence.Persistence/Repositories/LegacyPartyRepository.cs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/Altinn.Correspondence.API/appsettings.json
🧰 Additional context used
📓 Learnings (3)
src/Altinn.Correspondence.Application/DependencyInjection.cs (1)
Learnt from: CelineTrammi
PR: Altinn/altinn-correspondence#413
File: src/Altinn.Correspondence.Application/DependencyInjection.cs:0-0
Timestamp: 2024-11-12T05:02:53.065Z
Learning: In Altinn.Correspondence.Application, handlers with similar names—such as UploadAttachmentHandler, GetAttachmentDetailsHandler, GetAttachmentOverviewHandler, and PurgeAttachmentHandler—may have multiple distinct implementations and are intentionally registered separately in DependencyInjection.cs.
src/Altinn.Correspondence.Application/PublishCorrespondence/PublishCorrespondenceHandler.cs (1)
Learnt from: CelineTrammi
PR: Altinn/altinn-correspondence#483
File: src/Altinn.Correspondence.Application/UpdateCorrespondenceStatus/LegacyUpdateCorrespondenceStatusHandler.cs:75-75
Timestamp: 2024-11-12T14:46:34.110Z
Learning: In `LegacyUpdateCorrespondenceStatusHandler.cs`, the call to `_updateCorrespondenceStatusHelper.ReportActivityToDialogporten(...)` is intended to be a fire-and-forget event and does not need to be awaited.
src/Altinn.Correspondence.Core/Models/Entities/LegacyPartyEntity.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.
🪛 actionlint (1.7.4)
.github/workflows/ci-cd.yaml

98-98: missing input "CONTACT_RESERVATION_REGISTRY_BASE_URL" which is required by action "Deploy to Environment" defined at "./.github/actions/deploy-to-environment". all required inputs are "ACCESS_MANAGEMENT_SUBSCRIPTION_KEY", "AZURE_CLIENT_ID", "AZURE_ENVIRONMENT_KEY_VAULT_NAME", "AZURE_NAME_PREFIX", "AZURE_STORAGE_ACCOUNT_NAME", "AZURE_SUBSCRIPTION_ID", "AZURE_TENANT_ID", "AZURE_TEST_ACCESS_CLIENT_ID", "CONTACT_RESERVATION_REGISTRY_BASE_URL", "CORRESPONDENCE_BASE_URL", "DIALOGPORTEN_ISSUER", "IDPORTEN_CLIENT_ID", "IDPORTEN_CLIENT_SECRET", "IDPORTEN_ISSUER", "MASKINPORTEN_CLIENT_ID", "MASKINPORTEN_JWK", "PLATFORM_BASE_URL", "PLATFORM_SUBSCRIPTION_KEY", "SBL_BRIDGE_BASE_URL", "SLACK_URL", "environment", "imageTag"

(action)

🪛 yamllint (1.35.1)
.github/workflows/ci-cd.yaml

[error] 87-87: trailing spaces

(trailing-spaces)


[error] 89-89: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test application
🔇 Additional comments (28)
src/Altinn.Correspondence.Application/ProcessLegacyParty/ProcessLegacyPartyHandler.cs (1)

9-13: ⚠️ Potential issue

Fix the class declaration syntax

The class declaration uses an invalid syntax for constructor parameters in C#. Classes cannot have constructor parameters specified directly in the class declaration. Instead, define a constructor within the class body.

Apply this diff to correct the class declaration:

-public class ProcessLegacyPartyHandler(
-    ILogger<ProcessLegacyPartyHandler> logger,
-    IAltinnRegisterService altinnRegisterService,
-    IAltinnSblBridgeService sblBridgeService,
-    ILegacyPartyRepository legacyPartyRepository) : IHandler<string, Task>
+public class ProcessLegacyPartyHandler : IHandler<string, Task>
+{
+    private readonly ILogger<ProcessLegacyPartyHandler> logger;
+    private readonly IAltinnRegisterService altinnRegisterService;
+    private readonly IAltinnSblBridgeService sblBridgeService;
+    private readonly ILegacyPartyRepository legacyPartyRepository;
+
+    public ProcessLegacyPartyHandler(
+        ILogger<ProcessLegacyPartyHandler> logger,
+        IAltinnRegisterService altinnRegisterService,
+        IAltinnSblBridgeService sblBridgeService,
+        ILegacyPartyRepository legacyPartyRepository)
+    {
+        this.logger = logger;
+        this.altinnRegisterService = altinnRegisterService;
+        this.sblBridgeService = sblBridgeService;
+        this.legacyPartyRepository = legacyPartyRepository;
+    }

Likely invalid or redundant comment.

src/Altinn.Correspondence.Core/Services/IAltinnSblBridgeService.cs (1)

1-8: Interface 'IAltinnSblBridgeService' looks good

The interface is well-defined and follows proper conventions.

src/Altinn.Correspondence.Core/Repositories/ILegacyPartyRepository.cs (1)

1-10: Interface 'ILegacyPartyRepository' looks good

The interface methods are clearly defined and appropriately named.

src/Altinn.Correspondence.Core/Models/Entities/LegacyPartyEntity.cs (1)

11-11: Consider adding validation for PartyId

Based on the retrieved learnings about PartyId validation being under development, consider adding appropriate validation attributes or implementing validation logic for the PartyId property.

Would you like me to help implement the validation rules once they are determined?

src/Altinn.Correspondence.Core/Services/IAltinnRegisterService.cs (1)

7-7: Verify impact of breaking change in LookUpPartyId return type

The return type change from Task<string?> to Task<int?> is a breaking change. Ensure all implementations and consumers are updated accordingly.

Run this script to find potential impacts:

✅ Verification successful

Breaking change in LookUpPartyId return type has been properly implemented

All implementations and consumers have been updated to handle the Task<int?> return type correctly:

  • Both AltinnRegisterService and AltinnRegisterDevService implementations return Task<int?>
  • Consumers in AltinnEventBus and ProcessLegacyPartyHandler handle the integer type appropriately
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find all files that might be affected by the breaking change

# Look for method calls
echo "Files potentially calling LookUpPartyId:"
rg "LookUpPartyId\(" -l

# Look for implementations
echo -e "\nPotential implementations of IAltinnRegisterService:"
rg "class.*:.*IAltinnRegisterService" -l

Length of output: 829


Script:

#!/bin/bash
# Check implementations and usage patterns

echo "=== Implementation in AltinnRegisterDevService ==="
ast-grep --pattern 'async Task<$_> LookUpPartyId($_) {
  $$$
}' src/Altinn.Correspondence.Integrations/Altinn/Register/AltinnRegisterDevService.cs

echo -e "\n=== Implementation in AltinnRegisterService ==="
ast-grep --pattern 'async Task<$_> LookUpPartyId($_) {
  $$$
}' src/Altinn.Correspondence.Integrations/Altinn/Register/AltinnRegisterService.cs

echo -e "\n=== Usage in AltinnEventBus ==="
rg -A 5 "LookUpPartyId\(" src/Altinn.Correspondence.Integrations/Altinn/Events/AltinnEventBus.cs

echo -e "\n=== Usage in ProcessLegacyPartyHandler ==="
rg -A 5 "LookUpPartyId\(" src/Altinn.Correspondence.Application/ProcessLegacyParty/ProcessLegacyPartyHandler.cs

Length of output: 1529


Script:

#!/bin/bash
echo "=== Implementation in AltinnRegisterDevService ==="
rg -A 10 "LookUpPartyId" src/Altinn.Correspondence.Integrations/Altinn/Register/AltinnRegisterDevService.cs

echo -e "\n=== Implementation in AltinnRegisterService ==="
rg -A 10 "LookUpPartyId" src/Altinn.Correspondence.Integrations/Altinn/Register/AltinnRegisterService.cs

Length of output: 1364

.azure/applications/api/params.bicepparam (1)

8-8: LGTM!

The new parameter follows the existing pattern and is correctly integrated.

src/Altinn.Correspondence.Persistence/DependencyInjection.cs (1)

28-28: LGTM! Repository registration follows established patterns.

The registration of ILegacyPartyRepository as a scoped service aligns with the existing repository registration pattern and maintains consistency with other repository lifetimes.

src/Altinn.Correspondence.Persistence/Data/ApplicationDbContext.cs (1)

40-40: LGTM! DbSet property follows EF Core conventions.

The addition of LegacyParties DbSet property maintains consistency with existing Entity Framework Core patterns and naming conventions.

src/Altinn.Correspondence.Integrations/Altinn/Register/AltinnRegisterDevService.cs (1)

13-20: LGTM! Type change improves type safety.

The change from Task<string?> to Task<int?> for party IDs is more type-safe and eliminates unnecessary string conversion.

Let's verify that this change is consistent across all implementations of IAltinnRegisterService:

✅ Verification successful

Return type is consistent across all implementations

The change to Task<int?> in AltinnRegisterDevService matches both:

  • The interface definition in IAltinnRegisterService
  • The implementation in the main AltinnRegisterService
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all implementations of LookUpPartyId to ensure consistent return types
ast-grep --pattern 'Task<$_?> LookUpPartyId'

Length of output: 46


Script:

#!/bin/bash
# Find the interface definition
rg "interface IAltinnRegisterService" -A 5

# Find all implementations
rg "class.*: .*IAltinnRegisterService" -A 5

# Backup search for LookUpPartyId method
rg "LookUpPartyId.*Task<" -A 2

Length of output: 2604


Script:

#!/bin/bash
# Check AltinnRegisterService implementation
rg "LookUpPartyId.*Task<.*>" -B 2 -A 5 src/Altinn.Correspondence.Integrations/Altinn/Register/AltinnRegisterService.cs

Length of output: 120


Script:

#!/bin/bash
# Simple search for LookUpPartyId in the main service implementation
cat src/Altinn.Correspondence.Integrations/Altinn/Register/AltinnRegisterService.cs

Length of output: 5001

src/Altinn.Correspondence.Application/DependencyInjection.cs (1)

14-14: LGTM! Handler registration follows established patterns.

The registration of ProcessLegacyPartyHandler and its using directive maintain consistency with existing patterns. Based on previous feedback, separate handler registration is intentional in this codebase.

Also applies to: 51-51

src/Altinn.Correspondence.Integrations/Altinn/Register/AltinnRegisterService.cs (1)

24-27: LGTM! Type change improves type safety.

The change from Task<string?> to Task<int?> better represents the domain model where PartyId is inherently an integer.

Let's verify all callers have been updated to handle the new return type:

✅ Verification successful

All callers properly handle the new Task<int?> return type

The codebase has been correctly updated to work with the integer return type, with appropriate null checks and safe type conversions in place.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all usages of LookUpPartyId to ensure they handle the int? return type
rg -A 3 "LookUpPartyId\(" --type cs

Length of output: 2808

src/Altinn.Correspondence.Integrations/Altinn/Events/AltinnEventBus.cs (1)

33-33: LGTM! Null-safe type conversion.

The change correctly handles the new int? return type from LookUpPartyId by using the null-conditional operator and ToString().

src/Altinn.Correspondence.Application/PublishCorrespondence/PublishCorrespondenceHandler.cs (1)

3-3: LGTM! Clear dependency.

The using directive clearly indicates the new dependency on legacy party processing functionality.

src/Altinn.Correspondence.Persistence/Migrations/20241209072946_LegacyPartyId.Designer.cs (1)

1-524: Auto-generated migration designer file.

This is an auto-generated file that mirrors the model snapshot. No issues found.

src/Altinn.Correspondence.API/appsettings.Development.json (1)

37-37: LGTM!

The new setting AltinnSblBridgeBaseUrl is correctly placed under GeneralSettings and follows the existing naming convention.

.github/workflows/publish-branch.yml (1)

43-43: LGTM!

The new secret SBL_BRIDGE_BASE_URL is correctly referenced and follows the existing naming convention.

.github/workflows/deploy-to-environment.yml (1)

88-89: LGTM! Secret addition follows existing patterns.

The SBL_BRIDGE_BASE_URL secret is correctly added and follows the established pattern for secret declarations in the workflow.

.azure/applications/api/main.bicep (2)

20-21: LGTM! Secure parameter declaration is appropriate.

The sblBridgeBaseUrl is correctly declared with the @secure() decorator, ensuring the URL is handled securely throughout the deployment pipeline.


104-104: LGTM! Parameter correctly passed to containerApp module.

The sblBridgeBaseUrl is properly passed to the containerApp module, maintaining the secure context.

.github/actions/release-version/action.yml (2)

45-47: LGTM! Input parameter properly defined.

The SBL_BRIDGE_BASE_URL input parameter is correctly defined with appropriate description and required flag.


83-83: LGTM! Environment variable correctly mapped.

The input parameter is properly mapped to the environment variable for deployment.

.github/actions/deploy-to-environment/action.yml (2)

69-71: LGTM! Input parameter properly defined.

The SBL_BRIDGE_BASE_URL input parameter is correctly defined with appropriate description and required flag.


132-132: LGTM! Parameter correctly passed to release-version action.

The SBL_BRIDGE_BASE_URL is properly passed through to the release-version action.

.azure/modules/containerApp/main.bicep (2)

14-16: LGTM! Secure parameter properly declared.

The sblBridgeBaseUrl parameter is correctly declared with the @secure() decorator.


84-84: LGTM! Environment variable follows .NET configuration pattern.

The environment variable GeneralSettings__AltinnSblBridgeBaseUrl follows the correct configuration pattern for .NET applications, using double underscores for section delimiters.

.github/workflows/ci-cd.yaml (3)

81-81: LGTM! Consistent secret management across environments.

The SBL_BRIDGE_BASE_URL secret has been properly added to all deployment environments (test, staging, production), maintaining consistency in the configuration.

Also applies to: 164-164, 208-208


86-86: Environment configuration mismatch.

The job is named 'deploy-at22' but uses the 'test' environment. This could lead to confusion and potential deployment issues. Consider creating a dedicated 'at22' environment or clarify why 'test' environment is being used.


83-93: Verify deployment sequence for at22.

The new at22 deployment runs in parallel with the test deployment (same needs configuration). Please verify if this is the intended behavior or if at22 should be part of the sequential deployment pipeline (test → at22 → staging → production).

🧰 Tools
🪛 yamllint (1.35.1)

[error] 87-87: trailing spaces

(trailing-spaces)


[error] 89-89: trailing spaces

(trailing-spaces)

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: 4

🧹 Nitpick comments (4)
src/Altinn.Correspondence.Integrations/Altinn/SblBridge/AltinnSblBridgeDevService.cs (1)

4-5: Add XML documentation to clarify development service purpose.

Since this is a development implementation, add XML documentation to clearly indicate its purpose and usage limitations.

+/// <summary>
+/// Development implementation of IAltinnSblBridgeService for testing and local development.
+/// This implementation should not be used in production environments.
+/// </summary>
 public class AltinnSblBridgeDevService : IAltinnSblBridgeService
.github/workflows/ci-cd.yaml (1)

87-87: Remove trailing spaces.

Remove trailing spaces from the following lines:

  • Line 87: if: always() && !failure() && !cancelled()
  • Line 89: permissions:
  • Line 122: CONTACT_RESERVATION_REGISTRY_BASE_URL: ${{ secrets.CONTACT_RESERVATION_REGISTRY_BASE_URL }}

Also applies to: 89-89, 122-122

🧰 Tools
🪛 yamllint (1.35.1)

[error] 87-87: trailing spaces

(trailing-spaces)

src/Altinn.Correspondence.Application/ProcessLegacyParty/ProcessLegacyPartyHandler.cs (2)

15-15: Remove unused parameter.

The ClaimsPrincipal? user parameter is not used in the method implementation.

-    public async Task Process(string recipient, ClaimsPrincipal? user, CancellationToken cancellationToken)
+    public async Task Process(string recipient, CancellationToken cancellationToken)

17-17: Use consistent logging levels.

The logging levels should be consistent. Both logs are informational, but use different methods.

-        logger.LogInformation("Process legacy party {recipient}", recipient);
+        logger.LogInformation("Processing legacy party {recipient}", recipient);

-            logger.Log(LogLevel.Information, "Party {partyId} added to SBL", partyId);
+            logger.LogInformation("Party {partyId} added to SBL", partyId);

Also applies to: 31-31

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7a74ffc and 15a3b1a.

📒 Files selected for processing (7)
  • .github/workflows/ci-cd.yaml (3 hunks)
  • src/Altinn.Correspondence.Application/ProcessLegacyParty/ProcessLegacyPartyHandler.cs (1 hunks)
  • src/Altinn.Correspondence.Integrations/Altinn/SblBridge/AltinnSblBridgeDevService.cs (1 hunks)
  • src/Altinn.Correspondence.Integrations/Altinn/SblBridge/AltinnSblBridgeService.cs (1 hunks)
  • src/Altinn.Correspondence.Integrations/DependencyInjection.cs (3 hunks)
  • src/Altinn.Correspondence.Persistence/Migrations/20241209072946_LegacyPartyId.cs (1 hunks)
  • src/Altinn.Correspondence.Persistence/Repositories/LegacyPartyRepository.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/Altinn.Correspondence.Persistence/Repositories/LegacyPartyRepository.cs
  • src/Altinn.Correspondence.Integrations/DependencyInjection.cs
  • src/Altinn.Correspondence.Integrations/Altinn/SblBridge/AltinnSblBridgeService.cs
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/ci-cd.yaml

[error] 87-87: trailing spaces

(trailing-spaces)


[error] 89-89: trailing spaces

(trailing-spaces)


[error] 122-122: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test application
  • GitHub Check: Analyze (csharp)
🔇 Additional comments (4)
.github/workflows/ci-cd.yaml (2)

81-81: LGTM! SBL bridge URL configuration added consistently.

The SBL_BRIDGE_BASE_URL secret has been properly added to all deployment environments, which aligns with the PR objective of enabling SBL bridge functionality for correspondence marking.

Also applies to: 165-165, 209-209


97-120: Missing required input parameter.

The deploy-to-environment action requires CONTACT_RESERVATION_REGISTRY_BASE_URL, but it's not provided in the inputs.

src/Altinn.Correspondence.Persistence/Migrations/20241209072946_LegacyPartyId.cs (1)

14-33: LGTM! Well-structured migration with proper constraints.

The migration correctly implements:

  • UUID primary key
  • Integer PartyId with unique constraint
  • Index on PartyId for query optimization
  • Proper schema naming
src/Altinn.Correspondence.Application/ProcessLegacyParty/ProcessLegacyPartyHandler.cs (1)

26-33: Verify transaction handling.

Ensure that adding the party to both SBL bridge and legacy repository is transactional to maintain data consistency.

Run the following script to check for transaction handling in the repository implementation:

✅ Verification successful

Current implementation maintains data consistency.

The implementation is safe because:

  • SBL bridge operation fails fast before any DB changes
  • DB operation is atomic using EF Core's SaveChangesAsync
  • No partial/inconsistent state is possible with current operation order
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for transaction handling in repository implementation
# Look for transaction handling in repository implementation
rg -A 10 "class LegacyPartyRepository" 

# Look for transaction handling in DbContext
rg -A 10 "SaveChangesAsync" 

Length of output: 16423

@Andreass2 Andreass2 merged commit f57743f into main Jan 8, 2025
6 checks passed
@Andreass2 Andreass2 deleted the sbl-bridge branch January 8, 2025 08:36
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/feature-request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants