From 14903dbcdff9246dad10ee26b4d961a54a18d6b6 Mon Sep 17 00:00:00 2001 From: Carlos Schmidt <18703981+carlos-schmidt@users.noreply.github.com> Date: Mon, 15 Jul 2024 15:21:44 +0200 Subject: [PATCH 1/2] Use Federated Catalog Transformers over own --- client/build.gradle.kts | 1 + .../iosb/client/ClientExtension.java | 19 +++++++ .../iosb/client/policy/PolicyService.java | 23 ++------ .../JsonObjectToCatalogTransformer.java | 56 ------------------ .../JsonObjectToDataServiceTransformer.java | 50 ---------------- .../JsonObjectToDatasetTransformer.java | 55 ------------------ .../JsonObjectToDistributionTransformer.java | 57 ------------------- 7 files changed, 24 insertions(+), 237 deletions(-) delete mode 100644 client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToCatalogTransformer.java delete mode 100644 client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToDataServiceTransformer.java delete mode 100644 client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToDatasetTransformer.java delete mode 100644 client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToDistributionTransformer.java diff --git a/client/build.gradle.kts b/client/build.gradle.kts index e66435e3..f1578c86 100644 --- a/client/build.gradle.kts +++ b/client/build.gradle.kts @@ -21,6 +21,7 @@ dependencies { implementation(project(":data-plane-aas")) implementation("$group:connector-core:$edcVersion") // PolicyService + implementation("$group:federated-catalog-core:$edcVersion") // Transformers implementation("$group:control-plane-contract:$edcVersion") // Observe contract negotiations implementation("$group:control-plane-transform:$edcVersion") // Type transformers implementation("$group:data-plane-http-spi:$edcVersion") // EDC HttpDataAddress diff --git a/client/src/main/java/de/fraunhofer/iosb/client/ClientExtension.java b/client/src/main/java/de/fraunhofer/iosb/client/ClientExtension.java index fe04c380..63f0f667 100644 --- a/client/src/main/java/de/fraunhofer/iosb/client/ClientExtension.java +++ b/client/src/main/java/de/fraunhofer/iosb/client/ClientExtension.java @@ -19,11 +19,17 @@ import de.fraunhofer.iosb.client.datatransfer.DataTransferController; import de.fraunhofer.iosb.client.negotiation.NegotiationController; import de.fraunhofer.iosb.client.policy.PolicyController; +import org.eclipse.edc.catalog.transform.JsonObjectToCatalogTransformer; +import org.eclipse.edc.catalog.transform.JsonObjectToDataServiceTransformer; +import org.eclipse.edc.catalog.transform.JsonObjectToDatasetTransformer; +import org.eclipse.edc.catalog.transform.JsonObjectToDistributionTransformer; import org.eclipse.edc.connector.controlplane.contract.spi.negotiation.ConsumerContractNegotiationManager; import org.eclipse.edc.connector.controlplane.contract.spi.negotiation.observe.ContractNegotiationObservable; import org.eclipse.edc.connector.controlplane.contract.spi.negotiation.store.ContractNegotiationStore; import org.eclipse.edc.connector.controlplane.services.spi.catalog.CatalogService; import org.eclipse.edc.connector.controlplane.transfer.spi.TransferProcessManager; +import org.eclipse.edc.connector.controlplane.transform.odrl.OdrlTransformersFactory; +import org.eclipse.edc.connector.core.agent.NoOpParticipantIdMapper; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.Hostname; import org.eclipse.edc.spi.system.ServiceExtension; @@ -58,6 +64,7 @@ public class ClientExtension implements ServiceExtension { public void initialize(ServiceExtensionContext context) { var monitor = context.getMonitor(); var config = context.getConfig("edc.client"); + registerTransformers(); var negotiationController = new NegotiationController( consumerNegotiationManager, @@ -88,4 +95,16 @@ public void initialize(ServiceExtensionContext context) { .build()); } + /* + * Re-activate transformers that were deleted in EDC after version 0.6.0 + * Also activate other transformers needed for PolicyService but not registered in the right place + */ + private void registerTransformers() { + transformer.register(new JsonObjectToCatalogTransformer()); + transformer.register(new JsonObjectToDatasetTransformer()); + transformer.register(new JsonObjectToDataServiceTransformer()); + transformer.register(new JsonObjectToDistributionTransformer()); + OdrlTransformersFactory.jsonObjectToOdrlTransformers(new NoOpParticipantIdMapper()) + .forEach(transformer::register); + } } diff --git a/client/src/main/java/de/fraunhofer/iosb/client/policy/PolicyService.java b/client/src/main/java/de/fraunhofer/iosb/client/policy/PolicyService.java index 65c9bc06..274e9f2d 100644 --- a/client/src/main/java/de/fraunhofer/iosb/client/policy/PolicyService.java +++ b/client/src/main/java/de/fraunhofer/iosb/client/policy/PolicyService.java @@ -16,11 +16,11 @@ package de.fraunhofer.iosb.client.policy; import de.fraunhofer.iosb.client.exception.AmbiguousOrNullException; -import de.fraunhofer.iosb.client.policy.transform.JsonObjectToCatalogTransformer; -import de.fraunhofer.iosb.client.policy.transform.JsonObjectToDataServiceTransformer; -import de.fraunhofer.iosb.client.policy.transform.JsonObjectToDatasetTransformer; -import de.fraunhofer.iosb.client.policy.transform.JsonObjectToDistributionTransformer; import jakarta.json.Json; +import org.eclipse.edc.catalog.transform.JsonObjectToCatalogTransformer; +import org.eclipse.edc.catalog.transform.JsonObjectToDataServiceTransformer; +import org.eclipse.edc.catalog.transform.JsonObjectToDatasetTransformer; +import org.eclipse.edc.catalog.transform.JsonObjectToDistributionTransformer; import org.eclipse.edc.connector.controlplane.asset.spi.domain.Asset; import org.eclipse.edc.connector.controlplane.catalog.spi.Catalog; import org.eclipse.edc.connector.controlplane.catalog.spi.Dataset; @@ -84,10 +84,7 @@ class PolicyService { this.transformer = transformer; this.config = config; this.policyDefinitionStore = policyDefinitionStore; - this.jsonLdExpander = new TitaniumJsonLd(monitor); - - registerTransformers(); } Dataset getDatasetForAssetId(@NotNull String counterPartyId, @NotNull URL counterPartyUrl, @NotNull String assetId) throws InterruptedException { @@ -190,16 +187,4 @@ private boolean ruleEquality(T first, T second) { second.getConstraints()); } - /* Re-activate transformers that were deleted in EDC after version 0.6.0 - * Also activate other transformers needed for PolicyService but not registered in the right place - */ - private void registerTransformers() { - transformer.register(new JsonObjectToCatalogTransformer()); - transformer.register(new JsonObjectToDatasetTransformer()); - transformer.register(new JsonObjectToDataServiceTransformer()); - transformer.register(new JsonObjectToDistributionTransformer()); - OdrlTransformersFactory.jsonObjectToOdrlTransformers(new NoOpParticipantIdMapper()) - .forEach(transformer::register); - } - } diff --git a/client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToCatalogTransformer.java b/client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToCatalogTransformer.java deleted file mode 100644 index c40c8d7a..00000000 --- a/client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToCatalogTransformer.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige - * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten - * Forschung e.V. - * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://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. - */ -package de.fraunhofer.iosb.client.policy.transform; - -import jakarta.json.JsonObject; -import org.eclipse.edc.connector.controlplane.catalog.spi.Catalog; -import org.eclipse.edc.connector.controlplane.catalog.spi.DataService; -import org.eclipse.edc.connector.controlplane.catalog.spi.Dataset; -import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_DATASET_ATTRIBUTE; -import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_DATA_SERVICE_ATTRIBUTE; -import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DSPACE_PROPERTY_PARTICIPANT_ID; - -/** - * Transformer for Catalog in JSON representation to EDC Catalog class. - * Modified code from github.com - *
See also: https://github.com/eclipse-edc/Connector/pull/3916 - */ -public class JsonObjectToCatalogTransformer extends AbstractJsonLdTransformer { - - public JsonObjectToCatalogTransformer() { - super(JsonObject.class, Catalog.class); - } - - @Override - public @Nullable Catalog transform(@NotNull JsonObject jsonObject, @NotNull TransformerContext context) { - var builder = Catalog.Builder.newInstance(); - - // Collect parameters - builder.id(nodeId(jsonObject)); - transformString(jsonObject.get(DSPACE_PROPERTY_PARTICIPANT_ID), builder::participantId, context); - transformArrayOrObject(jsonObject.get(DCAT_DATASET_ATTRIBUTE), Dataset.class, builder::dataset, context); - transformArrayOrObject(jsonObject.get(DCAT_DATA_SERVICE_ATTRIBUTE), DataService.class, builder::dataService, context); - - // Note: We don't need additional properties here, so they are ignored - return builderResult(builder::build, context); - } -} diff --git a/client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToDataServiceTransformer.java b/client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToDataServiceTransformer.java deleted file mode 100644 index 61dfefaf..00000000 --- a/client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToDataServiceTransformer.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige - * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten - * Forschung e.V. - * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://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. - */ -package de.fraunhofer.iosb.client.policy.transform; - -import jakarta.json.JsonObject; -import org.eclipse.edc.connector.controlplane.catalog.spi.DataService; -import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_ENDPOINT_DESCRIPTION_ATTRIBUTE; -import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_ENDPOINT_URL_ATTRIBUTE; - -/** - * Transform JSON to DataService. - * Modified code from: https://github.com/eclipse-edc/Connector/tree/v0.5.1/core/common/transform-core - */ -public class JsonObjectToDataServiceTransformer extends AbstractJsonLdTransformer { - - public JsonObjectToDataServiceTransformer() { - super(JsonObject.class, DataService.class); - } - - @Override - public @Nullable DataService transform(@NotNull JsonObject jsonObject, @NotNull TransformerContext context) { - var builder = DataService.Builder.newInstance(); - - // Collect parameters - builder.id(nodeId(jsonObject)); - transformString(jsonObject.get(DCAT_ENDPOINT_DESCRIPTION_ATTRIBUTE), builder::endpointDescription, context); - transformString(jsonObject.get(DCAT_ENDPOINT_URL_ATTRIBUTE), builder::endpointUrl, context); - - return builderResult(builder::build, context); - } -} diff --git a/client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToDatasetTransformer.java b/client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToDatasetTransformer.java deleted file mode 100644 index e9c263b1..00000000 --- a/client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToDatasetTransformer.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige - * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten - * Forschung e.V. - * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://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. - */ -package de.fraunhofer.iosb.client.policy.transform; - -import jakarta.json.JsonObject; -import org.eclipse.edc.connector.controlplane.catalog.spi.Dataset; -import org.eclipse.edc.connector.controlplane.catalog.spi.Distribution; -import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; -import org.eclipse.edc.policy.model.Policy; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_DISTRIBUTION_ATTRIBUTE; -import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_POLICY_ATTRIBUTE; - - -/** - * Transform JSON to Dataset. - * Modified code from: https://github.com/eclipse-edc/Connector/tree/v0.5.1/core/common/transform-core - */ -public class JsonObjectToDatasetTransformer extends AbstractJsonLdTransformer { - - public JsonObjectToDatasetTransformer() { - super(JsonObject.class, Dataset.class); - } - - @Override - public @Nullable Dataset transform(@NotNull JsonObject jsonObject, @NotNull TransformerContext context) { - var builder = Dataset.Builder.newInstance(); - - // Collect parameters - builder.id(nodeId(jsonObject)); - transformArrayOrObject(jsonObject.get(DCAT_DISTRIBUTION_ATTRIBUTE), Distribution.class, builder::distribution, context); - jsonObject.getJsonArray(ODRL_POLICY_ATTRIBUTE) - .forEach(offer -> builder.offer(nodeId(offer), transformObject(offer, Policy.class, context))); - - // Note: properties not considered (see CatalogTransformer) - return builderResult(builder::build, context); - } -} diff --git a/client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToDistributionTransformer.java b/client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToDistributionTransformer.java deleted file mode 100644 index f5beff40..00000000 --- a/client/src/main/java/de/fraunhofer/iosb/client/policy/transform/JsonObjectToDistributionTransformer.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige - * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten - * Forschung e.V. - * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://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. - */ -package de.fraunhofer.iosb.client.policy.transform; - -import jakarta.json.JsonObject; -import org.eclipse.edc.connector.controlplane.catalog.spi.DataService; -import org.eclipse.edc.connector.controlplane.catalog.spi.Distribution; -import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_ACCESS_SERVICE_ATTRIBUTE; -import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_DATA_SERVICE_ATTRIBUTE; -import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCT_FORMAT_ATTRIBUTE; - -/** - * Transform JSON to DataService. - * Modified code from: https://github.com/eclipse-edc/Connector/tree/v0.5.1/core/common/transform-core - */ -public class JsonObjectToDistributionTransformer extends AbstractJsonLdTransformer { - - public JsonObjectToDistributionTransformer() { - super(JsonObject.class, Distribution.class); - } - - @Override - public @Nullable Distribution transform(@NotNull JsonObject jsonObject, @NotNull TransformerContext context) { - var builder = Distribution.Builder.newInstance(); - - transformMandatoryString(jsonObject.get(DCT_FORMAT_ATTRIBUTE), builder::format, context); - transformArrayOrObject( - Optional.of(jsonObject.get(DCAT_ACCESS_SERVICE_ATTRIBUTE)) - .orElse(jsonObject.get(DCAT_DATA_SERVICE_ATTRIBUTE)), - DataService.class, - builder::dataService, - context); - - return builderResult(builder::build, context); - } -} From 04ab9e43c8393902433b8713a443bf3550aab1d5 Mon Sep 17 00:00:00 2001 From: Carlos Schmidt <18703981+carlos-schmidt@users.noreply.github.com> Date: Mon, 15 Jul 2024 15:28:49 +0200 Subject: [PATCH 2/2] Cleanup code --- .../de/fraunhofer/iosb/client/policy/PolicyService.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/client/src/main/java/de/fraunhofer/iosb/client/policy/PolicyService.java b/client/src/main/java/de/fraunhofer/iosb/client/policy/PolicyService.java index 274e9f2d..43ff9c3d 100644 --- a/client/src/main/java/de/fraunhofer/iosb/client/policy/PolicyService.java +++ b/client/src/main/java/de/fraunhofer/iosb/client/policy/PolicyService.java @@ -17,17 +17,11 @@ import de.fraunhofer.iosb.client.exception.AmbiguousOrNullException; import jakarta.json.Json; -import org.eclipse.edc.catalog.transform.JsonObjectToCatalogTransformer; -import org.eclipse.edc.catalog.transform.JsonObjectToDataServiceTransformer; -import org.eclipse.edc.catalog.transform.JsonObjectToDatasetTransformer; -import org.eclipse.edc.catalog.transform.JsonObjectToDistributionTransformer; import org.eclipse.edc.connector.controlplane.asset.spi.domain.Asset; import org.eclipse.edc.connector.controlplane.catalog.spi.Catalog; import org.eclipse.edc.connector.controlplane.catalog.spi.Dataset; import org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractOffer; import org.eclipse.edc.connector.controlplane.services.spi.catalog.CatalogService; -import org.eclipse.edc.connector.controlplane.transform.odrl.OdrlTransformersFactory; -import org.eclipse.edc.connector.core.agent.NoOpParticipantIdMapper; import org.eclipse.edc.jsonld.TitaniumJsonLd; import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.policy.model.Policy;