Skip to content

Commit bfb99e6

Browse files
tfjanjuantruchsess
andauthored
feat(CxMembership): Set Catena-X Membership in BPDM (#1118)
Ref: #1111 * Add "BusinessPartnerPoolBaseAddress" in appsettings * refactor use of HttpClient * added migration files * update framework version --------- Co-authored-by: Norbert Truchsess <norbert.truchsess@t-online.de>
1 parent b02e24c commit bfb99e6

File tree

52 files changed

+10568
-60
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+10568
-60
lines changed

docs/api/administration-service.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4257,6 +4257,38 @@ paths:
42574257
description: Internal Server Error
42584258
'401':
42594259
description: The User is unauthorized
4260+
'/api/administration/registration/application/{applicationId}/retrigger-set-cx-membership':
4261+
post:
4262+
tags:
4263+
- Registration
4264+
summary: 'Retriggers the last failed step (Authorization required - Roles: approve_new_partner)'
4265+
parameters:
4266+
- name: applicationId
4267+
in: path
4268+
description: Id of the application that should be triggered
4269+
required: true
4270+
schema:
4271+
type: string
4272+
format: uuid
4273+
responses:
4274+
'204':
4275+
description: Empty response on success.
4276+
'400':
4277+
description: Either the CompanyApplication is not in status SUBMITTED or the next step can't automatically retriggered.
4278+
content:
4279+
application/json:
4280+
schema:
4281+
$ref: '#/components/schemas/ErrorResponse'
4282+
'404':
4283+
description: No application found for the applicationId.
4284+
content:
4285+
application/json:
4286+
schema:
4287+
$ref: '#/components/schemas/ErrorResponse'
4288+
'500':
4289+
description: Internal Server Error
4290+
'401':
4291+
description: The User is unauthorized
42604292
/api/administration/RegistrationStatus/callback:
42614293
get:
42624294
tags:
@@ -7529,6 +7561,8 @@ components:
75297561
- RETRIGGER_REMOVE_REGISTRATION_ROLES
75307562
- RETRIGGER_SET_THEME
75317563
- RETRIGGER_SET_MEMBERSHIP
7564+
- SET_CX_MEMBERSHIP_IN_BPDM
7565+
- RETRIGGER_SET_CX_MEMBERSHIP_IN_BPDM
75327566
- TRIGGER_PROVIDER
75337567
- AWAIT_START_AUTOSETUP
75347568
- OFFERSUBSCRIPTION_CLIENT_CREATION

docs/api/apps-service.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,6 +3631,8 @@ components:
36313631
- RETRIGGER_REMOVE_REGISTRATION_ROLES
36323632
- RETRIGGER_SET_THEME
36333633
- RETRIGGER_SET_MEMBERSHIP
3634+
- SET_CX_MEMBERSHIP_IN_BPDM
3635+
- RETRIGGER_SET_CX_MEMBERSHIP_IN_BPDM
36343636
- TRIGGER_PROVIDER
36353637
- AWAIT_START_AUTOSETUP
36363638
- OFFERSUBSCRIPTION_CLIENT_CREATION

docs/api/services-service.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,6 +2202,8 @@ components:
22022202
- RETRIGGER_REMOVE_REGISTRATION_ROLES
22032203
- RETRIGGER_SET_THEME
22042204
- RETRIGGER_SET_MEMBERSHIP
2205+
- SET_CX_MEMBERSHIP_IN_BPDM
2206+
- RETRIGGER_SET_CX_MEMBERSHIP_IN_BPDM
22052207
- TRIGGER_PROVIDER
22062208
- AWAIT_START_AUTOSETUP
22072209
- OFFERSUBSCRIPTION_CLIENT_CREATION

src/administration/Administration.Service/Controllers/RegistrationController.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,5 +726,27 @@ public async Task<NoContentResult> RetriggerSetMembership([FromRoute] Guid appli
726726
await logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.APPLICATION_ACTIVATION, ProcessStepTypeId.RETRIGGER_SET_MEMBERSHIP).ConfigureAwait(ConfigureAwaitOptions.None);
727727
return NoContent();
728728
}
729+
730+
/// <summary>
731+
/// Retriggers the last failed step
732+
/// </summary>
733+
/// <param name="applicationId" example="">Id of the application that should be triggered</param>
734+
/// <returns>NoContent</returns>
735+
/// Example: POST: api/administration/registration/application/{applicationId}/retrigger-set-cx-membership
736+
/// <response code="204">Empty response on success.</response>
737+
/// <response code="400">Either the CompanyApplication is not in status SUBMITTED or the next step can't automatically retriggered.</response>
738+
/// <response code="404">No application found for the applicationId.</response>
739+
[HttpPost]
740+
[Authorize(Roles = "approve_new_partner")]
741+
[Authorize(Policy = PolicyTypes.CompanyUser)]
742+
[Route("application/{applicationId}/retrigger-set-cx-membership")]
743+
[ProducesResponseType(StatusCodes.Status204NoContent)]
744+
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
745+
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
746+
public async Task<NoContentResult> RetriggerSetCxMembership([FromRoute] Guid applicationId)
747+
{
748+
await logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.APPLICATION_ACTIVATION, ProcessStepTypeId.RETRIGGER_SET_CX_MEMBERSHIP_IN_BPDM).ConfigureAwait(ConfigureAwaitOptions.None);
749+
return NoContent();
750+
}
729751
}
730752

