Skip to content

Commit

Permalink
Merge pull request #185 from catenax-ng/cx_24.05_pcf_refactor_changes_1
Browse files Browse the repository at this point in the history
fix | pcf exchange code refactor
  • Loading branch information
almadigabor authored May 27, 2024
2 parents 926df3b + 62054bc commit a09043e
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
distribution: 'temurin'

- name: Cache maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]
## [2.4.1] - 2024-05-24

### Added
- Correction in semanticId changes in pcf.
- EDC code changes refactor.
- PCF exchange code changes refactor.
- New changes for BPDM service api access/call using EDC.
- Refactors PCF asset exchange code changes.

### Fixed
- Fix for PCF data sovereignty test.
Expand Down Expand Up @@ -343,7 +344,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Compliance with Catena-X Guidelines
- Integration with Digital Twin registry service.

[unreleased]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.4.0...main
[unreleased]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.4.1...main
[2.4.1]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.4.0...v2.4.1
[2.4.0]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.3.7...v2.4.0
[2.3.7]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.3.6...v2.3.7
[2.3.6]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.3.5...v2.3.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void pushPCFDataForApproveRequest(List<JsonObject> originalObjectList, Po
// push api call
Runnable runnable = () -> proxyRequestInterface.sendNotificationToConsumer(status,
calculatedPCFValue, request.getProductId(), request.getBpnNumber(),
request.getRequestId(), request.getMessage(), false);
request.getRequestId(), "Pushed PCF updated data", false);

new Thread(runnable).start();

