From 93e915c5026fb945df8b0ddc1f495cdfc02e16ca Mon Sep 17 00:00:00 2001 From: ndr_brt Date: Wed, 14 Dec 2022 13:36:05 +0100 Subject: [PATCH] Hotfix 0.1.4 (#601) --- .../edc-controlplane-base/pom.xml | 6 +- .../pom.xml | 2 +- .../edc-controlplane-memory/pom.xml | 2 +- .../pom.xml | 2 +- .../edc-controlplane-postgresql/pom.xml | 2 +- edc-controlplane/pom.xml | 2 +- .../edc-dataplane-azure-vault/pom.xml | 2 +- edc-dataplane/edc-dataplane-base/pom.xml | 2 +- .../edc-dataplane-hashicorp-vault/pom.xml | 2 +- edc-dataplane/pom.xml | 2 +- .../business-partner-validation/README.md | 62 ++++- .../business-partner-validation/pom.xml | 2 +- edc-extensions/control-plane-adapter/pom.xml | 2 +- edc-extensions/custom-jsonld/README.md | 6 + edc-extensions/custom-jsonld/pom.xml | 156 +++++++++++ .../edc/jsonld/CustomJsonLdExtension.java | 100 ++++++++ ...spaceconnector.spi.system.ServiceExtension | 21 ++ edc-extensions/cx-oauth2/pom.xml | 2 +- edc-extensions/data-encryption/pom.xml | 2 +- .../dataplane-selector-configuration/pom.xml | 2 +- edc-extensions/hashicorp-vault/pom.xml | 2 +- edc-extensions/pom.xml | 5 +- edc-extensions/postgresql-migration/pom.xml | 2 +- edc-tests/pom.xml | 6 +- .../tractusx/edc/tests/DataManagementAPI.java | 242 +++++++++--------- .../tractusx/edc/tests/PolicyStepDefs.java | 51 ++-- .../tractusx/edc/tests/data/OrConstraint.java | 11 + .../edc/tests/features/ContractOffers.feature | 2 +- pom.xml | 12 +- 29 files changed, 535 insertions(+), 177 deletions(-) create mode 100644 edc-extensions/custom-jsonld/README.md create mode 100644 edc-extensions/custom-jsonld/pom.xml create mode 100644 edc-extensions/custom-jsonld/src/main/java/org/eclipse/tractusx/edc/jsonld/CustomJsonLdExtension.java create mode 100644 edc-extensions/custom-jsonld/src/main/resources/META-INF/services/org.eclipse.dataspaceconnector.spi.system.ServiceExtension create mode 100644 edc-tests/src/test/java/org/eclipse/tractusx/edc/tests/data/OrConstraint.java diff --git a/edc-controlplane/edc-controlplane-base/pom.xml b/edc-controlplane/edc-controlplane-base/pom.xml index 48d6ff542..569df894a 100644 --- a/edc-controlplane/edc-controlplane-base/pom.xml +++ b/edc-controlplane/edc-controlplane-base/pom.xml @@ -24,7 +24,7 @@ edc-controlplane org.eclipse.tractusx.edc - 0.1.3 + 0.1.4 4.0.0 @@ -73,6 +73,10 @@ org.eclipse.tractusx.edc.extensions cx-oauth2 + + org.eclipse.tractusx.edc.extensions + custom-jsonld + diff --git a/edc-controlplane/edc-controlplane-memory-hashicorp-vault/pom.xml b/edc-controlplane/edc-controlplane-memory-hashicorp-vault/pom.xml index 416ce398e..0e5cad636 100644 --- a/edc-controlplane/edc-controlplane-memory-hashicorp-vault/pom.xml +++ b/edc-controlplane/edc-controlplane-memory-hashicorp-vault/pom.xml @@ -23,7 +23,7 @@ edc-controlplane org.eclipse.tractusx.edc - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-controlplane/edc-controlplane-memory/pom.xml b/edc-controlplane/edc-controlplane-memory/pom.xml index 678838be1..8f86f3d60 100644 --- a/edc-controlplane/edc-controlplane-memory/pom.xml +++ b/edc-controlplane/edc-controlplane-memory/pom.xml @@ -22,7 +22,7 @@ org.eclipse.tractusx.edc edc-controlplane - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-controlplane/edc-controlplane-postgresql-hashicorp-vault/pom.xml b/edc-controlplane/edc-controlplane-postgresql-hashicorp-vault/pom.xml index 1e6bd8087..9ca0df4ac 100644 --- a/edc-controlplane/edc-controlplane-postgresql-hashicorp-vault/pom.xml +++ b/edc-controlplane/edc-controlplane-postgresql-hashicorp-vault/pom.xml @@ -23,7 +23,7 @@ org.eclipse.tractusx.edc edc-controlplane - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-controlplane/edc-controlplane-postgresql/pom.xml b/edc-controlplane/edc-controlplane-postgresql/pom.xml index e2d675671..c7cb74fd7 100644 --- a/edc-controlplane/edc-controlplane-postgresql/pom.xml +++ b/edc-controlplane/edc-controlplane-postgresql/pom.xml @@ -23,7 +23,7 @@ org.eclipse.tractusx.edc edc-controlplane - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-controlplane/pom.xml b/edc-controlplane/pom.xml index ddba99e2d..61f42c20a 100644 --- a/edc-controlplane/pom.xml +++ b/edc-controlplane/pom.xml @@ -23,7 +23,7 @@ org.eclipse.tractusx.edc product-edc-parent - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-dataplane/edc-dataplane-azure-vault/pom.xml b/edc-dataplane/edc-dataplane-azure-vault/pom.xml index 2528686a8..50596d0c6 100644 --- a/edc-dataplane/edc-dataplane-azure-vault/pom.xml +++ b/edc-dataplane/edc-dataplane-azure-vault/pom.xml @@ -23,7 +23,7 @@ org.eclipse.tractusx.edc edc-dataplane - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-dataplane/edc-dataplane-base/pom.xml b/edc-dataplane/edc-dataplane-base/pom.xml index 21451ca31..374f5d4af 100644 --- a/edc-dataplane/edc-dataplane-base/pom.xml +++ b/edc-dataplane/edc-dataplane-base/pom.xml @@ -24,7 +24,7 @@ edc-dataplane org.eclipse.tractusx.edc - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-dataplane/edc-dataplane-hashicorp-vault/pom.xml b/edc-dataplane/edc-dataplane-hashicorp-vault/pom.xml index 63b864b87..a5b451c6c 100644 --- a/edc-dataplane/edc-dataplane-hashicorp-vault/pom.xml +++ b/edc-dataplane/edc-dataplane-hashicorp-vault/pom.xml @@ -23,7 +23,7 @@ org.eclipse.tractusx.edc edc-dataplane - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-dataplane/pom.xml b/edc-dataplane/pom.xml index e439c384e..e678a4815 100644 --- a/edc-dataplane/pom.xml +++ b/edc-dataplane/pom.xml @@ -24,7 +24,7 @@ org.eclipse.tractusx.edc product-edc-parent - 0.1.3 + 0.1.4 edc-dataplane diff --git a/edc-extensions/business-partner-validation/README.md b/edc-extensions/business-partner-validation/README.md index 42b27bb0c..bcf7f7ed0 100644 --- a/edc-extensions/business-partner-validation/README.md +++ b/edc-extensions/business-partner-validation/README.md @@ -27,15 +27,14 @@ The `leftExpression` must always contain 'BusinessPartner', so that the policy f Additionally, the only `operator` that is supported by these policy functions is 'EQ'. Finally, the `rightExpression` must contain the Business Partner Number. +## Single BusinessPartnerNumber example + The most simple BPN policy would allow the usage of certain data to a single Business Partner. An example `Policy` is -shown below. In this example the `edctype` properties are added, so that this policy may even be sent to the Data -Management API. Theoretically it is also possible to combine multiple BPN constraints by wrapping them into an EDC `OrConstraint` (see EDC Repository). +shown below. +In this example the `edctype` properties are added, so that this policy may even be sent to the Management API. ```json { - "uid": "", - "prohibitions": [], - "obligations": [], "permissions": [ { "edctype": "dataspaceconnector:permission", @@ -61,6 +60,59 @@ Management API. Theoretically it is also possible to combine multiple BPN constr } ``` +## Multiple BusinessPartnerNumber example + +To define multiple BPN and allow multiple participants to use the data the `orconstraint` should be used. +It will permit the constraints contained to be evaluated using the `OR` operator. +```json +{ + "permissions": [ + { + "edctype": "dataspaceconnector:permission", + "action": { + "type": "USE", + }, + "constraints": [ + { + "edctype": "dataspaceconnector:orconstraint", + "constraints": [ + { + "edctype": "AtomicConstraint", + "leftExpression": { + "edctype": "dataspaceconnector:literalexpression", + "value": "BusinessPartnerNumber" + }, + "rightExpression": { + "edctype": "dataspaceconnector:literalexpression", + "value": "" + }, + "operator": "EQ" + }, + { + "edctype": "AtomicConstraint", + "leftExpression": { + "edctype": "dataspaceconnector:literalexpression", + "value": "BusinessPartnerNumber" + }, + "rightExpression": { + "edctype": "dataspaceconnector:literalexpression", + "value": "" + }, + "operator": "EQ" + }, + + ... + + // other constraints can be added + ] + } + ], + "duties": [] + } + ] +} +``` + # Important: EDC Policies are input sensitive Please be aware that the EDC ignores all Rules and Constraint it does not understand. This could cause your constrained policies to be public. diff --git a/edc-extensions/business-partner-validation/pom.xml b/edc-extensions/business-partner-validation/pom.xml index eecbb9567..84fbe8d2c 100644 --- a/edc-extensions/business-partner-validation/pom.xml +++ b/edc-extensions/business-partner-validation/pom.xml @@ -23,7 +23,7 @@ org.eclipse.tractusx.edc.extensions edc-extensions - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-extensions/control-plane-adapter/pom.xml b/edc-extensions/control-plane-adapter/pom.xml index b1582c7e3..5de47efd8 100644 --- a/edc-extensions/control-plane-adapter/pom.xml +++ b/edc-extensions/control-plane-adapter/pom.xml @@ -17,7 +17,7 @@ org.eclipse.tractusx.edc.extensions edc-extensions - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-extensions/custom-jsonld/README.md b/edc-extensions/custom-jsonld/README.md new file mode 100644 index 000000000..d9d8add9e --- /dev/null +++ b/edc-extensions/custom-jsonld/README.md @@ -0,0 +1,6 @@ +# Custom Json LD + +This module was introduced to patch the bug about `LogicalConstraint` serializer: +https://github.com/eclipse-edc/Connector/issues/2334 + +The module can be removed once the bug will be fixed, merged and integrated in the EDC version used by product-EDC diff --git a/edc-extensions/custom-jsonld/pom.xml b/edc-extensions/custom-jsonld/pom.xml new file mode 100644 index 000000000..846d18728 --- /dev/null +++ b/edc-extensions/custom-jsonld/pom.xml @@ -0,0 +1,156 @@ + + + + + edc-extensions + org.eclipse.tractusx.edc.extensions + 0.1.4 + + 4.0.0 + + custom-jsonld + jar + + + ${project.basedir}/src/main/java + ${originalSourceDirectory} + ${project.build.directory}/delombok + ${project.groupId}_${project.artifactId} + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${maven.compiler.source} + ${maven.compiler.target} + ${project.build.sourceEncoding} + + + org.projectlombok + lombok + ${org.projectlombok.lombok.version} + + + + + + + org.projectlombok + lombok-maven-plugin + ${org.projectlombok.lombok.maven.plugin.version} + + + generate-sources + + delombok + + + + + ${originalSourceDirectory} + ${delombokSourceDirectory} + false + UTF-8 + + skip + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + + + + + + org.eclipse.dataspaceconnector + core-spi + + + org.eclipse.dataspaceconnector + ids-jsonld-serdes + + + org.eclipse.dataspaceconnector + ids-spi + + + org.eclipse.dataspaceconnector + ids-core + + + + + org.projectlombok + lombok + + + org.slf4j + slf4j-api + + + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-annotations + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + + + org.junit.jupiter + junit-jupiter + test + + + org.mockito + mockito-core + test + + + diff --git a/edc-extensions/custom-jsonld/src/main/java/org/eclipse/tractusx/edc/jsonld/CustomJsonLdExtension.java b/edc-extensions/custom-jsonld/src/main/java/org/eclipse/tractusx/edc/jsonld/CustomJsonLdExtension.java new file mode 100644 index 000000000..986fa6d58 --- /dev/null +++ b/edc-extensions/custom-jsonld/src/main/java/org/eclipse/tractusx/edc/jsonld/CustomJsonLdExtension.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2021,2022 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.eclipse.tractusx.edc.jsonld; + +import de.fraunhofer.iais.eis.*; +import de.fraunhofer.iais.eis.util.TypedLiteral; +import org.eclipse.dataspaceconnector.ids.core.serialization.IdsConstraintImpl; +import org.eclipse.dataspaceconnector.ids.jsonld.JsonLd; +import org.eclipse.dataspaceconnector.ids.jsonld.JsonLdSerializer; +import org.eclipse.dataspaceconnector.ids.spi.domain.IdsConstants; +import org.eclipse.dataspaceconnector.ids.spi.service.ConnectorService; +import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Inject; +import org.eclipse.dataspaceconnector.spi.system.ServiceExtension; +import org.eclipse.dataspaceconnector.spi.system.ServiceExtensionContext; +import org.eclipse.dataspaceconnector.spi.types.TypeManager; + +/** + * This extension is a temporary fix for a serialization bug: + * https://github.com/eclipse-edc/Connector/issues/2334 + */ +public class CustomJsonLdExtension implements ServiceExtension { + + public static final String IDS = "ids"; + // this is only needed to ensure that this extension is initialized after the + // IdsCoreServiceExtension + @Inject private ConnectorService connectorService; + + @Override + public String name() { + return "Custom JsonLD"; + } + + @Override + public void initialize(ServiceExtensionContext context) { + var typeManager = context.getTypeManager(); + typeManager.registerContext(IDS, JsonLd.getObjectMapper()); + + registerIdsClasses(typeManager); + registerCustomConstraintImpl(typeManager); + } + + private void registerIdsClasses(TypeManager typeManager) { + registerSerializer(typeManager, ArtifactRequestMessage.class); + registerSerializer(typeManager, RequestInProcessMessage.class); + registerSerializer(typeManager, MessageProcessedNotificationMessage.class); + registerSerializer(typeManager, DescriptionRequestMessage.class); + registerSerializer(typeManager, NotificationMessage.class); + registerSerializer(typeManager, ParticipantUpdateMessage.class); + registerSerializer(typeManager, RejectionMessage.class); + registerSerializer(typeManager, ContractAgreementMessage.class); + registerSerializer(typeManager, ContractRejectionMessage.class); + registerSerializer(typeManager, ContractOfferMessage.class); + registerSerializer(typeManager, ContractRequestMessage.class); + registerSerializer(typeManager, DynamicAttributeToken.class); + registerSerializer(typeManager, TokenFormat.class); + registerSerializer(typeManager, ContractAgreement.class); + registerSerializer(typeManager, ContractOffer.class); + registerSerializer(typeManager, Contract.class); + registerSerializer(typeManager, Permission.class); + registerSerializer(typeManager, Prohibition.class); + registerSerializer(typeManager, Duty.class); + registerSerializer(typeManager, Action.class); + registerSerializer(typeManager, LogicalConstraint.class); + registerSerializer(typeManager, Constraint.class); + registerSerializer(typeManager, Artifact.class); + registerSerializer(typeManager, BaseConnector.class); + registerSerializer(typeManager, Representation.class); + registerSerializer(typeManager, Resource.class); + registerSerializer(typeManager, TypedLiteral.class); + registerSerializer(typeManager, ResourceCatalog.class); + registerSerializer(typeManager, CustomMediaType.class); + } + + private void registerCustomConstraintImpl(TypeManager typeManager) { + registerSerializer(typeManager, IdsConstraintImpl.class); + typeManager.registerTypes(IDS, IdsConstraintImpl.class); + } + + private void registerSerializer(TypeManager typeManager, Class clazz) { + typeManager.registerSerializer(IDS, clazz, new JsonLdSerializer<>(clazz, IdsConstants.CONTEXT)); + } +} diff --git a/edc-extensions/custom-jsonld/src/main/resources/META-INF/services/org.eclipse.dataspaceconnector.spi.system.ServiceExtension b/edc-extensions/custom-jsonld/src/main/resources/META-INF/services/org.eclipse.dataspaceconnector.spi.system.ServiceExtension new file mode 100644 index 000000000..52b428d41 --- /dev/null +++ b/edc-extensions/custom-jsonld/src/main/resources/META-INF/services/org.eclipse.dataspaceconnector.spi.system.ServiceExtension @@ -0,0 +1,21 @@ +# +# Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +# Copyright (c) 2021,2022 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +org.eclipse.tractusx.edc.jsonld.CustomJsonLdExtension diff --git a/edc-extensions/cx-oauth2/pom.xml b/edc-extensions/cx-oauth2/pom.xml index ee5ae5402..a5be935f9 100644 --- a/edc-extensions/cx-oauth2/pom.xml +++ b/edc-extensions/cx-oauth2/pom.xml @@ -24,7 +24,7 @@ edc-extensions org.eclipse.tractusx.edc.extensions - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-extensions/data-encryption/pom.xml b/edc-extensions/data-encryption/pom.xml index 3ab523166..b11bcef1f 100644 --- a/edc-extensions/data-encryption/pom.xml +++ b/edc-extensions/data-encryption/pom.xml @@ -24,7 +24,7 @@ edc-extensions org.eclipse.tractusx.edc.extensions - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-extensions/dataplane-selector-configuration/pom.xml b/edc-extensions/dataplane-selector-configuration/pom.xml index 534da5448..623208a52 100644 --- a/edc-extensions/dataplane-selector-configuration/pom.xml +++ b/edc-extensions/dataplane-selector-configuration/pom.xml @@ -24,7 +24,7 @@ edc-extensions org.eclipse.tractusx.edc.extensions - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-extensions/hashicorp-vault/pom.xml b/edc-extensions/hashicorp-vault/pom.xml index 6be7f43b1..4959efb9a 100644 --- a/edc-extensions/hashicorp-vault/pom.xml +++ b/edc-extensions/hashicorp-vault/pom.xml @@ -23,7 +23,7 @@ org.eclipse.tractusx.edc.extensions edc-extensions - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-extensions/pom.xml b/edc-extensions/pom.xml index 6ee1bc444..5937792a5 100644 --- a/edc-extensions/pom.xml +++ b/edc-extensions/pom.xml @@ -23,7 +23,7 @@ org.eclipse.tractusx.edc product-edc-parent - 0.1.3 + 0.1.4 4.0.0 @@ -41,8 +41,9 @@ hashicorp-vault dataplane-selector-configuration data-encryption - cx-oauth2 control-plane-adapter + custom-jsonld + cx-oauth2 diff --git a/edc-extensions/postgresql-migration/pom.xml b/edc-extensions/postgresql-migration/pom.xml index 8a3a03042..5d40f2a7f 100644 --- a/edc-extensions/postgresql-migration/pom.xml +++ b/edc-extensions/postgresql-migration/pom.xml @@ -23,7 +23,7 @@ edc-extensions org.eclipse.tractusx.edc.extensions - 0.1.3 + 0.1.4 4.0.0 diff --git a/edc-tests/pom.xml b/edc-tests/pom.xml index 020f5288c..57552e8fe 100644 --- a/edc-tests/pom.xml +++ b/edc-tests/pom.xml @@ -25,7 +25,7 @@ org.eclipse.tractusx.edc product-edc-parent - 0.1.3 + 0.1.4 org.eclipse.tractusx.edc.tests @@ -187,6 +187,10 @@ org.eclipse.tractusx.edc.extensions control-plane-adapter + + org.eclipse.tractusx.edc.extensions + custom-jsonld + org.eclipse.tractusx.edc diff --git a/edc-tests/src/test/java/org/eclipse/tractusx/edc/tests/DataManagementAPI.java b/edc-tests/src/test/java/org/eclipse/tractusx/edc/tests/DataManagementAPI.java index 92e84ef62..eb8d169e4 100644 --- a/edc-tests/src/test/java/org/eclipse/tractusx/edc/tests/DataManagementAPI.java +++ b/edc-tests/src/test/java/org/eclipse/tractusx/edc/tests/DataManagementAPI.java @@ -40,20 +40,7 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; -import org.eclipse.tractusx.edc.tests.data.Asset; -import org.eclipse.tractusx.edc.tests.data.AssetWithDataAddress; -import org.eclipse.tractusx.edc.tests.data.BusinessPartnerNumberConstraint; -import org.eclipse.tractusx.edc.tests.data.Constraint; -import org.eclipse.tractusx.edc.tests.data.ContractDefinition; -import org.eclipse.tractusx.edc.tests.data.ContractNegotiation; -import org.eclipse.tractusx.edc.tests.data.ContractNegotiationState; -import org.eclipse.tractusx.edc.tests.data.ContractOffer; -import org.eclipse.tractusx.edc.tests.data.DataAddress; -import org.eclipse.tractusx.edc.tests.data.PayMeConstraint; -import org.eclipse.tractusx.edc.tests.data.Permission; -import org.eclipse.tractusx.edc.tests.data.Policy; -import org.eclipse.tractusx.edc.tests.data.TransferProcess; -import org.eclipse.tractusx.edc.tests.data.TransferProcessState; +import org.eclipse.tractusx.edc.tests.data.*; @Slf4j public class DataManagementAPI { @@ -77,11 +64,11 @@ public DataManagementAPI(String dataManagementUrl, String dataMgmtAuthKey) { public List requestCatalogFrom(String receivingConnectorUrl) throws IOException { final String encodedUrl = URLEncoder.encode(receivingConnectorUrl, StandardCharsets.UTF_8); - final DataManagementApiContractOfferCatalog catalog = + final ManagementApiContractOfferCatalog catalog = get( CATALOG_PATH, "providerUrl=" + encodedUrl, - new TypeToken() {}); + new TypeToken() {}); log.debug("Received " + catalog.contractOffers.size() + " offers"); @@ -91,22 +78,22 @@ public List requestCatalogFrom(String receivingConnectorUrl) thro public String initiateNegotiation( String receivingConnectorUrl, String definitionId, String assetId, Policy policy) throws IOException { - final DataManagementApiOffer offer = new DataManagementApiOffer(); + final ManagementApiOffer offer = new ManagementApiOffer(); offer.offerId = definitionId + ":foo"; offer.assetId = assetId; offer.policy = mapPolicy(policy); offer.policy.permissions.forEach(p -> p.target = assetId); - final DataManagementApiNegotiationPayload negotiationPayload = - new DataManagementApiNegotiationPayload(); + final ManagementApiNegotiationPayload negotiationPayload = + new ManagementApiNegotiationPayload(); negotiationPayload.connectorAddress = receivingConnectorUrl; negotiationPayload.offer = offer; - final DataManagementApiNegotiationResponse response = + final ManagementApiNegotiationResponse response = post( NEGOTIATIONS_PATH, negotiationPayload, - new TypeToken() {}); + new TypeToken() {}); if (response == null) throw new RuntimeException( @@ -123,18 +110,18 @@ public String initiateTransferProcess( String assetId, DataAddress dataAddress) throws IOException { - final DataManagementApiTransfer transfer = new DataManagementApiTransfer(); + final ManagementApiTransfer transfer = new ManagementApiTransfer(); transfer.connectorAddress = receivingConnectorUrl; transfer.contractId = contractAgreementId; transfer.assetId = assetId; - transfer.transferType = new DataManagementApiTransferType(); + transfer.transferType = new ManagementApiTransferType(); transfer.managedResources = false; transfer.dataDestination = mapDataAddress(dataAddress); transfer.protocol = "ids-multipart"; - final DataManagementApiTransferResponse response = - post(TRANSFER_PATH, transfer, new TypeToken() {}); + final ManagementApiTransferResponse response = + post(TRANSFER_PATH, transfer, new TypeToken() {}); if (response == null) throw new RuntimeException( @@ -146,27 +133,27 @@ public String initiateTransferProcess( } public TransferProcess getTransferProcess(String id) throws IOException { - final DataManagementApiTransferProcess transferProcess = - get(TRANSFER_PATH + "/" + id, new TypeToken() {}); + final ManagementApiTransferProcess transferProcess = + get(TRANSFER_PATH + "/" + id, new TypeToken() {}); return mapTransferProcess(transferProcess); } public ContractNegotiation getNegotiation(String id) throws IOException { - final DataManagementApiNegotiation negotiation = - get(NEGOTIATIONS_PATH + "/" + id, new TypeToken() {}); + final ManagementApiNegotiation negotiation = + get(NEGOTIATIONS_PATH + "/" + id, new TypeToken() {}); return mapNegotiation(negotiation); } public void createAsset(Asset asset) throws IOException { - final DataManagementApiDataAddress dataAddress = new DataManagementApiDataAddress(); + final ManagementApiDataAddress dataAddress = new ManagementApiDataAddress(); + final ManagementApiAssetCreate assetCreate = new ManagementApiAssetCreate(); dataAddress.properties = Map.of( - DataManagementApiDataAddress.TYPE, + ManagementApiDataAddress.TYPE, "HttpData", "baseUrl", "https://jsonplaceholder.typicode.com/todos/1"); - final DataManagementApiAssetCreate assetCreate = new DataManagementApiAssetCreate(); assetCreate.asset = mapAsset(asset); assetCreate.dataAddress = dataAddress; @@ -174,7 +161,7 @@ public void createAsset(Asset asset) throws IOException { } public void createAsset(AssetWithDataAddress assetWithDataAddress) throws IOException { - final DataManagementApiAssetCreate assetCreate = new DataManagementApiAssetCreate(); + final ManagementApiAssetCreate assetCreate = new ManagementApiAssetCreate(); assetCreate.asset = mapAsset(assetWithDataAddress.getAsset()); assetCreate.dataAddress = mapDataAddress(assetWithDataAddress.getDataAddress()); @@ -247,7 +234,7 @@ private CloseableHttpResponse sendRequest(HttpRequestBase request) throws IOExce return response; } - private ContractNegotiation mapNegotiation(DataManagementApiNegotiation negotiation) { + private ContractNegotiation mapNegotiation(ManagementApiNegotiation negotiation) { ContractNegotiationState state; @@ -271,7 +258,7 @@ private ContractNegotiation mapNegotiation(DataManagementApiNegotiation negotiat return new ContractNegotiation(negotiation.id, negotiation.contractAgreementId, state); } - private TransferProcess mapTransferProcess(DataManagementApiTransferProcess transferProcess) { + private TransferProcess mapTransferProcess(ManagementApiTransferProcess transferProcess) { TransferProcessState state; @@ -286,75 +273,76 @@ private TransferProcess mapTransferProcess(DataManagementApiTransferProcess tran return new TransferProcess(transferProcess.id, state); } - private DataManagementApiDataAddress mapDataAddress(@NonNull DataAddress dataAddress) { - final DataManagementApiDataAddress apiObject = new DataManagementApiDataAddress(); + private ManagementApiDataAddress mapDataAddress(@NonNull DataAddress dataAddress) { + final ManagementApiDataAddress apiObject = new ManagementApiDataAddress(); apiObject.setProperties(dataAddress.getProperties()); return apiObject; } - private DataManagementApiAsset mapAsset(Asset asset) { + private ManagementApiAsset mapAsset(Asset asset) { final Map properties = Map.of( - DataManagementApiAsset.ID, asset.getId(), - DataManagementApiAsset.DESCRIPTION, asset.getDescription()); + ManagementApiAsset.ID, asset.getId(), + ManagementApiAsset.DESCRIPTION, asset.getDescription()); - final DataManagementApiAsset apiObject = new DataManagementApiAsset(); + final ManagementApiAsset apiObject = new ManagementApiAsset(); apiObject.setProperties(properties); return apiObject; } - private Policy mapPolicy(DataManagementApiPolicy dataManagementApiPolicy) { - final String id = dataManagementApiPolicy.uid; + private Policy mapPolicy(ManagementApiPolicy managementApiPolicy) { + final String id = managementApiPolicy.uid; final List permissions = - dataManagementApiPolicy.permissions.stream() + managementApiPolicy.permissions.stream() .map(this::mapPermission) .collect(Collectors.toList()); return new Policy(id, permissions); } - private DataManagementApiPolicy mapPolicy(Policy policy) { - final List permissions = + private ManagementApiPolicy mapPolicy(Policy policy) { + final List permissions = policy.getPermission().stream().map(this::mapPermission).collect(Collectors.toList()); - final DataManagementApiPolicy dataManagementApiPolicy = new DataManagementApiPolicy(); - dataManagementApiPolicy.permissions = permissions; + final ManagementApiPolicy managementApiPolicy = new ManagementApiPolicy(); + managementApiPolicy.permissions = permissions; - return dataManagementApiPolicy; + return managementApiPolicy; } - private DataManagementApiPolicyDefinition mapPolicyDefinition(Policy policy) { - final DataManagementApiPolicyDefinition apiObject = new DataManagementApiPolicyDefinition(); + private ManagementApiPolicyDefinition mapPolicyDefinition(Policy policy) { + final ManagementApiPolicyDefinition apiObject = new ManagementApiPolicyDefinition(); apiObject.id = policy.getId(); apiObject.policy = mapPolicy(policy); return apiObject; } - private Permission mapPermission(DataManagementApiPermission dataManagementApiPermission) { - final String target = dataManagementApiPermission.target; - final String action = dataManagementApiPermission.action.type; + private Permission mapPermission(ManagementApiPermission managementApiPermission) { + final String target = managementApiPermission.target; + final String action = managementApiPermission.action.type; return new Permission(action, target, new ArrayList<>()); } - private DataManagementApiPermission mapPermission(Permission permission) { + private ManagementApiPermission mapPermission(Permission permission) { final String target = permission.getTarget(); final String action = permission.getAction(); - final DataManagementApiRuleAction apiAction = new DataManagementApiRuleAction(); + final ManagementApiRuleAction apiAction = new ManagementApiRuleAction(); apiAction.type = action; - final List constraints = + var constraints = permission.getConstraints().stream().map(this::mapConstraint).collect(Collectors.toList()); - final DataManagementApiPermission apiObject = new DataManagementApiPermission(); + final ManagementApiPermission apiObject = new ManagementApiPermission(); apiObject.target = target; apiObject.action = apiAction; apiObject.constraints = constraints; return apiObject; } - private DataManagementApiConstraint mapConstraint(Constraint constraint) { - - if (BusinessPartnerNumberConstraint.class.equals(constraint.getClass())) { + private ManagementConstraint mapConstraint(Constraint constraint) { + if (OrConstraint.class.equals(constraint.getClass())) { + return mapConstraint((OrConstraint) constraint); + } else if (BusinessPartnerNumberConstraint.class.equals(constraint.getClass())) { return mapConstraint((BusinessPartnerNumberConstraint) constraint); } else if (PayMeConstraint.class.equals(constraint.getClass())) { return mapConstraint((PayMeConstraint) constraint); @@ -364,17 +352,14 @@ private DataManagementApiConstraint mapConstraint(Constraint constraint) { } } - private DataManagementApiConstraint mapConstraint(PayMeConstraint constraint) { - final DataManagementApiLiteralExpression leftExpression = - new DataManagementApiLiteralExpression(); + private ManagementAtomicConstraint mapConstraint(PayMeConstraint constraint) { + final ManagementApiLiteralExpression leftExpression = new ManagementApiLiteralExpression(); leftExpression.value = "PayMe"; - final DataManagementApiLiteralExpression rightExpression = - new DataManagementApiLiteralExpression(); + final ManagementApiLiteralExpression rightExpression = new ManagementApiLiteralExpression(); rightExpression.value = String.valueOf(constraint.getAmount()); - final DataManagementApiConstraint dataManagementApiConstraint = - new DataManagementApiConstraint(); + final ManagementAtomicConstraint dataManagementApiConstraint = new ManagementAtomicConstraint(); dataManagementApiConstraint.leftExpression = leftExpression; dataManagementApiConstraint.rightExpression = rightExpression; dataManagementApiConstraint.operator = "EQ"; @@ -382,17 +367,14 @@ private DataManagementApiConstraint mapConstraint(PayMeConstraint constraint) { return dataManagementApiConstraint; } - private DataManagementApiConstraint mapConstraint(BusinessPartnerNumberConstraint constraint) { - final DataManagementApiLiteralExpression leftExpression = - new DataManagementApiLiteralExpression(); + private ManagementAtomicConstraint mapConstraint(BusinessPartnerNumberConstraint constraint) { + final ManagementApiLiteralExpression leftExpression = new ManagementApiLiteralExpression(); leftExpression.value = "BusinessPartnerNumber"; - final DataManagementApiLiteralExpression rightExpression = - new DataManagementApiLiteralExpression(); + final ManagementApiLiteralExpression rightExpression = new ManagementApiLiteralExpression(); rightExpression.value = constraint.getBusinessPartnerNumber(); - final DataManagementApiConstraint dataManagementApiConstraint = - new DataManagementApiConstraint(); + final ManagementAtomicConstraint dataManagementApiConstraint = new ManagementAtomicConstraint(); dataManagementApiConstraint.leftExpression = leftExpression; dataManagementApiConstraint.rightExpression = rightExpression; dataManagementApiConstraint.operator = "EQ"; @@ -400,31 +382,37 @@ private DataManagementApiConstraint mapConstraint(BusinessPartnerNumberConstrain return dataManagementApiConstraint; } - private ContractOffer mapOffer(DataManagementApiContractOffer dataManagementApiContractOffer) { - final String id = dataManagementApiContractOffer.id; + private ManagementOrConstraint mapConstraint(OrConstraint constraint) { + var orConstraint = new ManagementOrConstraint(); + orConstraint.constraints = + constraint.getConstraints().stream().map(this::mapConstraint).collect(Collectors.toList()); + return orConstraint; + } + + private ContractOffer mapOffer(ManagementApiContractOffer managementApiContractOffer) { + final String id = managementApiContractOffer.id; final String assetId = - dataManagementApiContractOffer.assetId != null - ? dataManagementApiContractOffer.assetId - : (String) - dataManagementApiContractOffer.asset.getProperties().get(DataManagementApiAsset.ID); + managementApiContractOffer.assetId != null + ? managementApiContractOffer.assetId + : (String) managementApiContractOffer.asset.getProperties().get(ManagementApiAsset.ID); - final Policy policy = mapPolicy(dataManagementApiContractOffer.getPolicy()); + final Policy policy = mapPolicy(managementApiContractOffer.getPolicy()); return new ContractOffer(id, policy, assetId); } - private DataManagementApiContractDefinition mapContractDefinition( + private ManagementApiContractDefinition mapContractDefinition( ContractDefinition contractDefinition) { - final DataManagementApiContractDefinition apiObject = new DataManagementApiContractDefinition(); + final ManagementApiContractDefinition apiObject = new ManagementApiContractDefinition(); apiObject.id = contractDefinition.getId(); apiObject.accessPolicyId = contractDefinition.getAcccessPolicyId(); apiObject.contractPolicyId = contractDefinition.getContractPolicyId(); apiObject.criteria = new ArrayList<>(); for (final String assetId : contractDefinition.getAssetIds()) { - DataManagementApiCriterion criterion = new DataManagementApiCriterion(); - criterion.operandLeft = DataManagementApiAsset.ID; + ManagementApiCriterion criterion = new ManagementApiCriterion(); + criterion.operandLeft = ManagementApiAsset.ID; criterion.operator = "="; criterion.operandRight = assetId; @@ -435,68 +423,68 @@ private DataManagementApiContractDefinition mapContractDefinition( } @Data - private static class DataManagementApiNegotiationResponse { + private static class ManagementApiNegotiationResponse { private String id; } @Data - private static class DataManagementApiNegotiationPayload { + private static class ManagementApiNegotiationPayload { private String connectorId = "foo"; private String connectorAddress; - private DataManagementApiOffer offer; + private ManagementApiOffer offer; } @Data - private static class DataManagementApiNegotiation { + private static class ManagementApiNegotiation { private String id; private String state; private String contractAgreementId; } @Data - private static class DataManagementApiTransferProcess { + private static class ManagementApiTransferProcess { private String id; private String state; } @Data - private static class DataManagementApiOffer { + private static class ManagementApiOffer { private String offerId; private String assetId; - private DataManagementApiPolicy policy; + private ManagementApiPolicy policy; } @Data - private static class DataManagementApiTransfer { + private static class ManagementApiTransfer { private String connectorId = "foo"; private String connectorAddress; private String contractId; private String assetId; private String protocol; - private DataManagementApiDataAddress dataDestination; + private ManagementApiDataAddress dataDestination; private boolean managedResources; - private DataManagementApiTransferType transferType; + private ManagementApiTransferType transferType; } @Data - private static class DataManagementApiTransferType { + private static class ManagementApiTransferType { private String contentType = "application/octet-stream"; private boolean isFinite = true; } @Data - private static class DataManagementApiTransferResponse { + private static class ManagementApiTransferResponse { private String id; } @Data - private static class DataManagementApiAssetCreate { - private DataManagementApiAsset asset; - private DataManagementApiDataAddress dataAddress; + private static class ManagementApiAssetCreate { + private ManagementApiAsset asset; + private ManagementApiDataAddress dataAddress; } @Data - private static class DataManagementApiAsset { + private static class ManagementApiAsset { public static final String ID = "asset:prop:id"; public static final String DESCRIPTION = "asset:prop:description"; @@ -504,76 +492,84 @@ private static class DataManagementApiAsset { } @Data - private static class DataManagementApiDataAddress { + private static class ManagementApiDataAddress { public static final String TYPE = "type"; private Map properties; } @Data - private static class DataManagementApiPolicyDefinition { + private static class ManagementApiPolicyDefinition { private String id; - private DataManagementApiPolicy policy; + private ManagementApiPolicy policy; } @Data - private static class DataManagementApiPolicy { + private static class ManagementApiPolicy { private String uid; - private List permissions = new ArrayList<>(); + private List permissions = new ArrayList<>(); } @Data - private static class DataManagementApiPermission { + private static class ManagementApiPermission { private String edctype = "dataspaceconnector:permission"; - private DataManagementApiRuleAction action; + private ManagementApiRuleAction action; private String target; - private List constraints = new ArrayList<>(); + private List constraints = new ArrayList<>(); } @Data - private static class DataManagementApiConstraint { + private static class ManagementAtomicConstraint implements ManagementConstraint { private String edctype = "AtomicConstraint"; - private DataManagementApiLiteralExpression leftExpression; - private DataManagementApiLiteralExpression rightExpression; + private ManagementApiLiteralExpression leftExpression; + private ManagementApiLiteralExpression rightExpression; private String operator; } @Data - private static class DataManagementApiLiteralExpression { + private static class ManagementOrConstraint implements ManagementConstraint { + private String edctype = "dataspaceconnector:orconstraint"; + private List constraints; + } + + private interface ManagementConstraint {} + + @Data + private static class ManagementApiLiteralExpression { private String edctype = "dataspaceconnector:literalexpression"; private String value; } @Data - private static class DataManagementApiRuleAction { + private static class ManagementApiRuleAction { private String type; } @Data - private static class DataManagementApiContractDefinition { + private static class ManagementApiContractDefinition { private String id; private String accessPolicyId; private String contractPolicyId; - private List criteria = new ArrayList<>(); + private List criteria = new ArrayList<>(); } @Data - private static class DataManagementApiCriterion { + private static class ManagementApiCriterion { private Object operandLeft; private String operator; private Object operandRight; } @Data - private static class DataManagementApiContractOffer { + private static class ManagementApiContractOffer { private String id; - private DataManagementApiPolicy policy; - private DataManagementApiAsset asset; + private ManagementApiPolicy policy; + private ManagementApiAsset asset; private String assetId; } @Data - private static class DataManagementApiContractOfferCatalog { + private static class ManagementApiContractOfferCatalog { private String id; - private List contractOffers = new ArrayList<>(); + private List contractOffers = new ArrayList<>(); } } diff --git a/edc-tests/src/test/java/org/eclipse/tractusx/edc/tests/PolicyStepDefs.java b/edc-tests/src/test/java/org/eclipse/tractusx/edc/tests/PolicyStepDefs.java index c9569e54f..a7ede22be 100644 --- a/edc-tests/src/test/java/org/eclipse/tractusx/edc/tests/PolicyStepDefs.java +++ b/edc-tests/src/test/java/org/eclipse/tractusx/edc/tests/PolicyStepDefs.java @@ -20,48 +20,45 @@ package org.eclipse.tractusx.edc.tests; +import static java.util.Arrays.stream; +import static java.util.stream.Collectors.toList; + import io.cucumber.datatable.DataTable; import io.cucumber.java.en.Given; import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.eclipse.tractusx.edc.tests.data.BusinessPartnerNumberConstraint; -import org.eclipse.tractusx.edc.tests.data.Constraint; -import org.eclipse.tractusx.edc.tests.data.PayMeConstraint; -import org.eclipse.tractusx.edc.tests.data.Permission; -import org.eclipse.tractusx.edc.tests.data.Policy; +import org.eclipse.tractusx.edc.tests.data.*; public class PolicyStepDefs { @Given("'{connector}' has the following policies") public void hasPolicies(Connector connector, DataTable table) throws Exception { - final DataManagementAPI api = connector.getDataManagementAPI(); - final List policies = parseDataTable(table); + var api = connector.getDataManagementAPI(); + var policies = table.asMaps().stream().map(this::parseRow).collect(toList()); - for (Policy policy : policies) api.createPolicy(policy); + for (var policy : policies) api.createPolicy(policy); } - private List parseDataTable(DataTable table) { - final List policies = new ArrayList<>(); - - for (Map map : table.asMaps()) { - final String id = map.get("id"); - final String action = map.get("action"); - - List constraints = new ArrayList<>(); - final String businessPartnerNumber = map.get("businessPartnerNumber"); - if (businessPartnerNumber != null && !businessPartnerNumber.isBlank()) - constraints.add(new BusinessPartnerNumberConstraint(businessPartnerNumber)); + private Policy parseRow(Map row) { + var id = row.get("id"); + var action = row.get("action"); + var constraints = new ArrayList(); - final String payMe = map.get("payMe"); - if (payMe != null && !payMe.isBlank()) - constraints.add(new PayMeConstraint(Double.parseDouble(payMe))); - - final List permission = List.of(new Permission(action, null, constraints)); - - policies.add(new Policy(id, permission)); + var businessPartnerNumber = row.get("businessPartnerNumber"); + if (businessPartnerNumber != null && !businessPartnerNumber.isBlank()) { + var bpnConstraints = + stream(businessPartnerNumber.split(",")) + .map(BusinessPartnerNumberConstraint::new) + .collect(toList()); + constraints.add(new OrConstraint(bpnConstraints)); } - return policies; + var payMe = row.get("payMe"); + if (payMe != null && !payMe.isBlank()) + constraints.add(new PayMeConstraint(Double.parseDouble(payMe))); + + var permission = new Permission(action, null, constraints); + return new Policy(id, List.of(permission)); } } diff --git a/edc-tests/src/test/java/org/eclipse/tractusx/edc/tests/data/OrConstraint.java b/edc-tests/src/test/java/org/eclipse/tractusx/edc/tests/data/OrConstraint.java new file mode 100644 index 000000000..88bf3438d --- /dev/null +++ b/edc-tests/src/test/java/org/eclipse/tractusx/edc/tests/data/OrConstraint.java @@ -0,0 +1,11 @@ +package org.eclipse.tractusx.edc.tests.data; + +import java.util.List; +import lombok.NonNull; +import lombok.Value; + +@Value +public class OrConstraint implements Constraint { + + @NonNull List constraints; +} diff --git a/edc-tests/src/test/resources/org/eclipse/tractusx/edc/tests/features/ContractOffers.feature b/edc-tests/src/test/resources/org/eclipse/tractusx/edc/tests/features/ContractOffers.feature index b2ed77760..553258322 100644 --- a/edc-tests/src/test/resources/org/eclipse/tractusx/edc/tests/features/ContractOffers.feature +++ b/edc-tests/src/test/resources/org/eclipse/tractusx/edc/tests/features/ContractOffers.feature @@ -52,7 +52,7 @@ Feature: Contract Offers | id | action | businessPartnerNumber | | policy-1 | USE | | | policy-2 | USE | BPNFOO | - | policy-3 | USE | BPNSOKRATES | + | policy-3 | USE | BPNSOKRATES,BPNF00 | And 'Plato' has the following contract definitions | id | access policy | contract policy | asset | | contract-definition-1 | policy-1 | policy-1 | asset-1 | diff --git a/pom.xml b/pom.xml index d329f5228..2776cb6af 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ org.eclipse.tractusx.edc product-edc-parent - 0.1.3 + 0.1.4 pom product-edc @@ -363,6 +363,11 @@ control-plane-adapter ${project.version} + + org.eclipse.tractusx.edc.extensions + custom-jsonld + ${project.version} + @@ -1060,6 +1065,11 @@ jdk-logger-monitor ${org.eclipse.dataspaceconnector.version} + + org.eclipse.dataspaceconnector + ids-jsonld-serdes + ${org.eclipse.dataspaceconnector.version} + org.eclipse.dataspaceconnector jersey