Skip to content

Commit

Permalink
Merge pull request #211 from sachinargade123/release-pcf-2408
Browse files Browse the repository at this point in the history
PCF exchange implementation update for 2408 release
  • Loading branch information
almadigabor authored Jul 31, 2024
2 parents 008b137 + a4c9d09 commit 1c555d2
Show file tree
Hide file tree
Showing 47 changed files with 601 additions and 313 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Security config changes.
- Updated changelog and dependency file.
- Dependencies jar versions updated.
- PCF exchange changes for 2408 version.

### Fixed
- Dependabot bump jar version fixed.
- Trivy high security issue fixed for CVE-2024-34750.

### Fixed
- Dependabot bump jar version fixed.
Expand Down
1 change: 1 addition & 0 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ maven/mavencentral/org.springframework.cloud/spring-cloud-starter-openfeign/4.1.
maven/mavencentral/org.springframework.cloud/spring-cloud-starter/4.1.2, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.springframework.data/spring-data-commons/3.2.5, Apache-2.0, approved, #15202
maven/mavencentral/org.springframework.data/spring-data-jpa/3.2.5, Apache-2.0, approved, #15183
maven/mavencentral/org.springframework.retry/spring-retry/2.0.5, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.springframework.security/spring-security-config/6.1.2, Apache-2.0, approved, #9736
maven/mavencentral/org.springframework.security/spring-security-core/6.2.4, Apache-2.0, approved, #11904
maven/mavencentral/org.springframework.security/spring-security-crypto/6.2.4, Apache-2.0 AND ISC, approved, #11908
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void requestToProviderForPCFValue(String productId, StringBuilder reponse
reponseMap.append(errorMsg);
}
} catch (FeignException e) {
log.error(LogUtil.encode("FeignRequest requestToProviderForPCFValue:" + e.request()));
log.error("FeignRequest requestToProviderForPCFValue:" + e.request());
String error= StringUtils.isBlank(e.contentUTF8()) ? e.getMessage() : e.contentUTF8();
String errorMsg= "Unable to request to provider '"+ dataset.getConnectorOfferUrl()+"' for '"+productId+"' product PCF value beacuse error in remote service execution";
log.error(LogUtil.encode("FeignException requestToProviderForPCFValue: " + errorMsg + ", because: " +error));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,39 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import lombok.Getter;

import java.util.List;

@Component
@Configuration
@Getter
public class PCFAssetStaticPropertyHolder {

@Value(value = "${digital-twin.pcf.sematicid:}")
public String sematicId;

@Value(value = "${digital-twin.pcf.sematicid:}")
@Value(value = "${digital-twin.pcf.sematicid-part:}")
public String sematicIdPart;

@Value("${edc.asset.prop.type.pcfexchange.value:PcfExchange}")
private String assetPropTypePCFExchangeType;

@Value("${edc.policy.pcf.access:tx:BusinessPartnerGroup@odrl:eq@pcf-business-partner-group;Membership@active}")
private String pcfExchangeAccessPolicy;

private String pcfExchangeAssetId;
@Value("#{'${edc.policy.pcf.bpn:}'.split(',')}")
private List<String> whiteListBusinessList;
private static String PCF_BG = "pcf-business-partner-group";

@Value("${edc.policy.pcf.usage:FrameworkAgreement@DataExchangeGovernance:1.0;Membership@active;[email protected]:1}")
private String pcfExchangeUsagePolicy;

private String pcfExchangeAssetId;

public String getSematicId() {
if (StringUtils.isAllBlank(sematicId))
sematicId = "urn:samm:io.catenax.pcf:6.0.0#Pcf";
sematicId = "urn:samm:io.catenax.pcf:7.0.0#Pcf";
return sematicId;
}

Expand All @@ -63,5 +81,9 @@ public String getPcfExchangeAssetId() {
public void setPcfExchangeAssetId(String pcfExchangeAssetId) {
this.pcfExchangeAssetId = pcfExchangeAssetId;
}

public String getPcfBusinessPartnerGroup() {
return PCF_BG;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
public class Policies {

private String technicalKey;
private String operator;
private List<String> value;

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PolicyOperationUtil {
private PolicyOperationUtil() {
}

private static List<String> getBPNList(List<Policies> policies) {
public static List<String> getBPNList(List<Policies> policies) {
return policies.stream().filter(e -> e.getTechnicalKey().equals(BUSINESS_PARTNER_NUMBER))
.flatMap(e -> e.getValue().stream().filter(StringUtils::isNotBlank)).toList();
}
Expand All @@ -54,7 +54,12 @@ public static List<Policies> getStringPolicyAsPolicyList(String policyStr){
String[] split = policyStr.split(";");
for (int i = 0; i < split.length; i++) {
String[] split1 = split[i].split("@");
if (split1.length == 2) {

if (split1.length == 3) {
policies.add(Policies.builder().technicalKey(split1[0]).operator(split1[1]).value(List.of(split1[2])).build());
}

else if (split1.length == 2) {
policies.add(Policies.builder().technicalKey(split1[0]).value(List.of(split1[1])).build());
}
}
Expand Down
9 changes: 7 additions & 2 deletions modules/sde-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down Expand Up @@ -187,13 +191,13 @@
<artifactId>pcf</artifactId>
<version>0.0.1</version>
</dependency>

<dependency>
<groupId>org.eclipse.tractusx</groupId>
<artifactId>pcf-exchange</artifactId>
<version>0.0.1</version>
</dependency>

<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
Expand Down Expand Up @@ -222,6 +226,7 @@
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;


@SpringBootApplication(exclude = {UserDetailsServiceAutoConfiguration.class})
@EnableFeignClients
@EnableAsync
@EnableRetry
@ImportAutoConfiguration({FeignAutoConfiguration.class})
@EnableCaching
@EnableScheduling
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/********************************************************************************
* Copyright (c) 2023,2024 T-Systems International GmbH
* Copyright (c) 2023,2024 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
********************************************************************************/

package org.eclipse.tractusx.sde.configuration;

import java.util.List;

import org.eclipse.tractusx.sde.core.service.PartnerPoolService;
import org.eclipse.tractusx.sde.portal.model.response.LegalEntityResponse;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
@RequiredArgsConstructor
@Profile("default")
public class BPDMExchangeAssetConsumer {

private final PartnerPoolService partnerPoolService;

@PostConstruct
@SneakyThrows
public void init() {
try {
List<LegalEntityResponse> legalEntitiesResponse = partnerPoolService.fetchLegalEntitiesData(null, "test", 0,
10);
log.info("BPDM service ready to use, 'test' company found leagal entity =>" + legalEntitiesResponse.size());
} catch (Exception e) {
log.error("Unable to perform auto negotiation for BPDM service for legal entiry search");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.eclipse.tractusx.sde.common.utils.PolicyOperationUtil;
import org.eclipse.tractusx.sde.common.utils.UUIdGenerator;
import org.eclipse.tractusx.sde.core.utils.ValueReplacerUtility;
import org.eclipse.tractusx.sde.edc.constants.EDCAssetConfigurableConstant;
import org.eclipse.tractusx.sde.edc.constants.EDCAssetConstant;
import org.eclipse.tractusx.sde.edc.entities.request.asset.AssetEntryRequest;
import org.eclipse.tractusx.sde.edc.entities.request.asset.AssetEntryRequestFactory;
Expand Down Expand Up @@ -61,7 +60,6 @@ public class PCFExchangeAssetProvider {
private final CreateEDCAssetFacilator createEDCAssetFacilator;
private final ValueReplacerUtility valueReplacerUtility;
private final SDEConfigurationProperties sdeConfigurationProperties;
private final EDCAssetConfigurableConstant edcAssetConfigurableConstant;
private final PCFAssetStaticPropertyHolder pcfAssetStaticPropertyHolder;

@PostConstruct
Expand All @@ -70,7 +68,7 @@ public void init() {

String assetId = UUIdGenerator.getUuid();
AssetEntryRequest assetEntryRequest = assetFactory.getAssetRequest("", "PCF Exchange endpoint information",
assetId, "1", "", "", pcfAssetStaticPropertyHolder.getSematicId(), edcAssetConfigurableConstant.getAssetPropTypePCFExchangeType());
assetId, "1", "", "", pcfAssetStaticPropertyHolder.getSematicId(), pcfAssetStaticPropertyHolder.getAssetPropTypePCFExchangeType());

String baseUrl = sdeConfigurationProperties.getSdeHostname() + "/pcf";
assetEntryRequest.getDataAddress().getProperties().put("baseUrl", baseUrl);
Expand All @@ -81,7 +79,7 @@ public void init() {
Map<String, String> inputData = new HashMap<>();
inputData.put("baseUrl", baseUrl);
inputData.put(REGISTRY_TYPE, REGISTRY_TYPE);
inputData.put("assetType", edcAssetConfigurableConstant.getAssetPropTypePCFExchangeType());
inputData.put("assetType", pcfAssetStaticPropertyHolder.getAssetPropTypePCFExchangeType());

ObjectNode requestBody = (ObjectNode) new ObjectMapper().readTree(valueReplacerUtility
.valueReplacerUsingFileTemplate("/edc_request_template/edc_asset_lookup.json", inputData));
Expand All @@ -91,12 +89,19 @@ public void init() {
if (assetExistsLookupBasedOnTypeGetAsAsset == null ||
assetExistsLookupBasedOnTypeGetAsAsset.isNull() ||
(assetExistsLookupBasedOnTypeGetAsAsset.isArray() && assetExistsLookupBasedOnTypeGetAsAsset.isEmpty())) {


List<String> pcfBPNList = pcfAssetStaticPropertyHolder.getWhiteListBusinessList();

//iterate over pcfBPNList and create business partner group
for (String pcfBPN : pcfBPNList) {
edcGateway.addBPNintoPCFBusinessPartnerGroup(pcfBPN, pcfAssetStaticPropertyHolder.getPcfBusinessPartnerGroup());
}

List<Policies> accessPolicy = PolicyOperationUtil
.getStringPolicyAsPolicyList(edcAssetConfigurableConstant.getPcfExcahngeAccessPolicy());
.getStringPolicyAsPolicyList(pcfAssetStaticPropertyHolder.getPcfExchangeAccessPolicy());

List<Policies> usagePolicy = PolicyOperationUtil
.getStringPolicyAsPolicyList(edcAssetConfigurableConstant.getPcfExcahngeUsagePolicy());
.getStringPolicyAsPolicyList(pcfAssetStaticPropertyHolder.getPcfExchangeUsagePolicy());

PolicyModel policy= PolicyModel.builder()
.accessPolicies(accessPolicy)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public SubmodelRegistration(SubmodelCustomHistoryGenerator submodelCustomHistory
}

@SneakyThrows
public void register(SubmodelExtension subomdelService) {
Submodel submodel = subomdelService.submodel();
log.info(submodel.toString());
public void register(SubmodelExtension submodelService) {
Submodel submodel = submodelService.submodel();
log.debug(submodel.toString());


List<String> columns = submoduleUtility.getTableColomnHeader(submodel);
Expand All @@ -74,7 +74,7 @@ public void register(SubmodelExtension subomdelService) {

submodelCustomHistoryGenerator.checkTableIfNotExistCreate(submodel.getSchema(), columns, tableName, pkCol, databaseIdentifierCols);
}

log.info(submodel.getSchema().get("id") + " sub model registered successfully");
submodelList.add(submodel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public Map<String, Object> subscribeAndDownloadDataOffers(ConsumerRequest consum
// Save consumer Download history in DB
consumerDownloadHistoryRepository.save(entity);

ActionRequest action = policyConstraintBuilderService
List<ActionRequest> action = policyConstraintBuilderService
.getUsagePoliciesConstraints(consumerRequest.getUsagePolicies());

entry.getValue().parallelStream().forEach(offer -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package org.eclipse.tractusx.sde.core.service;

import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -91,8 +92,9 @@ private LegalEntityData fetchLegalEntityDataByEdrToken(String bpnLs, String lega

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

legalEntityData = partnerPoolExternalServiceApi.fetchLegalEntityData(bpnLs, legalName, page, size, header);
URI endpoint = new URI(edrToken.getEndpoint());

legalEntityData = partnerPoolExternalServiceApi.fetchLegalEntityData(endpoint, bpnLs, legalName, page, size, header);

} catch (FeignException e) {
String err = e.contentUTF8();
Expand Down
Loading

0 comments on commit 1c555d2

Please sign in to comment.