Expand Down Expand Up @@ -138,7 +138,7 @@ public void markedPCFDataForPendingProviderRequestAsRequested(List<String> produ
.orElseThrow(() -> new NoDataFoundException(
"No data found for product_id " + request.getProductId()));

pcfRepositoryService.savePcfStatus(request.getRequestId(), PCFRequestStatusEnum.REQUESTED);
pcfRepositoryService.savePcfStatus(request.getRequestId(), PCFRequestStatusEnum.REQUESTED, "PCF data available please take action on request");

} catch (NoDataFoundException e) {
msg = "Unable to markedPCFDataForPendingProviderRequestAsRequested becasue pcf calculated value does not exist "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,31 +135,32 @@ public void sendNotificationToConsumer(PCFRequestStatusEnum status, JsonObject c

@SneakyThrows
private void sendNotification(JsonObject calculatedPCFValue, String productId, String bpnNumber, String requestId,
QueryDataOfferModel dtOffer, PCFRequestStatusEnum status, String message, boolean isNeedToSendRequestIdtoConsumer) {
QueryDataOfferModel dtOffer, PCFRequestStatusEnum status, String message,
boolean isNeedToSendRequestIdtoConsumer) {
String sendNotificationStatus = "";
try {
EDRCachedByIdResponse edrToken = edcAssetUrlCacheService.verifyAndGetToken(bpnNumber, dtOffer);

if (edrToken != null) {

URI pcfpushEnpoint = new URI(
edrToken.getEndpoint() + SLASH_DELIMETER + PRODUCT_IDS + SLASH_DELIMETER + productId);

Map<String, String> header = new HashMap<>();
header.put("authorization", edrToken.getAuthorization());
header.put("Edc-Bpn", bpnNumber);

String sendRequestId = requestId;
if (!isNeedToSendRequestIdtoConsumer)
sendRequestId = "";

pcfExchangeProxy.uploadPcfSubmodel(pcfpushEnpoint, header, sendRequestId, message,
jsonObjectMapper.gsonObjectToJsonNode(calculatedPCFValue));

sendNotificationStatus = "SUCCESS";
} else {
String warn="EDC connector " + dtOffer.getConnectorOfferUrl()
+ ", The EDR token is null to find pcf exchange asset";
String warn = "EDC connector " + dtOffer.getConnectorOfferUrl()
+ ", The EDR token is null to find pcf exchange asset";
log.warn(warn);
sendNotificationStatus = warn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public ResponseEntity<Object> actionOnPcfRequestAndSendNotificationToConsumer(
@GetMapping(value = "/{type}/requests")
@PreAuthorize("hasPermission('','view_pcf_history')")
public ResponseEntity<Object> getPcfProviderData(@PathVariable PCFTypeEnum type,
@RequestParam(value = "status", required = false) PCFRequestStatusEnum status, @Param("page") Integer page,
@Param("pageSize") Integer pageSize) throws Exception {
@RequestParam(value = "status", required = false) PCFRequestStatusEnum status, @RequestParam("offset") Integer page,
@RequestParam("maxLimit") Integer pageSize) throws Exception {
log.info("Request received for GET: /api/pcf/{}/requests/", type.name().toLowerCase());

page = page == null ? 0 : page;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public List<LegalEntityResponse> fetchLegalEntitiesData(String bpnLs, String sea

if (edrToken != null) {

LegalEntityData legalEntity = fetchLegalEntityDataByEdrToken(bpnLs, searchText, edcAssetConfigurableConstant.getBpdmProviderEdcPublicApi(), edrToken, page, size );
LegalEntityData legalEntity = fetchLegalEntityDataByEdrToken(bpnLs, searchText, edrToken, page, size );
legalEntityResponseList.addAll(legalEntity.getContent().stream().map(companyData ->
LegalEntityResponse.builder()
.bpn(companyData.getBpnl())
Expand All @@ -84,8 +84,7 @@ public List<LegalEntityResponse> fetchLegalEntitiesData(String bpnLs, String sea
}


private LegalEntityData fetchLegalEntityDataByEdrToken(String bpnLs, String legalName,
String bpdmProviderEdcPublicUrl, EDRCachedByIdResponse edrToken, Integer page, Integer size) {
private LegalEntityData fetchLegalEntityDataByEdrToken(String bpnLs, String legalName, EDRCachedByIdResponse edrToken, Integer page, Integer size) {

LegalEntityData legalEntityData = null;
try {
Expand Down
8 changes: 6 additions & 2 deletions modules/sde-core/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#********************************************************************************
# Copyright (c) 2022 BMW GmbH
# Copyright (c) 2022, 2023 T-Systems International GmbH
# Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
# Copyright (c) 2022,2024 T-Systems International GmbH
# Copyright (c) 2022,2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
Expand Down Expand Up @@ -104,6 +104,10 @@ partner.pool.clientId=
partner.pool.clientSecret=
partner.pool.grantType=client_credentials

bpdm.provider.edc.dataspace.api=
bpdm.provider.bpnl=
bpdm.provider.edc.public.api=


## Portal backend and Connector discovery
portal.backend.hostname=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class PcfExchangeControllerTest {
void testGetPcfConsumerDataSuccess() throws Exception {
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/pcf/{type}/requests","CONSUMER")
.param("status", "")
.param("page", String.valueOf(0))
.param("pageSize", String.valueOf(10));
.param("offset", String.valueOf(0))
.param("maxLimit", String.valueOf(10));
ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(pcfExchangeController).build()
.perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().is(200));
Expand All @@ -67,8 +67,8 @@ void testGetPcfConsumerDataSuccess() throws Exception {
void testGetPcfProviderDataSuccess() throws Exception {
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/pcf/{type}/requests","PROVIDER")
.param("status", "REQUESTED")
.param("page", String.valueOf(0))
.param("pageSize", String.valueOf(10));
.param("offset", String.valueOf(0))
.param("maxLimit", String.valueOf(10));
ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(pcfExchangeController).build()
.perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().is(200));
Expand All @@ -78,8 +78,8 @@ void testGetPcfProviderDataSuccess() throws Exception {
void testGetPcfProviderDataFailure() throws Exception {
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/pcf/{type}/requests","")
.param("status", "REQUESTED")
.param("page", String.valueOf(0))
.param("pageSize", String.valueOf(10));
.param("offset", String.valueOf(0))
.param("maxLimit", String.valueOf(10));
ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(pcfExchangeController).build()
.perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().is(404));
Expand Down Expand Up @@ -109,6 +109,17 @@ void testUploadPcfSubmodelSuccess() throws Exception {
actualPerformResult.andExpect(MockMvcResultMatchers.status().isOk());
}

@Test
void testUploadPcfSubmodelSuccessForceUpdate() throws Exception {
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.put("/pcf/productIds/{productId}","test_product")
.header("Edc-Bpn", "BPNL001000TS0100")
.contentType("application/json")
.content(getPCFJsonResponse());
ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(pcfExchangeController).build()
.perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().isOk());
}

@Test
void testUploadPcfSubmodelFailure() throws Exception {
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.put("/pcf/productIds/{productId}","test_product")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public class EDCAssetLookUp {
private String consumerHost;

private String filterExpressionTemplate = """
"filterExpression": %s""";
"filterExpression": %s
""";

public List<QueryDataOfferModel> getEDCAssetsByType(String bpnNumber, List<Criterion> filtercriteria) {

Expand All @@ -62,8 +63,8 @@ public List<QueryDataOfferModel> getEDCAssetsByType(List<ConnectorInfo> distinct

List<QueryDataOfferModel> offers = new ArrayList<>();

Gson gson = new Gson();
String filterCriteriaList = gson.toJson(filterCriteria);
Gson gson = new Gson();
String filterCriteriaList = gson.toJson(filterCriteria);
String filterExpression = String.format(filterExpressionTemplate, filterCriteriaList);

distinctList.stream().forEach(
Expand Down

0 comments on commit a09043e

Please sign in to comment.