From d3483221049596964c77ba0ca07ced98d3e8910f Mon Sep 17 00:00:00 2001 From: jhartmann Date: Wed, 15 May 2024 12:39:47 +0200 Subject: [PATCH 01/12] feat(registry):[#616] Add new filter type for digital twin registry catalog request --- CHANGELOG.md | 7 +++ .../configuration/RegistryConfiguration.java | 4 +- .../irs/IrsWireMockIntegrationTest.java | 4 +- .../irs/edc/client/EdcSubmodelClient.java | 7 ++- .../irs/edc/client/EdcSubmodelClientImpl.java | 57 +++++++++++++++-- .../client/EdcSubmodelClientLocalStub.java | 6 ++ .../irs/edc/client/EdcSubmodelFacade.java | 10 +-- .../irs/edc/client/asset/EdcAssetService.java | 15 ++++- .../configuration/JsonLdConfiguration.java | 2 + .../irs/edc/client/EdcSubmodelFacadeTest.java | 11 ++-- .../edc/client/asset/EdcAssetServiceTest.java | 61 ++++++++++++++++++- .../registryclient/DefaultConfiguration.java | 4 +- .../EdcEndpointReferenceRetriever.java | 5 +- .../EndpointDataForConnectorsService.java | 5 +- .../DefaultConfigurationTest.java | 6 +- ...igitalTwinRegistryServiceWiremockTest.java | 27 +++----- .../EndpointDataForConnectorsServiceTest.java | 15 ++--- .../testing/testdata/transform-and-upload.py | 5 +- 18 files changed, 183 insertions(+), 68 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbf686da6e..29e1382ab9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ _**For better traceability add the corresponding GitHub issue number in each cha ## [Unreleased] +### Fixed + +- IRS now searches for Digital Twin Registry contract offers by + type `dct:type`: `https://w3id.org/catenax/taxonomy#DigitalTwinRegistry` + or `edc:type`: `data.core.digitalTwinRegistry`. #616 + + ## [5.1.2] - 2024-05-13 ### Fixed diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java index 936aa6ebbc..032758c0ab 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java @@ -76,9 +76,9 @@ public DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService( @Value("${digitalTwinRegistry.lookupShellsTemplate:}") final String lookupShellsTemplate, final EdcConfiguration edcConfiguration) { - final EdcEndpointReferenceRetriever endpointReferenceRetriever = (edcConnectorEndpoint, assetType, assetValue, bpn) -> { + final EdcEndpointReferenceRetriever endpointReferenceRetriever = (edcConnectorEndpoint, bpn) -> { try { - return facade.getEndpointReferencesForAsset(edcConnectorEndpoint, assetType, assetValue, bpn); + return facade.getEndpointReferencesForRegistryAsset(edcConnectorEndpoint, bpn); } catch (EdcClientException e) { throw new EdcRetrieverException(e); } diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java index 562083bfac..0a27cfe1c9 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java @@ -180,7 +180,7 @@ void shouldStopJobAfterDepthIsReached() { // Assert WiremockSupport.verifyDiscoveryCalls(1); - WiremockSupport.verifyNegotiationCalls(3); + WiremockSupport.verifyNegotiationCalls(5); assertThat(jobForJobId.getJob().getState()).isEqualTo(JobState.COMPLETED); assertThat(jobForJobId.getShells()).hasSize(2); @@ -273,7 +273,7 @@ void shouldStartRecursiveProcesses() { assertThat(jobForJobId.getSubmodels()).hasSize(6); WiremockSupport.verifyDiscoveryCalls(1); - WiremockSupport.verifyNegotiationCalls(6); + WiremockSupport.verifyNegotiationCalls(9); } private void successfulRegistryAndDataRequest(final String globalAssetId, final String idShort, final String bpn, diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClient.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClient.java index b1222f6f43..357492ade0 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClient.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClient.java @@ -37,7 +37,9 @@ /** * Public API facade for EDC domain */ -@SuppressWarnings({"PMD.ExcessiveImports", "PMD.UseObjectForClearerAPI"}) +@SuppressWarnings({ "PMD.ExcessiveImports", + "PMD.UseObjectForClearerAPI" +}) public interface EdcSubmodelClient { CompletableFuture getSubmodelPayload(String connectorEndpoint, String submodelDataplaneUrl, @@ -52,5 +54,8 @@ List> getEndpointReferencesForAsset(Str List> getEndpointReferencesForAsset(String endpointAddress, String filterKey, String filterValue, EndpointDataReferenceStatus cachedEndpointDataReference, String bpn) throws EdcClientException; + + List> getEndpointReferencesForRegistryAsset(String endpointAddress, + String bpn) throws EdcClientException; } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java index 0abebaabdd..e89fd22497 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java @@ -27,6 +27,7 @@ import static org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration.NAMESPACE_EDC_ID; import java.net.URI; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -52,6 +53,7 @@ import org.eclipse.tractusx.irs.edc.client.model.notification.EdcNotificationResponse; import org.eclipse.tractusx.irs.edc.client.model.notification.NotificationContent; import org.eclipse.tractusx.irs.edc.client.util.Masker; +import org.jetbrains.annotations.NotNull; import org.springframework.util.StopWatch; /** @@ -65,6 +67,11 @@ }) public class EdcSubmodelClientImpl implements EdcSubmodelClient { + private static final String DT_DCAT_TYPE_ID = "'https://purl.org/dc/terms/type'.'@id'"; + private static final String DT_TAXONOMY_REGISTRY = "https://w3id.org/catenax/taxonomy#DigitalTwinRegistry"; + private static final String DT_EDC_TYPE = "https://w3id.org/edc/v0.0.1/ns/type"; + private static final String DT_DATA_CORE_REGISTRY = "data.core.digitalTwinRegistry"; + private final EdcConfiguration config; private final ContractNegotiationService contractNegotiationService; private final EdcDataPlaneClient edcDataPlaneClient; @@ -99,8 +106,7 @@ private Optional retrieveSubmodelData(final String submodelD final String payload = edcDataPlaneClient.getData(endpointDataReference, submodelDataplaneUrl); stopWatchOnEdcTask(stopWatch); - return Optional.of( - new SubmodelDescriptor(endpointDataReference.getContractId(), payload)); + return Optional.of(new SubmodelDescriptor(endpointDataReference.getContractId(), payload)); } return Optional.empty(); @@ -234,11 +240,17 @@ public List> getEndpointReferencesForAs endpointAddress, filterKey, filterValue)); } - // We need to process each contract offer in parallel - // (see src/docs/arc42/cross-cutting/discovery-DTR--multiple-EDCs-with-multiple-DTRs.puml - // and src/docs/arc42/cross-cutting/discovery-DTR--multiple-EDCs-with-multiple-DTRs--detailed.puml) - return contractOffers.stream().map(contractOffer -> { + return createCompletableFuturesForContractOffers(endpointDataReferenceStatus, bpn, contractOffers, + providerWithSuffix, stopWatch); + } + // We need to process each contract offer in parallel + // (see src/docs/arc42/cross-cutting/discovery-DTR--multiple-EDCs-with-multiple-DTRs.puml + // and src/docs/arc42/cross-cutting/discovery-DTR--multiple-EDCs-with-multiple-DTRs--detailed.puml) + private @NotNull List> createCompletableFuturesForContractOffers( + final EndpointDataReferenceStatus endpointDataReferenceStatus, final String bpn, + final List contractOffers, final String providerWithSuffix, final StopWatch stopWatch) { + return contractOffers.stream().map(contractOffer -> { final NegotiationResponse negotiationResponse; try { negotiationResponse = negotiateContract(endpointDataReferenceStatus, contractOffer, providerWithSuffix, @@ -262,6 +274,39 @@ public List> getEndpointReferencesForAs }).toList(); } + @Override + public List> getEndpointReferencesForRegistryAsset( + final String endpointAddress, final String bpn) throws EdcClientException { + return execute(endpointAddress, () -> getEndpointReferencesForRegistryAsset(endpointAddress, + new EndpointDataReferenceStatus(null, TokenStatus.REQUIRED_NEW), bpn)); + } + + public List> getEndpointReferencesForRegistryAsset( + final String endpointAddress, final EndpointDataReferenceStatus endpointDataReferenceStatus, + final String bpn) throws EdcClientException { + final StopWatch stopWatch = new StopWatch(); + stopWatch.start("Get EndpointDataReference task for shell descriptor, endpoint " + endpointAddress); + final String providerWithSuffix = appendSuffix(endpointAddress, config.getControlplane().getProviderSuffix()); + + // CatalogItem = contract offer + final List contractOffers = new ArrayList<>( + catalogFacade.fetchCatalogByFilter(providerWithSuffix, DT_DCAT_TYPE_ID, DT_TAXONOMY_REGISTRY, bpn)); + + final List contractOffersDataCore = catalogFacade.fetchCatalogByFilter(providerWithSuffix, + DT_EDC_TYPE, DT_DATA_CORE_REGISTRY, bpn); + contractOffers.addAll(contractOffersDataCore); + + if (contractOffers.isEmpty()) { + throw new EdcClientException( + "No DigitalTwinRegistry contract offers found for endpointAddress '%s' filterKey '%s', filterValue '%s' or filterKey '%s', filterValue '%s'".formatted( + endpointAddress, DT_DCAT_TYPE_ID, DT_TAXONOMY_REGISTRY, DT_EDC_TYPE, + DT_DATA_CORE_REGISTRY)); + } + + return createCompletableFuturesForContractOffers(endpointDataReferenceStatus, bpn, contractOffers, + providerWithSuffix, stopWatch); + } + private NegotiationResponse negotiateContract(final EndpointDataReferenceStatus endpointDataReferenceStatus, final CatalogItem catalogItem, final String providerWithSuffix, final String bpn) throws EdcClientException { diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientLocalStub.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientLocalStub.java index 9ac58b2bd1..d0f2898cfb 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientLocalStub.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientLocalStub.java @@ -81,4 +81,10 @@ public List> getEndpointReferencesForAs final String filterKey, final String filterValue, final String bpn) throws EdcClientException { throw new EdcClientException("Not implemented"); } + + @Override + public List> getEndpointReferencesForRegistryAsset( + final String endpointAddress, final String bpn) throws EdcClientException { + throw new EdcClientException("Not implemented"); + } } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelFacade.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelFacade.java index e99107d1de..8913c52127 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelFacade.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelFacade.java @@ -43,7 +43,9 @@ */ @Slf4j @RequiredArgsConstructor -@SuppressWarnings({"PMD.AvoidDuplicateLiterals", "PMD.UseObjectForClearerAPI"}) +@SuppressWarnings({ "PMD.AvoidDuplicateLiterals", + "PMD.UseObjectForClearerAPI" +}) public class EdcSubmodelFacade { private final EdcSubmodelClient client; @@ -93,9 +95,9 @@ public EdcNotificationResponse sendNotification(final String submodelEndpointAdd } } - public List> getEndpointReferencesForAsset(final String endpointAddress, - final String filterKey, final String filterValue, final String bpn) throws EdcClientException { - return client.getEndpointReferencesForAsset(endpointAddress, filterKey, filterValue, bpn); + public List> getEndpointReferencesForRegistryAsset( + final String endpointAddress, final String bpn) throws EdcClientException { + return client.getEndpointReferencesForRegistryAsset(endpointAddress, bpn); } } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java index 4691f5226b..97d9c4d567 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java @@ -63,9 +63,15 @@ public class EdcAssetService { private static final String ASSET_CREATION_PROPERTY_DESCRIPTION = "https://w3id.org/edc/v0.0.1/ns/description"; private static final String ASSET_CREATION_PROPERTY_CONTENT_TYPE = "https://w3id.org/edc/v0.0.1/ns/contenttype"; private static final String ASSET_CREATION_PROPERTY_POLICY_ID = "https://w3id.org/edc/v0.0.1/ns/policy-id"; - private static final String ASSET_CREATION_PROPERTY_TYPE = "https://w3id.org/edc/v0.0.1/ns/type"; + private static final String ASSET_CREATION_PROPERTY_EDC_TYPE = "https://w3id.org/edc/v0.0.1/ns/type"; + private static final String ASSET_CREATION_PROPERTY_DATA_CORE_REGISTRY = "data.core.digitalTwinRegistry"; + private static final String ASSET_CREATION_PROPERTY_DCAT_TYPE = "https://purl.org/dc/terms/type"; + private static final String ASSET_CREATION_PROPERTY_DCAT_REGISTRY = "https://w3id.org/catenax/taxonomy#DigitalTwinRegistry"; + private static final String ASSET_CREATION_PROPERTY_COMMON_VERSION_KEY = "https://w3id.org/catenax/ontology/common#version"; + private static final String ASSET_CREATION_PROPERTY_COMMON_VERSION_VALUE = "3.0"; private static final String ASSET_CREATION_PROPERTY_NOTIFICATION_TYPE = "https://w3id.org/edc/v0.0.1/ns/notificationtype"; private static final String ASSET_CREATION_PROPERTY_NOTIFICATION_METHOD = "https://w3id.org/edc/v0.0.1/ns/notificationmethod"; + public static final String DATA_ADDRESS_TYPE_HTTP_DATA = "HttpData"; private final EdcTransformer edcTransformer; @@ -128,7 +134,7 @@ private Asset createNotificationAssetRequest(final String assetName, final Strin final String assetId = UUID.randomUUID().toString(); final Map properties = Map.of(ASSET_CREATION_PROPERTY_DESCRIPTION, assetName, ASSET_CREATION_PROPERTY_CONTENT_TYPE, DEFAULT_CONTENT_TYPE, ASSET_CREATION_PROPERTY_POLICY_ID, - DEFAULT_POLICY_ID, ASSET_CREATION_PROPERTY_TYPE, notificationType.getValue(), + DEFAULT_POLICY_ID, ASSET_CREATION_PROPERTY_EDC_TYPE, notificationType.getValue(), ASSET_CREATION_PROPERTY_NOTIFICATION_TYPE, notificationType.getValue(), ASSET_CREATION_PROPERTY_NOTIFICATION_METHOD, notificationMethod.getValue()); @@ -153,7 +159,10 @@ private Asset createNotificationAssetRequest(final String assetName, final Strin private Asset createDtrAssetRequest(final String assetId, final String baseUrl) { final Map properties = Map.of(ASSET_CREATION_PROPERTY_DESCRIPTION, - "Digital Twin Registry Asset", ASSET_CREATION_PROPERTY_TYPE, "data.core.digitalTwinRegistry"); + "Digital Twin Registry Asset", ASSET_CREATION_PROPERTY_EDC_TYPE, + ASSET_CREATION_PROPERTY_DATA_CORE_REGISTRY, ASSET_CREATION_PROPERTY_COMMON_VERSION_KEY, + ASSET_CREATION_PROPERTY_COMMON_VERSION_VALUE, ASSET_CREATION_PROPERTY_DCAT_TYPE, + Map.of("@id", ASSET_CREATION_PROPERTY_DCAT_REGISTRY)); final DataAddress dataAddress = DataAddress.Builder.newInstance() .type("DataAddress") diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfiguration.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfiguration.java index f4684299eb..299e981343 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfiguration.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfiguration.java @@ -53,6 +53,7 @@ public class JsonLdConfiguration { public static final String NAMESPACE_TRACTUSX = "https://w3id.org/tractusx/v0.0.1/ns/"; public static final String NAMESPACE_DCT = "https://purl.org/dc/terms/"; public static final String JSON_LD_OBJECT_MAPPER = "jsonLdObjectMapper"; + public static final String NAMESPACE_CATENAX_ONTOLOGY_COMMON = "https://w3id.org/catenax/ontology/common#"; @Bean /* package */ TitaniumJsonLd titaniumJsonLd(final Monitor monitor) { final TitaniumJsonLd titaniumJsonLd = new TitaniumJsonLd(monitor); @@ -62,6 +63,7 @@ public class JsonLdConfiguration { titaniumJsonLd.registerNamespace("edc", NAMESPACE_EDC); titaniumJsonLd.registerNamespace("dcat", JsonLdConfiguration.NAMESPACE_DCAT); titaniumJsonLd.registerNamespace("dspace", NAMESPACE_DSPACE); + titaniumJsonLd.registerNamespace("cx-common", NAMESPACE_CATENAX_ONTOLOGY_COMMON); return titaniumJsonLd; } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelFacadeTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelFacadeTest.java index 95f81b1fc7..3f229e5fa1 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelFacadeTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelFacadeTest.java @@ -60,7 +60,7 @@ class EdcSubmodelFacadeTest { @Mock private EdcSubmodelClient client; - private EdcConfiguration config = new EdcConfiguration(); + private final EdcConfiguration config = new EdcConfiguration(); @BeforeEach public void beforeEach() { @@ -174,10 +174,10 @@ class GetEndpointReferencesForAssetTests { void shouldThrowEdcClientExceptionForEndpointReference() throws EdcClientException { // arrange final EdcClientException e = new EdcClientException("test"); - when(client.getEndpointReferencesForAsset(any(), any(), any(), any())).thenThrow(e); + when(client.getEndpointReferencesForRegistryAsset(any(), any())).thenThrow(e); // act - ThrowableAssert.ThrowingCallable action = () -> testee.getEndpointReferencesForAsset("", "", "", ""); + ThrowableAssert.ThrowingCallable action = () -> testee.getEndpointReferencesForRegistryAsset("", ""); // assert assertThatThrownBy(action).isInstanceOf(EdcClientException.class); @@ -187,12 +187,11 @@ void shouldThrowEdcClientExceptionForEndpointReference() throws EdcClientExcepti void shouldReturnFailedFuture() throws EdcClientException { // arrange - when(client.getEndpointReferencesForAsset(any(), any(), any(), any())).thenReturn( + when(client.getEndpointReferencesForRegistryAsset(any(), any())).thenReturn( List.of(CompletableFuture.failedFuture(new EdcClientException("test")))); // act - final List> results = testee.getEndpointReferencesForAsset("", "", - "", ""); + final List> results = testee.getEndpointReferencesForRegistryAsset("", ""); // assert assertThat(results).hasSize(1); diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java index 48d0aec6e4..580e8da43a 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java @@ -29,7 +29,6 @@ import java.util.Map; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -88,6 +87,7 @@ void setUp() { jsonLd.registerNamespace("edc", "https://w3id.org/edc/v0.0.1/ns/"); jsonLd.registerNamespace("dcat", "https://www.w3.org/ns/dcat/"); jsonLd.registerNamespace("dspace", "https://w3id.org/dspace/v0.8/"); + jsonLd.registerNamespace("cx-common", "https://w3id.org/catenax/ontology/common#"); this.edcTransformer = new EdcTransformer(objectMapper(), jsonLd, new TypeTransformerRegistryImpl()); this.service = new EdcAssetService(edcTransformer, edcConfiguration, restTemplate); @@ -153,6 +153,65 @@ void testAssetCreateRequestStructure() throws JSONException { """, jsonObject.toString(), false); } + @Test + void testRegistryAssetCreateRequestStructure() throws JSONException { + + Map properties = Map.of("https://purl.org/dc/terms/type", + Map.of("@id", "https://w3id.org/catenax/taxonomy#DigitalTwinRegistry"), + "https://w3id.org/catenax/ontology/common#version", "3.0", "https://w3id.org/edc/v0.0.1/ns/type", + "data.core.digitalTwinRegistry"); + + DataAddress dataAddress = DataAddress.Builder.newInstance() + .type(DATA_ADDRESS_TYPE_HTTP_DATA) + .property("https://w3id.org/edc/v0.0.1/ns/type", "HttpData") + .property("https://w3id.org/edc/v0.0.1/ns/baseUrl", + "https://test.dtr/registry") + .property("https://w3id.org/edc/v0.0.1/ns/proxyMethod", "true") + .property("https://w3id.org/edc/v0.0.1/ns/proxyBody", "true") + .property("https://w3id.org/edc/v0.0.1/ns/method", "POST") + .build(); + + Asset asset = Asset.Builder.newInstance() + .id("Asset1") + .contentType("Asset") + .properties(properties) + .dataAddress(dataAddress) + .build(); + JsonObject jsonObject = edcTransformer.transformAssetToJson(asset); + + JSONAssert.assertEquals(""" + { + "@id": "Asset1", + "@type": "edc:Asset", + "edc:properties": { + "dct:type": { + "@id": "https://w3id.org/catenax/taxonomy#DigitalTwinRegistry" + }, + "cx-common:version": "3.0", + "edc:type": "data.core.digitalTwinRegistry", + "edc:id": "Asset1", + "edc:contenttype": "Asset" + }, + "edc:dataAddress": { + "@type": "edc:DataAddress", + "edc:method": "POST", + "edc:type": "HttpData", + "edc:proxyMethod": "true", + "edc:proxyBody": "true", + "edc:baseUrl": "https://test.dtr/registry" + }, + "@context": { + "dct": "https://purl.org/dc/terms/", + "tx": "https://w3id.org/tractusx/v0.0.1/ns/", + "edc": "https://w3id.org/edc/v0.0.1/ns/", + "odrl": "http://www.w3.org/ns/odrl/2/", + "dcat": "https://www.w3.org/ns/dcat/", + "dspace": "https://w3id.org/dspace/v0.8/" + } + } + """, jsonObject.toString(), false); + } + @Test void givenCreateNotificationAsset_whenOk_ThenReturnCreatedAssetId() throws CreateEdcAssetException { // given diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java index 73c4da4907..a15eeb7221 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java @@ -118,9 +118,9 @@ public ConnectorEndpointsService connectorEndpointsService(final DiscoveryFinder @ConditionalOnProperty(prefix = CONFIG_PREFIX, name = CONFIG_FIELD_TYPE, havingValue = CONFIG_VALUE_DECENTRAL) public EndpointDataForConnectorsService endpointDataForConnectorsService(final EdcSubmodelFacade facade) { - final EdcEndpointReferenceRetriever edcEndpointReferenceRetriever = (edcConnectorEndpoint, assetType, assetValue, bpn) -> { + final EdcEndpointReferenceRetriever edcEndpointReferenceRetriever = (edcConnectorEndpoint, bpn) -> { try { - return facade.getEndpointReferencesForAsset(edcConnectorEndpoint, assetType, assetValue, bpn); + return facade.getEndpointReferencesForRegistryAsset(edcConnectorEndpoint, bpn); } catch (EdcClientException e) { throw new EdcRetrieverException(e); } diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/EdcEndpointReferenceRetriever.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/EdcEndpointReferenceRetriever.java index 3b76116a3a..68ba435f48 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/EdcEndpointReferenceRetriever.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/EdcEndpointReferenceRetriever.java @@ -37,13 +37,10 @@ public interface EdcEndpointReferenceRetriever { * Retrieves the EDC endpoint references from the specified connector endpoint and asset combination * * @param edcConnectorEndpoint the endpoint URL - * @param assetType the asset type id - * @param assetValue the asset type value * @param bpn bpn value * @return the endpoint data references as list of futures * @throws EdcRetrieverException on any EDC errors */ @SuppressWarnings("PMD.UseObjectForClearerAPI") - List> getEndpointReferencesForAsset(String edcConnectorEndpoint, - String assetType, String assetValue, String bpn) throws EdcRetrieverException; + List> getEndpointReferencesForAsset(String edcConnectorEndpoint, String bpn) throws EdcRetrieverException; } diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/EndpointDataForConnectorsService.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/EndpointDataForConnectorsService.java index c65abe5f1e..a71abc4d6e 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/EndpointDataForConnectorsService.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/EndpointDataForConnectorsService.java @@ -40,8 +40,6 @@ @RequiredArgsConstructor public class EndpointDataForConnectorsService { - private static final String DT_REGISTRY_ASSET_TYPE = "https://w3id.org/edc/v0.0.1/ns/type"; - private static final String DT_REGISTRY_ASSET_VALUE = "data.core.digitalTwinRegistry"; private static final String TOOK_MS = "{} took {} ms"; private final EdcEndpointReferenceRetriever edcSubmodelFacade; @@ -77,8 +75,7 @@ private List> createGetEndpointReferenc log.info(msg); try { - return edcSubmodelFacade.getEndpointReferencesForAsset(edcUrl, DT_REGISTRY_ASSET_TYPE, - DT_REGISTRY_ASSET_VALUE, bpn); + return edcSubmodelFacade.getEndpointReferencesForAsset(edcUrl, bpn); } catch (EdcRetrieverException e) { log.warn("Exception occurred when retrieving EndpointDataReference from connector '{}'", edcUrl, e); return List.of(CompletableFuture.failedFuture(e)); diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/DefaultConfigurationTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/DefaultConfigurationTest.java index f5f47863ff..22bbf0c673 100644 --- a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/DefaultConfigurationTest.java +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/DefaultConfigurationTest.java @@ -88,7 +88,7 @@ void endpointDataForConnectorsService() throws EdcClientException { final var endpointAddress = "endpointaddress"; final String contractAgreementId = "contractAgreementId"; final var endpointDataReference = endpointDataReference(contractAgreementId, endpointAddress); - when(mock.getEndpointReferencesForAsset(eq(endpointAddress), any(), any(), any())).thenReturn( + when(mock.getEndpointReferencesForRegistryAsset(eq(endpointAddress), any())).thenReturn( List.of(CompletableFuture.completedFuture(endpointDataReference))); // ACT @@ -107,13 +107,13 @@ void endpointDataForConnectorsService() throws EdcClientException { }); // ASSERT - verify(mock).getEndpointReferencesForAsset(eq(endpointAddress), any(), any(), any()); + verify(mock).getEndpointReferencesForRegistryAsset(eq(endpointAddress), any()); } @Test void endpointDataForConnectorsService_withException() throws EdcClientException { final var mock = mock(EdcSubmodelFacade.class); - when(mock.getEndpointReferencesForAsset(any(), any(), any(), any())).thenThrow(new EdcClientException("test")); + when(mock.getEndpointReferencesForRegistryAsset(any(), any())).thenThrow(new EdcClientException("test")); final var endpointDataForConnectorsService = testee.endpointDataForConnectorsService(mock); final var dummyEndpoints = List.of("test"); diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java index 59a09cccb1..fb3164c045 100644 --- a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java @@ -112,8 +112,7 @@ void shouldDiscoverEDCAndRequestRegistry() throws RegistryServiceException, EdcR givenThat(getShellDescriptor200()); final var endpointDataReference = endpointDataReference("assetId"); - when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(any(), any(), any(), - any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference))); + when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(any(), any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference))); // Act final Collection shells = decentralDigitalTwinRegistryService.fetchShells( @@ -161,8 +160,7 @@ void shouldThrowInCaseOfLookupShellsError() throws EdcRetrieverException { givenThat(postEdcDiscovery200()); final var endpointDataReference = endpointDataReference("assetId"); - when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(any(), any(), any(), - any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference))); + when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(any(), any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference))); givenThat(getLookupShells404()); final List testId = List.of(new DigitalTwinRegistryKey("testId", TEST_BPN)); @@ -182,8 +180,7 @@ void shouldThrowInCaseOfShellDescriptorsError() throws EdcRetrieverException { givenThat(postEdcDiscovery200()); final var endpointDataReference = endpointDataReference("assetId"); - when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(any(), any(), any(), - any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference))); + when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(any(), any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference))); givenThat(getLookupShells200()); givenThat(getShellDescriptor404()); @@ -205,8 +202,7 @@ void shouldThrowExceptionOnEmptyShells() throws EdcRetrieverException { givenThat(postEdcDiscovery200()); final var endpointDataReference = endpointDataReference("assetId"); - when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(any(), any(), any(), - any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference))); + when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(any(), any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference))); givenThat(getLookupShells200Empty()); givenThat(getShellDescriptor404()); @@ -235,8 +231,7 @@ void lookupShellIdentifiers_oneEDC_oneDTR() throws RegistryServiceException, Edc // simulate endpoint data reference final var endpointDataReference = endpointDataReference("assetId"); - when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(any(), any(), any(), - any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference))); + when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(any(), any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference))); // Act final Collection digitalTwinRegistryKeys = decentralDigitalTwinRegistryService.lookupShellIdentifiers( @@ -266,10 +261,8 @@ void lookupShellIdentifiers_multipleEDCs_oneDTR(String title, // simulate endpoint data reference final var endpointDataReference = endpointDataReference("assetId"); - when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(eq(edc1Url), any(), any(), - any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference))); - when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(eq(edc2Url), any(), any(), - any())).thenReturn(endpointDataReferenceForAssetFutures); + when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(eq(edc1Url), any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference))); + when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(eq(edc2Url), any())).thenReturn(endpointDataReferenceForAssetFutures); // Act final Collection digitalTwinRegistryKeys = decentralDigitalTwinRegistryService.lookupShellIdentifiers( @@ -311,10 +304,8 @@ void lookupShellIdentifiers_multipleEDCs_multipleDTRs() throws RegistryServiceEx // simulate endpoint data reference final var endpointDataReference1 = endpointDataReference("dtr1-assetId"); final var endpointDataReference2 = endpointDataReference("dtr2-assetId"); - when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(eq(edc1Url), any(), any(), - any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference1))); - when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(eq(edc2Url), any(), any(), - any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference2))); + when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(eq(edc1Url), any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference1))); + when(edcEndpointReferenceRetrieverMock.getEndpointReferencesForAsset(eq(edc2Url), any())).thenReturn(List.of(CompletableFuture.completedFuture(endpointDataReference2))); // Act & Assert final Collection digitalTwinRegistryKeys = decentralDigitalTwinRegistryService.lookupShellIdentifiers( diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/EndpointDataForConnectorsServiceTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/EndpointDataForConnectorsServiceTest.java index ffee494aaf..30163c000f 100644 --- a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/EndpointDataForConnectorsServiceTest.java +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/EndpointDataForConnectorsServiceTest.java @@ -43,9 +43,6 @@ class EndpointDataForConnectorsServiceTest { - private static final String DT_REGISTRY_ASSET_TYPE = "https://w3id.org/edc/v0.0.1/ns/type"; - private static final String DT_REGISTRY_ASSET_VALUE = "data.core.digitalTwinRegistry"; - private static final String CONNECTION_ONE_ADDRESS = "connectionOneAddress"; private static final String CONNECTION_TWO_ADDRESS = "connectionTwoAddress"; private static final String CONNECTION_ONE_CONTRACT_ID = "id1"; @@ -77,8 +74,7 @@ class EndpointDataForConnectorsServiceTest { void shouldReturnExpectedEndpointDataReference() throws EdcRetrieverException { // GIVEN - when(edcSubmodelFacade.getEndpointReferencesForAsset(CONNECTION_ONE_ADDRESS, DT_REGISTRY_ASSET_TYPE, - DT_REGISTRY_ASSET_VALUE, BPN)).thenReturn( + when(edcSubmodelFacade.getEndpointReferencesForAsset(CONNECTION_ONE_ADDRESS, BPN)).thenReturn( List.of(CompletableFuture.completedFuture(CONNECTION_ONE_DATA_REF))); // WHEN @@ -99,13 +95,11 @@ void shouldReturnExpectedEndpointDataReferenceFromSecondConnectionEndpoint() thr // GIVEN // a first endpoint failing (1) - when(edcSubmodelFacade.getEndpointReferencesForAsset(CONNECTION_ONE_ADDRESS, DT_REGISTRY_ASSET_TYPE, - DT_REGISTRY_ASSET_VALUE, BPN)).thenThrow( + when(edcSubmodelFacade.getEndpointReferencesForAsset(CONNECTION_ONE_ADDRESS, BPN)).thenThrow( new EdcRetrieverException(new EdcClientException("EdcClientException"))); // and a second endpoint returning successfully (2) - when(edcSubmodelFacade.getEndpointReferencesForAsset(CONNECTION_TWO_ADDRESS, DT_REGISTRY_ASSET_TYPE, - DT_REGISTRY_ASSET_VALUE, BPN)).thenReturn( + when(edcSubmodelFacade.getEndpointReferencesForAsset(CONNECTION_TWO_ADDRESS, BPN)).thenReturn( List.of(CompletableFuture.completedFuture(CONNECTION_TWO_DATA_REF))); // WHEN @@ -140,8 +134,7 @@ private static EndpointDataReference executeFutureMappingErrorsToNull( void shouldThrowExceptionWhenConnectorEndpointsNotReachable() throws EdcRetrieverException { // GIVEN - when(edcSubmodelFacade.getEndpointReferencesForAsset(anyString(), eq(DT_REGISTRY_ASSET_TYPE), - eq(DT_REGISTRY_ASSET_VALUE), eq(BPN))).thenThrow( + when(edcSubmodelFacade.getEndpointReferencesForAsset(anyString(), eq(BPN))).thenThrow( new EdcRetrieverException(new EdcClientException("EdcClientException"))); // WHEN diff --git a/local/testing/testdata/transform-and-upload.py b/local/testing/testdata/transform-and-upload.py index 9c7d3e3765..d550c922b5 100644 --- a/local/testing/testdata/transform-and-upload.py +++ b/local/testing/testdata/transform-and-upload.py @@ -60,6 +60,8 @@ def create_edc_registry_asset_payload(registry_url_, asset_prop_id_): "@context": edc_context(), "@id": f"{asset_prop_id_}", # DTR-EDC-instance-unique-ID "edc:properties": { + "dct:type": {"@id": "https://w3id.org/catenax/taxonomy#DigitalTwinRegistry"}, + "cx-common:version": "3.0", "edc:description": "Digital Twin Registry Endpoint of IRS DEV", "edc:id": f"{asset_prop_id_}", # DTR-EDC-instance-unique-ID "edc:type": "data.core.digitalTwinRegistry" @@ -84,7 +86,8 @@ def edc_context(): "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", "odrl": "http://www.w3.org/ns/odrl/2/", - "dspace": "https://w3id.org/dspace/v0.8/" + "dspace": "https://w3id.org/dspace/v0.8/", + "cx-common": "https://w3id.org/catenax/ontology/common#" } From 5760941501623745d4966bf67ff1e50e5d77d5ce Mon Sep 17 00:00:00 2001 From: jhartmann Date: Wed, 15 May 2024 14:30:38 +0200 Subject: [PATCH 02/12] feat(edc-client):[#616] Fix policy transformation and add missing namespaces --- docs/src/api/irs-api.yaml | 6 +- .../irs/ess/service/EdcRegistration.java | 2 +- .../irs/edc/client/EdcSubmodelClientImpl.java | 2 +- .../irs/edc/client/asset/EdcAssetService.java | 2 +- .../configuration/JsonLdConfiguration.java | 4 +- .../irs/edc/client/policy/Permission.java | 2 +- .../irs/edc/client/policy/PolicyType.java | 12 +- .../service/EdcPolicyDefinitionService.java | 2 +- .../irs/edc/client/EdcSubmodelClientTest.java | 2 +- .../edc/client/asset/EdcAssetServiceTest.java | 8 +- .../JsonLdConfigurationTest.java | 2 +- ...tractAgreementNegotiationResponseTest.java | 2 +- .../EdcContractAgreementsResponseTest.java | 4 +- .../EdcPolicyDefinitionServiceTest.java | 4 +- .../irs/edc/client/testutil/TestMother.java | 2 +- .../transformer/EdcTransformerTest.java | 16 +- .../JsonObjectToCatalogTransformerTest.java | 6 +- .../JsonObjectToIrsPolicyTransformerTest.java | 2 +- .../__files/edc/responseCatalog.json | 4 +- .../edc/responseGetTransferConfirmed.json | 2 +- .../models/CreatePolicyRequest.java | 2 +- .../policystore/models/PolicyResponse.java | 4 +- .../PolicyStoreControllerTest.java | 2 +- .../SubmodelFacadeWiremockSupport.java | 6 +- ...data_v1.7.0_PartInstance-new-registry.json | 166 ++++++++++++++++++ .../testing/testdata/transform-and-upload.py | 7 +- 26 files changed, 228 insertions(+), 45 deletions(-) create mode 100644 local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-new-registry.json diff --git a/docs/src/api/irs-api.yaml b/docs/src/api/irs-api.yaml index 2f48b91208..d4691434cd 100644 --- a/docs/src/api/irs-api.yaml +++ b/docs/src/api/irs-api.yaml @@ -821,7 +821,7 @@ paths: createdOn: 2024-03-28T03:34:42.9454448Z validUntil: 2025-12-12T23:59:59.999Z permissions: - - action: USE + - action: odrl:use constraint: and: - leftOperand: Membership @@ -1807,7 +1807,7 @@ components: policy: '@type': Policy odrl:permission: - - odrl:action: USE + - odrl:action: odrl:use odrl:constraint: odrl:and: - odrl:leftOperand: Membership @@ -2200,7 +2200,7 @@ components: policy: '@type': Policy odrl:permission: - - odrl:action: USE + - odrl:action: odrl:use odrl:constraint: odrl:and: - odrl:leftOperand: Membership diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/ess/service/EdcRegistration.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/ess/service/EdcRegistration.java index 9af1ac74dc..7502220cb5 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/ess/service/EdcRegistration.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/ess/service/EdcRegistration.java @@ -150,7 +150,7 @@ private void registerPolicy(final String policyId) { "policy": { "odrl:permission": [ { - "odrl:action": "USE", + "odrl:action": "odrl:use", "odrl:constraint": { "@type": "AtomicConstraint", "odrl:or": [ diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java index e89fd22497..51fdb5b622 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java @@ -67,7 +67,7 @@ }) public class EdcSubmodelClientImpl implements EdcSubmodelClient { - private static final String DT_DCAT_TYPE_ID = "'https://purl.org/dc/terms/type'.'@id'"; + private static final String DT_DCAT_TYPE_ID = "'http://purl.org/dc/terms/type'.'@id'"; private static final String DT_TAXONOMY_REGISTRY = "https://w3id.org/catenax/taxonomy#DigitalTwinRegistry"; private static final String DT_EDC_TYPE = "https://w3id.org/edc/v0.0.1/ns/type"; private static final String DT_DATA_CORE_REGISTRY = "data.core.digitalTwinRegistry"; diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java index 97d9c4d567..06722a85df 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java @@ -65,7 +65,7 @@ public class EdcAssetService { private static final String ASSET_CREATION_PROPERTY_POLICY_ID = "https://w3id.org/edc/v0.0.1/ns/policy-id"; private static final String ASSET_CREATION_PROPERTY_EDC_TYPE = "https://w3id.org/edc/v0.0.1/ns/type"; private static final String ASSET_CREATION_PROPERTY_DATA_CORE_REGISTRY = "data.core.digitalTwinRegistry"; - private static final String ASSET_CREATION_PROPERTY_DCAT_TYPE = "https://purl.org/dc/terms/type"; + private static final String ASSET_CREATION_PROPERTY_DCAT_TYPE = "http://purl.org/dc/terms/type"; private static final String ASSET_CREATION_PROPERTY_DCAT_REGISTRY = "https://w3id.org/catenax/taxonomy#DigitalTwinRegistry"; private static final String ASSET_CREATION_PROPERTY_COMMON_VERSION_KEY = "https://w3id.org/catenax/ontology/common#version"; private static final String ASSET_CREATION_PROPERTY_COMMON_VERSION_VALUE = "3.0"; diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfiguration.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfiguration.java index 299e981343..1513207f27 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfiguration.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfiguration.java @@ -51,9 +51,10 @@ public class JsonLdConfiguration { public static final String NAMESPACE_EDC_PARTICIPANT_ID = NAMESPACE_EDC + "participantId"; public static final String NAMESPACE_EDC_ID = NAMESPACE_EDC + "id"; public static final String NAMESPACE_TRACTUSX = "https://w3id.org/tractusx/v0.0.1/ns/"; - public static final String NAMESPACE_DCT = "https://purl.org/dc/terms/"; + public static final String NAMESPACE_DCT = "http://purl.org/dc/terms/"; public static final String JSON_LD_OBJECT_MAPPER = "jsonLdObjectMapper"; public static final String NAMESPACE_CATENAX_ONTOLOGY_COMMON = "https://w3id.org/catenax/ontology/common#"; + public static final String NAMESPACE_CATENAX_TAXONOMY = "https://w3id.org/catenax/taxonomy#"; @Bean /* package */ TitaniumJsonLd titaniumJsonLd(final Monitor monitor) { final TitaniumJsonLd titaniumJsonLd = new TitaniumJsonLd(monitor); @@ -64,6 +65,7 @@ public class JsonLdConfiguration { titaniumJsonLd.registerNamespace("dcat", JsonLdConfiguration.NAMESPACE_DCAT); titaniumJsonLd.registerNamespace("dspace", NAMESPACE_DSPACE); titaniumJsonLd.registerNamespace("cx-common", NAMESPACE_CATENAX_ONTOLOGY_COMMON); + titaniumJsonLd.registerNamespace("cx-taxo", NAMESPACE_CATENAX_TAXONOMY); return titaniumJsonLd; } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/Permission.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/Permission.java index a447e02388..61ec1a20c9 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/Permission.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/Permission.java @@ -41,7 +41,7 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class Permission { - @Schema(implementation = PolicyType.class, example = "USE") + @Schema(implementation = PolicyType.class, example = "odrl:use") @JsonAlias({"odrl:action"}) private PolicyType action; @Schema diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/PolicyType.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/PolicyType.java index 481f15c642..802f0ae3f0 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/PolicyType.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/PolicyType.java @@ -23,11 +23,19 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.policy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import com.fasterxml.jackson.annotation.JsonValue; + /** * A PolicyType object use in Permission */ +@Getter +@RequiredArgsConstructor public enum PolicyType { + ACCESS("odrl:access"), + USE("odrl:use"); - ACCESS, USE - + @JsonValue + private final String value; } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java index 80f88f547f..62e1e52e81 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -54,12 +54,12 @@ @RequiredArgsConstructor public class EdcPolicyDefinitionService { - private static final String USE_ACTION = "USE"; private static final String POLICY_TYPE = "Policy"; private static final String POLICY_DEFINITION_TYPE = "PolicyDefinitionRequestDto"; private static final String ATOMIC_CONSTRAINT = "AtomicConstraint"; private static final String CONSTRAINT = "Constraint"; private static final String OPERATOR_PREFIX = "odrl:"; + private static final String USE_ACTION = OPERATOR_PREFIX + "use"; private final EdcConfiguration config; private final RestTemplate restTemplate; diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java index 0171c77e91..c726d09d6e 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java @@ -93,7 +93,7 @@ class EdcSubmodelClientTest extends LocalTestDataConfigurationAware { private static final String PROVIDER_SUFFIX = "/test"; private static final String CONNECTOR_ENDPOINT = "https://connector.endpoint.com"; private static final String existingCatenaXId = "urn:uuid:5e1908ed-e176-4f57-9616-1415097d0fdf"; - private static final String BPN = "BPNL00000003CRHK"; + private static final String BPN = "BPNL00000000TEST"; private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); private final TimeMachine clock = new TimeMachine(); diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java index 580e8da43a..6ee57e1220 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java @@ -82,7 +82,7 @@ class EdcAssetServiceTest { void setUp() { TitaniumJsonLd jsonLd = new TitaniumJsonLd(new ConsoleMonitor()); jsonLd.registerNamespace("odrl", "http://www.w3.org/ns/odrl/2/"); - jsonLd.registerNamespace("dct", "https://purl.org/dc/terms/"); + jsonLd.registerNamespace("dct", "http://purl.org/dc/terms/"); jsonLd.registerNamespace("tx", "https://w3id.org/tractusx/v0.0.1/ns/"); jsonLd.registerNamespace("edc", "https://w3id.org/edc/v0.0.1/ns/"); jsonLd.registerNamespace("dcat", "https://www.w3.org/ns/dcat/"); @@ -142,7 +142,7 @@ void testAssetCreateRequestStructure() throws JSONException { "edc:baseUrl": "https://traceability.dev.demo.catena-x.net/api/qualitynotifications/receive" }, "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "odrl": "http://www.w3.org/ns/odrl/2/", @@ -156,7 +156,7 @@ void testAssetCreateRequestStructure() throws JSONException { @Test void testRegistryAssetCreateRequestStructure() throws JSONException { - Map properties = Map.of("https://purl.org/dc/terms/type", + Map properties = Map.of("http://purl.org/dc/terms/type", Map.of("@id", "https://w3id.org/catenax/taxonomy#DigitalTwinRegistry"), "https://w3id.org/catenax/ontology/common#version", "3.0", "https://w3id.org/edc/v0.0.1/ns/type", "data.core.digitalTwinRegistry"); @@ -201,7 +201,7 @@ void testRegistryAssetCreateRequestStructure() throws JSONException { "edc:baseUrl": "https://test.dtr/registry" }, "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "odrl": "http://www.w3.org/ns/odrl/2/", diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfigurationTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfigurationTest.java index 11d579dd55..561cebd908 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfigurationTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfigurationTest.java @@ -42,7 +42,7 @@ void shouldConvertJsonLD() { final JsonLdConfiguration jsonLdConfiguration = new JsonLdConfiguration(); final TitaniumJsonLd titaniumJsonLd = jsonLdConfiguration.titaniumJsonLd(jsonLdConfiguration.monitor()); final JsonObject build = Json.createObjectBuilder() - .add("dct", "https://purl.org/dc/terms/") + .add("dct", "http://purl.org/dc/terms/") .add("tx", "https://w3id.org/tractusx/v0.0.1/ns/") .add("edc", "https://w3id.org/edc/v0.0.1/ns/") .add("dcat", "https://www.w3.org/ns/dcat/") diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementNegotiationResponseTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementNegotiationResponseTest.java index 31814223e2..aa7d82fa9c 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementNegotiationResponseTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementNegotiationResponseTest.java @@ -42,7 +42,7 @@ void shouldParseEdcContractAgreementNegotiationResponse() throws JsonProcessingE "edc:createdAt": 1708590580001, "edc:contractAgreementId": "ODA3MmUyNTQtOGNlZi00YzQ2LTljNGYtNGYzNjE2YjQ5NTZl:cmVnaXN0cnktYXNzZXQ=:MDljNDMzY2EtODI5OS00OGE3LWI0MjYtNzZmZjJmODE1ZWE2", "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementsResponseTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementsResponseTest.java index 045de84d92..116dc2ff66 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementsResponseTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementsResponseTest.java @@ -42,7 +42,7 @@ void shouldParseEdcContractAgreementsResponse() throws JsonProcessingException { "odrl:permission": { "odrl:target": "registry-asset", "odrl:action": { - "odrl:type": "USE" + "odrl:type": "odrl:use" }, "odrl:constraint": { "odrl:or": { @@ -62,7 +62,7 @@ void shouldParseEdcContractAgreementsResponse() throws JsonProcessingException { "edc:consumerId": "BPNL00000003CML1", "edc:providerId": "BPNL00000003CML1", "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java index f47772e25d..950ffbfcfd 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java @@ -92,7 +92,7 @@ void testCreatePolicyDefinitionRequest() throws JsonProcessingException, JSONExc "@type": "Policy", "odrl:permission": [ { - "odrl:action": "USE", + "odrl:action": "odrl:use", "odrl:constraint": { "@type": "AtomicConstraint", "odrl:or": [ @@ -167,7 +167,7 @@ void givenPolicyName_WhenGetPolicy_ThenNotExists() throws GetEdcPolicyDefinition } @Test - void givenCreatePolicy_whenConflict_thenReturnExstingPolicyId() throws CreateEdcPolicyDefinitionException { + void givenCreatePolicy_whenConflict_thenReturnExstingPolicyId() { // given when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java index 58a34c2d81..300e2ecf66 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java @@ -139,7 +139,7 @@ private static String getOfferId(final String assetId) { private static Permission createUsePermission(final Constraint constraint) { return Permission.Builder.newInstance() - .action(Action.Builder.newInstance().type("USE").build()) + .action(Action.Builder.newInstance().type("odrl:use").build()) .constraint(constraint) .build(); } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformerTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformerTest.java index 6d5f0e9c7d..2319d0cee4 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformerTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformerTest.java @@ -83,7 +83,7 @@ class EdcTransformerTest { "@type": "odrl:Offer", "odrl:permission": { "odrl:action": { - "odrl:type": "USE" + "odrl:type": "odrl:use" }, "odrl:constraint": { "odrl:or": { @@ -133,8 +133,8 @@ class EdcTransformerTest { "dct:terms": "connector", "dct:endpointUrl": "https://irs-test-controlplane-provider.dev.demo.catena-x.net/api/v1/dsp" }, - "dspace:participantId": "BPNL00000003CRHK", - "participantId": "BPNL00000003CRHK", + "dspace:participantId": "BPNL00000000TEST", + "participantId": "BPNL00000000TEST", "@context": { "@vocab": "https://w3id.org/edc/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", @@ -195,7 +195,7 @@ private static NegotiationRequest createNegotiation(final String providerBPN, fi } private static Policy createPolicy(final String assetId) { - final Action action = Action.Builder.newInstance().type("USE").build(); + final Action action = Action.Builder.newInstance().type("odrl:use").build(); final AtomicConstraint atomicConstraint = AtomicConstraint.Builder.newInstance() .leftExpression( new LiteralExpression("PURPOSE")) @@ -212,11 +212,13 @@ private static Policy createPolicy(final String assetId) { void setUp() { jsonLd = new TitaniumJsonLd(new ConsoleMonitor()); jsonLd.registerNamespace("odrl", "http://www.w3.org/ns/odrl/2/"); - jsonLd.registerNamespace("dct", "https://purl.org/dc/terms/"); + jsonLd.registerNamespace("dct", "http://purl.org/dc/terms/"); jsonLd.registerNamespace("tx", "https://w3id.org/tractusx/v0.0.1/ns/"); jsonLd.registerNamespace("edc", "https://w3id.org/edc/v0.0.1/ns/"); jsonLd.registerNamespace("dcat", "https://www.w3.org/ns/dcat/"); jsonLd.registerNamespace("dspace", "https://w3id.org/dspace/v0.8/"); + jsonLd.registerNamespace("cx-common", "https://w3id.org/catenax/ontology/common#"); + jsonLd.registerNamespace("cx-taxo", "https://w3id.org/catenax/taxonomy#"); ObjectMapper objectMapper = objectMapper(); edcTransformer = new EdcTransformer(objectMapper, jsonLd, new TypeTransformerRegistryImpl()); @@ -245,7 +247,7 @@ void shouldDeserializeJsonLdResponseToCatalog() throws JsonProcessingException { assertThat(actualCatalog).isNotNull(); assertThat(actualCatalog.getId()).isEqualTo("78ff625c-0c05-4014-965c-bd3d0a6a0de0"); assertThat(actualCatalog.getProperties()).containsEntry("https://w3id.org/edc/v0.0.1/ns/participantId", - "BPNL00000003CRHK"); + "BPNL00000000TEST"); assertThat(actualCatalog.getDatasets()).hasSize(1); assertThat(actualCatalog.getDataServices().get(0)).isEqualTo(expectedDataService); @@ -317,7 +319,7 @@ void shouldSerializeTransferRequestDtoToJsonObject() { final String protocol = "dataspace-protocol-http"; final String contractId = "7681f966-36ea-4542-b5ea-0d0db81967de:35c78eca-db53-442c-9e01-467fc22c9434-55840861-5d7f-444b-972a-6e8b78552d8a:66131c58-32af-4df0-825d-77f7df6017c"; final String assetId = "urn:uuid:35c78eca-db53-442c-9e01-467fc22c9434-urn:uuid:55840861-5d7f-444b-972a-6e8b78552d8a"; - final String connectorId = "BPNL00000003CRHK"; + final String connectorId = "BPNL00000000TEST"; final DataAddress dataAddress = DataAddress.Builder.newInstance().type("HttpProxy").build(); final List callbackAddresses = List.of(CallbackAddress.Builder.newInstance() .uri("https://backend.app/endpoint-data-reference") diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToCatalogTransformerTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToCatalogTransformerTest.java index 07f8560167..1aadf7a3ae 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToCatalogTransformerTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToCatalogTransformerTest.java @@ -46,7 +46,7 @@ class JsonObjectToCatalogTransformerTest { void setUp() { final TitaniumJsonLd jsonLd = new TitaniumJsonLd(new ConsoleMonitor()); jsonLd.registerNamespace("odrl", "http://www.w3.org/ns/odrl/2/"); - jsonLd.registerNamespace("dct", "https://purl.org/dc/terms/"); + jsonLd.registerNamespace("dct", "http://purl.org/dc/terms/"); jsonLd.registerNamespace("tx", "https://w3id.org/tractusx/v0.0.1/ns/"); jsonLd.registerNamespace("edc", "https://w3id.org/edc/v0.0.1/ns/"); jsonLd.registerNamespace("dcat", "https://www.w3.org/ns/dcat/"); @@ -96,7 +96,7 @@ void shouldTransformJsonObjectToPolicyCorrectly() { "@type": "odrl:Offer", "odrl:permission": { "odrl:action": { - "odrl:type": "USE" + "odrl:type": "odrl:use" }, "odrl:constraint": { "odrl:or": { @@ -161,7 +161,7 @@ void shouldTransformJsonObjectToPolicyCorrectly() { "@type": "odrl:Offer", "odrl:permission": { "odrl:action": { - "odrl:type": "USE" + "odrl:type": "odrl:use" }, "odrl:constraint": { "odrl:or": { diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToIrsPolicyTransformerTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToIrsPolicyTransformerTest.java index 8c5c83ed8c..31937c48c7 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToIrsPolicyTransformerTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToIrsPolicyTransformerTest.java @@ -59,7 +59,7 @@ class JsonObjectToIrsPolicyTransformerTest { "policy": { "odrl:permission": [ { - "odrl:action": "USE", + "odrl:action": "odrl:use", "odrl:constraint": { "odrl:and": [ { diff --git a/irs-edc-client/src/test/resources/__files/edc/responseCatalog.json b/irs-edc-client/src/test/resources/__files/edc/responseCatalog.json index ba262b2acd..fb727a779a 100644 --- a/irs-edc-client/src/test/resources/__files/edc/responseCatalog.json +++ b/irs-edc-client/src/test/resources/__files/edc/responseCatalog.json @@ -1,7 +1,7 @@ { "@id": "78ff625c-0c05-4014-965c-bd3d0a6a0de0", "@type": "dcat:Catalog", - "dspace:participantId": "BPNL00000003CRHK", + "dspace:participantId": "BPNL00000000TEST", "dcat:dataset": { "@id": "urn:uuid:ea32f6f7-c884-4bfd-af4a-778666a1fffb", "@type": "dcat:Dataset", @@ -81,7 +81,7 @@ "dct:terms": "connector", "dct:endpointUrl": "http://edc.io/api/v1/dsp" }, - "participantId": "BPNL00000003CRHK", + "participantId": "BPNL00000000TEST", "@context": { "@vocab": "https://w3id.org/edc/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", diff --git a/irs-edc-client/src/test/resources/__files/edc/responseGetTransferConfirmed.json b/irs-edc-client/src/test/resources/__files/edc/responseGetTransferConfirmed.json index 119861b6f0..4e75a141eb 100644 --- a/irs-edc-client/src/test/resources/__files/edc/responseGetTransferConfirmed.json +++ b/irs-edc-client/src/test/resources/__files/edc/responseGetTransferConfirmed.json @@ -13,7 +13,7 @@ "@id": "1b21e963-0bc5-422a-b30d-fd3511861d88", "edc:assetId": "5a7ab616-989f-46ae-bdf2-32027b9f6ee6-31b614f5-ec14-4ed2-a509-e7b7780083e7", "edc:contractId": "7681f966-36ea-4542-b5ea-0d0db81967de:5a7ab616-989f-46ae-bdf2-32027b9f6ee6-31b614f5-ec14-4ed2-a509-e7b7780083e7:a6144a2e-c1b1-4ec6-96e1-a221da134e4f", - "edc:connectorId": "BPNL00000003CRHK" + "edc:connectorId": "BPNL00000000TEST" }, "edc:receiverHttpEndpoint": "https://irs-submodel-server3.dev.demo.catena-x.net/data/endpoint-data", "@context": { diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/CreatePolicyRequest.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/CreatePolicyRequest.java index 59624d8d47..e8d0bfbe73 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/CreatePolicyRequest.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/CreatePolicyRequest.java @@ -72,7 +72,7 @@ The business partner number (BPN) for which the policy should be registered. "@type": "Policy", "odrl:permission": [ { - "odrl:action": "USE", + "odrl:action": "odrl:use", "odrl:constraint": { "odrl:and": [ { diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java index b4c583a91a..d1ccd7d16f 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java @@ -48,7 +48,7 @@ public record PolicyResponse(OffsetDateTime validUntil, Payload payload) { "validUntil": "2025-12-12T23:59:59.999Z", "permissions": [ { - "action": "USE", + "action": "odrl:use", "constraint": { "and": [ { @@ -94,7 +94,7 @@ public record PolicyResponse(OffsetDateTime validUntil, Payload payload) { "policy": { "odrl:permission": [ { - "odrl:action": "USE", + "odrl:action": "odrl:use", "odrl:constraint": { "odrl:and": [ { diff --git a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreControllerTest.java b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreControllerTest.java index efb004e775..134d227dc0 100644 --- a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreControllerTest.java +++ b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreControllerTest.java @@ -70,7 +70,7 @@ public class PolicyStoreControllerTest { "policy": { "odrl:permission": [ { - "odrl:action": "USE", + "odrl:action": "odrl:use", "odrl:constraint": { "odrl:and": [ { diff --git a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockSupport.java b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockSupport.java index 18ba695874..c91d2ab44c 100644 --- a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockSupport.java +++ b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockSupport.java @@ -50,12 +50,13 @@ public final class SubmodelFacadeWiremockSupport { }"""; public static final String EDC_PROVIDER_DUMMY_URL = "https://edc.io/api/v1/dsp"; public static final String IRS_INTERNAL_CALLBACK_URL = "https://irs.test/internal/endpoint-data-reference"; - public static final String EDC_PROVIDER_BPN = "BPNL00000003CRHK"; + public static final String EDC_PROVIDER_BPN = "BPNL00000000TEST"; public static final int STATUS_CODE_OK = 200; public static final String CX_POLICY_FRAMEWORK_AGREEMENT = "cx-policy:FrameworkAgreement"; public static final String TRACEABILITY_1_0 = "traceability:1.0"; public static final String CX_POLICY_USAGE_PURPOSE = "cx-policy:UsagePurpose"; public static final String CX_CORE_INDUSTRYCORE_1 = "cx.core.industrycore:1"; + public static final String PERMISSION_TYPE = "odrl:use"; private SubmodelFacadeWiremockSupport() { } @@ -73,7 +74,8 @@ public static void prepareNegotiation(final String negotiationId, final String t stubFor(post(urlPathEqualTo(PATH_CATALOG)).willReturn(WireMockConfig.responseWithStatus(STATUS_CODE_OK) .withBody(getCatalogResponse(edcAssetId, - contractAgreementId, "USE", + contractAgreementId, + PERMISSION_TYPE, EDC_PROVIDER_BPN)))); stubFor(post(urlPathEqualTo(PATH_NEGOTIATE)).willReturn( diff --git a/local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-new-registry.json b/local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-new-registry.json new file mode 100644 index 0000000000..87f07ce160 --- /dev/null +++ b/local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-new-registry.json @@ -0,0 +1,166 @@ +{ + "policies": { + "traceability-core": { + "@context": { + "odrl": "http://www.w3.org/ns/odrl/2/" + }, + "@type": "PolicyDefinitionRequestDto", + "@id": "traceability-core", + "policy": { + "@type": "odrl:Set", + "odrl:permission": [ + { + "odrl:action": "USE", + "odrl:constraint": { + "@type": "AtomicConstraint", + "odrl:and": [ + { + "@type": "Constraint", + "odrl:leftOperand": "cx-policy:FrameworkAgreement", + "odrl:operator": { + "@id": "odrl:eq" + }, + "odrl:rightOperand": "traceability:1.0" + }, + { + "@type": "Constraint", + "odrl:leftOperand": "cx-policy:UsagePurpose", + "odrl:operator": { + "@id": "odrl:eq" + }, + "odrl:rightOperand": "cx.core.industrycore:1" + } + ] + } + } + ] + } + } + }, + "https://catenax.io/schema/TestDataContainer/1.0.0": [ + { + "urn:samm:io.catenax.single_level_bom_as_built:3.0.0#SingleLevelBomAsBuilt": [ + { + "catenaXId": "urn:uuid:a13c18cf-3b88-4805-9f9e-f30fc7dc0a00", + "childItems": [] + } + ], + "catenaXId": "urn:uuid:a13c18cf-3b88-4805-9f9e-f30fc7dc0a00", + "bpnl": "BPNL00000003AYRE", + "urn:samm:io.catenax.secondary_material_content_verifiable:1.0.0#SecondaryMaterialContentVerifiable": [ + { + "orderNumber": "845221", + "secondaryMaterialContent": [ + { + "bioBased": { + "primaryBioBased": { + "percentageOfMaterialWeight": 12 + }, + "bioBasedClass": "gen1", + "secondaryBioBased": { + "isMassBalanced": true, + "percentageOfMaterialWeight": 18 + } + }, + "additionalInformation": "eOMtThyhVNLWUZNRcBaQKxI", + "materialClass": "3.1", + "unitOfMeasure": { + "unitOfMeasureKey": "unit:centigram", + "grossMaterialInputMass": 3500, + "materialNetMass": 3000 + }, + "certificate": [ + { + "certificateName": "Yellowcert", + "certificateLink": "telnet://192.0.2.16:80/" + } + ], + "materialNameStandardized": { + "referencedStandard": "AISI", + "referencedStandardID": "1665", + "materialNameStandardizedValue": "PP-TD10" + }, + "inorganic": { + "primaryInorganic": { + "percentageOfMaterialWeight": 12 + }, + "secondaryInorganic": { + "postConsumer": { + "isPreviousIndustryAutomotive": false, + "chemicalRecycling": { + "isMassBalanced": false, + "percentageOfMaterialWeight": 13 + }, + "mechanicalRecycling": { + "isMassBalanced": true, + "percentageOfMaterialWeight": 11 + } + }, + "postConsumerAutomotive": { + "chemicalRecycling": { + "isMassBalanced": true, + "percentageOfMaterialWeight": 12 + }, + "mechanicalRecycling": { + "isMassBalanced": true, + "percentageOfMaterialWeight": 12 + } + }, + "preConsumer": { + "mechanicalRecycling": { + "isMassBalanced": true, + "percentageOfMaterialWeight": 10 + } + } + } + } + } + ] + } + ], + "urn:samm:io.catenax.serial_part:3.0.0#SerialPart": [ + { + "localIdentifiers": [ + { + "value": "BPNL00000003AYRE", + "key": "manufacturerId" + }, + { + "value": "8840838-04", + "key": "manufacturerPartId" + }, + { + "value": "NO-088559388438816364444095", + "key": "partInstanceId" + } + ], + "manufacturingInformation": { + "date": "2022-02-04T14:48:54", + "country": "DEU", + "sites": [ + { + "catenaXsiteId": "BPNS000004711DMY", + "function": "production" + } + ] + }, + "catenaXId": "urn:uuid:a13c18cf-3b88-4805-9f9e-f30fc7dc0a00", + "partTypeInformation": { + "manufacturerPartId": "8840374-09", + "customerPartId": "8840374-09", + "partClassification": [ + { + "classificationDescription": "Standard data element types with associated classification scheme for electric components.", + "classificationStandard": "IEC", + "classificationID": "61360- 2:2012 " + } + ], + "nameAtManufacturer": "ZB ZELLE", + "nameAtCustomer": "ZB ZELLE" + }, + "itemVersion": "04" + } + ] + } + ] +} \ No newline at end of file diff --git a/local/testing/testdata/transform-and-upload.py b/local/testing/testdata/transform-and-upload.py index d550c922b5..816857ea2c 100644 --- a/local/testing/testdata/transform-and-upload.py +++ b/local/testing/testdata/transform-and-upload.py @@ -60,9 +60,11 @@ def create_edc_registry_asset_payload(registry_url_, asset_prop_id_): "@context": edc_context(), "@id": f"{asset_prop_id_}", # DTR-EDC-instance-unique-ID "edc:properties": { - "dct:type": {"@id": "https://w3id.org/catenax/taxonomy#DigitalTwinRegistry"}, + "dct:type": { + "@id": "cx-taxo:DigitalTwinRegistry" + }, "cx-common:version": "3.0", - "edc:description": "Digital Twin Registry Endpoint of IRS DEV", + "edc:description": "Digital Twin Registry Endpoint", "edc:id": f"{asset_prop_id_}", # DTR-EDC-instance-unique-ID "edc:type": "data.core.digitalTwinRegistry" }, @@ -87,6 +89,7 @@ def edc_context(): "dcat": "https://www.w3.org/ns/dcat/", "odrl": "http://www.w3.org/ns/odrl/2/", "dspace": "https://w3id.org/dspace/v0.8/", + "cx-taxo": "https://w3id.org/catenax/taxonomy#", "cx-common": "https://w3id.org/catenax/ontology/common#" } From 27783490543ec5b116ea651ae522be547c07f2b3 Mon Sep 17 00:00:00 2001 From: jhartmann Date: Wed, 15 May 2024 14:39:22 +0200 Subject: [PATCH 03/12] feat(edc-client):[#616] Add missing tests --- .../EdcSubmodelClientLocalStubTest.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientLocalStubTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientLocalStubTest.java index f979c91a8e..6db9e48d66 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientLocalStubTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientLocalStubTest.java @@ -23,21 +23,20 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import org.eclipse.tractusx.irs.edc.client.exceptions.EdcClientException; +import org.eclipse.tractusx.irs.edc.client.model.notification.EdcNotification; +import org.eclipse.tractusx.irs.edc.client.model.notification.NotificationContent; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) class EdcSubmodelClientLocalStubTest { - @Mock - private SubmodelTestdataCreator testdataCreator; - @InjectMocks private EdcSubmodelClientLocalStub edcSubmodelClientLocalStub; @@ -47,6 +46,32 @@ void shouldThrowExceptionFor() { String assetId = "urn:uuid:c35ee875-5443-4a2d-bc14-fdacd64b9446"; // when - assertThrows(EdcClientException.class, () -> edcSubmodelClientLocalStub.getSubmodelPayload("", "", assetId, "")); + assertThrows(EdcClientException.class, + () -> edcSubmodelClientLocalStub.getSubmodelPayload("", "", assetId, "")); + } + + @Test + void sendNotification() { + final EdcNotification notification = EdcNotification.builder().build(); + final var actual = edcSubmodelClientLocalStub.sendNotification("", "", notification, ""); + assertThat(actual).isCompleted(); + } + + @Test + void getEndpointReferencesForAsset() { + assertThrows(EdcClientException.class, + () -> edcSubmodelClientLocalStub.getEndpointReferencesForAsset("", "", "", "")); + } + + @Test + void testGetEndpointReferencesForAsset() { + assertThrows(EdcClientException.class, + () -> edcSubmodelClientLocalStub.getEndpointReferencesForAsset("", "", "", "")); + } + + @Test + void getEndpointReferencesForRegistryAsset() { + assertThrows(EdcClientException.class, + () -> edcSubmodelClientLocalStub.getEndpointReferencesForRegistryAsset("", "")); } } \ No newline at end of file From 095e237b845bd637f3616d90bf961c34408ef1f5 Mon Sep 17 00:00:00 2001 From: jhartmann Date: Wed, 15 May 2024 17:30:36 +0200 Subject: [PATCH 04/12] feat(edc-client):[#616] Add missing tests --- .../irs/IrsWireMockIntegrationTest.java | 4 +- .../irs/edc/client/EdcSubmodelClientImpl.java | 8 +- .../irs/edc/client/EdcSubmodelClientTest.java | 74 +++++++++++++++++++ 3 files changed, 81 insertions(+), 5 deletions(-) diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java index 0a27cfe1c9..562083bfac 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java @@ -180,7 +180,7 @@ void shouldStopJobAfterDepthIsReached() { // Assert WiremockSupport.verifyDiscoveryCalls(1); - WiremockSupport.verifyNegotiationCalls(5); + WiremockSupport.verifyNegotiationCalls(3); assertThat(jobForJobId.getJob().getState()).isEqualTo(JobState.COMPLETED); assertThat(jobForJobId.getShells()).hasSize(2); @@ -273,7 +273,7 @@ void shouldStartRecursiveProcesses() { assertThat(jobForJobId.getSubmodels()).hasSize(6); WiremockSupport.verifyDiscoveryCalls(1); - WiremockSupport.verifyNegotiationCalls(9); + WiremockSupport.verifyNegotiationCalls(6); } private void successfulRegistryAndDataRequest(final String globalAssetId, final String idShort, final String bpn, diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java index 51fdb5b622..86844d3646 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java @@ -292,9 +292,11 @@ public List> getEndpointReferencesForRe final List contractOffers = new ArrayList<>( catalogFacade.fetchCatalogByFilter(providerWithSuffix, DT_DCAT_TYPE_ID, DT_TAXONOMY_REGISTRY, bpn)); - final List contractOffersDataCore = catalogFacade.fetchCatalogByFilter(providerWithSuffix, - DT_EDC_TYPE, DT_DATA_CORE_REGISTRY, bpn); - contractOffers.addAll(contractOffersDataCore); + if (contractOffers.isEmpty()) { + final List contractOffersDataCore = catalogFacade.fetchCatalogByFilter(providerWithSuffix, + DT_EDC_TYPE, DT_DATA_CORE_REGISTRY, bpn); + contractOffers.addAll(contractOffersDataCore); + } if (contractOffers.isEmpty()) { throw new EdcClientException( diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java index c726d09d6e..053aca2ef2 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java @@ -24,6 +24,7 @@ package org.eclipse.tractusx.irs.edc.client; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.fail; import static org.eclipse.tractusx.irs.edc.client.cache.endpointdatareference.EndpointDataReferenceStatus.TokenStatus; import static org.mockito.ArgumentMatchers.any; @@ -45,6 +46,7 @@ import java.time.Duration; import java.time.Instant; import java.time.ZoneId; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -94,6 +96,10 @@ class EdcSubmodelClientTest extends LocalTestDataConfigurationAware { private static final String CONNECTOR_ENDPOINT = "https://connector.endpoint.com"; private static final String existingCatenaXId = "urn:uuid:5e1908ed-e176-4f57-9616-1415097d0fdf"; private static final String BPN = "BPNL00000000TEST"; + public static final String TAXONOMY_DIGITAL_TWIN_REGISTRY = "https://w3id.org/catenax/taxonomy#DigitalTwinRegistry"; + public static final String DCT_TYPE_ID = "'http://purl.org/dc/terms/type'.'@id'"; + public static final String EDC_TYPE = "https://w3id.org/edc/v0.0.1/ns/type"; + public static final String DATA_CORE_DIGITAL_TWIN_REGISTRY = "data.core.digitalTwinRegistry"; private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); private final TimeMachine clock = new TimeMachine(); @@ -462,6 +468,74 @@ void shouldRetrieveEndpointReferenceForAsset2() throws Exception { assertThat(actual).isEqualTo(expected); } + @Test + void shouldRetrieveEndpointReferenceForRegistryAssetForOldIdentifier() throws Exception { + // arrange + when(config.getControlplane().getProviderSuffix()).thenReturn(PROVIDER_SUFFIX); + + final String agreementId = "agreementId"; + when(catalogFacade.fetchCatalogByFilter(any(), eq(DCT_TYPE_ID), eq(TAXONOMY_DIGITAL_TWIN_REGISTRY), + any())).thenReturn(Collections.emptyList()); + when(catalogFacade.fetchCatalogByFilter(any(), eq(EDC_TYPE), eq(DATA_CORE_DIGITAL_TWIN_REGISTRY), + any())).thenReturn(List.of(CatalogItem.builder().itemId("asset-id").build())); + when(contractNegotiationService.negotiate(any(), any(), + eq(new EndpointDataReferenceStatus(null, TokenStatus.REQUIRED_NEW)), any())).thenReturn( + NegotiationResponse.builder().contractAgreementId(agreementId).build()); + final EndpointDataReference expected = mock(EndpointDataReference.class); + when(endpointDataReferenceCacheService.getEndpointDataReferenceFromStorage(agreementId)).thenReturn( + Optional.ofNullable(expected)); + + // act + final var result = testee.getEndpointReferencesForRegistryAsset(ENDPOINT_ADDRESS, "bpn"); + + // assert + assertThat(result).hasSize(1); + final EndpointDataReference actual = result.get(0).get(5, TimeUnit.SECONDS); + assertThat(actual).isEqualTo(expected); + } + + @Test + void shouldRetrieveEndpointReferenceForRegistryAssetForNewIdentifier() throws Exception { + // arrange + when(config.getControlplane().getProviderSuffix()).thenReturn(PROVIDER_SUFFIX); + + final String agreementId = "agreementId"; + when(catalogFacade.fetchCatalogByFilter(any(), eq(DCT_TYPE_ID), eq(TAXONOMY_DIGITAL_TWIN_REGISTRY), + any())).thenReturn(List.of(CatalogItem.builder().itemId("asset-id").build())); + when(contractNegotiationService.negotiate(any(), any(), + eq(new EndpointDataReferenceStatus(null, TokenStatus.REQUIRED_NEW)), any())).thenReturn( + NegotiationResponse.builder().contractAgreementId(agreementId).build()); + final EndpointDataReference expected = mock(EndpointDataReference.class); + when(endpointDataReferenceCacheService.getEndpointDataReferenceFromStorage(agreementId)).thenReturn( + Optional.ofNullable(expected)); + + // act + final var result = testee.getEndpointReferencesForRegistryAsset(ENDPOINT_ADDRESS, "bpn"); + + // assert + assertThat(result).hasSize(1); + final EndpointDataReference actual = result.get(0).get(5, TimeUnit.SECONDS); + assertThat(actual).isEqualTo(expected); + } + + @Test + void shouldFailEndpointReferenceRetrievalForNoRegistryAsset() throws Exception { + // arrange + final String edcUrl = "https://edc.controlplane.org/public"; + when(config.getControlplane().getProviderSuffix()).thenReturn(PROVIDER_SUFFIX); + + when(catalogFacade.fetchCatalogByFilter(any(), eq(DCT_TYPE_ID), eq(TAXONOMY_DIGITAL_TWIN_REGISTRY), + any())).thenReturn(Collections.emptyList()); + when(catalogFacade.fetchCatalogByFilter(any(), eq(EDC_TYPE), eq(DATA_CORE_DIGITAL_TWIN_REGISTRY), + any())).thenReturn(Collections.emptyList()); + + // act & assert + final String expectedErrorMessage = "No DigitalTwinRegistry contract offers found for endpointAddress '%s' filterKey '%s', filterValue '%s' or filterKey '%s', filterValue '%s'".formatted( + edcUrl, DCT_TYPE_ID, TAXONOMY_DIGITAL_TWIN_REGISTRY, EDC_TYPE, DATA_CORE_DIGITAL_TWIN_REGISTRY); + assertThatThrownBy(() -> testee.getEndpointReferencesForRegistryAsset(edcUrl, "bpn")).isInstanceOf( + EdcClientException.class).hasMessage(expectedErrorMessage); + } + @Test void shouldUseCachedEndpointReferenceValueWhenTokenIsValid() throws EdcClientException, ExecutionException, InterruptedException { From 2398066c11e21de82d1c10290a748c230197aaee Mon Sep 17 00:00:00 2001 From: jhartmann Date: Wed, 15 May 2024 18:03:51 +0200 Subject: [PATCH 05/12] chore(docs):[#616] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29e1382ab9..a29f09c72d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ _**For better traceability add the corresponding GitHub issue number in each cha - IRS now searches for Digital Twin Registry contract offers by type `dct:type`: `https://w3id.org/catenax/taxonomy#DigitalTwinRegistry` or `edc:type`: `data.core.digitalTwinRegistry`. #616 +- Fix missing and malformed properties for EDC policy transformation. #648 ## [5.1.2] - 2024-05-13 From 1715a3a78b99ea9a4cbf6d57bbb1c18e0998a60d Mon Sep 17 00:00:00 2001 From: jhartmann Date: Thu, 16 May 2024 12:33:49 +0200 Subject: [PATCH 06/12] chore(docs):[#616] fix sonar issues --- .../client/EdcSubmodelClientLocalStub.java | 7 +- .../irs/edc/client/EdcSubmodelClientTest.java | 2 +- ...data_v1.7.0_PartInstance-new-registry.json | 166 ------------------ 3 files changed, 5 insertions(+), 170 deletions(-) delete mode 100644 local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-new-registry.json diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientLocalStub.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientLocalStub.java index d0f2898cfb..9df5ed79fd 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientLocalStub.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientLocalStub.java @@ -44,6 +44,7 @@ @SuppressWarnings("PMD.UseObjectForClearerAPI") public class EdcSubmodelClientLocalStub implements EdcSubmodelClient { + public static final String NOT_IMPLEMENTED = "Not implemented"; private final SubmodelTestdataCreator testdataCreator; /* package */ @@ -73,18 +74,18 @@ public CompletableFuture sendNotification(final String public List> getEndpointReferencesForAsset(final String endpointAddress, final String filterKey, final String filterValue, final EndpointDataReferenceStatus cachedEndpointDataReference, final String bpn) throws EdcClientException { - throw new EdcClientException("Not implemented"); + throw new EdcClientException(NOT_IMPLEMENTED); } @Override public List> getEndpointReferencesForAsset(final String endpointAddress, final String filterKey, final String filterValue, final String bpn) throws EdcClientException { - throw new EdcClientException("Not implemented"); + throw new EdcClientException(NOT_IMPLEMENTED); } @Override public List> getEndpointReferencesForRegistryAsset( final String endpointAddress, final String bpn) throws EdcClientException { - throw new EdcClientException("Not implemented"); + throw new EdcClientException(NOT_IMPLEMENTED); } } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java index 053aca2ef2..33a61964db 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java @@ -519,7 +519,7 @@ void shouldRetrieveEndpointReferenceForRegistryAssetForNewIdentifier() throws Ex } @Test - void shouldFailEndpointReferenceRetrievalForNoRegistryAsset() throws Exception { + void shouldFailEndpointReferenceRetrievalForNoRegistryAsset() { // arrange final String edcUrl = "https://edc.controlplane.org/public"; when(config.getControlplane().getProviderSuffix()).thenReturn(PROVIDER_SUFFIX); diff --git a/local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-new-registry.json b/local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-new-registry.json deleted file mode 100644 index 87f07ce160..0000000000 --- a/local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-new-registry.json +++ /dev/null @@ -1,166 +0,0 @@ -{ - "policies": { - "traceability-core": { - "@context": { - "odrl": "http://www.w3.org/ns/odrl/2/" - }, - "@type": "PolicyDefinitionRequestDto", - "@id": "traceability-core", - "policy": { - "@type": "odrl:Set", - "odrl:permission": [ - { - "odrl:action": "USE", - "odrl:constraint": { - "@type": "AtomicConstraint", - "odrl:and": [ - { - "@type": "Constraint", - "odrl:leftOperand": "cx-policy:FrameworkAgreement", - "odrl:operator": { - "@id": "odrl:eq" - }, - "odrl:rightOperand": "traceability:1.0" - }, - { - "@type": "Constraint", - "odrl:leftOperand": "cx-policy:UsagePurpose", - "odrl:operator": { - "@id": "odrl:eq" - }, - "odrl:rightOperand": "cx.core.industrycore:1" - } - ] - } - } - ] - } - } - }, - "https://catenax.io/schema/TestDataContainer/1.0.0": [ - { - "urn:samm:io.catenax.single_level_bom_as_built:3.0.0#SingleLevelBomAsBuilt": [ - { - "catenaXId": "urn:uuid:a13c18cf-3b88-4805-9f9e-f30fc7dc0a00", - "childItems": [] - } - ], - "catenaXId": "urn:uuid:a13c18cf-3b88-4805-9f9e-f30fc7dc0a00", - "bpnl": "BPNL00000003AYRE", - "urn:samm:io.catenax.secondary_material_content_verifiable:1.0.0#SecondaryMaterialContentVerifiable": [ - { - "orderNumber": "845221", - "secondaryMaterialContent": [ - { - "bioBased": { - "primaryBioBased": { - "percentageOfMaterialWeight": 12 - }, - "bioBasedClass": "gen1", - "secondaryBioBased": { - "isMassBalanced": true, - "percentageOfMaterialWeight": 18 - } - }, - "additionalInformation": "eOMtThyhVNLWUZNRcBaQKxI", - "materialClass": "3.1", - "unitOfMeasure": { - "unitOfMeasureKey": "unit:centigram", - "grossMaterialInputMass": 3500, - "materialNetMass": 3000 - }, - "certificate": [ - { - "certificateName": "Yellowcert", - "certificateLink": "telnet://192.0.2.16:80/" - } - ], - "materialNameStandardized": { - "referencedStandard": "AISI", - "referencedStandardID": "1665", - "materialNameStandardizedValue": "PP-TD10" - }, - "inorganic": { - "primaryInorganic": { - "percentageOfMaterialWeight": 12 - }, - "secondaryInorganic": { - "postConsumer": { - "isPreviousIndustryAutomotive": false, - "chemicalRecycling": { - "isMassBalanced": false, - "percentageOfMaterialWeight": 13 - }, - "mechanicalRecycling": { - "isMassBalanced": true, - "percentageOfMaterialWeight": 11 - } - }, - "postConsumerAutomotive": { - "chemicalRecycling": { - "isMassBalanced": true, - "percentageOfMaterialWeight": 12 - }, - "mechanicalRecycling": { - "isMassBalanced": true, - "percentageOfMaterialWeight": 12 - } - }, - "preConsumer": { - "mechanicalRecycling": { - "isMassBalanced": true, - "percentageOfMaterialWeight": 10 - } - } - } - } - } - ] - } - ], - "urn:samm:io.catenax.serial_part:3.0.0#SerialPart": [ - { - "localIdentifiers": [ - { - "value": "BPNL00000003AYRE", - "key": "manufacturerId" - }, - { - "value": "8840838-04", - "key": "manufacturerPartId" - }, - { - "value": "NO-088559388438816364444095", - "key": "partInstanceId" - } - ], - "manufacturingInformation": { - "date": "2022-02-04T14:48:54", - "country": "DEU", - "sites": [ - { - "catenaXsiteId": "BPNS000004711DMY", - "function": "production" - } - ] - }, - "catenaXId": "urn:uuid:a13c18cf-3b88-4805-9f9e-f30fc7dc0a00", - "partTypeInformation": { - "manufacturerPartId": "8840374-09", - "customerPartId": "8840374-09", - "partClassification": [ - { - "classificationDescription": "Standard data element types with associated classification scheme for electric components.", - "classificationStandard": "IEC", - "classificationID": "61360- 2:2012 " - } - ], - "nameAtManufacturer": "ZB ZELLE", - "nameAtCustomer": "ZB ZELLE" - }, - "itemVersion": "04" - } - ] - } - ] -} \ No newline at end of file From dfc3e9cb7894f1b22931cedc62197603cbc511ff Mon Sep 17 00:00:00 2001 From: jhartmann Date: Thu, 16 May 2024 13:47:35 +0200 Subject: [PATCH 07/12] chore(docs):[#616] remove "odrl:" prefix from action type --- docs/src/api/irs-api.yaml | 6 +++--- .../eclipse/tractusx/irs/ess/service/EdcRegistration.java | 2 +- .../eclipse/tractusx/irs/edc/client/policy/Permission.java | 2 +- .../eclipse/tractusx/irs/edc/client/policy/PolicyType.java | 4 ++-- .../client/policy/service/EdcPolicyDefinitionService.java | 2 +- .../contract/model/EdcContractAgreementsResponseTest.java | 2 +- .../policy/service/EdcPolicyDefinitionServiceTest.java | 2 +- .../tractusx/irs/edc/client/testutil/TestMother.java | 2 +- .../irs/edc/client/transformer/EdcTransformerTest.java | 4 ++-- .../transformer/JsonObjectToCatalogTransformerTest.java | 4 ++-- .../transformer/JsonObjectToIrsPolicyTransformerTest.java | 2 +- .../irs/policystore/models/CreatePolicyRequest.java | 2 +- .../tractusx/irs/policystore/models/PolicyResponse.java | 4 ++-- .../policystore/controllers/PolicyStoreControllerTest.java | 2 +- .../irs/testing/wiremock/SubmodelFacadeWiremockSupport.java | 2 +- 15 files changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/src/api/irs-api.yaml b/docs/src/api/irs-api.yaml index d4691434cd..1d7d2189d4 100644 --- a/docs/src/api/irs-api.yaml +++ b/docs/src/api/irs-api.yaml @@ -821,7 +821,7 @@ paths: createdOn: 2024-03-28T03:34:42.9454448Z validUntil: 2025-12-12T23:59:59.999Z permissions: - - action: odrl:use + - action: use constraint: and: - leftOperand: Membership @@ -1807,7 +1807,7 @@ components: policy: '@type': Policy odrl:permission: - - odrl:action: odrl:use + - odrl:action: use odrl:constraint: odrl:and: - odrl:leftOperand: Membership @@ -2200,7 +2200,7 @@ components: policy: '@type': Policy odrl:permission: - - odrl:action: odrl:use + - odrl:action: use odrl:constraint: odrl:and: - odrl:leftOperand: Membership diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/ess/service/EdcRegistration.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/ess/service/EdcRegistration.java index 7502220cb5..bc2f3a1d8c 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/ess/service/EdcRegistration.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/ess/service/EdcRegistration.java @@ -150,7 +150,7 @@ private void registerPolicy(final String policyId) { "policy": { "odrl:permission": [ { - "odrl:action": "odrl:use", + "odrl:action": "use", "odrl:constraint": { "@type": "AtomicConstraint", "odrl:or": [ diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/Permission.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/Permission.java index 61ec1a20c9..639a6551df 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/Permission.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/Permission.java @@ -41,7 +41,7 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class Permission { - @Schema(implementation = PolicyType.class, example = "odrl:use") + @Schema(implementation = PolicyType.class, example = "use") @JsonAlias({"odrl:action"}) private PolicyType action; @Schema diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/PolicyType.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/PolicyType.java index 802f0ae3f0..c5ed0ac4ee 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/PolicyType.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/PolicyType.java @@ -33,8 +33,8 @@ @Getter @RequiredArgsConstructor public enum PolicyType { - ACCESS("odrl:access"), - USE("odrl:use"); + ACCESS("access"), + USE("use"); @JsonValue private final String value; diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java index 62e1e52e81..ad76aa4c15 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -59,7 +59,7 @@ public class EdcPolicyDefinitionService { private static final String ATOMIC_CONSTRAINT = "AtomicConstraint"; private static final String CONSTRAINT = "Constraint"; private static final String OPERATOR_PREFIX = "odrl:"; - private static final String USE_ACTION = OPERATOR_PREFIX + "use"; + private static final String USE_ACTION = "use"; private final EdcConfiguration config; private final RestTemplate restTemplate; diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementsResponseTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementsResponseTest.java index 116dc2ff66..f535088ee1 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementsResponseTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementsResponseTest.java @@ -42,7 +42,7 @@ void shouldParseEdcContractAgreementsResponse() throws JsonProcessingException { "odrl:permission": { "odrl:target": "registry-asset", "odrl:action": { - "odrl:type": "odrl:use" + "odrl:type": "use" }, "odrl:constraint": { "odrl:or": { diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java index 950ffbfcfd..4f91cf298a 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java @@ -92,7 +92,7 @@ void testCreatePolicyDefinitionRequest() throws JsonProcessingException, JSONExc "@type": "Policy", "odrl:permission": [ { - "odrl:action": "odrl:use", + "odrl:action": "use", "odrl:constraint": { "@type": "AtomicConstraint", "odrl:or": [ diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java index 300e2ecf66..b37b77321d 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java @@ -139,7 +139,7 @@ private static String getOfferId(final String assetId) { private static Permission createUsePermission(final Constraint constraint) { return Permission.Builder.newInstance() - .action(Action.Builder.newInstance().type("odrl:use").build()) + .action(Action.Builder.newInstance().type("use").build()) .constraint(constraint) .build(); } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformerTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformerTest.java index 2319d0cee4..e2c40abc06 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformerTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformerTest.java @@ -83,7 +83,7 @@ class EdcTransformerTest { "@type": "odrl:Offer", "odrl:permission": { "odrl:action": { - "odrl:type": "odrl:use" + "odrl:type": "use" }, "odrl:constraint": { "odrl:or": { @@ -195,7 +195,7 @@ private static NegotiationRequest createNegotiation(final String providerBPN, fi } private static Policy createPolicy(final String assetId) { - final Action action = Action.Builder.newInstance().type("odrl:use").build(); + final Action action = Action.Builder.newInstance().type("use").build(); final AtomicConstraint atomicConstraint = AtomicConstraint.Builder.newInstance() .leftExpression( new LiteralExpression("PURPOSE")) diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToCatalogTransformerTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToCatalogTransformerTest.java index 1aadf7a3ae..44eb6e83ae 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToCatalogTransformerTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToCatalogTransformerTest.java @@ -96,7 +96,7 @@ void shouldTransformJsonObjectToPolicyCorrectly() { "@type": "odrl:Offer", "odrl:permission": { "odrl:action": { - "odrl:type": "odrl:use" + "odrl:type": "use" }, "odrl:constraint": { "odrl:or": { @@ -161,7 +161,7 @@ void shouldTransformJsonObjectToPolicyCorrectly() { "@type": "odrl:Offer", "odrl:permission": { "odrl:action": { - "odrl:type": "odrl:use" + "odrl:type": "use" }, "odrl:constraint": { "odrl:or": { diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToIrsPolicyTransformerTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToIrsPolicyTransformerTest.java index 31937c48c7..0fe40a1e52 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToIrsPolicyTransformerTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToIrsPolicyTransformerTest.java @@ -59,7 +59,7 @@ class JsonObjectToIrsPolicyTransformerTest { "policy": { "odrl:permission": [ { - "odrl:action": "odrl:use", + "odrl:action": "use", "odrl:constraint": { "odrl:and": [ { diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/CreatePolicyRequest.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/CreatePolicyRequest.java index e8d0bfbe73..22d43026ed 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/CreatePolicyRequest.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/CreatePolicyRequest.java @@ -72,7 +72,7 @@ The business partner number (BPN) for which the policy should be registered. "@type": "Policy", "odrl:permission": [ { - "odrl:action": "odrl:use", + "odrl:action": "use", "odrl:constraint": { "odrl:and": [ { diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java index d1ccd7d16f..11cbcdd24c 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java @@ -48,7 +48,7 @@ public record PolicyResponse(OffsetDateTime validUntil, Payload payload) { "validUntil": "2025-12-12T23:59:59.999Z", "permissions": [ { - "action": "odrl:use", + "action": "use", "constraint": { "and": [ { @@ -94,7 +94,7 @@ public record PolicyResponse(OffsetDateTime validUntil, Payload payload) { "policy": { "odrl:permission": [ { - "odrl:action": "odrl:use", + "odrl:action": "use", "odrl:constraint": { "odrl:and": [ { diff --git a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreControllerTest.java b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreControllerTest.java index 134d227dc0..393b27f2f7 100644 --- a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreControllerTest.java +++ b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreControllerTest.java @@ -70,7 +70,7 @@ public class PolicyStoreControllerTest { "policy": { "odrl:permission": [ { - "odrl:action": "odrl:use", + "odrl:action": "use", "odrl:constraint": { "odrl:and": [ { diff --git a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockSupport.java b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockSupport.java index c91d2ab44c..17d1573002 100644 --- a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockSupport.java +++ b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockSupport.java @@ -56,7 +56,7 @@ public final class SubmodelFacadeWiremockSupport { public static final String TRACEABILITY_1_0 = "traceability:1.0"; public static final String CX_POLICY_USAGE_PURPOSE = "cx-policy:UsagePurpose"; public static final String CX_CORE_INDUSTRYCORE_1 = "cx.core.industrycore:1"; - public static final String PERMISSION_TYPE = "odrl:use"; + public static final String PERMISSION_TYPE = "use"; private SubmodelFacadeWiremockSupport() { } From 819667ecc7d13e6f569355c347ee8c10aa581be3 Mon Sep 17 00:00:00 2001 From: jhartmann Date: Thu, 16 May 2024 14:07:46 +0200 Subject: [PATCH 08/12] feat(edc-client):[#616] fix namespaces --- .../irs/edc/client/configuration/JsonLdConfiguration.java | 6 ++---- .../tractusx/irs/edc/client/asset/EdcAssetServiceTest.java | 4 ++-- .../tractusx/irs/edc/client/testutil/TestMother.java | 2 ++ .../irs/edc/client/transformer/EdcTransformerTest.java | 3 +-- .../transformer/JsonObjectToCatalogTransformerTest.java | 1 + 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfiguration.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfiguration.java index 1513207f27..71f49e3aa0 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfiguration.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/configuration/JsonLdConfiguration.java @@ -53,8 +53,7 @@ public class JsonLdConfiguration { public static final String NAMESPACE_TRACTUSX = "https://w3id.org/tractusx/v0.0.1/ns/"; public static final String NAMESPACE_DCT = "http://purl.org/dc/terms/"; public static final String JSON_LD_OBJECT_MAPPER = "jsonLdObjectMapper"; - public static final String NAMESPACE_CATENAX_ONTOLOGY_COMMON = "https://w3id.org/catenax/ontology/common#"; - public static final String NAMESPACE_CATENAX_TAXONOMY = "https://w3id.org/catenax/taxonomy#"; + public static final String NAMESPACE_CATENAX_POLICY = "https://w3id.org/catenax/policy/"; @Bean /* package */ TitaniumJsonLd titaniumJsonLd(final Monitor monitor) { final TitaniumJsonLd titaniumJsonLd = new TitaniumJsonLd(monitor); @@ -64,8 +63,7 @@ public class JsonLdConfiguration { titaniumJsonLd.registerNamespace("edc", NAMESPACE_EDC); titaniumJsonLd.registerNamespace("dcat", JsonLdConfiguration.NAMESPACE_DCAT); titaniumJsonLd.registerNamespace("dspace", NAMESPACE_DSPACE); - titaniumJsonLd.registerNamespace("cx-common", NAMESPACE_CATENAX_ONTOLOGY_COMMON); - titaniumJsonLd.registerNamespace("cx-taxo", NAMESPACE_CATENAX_TAXONOMY); + titaniumJsonLd.registerNamespace("cx-policy", NAMESPACE_CATENAX_POLICY); return titaniumJsonLd; } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java index 6ee57e1220..1653da5d41 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java @@ -87,7 +87,7 @@ void setUp() { jsonLd.registerNamespace("edc", "https://w3id.org/edc/v0.0.1/ns/"); jsonLd.registerNamespace("dcat", "https://www.w3.org/ns/dcat/"); jsonLd.registerNamespace("dspace", "https://w3id.org/dspace/v0.8/"); - jsonLd.registerNamespace("cx-common", "https://w3id.org/catenax/ontology/common#"); + jsonLd.registerNamespace("cx-policy", "https://w3id.org/catenax/policy/"); this.edcTransformer = new EdcTransformer(objectMapper(), jsonLd, new TypeTransformerRegistryImpl()); this.service = new EdcAssetService(edcTransformer, edcConfiguration, restTemplate); @@ -187,7 +187,7 @@ void testRegistryAssetCreateRequestStructure() throws JSONException { "dct:type": { "@id": "https://w3id.org/catenax/taxonomy#DigitalTwinRegistry" }, - "cx-common:version": "3.0", + "https://w3id.org/catenax/ontology/common#version": "3.0", "edc:type": "data.core.digitalTwinRegistry", "edc:id": "Asset1", "edc:contenttype": "Asset" diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java index b37b77321d..369624a740 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java @@ -23,6 +23,7 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.testutil; +import static org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration.NAMESPACE_CATENAX_POLICY; import static org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration.NAMESPACE_DCAT; import static org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration.NAMESPACE_DCT; import static org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration.NAMESPACE_DSPACE; @@ -79,6 +80,7 @@ public static EdcTransformer createEdcTransformer() { titaniumJsonLd.registerNamespace("edc", NAMESPACE_EDC); titaniumJsonLd.registerNamespace("dcat", NAMESPACE_DCAT); titaniumJsonLd.registerNamespace("dspace", NAMESPACE_DSPACE); + titaniumJsonLd.registerNamespace("cx-policy", NAMESPACE_CATENAX_POLICY); return new EdcTransformer(objectMapper(), titaniumJsonLd, new TypeTransformerRegistryImpl()); } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformerTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformerTest.java index e2c40abc06..f5b5b287cd 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformerTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformerTest.java @@ -217,8 +217,7 @@ void setUp() { jsonLd.registerNamespace("edc", "https://w3id.org/edc/v0.0.1/ns/"); jsonLd.registerNamespace("dcat", "https://www.w3.org/ns/dcat/"); jsonLd.registerNamespace("dspace", "https://w3id.org/dspace/v0.8/"); - jsonLd.registerNamespace("cx-common", "https://w3id.org/catenax/ontology/common#"); - jsonLd.registerNamespace("cx-taxo", "https://w3id.org/catenax/taxonomy#"); + jsonLd.registerNamespace("cx-policy", "https://w3id.org/catenax/policy/"); ObjectMapper objectMapper = objectMapper(); edcTransformer = new EdcTransformer(objectMapper, jsonLd, new TypeTransformerRegistryImpl()); diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToCatalogTransformerTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToCatalogTransformerTest.java index 44eb6e83ae..d546e7baef 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToCatalogTransformerTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/transformer/JsonObjectToCatalogTransformerTest.java @@ -51,6 +51,7 @@ void setUp() { jsonLd.registerNamespace("edc", "https://w3id.org/edc/v0.0.1/ns/"); jsonLd.registerNamespace("dcat", "https://www.w3.org/ns/dcat/"); jsonLd.registerNamespace("dspace", "https://w3id.org/dspace/v0.8/"); + jsonLd.registerNamespace("cx-policy", "https://w3id.org/catenax/policy/"); ObjectMapper objectMapper = objectMapper(); edcTransformer = new EdcTransformer(objectMapper, jsonLd, new TypeTransformerRegistryImpl()); From eb934b0a99072032b0ea3351ef81720734957e00 Mon Sep 17 00:00:00 2001 From: jhartmann Date: Thu, 16 May 2024 14:11:40 +0200 Subject: [PATCH 09/12] feat(testdata):[#616] fix namespaces and action type --- local/testing/testdata/CX_Testdata_v.1.7.0_PartType.json | 5 +++-- .../CX_Testdata_v1.7.0_PartInstance-not-accepted-policy.json | 2 +- .../testdata/CX_Testdata_v1.7.0_PartInstance-reduced.json | 5 +++-- local/testing/testdata/ESS_Testdata_v2.0.0-AsPlanned.json | 5 +++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/local/testing/testdata/CX_Testdata_v.1.7.0_PartType.json b/local/testing/testdata/CX_Testdata_v.1.7.0_PartType.json index 5572c4ff4b..c3fe01b1fa 100644 --- a/local/testing/testdata/CX_Testdata_v.1.7.0_PartType.json +++ b/local/testing/testdata/CX_Testdata_v.1.7.0_PartType.json @@ -2,7 +2,8 @@ "policies": { "traceability-core": { "@context": { - "odrl": "http://www.w3.org/ns/odrl/2/" + "odrl": "http://www.w3.org/ns/odrl/2/", + "cx-policy": "https://w3id.org/catenax/policy/" }, "@type": "PolicyDefinitionRequestDto", "@id": "traceability-core", @@ -10,7 +11,7 @@ "@type": "odrl:Set", "odrl:permission": [ { - "odrl:action": "USE", + "odrl:action": "use", "odrl:constraint": { "@type": "AtomicConstraint", "odrl:and": [ diff --git a/local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-not-accepted-policy.json b/local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-not-accepted-policy.json index 2106d4d0ac..8d3ecfcdae 100644 --- a/local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-not-accepted-policy.json +++ b/local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-not-accepted-policy.json @@ -10,7 +10,7 @@ "@type": "odrl:Set", "odrl:permission": [ { - "odrl:action": "USE", + "odrl:action": "use", "odrl:constraint": { "odrl:or": [ { diff --git a/local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-reduced.json b/local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-reduced.json index 923c27186b..a789d15a9c 100644 --- a/local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-reduced.json +++ b/local/testing/testdata/CX_Testdata_v1.7.0_PartInstance-reduced.json @@ -2,7 +2,8 @@ "policies": { "traceability-core": { "@context": { - "odrl": "http://www.w3.org/ns/odrl/2/" + "odrl": "http://www.w3.org/ns/odrl/2/", + "cx-policy": "https://w3id.org/catenax/policy/" }, "@type": "PolicyDefinitionRequestDto", "@id": "traceability-core", @@ -10,7 +11,7 @@ "@type": "odrl:Set", "odrl:permission": [ { - "odrl:action": "USE", + "odrl:action": "use", "odrl:constraint": { "@type": "AtomicConstraint", "odrl:and": [ diff --git a/local/testing/testdata/ESS_Testdata_v2.0.0-AsPlanned.json b/local/testing/testdata/ESS_Testdata_v2.0.0-AsPlanned.json index 421ce2022b..43b0d510de 100644 --- a/local/testing/testdata/ESS_Testdata_v2.0.0-AsPlanned.json +++ b/local/testing/testdata/ESS_Testdata_v2.0.0-AsPlanned.json @@ -2,7 +2,8 @@ "policies": { "traceability-core": { "@context": { - "odrl": "http://www.w3.org/ns/odrl/2/" + "odrl": "http://www.w3.org/ns/odrl/2/", + "cx-policy": "https://w3id.org/catenax/policy/" }, "@type": "PolicyDefinitionRequestDto", "@id": "traceability-core", @@ -10,7 +11,7 @@ "@type": "odrl:Set", "odrl:permission": [ { - "odrl:action": "USE", + "odrl:action": "use", "odrl:constraint": { "@type": "AtomicConstraint", "odrl:and": [ From c817df1f82a55d05b1825aacb4b5875bdfc7871c Mon Sep 17 00:00:00 2001 From: jhartmann Date: Thu, 16 May 2024 15:11:14 +0200 Subject: [PATCH 10/12] feat(testdata):[#616] fix dct:type for registry asset creation --- local/testing/testdata/transform-and-upload.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/local/testing/testdata/transform-and-upload.py b/local/testing/testdata/transform-and-upload.py index 816857ea2c..0349f15d53 100644 --- a/local/testing/testdata/transform-and-upload.py +++ b/local/testing/testdata/transform-and-upload.py @@ -61,7 +61,7 @@ def create_edc_registry_asset_payload(registry_url_, asset_prop_id_): "@id": f"{asset_prop_id_}", # DTR-EDC-instance-unique-ID "edc:properties": { "dct:type": { - "@id": "cx-taxo:DigitalTwinRegistry" + "@id": "https://w3id.org/catenax/taxonomy#DigitalTwinRegistry" }, "cx-common:version": "3.0", "edc:description": "Digital Twin Registry Endpoint", @@ -89,7 +89,6 @@ def edc_context(): "dcat": "https://www.w3.org/ns/dcat/", "odrl": "http://www.w3.org/ns/odrl/2/", "dspace": "https://w3id.org/dspace/v0.8/", - "cx-taxo": "https://w3id.org/catenax/taxonomy#", "cx-common": "https://w3id.org/catenax/ontology/common#" } From a5fcb50e6049a38c7faaa5e00b9f9b88a1c56efc Mon Sep 17 00:00:00 2001 From: jhartmann Date: Thu, 16 May 2024 18:08:27 +0200 Subject: [PATCH 11/12] feat(policy-store):[#616] fix action in policy creation --- .../test/resources/templates/policy-for-e2e-tests.json | 2 +- .../__files/edc/responseGetNegotiationConfirmed.json | 2 +- .../__files/edc/responseGetNegotiationState.json | 2 +- .../__files/edc/responseGetTransferConfirmed.json | 2 +- .../__files/edc/responseGetTransferState.json | 2 +- .../__files/edc/responseStartNegotiation.json | 2 +- .../__files/edc/responseStartTransferprocess.json | 2 +- .../policystore/controllers/PolicyStoreController.java | 8 +++++++- .../request-collection/IRS_Request_Collection.json | 10 +++++----- local/testing/testdata/transform-and-upload.py | 2 +- 10 files changed, 20 insertions(+), 14 deletions(-) diff --git a/irs-cucumber-tests/src/test/resources/templates/policy-for-e2e-tests.json b/irs-cucumber-tests/src/test/resources/templates/policy-for-e2e-tests.json index bcfccffc15..854ad8f673 100644 --- a/irs-cucumber-tests/src/test/resources/templates/policy-for-e2e-tests.json +++ b/irs-cucumber-tests/src/test/resources/templates/policy-for-e2e-tests.json @@ -6,7 +6,7 @@ "policy": { "odrl:permission": [ { - "odrl:action": "USE", + "odrl:action": "use", "odrl:constraint": { "odrl:and": [ { diff --git a/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationConfirmed.json b/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationConfirmed.json index 7dd7e1ad38..080345bada 100644 --- a/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationConfirmed.json +++ b/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationConfirmed.json @@ -8,7 +8,7 @@ "edc:callbackAddresses": [], "edc:contractAgreementId": "7681f966-36ea-4542-b5ea-0d0db81967de:5a7ab616-989f-46ae-bdf2-32027b9f6ee6-31b614f5-ec14-4ed2-a509-e7b7780083e7:a6144a2e-c1b1-4ec6-96e1-a221da134e4f", "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", diff --git a/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationState.json b/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationState.json index ee4e9141e6..17ad6b9987 100644 --- a/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationState.json +++ b/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationState.json @@ -2,7 +2,7 @@ "@type": "edc:NegotiationState", "edc:state": "FINALIZED", "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", diff --git a/irs-edc-client/src/test/resources/__files/edc/responseGetTransferConfirmed.json b/irs-edc-client/src/test/resources/__files/edc/responseGetTransferConfirmed.json index 4e75a141eb..f6e6234dfb 100644 --- a/irs-edc-client/src/test/resources/__files/edc/responseGetTransferConfirmed.json +++ b/irs-edc-client/src/test/resources/__files/edc/responseGetTransferConfirmed.json @@ -17,7 +17,7 @@ }, "edc:receiverHttpEndpoint": "https://irs-submodel-server3.dev.demo.catena-x.net/data/endpoint-data", "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", diff --git a/irs-edc-client/src/test/resources/__files/edc/responseGetTransferState.json b/irs-edc-client/src/test/resources/__files/edc/responseGetTransferState.json index 7d0b2f267c..22715906e8 100644 --- a/irs-edc-client/src/test/resources/__files/edc/responseGetTransferState.json +++ b/irs-edc-client/src/test/resources/__files/edc/responseGetTransferState.json @@ -2,7 +2,7 @@ "@type": "edc:TransferState", "edc:state": "COMPLETED", "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", diff --git a/irs-edc-client/src/test/resources/__files/edc/responseStartNegotiation.json b/irs-edc-client/src/test/resources/__files/edc/responseStartNegotiation.json index cb7ca32a7c..75cacfebbc 100644 --- a/irs-edc-client/src/test/resources/__files/edc/responseStartNegotiation.json +++ b/irs-edc-client/src/test/resources/__files/edc/responseStartNegotiation.json @@ -3,7 +3,7 @@ "@id": "1bbaec6e-c316-4e1e-8258-c07a648cc43c", "edc:createdAt": 1686830151573, "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", diff --git a/irs-edc-client/src/test/resources/__files/edc/responseStartTransferprocess.json b/irs-edc-client/src/test/resources/__files/edc/responseStartTransferprocess.json index f6be3d222e..c4a8edc4a2 100644 --- a/irs-edc-client/src/test/resources/__files/edc/responseStartTransferprocess.json +++ b/irs-edc-client/src/test/resources/__files/edc/responseStartTransferprocess.json @@ -3,7 +3,7 @@ "@id": "1b21e963-0bc5-422a-b30d-fd3511861d88", "edc:createdAt": 1686758532950, "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java index 470f714830..bd2aa004ca 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java @@ -46,6 +46,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; import org.eclipse.tractusx.irs.common.auth.IrsRoles; +import org.eclipse.tractusx.irs.data.JsonParseException; import org.eclipse.tractusx.irs.dtos.ErrorResponse; import org.eclipse.tractusx.irs.edc.client.policy.Policy; import org.eclipse.tractusx.irs.policystore.models.CreatePoliciesResponse; @@ -126,8 +127,13 @@ public class PolicyStoreController { @ResponseStatus(HttpStatus.CREATED) @PreAuthorize("hasAuthority('" + IrsRoles.ADMIN_IRS + "')") public CreatePoliciesResponse registerAllowedPolicy(@Valid @RequestBody final CreatePolicyRequest request) { + final Policy registeredPolicy; - final Policy registeredPolicy = service.registerPolicy(request); + try { + registeredPolicy = service.registerPolicy(request); + } catch (JsonParseException e) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage(), e); + } if (registeredPolicy == null) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Policy was not registered"); diff --git a/local/testing/request-collection/IRS_Request_Collection.json b/local/testing/request-collection/IRS_Request_Collection.json index a1d2156f6d..569d04030d 100644 --- a/local/testing/request-collection/IRS_Request_Collection.json +++ b/local/testing/request-collection/IRS_Request_Collection.json @@ -2651,7 +2651,7 @@ "method": "POST", "body": { "mimeType": "application/json", - "text": "{\n\t\"@context\": {\n\t\t\"dct\": \"https://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t},\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:providerUrl\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\"\n}" + "text": "{\n\t\"@context\": {\n\t\t\"dct\": \"http://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t},\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:providerUrl\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\"\n}" }, "parameters": [], "headers": [ @@ -2712,7 +2712,7 @@ "method": "POST", "body": { "mimeType": "application/json", - "text": "{\n\t\"@context\": {\n\t\t\"dct\": \"https://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t},\n\t\"edc:providerUrl\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:querySpec\": {\n\t\t\"edc:filterExpression\": {\n\t\t\t\"edc:operandLeft\": \"https://w3id.org/edc/v0.0.1/ns/type\",\n\t\t\t\"edc:operator\": \"=\",\n\t\t\t\"edc:operandRight\": \"data.core.digitalTwinRegistry\"\n\t\t}\n\t}\n}" + "text": "{\n\t\"@context\": {\n\t\t\"dct\": \"http://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t},\n\t\"edc:providerUrl\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:querySpec\": {\n\t\t\"edc:filterExpression\": {\n\t\t\t\"edc:operandLeft\": \"https://w3id.org/edc/v0.0.1/ns/type\",\n\t\t\t\"edc:operator\": \"=\",\n\t\t\t\"edc:operandRight\": \"data.core.digitalTwinRegistry\"\n\t\t}\n\t}\n}" }, "parameters": [], "headers": [ @@ -2749,7 +2749,7 @@ "method": "POST", "body": { "mimeType": "application/json", - "text": "{\n\t\"@context\": {\n\t\t\"dct\": \"https://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t},\n\t\"edc:providerUrl\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:querySpec\": {\n\t\t\"edc:filterExpression\": {\n\t\t\t\"edc:operandLeft\": \"https://w3id.org/edc/v0.0.1/ns/id\",\n\t\t\t\"edc:operator\": \"=\",\n\t\t\t\"edc:operandRight\": \"{% prompt 'assetId', '', '', '', false, true %}\"\n\t\t}\n\t}\n}" + "text": "{\n\t\"@context\": {\n\t\t\"dct\": \"http://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t},\n\t\"edc:providerUrl\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:querySpec\": {\n\t\t\"edc:filterExpression\": {\n\t\t\t\"edc:operandLeft\": \"https://w3id.org/edc/v0.0.1/ns/id\",\n\t\t\t\"edc:operator\": \"=\",\n\t\t\t\"edc:operandRight\": \"{% prompt 'assetId', '', '', '', false, true %}\"\n\t\t}\n\t}\n}" }, "parameters": [], "headers": [ @@ -2786,7 +2786,7 @@ "method": "POST", "body": { "mimeType": "application/json", - "text": "{\n\t\"edc:connectorAddress\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:connectorId\": \"BPNL00000001CRHK\",\n\t\"edc:offer\": {\n\t\t\"@type\": \"edc:ContractOfferDescription\",\n\t\t\"edc:offerId\": \"ZGR0ci1jeG1lbWJlcnMtY29udHJhY3Q=:ZGlnaXRhbC10d2luLXJlZ2lzdHJ5:OGQ0ZTNkODYtOTIxOC00MjljLWI1N2EtNWZlZTZkODIzMmEx\",\n\t\t\"edc:assetId\": \"digital-twin-registry\",\n\t\t\"edc:policy\": {\n\t\t\t\"@type\": \"odrl:Set\",\n\t\t\t\"odrl:permission\": {\n\t\t\t\t\"odrl:target\": \"digital-twin-registry\",\n\t\t\t\t\"odrl:action\": {\n\t\t\t\t\t\"odrl:type\": \"USE\"\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"odrl:prohibition\": [],\n\t\t\t\"odrl:obligation\": [],\n\t\t\t\"odrl:target\": \"digital-twin-registry\"\n\t\t}\n\t},\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:callbackAddresses\": [],\n\t\"@context\": {\n\t\t\"dct\": \"https://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t}\n}" + "text": "{\n\t\"edc:connectorAddress\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:connectorId\": \"BPNL00000001CRHK\",\n\t\"edc:offer\": {\n\t\t\"@type\": \"edc:ContractOfferDescription\",\n\t\t\"edc:offerId\": \"ZGR0ci1jeG1lbWJlcnMtY29udHJhY3Q=:ZGlnaXRhbC10d2luLXJlZ2lzdHJ5:OGQ0ZTNkODYtOTIxOC00MjljLWI1N2EtNWZlZTZkODIzMmEx\",\n\t\t\"edc:assetId\": \"digital-twin-registry\",\n\t\t\"edc:policy\": {\n\t\t\t\"@type\": \"odrl:Set\",\n\t\t\t\"odrl:permission\": {\n\t\t\t\t\"odrl:target\": \"digital-twin-registry\",\n\t\t\t\t\"odrl:action\": {\n\t\t\t\t\t\"odrl:type\": \"USE\"\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"odrl:prohibition\": [],\n\t\t\t\"odrl:obligation\": [],\n\t\t\t\"odrl:target\": \"digital-twin-registry\"\n\t\t}\n\t},\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:callbackAddresses\": [],\n\t\"@context\": {\n\t\t\"dct\": \"http://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t}\n}" }, "parameters": [], "headers": [ @@ -2935,7 +2935,7 @@ "method": "POST", "body": { "mimeType": "application/json", - "text": "{\n\t\"edc:assetId\": \"digital-twin-registry\",\n\t\"edc:connectorAddress\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:contractId\": \"ZGR0ci1jeG1lbWJlcnMtY29udHJhY3Q=:ZGlnaXRhbC10d2luLXJlZ2lzdHJ5:NGNlMDk0ODgtOTMzYy00ZDk3LThiNTAtNDMyZWRjMzIwM2Fm\",\n\t\"edc:dataDestination\": {\n\t\t\"edc:type\": \"HttpProxy\"\n\t},\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:managedResources\": false,\n\t\"edc:connectorId\": \"BPNL00000001CRHK\",\n\t\"@context\": {\n\t\t\"dct\": \"https://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t}\n}" + "text": "{\n\t\"edc:assetId\": \"digital-twin-registry\",\n\t\"edc:connectorAddress\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:contractId\": \"ZGR0ci1jeG1lbWJlcnMtY29udHJhY3Q=:ZGlnaXRhbC10d2luLXJlZ2lzdHJ5:NGNlMDk0ODgtOTMzYy00ZDk3LThiNTAtNDMyZWRjMzIwM2Fm\",\n\t\"edc:dataDestination\": {\n\t\t\"edc:type\": \"HttpProxy\"\n\t},\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:managedResources\": false,\n\t\"edc:connectorId\": \"BPNL00000001CRHK\",\n\t\"@context\": {\n\t\t\"dct\": \"http://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t}\n}" }, "parameters": [], "headers": [ diff --git a/local/testing/testdata/transform-and-upload.py b/local/testing/testdata/transform-and-upload.py index 0349f15d53..ed81839dc6 100644 --- a/local/testing/testdata/transform-and-upload.py +++ b/local/testing/testdata/transform-and-upload.py @@ -83,7 +83,7 @@ def create_edc_registry_asset_payload(registry_url_, asset_prop_id_): def edc_context(): return { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", From 446ec3fee3ae7e087a79187db75a64deb306f9a7 Mon Sep 17 00:00:00 2001 From: jhartmann Date: Fri, 17 May 2024 11:35:05 +0200 Subject: [PATCH 12/12] feat(edc-client):[#616] refactoring after review --- .../service/EdcPolicyDefinitionService.java | 3 ++- .../irs/edc/client/EdcSubmodelClientTest.java | 17 +++++++++++------ .../irs/edc/client/testutil/TestMother.java | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java index ad76aa4c15..db404d211d 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -29,6 +29,7 @@ import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; import org.eclipse.tractusx.irs.edc.client.asset.model.OdrlContext; import org.eclipse.tractusx.irs.edc.client.contract.model.EdcOperator; +import org.eclipse.tractusx.irs.edc.client.policy.PolicyType; import org.eclipse.tractusx.irs.edc.client.policy.model.EdcCreatePolicyDefinitionRequest; import org.eclipse.tractusx.irs.edc.client.policy.model.EdcPolicy; import org.eclipse.tractusx.irs.edc.client.policy.model.EdcPolicyPermission; @@ -59,7 +60,7 @@ public class EdcPolicyDefinitionService { private static final String ATOMIC_CONSTRAINT = "AtomicConstraint"; private static final String CONSTRAINT = "Constraint"; private static final String OPERATOR_PREFIX = "odrl:"; - private static final String USE_ACTION = "use"; + private static final String USE_ACTION = PolicyType.USE.getValue(); private final EdcConfiguration config; private final RestTemplate restTemplate; diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java index 33a61964db..f9625f6858 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientTest.java @@ -469,15 +469,18 @@ void shouldRetrieveEndpointReferenceForAsset2() throws Exception { } @Test - void shouldRetrieveEndpointReferenceForRegistryAssetForOldIdentifier() throws Exception { + void shouldRetrieveEndpointReferenceForRegistryAssetUsingFallbackOldIdentifier() throws Exception { // arrange - when(config.getControlplane().getProviderSuffix()).thenReturn(PROVIDER_SUFFIX); - - final String agreementId = "agreementId"; + // no catalog item for taxonomy#DigitalTwinRegistry is found, + // so the fallback data.core.digitalTwinRegistry is used when(catalogFacade.fetchCatalogByFilter(any(), eq(DCT_TYPE_ID), eq(TAXONOMY_DIGITAL_TWIN_REGISTRY), any())).thenReturn(Collections.emptyList()); when(catalogFacade.fetchCatalogByFilter(any(), eq(EDC_TYPE), eq(DATA_CORE_DIGITAL_TWIN_REGISTRY), any())).thenReturn(List.of(CatalogItem.builder().itemId("asset-id").build())); + + when(config.getControlplane().getProviderSuffix()).thenReturn(PROVIDER_SUFFIX); + + final String agreementId = "agreementId"; when(contractNegotiationService.negotiate(any(), any(), eq(new EndpointDataReferenceStatus(null, TokenStatus.REQUIRED_NEW)), any())).thenReturn( NegotiationResponse.builder().contractAgreementId(agreementId).build()); @@ -497,11 +500,13 @@ void shouldRetrieveEndpointReferenceForRegistryAssetForOldIdentifier() throws Ex @Test void shouldRetrieveEndpointReferenceForRegistryAssetForNewIdentifier() throws Exception { // arrange + // catalog item for taxonomy#DigitalTwinRegistry is found, so the fallback type is not used + when(catalogFacade.fetchCatalogByFilter(any(), eq(DCT_TYPE_ID), eq(TAXONOMY_DIGITAL_TWIN_REGISTRY), + any())).thenReturn(List.of(CatalogItem.builder().itemId("asset-id").build())); + when(config.getControlplane().getProviderSuffix()).thenReturn(PROVIDER_SUFFIX); final String agreementId = "agreementId"; - when(catalogFacade.fetchCatalogByFilter(any(), eq(DCT_TYPE_ID), eq(TAXONOMY_DIGITAL_TWIN_REGISTRY), - any())).thenReturn(List.of(CatalogItem.builder().itemId("asset-id").build())); when(contractNegotiationService.negotiate(any(), any(), eq(new EndpointDataReferenceStatus(null, TokenStatus.REQUIRED_NEW)), any())).thenReturn( NegotiationResponse.builder().contractAgreementId(agreementId).build()); diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java index 369624a740..6504954a78 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/testutil/TestMother.java @@ -67,6 +67,7 @@ import org.eclipse.tractusx.irs.data.StringMapper; import org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration; import org.eclipse.tractusx.irs.edc.client.model.EDRAuthCode; +import org.eclipse.tractusx.irs.edc.client.policy.PolicyType; import org.eclipse.tractusx.irs.edc.client.transformer.EdcTransformer; import org.jetbrains.annotations.NotNull; @@ -141,7 +142,7 @@ private static String getOfferId(final String assetId) { private static Permission createUsePermission(final Constraint constraint) { return Permission.Builder.newInstance() - .action(Action.Builder.newInstance().type("use").build()) + .action(Action.Builder.newInstance().type(PolicyType.USE.getValue()).build()) .constraint(constraint) .build(); }