-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bpdm): adjust bpdm service calls to new service (#164)
* structure of bpdm service has changed, therefor the models have been aligned * feat(bpdm): Remove FetchBusinessPartner call * feat(bpdm): fix search legal-entity Refs: CPLP-2976 --------- Co-authored-by: Norbert Truchsess <[email protected]> Reviewed-By: Norbert Truchsess <[email protected]>
- Loading branch information
Showing
23 changed files
with
738 additions
and
1,503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 Microsoft and BMW Group AG | ||
* Copyright (c) 2021, 2023 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 Org.Eclipse.TractusX.Portal.Backend.Bpdm.Library.Models; | ||
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; | ||
using Org.Eclipse.TractusX.Portal.Backend.Framework.HttpClientExtensions; | ||
using System.Net.Http.Headers; | ||
using System.Net.Http.Json; | ||
using System.Text.Json; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Bpdm.Library; | ||
|
||
public class BpnAccess : IBpnAccess | ||
{ | ||
private readonly HttpClient _httpClient; | ||
private static readonly JsonSerializerOptions Options = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; | ||
|
||
public BpnAccess(IHttpClientFactory httpFactory) | ||
{ | ||
_httpClient = httpFactory.CreateClient(nameof(BpnAccess)); | ||
} | ||
|
||
public async Task<BpdmLegalEntityDto> FetchLegalEntityByBpn(string businessPartnerNumber, string token, CancellationToken cancellationToken) | ||
{ | ||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); | ||
var uri = new UriBuilder | ||
{ | ||
Path = $"pool/api/catena/legal-entities/{Uri.EscapeDataString(businessPartnerNumber)}", | ||
Query = "idType=BPN" | ||
}.Uri; | ||
var result = await _httpClient.GetAsync(uri.PathAndQuery, cancellationToken) | ||
.CatchingIntoServiceExceptionFor("bpn-fetch-legal-entity") | ||
.ConfigureAwait(false); | ||
try | ||
{ | ||
var legalEntityResponse = await result.Content.ReadFromJsonAsync<BpdmLegalEntityDto>(Options, cancellationToken).ConfigureAwait(false); | ||
if (legalEntityResponse?.Bpn == null) | ||
{ | ||
throw new ServiceException("Access to external system bpdm did not return a valid legal entity response"); | ||
} | ||
return legalEntityResponse; | ||
} | ||
catch (JsonException je) | ||
{ | ||
throw new ServiceException($"Access to external system bpdm did not return a valid json response: {je.Message}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.