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

chore(CxMembership): Set Catena-X Membership in BPDM #1118

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
34 changes: 34 additions & 0 deletions docs/api/administration-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4257,6 +4257,38 @@ paths:
description: Internal Server Error
'401':
description: The User is unauthorized
'/api/administration/registration/application/{applicationId}/retrigger-set-cx-membership':
post:
tags:
- Registration
summary: 'Retriggers the last failed step (Authorization required - Roles: approve_new_partner)'
parameters:
- name: applicationId
in: path
description: Id of the application that should be triggered
required: true
schema:
type: string
format: uuid
responses:
'204':
description: Empty response on success.
'400':
description: Either the CompanyApplication is not in status SUBMITTED or the next step can't automatically retriggered.
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: No application found for the applicationId.
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal Server Error
'401':
description: The User is unauthorized
/api/administration/RegistrationStatus/callback:
get:
tags:
Expand Down Expand Up @@ -7529,6 +7561,8 @@ components:
- RETRIGGER_REMOVE_REGISTRATION_ROLES
- RETRIGGER_SET_THEME
- RETRIGGER_SET_MEMBERSHIP
- SET_CX_MEMBERSHIP_IN_BPDM
- RETRIGGER_SET_CX_MEMBERSHIP_IN_BPDM
- TRIGGER_PROVIDER
- AWAIT_START_AUTOSETUP
- OFFERSUBSCRIPTION_CLIENT_CREATION
Expand Down
2 changes: 2 additions & 0 deletions docs/api/apps-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3564,6 +3564,8 @@ components:
- RETRIGGER_REMOVE_REGISTRATION_ROLES
- RETRIGGER_SET_THEME
- RETRIGGER_SET_MEMBERSHIP
- SET_CX_MEMBERSHIP_IN_BPDM
- RETRIGGER_SET_CX_MEMBERSHIP_IN_BPDM
- TRIGGER_PROVIDER
- AWAIT_START_AUTOSETUP
- OFFERSUBSCRIPTION_CLIENT_CREATION
Expand Down
2 changes: 2 additions & 0 deletions docs/api/services-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,8 @@ components:
- RETRIGGER_REMOVE_REGISTRATION_ROLES
- RETRIGGER_SET_THEME
- RETRIGGER_SET_MEMBERSHIP
- SET_CX_MEMBERSHIP_IN_BPDM
- RETRIGGER_SET_CX_MEMBERSHIP_IN_BPDM
- TRIGGER_PROVIDER
- AWAIT_START_AUTOSETUP
- OFFERSUBSCRIPTION_CLIENT_CREATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,5 +726,27 @@ public async Task<NoContentResult> RetriggerSetMembership([FromRoute] Guid appli
await logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.APPLICATION_ACTIVATION, ProcessStepTypeId.RETRIGGER_SET_MEMBERSHIP).ConfigureAwait(ConfigureAwaitOptions.None);
return NoContent();
}

/// <summary>
/// Retriggers the last failed step
/// </summary>
/// <param name="applicationId" example="">Id of the application that should be triggered</param>
/// <returns>NoContent</returns>
/// Example: POST: api/administration/registration/application/{applicationId}/retrigger-set-cx-membership
/// <response code="204">Empty response on success.</response>
/// <response code="400">Either the CompanyApplication is not in status SUBMITTED or the next step can't automatically retriggered.</response>
/// <response code="404">No application found for the applicationId.</response>
[HttpPost]
[Authorize(Roles = "approve_new_partner")]
[Authorize(Policy = PolicyTypes.CompanyUser)]
[Route("application/{applicationId}/retrigger-set-cx-membership")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
public async Task<NoContentResult> RetriggerSetCxMembership([FromRoute] Guid applicationId)
{
await logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.APPLICATION_ACTIVATION, ProcessStepTypeId.RETRIGGER_SET_CX_MEMBERSHIP_IN_BPDM).ConfigureAwait(ConfigureAwaitOptions.None);
return NoContent();
}
}