src/administration/Administration.Service/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@
298298
"TokenAddress": "",
299299
"BaseAddress": "",
300300
"UseDimWallet": false,
301-
"StartSharingStateAsReady": false
301+
"StartSharingStateAsReady": false,
302+
"BusinessPartnerPoolBaseAddress": ""
302303
},
303304
"Clearinghouse": {
304305
"Username": "",

src/externalsystems/Bpdm.Library/BpdmService.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,23 @@ public async Task<BpdmSharingState> GetSharingState(Guid applicationId, Cancella
176176
throw new ServiceException($"Access to sharing state did not return a valid json response: {je.Message}");
177177
}
178178
}
179+
180+
/// <inheritdoc />
181+
public async Task<bool> SetCxMembership(string businessPartnerNumber, CancellationToken cancellationToken)
182+
{
183+
using var httpClient = await _tokenService.GetAuthorizedClient($"{typeof(BpdmService).Name}Pool", _settings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
184+
185+
var requestData = new BpdmCxMembership(
186+
new BpdmCxMembershipDto[]{
187+
new(businessPartnerNumber, true)
188+
}.AsEnumerable()
189+
);
190+
191+
async ValueTask<(bool, string?)> CreateErrorMessage(HttpResponseMessage errorResponse) =>
192+
(false, await errorResponse.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None));
193+
194+
await httpClient.PutAsJsonAsync("v6/cx-memberships", requestData, Options, cancellationToken)
195+
.CatchingIntoServiceExceptionFor("bpdm-put-cx-membership", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE, CreateErrorMessage).ConfigureAwait(false);
196+
return true;
197+
}
179198
}

src/externalsystems/Bpdm.Library/BpdmServiceSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ public class BpdmServiceSettings : KeyVaultAuthSettings
3434
public bool UseDimWallet { get; set; }
3535

3636
public bool StartSharingStateAsReady { get; set; }
37+
38+
[Required(AllowEmptyStrings = false)]
39+
public string BusinessPartnerPoolBaseAddress { get; set; } = null!;
3740
}

src/externalsystems/Bpdm.Library/DependencyInjection/BpdmServiceCollectionExtension.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ public static IServiceCollection AddBpdmService(this IServiceCollection services
3838
var sp = services.BuildServiceProvider();
3939
var settings = sp.GetRequiredService<IOptions<BpdmServiceSettings>>();
4040
var baseAddress = settings.Value.BaseAddress;
41+
var poolBaseAddress = settings.Value.BusinessPartnerPoolBaseAddress;
4142
services
4243
.AddCustomHttpClientWithAuthentication<BpdmService>(baseAddress.EndsWith('/') ? baseAddress : $"{baseAddress}/")
44+
.AddCustomHttpClientWithAuthentication<BpdmService>($"{typeof(BpdmService).Name}Pool", poolBaseAddress.EndsWith('/') ? poolBaseAddress : $"{poolBaseAddress}/")
4345
.AddTransient<IBpdmService, BpdmService>()
4446
.AddTransient<IBpdmBusinessLogic, BpdmBusinessLogic>();
4547

src/externalsystems/Bpdm.Library/IBpdmService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,12 @@ public interface IBpdmService
4444
Task<bool> SetSharingStateToReady(string externalId, CancellationToken cancellationToken);
4545
Task<BpdmLegalEntityOutputData> FetchInputLegalEntity(string externalId, CancellationToken cancellationToken);
4646
Task<BpdmSharingState> GetSharingState(Guid applicationId, CancellationToken cancellationToken);
47+
48+
/// <summary>
49+
/// Send membership information to the BPDM Pool
50+
/// </summary>
51+
/// <param name="businessPartnerNumber">The BPN to set Cx Membership</param>
52+
/// <param name="cancellationToken">Cancellation Token</param>
53+
/// <returns>Returns <c>true</c> if the service call was successful, otherwise <c>false</c></returns>
54+
Task<bool> SetCxMembership(string businessPartnerNumber, CancellationToken cancellationToken);
4755
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/********************************************************************************
2+
* Copyright (c) 2024 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Apache License, Version 2.0 which is available at
9+
* https://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations
15+
* under the License.
16+
*
17+
* SPDX-License-Identifier: Apache-2.0
18+
********************************************************************************/
19+
20+
using System.Text.Json.Serialization;
21+
namespace Org.Eclipse.TractusX.Portal.Backend.Bpdm.Library.Models;
22+
23+
/// <summary>
24+
/// Modal to send multiple data to BPDM.
25+
/// </summary>
26+
/// <param name="Memberships">List of memberships</param>
27+
public record BpdmCxMembership(
28+
[property: JsonPropertyName("memberships")] IEnumerable<BpdmCxMembershipDto> Memberships
29+
);
30+
31+
/// <summary>
32+
/// Modal to send single data to BPDM.
33+
/// </summary>
34+
/// <param name="Bpn">Business Partner Number</param>
35+
/// <param name="IsCatenaXMember">True, if BPN has added for Catena-X mambership</param>
36+
public record BpdmCxMembershipDto(
37+
[property: JsonPropertyName("bpnL")] string Bpn,
38+
[property: JsonPropertyName("isCatenaXMember")] bool IsCatenaXMember
39+
);

0 commit comments

Comments
 (0)