3 changes: 2 additions & 1 deletion src/administration/Administration.Service/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@
"TokenAddress": "",
"BaseAddress": "",
"UseDimWallet": false,
"StartSharingStateAsReady": false
"StartSharingStateAsReady": false,
"BusinessPartnerPoolBaseAddress": ""
},
"Clearinghouse": {
"Username": "",
Expand Down
20 changes: 20 additions & 0 deletions src/externalsystems/Bpdm.Library/BpdmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Org.Eclipse.TractusX.Portal.Backend.Framework.HttpClientExtensions;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Token;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

Expand Down Expand Up @@ -176,4 +177,23 @@ public async Task<BpdmSharingState> GetSharingState(Guid applicationId, Cancella
throw new ServiceException($"Access to sharing state did not return a valid json response: {je.Message}");
}
}

/// <inheritdoc />
public async Task<bool> SetCxMembership(string businessPartnerNumber, CancellationToken cancellationToken)
{
using var httpClient = await _tokenService.GetAuthorizedClient<BpdmService>(_settings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);

// Same User (which we have for BPDM service) can be used to call Business Partner Pool
// But BaseAddress of Business Partner Pool is different as its deployed on another server.
httpClient.BaseAddress = new Uri(_settings.BusinessPartnerPoolBaseAddress);
Copy link
Contributor

@ntruchsess ntruchsess Nov 20, 2024

Choose a reason for hiding this comment

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

(while technically working) this is not how a httpClientFactory (which is used in tokenService) should be used. The service-code should not have to deal with the baseAddress.


var requestData = new BpdmCxMembership([new(businessPartnerNumber, true)]);

async ValueTask<(bool, string?)> CreateErrorMessage(HttpResponseMessage errorResponse) =>
(false, await errorResponse.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None));

await httpClient.PutAsJsonAsync("v6/cx-memberships", requestData, Options, cancellationToken)
.CatchingIntoServiceExceptionFor("bpdm-put-cx-membership", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE, CreateErrorMessage).ConfigureAwait(false);
return true;
}
}
3 changes: 3 additions & 0 deletions src/externalsystems/Bpdm.Library/BpdmServiceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ public class BpdmServiceSettings : KeyVaultAuthSettings
public bool UseDimWallet { get; set; }

public bool StartSharingStateAsReady { get; set; }

[Required(AllowEmptyStrings = false)]
public string BusinessPartnerPoolBaseAddress { get; set; } = null!;
}
8 changes: 8 additions & 0 deletions src/externalsystems/Bpdm.Library/IBpdmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ public interface IBpdmService
Task<bool> SetSharingStateToReady(string externalId, CancellationToken cancellationToken);
Task<BpdmLegalEntityOutputData> FetchInputLegalEntity(string externalId, CancellationToken cancellationToken);
Task<BpdmSharingState> GetSharingState(Guid applicationId, CancellationToken cancellationToken);

/// <summary>
/// Send membership information to the BPDM Pool
/// </summary>
/// <param name="businessPartnerNumber">The BPN to set Cx Membership</param>
/// <param name="cancellationToken">Cancellation Token</param>
/// <returns>Returns <c>true</c> if the service call was successful, otherwise <c>false</c></returns>
Task<bool> SetCxMembership(string businessPartnerNumber, CancellationToken cancellationToken);
}
39 changes: 39 additions & 0 deletions src/externalsystems/Bpdm.Library/Models/BpdmCxMembershipDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using System.Text.Json.Serialization;
namespace Org.Eclipse.TractusX.Portal.Backend.Bpdm.Library.Models;

/// <summary>
/// Modal to send multiple data to BPDM.
/// </summary>
/// <param name="Memberships">List of memberships</param>
public record BpdmCxMembership(
[property: JsonPropertyName("memberships")] IEnumerable<BpdmCxMembershipDto> Memberships
);

/// <summary>
/// Modal to send single data to BPDM.
/// </summary>
/// <param name="Bpn">Business Partner Number</param>
/// <param name="IsCatenaXMember">True, if BPN has added for Catena-X mambership</param>
public record BpdmCxMembershipDto(
[property: JsonPropertyName("bpnL")] string Bpn,
[property: JsonPropertyName("isCatenaXMember")] bool IsCatenaXMember
);
Loading
Loading