diff --git a/core/common/connector-core/build.gradle.kts b/core/common/connector-core/build.gradle.kts index 3ed9683cb4d..7d5d2f93d8e 100644 --- a/core/common/connector-core/build.gradle.kts +++ b/core/common/connector-core/build.gradle.kts @@ -28,6 +28,7 @@ dependencies { api(project(":spi:common:validator-spi")) implementation(project(":core:common:policy-engine")) + implementation(project(":core:common:transform-core")) implementation(project(":core:common:util")) implementation(libs.dnsOverHttps) diff --git a/core/common/connector-core/src/main/java/org/eclipse/edc/connector/core/CoreServicesExtension.java b/core/common/connector-core/src/main/java/org/eclipse/edc/connector/core/CoreServicesExtension.java index 826d8933273..559e63c9f14 100644 --- a/core/common/connector-core/src/main/java/org/eclipse/edc/connector/core/CoreServicesExtension.java +++ b/core/common/connector-core/src/main/java/org/eclipse/edc/connector/core/CoreServicesExtension.java @@ -22,8 +22,8 @@ import org.eclipse.edc.connector.core.health.HealthCheckServiceConfiguration; import org.eclipse.edc.connector.core.health.HealthCheckServiceImpl; import org.eclipse.edc.connector.core.security.DefaultPrivateKeyParseFunction; -import org.eclipse.edc.connector.core.transform.TypeTransformerRegistryImpl; import org.eclipse.edc.connector.core.validator.JsonObjectValidatorRegistryImpl; +import org.eclipse.edc.core.transform.TypeTransformerRegistryImpl; import org.eclipse.edc.policy.engine.PolicyEngineImpl; import org.eclipse.edc.policy.engine.RuleBindingRegistryImpl; import org.eclipse.edc.policy.engine.ScopeFilter; diff --git a/core/common/junit/src/main/java/org/eclipse/edc/junit/assertions/AbstractResultAssert.java b/core/common/junit/src/main/java/org/eclipse/edc/junit/assertions/AbstractResultAssert.java index 3d923f2f6f8..526579c91c5 100644 --- a/core/common/junit/src/main/java/org/eclipse/edc/junit/assertions/AbstractResultAssert.java +++ b/core/common/junit/src/main/java/org/eclipse/edc/junit/assertions/AbstractResultAssert.java @@ -43,7 +43,7 @@ public static , RESULT ext public ObjectAssert isSucceeded() { isNotNull(); if (!actual.succeeded()) { - failWithMessage("Expected result to be succeeded, but it was failed"); + failWithMessage("Expected result to be succeeded, but it was failed: " + actual.getFailureDetail()); } return Assertions.assertThat(actual.getContent()); } diff --git a/data-protocols/dsp/dsp-transform/build.gradle.kts b/core/common/transform-core/build.gradle.kts similarity index 60% rename from data-protocols/dsp/dsp-transform/build.gradle.kts rename to core/common/transform-core/build.gradle.kts index 92155b37ddb..5913d6c63bc 100644 --- a/data-protocols/dsp/dsp-transform/build.gradle.kts +++ b/core/common/transform-core/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * This program and the accompanying materials are made available under the * terms of the Apache License, Version 2.0 which is available at @@ -8,21 +8,23 @@ * SPDX-License-Identifier: Apache-2.0 * * Contributors: - * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation * */ plugins { `java-library` + `maven-publish` } dependencies { - api(libs.titaniumJsonLd) - - api(project(":extensions:common:json-ld")) - api(project(":spi:common:core-spi")) api(project(":spi:common:catalog-spi")) + api(project(":spi:common:core-spi")) api(project(":spi:common:json-ld-spi")) + api(project(":spi:common:transform-spi")) + + api(libs.jakartaJson) testImplementation(project(":core:common:junit")) + testImplementation(project(":extensions:common:json-ld")) } diff --git a/core/common/connector-core/src/main/java/org/eclipse/edc/connector/core/transform/TransformerContextImpl.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/TransformerContextImpl.java similarity index 93% rename from core/common/connector-core/src/main/java/org/eclipse/edc/connector/core/transform/TransformerContextImpl.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/TransformerContextImpl.java index f98fba45fb8..1c5511f6873 100644 --- a/core/common/connector-core/src/main/java/org/eclipse/edc/connector/core/transform/TransformerContextImpl.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/TransformerContextImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022 - 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * This program and the accompanying materials are made available under the * terms of the Apache License, Version 2.0 which is available at @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.connector.core.transform; +package org.eclipse.edc.core.transform; import org.eclipse.edc.transform.spi.ProblemBuilder; import org.eclipse.edc.transform.spi.TransformerContext; diff --git a/core/common/connector-core/src/main/java/org/eclipse/edc/connector/core/transform/TypeTransformerRegistryImpl.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/TypeTransformerRegistryImpl.java similarity index 95% rename from core/common/connector-core/src/main/java/org/eclipse/edc/connector/core/transform/TypeTransformerRegistryImpl.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/TypeTransformerRegistryImpl.java index 67edd80536c..22b1485e2d8 100644 --- a/core/common/connector-core/src/main/java/org/eclipse/edc/connector/core/transform/TypeTransformerRegistryImpl.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/TypeTransformerRegistryImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022 - 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * This program and the accompanying materials are made available under the * terms of the Apache License, Version 2.0 which is available at @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.connector.core.transform; +package org.eclipse.edc.core.transform; import org.eclipse.edc.spi.EdcException; import org.eclipse.edc.spi.result.Result; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/OdrlTransformersFactory.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/OdrlTransformersFactory.java similarity index 63% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/OdrlTransformersFactory.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/OdrlTransformersFactory.java index e7543d83ccc..e69d3d17ac4 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/OdrlTransformersFactory.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/OdrlTransformersFactory.java @@ -12,15 +12,15 @@ * */ -package org.eclipse.edc.jsonld.transformer; +package org.eclipse.edc.core.transform.transformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToActionTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToConstraintTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToDutyTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToOperatorTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToPermissionTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToPolicyTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToProhibitionTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToActionTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToConstraintTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToDutyTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToOperatorTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToPermissionTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToPolicyTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToProhibitionTransformer; import org.eclipse.edc.transform.spi.TypeTransformer; import java.util.stream.Stream; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromAssetTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromAssetTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromAssetTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromAssetTransformer.java index b908f16f16e..96928451169 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromAssetTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromAssetTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.JsonBuilderFactory; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromCatalogTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromCatalogTransformer.java similarity index 98% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromCatalogTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromCatalogTransformer.java index b1b0fc53ca8..38b30027f59 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromCatalogTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromCatalogTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.JsonArrayBuilder; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromCriterionTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromCriterionTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromCriterionTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromCriterionTransformer.java index 5c38fb0f56d..c4e56746d95 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromCriterionTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromCriterionTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.JsonBuilderFactory; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDataServiceTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDataServiceTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDataServiceTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDataServiceTransformer.java index c53ee457ca1..0b75844967b 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDataServiceTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDataServiceTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import jakarta.json.JsonBuilderFactory; import jakarta.json.JsonObject; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDatasetTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDatasetTransformer.java similarity index 98% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDatasetTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDatasetTransformer.java index d1e033c30b7..a56a2c3039d 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDatasetTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDatasetTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.Json; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDistributionTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDistributionTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDistributionTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDistributionTransformer.java index 7d99782733e..beded81de6c 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDistributionTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDistributionTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import jakarta.json.JsonBuilderFactory; import jakarta.json.JsonObject; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromPolicyTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromPolicyTransformer.java similarity index 99% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromPolicyTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromPolicyTransformer.java index cc1b2c05801..c06799d93d4 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromPolicyTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromPolicyTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import jakarta.json.Json; import jakarta.json.JsonArray; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromQuerySpecTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromQuerySpecTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromQuerySpecTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromQuerySpecTransformer.java index fc3fa693cbf..26284869d7a 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromQuerySpecTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromQuerySpecTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import jakarta.json.JsonArrayBuilder; import jakarta.json.JsonBuilderFactory; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToActionTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToActionTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToActionTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToActionTransformer.java index 7ffc927be7c..5462fd91bd8 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToActionTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToActionTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonObject; import jakarta.json.JsonValue; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToAssetTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToAssetTransformer.java similarity index 98% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToAssetTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToAssetTransformer.java index efe8ba36b90..fdabf1ba137 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToAssetTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToAssetTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonArray; import jakarta.json.JsonObject; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToCatalogTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToCatalogTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToCatalogTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToCatalogTransformer.java index 055be491837..c472a62c1a4 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToCatalogTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToCatalogTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonObject; import jakarta.json.JsonValue; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToConstraintTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToConstraintTransformer.java similarity index 99% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToConstraintTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToConstraintTransformer.java index 6a1b48b831d..8bcf6d21aeb 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToConstraintTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToConstraintTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonNumber; import jakarta.json.JsonObject; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToCriterionTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToCriterionTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToCriterionTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToCriterionTransformer.java index 7c25d45c056..9defde784c0 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToCriterionTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToCriterionTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonObject; import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDataAddressTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDataAddressTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDataAddressTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDataAddressTransformer.java index 4166ad8dbe3..ee5f465d430 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDataAddressTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDataAddressTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonArray; import jakarta.json.JsonObject; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDataServiceTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDataServiceTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDataServiceTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDataServiceTransformer.java index dbab801b47b..0d24ad6b739 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDataServiceTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDataServiceTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonObject; import jakarta.json.JsonValue; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDatasetTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDatasetTransformer.java similarity index 98% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDatasetTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDatasetTransformer.java index eecd5d4bf8e..1185a22aef1 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDatasetTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDatasetTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonArray; import jakarta.json.JsonObject; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDistributionTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDistributionTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDistributionTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDistributionTransformer.java index 3903000afe6..db19642c4ea 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDistributionTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDistributionTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonObject; import jakarta.json.JsonValue; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDutyTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDutyTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDutyTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDutyTransformer.java index bb03f3d0763..a1711b553fe 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDutyTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDutyTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonObject; import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToOperatorTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToOperatorTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToOperatorTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToOperatorTransformer.java index 9976635fcd1..277b46329ab 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToOperatorTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToOperatorTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonObject; import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToPermissionTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToPermissionTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToPermissionTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToPermissionTransformer.java index 2886851011e..f6c2f42b97e 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToPermissionTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToPermissionTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonObject; import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToPolicyTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToPolicyTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToPolicyTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToPolicyTransformer.java index 33f8e6ae3f0..45fb46db7ad 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToPolicyTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToPolicyTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonObject; import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToProhibitionTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToProhibitionTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToProhibitionTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToProhibitionTransformer.java index 12bf223436a..07ab08d37ab 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToProhibitionTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToProhibitionTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonObject; import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToQuerySpecTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToQuerySpecTransformer.java similarity index 97% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToQuerySpecTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToQuerySpecTransformer.java index 91438b15104..71dd4bef877 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToQuerySpecTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToQuerySpecTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonObject; import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonValueToGenericTypeTransformer.java b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonValueToGenericTypeTransformer.java similarity index 98% rename from extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonValueToGenericTypeTransformer.java rename to core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonValueToGenericTypeTransformer.java index ce03678046a..fcdcd6caa70 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/transformer/to/JsonValueToGenericTypeTransformer.java +++ b/core/common/transform-core/src/main/java/org/eclipse/edc/core/transform/transformer/to/JsonValueToGenericTypeTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/Payload.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/Payload.java similarity index 95% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/Payload.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/Payload.java index 76b412d2704..2a2ddd1a242 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/Payload.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/Payload.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer; +package org.eclipse.edc.core.transform; public class Payload { private String name; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/PayloadTransformer.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/PayloadTransformer.java similarity index 96% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/PayloadTransformer.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/PayloadTransformer.java index d2b3e6d6690..54bed6cd2d2 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/PayloadTransformer.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/PayloadTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer; +package org.eclipse.edc.core.transform; import jakarta.json.JsonObject; import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; diff --git a/core/common/connector-core/src/test/java/org/eclipse/edc/connector/core/transform/StringIntegerTypeTransformer.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/StringIntegerTypeTransformer.java similarity index 90% rename from core/common/connector-core/src/test/java/org/eclipse/edc/connector/core/transform/StringIntegerTypeTransformer.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/StringIntegerTypeTransformer.java index 4bd39d9d6ec..ee0a0bb3a51 100644 --- a/core/common/connector-core/src/test/java/org/eclipse/edc/connector/core/transform/StringIntegerTypeTransformer.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/StringIntegerTypeTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022 - 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * This program and the accompanying materials are made available under the * terms of the Apache License, Version 2.0 which is available at @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.connector.core.transform; +package org.eclipse.edc.core.transform; import org.eclipse.edc.transform.spi.TransformerContext; import org.eclipse.edc.transform.spi.TypeTransformer; diff --git a/core/common/connector-core/src/test/java/org/eclipse/edc/connector/core/transform/TransformerContextImplTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/TransformerContextImplTest.java similarity index 93% rename from core/common/connector-core/src/test/java/org/eclipse/edc/connector/core/transform/TransformerContextImplTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/TransformerContextImplTest.java index a9ee911723d..a1e2b1515df 100644 --- a/core/common/connector-core/src/test/java/org/eclipse/edc/connector/core/transform/TransformerContextImplTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/TransformerContextImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022 - 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * This program and the accompanying materials are made available under the * terms of the Apache License, Version 2.0 which is available at @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.connector.core.transform; +package org.eclipse.edc.core.transform; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.junit.jupiter.api.Test; diff --git a/core/common/connector-core/src/test/java/org/eclipse/edc/connector/core/transform/TypeTransformerRegistryImplTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/TypeTransformerRegistryImplTest.java similarity index 96% rename from core/common/connector-core/src/test/java/org/eclipse/edc/connector/core/transform/TypeTransformerRegistryImplTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/TypeTransformerRegistryImplTest.java index 457bc92c05e..35217bb106f 100644 --- a/core/common/connector-core/src/test/java/org/eclipse/edc/connector/core/transform/TypeTransformerRegistryImplTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/TypeTransformerRegistryImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022 - 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * This program and the accompanying materials are made available under the * terms of the Apache License, Version 2.0 which is available at @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.connector.core.transform; +package org.eclipse.edc.core.transform; import org.eclipse.edc.spi.EdcException; import org.eclipse.edc.spi.result.Result; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/TestInput.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/TestInput.java similarity index 95% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/TestInput.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/TestInput.java index fe7ae0a0f17..249d2735921 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/TestInput.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/TestInput.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer; import com.apicatalog.jsonld.document.JsonDocument; import jakarta.json.JsonObject; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromAssetTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromAssetTransformerTest.java similarity index 98% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromAssetTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromAssetTransformerTest.java index c09b3bd9339..58e8e446e70 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromAssetTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromAssetTransformerTest.java @@ -12,12 +12,12 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import jakarta.json.Json; import jakarta.json.JsonArrayBuilder; import jakarta.json.JsonObject; -import org.eclipse.edc.jsonld.transformer.Payload; +import org.eclipse.edc.core.transform.Payload; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.edc.transform.spi.TransformerContext; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromCatalogTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromCatalogTransformerTest.java similarity index 98% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromCatalogTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromCatalogTransformerTest.java index 71f13add879..decdddaefc8 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromCatalogTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromCatalogTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.Json; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromCriterionTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromCriterionTransformerTest.java similarity index 98% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromCriterionTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromCriterionTransformerTest.java index 8461983c498..712ea93e534 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromCriterionTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromCriterionTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.Json; @@ -87,4 +87,4 @@ void transform_reportErrors() { } -} \ No newline at end of file +} diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDataServiceTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDataServiceTransformerTest.java similarity index 97% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDataServiceTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDataServiceTransformerTest.java index 457c05f9f43..a161a243296 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDataServiceTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDataServiceTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import jakarta.json.Json; import jakarta.json.JsonBuilderFactory; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDatasetTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDatasetTransformerTest.java similarity index 98% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDatasetTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDatasetTransformerTest.java index ead884dda79..7e501501093 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDatasetTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDatasetTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.Json; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDistributionTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDistributionTransformerTest.java similarity index 97% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDistributionTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDistributionTransformerTest.java index 252f9e1e989..261ea3e55ff 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromDistributionTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromDistributionTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import jakarta.json.Json; import jakarta.json.JsonBuilderFactory; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromPolicyTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromPolicyTransformerTest.java similarity index 99% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromPolicyTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromPolicyTransformerTest.java index 2af32b52e0e..d99ddc10ecf 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromPolicyTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromPolicyTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import jakarta.json.Json; import jakarta.json.JsonArray; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromQuerySpecTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromQuerySpecTransformerTest.java similarity index 97% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromQuerySpecTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromQuerySpecTransformerTest.java index fc54ed4fcb6..268d965be07 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/from/JsonObjectFromQuerySpecTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/from/JsonObjectFromQuerySpecTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.from; +package org.eclipse.edc.core.transform.transformer.from; import jakarta.json.Json; import jakarta.json.JsonArray; @@ -69,4 +69,4 @@ void transform() { } -} \ No newline at end of file +} diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToActionTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToActionTransformerTest.java similarity index 97% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToActionTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToActionTransformerTest.java index 8975bdead6c..06d4e60c957 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToActionTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToActionTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.Json; import jakarta.json.JsonBuilderFactory; @@ -29,12 +29,12 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_ACTION_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_ACTION_TYPE_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_INCLUDED_IN_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_REFINEMENT_ATTRIBUTE; -import static org.eclipse.edc.jsonld.transformer.to.TestInput.getExpanded; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToAssetTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToAssetTransformerTest.java similarity index 96% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToAssetTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToAssetTransformerTest.java index 2b36710b32b..e451cced035 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToAssetTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToAssetTransformerTest.java @@ -12,17 +12,17 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import com.fasterxml.jackson.core.JsonProcessingException; import jakarta.json.Json; import jakarta.json.JsonBuilderFactory; import jakarta.json.JsonObject; import jakarta.json.JsonObjectBuilder; -import org.eclipse.edc.connector.core.transform.TypeTransformerRegistryImpl; +import org.eclipse.edc.core.transform.Payload; +import org.eclipse.edc.core.transform.PayloadTransformer; +import org.eclipse.edc.core.transform.TypeTransformerRegistryImpl; import org.eclipse.edc.jsonld.TitaniumJsonLd; -import org.eclipse.edc.jsonld.transformer.Payload; -import org.eclipse.edc.jsonld.transformer.PayloadTransformer; import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.asset.Asset; @@ -33,11 +33,11 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; -import static org.eclipse.edc.jsonld.transformer.to.TestInput.getExpanded; import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToAtomicConstraintComplexTypeTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToAtomicConstraintComplexTypeTest.java similarity index 98% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToAtomicConstraintComplexTypeTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToAtomicConstraintComplexTypeTest.java index 1ad01ea2e27..710f6d5d187 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToAtomicConstraintComplexTypeTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToAtomicConstraintComplexTypeTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.Json; import jakarta.json.JsonArray; @@ -32,12 +32,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.InstanceOfAssertFactories.type; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_LEFT_OPERAND_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_OPERATOR_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_RIGHT_OPERAND_ATTRIBUTE; -import static org.eclipse.edc.jsonld.transformer.to.TestInput.getExpanded; import static org.eclipse.edc.policy.model.Operator.EQ; import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; import static org.eclipse.edc.spi.CoreConstants.EDC_PREFIX; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToCatalogTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToCatalogTransformerTest.java similarity index 97% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToCatalogTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToCatalogTransformerTest.java index 39888d00182..76db456d1f2 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToCatalogTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToCatalogTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.Json; import jakarta.json.JsonBuilderFactory; @@ -29,12 +29,12 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_CATALOG_TYPE; 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.transformer.to.TestInput.getExpanded; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToConstraintTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToConstraintTransformerTest.java similarity index 98% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToConstraintTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToConstraintTransformerTest.java index eb5ec802161..7868a5b1780 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToConstraintTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToConstraintTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.Json; import jakarta.json.JsonBuilderFactory; @@ -41,6 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.InstanceOfAssertFactories.type; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; @@ -51,7 +52,6 @@ import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_OR_CONSTRAINT_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_RIGHT_OPERAND_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_XONE_CONSTRAINT_ATTRIBUTE; -import static org.eclipse.edc.jsonld.transformer.to.TestInput.getExpanded; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToCriterionTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToCriterionTransformerTest.java similarity index 94% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToCriterionTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToCriterionTransformerTest.java index 6eee1024782..64570bb47d7 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToCriterionTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToCriterionTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.Json; import jakarta.json.JsonValue; @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.edc.jsonld.transformer.to.TestInput.getExpanded; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; import static org.eclipse.edc.spi.query.Criterion.CRITERION_OPERAND_LEFT; import static org.eclipse.edc.spi.query.Criterion.CRITERION_OPERAND_RIGHT; @@ -55,4 +55,4 @@ void transform() { assertThat(crit.getOperandLeft()).isEqualTo("foo"); assertThat(crit.getOperandRight()).isEqualTo("bar"); } -} \ No newline at end of file +} diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDataAddressTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDataAddressTransformerTest.java similarity index 98% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDataAddressTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDataAddressTransformerTest.java index 95c41e9f28d..053590cac3f 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDataAddressTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDataAddressTransformerTest.java @@ -12,14 +12,14 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.JsonObject; import jakarta.json.JsonObjectBuilder; import jakarta.json.JsonValue; +import org.eclipse.edc.core.transform.Payload; import org.eclipse.edc.jsonld.TitaniumJsonLd; import org.eclipse.edc.jsonld.spi.JsonLd; -import org.eclipse.edc.jsonld.transformer.Payload; import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.transform.spi.ProblemBuilder; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDataServiceTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDataServiceTransformerTest.java similarity index 95% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDataServiceTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDataServiceTransformerTest.java index f0ac7fe70b4..5d52dae60d4 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDataServiceTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDataServiceTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.Json; import jakarta.json.JsonBuilderFactory; @@ -23,12 +23,12 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_DATA_SERVICE_TYPE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCT_ENDPOINT_URL_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCT_TERMS_ATTRIBUTE; -import static org.eclipse.edc.jsonld.transformer.to.TestInput.getExpanded; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDatasetTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDatasetTransformerTest.java similarity index 97% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDatasetTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDatasetTransformerTest.java index 3bebb6b076c..9dc9870585d 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDatasetTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDatasetTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.Json; import jakarta.json.JsonBuilderFactory; @@ -28,12 +28,12 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_DATASET_TYPE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_DISTRIBUTION_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_POLICY_ATTRIBUTE; -import static org.eclipse.edc.jsonld.transformer.to.TestInput.getExpanded; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDistributionTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDistributionTransformerTest.java similarity index 95% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDistributionTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDistributionTransformerTest.java index 80686b53f77..c96dfa44a65 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDistributionTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDistributionTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.Json; import jakarta.json.JsonBuilderFactory; @@ -23,11 +23,11 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_ACCESS_SERVICE_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_DISTRIBUTION_TYPE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCT_FORMAT_ATTRIBUTE; -import static org.eclipse.edc.jsonld.transformer.to.TestInput.getExpanded; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDutyTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDutyTransformerTest.java similarity index 97% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDutyTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDutyTransformerTest.java index f352eccfb13..f1b122b9bd6 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToDutyTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToDutyTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.Json; import jakarta.json.JsonObject; @@ -29,12 +29,12 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_ACTION_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_CONSEQUENCE_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_CONSTRAINT_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_TARGET_ATTRIBUTE; -import static org.eclipse.edc.jsonld.transformer.to.TestInput.getExpanded; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToOperatorTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToOperatorTransformerTest.java similarity index 97% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToOperatorTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToOperatorTransformerTest.java index eee51ce8966..fb09eb740f7 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToOperatorTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToOperatorTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.Json; import jakarta.json.JsonBuilderFactory; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToPermissionTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToPermissionTransformerTest.java similarity index 97% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToPermissionTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToPermissionTransformerTest.java index 80dd5951b3d..5fad443b1ef 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToPermissionTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToPermissionTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.Json; import jakarta.json.JsonObject; @@ -29,12 +29,12 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_ACTION_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_CONSTRAINT_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_DUTY_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_TARGET_ATTRIBUTE; -import static org.eclipse.edc.jsonld.transformer.to.TestInput.getExpanded; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToPolicyTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToPolicyTransformerTest.java similarity index 98% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToPolicyTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToPolicyTransformerTest.java index 9038485d4e1..25a0302e7cd 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToPolicyTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToPolicyTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.Json; import jakarta.json.JsonBuilderFactory; @@ -33,6 +33,7 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_OBLIGATION_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_PERMISSION_ATTRIBUTE; @@ -41,7 +42,6 @@ import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_POLICY_TYPE_SET; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_PROHIBITION_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_TARGET_ATTRIBUTE; -import static org.eclipse.edc.jsonld.transformer.to.TestInput.getExpanded; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToProhibitionTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToProhibitionTransformerTest.java similarity index 96% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToProhibitionTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToProhibitionTransformerTest.java index 5ff618dd7e9..f9316f0074f 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToProhibitionTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToProhibitionTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.Json; import jakarta.json.JsonObject; @@ -28,11 +28,11 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_ACTION_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_CONSTRAINT_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_TARGET_ATTRIBUTE; -import static org.eclipse.edc.jsonld.transformer.to.TestInput.getExpanded; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToQuerySpecTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToQuerySpecTransformerTest.java similarity index 95% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToQuerySpecTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToQuerySpecTransformerTest.java index 84b815f8365..f3cf72bb0c7 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonObjectToQuerySpecTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonObjectToQuerySpecTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import jakarta.json.Json; import jakarta.json.JsonObject; @@ -22,8 +22,8 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; -import static org.eclipse.edc.jsonld.transformer.to.TestInput.getExpanded; import static org.eclipse.edc.spi.query.QuerySpec.EDC_QUERY_SPEC_FILTER_EXPRESSION; import static org.eclipse.edc.spi.query.QuerySpec.EDC_QUERY_SPEC_LIMIT; import static org.eclipse.edc.spi.query.QuerySpec.EDC_QUERY_SPEC_OFFSET; diff --git a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonValueToGenericPropertyTransformerTest.java b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonValueToGenericPropertyTransformerTest.java similarity index 97% rename from extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonValueToGenericPropertyTransformerTest.java rename to core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonValueToGenericPropertyTransformerTest.java index 3f19348a42a..51911224211 100644 --- a/extensions/common/json-ld/src/test/java/org/eclipse/edc/jsonld/transformer/to/JsonValueToGenericPropertyTransformerTest.java +++ b/core/common/transform-core/src/test/java/org/eclipse/edc/core/transform/transformer/to/JsonValueToGenericPropertyTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.jsonld.transformer.to; +package org.eclipse.edc.core.transform.transformer.to; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -27,9 +27,9 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.core.transform.transformer.TestInput.getExpanded; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; -import static org.eclipse.edc.jsonld.transformer.to.TestInput.getExpanded; import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; diff --git a/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/ContractCoreExtension.java b/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/ContractCoreExtension.java index 1657afe270d..504b387ec0b 100644 --- a/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/ContractCoreExtension.java +++ b/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/ContractCoreExtension.java @@ -22,7 +22,6 @@ import org.eclipse.edc.connector.contract.negotiation.ProviderContractNegotiationManagerImpl; import org.eclipse.edc.connector.contract.observe.ContractNegotiationObservableImpl; import org.eclipse.edc.connector.contract.offer.ContractDefinitionResolverImpl; -import org.eclipse.edc.connector.contract.offer.ContractOfferResolverImpl; import org.eclipse.edc.connector.contract.policy.PolicyArchiveImpl; import org.eclipse.edc.connector.contract.policy.PolicyEquality; import org.eclipse.edc.connector.contract.spi.negotiation.ConsumerContractNegotiationManager; @@ -31,7 +30,6 @@ import org.eclipse.edc.connector.contract.spi.negotiation.observe.ContractNegotiationObservable; import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore; import org.eclipse.edc.connector.contract.spi.offer.ContractDefinitionResolver; -import org.eclipse.edc.connector.contract.spi.offer.ContractOfferResolver; import org.eclipse.edc.connector.contract.spi.offer.store.ContractDefinitionStore; import org.eclipse.edc.connector.contract.spi.types.command.ContractNegotiationCommand; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; @@ -74,9 +72,8 @@ import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA; @Provides({ - ContractOfferResolver.class, ContractValidationService.class, ConsumerContractNegotiationManager.class, - PolicyArchive.class, ProviderContractNegotiationManager.class, ContractNegotiationObservable.class, - ContractDefinitionResolver.class + ContractValidationService.class, ConsumerContractNegotiationManager.class, PolicyArchive.class, + ProviderContractNegotiationManager.class, ContractNegotiationObservable.class, ContractDefinitionResolver.class }) @CoreExtension @Extension(value = ContractCoreExtension.NAME) @@ -192,8 +189,6 @@ private void registerServices(ServiceExtensionContext context) { context.registerService(ContractDefinitionResolver.class, definitionService); var participantId = context.getParticipantId(); - var contractOfferResolver = new ContractOfferResolverImpl(participantId, agentService, definitionService, assetIndex, policyStore, clock, monitor); - context.registerService(ContractOfferResolver.class, contractOfferResolver); var policyEquality = new PolicyEquality(typeManager); var validationService = new ContractValidationServiceImpl(participantId, agentService, definitionService, assetIndex, policyStore, policyEngine, policyEquality); diff --git a/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/negotiation/ConsumerContractNegotiationManagerImpl.java b/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/negotiation/ConsumerContractNegotiationManagerImpl.java index dc0b525d5d9..f6efd3fc3c0 100644 --- a/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/negotiation/ConsumerContractNegotiationManagerImpl.java +++ b/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/negotiation/ConsumerContractNegotiationManagerImpl.java @@ -89,19 +89,18 @@ public void stop() { @Override public StatusResult initiate(ContractRequest request) { var id = UUID.randomUUID().toString(); - var requestData = request.getRequestData(); var negotiation = ContractNegotiation.Builder.newInstance() .id(id) .correlationId(id) - .protocol(requestData.getProtocol()) - .counterPartyId(requestData.getConnectorId()) - .counterPartyAddress(requestData.getCounterPartyAddress()) + .protocol(request.getProtocol()) + .counterPartyId(request.getProviderId()) + .counterPartyAddress(request.getCounterPartyAddress()) .callbackAddresses(request.getCallbackAddresses()) .traceContext(telemetry.getCurrentTraceContext()) .type(CONSUMER) .build(); - negotiation.addContractOffer(requestData.getContractOffer()); + negotiation.addContractOffer(request.getContractOffer()); transitionToInitial(negotiation); return StatusResult.success(negotiation); diff --git a/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/offer/ContractOfferResolverImpl.java b/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/offer/ContractOfferResolverImpl.java deleted file mode 100644 index 4fe0ff55b60..00000000000 --- a/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/offer/ContractOfferResolverImpl.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2021 Daimler TSS GmbH - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Daimler TSS GmbH - Initial API and Implementation - * Microsoft Corporation - Refactoring - * Fraunhofer Institute for Software and Systems Engineering - extended method implementation - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - improvements - * ZF Friedrichshafen AG - enable asset filtering - * - */ - -package org.eclipse.edc.connector.contract.offer; - -import org.eclipse.edc.connector.contract.spi.ContractId; -import org.eclipse.edc.connector.contract.spi.offer.ContractDefinitionResolver; -import org.eclipse.edc.connector.contract.spi.offer.ContractOfferQuery; -import org.eclipse.edc.connector.contract.spi.offer.ContractOfferResolver; -import org.eclipse.edc.connector.contract.spi.types.offer.ContractDefinition; -import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer; -import org.eclipse.edc.connector.policy.spi.store.PolicyDefinitionStore; -import org.eclipse.edc.policy.model.Policy; -import org.eclipse.edc.spi.agent.ParticipantAgentService; -import org.eclipse.edc.spi.asset.AssetIndex; -import org.eclipse.edc.spi.monitor.Monitor; -import org.eclipse.edc.spi.query.QuerySpec; -import org.jetbrains.annotations.NotNull; - -import java.time.Clock; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicLong; -import java.util.stream.Stream; - -import static java.lang.Math.max; -import static java.lang.Math.min; -import static java.util.stream.Collectors.toList; -import static java.util.stream.Stream.concat; - -/** - * Implementation of the {@link ContractOfferResolver}. - */ -public class ContractOfferResolverImpl implements ContractOfferResolver { - private final String participantId; - private final ParticipantAgentService agentService; - private final ContractDefinitionResolver definitionService; - private final AssetIndex assetIndex; - private final PolicyDefinitionStore policyStore; - private final Clock clock; - private final Monitor monitor; - - public ContractOfferResolverImpl(String participantId, - ParticipantAgentService agentService, - ContractDefinitionResolver definitionService, - AssetIndex assetIndex, - PolicyDefinitionStore policyStore, - Clock clock, - Monitor monitor) { - this.participantId = participantId; - this.agentService = agentService; - this.definitionService = definitionService; - this.assetIndex = assetIndex; - this.policyStore = policyStore; - this.clock = clock; - this.monitor = monitor; - } - - @Override - @NotNull - public Stream queryContractOffers(ContractOfferQuery query) { - var agent = agentService.createFor(query.getClaimToken()); - - var numFetchedAssets = new AtomicLong(0); - var numSeenAssets = new AtomicLong(0); - - var range = query.getRange(); - var offset = Long.valueOf(range.getFrom()); - var limit = Long.valueOf(range.getTo() - range.getFrom()); - - return definitionService.definitionsFor(agent) - .takeWhile(d -> numFetchedAssets.get() < limit) - .flatMap(definition -> { - var criteria = definition.getAssetsSelector(); - var querySpecBuilder = QuerySpec.Builder.newInstance() - .filter(concat(criteria.stream(), query.getAssetsCriteria().stream()).collect(toList())); - var querySpec = querySpecBuilder.build(); - var numAssets = assetIndex.countAssets(querySpec.getFilterExpression()); - - var dynamicOffset = max(0L, offset - numSeenAssets.get()); - var dynamicLimit = min(limit - numFetchedAssets.get(), max(0, numAssets - dynamicOffset)); - - querySpecBuilder.offset(Long.valueOf(dynamicOffset).intValue()); - querySpecBuilder.limit(Long.valueOf(dynamicLimit).intValue()); - - var offers = dynamicOffset >= numAssets ? Stream.empty() : - createContractOffers(definition, querySpecBuilder.build()) - .map(offerBuilder -> offerBuilder.providerId(participantId).build()); - - numFetchedAssets.addAndGet(dynamicLimit); - numSeenAssets.addAndGet(numAssets); - - return offers; - }); - } - - @NotNull - private Stream createContractOffers(ContractDefinition definition, QuerySpec assetQuerySpec) { - return Optional.of(definition.getContractPolicyId()) - .map(policyStore::findById) - .map(policyDefinition -> assetIndex.queryAssets(assetQuerySpec) - .map(asset -> ContractId.create(definition.getId(), asset.getId())) - .map(contractId -> createContractOffer(policyDefinition.getPolicy(), contractId))) - .orElse(Stream.empty()); - } - - @NotNull - private ContractOffer.Builder createContractOffer(Policy policy, ContractId contractId) { - return ContractOffer.Builder.newInstance() - .id(contractId.toString()) - .policy(policy.withTarget(contractId.assetIdPart())) - .assetId(contractId.assetIdPart()); - } -} diff --git a/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/validation/ContractValidationServiceImpl.java b/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/validation/ContractValidationServiceImpl.java index eead192cade..bce7dff226b 100644 --- a/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/validation/ContractValidationServiceImpl.java +++ b/core/control-plane/contract-core/src/main/java/org/eclipse/edc/connector/contract/validation/ContractValidationServiceImpl.java @@ -203,7 +203,6 @@ private Result validateInitialOffer(ContractId contractId, ParticipantAg private ContractOffer createContractOffer(Policy policy, ContractId contractId) { return ContractOffer.Builder.newInstance() .id(contractId.toString()) - .providerId(participantId) .policy(policy) .assetId(contractId.assetIdPart()) .build(); diff --git a/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/negotiation/ConsumerContractNegotiationManagerImplTest.java b/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/negotiation/ConsumerContractNegotiationManagerImplTest.java index b35e362095f..314dca862ab 100644 --- a/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/negotiation/ConsumerContractNegotiationManagerImplTest.java +++ b/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/negotiation/ConsumerContractNegotiationManagerImplTest.java @@ -24,7 +24,6 @@ import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest; -import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequestData; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequestMessage; import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer; import org.eclipse.edc.connector.policy.spi.store.PolicyDefinitionStore; @@ -128,15 +127,11 @@ void setUp() { void initiate_shouldSaveNewNegotiationInInitialState() { var contractOffer = contractOffer(); - var requestData = ContractRequestData.Builder.newInstance() - .connectorId("connectorId") + var request = ContractRequest.Builder.newInstance() + .providerId("providerId") .counterPartyAddress("callbackAddress") .protocol("protocol") .contractOffer(contractOffer) - .build(); - - var request = ContractRequest.Builder.newInstance() - .requestData(requestData) .callbackAddresses(List.of(CallbackAddress.Builder.newInstance() .uri("local://test") .build())) @@ -147,9 +142,9 @@ void initiate_shouldSaveNewNegotiationInInitialState() { assertThat(result.succeeded()).isTrue(); verify(store).save(argThat(negotiation -> negotiation.getState() == INITIAL.code() && - negotiation.getCounterPartyId().equals(requestData.getConnectorId()) && - negotiation.getCounterPartyAddress().equals(requestData.getCounterPartyAddress()) && - negotiation.getProtocol().equals(requestData.getProtocol()) && + negotiation.getCounterPartyId().equals("providerId") && + negotiation.getCounterPartyAddress().equals(request.getCounterPartyAddress()) && + negotiation.getProtocol().equals(request.getProtocol()) && negotiation.getCorrelationId().equals(negotiation.getId()) && negotiation.getContractOffers().size() == 1 && negotiation.getLastContractOffer().equals(contractOffer) && diff --git a/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/negotiation/ContractNegotiationIntegrationTest.java b/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/negotiation/ContractNegotiationIntegrationTest.java index 44aa1bcc44c..0949af54955 100644 --- a/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/negotiation/ContractNegotiationIntegrationTest.java +++ b/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/negotiation/ContractNegotiationIntegrationTest.java @@ -26,7 +26,6 @@ import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationTerminationMessage; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest; -import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequestData; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequestMessage; import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer; import org.eclipse.edc.connector.contract.spi.validation.ContractValidationService; @@ -158,9 +157,13 @@ void testNegotiation_initialOfferAccepted() { consumerManager.start(); // Create an initial request and trigger consumer manager - var requestData = ContractRequestData.Builder.newInstance().connectorId(PROVIDER_ID).counterPartyAddress("callbackAddress").contractOffer(offer).protocol("protocol").build(); - - var request = ContractRequest.Builder.newInstance().callbackAddresses(List.of(CallbackAddress.Builder.newInstance().uri("local://test").build())).requestData(requestData).build(); + var request = ContractRequest.Builder.newInstance() + .providerId(PROVIDER_ID) + .counterPartyAddress("callbackAddress") + .contractOffer(offer) + .protocol("protocol") + .callbackAddresses(List.of(CallbackAddress.Builder.newInstance().uri("local://test").build())) + .build(); consumerManager.initiate(request); @@ -202,9 +205,12 @@ void testNegotiation_initialOfferDeclined() { consumerManager.start(); // Create an initial request and trigger consumer manager - var requestData = ContractRequestData.Builder.newInstance().connectorId("connectorId").counterPartyAddress("callbackAddress").contractOffer(offer).protocol("protocol").build(); - - var request = ContractRequest.Builder.newInstance().requestData(requestData).build(); + var request = ContractRequest.Builder.newInstance() + .providerId("connectorId") + .counterPartyAddress("callbackAddress") + .contractOffer(offer) + .protocol("protocol") + .build(); consumerManager.initiate(request); @@ -227,9 +233,14 @@ void testNegotiation_agreementDeclined() { consumerManager.start(); // Create an initial request and trigger consumer manager - var requestData = ContractRequestData.Builder.newInstance().connectorId("connectorId").counterPartyAddress("callbackAddress").contractOffer(offer).protocol("protocol").build(); + var request = ContractRequest.Builder.newInstance() + .providerId("connectorId") + .counterPartyAddress("callbackAddress") + .contractOffer(offer) + .protocol("protocol") + .callbackAddresses(List.of(CallbackAddress.Builder.newInstance().uri("local://test").build())) + .build(); - var request = ContractRequest.Builder.newInstance().requestData(requestData).callbackAddresses(List.of(CallbackAddress.Builder.newInstance().uri("local://test").build())).build(); consumerManager.initiate(request); await().atMost(DEFAULT_TEST_TIMEOUT).pollInterval(DEFAULT_POLL_INTERVAL).untilAsserted(() -> { @@ -328,7 +339,6 @@ private CompletableFuture toFuture(ServiceResult result) private ContractOffer getContractOffer() { return ContractOffer.Builder.newInstance() .id(ContractId.create("1", "test-asset-id").toString()) - .providerId("provider") .assetId(randomUUID().toString()) .policy(Policy.Builder.newInstance() .type(PolicyType.CONTRACT) diff --git a/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/negotiation/ProviderContractNegotiationManagerImplTest.java b/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/negotiation/ProviderContractNegotiationManagerImplTest.java index 52381d5e9cd..cde9928cdac 100644 --- a/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/negotiation/ProviderContractNegotiationManagerImplTest.java +++ b/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/negotiation/ProviderContractNegotiationManagerImplTest.java @@ -260,7 +260,6 @@ private ContractOffer contractOffer() { .id(ContractId.create("1", "test-asset-id").toString()) .policy(Policy.Builder.newInstance().build()) .assetId("assetId") - .providerId(PROVIDER_ID) .build(); } diff --git a/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/offer/ContractOfferResolverImplIntegrationTest.java b/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/offer/ContractOfferResolverImplIntegrationTest.java deleted file mode 100644 index dcc5bb0e453..00000000000 --- a/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/offer/ContractOfferResolverImplIntegrationTest.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2021 Daimler TSS GmbH - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Daimler TSS GmbH - Initial API and Implementation - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - improvements - * - */ - -package org.eclipse.edc.connector.contract.offer; - -import org.eclipse.edc.connector.contract.spi.offer.ContractDefinitionResolver; -import org.eclipse.edc.connector.contract.spi.offer.ContractOfferQuery; -import org.eclipse.edc.connector.contract.spi.offer.ContractOfferResolver; -import org.eclipse.edc.connector.contract.spi.types.offer.ContractDefinition; -import org.eclipse.edc.connector.defaults.storage.assetindex.InMemoryAssetIndex; -import org.eclipse.edc.connector.policy.spi.PolicyDefinition; -import org.eclipse.edc.connector.policy.spi.store.PolicyDefinitionStore; -import org.eclipse.edc.policy.model.Policy; -import org.eclipse.edc.spi.agent.ParticipantAgent; -import org.eclipse.edc.spi.agent.ParticipantAgentService; -import org.eclipse.edc.spi.asset.AssetIndex; -import org.eclipse.edc.spi.iam.ClaimToken; -import org.eclipse.edc.spi.message.Range; -import org.eclipse.edc.spi.monitor.Monitor; -import org.eclipse.edc.spi.query.Criterion; -import org.eclipse.edc.spi.types.domain.DataAddress; -import org.eclipse.edc.spi.types.domain.asset.Asset; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.ArgumentsProvider; -import org.junit.jupiter.params.provider.ArgumentsSource; - -import java.time.Clock; -import java.time.Instant; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static java.lang.Math.max; -import static java.lang.Math.min; -import static java.time.ZoneOffset.UTC; -import static java.util.Collections.emptyMap; -import static java.util.stream.IntStream.range; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * This could be seen as se second part of the {@code ContractOfferServiceImplTest}, using the in-mem asset index - */ -class ContractOfferResolverImplIntegrationTest { - private static final String PARTICIPANT_ID = "urn:connector:provider"; - - private final Instant now = Instant.now(); - private final Clock clock = Clock.fixed(now, UTC); - private final ContractDefinitionResolver contractDefinitionResolver = mock(ContractDefinitionResolver.class); - private final ParticipantAgentService agentService = mock(ParticipantAgentService.class); - private final PolicyDefinitionStore policyStore = mock(PolicyDefinitionStore.class); - private final Monitor monitor = mock(Monitor.class); - private AssetIndex assetIndex; - private ContractOfferResolver contractOfferResolver; - - @BeforeEach - void setUp() { - assetIndex = new InMemoryAssetIndex(); - contractOfferResolver = new ContractOfferResolverImpl(PARTICIPANT_ID, agentService, contractDefinitionResolver, assetIndex, policyStore, clock, monitor); - } - - @Test - void shouldLimitResult_withHeterogenousChunks() { - var assets1 = range(10, 24).mapToObj(i -> createAsset("asset" + i).build()).collect(Collectors.toList()); - var assets2 = range(24, 113).mapToObj(i -> createAsset("asset" + i).build()).collect(Collectors.toList()); - var assets3 = range(113, 178).mapToObj(i -> createAsset("asset" + i).build()).collect(Collectors.toList()); - - assets1.forEach(assetIndex::create); - assets2.forEach(assetIndex::create); - assets3.forEach(assetIndex::create); - - var def1 = getContractDefBuilder("def1").assetsSelector(selectorFrom(assets1)).build(); - var def2 = getContractDefBuilder("def2").assetsSelector(selectorFrom(assets2)).build(); - var def3 = getContractDefBuilder("def3").assetsSelector(selectorFrom(assets3)).build(); - - when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap())); - when(contractDefinitionResolver.definitionsFor(isA(ParticipantAgent.class))).thenAnswer(i -> Stream.of(def1, def2, def3)); - - when(policyStore.findById(any())).thenReturn(PolicyDefinition.Builder.newInstance().policy(Policy.Builder.newInstance().build()).build()); - - - var from = 20; - var to = 50; - var query = ContractOfferQuery.builder().range(new Range(from, to)).claimToken(ClaimToken.Builder.newInstance().build()).build(); - - assertThat(contractOfferResolver.queryContractOffers(query)).hasSize(to - from); - verify(agentService).createFor(isA(ClaimToken.class)); - verify(contractDefinitionResolver, times(1)).definitionsFor(isA(ParticipantAgent.class)); - verify(policyStore).findById("contract"); - } - - @ParameterizedTest - @ArgumentsSource(RangeProvider.class) - void should_return_offers_subset_when_across_multiple_contract_definitions(int from, int to) { - - var assets1 = range(0, 10).mapToObj(i -> createAsset("asset-" + i).build()).collect(Collectors.toList()); - var assets2 = range(10, 20).mapToObj(i -> createAsset("asset-" + i).build()).collect(Collectors.toList()); - var maximumRange = max(0, (assets1.size() + assets2.size()) - from); - var requestedRange = to - from; - - assets1.forEach(assetIndex::create); - assets2.forEach(assetIndex::create); - - var contractDefinition1 = getContractDefBuilder("contract-definition-") - .assetsSelector(selectorFrom(assets1)).build(); - var contractDefinition2 = getContractDefBuilder("contract-definition-") - .assetsSelector(selectorFrom(assets2)).build(); - - when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap())); - when(contractDefinitionResolver.definitionsFor(isA(ParticipantAgent.class))).thenAnswer(i -> Stream.of(contractDefinition1, contractDefinition2)); - when(policyStore.findById(any())).thenReturn(PolicyDefinition.Builder.newInstance().policy(Policy.Builder.newInstance().build()).build()); - - var query = ContractOfferQuery.builder().range(new Range(from, to)).claimToken(ClaimToken.Builder.newInstance().build()).build(); - assertThat(contractOfferResolver.queryContractOffers(query)).hasSize(min(requestedRange, maximumRange)); - } - - @Test - void shouldLimitResult_insufficientAssets() { - var assets1 = range(0, 12).mapToObj(i -> createAsset("asset" + i).build()).collect(Collectors.toList()); - var assets2 = range(12, 18).mapToObj(i -> createAsset("asset" + i).build()).collect(Collectors.toList()); - - assets1.forEach(assetIndex::create); - assets2.forEach(assetIndex::create); - - var def1 = getContractDefBuilder("def1").assetsSelector(selectorFrom(assets1)).build(); - var def2 = getContractDefBuilder("def2").assetsSelector(selectorFrom(assets2)).build(); - - when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap())); - when(contractDefinitionResolver.definitionsFor(isA(ParticipantAgent.class))).thenAnswer(i -> Stream.of(def1, def2)); - when(policyStore.findById(any())).thenReturn(PolicyDefinition.Builder.newInstance().policy(Policy.Builder.newInstance().build()).build()); - - var from = 14; - var to = 50; - var query = ContractOfferQuery.builder().range(new Range(from, to)).claimToken(ClaimToken.Builder.newInstance().build()).build(); - - // 4 definitions, 10 assets each = 40 offers total -> offset 20 ==> result = 20 - assertThat(contractOfferResolver.queryContractOffers(query)).hasSize(4); - verify(agentService).createFor(isA(ClaimToken.class)); - verify(contractDefinitionResolver).definitionsFor(isA(ParticipantAgent.class)); - verify(policyStore, atLeastOnce()).findById("contract"); - } - - @Test - void shouldLimitResult_pageOffsetLargerThanNumAssets() { - var contractDefinition = range(0, 2).mapToObj(i -> getContractDefBuilder(String.valueOf(i)) - .build()); - - when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap())); - when(contractDefinitionResolver.definitionsFor(isA(ParticipantAgent.class))).thenAnswer(i -> contractDefinition); - - when(policyStore.findById(any())).thenReturn(PolicyDefinition.Builder.newInstance().policy(Policy.Builder.newInstance().build()).build()); - - var from = 25; - var to = 50; - var query = ContractOfferQuery.builder().range(new Range(from, to)).claimToken(ClaimToken.Builder.newInstance().build()).build(); - - // 2 definitions, 10 assets each = 20 offers total -> offset of 25 is outside - assertThat(contractOfferResolver.queryContractOffers(query)).isEmpty(); - verify(agentService).createFor(isA(ClaimToken.class)); - verify(contractDefinitionResolver).definitionsFor(isA(ParticipantAgent.class)); - verify(policyStore, never()).findById("contract"); - } - - private List selectorFrom(Collection assets1) { - var ids = assets1.stream().map(Asset::getId).toList(); - return List.of(new Criterion(Asset.PROPERTY_ID, "in", ids)); - } - - private ContractDefinition.Builder getContractDefBuilder(String id) { - return ContractDefinition.Builder.newInstance() - .id(id) - .accessPolicyId("access") - .contractPolicyId("contract"); - } - - private Asset.Builder createAsset(String id) { - return Asset.Builder.newInstance() - .id(id) - .name("test asset " + id) - .dataAddress(DataAddress.Builder.newInstance().type("test-type").build()); - } - - static class RangeProvider implements ArgumentsProvider { - @Override - public Stream provideArguments(ExtensionContext context) { - return Stream.of( - Arguments.of(0, 12), - Arguments.of(8, 14), - Arguments.of(0, 999), - Arguments.of(4, 888), - Arguments.of(3, 20), - Arguments.of(23, 25) - ); - } - } -} diff --git a/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/offer/ContractOfferResolverImplTest.java b/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/offer/ContractOfferResolverImplTest.java deleted file mode 100644 index 4b0d1d14edf..00000000000 --- a/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/offer/ContractOfferResolverImplTest.java +++ /dev/null @@ -1,314 +0,0 @@ -/* - * Copyright (c) 2021 Daimler TSS GmbH - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Daimler TSS GmbH - Initial API and Implementation - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - improvements - * - */ - -package org.eclipse.edc.connector.contract.offer; - -import org.eclipse.edc.connector.contract.spi.offer.ContractDefinitionResolver; -import org.eclipse.edc.connector.contract.spi.offer.ContractOfferQuery; -import org.eclipse.edc.connector.contract.spi.offer.ContractOfferResolver; -import org.eclipse.edc.connector.contract.spi.types.offer.ContractDefinition; -import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer; -import org.eclipse.edc.connector.policy.spi.PolicyDefinition; -import org.eclipse.edc.connector.policy.spi.store.PolicyDefinitionStore; -import org.eclipse.edc.policy.model.Policy; -import org.eclipse.edc.spi.agent.ParticipantAgent; -import org.eclipse.edc.spi.agent.ParticipantAgentService; -import org.eclipse.edc.spi.asset.AssetIndex; -import org.eclipse.edc.spi.iam.ClaimToken; -import org.eclipse.edc.spi.message.Range; -import org.eclipse.edc.spi.monitor.Monitor; -import org.eclipse.edc.spi.query.Criterion; -import org.eclipse.edc.spi.query.QuerySpec; -import org.eclipse.edc.spi.types.domain.asset.Asset; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.time.Clock; -import java.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static java.time.ZoneOffset.UTC; -import static java.util.Collections.emptyMap; -import static java.util.stream.IntStream.range; -import static java.util.stream.Stream.concat; -import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.edc.spi.agent.ParticipantAgent.PARTICIPANT_IDENTITY; -import static org.mockito.AdditionalMatchers.and; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -class ContractOfferResolverImplTest { - public static final String CONSUMER_ID = "urn:connector:consumer"; - private static final String PARTICIPANT_ID = "urn:connector:provider"; - private static final Range DEFAULT_RANGE = new Range(0, 10); - private final Instant now = Instant.now(); - private final Clock clock = Clock.fixed(now, UTC); - private final ContractDefinitionResolver contractDefinitionResolver = mock(ContractDefinitionResolver.class); - private final AssetIndex assetIndex = mock(AssetIndex.class); - private final ParticipantAgentService agentService = mock(ParticipantAgentService.class); - private final PolicyDefinitionStore policyStore = mock(PolicyDefinitionStore.class); - private final Monitor monitor = mock(Monitor.class); - - private ContractOfferResolver contractOfferResolver; - - @BeforeEach - void setUp() { - contractOfferResolver = new ContractOfferResolverImpl(PARTICIPANT_ID, agentService, contractDefinitionResolver, assetIndex, policyStore, clock, monitor); - } - - @Test - void shouldGetContractOffers() { - var contractDefinition = getContractDefBuilder("1") - .build(); - - when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), Map.of(PARTICIPANT_IDENTITY, CONSUMER_ID))); - when(contractDefinitionResolver.definitionsFor(isA(ParticipantAgent.class))).thenReturn(Stream.of(contractDefinition)); - var assetStream = Stream.of(Asset.Builder.newInstance().build(), Asset.Builder.newInstance().build()); - when(assetIndex.countAssets(anyList())).thenReturn(2L); - when(assetIndex.queryAssets(isA(QuerySpec.class))).thenReturn(assetStream); - when(policyStore.findById(any())).thenReturn(PolicyDefinition.Builder.newInstance().policy(Policy.Builder.newInstance().build()).build()); - var query = ContractOfferQuery.builder() - .claimToken(ClaimToken.Builder.newInstance().build()) - .build(); - - var offers = contractOfferResolver.queryContractOffers(query); - - assertThat(offers) - .hasSize(2) - .allSatisfy(contractOffer -> assertThat(contractOffer.getProviderId()).isEqualTo(PARTICIPANT_ID)); - verify(agentService).createFor(isA(ClaimToken.class)); - verify(contractDefinitionResolver).definitionsFor(isA(ParticipantAgent.class)); - verify(assetIndex).queryAssets(isA(QuerySpec.class)); - verify(policyStore, atLeastOnce()).findById("contract"); - } - - @Test - void shouldNotGetContractOfferIfPolicyIsNotFound() { - var contractDefinition = getContractDefBuilder("1") - .build(); - when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap())); - when(contractDefinitionResolver.definitionsFor(isA(ParticipantAgent.class))).thenReturn(Stream.of(contractDefinition)); - when(assetIndex.queryAssets(isA(QuerySpec.class))).thenReturn(Stream.of(Asset.Builder.newInstance().build())); - when(policyStore.findById(any())).thenReturn(null); - var query = ContractOfferQuery.builder().claimToken(ClaimToken.Builder.newInstance().build()).build(); - - var result = contractOfferResolver.queryContractOffers(query); - - assertThat(result).isEmpty(); - } - - @Test - void shouldLimitResult() { - var contractDefinition = range(0, 10).mapToObj(i -> getContractDefBuilder(String.valueOf(i)) - .build()); - - when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap())); - when(contractDefinitionResolver.definitionsFor(isA(ParticipantAgent.class))).thenAnswer(i -> contractDefinition); - when(assetIndex.countAssets(anyList())).thenReturn(100L); - when(assetIndex.queryAssets(isA(QuerySpec.class))).thenAnswer(inv -> range(20, 50).mapToObj(i -> createAsset("asset" + i).build())); - when(policyStore.findById(any())).thenReturn(PolicyDefinition.Builder.newInstance().policy(Policy.Builder.newInstance().build()).build()); - - var from = 20; - var to = 50; - - var offers = contractOfferResolver.queryContractOffers(getQuery(from, to)); - - assertThat(offers).hasSize(to - from) - .extracting(ContractOffer::getAssetId) - .allSatisfy(id -> { - var idNumber = Integer.valueOf(id.replace("asset", "")); - assertThat(idNumber).isStrictlyBetween(from - 1, to); - }); - verify(agentService).createFor(isA(ClaimToken.class)); - verify(contractDefinitionResolver).definitionsFor(isA(ParticipantAgent.class)); - verify(assetIndex).queryAssets(isA(QuerySpec.class)); - verify(policyStore).findById("contract"); - } - - - @Test - void shouldLimitResultToTheRemainingAssetsOfTheContractDefinition() { - var contractDefinition = getContractDefBuilder("1").build(); - - when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap())); - when(contractDefinitionResolver.definitionsFor(isA(ParticipantAgent.class))).thenReturn(Stream.of(contractDefinition)); - when(assetIndex.countAssets(anyList())).thenReturn(40L); - when(assetIndex.queryAssets(isA(QuerySpec.class))).thenAnswer(inv -> range(20, 50).mapToObj(i -> createAsset("asset" + i).build())); - when(policyStore.findById(any())).thenReturn(PolicyDefinition.Builder.newInstance().policy(Policy.Builder.newInstance().build()).build()); - - var from = 20; - var to = 80; - - var result = contractOfferResolver.queryContractOffers(getQuery(from, to)); - - assertThat(result).isNotEmpty(); - verify(assetIndex, times(1)).queryAssets(and(isA(QuerySpec.class), argThat(it -> it.getLimit() == 20))); - } - - @Test - void shouldLimitResult_insufficientAssets() { - var contractDefinition = range(0, 4).mapToObj(i -> getContractDefBuilder(String.valueOf(i)) - .build()); - - when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap())); - when(contractDefinitionResolver.definitionsFor(isA(ParticipantAgent.class))).thenAnswer(i -> contractDefinition); - when(assetIndex.queryAssets(isA(QuerySpec.class))).thenAnswer(inv -> range(0, 10).mapToObj(i -> createAsset("asset" + i).build())); - when(assetIndex.countAssets(anyList())).thenReturn(10L); - when(policyStore.findById(any())).thenReturn(PolicyDefinition.Builder.newInstance().policy(Policy.Builder.newInstance().build()).build()); - - var from = 20; - var to = 50; - - var offers = contractOfferResolver.queryContractOffers(getQuery(from, to)); - - // 4 definitions, 10 assets each = 40 offers total -> offset 20 ==> result = 20 - assertThat(offers).hasSize(20); - verify(agentService).createFor(isA(ClaimToken.class)); - verify(contractDefinitionResolver).definitionsFor(isA(ParticipantAgent.class)); - verify(assetIndex, atLeastOnce()).queryAssets(isA(QuerySpec.class)); - verify(policyStore, atLeastOnce()).findById("contract"); - } - - @Test - void shouldLimitResult_pageOffsetLargerThanNumAssets() { - var contractDefinition = range(0, 2).mapToObj(i -> getContractDefBuilder(String.valueOf(i)) - .build()); - - when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap())); - when(contractDefinitionResolver.definitionsFor(isA(ParticipantAgent.class))).thenAnswer(i -> contractDefinition); - when(assetIndex.countAssets(anyList())).thenReturn(10L); - when(assetIndex.queryAssets(isA(QuerySpec.class))).thenAnswer(inv -> range(0, 10).mapToObj(i -> createAsset("asset" + i).build())); - when(policyStore.findById(any())).thenReturn(PolicyDefinition.Builder.newInstance().policy(Policy.Builder.newInstance().build()).build()); - - var from = 25; - var to = 50; - - var offers = contractOfferResolver.queryContractOffers(getQuery(from, to)); - - // 2 definitions, 10 assets each = 20 offers total -> offset of 25 is outside - assertThat(offers).isEmpty(); - verify(agentService).createFor(isA(ClaimToken.class)); - verify(contractDefinitionResolver).definitionsFor(isA(ParticipantAgent.class)); - verify(assetIndex, never()).queryAssets(isA(QuerySpec.class)); - verify(policyStore, never()).findById("contract"); - } - - @Test - void shouldLimitResultOfSingleAssetForContractDefinition() { - var contractDefinitions = range(0, 80) - .mapToObj(i -> getContractDefBuilder(String.valueOf(i)).build()); - - when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap())); - when(contractDefinitionResolver.definitionsFor(isA(ParticipantAgent.class))).thenAnswer(i -> contractDefinitions); - when(assetIndex.countAssets(anyList())).thenReturn(1L); - when(assetIndex.queryAssets(isA(QuerySpec.class))).thenAnswer(inv -> Stream.of(createAsset("asset").build())); - when(policyStore.findById(any())).thenReturn(PolicyDefinition.Builder.newInstance().policy(Policy.Builder.newInstance().build()).build()); - - var from = 20; - var to = 50; - - var offers = contractOfferResolver.queryContractOffers(getQuery(from, to)); - - assertThat(offers).hasSize(to - from); - verify(contractDefinitionResolver).definitionsFor(isA(ParticipantAgent.class)); - verify(assetIndex, times(30)).queryAssets(isA(QuerySpec.class)); - verify(policyStore, times(30)).findById("contract"); - } - - @Test - void shouldGetContractOffersWithAssetFilteringApplied() { - var contractDefinition = ContractDefinition.Builder.newInstance() - .id("1") - .accessPolicyId("access") - .contractPolicyId("contract") - .assetsSelector(List.of(Criterion.criterion(Asset.PROPERTY_NAME, "=", "1"))) - .build(); - - when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap())); - when(contractDefinitionResolver.definitionsFor(isA(ParticipantAgent.class))).thenReturn(Stream.of(contractDefinition)); - var assetStream = Stream.of(Asset.Builder.newInstance().build(), Asset.Builder.newInstance().build()); - when(assetIndex.countAssets(anyList())).thenReturn(1000L); - when(assetIndex.queryAssets(isA(QuerySpec.class))).thenReturn(assetStream); - when(policyStore.findById(any())).thenReturn(PolicyDefinition.Builder.newInstance().policy(Policy.Builder.newInstance().build()).build()); - - var query = ContractOfferQuery.builder() - .range(DEFAULT_RANGE) - .claimToken(ClaimToken.Builder.newInstance().build()) - .assetsCriteria(List.of(new Criterion(Asset.PROPERTY_ID, "=", "2"))) - .build(); - - var offers = contractOfferResolver.queryContractOffers(query); - - assertThat(offers).hasSize(2); - verify(agentService).createFor(isA(ClaimToken.class)); - verify(contractDefinitionResolver).definitionsFor(isA(ParticipantAgent.class)); - verify(policyStore).findById("contract"); - var expectedQuerySpec = QuerySpec.Builder.newInstance() - .filter(concat(contractDefinition.getAssetsSelector().stream(), query.getAssetsCriteria().stream()).collect(Collectors.toList())) - .range(DEFAULT_RANGE) - .build(); - verify(assetIndex).queryAssets(expectedQuerySpec); - } - - @Test - void shouldReturnMaximumContractEndtime_whenItExceedsMaximimLongValue() { - - var contractDefinition = getContractDefBuilder("ContractForever").build(); - - when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap())); - when(contractDefinitionResolver.definitionsFor(isA(ParticipantAgent.class))).thenReturn(Stream.of(contractDefinition)); - var assetStream = Stream.of(Asset.Builder.newInstance().build()); - when(assetIndex.countAssets(anyList())).thenReturn(1L); - when(assetIndex.queryAssets(isA(QuerySpec.class))).thenReturn(assetStream); - when(policyStore.findById(any())).thenReturn(PolicyDefinition.Builder.newInstance().policy(Policy.Builder.newInstance().build()).build()); - var query = ContractOfferQuery.builder() - .claimToken(ClaimToken.Builder.newInstance().build()) - .build(); - - var offers = contractOfferResolver.queryContractOffers(query); - - assertThat(offers) - .hasSize(1); - } - - private ContractOfferQuery getQuery(int from, int to) { - return ContractOfferQuery.builder() - .range(new Range(from, to)) - .claimToken(ClaimToken.Builder.newInstance().build()) - .build(); - } - - private ContractDefinition.Builder getContractDefBuilder(String id) { - return ContractDefinition.Builder.newInstance() - .id(id) - .accessPolicyId("access") - .contractPolicyId("contract"); - } - - private Asset.Builder createAsset(String id) { - return Asset.Builder.newInstance().id(id).name("test asset " + id); - } -} diff --git a/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/validation/ContractValidationServiceImplTest.java b/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/validation/ContractValidationServiceImplTest.java index 35fb2df10bc..50483098ef1 100644 --- a/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/validation/ContractValidationServiceImplTest.java +++ b/core/control-plane/contract-core/src/test/java/org/eclipse/edc/connector/contract/validation/ContractValidationServiceImplTest.java @@ -126,7 +126,6 @@ void verifyContractOfferValidation(boolean verifyById) { assertThat(validatedOffer.getPolicy()).isNotSameAs(originalPolicy); // verify the returned policy is the sanitized one assertThat(validatedOffer.getAssetId()).isEqualTo(asset.getId()); assertThat(result.getContent().getConsumerIdentity()).isEqualTo(CONSUMER_ID); // verify the returned policy has the consumer id set, essential for later validation checks - assertThat(validatedOffer.getProviderId()).isEqualTo(offer.getProviderId()); verify(agentService).createFor(isA(ClaimToken.class)); verify(definitionResolver).definitionFor(isA(ParticipantAgent.class), eq("1")); @@ -501,7 +500,6 @@ private ContractOffer createContractOffer(Asset asset, Policy policy) { .id(ContractId.create("1", asset.getId()).toString()) .assetId(asset.getId()) .policy(policy) - .providerId(PROVIDER_ID) .build(); } diff --git a/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationEventDispatchTest.java b/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationEventDispatchTest.java index 09698bad073..f068880fdf2 100644 --- a/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationEventDispatchTest.java +++ b/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationEventDispatchTest.java @@ -113,7 +113,6 @@ private ContractRequestMessage createContractOfferRequest(Policy policy, String .id(ContractId.create("contractDefinitionId", assetId).toString()) .assetId("assetId") .policy(policy) - .providerId(PROVIDER) .build(); return ContractRequestMessage.Builder.newInstance() diff --git a/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationProtocolServiceImplTest.java b/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationProtocolServiceImplTest.java index 4e028476b6e..e197eda7528 100644 --- a/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationProtocolServiceImplTest.java +++ b/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationProtocolServiceImplTest.java @@ -471,7 +471,6 @@ private ContractOffer contractOffer() { .id(ContractId.create("1", "test-asset-id").toString()) .policy(createPolicy()) .assetId("assetId") - .providerId(PROVIDER_ID) .build(); } diff --git a/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationServiceImplTest.java b/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationServiceImplTest.java index 52f835c5ab0..ee7f62b9b93 100644 --- a/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationServiceImplTest.java +++ b/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationServiceImplTest.java @@ -23,7 +23,6 @@ import org.eclipse.edc.connector.contract.spi.types.command.DeclineNegotiationCommand; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest; -import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequestData; import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer; import org.eclipse.edc.policy.model.Policy; import org.eclipse.edc.spi.query.Criterion; @@ -192,15 +191,14 @@ void getForNegotiation_returnsNullIfNotFound() { void initiateNegotiation_callsManager() { var contractNegotiation = createContractNegotiation("negotiationId"); when(consumerManager.initiate(isA(ContractRequest.class))).thenReturn(StatusResult.success(contractNegotiation)); - var requestData = ContractRequestData.Builder.newInstance() - .connectorId("connectorId") + + var request = ContractRequest.Builder.newInstance() + .providerId("providerId") .counterPartyAddress("address") .protocol("protocol") .contractOffer(createContractOffer()) .build(); - var request = ContractRequest.Builder.newInstance().requestData(requestData).build(); - var result = service.initiateNegotiation(request); assertThat(result).matches(it -> it.getId().equals("negotiationId")); diff --git a/data-protocols/dsp/build.gradle.kts b/data-protocols/dsp/build.gradle.kts index 7f4a1d302dc..5f27d435226 100644 --- a/data-protocols/dsp/build.gradle.kts +++ b/data-protocols/dsp/build.gradle.kts @@ -24,5 +24,4 @@ dependencies { api(project(":data-protocols:dsp:dsp-http-spi")) api(project(":data-protocols:dsp:dsp-negotiation")) api(project(":data-protocols:dsp:dsp-transfer-process")) - api(project(":data-protocols:dsp:dsp-transform")) } diff --git a/data-protocols/dsp/dsp-api-configuration/build.gradle.kts b/data-protocols/dsp/dsp-api-configuration/build.gradle.kts index f0387267a44..28fc30557d2 100644 --- a/data-protocols/dsp/dsp-api-configuration/build.gradle.kts +++ b/data-protocols/dsp/dsp-api-configuration/build.gradle.kts @@ -21,6 +21,7 @@ dependencies { api(project(":spi:common:core-spi")) api(project(":data-protocols:dsp:dsp-spi")) implementation(project(":core:common:jersey-providers")) + implementation(project(":core:common:transform-core")) implementation(project(":extensions:common:http")) implementation(libs.jakarta.rsApi) diff --git a/data-protocols/dsp/dsp-api-configuration/src/main/java/org/eclipse/edc/protocol/dsp/api/configuration/DspApiConfigurationExtension.java b/data-protocols/dsp/dsp-api-configuration/src/main/java/org/eclipse/edc/protocol/dsp/api/configuration/DspApiConfigurationExtension.java index 688e722fbdf..f4520e941bf 100644 --- a/data-protocols/dsp/dsp-api-configuration/src/main/java/org/eclipse/edc/protocol/dsp/api/configuration/DspApiConfigurationExtension.java +++ b/data-protocols/dsp/dsp-api-configuration/src/main/java/org/eclipse/edc/protocol/dsp/api/configuration/DspApiConfigurationExtension.java @@ -14,7 +14,27 @@ package org.eclipse.edc.protocol.dsp.api.configuration; +import jakarta.json.Json; +import org.eclipse.edc.core.transform.transformer.OdrlTransformersFactory; +import org.eclipse.edc.core.transform.transformer.from.JsonObjectFromAssetTransformer; +import org.eclipse.edc.core.transform.transformer.from.JsonObjectFromCatalogTransformer; +import org.eclipse.edc.core.transform.transformer.from.JsonObjectFromCriterionTransformer; +import org.eclipse.edc.core.transform.transformer.from.JsonObjectFromDataServiceTransformer; +import org.eclipse.edc.core.transform.transformer.from.JsonObjectFromDatasetTransformer; +import org.eclipse.edc.core.transform.transformer.from.JsonObjectFromDistributionTransformer; +import org.eclipse.edc.core.transform.transformer.from.JsonObjectFromPolicyTransformer; +import org.eclipse.edc.core.transform.transformer.from.JsonObjectFromQuerySpecTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToAssetTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToCatalogTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToCriterionTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToDataServiceTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToDatasetTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToDistributionTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToQuerySpecTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonValueToGenericTypeTransformer; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.policy.model.AtomicConstraint; +import org.eclipse.edc.policy.model.LiteralExpression; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.runtime.metamodel.annotation.Provides; @@ -22,6 +42,7 @@ import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; import org.eclipse.edc.spi.types.TypeManager; +import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.web.jersey.jsonld.JerseyJsonLdInterceptor; import org.eclipse.edc.web.jersey.jsonld.ObjectMapperProvider; import org.eclipse.edc.web.spi.WebServer; @@ -29,6 +50,8 @@ import org.eclipse.edc.web.spi.configuration.WebServiceConfigurer; import org.eclipse.edc.web.spi.configuration.WebServiceSettings; +import java.util.Map; + import static org.eclipse.edc.spi.CoreConstants.JSON_LD; /** @@ -73,6 +96,9 @@ public class DspApiConfigurationExtension implements ServiceExtension { @Inject private JsonLd jsonLd; + + @Inject + private TypeTransformerRegistry transformerRegistry; @Override public String name() { @@ -90,6 +116,40 @@ public void initialize(ServiceExtensionContext context) { var jsonLdMapper = typeManager.getMapper(JSON_LD); webService.registerResource(config.getContextAlias(), new ObjectMapperProvider(jsonLdMapper)); webService.registerResource(config.getContextAlias(), new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper)); + + registerTransformers(); } - + + private void registerTransformers() { + var mapper = typeManager.getMapper(JSON_LD); + mapper.registerSubtypes(AtomicConstraint.class, LiteralExpression.class); + + var jsonBuilderFactory = Json.createBuilderFactory(Map.of()); + + // EDC model to JSON-LD transformers + transformerRegistry.register(new JsonObjectFromCatalogTransformer(jsonBuilderFactory, mapper)); + transformerRegistry.register(new JsonObjectFromDatasetTransformer(jsonBuilderFactory, mapper)); + transformerRegistry.register(new JsonObjectFromPolicyTransformer(jsonBuilderFactory)); + transformerRegistry.register(new JsonObjectFromDistributionTransformer(jsonBuilderFactory)); + transformerRegistry.register(new JsonObjectFromDataServiceTransformer(jsonBuilderFactory)); + transformerRegistry.register(new JsonObjectFromAssetTransformer(jsonBuilderFactory, mapper)); + transformerRegistry.register(new JsonObjectFromQuerySpecTransformer(jsonBuilderFactory)); + transformerRegistry.register(new JsonObjectFromCriterionTransformer(jsonBuilderFactory, mapper)); + + // JSON-LD to EDC model transformers + // DCAT transformers + transformerRegistry.register(new JsonObjectToCatalogTransformer()); + transformerRegistry.register(new JsonObjectToDataServiceTransformer()); + transformerRegistry.register(new JsonObjectToDatasetTransformer()); + transformerRegistry.register(new JsonObjectToDistributionTransformer()); + + // ODRL Transformers + OdrlTransformersFactory.jsonObjectToOdrlTransformers().forEach(transformerRegistry::register); + + transformerRegistry.register(new JsonValueToGenericTypeTransformer(mapper)); + transformerRegistry.register(new JsonObjectToAssetTransformer()); + transformerRegistry.register(new JsonObjectToQuerySpecTransformer()); + transformerRegistry.register(new JsonObjectToCriterionTransformer()); + } + } diff --git a/data-protocols/dsp/dsp-api-configuration/src/test/java/org/eclipse/edc/protocol/dsp/api/configuration/DspApiConfigurationExtensionTest.java b/data-protocols/dsp/dsp-api-configuration/src/test/java/org/eclipse/edc/protocol/dsp/api/configuration/DspApiConfigurationExtensionTest.java index 6923444f0af..73a02975982 100644 --- a/data-protocols/dsp/dsp-api-configuration/src/test/java/org/eclipse/edc/protocol/dsp/api/configuration/DspApiConfigurationExtensionTest.java +++ b/data-protocols/dsp/dsp-api-configuration/src/test/java/org/eclipse/edc/protocol/dsp/api/configuration/DspApiConfigurationExtensionTest.java @@ -17,7 +17,7 @@ import org.eclipse.edc.junit.extensions.DependencyInjectionExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; import org.eclipse.edc.spi.system.configuration.ConfigFactory; -import org.eclipse.edc.spi.system.injection.ObjectFactory; +import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.web.jersey.jsonld.JerseyJsonLdInterceptor; import org.eclipse.edc.web.jersey.jsonld.ObjectMapperProvider; import org.eclipse.edc.web.spi.WebServer; @@ -48,26 +48,26 @@ class DspApiConfigurationExtensionTest { private final WebServiceConfigurer configurer = mock(); private final WebServer webServer = mock(); private final WebService webService = mock(); - - private DspApiConfigurationExtension extension; + private final TypeManager typeManager = mock(); @BeforeEach - void setUp(ServiceExtensionContext context, ObjectFactory factory) { + void setUp(ServiceExtensionContext context) { context.registerService(WebServer.class, webServer); context.registerService(WebService.class, webService); context.registerService(WebServiceConfigurer.class, configurer); - extension = factory.constructInstance(DspApiConfigurationExtension.class); - + context.registerService(TypeManager.class, typeManager); + var webServiceConfiguration = WebServiceConfiguration.Builder.newInstance() .contextAlias(CONTEXT_ALIAS) .path("/path") .port(1234) .build(); when(configurer.configure(any(), any(), any())).thenReturn(webServiceConfiguration); + when(typeManager.getMapper(any())).thenReturn(mock()); } @Test - void initialize_noSettingsProvided_useDspDefault(ServiceExtensionContext context) { + void initialize_noSettingsProvided_useDspDefault(DspApiConfigurationExtension extension, ServiceExtensionContext context) { when(context.getConfig()).thenReturn(ConfigFactory.empty()); when(context.getSetting(DSP_CALLBACK_ADDRESS, DEFAULT_DSP_CALLBACK_ADDRESS)).thenReturn(DEFAULT_DSP_CALLBACK_ADDRESS); @@ -80,9 +80,8 @@ void initialize_noSettingsProvided_useDspDefault(ServiceExtensionContext context } @Test - void initialize_settingsProvided_useSettings(ServiceExtensionContext context) { + void initialize_settingsProvided_useSettings(DspApiConfigurationExtension extension, ServiceExtensionContext context) { var webhookAddress = "http://webhook"; - when(context.getConfig()).thenReturn(ConfigFactory.fromMap(Map.of( "web.http.protocol.port", String.valueOf(1234), "web.http.protocol.path", "/path")) @@ -98,7 +97,7 @@ void initialize_settingsProvided_useSettings(ServiceExtensionContext context) { } @Test - void initialize_shouldRegisterWebServiceProviders(ServiceExtensionContext context) { + void initialize_shouldRegisterWebServiceProviders(DspApiConfigurationExtension extension, ServiceExtensionContext context) { extension.initialize(context); verify(webService).registerResource(eq(CONTEXT_ALIAS), isA(ObjectMapperProvider.class)); diff --git a/data-protocols/dsp/dsp-catalog/dsp-catalog-api/build.gradle.kts b/data-protocols/dsp/dsp-catalog/dsp-catalog-api/build.gradle.kts index 30f929c0525..9849e58cd9c 100644 --- a/data-protocols/dsp/dsp-catalog/dsp-catalog-api/build.gradle.kts +++ b/data-protocols/dsp/dsp-catalog/dsp-catalog-api/build.gradle.kts @@ -20,7 +20,6 @@ dependencies { api(project(":data-protocols:dsp:dsp-api-configuration")) api(project(":data-protocols:dsp:dsp-spi")) api(project(":data-protocols:dsp:dsp-http-spi")) - api(project(":data-protocols:dsp:dsp-transform")) api(project(":spi:common:core-spi")) api(project(":spi:control-plane:control-plane-spi")) diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/build.gradle.kts b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/build.gradle.kts index 28b42812503..bcc4fe67fa8 100644 --- a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/build.gradle.kts +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/build.gradle.kts @@ -19,8 +19,7 @@ plugins { dependencies { api(project(":data-protocols:dsp:dsp-spi")) api(project(":data-protocols:dsp:dsp-http-spi")) - api(project(":data-protocols:dsp:dsp-transform")) api(project(":extensions:common:json-ld")) api(project(":spi:common:transform-spi")) api(project(":spi:control-plane:contract-spi")) -} \ No newline at end of file +} diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/build.gradle.kts b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/build.gradle.kts index 2a498171458..e40c17f9c7d 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/build.gradle.kts +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/build.gradle.kts @@ -19,10 +19,10 @@ plugins { dependencies { api(project(":spi:control-plane:transfer-spi")) api(project(":spi:common:transform-spi")) + api(project(":core:common:transform-core")) api(project(":extensions:common:json-ld")) api(project(":data-protocols:dsp:dsp-spi")) api(project(":data-protocols:dsp:dsp-http-spi")) - api(project(":data-protocols:dsp:dsp-transform")) testImplementation(project(":core:common:junit")) } diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/DspTransferProcessTransformExtension.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/DspTransferProcessTransformExtension.java index 68fd7f938d0..8d77e81d58b 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/DspTransferProcessTransformExtension.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/DspTransferProcessTransformExtension.java @@ -15,8 +15,7 @@ package org.eclipse.edc.protocol.dsp.transferprocess.transformer; import jakarta.json.Json; -import org.eclipse.edc.jsonld.spi.JsonLd; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToDataAddressTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToDataAddressTransformer; import org.eclipse.edc.protocol.dsp.transferprocess.transformer.type.from.JsonObjectFromDataAddressTransformer; import org.eclipse.edc.protocol.dsp.transferprocess.transformer.type.from.JsonObjectFromTransferCompletionMessageTransformer; import org.eclipse.edc.protocol.dsp.transferprocess.transformer.type.from.JsonObjectFromTransferProcessTransformer; @@ -45,8 +44,6 @@ public class DspTransferProcessTransformExtension implements ServiceExtension { @Inject private TypeTransformerRegistry registry; - @Inject - private JsonLd jsonLdService; @Override public String name() { diff --git a/data-protocols/dsp/dsp-transform/src/main/java/org/eclipse/edc/protocol/dsp/transform/DspTransformExtension.java b/data-protocols/dsp/dsp-transform/src/main/java/org/eclipse/edc/protocol/dsp/transform/DspTransformExtension.java deleted file mode 100644 index be247915f5c..00000000000 --- a/data-protocols/dsp/dsp-transform/src/main/java/org/eclipse/edc/protocol/dsp/transform/DspTransformExtension.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation - * - */ - -package org.eclipse.edc.protocol.dsp.transform; - -import jakarta.json.Json; -import org.eclipse.edc.jsonld.transformer.OdrlTransformersFactory; -import org.eclipse.edc.jsonld.transformer.from.JsonObjectFromAssetTransformer; -import org.eclipse.edc.jsonld.transformer.from.JsonObjectFromCatalogTransformer; -import org.eclipse.edc.jsonld.transformer.from.JsonObjectFromCriterionTransformer; -import org.eclipse.edc.jsonld.transformer.from.JsonObjectFromDataServiceTransformer; -import org.eclipse.edc.jsonld.transformer.from.JsonObjectFromDatasetTransformer; -import org.eclipse.edc.jsonld.transformer.from.JsonObjectFromDistributionTransformer; -import org.eclipse.edc.jsonld.transformer.from.JsonObjectFromPolicyTransformer; -import org.eclipse.edc.jsonld.transformer.from.JsonObjectFromQuerySpecTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToAssetTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToCatalogTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToCriterionTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToDataServiceTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToDatasetTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToDistributionTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToQuerySpecTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonValueToGenericTypeTransformer; -import org.eclipse.edc.policy.model.AtomicConstraint; -import org.eclipse.edc.policy.model.LiteralExpression; -import org.eclipse.edc.runtime.metamodel.annotation.Extension; -import org.eclipse.edc.runtime.metamodel.annotation.Inject; -import org.eclipse.edc.spi.system.ServiceExtension; -import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.types.TypeManager; -import org.eclipse.edc.transform.spi.TypeTransformerRegistry; - -import java.util.Map; - -import static org.eclipse.edc.spi.CoreConstants.JSON_LD; - -/** - * Provides support for transforming DCAT catalog and ODRL policy types to and from JSON-LD. The - * respective transformers are registered with the {@link TypeTransformerRegistry}. - */ -@Extension(value = DspTransformExtension.NAME) -public class DspTransformExtension implements ServiceExtension { - - public static final String NAME = "Dataspace Protocol Transform Extension"; - - @Inject - private TypeManager typeManager; - - @Inject - private TypeTransformerRegistry registry; - - @Override - public String name() { - return NAME; - } - - @Override - public void initialize(ServiceExtensionContext context) { - var mapper = typeManager.getMapper(JSON_LD); - mapper.registerSubtypes(AtomicConstraint.class, LiteralExpression.class); - - var jsonBuilderFactory = Json.createBuilderFactory(Map.of()); - - // EDC model to JSON-LD transformers - registry.register(new JsonObjectFromCatalogTransformer(jsonBuilderFactory, mapper)); - registry.register(new JsonObjectFromDatasetTransformer(jsonBuilderFactory, mapper)); - registry.register(new JsonObjectFromPolicyTransformer(jsonBuilderFactory)); - registry.register(new JsonObjectFromDistributionTransformer(jsonBuilderFactory)); - registry.register(new JsonObjectFromDataServiceTransformer(jsonBuilderFactory)); - registry.register(new JsonObjectFromAssetTransformer(jsonBuilderFactory, mapper)); - registry.register(new JsonObjectFromQuerySpecTransformer(jsonBuilderFactory)); - registry.register(new JsonObjectFromCriterionTransformer(jsonBuilderFactory, mapper)); - - // JSON-LD to EDC model transformers - // DCAT transformers - registry.register(new JsonObjectToCatalogTransformer()); - registry.register(new JsonObjectToDataServiceTransformer()); - registry.register(new JsonObjectToDatasetTransformer()); - registry.register(new JsonObjectToDistributionTransformer()); - - // ODRL Transformers - OdrlTransformersFactory.jsonObjectToOdrlTransformers().forEach(registry::register); - - registry.register(new JsonValueToGenericTypeTransformer(mapper)); - registry.register(new JsonObjectToAssetTransformer()); - registry.register(new JsonObjectToQuerySpecTransformer()); - registry.register(new JsonObjectToCriterionTransformer()); - - } -} diff --git a/data-protocols/dsp/dsp-transform/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension b/data-protocols/dsp/dsp-transform/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension deleted file mode 100644 index 6fb64f97a97..00000000000 --- a/data-protocols/dsp/dsp-transform/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension +++ /dev/null @@ -1,15 +0,0 @@ -# -# Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering -# -# 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 -# -# SPDX-License-Identifier: Apache-2.0 -# -# Contributors: -# Fraunhofer Institute for Software and Systems Engineering - Initial API and Implementation -# -# - -org.eclipse.edc.protocol.dsp.transform.DspTransformExtension \ No newline at end of file diff --git a/extensions/common/api/api-core/build.gradle.kts b/extensions/common/api/api-core/build.gradle.kts index e2b0d15730a..991ee88196f 100644 --- a/extensions/common/api/api-core/build.gradle.kts +++ b/extensions/common/api/api-core/build.gradle.kts @@ -23,6 +23,7 @@ dependencies { api(project(":spi:common:web-spi")) api(project(":spi:common:json-ld-spi")) + implementation(project(":core:common:transform-core")) implementation(project(":core:common:util")) implementation(project(":core:common:validator-core")) implementation(libs.jakarta.rsApi) diff --git a/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCallbackAddressTransformerTest.java b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCallbackAddressTransformerTest.java index 1a3ca84a561..53503fa038f 100644 --- a/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCallbackAddressTransformerTest.java +++ b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCallbackAddressTransformerTest.java @@ -15,9 +15,9 @@ package org.eclipse.edc.api.transformer; import jakarta.json.Json; +import org.eclipse.edc.core.transform.transformer.to.JsonValueToGenericTypeTransformer; import org.eclipse.edc.jsonld.TitaniumJsonLd; import org.eclipse.edc.jsonld.spi.JsonLd; -import org.eclipse.edc.jsonld.transformer.to.JsonValueToGenericTypeTransformer; import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.transform.spi.TransformerContext; import org.junit.jupiter.api.BeforeEach; diff --git a/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCriterionDtoTransformerTest.java b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCriterionDtoTransformerTest.java index f1d9fab771e..b7e2e2fd342 100644 --- a/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCriterionDtoTransformerTest.java +++ b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCriterionDtoTransformerTest.java @@ -16,8 +16,8 @@ import jakarta.json.JsonArrayBuilder; import jakarta.json.JsonValue; +import org.eclipse.edc.core.transform.transformer.to.JsonValueToGenericTypeTransformer; import org.eclipse.edc.jsonld.spi.JsonLdKeywords; -import org.eclipse.edc.jsonld.transformer.to.JsonValueToGenericTypeTransformer; import org.eclipse.edc.transform.spi.TransformerContext; import org.junit.jupiter.api.Test; diff --git a/extensions/common/api/management-api-configuration/build.gradle.kts b/extensions/common/api/management-api-configuration/build.gradle.kts index 6600d0434d3..cd58d12b7c2 100644 --- a/extensions/common/api/management-api-configuration/build.gradle.kts +++ b/extensions/common/api/management-api-configuration/build.gradle.kts @@ -21,6 +21,7 @@ dependencies { api(project(":spi:common:json-ld-spi")) api(project(":spi:common:web-spi")) implementation(project(":core:common:jersey-providers")) + implementation(project(":core:common:transform-core")) implementation(project(":extensions:common:api:api-core")) testImplementation(project(":core:common:junit")) diff --git a/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiConfigurationExtension.java b/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiConfigurationExtension.java index eb07f6e3e01..89d2a1175fb 100644 --- a/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiConfigurationExtension.java +++ b/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiConfigurationExtension.java @@ -16,13 +16,17 @@ import org.eclipse.edc.api.auth.spi.AuthenticationRequestFilter; import org.eclipse.edc.api.auth.spi.AuthenticationService; +import org.eclipse.edc.connector.api.management.configuration.transform.ManagementApiTypeTransformerRegistry; +import org.eclipse.edc.connector.api.management.configuration.transform.ManagementApiTypeTransformerRegistryImpl; import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; +import org.eclipse.edc.runtime.metamodel.annotation.Provider; import org.eclipse.edc.runtime.metamodel.annotation.Provides; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; import org.eclipse.edc.spi.types.TypeManager; +import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.web.jersey.jsonld.JerseyJsonLdInterceptor; import org.eclipse.edc.web.jersey.jsonld.ObjectMapperProvider; import org.eclipse.edc.web.spi.WebServer; @@ -75,6 +79,9 @@ public class ManagementApiConfigurationExtension implements ServiceExtension { @Inject private JsonLd jsonLd; + @Inject + private TypeTransformerRegistry transformerRegistry; + @Override public String name() { return NAME; @@ -91,4 +98,9 @@ public void initialize(ServiceExtensionContext context) { webService.registerResource(webServiceConfiguration.getContextAlias(), new ObjectMapperProvider(jsonLdMapper)); webService.registerResource(webServiceConfiguration.getContextAlias(), new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper)); } + + @Provider + public ManagementApiTypeTransformerRegistry managementApiTypeTransformerRegistry() { + return new ManagementApiTypeTransformerRegistryImpl(this.transformerRegistry); + } } diff --git a/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/transform/ManagementApiTypeTransformerRegistry.java b/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/transform/ManagementApiTypeTransformerRegistry.java new file mode 100644 index 00000000000..872cf3ab53d --- /dev/null +++ b/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/transform/ManagementApiTypeTransformerRegistry.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +package org.eclipse.edc.connector.api.management.configuration.transform; + +import org.eclipse.edc.transform.spi.TypeTransformerRegistry; + +/** + * Type transformer used in the management api context + */ +public interface ManagementApiTypeTransformerRegistry extends TypeTransformerRegistry { +} diff --git a/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/transform/ManagementApiTypeTransformerRegistryImpl.java b/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/transform/ManagementApiTypeTransformerRegistryImpl.java new file mode 100644 index 00000000000..7de1baa51ed --- /dev/null +++ b/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/transform/ManagementApiTypeTransformerRegistryImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +package org.eclipse.edc.connector.api.management.configuration.transform; + +import org.eclipse.edc.core.transform.TypeTransformerRegistryImpl; +import org.eclipse.edc.spi.EdcException; +import org.eclipse.edc.transform.spi.TypeTransformer; +import org.eclipse.edc.transform.spi.TypeTransformerRegistry; +import org.jetbrains.annotations.NotNull; + +public class ManagementApiTypeTransformerRegistryImpl extends TypeTransformerRegistryImpl implements ManagementApiTypeTransformerRegistry { + + private final TypeTransformerRegistry fallback; + + public ManagementApiTypeTransformerRegistryImpl(TypeTransformerRegistry fallback) { + super(); + this.fallback = fallback; + } + + @Override + public @NotNull TypeTransformer transformerFor(@NotNull INPUT input, @NotNull Class outputType) { + try { + return super.transformerFor(input, outputType); + } catch (EdcException exception) { + return fallback.transformerFor(input, outputType); + } + } +} diff --git a/extensions/common/api/management-api-configuration/src/test/java/org/eclipse/edc/connector/api/management/configuration/transform/ManagementApiTypeTransformerRegistryImplTest.java b/extensions/common/api/management-api-configuration/src/test/java/org/eclipse/edc/connector/api/management/configuration/transform/ManagementApiTypeTransformerRegistryImplTest.java new file mode 100644 index 00000000000..a93c148890c --- /dev/null +++ b/extensions/common/api/management-api-configuration/src/test/java/org/eclipse/edc/connector/api/management/configuration/transform/ManagementApiTypeTransformerRegistryImplTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +package org.eclipse.edc.connector.api.management.configuration.transform; + +import jakarta.json.Json; +import jakarta.json.JsonObject; +import org.eclipse.edc.core.transform.TypeTransformerRegistryImpl; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.eclipse.edc.transform.spi.TypeTransformer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.Test; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; + +class ManagementApiTypeTransformerRegistryImplTest { + + @Test + void shouldUseRegisteredTransformer() { + var fallbackRegistry = spy(new TypeTransformerRegistryImpl()); + TypeTransformer fallbackTransformer = spy(new StringJsonObjectTypeTransformer()); + fallbackRegistry.register(fallbackTransformer); + ManagementApiTypeTransformerRegistry transformerRegistry = new ManagementApiTypeTransformerRegistryImpl(fallbackRegistry); + TypeTransformer transformer = spy(new StringJsonObjectTypeTransformer()); + transformerRegistry.register(transformer); + + transformerRegistry.transform("{}", JsonObject.class); + + verify(transformer).transform(eq("{}"), any()); + verifyNoInteractions(fallbackTransformer); + } + + @Test + void shouldUsePassedRegistryTransformer_whenNoTransformerFound() { + var fallbackRegistry = new TypeTransformerRegistryImpl(); + TypeTransformer fallbackTransformer = spy(new StringJsonObjectTypeTransformer()); + fallbackRegistry.register(fallbackTransformer); + ManagementApiTypeTransformerRegistry transformerRegistry = new ManagementApiTypeTransformerRegistryImpl(fallbackRegistry); + + transformerRegistry.transform("{}", JsonObject.class); + + verify(fallbackTransformer).transform(eq("{}"), any()); + } + + private static class StringJsonObjectTypeTransformer implements TypeTransformer { + @Override + public Class getInputType() { + return String.class; + } + + @Override + public Class getOutputType() { + return JsonObject.class; + } + + @Override + public @Nullable JsonObject transform(@NotNull String s, @NotNull TransformerContext context) { + return Json.createObjectBuilder().build(); + } + } +} diff --git a/extensions/control-plane/api/management-api/asset-api/build.gradle.kts b/extensions/control-plane/api/management-api/asset-api/build.gradle.kts index 34baf680488..60d750ff00f 100644 --- a/extensions/control-plane/api/management-api/asset-api/build.gradle.kts +++ b/extensions/control-plane/api/management-api/asset-api/build.gradle.kts @@ -27,6 +27,7 @@ dependencies { implementation(libs.jakarta.rsApi) + testImplementation(project(":core:common:transform-core")) testImplementation(project(":core:control-plane:control-plane-core")) testImplementation(project(":core:data-plane-selector:data-plane-selector-core")) testImplementation(project(":extensions:common:http")) diff --git a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApiExtension.java b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApiExtension.java index e0eb57183c5..c7ff031e99d 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApiExtension.java +++ b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApiExtension.java @@ -25,13 +25,13 @@ import org.eclipse.edc.connector.api.management.asset.validation.AssetEntryDtoValidator; import org.eclipse.edc.connector.api.management.asset.validation.AssetValidator; import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration; +import org.eclipse.edc.connector.api.management.configuration.transform.ManagementApiTypeTransformerRegistry; import org.eclipse.edc.connector.spi.asset.AssetService; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.asset.DataAddressResolver; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.web.spi.WebService; @@ -51,7 +51,7 @@ public class AssetApiExtension implements ServiceExtension { private ManagementApiConfiguration config; @Inject - private TypeTransformerRegistry transformerRegistry; + private ManagementApiTypeTransformerRegistry transformerRegistry; @Inject private AssetService assetService; diff --git a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/v3/AssetApiTest.java b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/v3/AssetApiTest.java index 81dcad9d70b..16d2765da77 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/v3/AssetApiTest.java +++ b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/v3/AssetApiTest.java @@ -18,12 +18,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.JsonObject; import org.eclipse.edc.connector.api.management.asset.validation.AssetValidator; -import org.eclipse.edc.connector.core.transform.TypeTransformerRegistryImpl; +import org.eclipse.edc.core.transform.TypeTransformerRegistryImpl; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToAssetTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonObjectToDataAddressTransformer; +import org.eclipse.edc.core.transform.transformer.to.JsonValueToGenericTypeTransformer; import org.eclipse.edc.jsonld.TitaniumJsonLd; import org.eclipse.edc.jsonld.spi.JsonLd; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToAssetTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonObjectToDataAddressTransformer; -import org.eclipse.edc.jsonld.transformer.to.JsonValueToGenericTypeTransformer; import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; diff --git a/extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/api/management/catalog/CatalogApiExtension.java b/extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/api/management/catalog/CatalogApiExtension.java index f348a63e619..cf0cf77ed93 100644 --- a/extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/api/management/catalog/CatalogApiExtension.java +++ b/extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/api/management/catalog/CatalogApiExtension.java @@ -19,12 +19,12 @@ import org.eclipse.edc.connector.api.management.catalog.transform.JsonObjectToCatalogRequestDtoTransformer; import org.eclipse.edc.connector.api.management.catalog.validation.CatalogRequestValidator; import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration; +import org.eclipse.edc.connector.api.management.configuration.transform.ManagementApiTypeTransformerRegistry; import org.eclipse.edc.connector.spi.catalog.CatalogService; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.web.spi.WebService; @@ -40,7 +40,7 @@ public class CatalogApiExtension implements ServiceExtension { private ManagementApiConfiguration config; @Inject - private TypeTransformerRegistry transformerRegistry; + private ManagementApiTypeTransformerRegistry transformerRegistry; @Inject private CatalogService service; diff --git a/extensions/control-plane/api/management-api/contract-agreement-api/build.gradle.kts b/extensions/control-plane/api/management-api/contract-agreement-api/build.gradle.kts index fe156e7ffc5..ad4e0bb17a8 100644 --- a/extensions/control-plane/api/management-api/contract-agreement-api/build.gradle.kts +++ b/extensions/control-plane/api/management-api/contract-agreement-api/build.gradle.kts @@ -26,6 +26,7 @@ dependencies { implementation(libs.jakarta.rsApi) + testImplementation(project(":core:common:transform-core")) testImplementation(project(":core:control-plane:control-plane-core")) testImplementation(project(":core:data-plane-selector:data-plane-selector-core")) testImplementation(project(":extensions:common:http")) diff --git a/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiExtension.java b/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiExtension.java index f8e53564cd6..dede652cffe 100644 --- a/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiExtension.java +++ b/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiExtension.java @@ -17,6 +17,7 @@ import jakarta.json.Json; import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration; +import org.eclipse.edc.connector.api.management.configuration.transform.ManagementApiTypeTransformerRegistry; import org.eclipse.edc.connector.api.management.contractagreement.transform.ContractAgreementToContractAgreementDtoTransformer; import org.eclipse.edc.connector.api.management.contractagreement.transform.JsonObjectFromContractAgreementDtoTransformer; import org.eclipse.edc.connector.spi.contractagreement.ContractAgreementService; @@ -24,7 +25,6 @@ import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.web.spi.WebService; @@ -41,7 +41,7 @@ public class ContractAgreementApiExtension implements ServiceExtension { private ManagementApiConfiguration config; @Inject - private TypeTransformerRegistry transformerRegistry; + private ManagementApiTypeTransformerRegistry transformerRegistry; @Inject private ContractAgreementService service; diff --git a/extensions/control-plane/api/management-api/contract-definition-api/build.gradle.kts b/extensions/control-plane/api/management-api/contract-definition-api/build.gradle.kts index 6fc202257b4..1be33851b40 100644 --- a/extensions/control-plane/api/management-api/contract-definition-api/build.gradle.kts +++ b/extensions/control-plane/api/management-api/contract-definition-api/build.gradle.kts @@ -26,6 +26,7 @@ dependencies { implementation(libs.jakarta.rsApi) + testImplementation(project(":core:common:transform-core")) testImplementation(project(":core:control-plane:control-plane-core")) testImplementation(project(":core:data-plane-selector:data-plane-selector-core")) testImplementation(project(":extensions:common:http")) diff --git a/extensions/control-plane/api/management-api/contract-definition-api/src/main/java/org/eclipse/edc/connector/api/management/contractdefinition/ContractDefinitionApiExtension.java b/extensions/control-plane/api/management-api/contract-definition-api/src/main/java/org/eclipse/edc/connector/api/management/contractdefinition/ContractDefinitionApiExtension.java index 482c0fa0433..65e15bad596 100644 --- a/extensions/control-plane/api/management-api/contract-definition-api/src/main/java/org/eclipse/edc/connector/api/management/contractdefinition/ContractDefinitionApiExtension.java +++ b/extensions/control-plane/api/management-api/contract-definition-api/src/main/java/org/eclipse/edc/connector/api/management/contractdefinition/ContractDefinitionApiExtension.java @@ -17,6 +17,7 @@ import jakarta.json.Json; import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration; +import org.eclipse.edc.connector.api.management.configuration.transform.ManagementApiTypeTransformerRegistry; import org.eclipse.edc.connector.api.management.contractdefinition.transform.JsonObjectFromContractDefinitionTransformer; import org.eclipse.edc.connector.api.management.contractdefinition.transform.JsonObjectToContractDefinitionTransformer; import org.eclipse.edc.connector.api.management.contractdefinition.validation.ContractDefinitionValidator; @@ -25,7 +26,6 @@ import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.web.spi.WebService; @@ -45,7 +45,7 @@ public class ContractDefinitionApiExtension implements ServiceExtension { ManagementApiConfiguration config; @Inject - TypeTransformerRegistry transformerRegistry; + ManagementApiTypeTransformerRegistry transformerRegistry; @Inject ContractDefinitionService service; diff --git a/extensions/control-plane/api/management-api/contract-definition-api/src/test/java/org/eclipse/edc/connector/api/management/contractdefinition/ContractDefinitionApiTest.java b/extensions/control-plane/api/management-api/contract-definition-api/src/test/java/org/eclipse/edc/connector/api/management/contractdefinition/ContractDefinitionApiTest.java index 8a4983eebca..4b5b3abeafb 100644 --- a/extensions/control-plane/api/management-api/contract-definition-api/src/test/java/org/eclipse/edc/connector/api/management/contractdefinition/ContractDefinitionApiTest.java +++ b/extensions/control-plane/api/management-api/contract-definition-api/src/test/java/org/eclipse/edc/connector/api/management/contractdefinition/ContractDefinitionApiTest.java @@ -20,7 +20,7 @@ import org.eclipse.edc.connector.api.management.contractdefinition.transform.JsonObjectToContractDefinitionTransformer; import org.eclipse.edc.connector.api.management.contractdefinition.validation.ContractDefinitionValidator; import org.eclipse.edc.connector.contract.spi.types.offer.ContractDefinition; -import org.eclipse.edc.connector.core.transform.TypeTransformerRegistryImpl; +import org.eclipse.edc.core.transform.TypeTransformerRegistryImpl; import org.eclipse.edc.jsonld.TitaniumJsonLd; import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.jsonld.util.JacksonJsonLd; diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/build.gradle.kts b/extensions/control-plane/api/management-api/contract-negotiation-api/build.gradle.kts index f806bcf2442..4d34289f5ca 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/build.gradle.kts +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/build.gradle.kts @@ -24,6 +24,7 @@ dependencies { implementation(libs.jakarta.rsApi) + testImplementation(project(":core:common:transform-core")) testImplementation(project(":core:common:util")) testImplementation(project(":core:control-plane:control-plane-core")) testImplementation(project(":core:data-plane-selector:data-plane-selector-core")) diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApi.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApi.java index 3fa0f37b08f..eb52ecbcac8 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApi.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApi.java @@ -26,23 +26,31 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.json.JsonArray; import jakarta.json.JsonObject; -import org.eclipse.edc.api.model.IdResponseDto; -import org.eclipse.edc.api.model.QuerySpecDto; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractAgreementDto; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto; +import org.eclipse.edc.api.model.ApiCoreSchema; +import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription; import org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationState; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; +import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; import org.eclipse.edc.web.spi.ApiErrorDetail; +import java.util.List; +import java.util.Set; + +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_TYPE; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.CONTRACT_REQUEST_TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; + @OpenAPIDefinition @Tag(name = "Contract Negotiation") public interface ContractNegotiationApi { @Operation(description = "Returns all contract negotiations according to a query", - requestBody = @RequestBody(content = @Content(schema = @Schema(implementation = QuerySpecDto.class))), + requestBody = @RequestBody(content = @Content(schema = @Schema(implementation = ApiCoreSchema.QuerySpecSchema.class))), responses = { @ApiResponse(responseCode = "200", description = "The contract negotiations that match the query", - content = @Content(array = @ArraySchema(schema = @Schema(implementation = ContractNegotiationDto.class)))), + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ContractNegotiationSchema.class)))), @ApiResponse(responseCode = "400", description = "Request was malformed", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))) } ) @@ -51,7 +59,7 @@ public interface ContractNegotiationApi { @Operation(description = "Gets a contract negotiation with the given ID", responses = { @ApiResponse(responseCode = "200", description = "The contract negotiation", - content = @Content(schema = @Schema(implementation = ContractNegotiationDto.class))), + content = @Content(schema = @Schema(implementation = ContractNegotiationSchema.class))), @ApiResponse(responseCode = "400", description = "Request was malformed, e.g. id was null", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))), @ApiResponse(responseCode = "404", description = "An contract negotiation with the given ID does not exist", @@ -76,7 +84,7 @@ public interface ContractNegotiationApi { @Operation(description = "Gets a contract agreement for a contract negotiation with the given ID", responses = { @ApiResponse(responseCode = "200", description = "The contract agreement that is attached to the negotiation, or null", - content = @Content(schema = @Schema(implementation = ContractAgreementDto.class))), + content = @Content(schema = @Schema(implementation = ContractAgreementSchema.class))), @ApiResponse(responseCode = "400", description = "Request was malformed, e.g. id was null", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))), @ApiResponse(responseCode = "404", description = "An contract negotiation with the given ID does not exist", @@ -87,10 +95,10 @@ public interface ContractNegotiationApi { @Operation(description = "Initiates a contract negotiation for a given offer and with the given counter part. Please note that successfully invoking this endpoint " + "only means that the negotiation was initiated. Clients must poll the /{id}/state endpoint to track the state", - requestBody = @RequestBody(content = @Content(schema = @Schema(implementation = NegotiationInitiateRequestDto.class))), + requestBody = @RequestBody(content = @Content(schema = @Schema(implementation = ContractRequestSchema.class))), responses = { @ApiResponse(responseCode = "200", description = "The negotiation was successfully initiated. Returns the contract negotiation ID and created timestamp", - content = @Content(schema = @Schema(implementation = IdResponseDto.class)), + content = @Content(schema = @Schema(implementation = ApiCoreSchema.IdResponseSchema.class)), links = @Link(name = "poll-state", operationId = "getNegotiationState", parameters = { @LinkParameter(name = "id", expression = "$response.body#/id") }) @@ -124,4 +132,165 @@ public interface ContractNegotiationApi { } ) void declineNegotiation(String id); + + @Schema(example = ContractRequestSchema.CONTRACT_REQUEST_EXAMPLE) + record ContractRequestSchema( + @Schema(name = TYPE, example = CONTRACT_REQUEST_TYPE) + String type, + String protocol, + String connectorAddress, + @Deprecated(since = "0.1.3") + @Schema(deprecated = true, description = "please use providerId instead") + String connectorId, + @Deprecated(since = "0.1.3") + @Schema(deprecated = true, description = "this field is not used anymore") + String consumerId, + String providerId, + ContractOfferDescriptionSchema offer, + List callbackAddresses) { + + // policy example took from https://w3c.github.io/odrl/bp/ + public static final String CONTRACT_REQUEST_EXAMPLE = """ + { + "@context": { "edc": "https://w3id.org/edc/v0.0.1/ns/" }, + "@type": "https://w3id.org/edc/v0.0.1/ns/ContractRequest", + "connectorAddress": "http://provider-address", + "protocol": "dataspace-protocol-http", + "providerId": "provider-id", + "offer": { + "offerId": "offer-id", + "assetId": "asset-id", + "policy": { + "@context": "http://www.w3.org/ns/odrl.jsonld", + "@type": "Set", + "@id": "offer-id", + "permission": [{ + "target": "asset-id", + "action": "display" + }] + } + }, + "callbackAddresses": [{ + "transactional": false, + "uri": "http://callback/url", + "events": ["contract.negotiation", "transfer.process"], + "authKey": "auth-key", + "authCodeId": "auth-code-id" + }] + } + """; + } + + @Schema(example = ContractNegotiationSchema.CONTRACT_NEGOTIATION_EXAMPLE) + record ContractNegotiationSchema( + @Schema(name = TYPE, example = CONTRACT_NEGOTIATION_TYPE) + String ldType, + @Schema(name = ID) + String id, + ContractNegotiation.Type type, + String protocol, + String counterPartyId, + String counterPartyAddress, + String state, + String contractAgreementId, + String errorDetail, + List callbackAddresses + ) { + public static final String CONTRACT_NEGOTIATION_EXAMPLE = """ + { + "@context": { "edc": "https://w3id.org/edc/v0.0.1/ns/" }, + "@type": "https://w3id.org/edc/v0.0.1/ns/ContractNegotiation", + "@id": "negotiation-id", + "type": "PROVIDER", + "protocol": "dataspace-protocol-http", + "counterPartyId": "counter-party-id", + "counterPartyAddress": "http://counter/party/address", + "state": "VERIFIED", + "contractAgreementId": "contract:agreement:id", + "errorDetail": "eventual-error-detail", + "createdAt": 1688465655, + "callbackAddresses": [{ + "transactional": false, + "uri": "http://callback/url", + "events": ["contract.negotiation", "transfer.process"], + "authKey": "auth-key", + "authCodeId": "auth-code-id" + }] + } + """; + } + + @Schema(example = ContractAgreementSchema.CONTRACT_AGREEMENT_EXAMPLE) + record ContractAgreementSchema( + @Schema(name = TYPE, example = ContractAgreement.CONTRACT_AGREEMENT_TYPE) + String ldType, + @Schema(name = ID) + String id, + String providerId, + String consumerId, + long contractSigningDate, + String assetId, + @Schema(description = "ODRL policy") + Object policy + ) { + public static final String CONTRACT_AGREEMENT_EXAMPLE = """ + { + "@context": { "edc": "https://w3id.org/edc/v0.0.1/ns/" }, + "@type": "https://w3id.org/edc/v0.0.1/ns/ContractAgreement", + "@id": "negotiation-id", + "providerId": "provider-id", + "consumerId": "consumer-id", + "assetId": "asset-id", + "contractSigningDate": 1688465655, + "policy": { + "@context": "http://www.w3.org/ns/odrl.jsonld", + "@type": "Set", + "@id": "offer-id", + "permission": [{ + "target": "asset-id", + "action": "display" + }] + } + } + """; + } + + + @Schema(example = NegotiationStateSchema.NEGOTIATION_STATE_EXAMPLE) + record NegotiationStateSchema( + @Schema(name = TYPE, example = NegotiationState.NEGOTIATION_STATE_TYPE) + String ldType, + String state + ) { + public static final String NEGOTIATION_STATE_EXAMPLE = """ + { + "@context": { "edc": "https://w3id.org/edc/v0.0.1/ns/" }, + "@type": "https://w3id.org/edc/v0.0.1/ns/NegotiationState", + "state": "REQUESTED" + } + """; + } + + record ContractOfferDescriptionSchema( + @Schema(name = TYPE, example = ContractOfferDescription.CONTRACT_OFFER_DESCRIPTION_TYPE) + String type, + String offerId, + String assetId, + @Schema(description = "ODRL policy") + Object policy + ) { + + } + + record CallbackAddressSchema( + @Schema(name = TYPE, example = CallbackAddress.CALLBACKADDRESS_TYPE) + String type, + String uri, + Set events, + boolean transactional, + String authKey, + String authCodeId + ) { + + } } diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiController.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiController.java index b58db8da3c9..632233d1db4 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiController.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiController.java @@ -27,9 +27,6 @@ import jakarta.ws.rs.core.MediaType; import org.eclipse.edc.api.model.IdResponseDto; import org.eclipse.edc.api.model.QuerySpecDto; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractAgreementDto; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto; import org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationState; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest; @@ -85,8 +82,7 @@ public JsonArray queryNegotiations(JsonObject querySpecDto) { try (var stream = service.query(querySpec).orElseThrow(exceptionMapper(ContractNegotiation.class, null))) { return stream - .map(it -> transformerRegistry.transform(it, ContractNegotiationDto.class) - .compose(dto -> transformerRegistry.transform(dto, JsonObject.class))) + .map(it -> transformerRegistry.transform(it, JsonObject.class)) .peek(this::logIfError) .filter(Result::succeeded) .map(Result::getContent) @@ -101,9 +97,8 @@ public JsonObject getNegotiation(@PathParam("id") String id) { return Optional.of(id) .map(service::findbyId) - .map(it -> transformerRegistry.transform(it, ContractNegotiationDto.class) - .compose(dto -> transformerRegistry.transform(dto, JsonObject.class)) - .orElseThrow(InvalidRequestException::new)) + .map(it -> transformerRegistry.transform(it, JsonObject.class)) + .map(Result::getContent) .orElseThrow(() -> new ObjectNotFoundException(ContractNegotiation.class, id)); } @@ -125,8 +120,7 @@ public JsonObject getNegotiationState(@PathParam("id") String id) { public JsonObject getAgreementForNegotiation(@PathParam("id") String negotiationId) { return Optional.of(negotiationId) .map(service::getForNegotiation) - .map(it -> transformerRegistry.transform(it, ContractAgreementDto.class) - .compose(dto -> transformerRegistry.transform(dto, JsonObject.class)) + .map(it -> transformerRegistry.transform(it, JsonObject.class) .orElseThrow(failure -> new EdcException(failure.getFailureDetail()))) .orElseThrow(() -> new ObjectNotFoundException(ContractNegotiation.class, negotiationId)); } @@ -134,14 +128,12 @@ public JsonObject getAgreementForNegotiation(@PathParam("id") String negotiation @POST @Override public JsonObject initiateContractNegotiation(JsonObject requestObject) { - validatorRegistry.validate(NegotiationInitiateRequestDto.TYPE, requestObject) + validatorRegistry.validate(ContractRequest.CONTRACT_REQUEST_TYPE, requestObject) .orElseThrow(ValidationFailureException::new); - var contractRequest = transformerRegistry.transform(requestObject, NegotiationInitiateRequestDto.class) - .compose(dto -> transformerRegistry.transform(dto, ContractRequest.class)) + var contractRequest = transformerRegistry.transform(requestObject, ContractRequest.class) .orElseThrow(InvalidRequestException::new); - var contractNegotiation = service.initiateNegotiation(contractRequest); var responseDto = IdResponseDto.Builder.newInstance() diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtension.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtension.java index 8aaf07cbd13..8ca23c9fda9 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtension.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtension.java @@ -17,26 +17,22 @@ import jakarta.json.Json; import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto; -import org.eclipse.edc.connector.api.management.contractnegotiation.transform.ContractAgreementToContractAgreementDtoTransformer; -import org.eclipse.edc.connector.api.management.contractnegotiation.transform.ContractNegotiationToContractNegotiationDtoTransformer; -import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectFromContractAgreementDtoTransformer; -import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectFromContractNegotiationDtoTransformer; +import org.eclipse.edc.connector.api.management.configuration.transform.ManagementApiTypeTransformerRegistry; +import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectFromContractAgreementTransformer; +import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectFromContractNegotiationTransformer; import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectFromNegotiationStateTransformer; import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectToContractOfferDescriptionTransformer; -import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectToNegotiationInitiateRequestDtoTransformer; -import org.eclipse.edc.connector.api.management.contractnegotiation.transform.NegotiationInitiateRequestDtoToDataRequestTransformer; -import org.eclipse.edc.connector.api.management.contractnegotiation.validation.NegotiationInitiateRequestDtoValidator; +import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectToContractRequestTransformer; +import org.eclipse.edc.connector.api.management.contractnegotiation.validation.ContractRequestValidator; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest; import org.eclipse.edc.connector.spi.contractnegotiation.ContractNegotiationService; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.web.spi.WebService; -import java.time.Clock; import java.util.Map; @Extension(value = ContractNegotiationApiExtension.NAME) @@ -51,14 +47,11 @@ public class ContractNegotiationApiExtension implements ServiceExtension { private ManagementApiConfiguration config; @Inject - private TypeTransformerRegistry transformerRegistry; + private ManagementApiTypeTransformerRegistry transformerRegistry; @Inject private ContractNegotiationService service; - @Inject - private Clock clock; - @Inject private JsonObjectValidatorRegistry validatorRegistry; @@ -69,17 +62,14 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - transformerRegistry.register(new ContractNegotiationToContractNegotiationDtoTransformer()); - transformerRegistry.register(new ContractAgreementToContractAgreementDtoTransformer()); - transformerRegistry.register(new NegotiationInitiateRequestDtoToDataRequestTransformer(clock)); var factory = Json.createBuilderFactory(Map.of()); - transformerRegistry.register(new JsonObjectFromContractNegotiationDtoTransformer(factory)); - transformerRegistry.register(new JsonObjectFromContractAgreementDtoTransformer(factory)); - transformerRegistry.register(new JsonObjectToNegotiationInitiateRequestDtoTransformer()); + transformerRegistry.register(new JsonObjectFromContractNegotiationTransformer(factory)); + transformerRegistry.register(new JsonObjectFromContractAgreementTransformer(factory)); + transformerRegistry.register(new JsonObjectToContractRequestTransformer()); transformerRegistry.register(new JsonObjectFromNegotiationStateTransformer(factory)); transformerRegistry.register(new JsonObjectToContractOfferDescriptionTransformer()); - validatorRegistry.register(NegotiationInitiateRequestDto.TYPE, NegotiationInitiateRequestDtoValidator.instance()); + validatorRegistry.register(ContractRequest.CONTRACT_REQUEST_TYPE, ContractRequestValidator.instance()); var monitor = context.getMonitor(); diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractAgreementDto.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractAgreementDto.java deleted file mode 100644 index 938d76e0769..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractAgreementDto.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2020 - 2022 Microsoft Corporation - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Microsoft Corporation - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.model; - -import org.eclipse.edc.policy.model.Policy; - -import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; - -public class ContractAgreementDto { - public static final String TYPE = EDC_NAMESPACE + "ContractAgreementDto"; - public static final String CONTRACT_AGREEMENT_ASSET_ID = EDC_NAMESPACE + "assetId"; - public static final String CONTRACT_AGREEMENT_PROVIDER_ID = EDC_NAMESPACE + "providerId"; - public static final String CONTRACT_AGREEMENT_CONSUMER_ID = EDC_NAMESPACE + "consumerId"; - public static final String CONTRACT_AGREEMENT_SIGNING_DATE = EDC_NAMESPACE + "contractSigningDate"; - public static final String CONTRACT_AGREEMENT_POLICY = EDC_NAMESPACE + "policy"; - - private String id; - private String providerId; - private String consumerId; - private long contractSigningDate; - private String assetId; - private Policy policy; - - public String getId() { - return id; - } - - public String getProviderId() { - return providerId; - } - - public String getConsumerId() { - return consumerId; - } - - public long getContractSigningDate() { - return contractSigningDate; - } - - public String getAssetId() { - return assetId; - } - - public Policy getPolicy() { - return policy; - } - - public static final class Builder { - private final ContractAgreementDto agreement; - - private Builder() { - agreement = new ContractAgreementDto(); - } - - public static Builder newInstance() { - return new Builder(); - } - - public Builder id(String id) { - agreement.id = id; - return this; - } - - public Builder providerId(String providerId) { - agreement.providerId = providerId; - return this; - } - - public Builder consumerId(String consumerId) { - agreement.consumerId = consumerId; - return this; - } - - public Builder contractSigningDate(long contractSigningDate) { - agreement.contractSigningDate = contractSigningDate; - return this; - } - - public Builder assetId(String assetId) { - agreement.assetId = assetId; - return this; - } - - public Builder policy(Policy policy) { - agreement.policy = policy; - return this; - } - - public ContractAgreementDto build() { - return agreement; - } - } -} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractNegotiationDto.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractNegotiationDto.java deleted file mode 100644 index 1df92e42a97..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractNegotiationDto.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2022 ZF Friedrichshafen AG - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * ZF Friedrichshafen AG - Initial API and Implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.model; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; -import org.eclipse.edc.api.model.MutableDto; -import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.Type; -import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; - -import java.util.ArrayList; -import java.util.List; - -import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; - -@JsonDeserialize(builder = ContractNegotiationDto.Builder.class) -public class ContractNegotiationDto extends MutableDto { - // constants used for JSON-LD transformation - public static final String CONTRACT_NEGOTIATION_TYPE = EDC_NAMESPACE + "ContractNegotiationDto"; - public static final String CONTRACT_NEGOTIATION_AGREEMENT_ID = EDC_NAMESPACE + "contractAgreementId"; - public static final String CONTRACT_NEGOTIATION_COUNTERPARTY_ADDR = EDC_NAMESPACE + "counterPartyAddress"; - public static final String CONTRACT_NEGOTIATION_ERRORDETAIL = EDC_NAMESPACE + "errorDetail"; - public static final String CONTRACT_NEGOTIATION_PROTOCOL = EDC_NAMESPACE + "protocol"; - public static final String CONTRACT_NEGOTIATION_STATE = EDC_NAMESPACE + "state"; - public static final String CONTRACT_NEGOTIATION_NEG_TYPE = EDC_NAMESPACE + "type"; - public static final String CONTRACT_NEGOTIATION_CALLBACK_ADDR = EDC_NAMESPACE + "callbackAddresses"; - - private String contractAgreementId; // is null until state == CONFIRMED - private String counterPartyAddress; - private String errorDetail; - - private String protocol; - private String state; - private Type type = Type.CONSUMER; - - private List callbackAddresses = new ArrayList<>(); - - - private ContractNegotiationDto() { - } - - public String getCounterPartyAddress() { - return counterPartyAddress; - } - - public String getProtocol() { - return protocol; - } - - public Type getType() { - return type; - } - - public String getState() { - return state; - } - - public String getErrorDetail() { - return errorDetail; - } - - public String getContractAgreementId() { - return contractAgreementId; - } - - public List getCallbackAddresses() { - return callbackAddresses; - } - - @JsonPOJOBuilder(withPrefix = "") - public static final class Builder extends MutableDto.Builder { - - private Builder() { - super(new ContractNegotiationDto()); - } - - @JsonCreator - public static Builder newInstance() { - return new Builder(); - } - - public Builder counterPartyAddress(String counterPartyAddress) { - dto.counterPartyAddress = counterPartyAddress; - return this; - } - - public Builder protocol(String protocol) { - dto.protocol = protocol; - return this; - } - - public Builder state(String state) { - dto.state = state; - return this; - } - - public Builder errorDetail(String errorDetail) { - dto.errorDetail = errorDetail; - return this; - } - - public Builder contractAgreementId(String contractAgreementId) { - dto.contractAgreementId = contractAgreementId; - return this; - } - - public Builder callbackAddresses(List callbackAddresses) { - dto.callbackAddresses = callbackAddresses; - return this; - } - - - public Builder type(Type type) { - dto.type = type; - return this; - } - - @Override - public Builder self() { - return this; - } - } -} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractOfferDescription.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractOfferDescription.java index 387cc7343da..52e99e99554 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractOfferDescription.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractOfferDescription.java @@ -21,7 +21,7 @@ public class ContractOfferDescription { - public static final String TYPE = EDC_NAMESPACE + "ContractOfferDescription"; + public static final String CONTRACT_OFFER_DESCRIPTION_TYPE = EDC_NAMESPACE + "ContractOfferDescription"; public static final String OFFER_ID = EDC_NAMESPACE + "offerId"; public static final String ASSET_ID = EDC_NAMESPACE + "assetId"; public static final String POLICY = EDC_NAMESPACE + "policy"; diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/NegotiationInitiateRequestDto.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/NegotiationInitiateRequestDto.java deleted file mode 100644 index 0e9763fc916..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/NegotiationInitiateRequestDto.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2020 - 2022 Microsoft Corporation - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Microsoft Corporation - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.model; - -import org.eclipse.edc.api.model.BaseDto; -import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; - -import java.util.ArrayList; -import java.util.List; - -import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; - -public class NegotiationInitiateRequestDto extends BaseDto { - public static final String TYPE = EDC_NAMESPACE + "NegotiationInitiateRequestDto"; - public static final String CONNECTOR_ADDRESS = EDC_NAMESPACE + "connectorAddress"; - public static final String PROTOCOL = EDC_NAMESPACE + "protocol"; - public static final String CONNECTOR_ID = EDC_NAMESPACE + "connectorId"; - public static final String PROVIDER_ID = EDC_NAMESPACE + "providerId"; - public static final String CONSUMER_ID = EDC_NAMESPACE + "consumerId"; - public static final String OFFER = EDC_NAMESPACE + "offer"; - public static final String CALLBACK_ADDRESSES = EDC_NAMESPACE + "callbackAddresses"; - - private String connectorAddress; // TODO change to callbackAddress - private String protocol; - private String connectorId; - private ContractOfferDescription offer; - private String providerId; - private String consumerId; - - private List callbackAddresses = new ArrayList<>(); - - private NegotiationInitiateRequestDto() { - - } - - public String getConnectorAddress() { - return connectorAddress; - } - - public String getProtocol() { - return protocol; - } - - public String getConnectorId() { - return connectorId; - } - - public ContractOfferDescription getOffer() { - return offer; - } - - - public String getConsumerId() { - return consumerId; - } - - public String getProviderId() { - return providerId; - } - - public List getCallbackAddresses() { - return callbackAddresses; - } - - public static final class Builder { - private final NegotiationInitiateRequestDto dto; - - private Builder() { - dto = new NegotiationInitiateRequestDto(); - } - - public static Builder newInstance() { - return new Builder(); - } - - public Builder connectorAddress(String connectorAddress) { - dto.connectorAddress = connectorAddress; - return this; - } - - public Builder protocol(String protocol) { - dto.protocol = protocol; - return this; - } - - public Builder connectorId(String connectorId) { - dto.connectorId = connectorId; - return this; - } - - public Builder offer(ContractOfferDescription offer) { - dto.offer = offer; - return this; - } - - public Builder consumerId(String consumerId) { - dto.consumerId = consumerId; - return this; - } - - public Builder providerId(String providerId) { - dto.providerId = providerId; - return this; - } - - public Builder callbackAddresses(List callbackAddresses) { - dto.callbackAddresses = callbackAddresses; - return this; - } - - public NegotiationInitiateRequestDto build() { - return dto; - } - } -} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/ContractAgreementToContractAgreementDtoTransformer.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/ContractAgreementToContractAgreementDtoTransformer.java deleted file mode 100644 index ae9c93d7874..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/ContractAgreementToContractAgreementDtoTransformer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; - -import org.eclipse.edc.api.transformer.DtoTransformer; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractAgreementDto; -import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class ContractAgreementToContractAgreementDtoTransformer implements DtoTransformer { - - @Override - public Class getInputType() { - return ContractAgreement.class; - } - - @Override - public Class getOutputType() { - return ContractAgreementDto.class; - } - - @Override - public @Nullable ContractAgreementDto transform(@NotNull ContractAgreement object, @NotNull TransformerContext context) { - return ContractAgreementDto.Builder.newInstance() - .id(object.getId()) - .assetId(object.getAssetId()) - .policy(object.getPolicy()) - .consumerId(object.getConsumerId()) - .providerId(object.getProviderId()) - .contractSigningDate(object.getContractSigningDate()) - .build(); - } -} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/ContractNegotiationToContractNegotiationDtoTransformer.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/ContractNegotiationToContractNegotiationDtoTransformer.java deleted file mode 100644 index 89cac8268bf..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/ContractNegotiationToContractNegotiationDtoTransformer.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; - -import org.eclipse.edc.api.transformer.DtoTransformer; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto; -import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; -import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; -import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static java.util.Optional.ofNullable; - -public class ContractNegotiationToContractNegotiationDtoTransformer implements DtoTransformer { - @Override - public Class getInputType() { - return ContractNegotiation.class; - } - - @Override - public Class getOutputType() { - return ContractNegotiationDto.class; - } - - @Override - public @Nullable ContractNegotiationDto transform(@NotNull ContractNegotiation object, @NotNull TransformerContext context) { - return ContractNegotiationDto.Builder.newInstance() - .id(object.getId()) - .type(object.getType()) - .contractAgreementId(ofNullable(object.getContractAgreement()).map(ContractAgreement::getId).orElse(null)) - .state(ContractNegotiationStates.from(object.getState()).name()) - .protocol(object.getProtocol()) - .counterPartyAddress(object.getCounterPartyAddress()) - .errorDetail(object.getErrorDetail()) - .callbackAddresses(object.getCallbackAddresses()) - .createdAt(object.getCreatedAt()) - .updatedAt(object.getUpdatedAt()) - .build(); - } -} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementDtoTransformer.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementTransformer.java similarity index 57% rename from extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementDtoTransformer.java rename to extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementTransformer.java index 511cd4e9f69..0e7b3118f3f 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementDtoTransformer.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementTransformer.java @@ -16,39 +16,39 @@ import jakarta.json.JsonBuilderFactory; import jakarta.json.JsonObject; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractAgreementDto; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; 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.connector.api.management.contractnegotiation.model.ContractAgreementDto.CONTRACT_AGREEMENT_ASSET_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractAgreementDto.CONTRACT_AGREEMENT_CONSUMER_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractAgreementDto.CONTRACT_AGREEMENT_POLICY; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractAgreementDto.CONTRACT_AGREEMENT_PROVIDER_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractAgreementDto.CONTRACT_AGREEMENT_SIGNING_DATE; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_ASSET_ID; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_CONSUMER_ID; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_POLICY; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_PROVIDER_ID; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_SIGNING_DATE; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_TYPE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; -public class JsonObjectFromContractAgreementDtoTransformer extends AbstractJsonLdTransformer { +public class JsonObjectFromContractAgreementTransformer extends AbstractJsonLdTransformer { private final JsonBuilderFactory jsonFactory; - public JsonObjectFromContractAgreementDtoTransformer(JsonBuilderFactory jsonFactory) { - super(ContractAgreementDto.class, JsonObject.class); + public JsonObjectFromContractAgreementTransformer(JsonBuilderFactory jsonFactory) { + super(ContractAgreement.class, JsonObject.class); this.jsonFactory = jsonFactory; } @Override - public @Nullable JsonObject transform(@NotNull ContractAgreementDto dto, @NotNull TransformerContext context) { - - var bldr = jsonFactory.createObjectBuilder(); - bldr.add(TYPE, ContractAgreementDto.TYPE) + public @Nullable JsonObject transform(@NotNull ContractAgreement dto, @NotNull TransformerContext context) { + return jsonFactory.createObjectBuilder() + .add(TYPE, CONTRACT_AGREEMENT_TYPE) .add(ID, dto.getId()) .add(CONTRACT_AGREEMENT_ASSET_ID, dto.getAssetId()) .add(CONTRACT_AGREEMENT_POLICY, context.transform(dto.getPolicy(), JsonObject.class)) .add(CONTRACT_AGREEMENT_SIGNING_DATE, dto.getContractSigningDate()) .add(CONTRACT_AGREEMENT_CONSUMER_ID, dto.getConsumerId()) - .add(CONTRACT_AGREEMENT_PROVIDER_ID, dto.getProviderId()); - return bldr.build(); + .add(CONTRACT_AGREEMENT_PROVIDER_ID, dto.getProviderId()) + .build(); } } diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractNegotiationDtoTransformer.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractNegotiationDtoTransformer.java deleted file mode 100644 index 7f047d1bc38..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractNegotiationDtoTransformer.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; - -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonBuilderFactory; -import jakarta.json.JsonObject; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto; -import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; -import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -import static java.util.Optional.ofNullable; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto.CONTRACT_NEGOTIATION_AGREEMENT_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto.CONTRACT_NEGOTIATION_CALLBACK_ADDR; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto.CONTRACT_NEGOTIATION_COUNTERPARTY_ADDR; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto.CONTRACT_NEGOTIATION_ERRORDETAIL; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto.CONTRACT_NEGOTIATION_NEG_TYPE; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto.CONTRACT_NEGOTIATION_PROTOCOL; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto.CONTRACT_NEGOTIATION_STATE; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto.CONTRACT_NEGOTIATION_TYPE; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; - -public class JsonObjectFromContractNegotiationDtoTransformer extends AbstractJsonLdTransformer { - - private final JsonBuilderFactory jsonFactory; - - public JsonObjectFromContractNegotiationDtoTransformer(JsonBuilderFactory jsonFactory) { - super(ContractNegotiationDto.class, JsonObject.class); - this.jsonFactory = jsonFactory; - } - - @Override - public @Nullable JsonObject transform(@NotNull ContractNegotiationDto dto, @NotNull TransformerContext context) { - var builder = jsonFactory.createObjectBuilder(); - builder.add(TYPE, CONTRACT_NEGOTIATION_TYPE) - .add(ID, dto.getId()) - .add(CONTRACT_NEGOTIATION_NEG_TYPE, dto.getType().toString()) - .add(CONTRACT_NEGOTIATION_PROTOCOL, dto.getProtocol()) - .add(CONTRACT_NEGOTIATION_STATE, dto.getState()) - .add(CONTRACT_NEGOTIATION_COUNTERPARTY_ADDR, dto.getCounterPartyAddress()) - .add(CONTRACT_NEGOTIATION_CALLBACK_ADDR, asArray(dto.getCallbackAddresses(), context)); - ofNullable(dto.getContractAgreementId()).ifPresent(s -> builder.add(CONTRACT_NEGOTIATION_AGREEMENT_ID, s)); - ofNullable(dto.getErrorDetail()).ifPresent(s -> builder.add(CONTRACT_NEGOTIATION_ERRORDETAIL, s)); - - - return builder.build(); - } - - private JsonArrayBuilder asArray(List callbackAddresses, TransformerContext context) { - var bldr = jsonFactory.createArrayBuilder(); - callbackAddresses.stream() - .map(cba -> context.transform(cba, JsonObject.class)) - .forEach(bldr::add); - - return bldr; - } -} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractNegotiationTransformer.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractNegotiationTransformer.java new file mode 100644 index 00000000000..b8b3021b0d7 --- /dev/null +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractNegotiationTransformer.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +package org.eclipse.edc.connector.api.management.contractnegotiation.transform; + +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates; +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 jakarta.json.stream.JsonCollectors.toJsonArray; +import static java.util.Optional.ofNullable; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_AGREEMENT_ID; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_CALLBACK_ADDR; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_COUNTERPARTY_ADDR; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_COUNTERPARTY_ID; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_CREATED_AT; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_ERRORDETAIL; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_NEG_TYPE; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_PROTOCOL; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_STATE; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; + +public class JsonObjectFromContractNegotiationTransformer extends AbstractJsonLdTransformer { + + private final JsonBuilderFactory jsonFactory; + + public JsonObjectFromContractNegotiationTransformer(JsonBuilderFactory jsonFactory) { + super(ContractNegotiation.class, JsonObject.class); + this.jsonFactory = jsonFactory; + } + + @Override + public @Nullable JsonObject transform(@NotNull ContractNegotiation contractNegotiation, @NotNull TransformerContext context) { + var builder = jsonFactory.createObjectBuilder(); + + var callbackAddresses = contractNegotiation.getCallbackAddresses().stream() + .map(callbackAddress -> context.transform(callbackAddress, JsonObject.class)) + .collect(toJsonArray()); + + builder.add(TYPE, CONTRACT_NEGOTIATION_TYPE) + .add(ID, contractNegotiation.getId()) + .add(CONTRACT_NEGOTIATION_NEG_TYPE, contractNegotiation.getType().toString()) + .add(CONTRACT_NEGOTIATION_PROTOCOL, contractNegotiation.getProtocol()) + .add(CONTRACT_NEGOTIATION_STATE, ContractNegotiationStates.from(contractNegotiation.getState()).name()) + .add(CONTRACT_NEGOTIATION_COUNTERPARTY_ID, contractNegotiation.getCounterPartyId()) + .add(CONTRACT_NEGOTIATION_COUNTERPARTY_ADDR, contractNegotiation.getCounterPartyAddress()) + .add(CONTRACT_NEGOTIATION_CALLBACK_ADDR, callbackAddresses) + .add(CONTRACT_NEGOTIATION_CREATED_AT, contractNegotiation.getCreatedAt()); + + ofNullable(contractNegotiation.getContractAgreement()).map(ContractAgreement::getId).ifPresent(s -> builder.add(CONTRACT_NEGOTIATION_AGREEMENT_ID, s)); + ofNullable(contractNegotiation.getErrorDetail()).ifPresent(s -> builder.add(CONTRACT_NEGOTIATION_ERRORDETAIL, s)); + + return builder.build(); + } + +} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToContractRequestTransformer.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToContractRequestTransformer.java new file mode 100644 index 00000000000..e17f086aa15 --- /dev/null +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToContractRequestTransformer.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +package org.eclipse.edc.connector.api.management.contractnegotiation.transform; + +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest; +import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer; +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; +import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; + +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.CALLBACK_ADDRESSES; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.CONNECTOR_ADDRESS; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.CONNECTOR_ID; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.OFFER; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.PROTOCOL; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.PROVIDER_ID; + +public class JsonObjectToContractRequestTransformer extends AbstractJsonLdTransformer { + + public JsonObjectToContractRequestTransformer() { + super(JsonObject.class, ContractRequest.class); + } + + @Override + public @Nullable ContractRequest transform(@NotNull JsonObject jsonObject, @NotNull TransformerContext context) { + var contractRequestBuilder = ContractRequest.Builder.newInstance() + .providerId(getProviderId(jsonObject, context)) + .counterPartyAddress(transformString(jsonObject.get(CONNECTOR_ADDRESS), context)) + .protocol(transformString(jsonObject.get(PROTOCOL), context)); + + var contractOfferDescription = transformObject(jsonObject.get(OFFER), ContractOfferDescription.class, context); + var contractOffer = ContractOffer.Builder.newInstance() + .id(contractOfferDescription.getOfferId()) + .assetId(contractOfferDescription.getAssetId()) + .policy(contractOfferDescription.getPolicy()) + .build(); + contractRequestBuilder.contractOffer(contractOffer); + + var callbackAddress = jsonObject.get(CALLBACK_ADDRESSES); + if (callbackAddress != null) { + var addresses = new ArrayList(); + transformArrayOrObject(callbackAddress, CallbackAddress.class, addresses::add, context); + contractRequestBuilder.callbackAddresses(addresses); + } + + return contractRequestBuilder.build(); + } + + private String getProviderId(@NotNull JsonObject jsonObject, @NotNull TransformerContext context) { + var providerId = jsonObject.get(PROVIDER_ID); + if (providerId != null) { + return transformString(providerId, context); + } + + var connectorId = jsonObject.get(CONNECTOR_ID); + if (connectorId != null) { + return transformString(connectorId, context); + } + + return transformString(jsonObject.get(CONNECTOR_ADDRESS), context); + + } + +} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToNegotiationInitiateRequestDtoTransformer.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToNegotiationInitiateRequestDtoTransformer.java deleted file mode 100644 index 2c40e740c8b..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToNegotiationInitiateRequestDtoTransformer.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; - -import jakarta.json.JsonObject; -import jakarta.json.JsonValue; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto; -import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; -import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; - -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.CALLBACK_ADDRESSES; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.CONNECTOR_ADDRESS; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.CONNECTOR_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.CONSUMER_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.OFFER; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.PROTOCOL; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.PROVIDER_ID; - -public class JsonObjectToNegotiationInitiateRequestDtoTransformer extends AbstractJsonLdTransformer { - - public JsonObjectToNegotiationInitiateRequestDtoTransformer() { - super(JsonObject.class, NegotiationInitiateRequestDto.class); - } - - @Override - public @Nullable NegotiationInitiateRequestDto transform(@NotNull JsonObject jsonObject, @NotNull TransformerContext context) { - var builder = NegotiationInitiateRequestDto.Builder.newInstance(); - - visitProperties(jsonObject, (k, v) -> setProperties(k, v, builder, context)); - return builder.build(); - } - - private void setProperties(String key, JsonValue value, NegotiationInitiateRequestDto.Builder builder, TransformerContext context) { - - switch (key) { - case CONNECTOR_ADDRESS: - transformString(value, builder::connectorAddress, context); - break; - case PROTOCOL: - transformString(value, builder::protocol, context); - break; - case CONNECTOR_ID: - transformString(value, builder::connectorId, context); - break; - case PROVIDER_ID: - transformString(value, builder::providerId, context); - break; - case CONSUMER_ID: - transformString(value, builder::consumerId, context); - break; - case CALLBACK_ADDRESSES: - var addresses = new ArrayList(); - transformArrayOrObject(value, CallbackAddress.class, addresses::add, context); - builder.callbackAddresses(addresses); - break; - case OFFER: - transformArrayOrObject(value, ContractOfferDescription.class, builder::offer, context); - break; - default: - context.problem() - .unexpectedType() - .type(NegotiationInitiateRequestDto.TYPE) - .property(key) - .actual(key) - .expected(CONNECTOR_ADDRESS) - .expected(PROTOCOL) - .expected(CONNECTOR_ID) - .expected(PROVIDER_ID) - .expected(CONSUMER_ID) - .expected(CALLBACK_ADDRESSES) - .expected(OFFER) - .report(); - break; - } - } -} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/NegotiationInitiateRequestDtoToDataRequestTransformer.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/NegotiationInitiateRequestDtoToDataRequestTransformer.java deleted file mode 100644 index 12b8fb12c2c..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/NegotiationInitiateRequestDtoToDataRequestTransformer.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; - -import org.eclipse.edc.api.transformer.DtoTransformer; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto; -import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest; -import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequestData; -import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.time.Clock; - -public class NegotiationInitiateRequestDtoToDataRequestTransformer implements DtoTransformer { - - private final Clock clock; - - /** - * Instantiates the NegotiationInitiateRequestDtoToDataRequestTransformer. - *

- * If the {@link NegotiationInitiateRequestDto#getConsumerId()} is null, the default consumer ID is used. - * IF the {@link NegotiationInitiateRequestDto#getProviderId()} is null, the connector address is used instead - * - * @param clock the time base for the contract offer transformation - */ - public NegotiationInitiateRequestDtoToDataRequestTransformer(Clock clock) { - this.clock = clock; - } - - @Override - public Class getInputType() { - return NegotiationInitiateRequestDto.class; - } - - @Override - public Class getOutputType() { - return ContractRequest.class; - } - - @Override - public @Nullable ContractRequest transform(@NotNull NegotiationInitiateRequestDto object, @NotNull TransformerContext context) { - // TODO: ContractOfferRequest should contain only the contractOfferId and the contract offer should be retrieved from the catalog. Ref #985 - var contractOffer = ContractOffer.Builder.newInstance() - .id(object.getOffer().getOfferId()) - .assetId(object.getOffer().getAssetId()) - .providerId(getId(object.getProviderId(), object.getConnectorAddress())) - .policy(object.getOffer().getPolicy()) - .build(); - - var requestData = ContractRequestData.Builder.newInstance() - .connectorId(object.getConnectorId()) - .counterPartyAddress(object.getConnectorAddress()) - .protocol(object.getProtocol()) - .contractOffer(contractOffer) - .build(); - - return ContractRequest.Builder.newInstance() - .requestData(requestData) - .callbackAddresses(object.getCallbackAddresses()) - .build(); - } - - private String getId(String value, String defaultValue) { - return value != null ? value : defaultValue; - } -} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/NegotiationInitiateRequestDtoValidator.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/ContractRequestValidator.java similarity index 73% rename from extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/NegotiationInitiateRequestDtoValidator.java rename to extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/ContractRequestValidator.java index d70582d8114..db1da5fdcb2 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/NegotiationInitiateRequestDtoValidator.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/ContractRequestValidator.java @@ -23,17 +23,15 @@ import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription.ASSET_ID; import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription.OFFER_ID; import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription.POLICY; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.CONNECTOR_ADDRESS; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.CONNECTOR_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.OFFER; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.PROTOCOL; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.CONNECTOR_ADDRESS; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.OFFER; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.PROTOCOL; -public class NegotiationInitiateRequestDtoValidator { +public class ContractRequestValidator { public static Validator instance() { return JsonObjectValidator.newValidator() .verify(CONNECTOR_ADDRESS, MandatoryValue::new) .verify(PROTOCOL, MandatoryValue::new) - .verify(CONNECTOR_ID, MandatoryValue::new) .verify(OFFER, MandatoryObject::new) .verifyObject(OFFER, v -> v .verify(OFFER_ID, MandatoryValue::new) diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiControllerTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiControllerTest.java index d0566edd925..b6c4fe1f5aa 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiControllerTest.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiControllerTest.java @@ -20,15 +20,10 @@ import jakarta.json.JsonObject; import org.eclipse.edc.api.model.IdResponseDto; import org.eclipse.edc.api.model.QuerySpecDto; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractAgreementDto; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto; import org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationState; import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; -import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest; -import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequestData; import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer; import org.eclipse.edc.connector.spi.contractnegotiation.ContractNegotiationService; import org.eclipse.edc.junit.annotations.ApiTest; @@ -83,9 +78,7 @@ void getAll() { ))); var responseBody = createObjectBuilder().add(ID, "cn").build(); - when(transformerRegistry.transform(any(ContractNegotiation.class), eq(ContractNegotiationDto.class))) - .thenReturn(Result.success(createContractNegotiationDto().build())); - when(transformerRegistry.transform(any(ContractNegotiationDto.class), eq(JsonObject.class))) + when(transformerRegistry.transform(any(ContractNegotiation.class), eq(JsonObject.class))) .thenReturn(Result.success(responseBody)); baseRequest() @@ -98,8 +91,7 @@ void getAll() { verifyNoInteractions(validatorRegistry); verify(service).query(any(QuerySpec.class)); - verify(transformerRegistry, times(2)).transform(any(ContractNegotiation.class), eq(ContractNegotiationDto.class)); - verify(transformerRegistry, times(2)).transform(any(ContractNegotiationDto.class), eq(JsonObject.class)); + verify(transformerRegistry, times(2)).transform(any(ContractNegotiation.class), eq(JsonObject.class)); } @Test @@ -148,7 +140,7 @@ void getAll_dtoTransformationFails() { createContractNegotiation("cn1"), createContractNegotiation("cn2") ))); - when(transformerRegistry.transform(any(ContractNegotiation.class), eq(ContractNegotiationDto.class))) + when(transformerRegistry.transform(any(ContractNegotiation.class), any())) .thenReturn(Result.failure("test-failure")); baseRequest() @@ -159,9 +151,7 @@ void getAll_dtoTransformationFails() { .contentType(JSON) .body("size()", is(0)); - verify(transformerRegistry, times(2)).transform(any(ContractNegotiation.class), eq(ContractNegotiationDto.class)); verify(service).query(any(QuerySpec.class)); - verifyNoMoreInteractions(transformerRegistry); } @Test @@ -170,9 +160,7 @@ void getAll_singleFailure_shouldLogError() { createContractNegotiation("cn1"), createContractNegotiation("cn2") ))); - when(transformerRegistry.transform(any(ContractNegotiation.class), eq(ContractNegotiationDto.class))) - .thenReturn(Result.success(createContractNegotiationDto().build())); - when(transformerRegistry.transform(any(ContractNegotiationDto.class), eq(JsonObject.class))) + when(transformerRegistry.transform(any(ContractNegotiation.class), eq(JsonObject.class))) .thenReturn(Result.success(createObjectBuilder().build())) .thenReturn(Result.failure("test-failure")); @@ -185,8 +173,7 @@ void getAll_singleFailure_shouldLogError() { .body("size()", is(1)); verify(service).query(any(QuerySpec.class)); - verify(transformerRegistry, times(2)).transform(any(ContractNegotiation.class), eq(ContractNegotiationDto.class)); - verify(transformerRegistry, times(2)).transform(any(ContractNegotiationDto.class), eq(JsonObject.class)); + verify(transformerRegistry, times(2)).transform(any(ContractNegotiation.class), eq(JsonObject.class)); verify(monitor).warning(contains("test-failure")); } @@ -199,9 +186,7 @@ void getAll_jsonObjectTransformationFails() { ))); when(transformerRegistry.transform(any(JsonObject.class), eq(QuerySpecDto.class))).thenReturn(Result.success(QuerySpecDto.Builder.newInstance().build())); when(transformerRegistry.transform(any(QuerySpecDto.class), eq(QuerySpec.class))).thenReturn(Result.success(QuerySpec.none())); - when(transformerRegistry.transform(any(ContractNegotiation.class), eq(ContractNegotiationDto.class))) - .thenReturn(Result.success(createContractNegotiationDto().build())); - when(transformerRegistry.transform(any(ContractNegotiationDto.class), eq(JsonObject.class))) + when(transformerRegistry.transform(any(ContractNegotiation.class), eq(JsonObject.class))) .thenReturn(Result.failure("test-failure")); var requestBody = createObjectBuilder().build(); @@ -217,16 +202,13 @@ void getAll_jsonObjectTransformationFails() { verify(service).query(any(QuerySpec.class)); verify(transformerRegistry).transform(any(JsonObject.class), eq(QuerySpecDto.class)); verify(transformerRegistry).transform(any(QuerySpecDto.class), eq(QuerySpec.class)); - verify(transformerRegistry, times(2)).transform(any(ContractNegotiation.class), eq(ContractNegotiationDto.class)); - verify(transformerRegistry, times(2)).transform(any(ContractNegotiationDto.class), eq(JsonObject.class)); + verify(transformerRegistry, times(2)).transform(any(ContractNegotiation.class), eq(JsonObject.class)); } @Test void getById() { when(service.findbyId(anyString())).thenReturn(createContractNegotiation("cn1")); - when(transformerRegistry.transform(any(ContractNegotiation.class), eq(ContractNegotiationDto.class))) - .thenReturn(Result.success(createContractNegotiationDto().build())); - when(transformerRegistry.transform(any(ContractNegotiationDto.class), eq(JsonObject.class))) + when(transformerRegistry.transform(any(ContractNegotiation.class), eq(JsonObject.class))) .thenReturn(Result.success(createObjectBuilder().build())); baseRequest() @@ -237,8 +219,7 @@ void getById() { .body(notNullValue()); verify(service).findbyId(anyString()); - verify(transformerRegistry).transform(any(ContractNegotiation.class), eq(ContractNegotiationDto.class)); - verify(transformerRegistry).transform(any(ContractNegotiationDto.class), eq(JsonObject.class)); + verify(transformerRegistry).transform(any(ContractNegotiation.class), eq(JsonObject.class)); } @Test @@ -259,25 +240,22 @@ void getById_notFound() { @Test void getById_transformationFails() { when(service.findbyId(eq("cn1"))).thenReturn(createContractNegotiation("cn1")); - when(transformerRegistry.transform(any(ContractNegotiation.class), eq(ContractNegotiationDto.class))) - .thenReturn(Result.success(createContractNegotiationDto().build())); - when(transformerRegistry.transform(any(ContractNegotiationDto.class), eq(JsonObject.class))) + when(transformerRegistry.transform(any(ContractNegotiation.class), eq(JsonObject.class))) .thenReturn(Result.failure("test-failure")); baseRequest() .get("/cn1") .then() - .statusCode(400) + .statusCode(404) .contentType(JSON) .body(notNullValue()); verify(service).findbyId(anyString()); - verify(transformerRegistry).transform(any(ContractNegotiation.class), eq(ContractNegotiationDto.class)); - verify(transformerRegistry).transform(any(ContractNegotiationDto.class), eq(JsonObject.class)); + verify(transformerRegistry).transform(any(ContractNegotiation.class), eq(JsonObject.class)); } @Test - void getSingleContractNegotationState() { + void getSingleContractNegotiationState() { var compacted = createObjectBuilder() .add(TYPE, NEGOTIATION_STATE_TYPE) .add("edc:state", "REQUESTED") @@ -299,11 +277,9 @@ void getSingleContractNegotationState() { } @Test - void getSingleContractNegotationAgreement() { + void getSingleContractNegotiationAgreement() { when(service.getForNegotiation(eq("cn1"))).thenReturn(createContractAgreement("cn1")); - when(transformerRegistry.transform(any(ContractAgreement.class), eq(ContractAgreementDto.class))) - .thenReturn(Result.success(ContractAgreementDto.Builder.newInstance().build())); - when(transformerRegistry.transform(any(ContractAgreementDto.class), eq(JsonObject.class))) + when(transformerRegistry.transform(any(ContractAgreement.class), eq(JsonObject.class))) .thenReturn(Result.success(createObjectBuilder().build())); baseRequest() @@ -314,16 +290,14 @@ void getSingleContractNegotationAgreement() { .body(notNullValue()); verify(service).getForNegotiation(eq("cn1")); - verify(transformerRegistry).transform(any(ContractAgreement.class), eq(ContractAgreementDto.class)); - verify(transformerRegistry).transform(any(ContractAgreementDto.class), eq(JsonObject.class)); + verify(transformerRegistry).transform(any(ContractAgreement.class), eq(JsonObject.class)); verifyNoMoreInteractions(transformerRegistry, service); } @Test - void getSingleContractNegotationAgreement_transformationFails() { - + void getSingleContractNegotiationAgreement_transformationFails() { when(service.getForNegotiation(eq("cn1"))).thenReturn(createContractAgreement("cn1")); - when(transformerRegistry.transform(any(ContractAgreement.class), eq(ContractAgreementDto.class))) + when(transformerRegistry.transform(any(ContractAgreement.class), eq(JsonObject.class))) .thenReturn(Result.failure("test-failure")); baseRequest() @@ -332,12 +306,12 @@ void getSingleContractNegotationAgreement_transformationFails() { .statusCode(500); verify(service).getForNegotiation(eq("cn1")); - verify(transformerRegistry).transform(any(ContractAgreement.class), eq(ContractAgreementDto.class)); + verify(transformerRegistry).transform(any(ContractAgreement.class), eq(JsonObject.class)); verifyNoMoreInteractions(transformerRegistry, service); } @Test - void getSingleContractNegotationAgreement_whenNoneFound() { + void getSingleContractNegotiationAgreement_whenNoneFound() { when(service.getForNegotiation(eq("cn1"))).thenReturn(null); baseRequest() @@ -357,17 +331,15 @@ void initiate() { var contractNegotiation = createContractNegotiation("cn1"); var responseBody = createObjectBuilder().add(TYPE, EDC_ID_RESPONSE_DTO_TYPE).add(ID, contractNegotiation.getId()).build(); - when(transformerRegistry.transform(any(JsonObject.class), eq(NegotiationInitiateRequestDto.class))).thenReturn(Result.success(NegotiationInitiateRequestDto.Builder.newInstance().build())); - when(transformerRegistry.transform(any(NegotiationInitiateRequestDto.class), eq(ContractRequest.class))).thenReturn(Result.success( + when(transformerRegistry.transform(any(JsonObject.class), eq(ContractRequest.class))).thenReturn(Result.success( ContractRequest.Builder.newInstance() - .requestData(ContractRequestData.Builder.newInstance() - .protocol("test-protocol") - .counterPartyAddress("test-cb") - .contractOffer(ContractOffer.Builder.newInstance() - .id("test-offer-id") - .assetId(randomUUID().toString()) - .policy(Policy.Builder.newInstance().build()) - .build()) + .protocol("test-protocol") + .providerId("test-provider-id") + .counterPartyAddress("test-cb") + .contractOffer(ContractOffer.Builder.newInstance() + .id("test-offer-id") + .assetId(randomUUID().toString()) + .policy(Policy.Builder.newInstance().build()) .build()) .build())); @@ -385,8 +357,7 @@ void initiate() { .body(ID, is(contractNegotiation.getId())); verify(service).initiateNegotiation(any()); - verify(transformerRegistry).transform(any(JsonObject.class), eq(NegotiationInitiateRequestDto.class)); - verify(transformerRegistry).transform(any(NegotiationInitiateRequestDto.class), eq(ContractRequest.class)); + verify(transformerRegistry).transform(any(JsonObject.class), eq(ContractRequest.class)); verify(transformerRegistry).transform(any(IdResponseDto.class), eq(JsonObject.class)); verifyNoMoreInteractions(transformerRegistry, service); } @@ -402,14 +373,14 @@ void initiate_shouldReturnBadRequest_whenValidationFails() { .then() .statusCode(400); - verify(validatorRegistry).validate(eq(NegotiationInitiateRequestDto.TYPE), any()); + verify(validatorRegistry).validate(eq(ContractRequest.CONTRACT_REQUEST_TYPE), any()); verifyNoInteractions(transformerRegistry, service); } @Test void initiate_invalidRequest() { when(validatorRegistry.validate(any(), any())).thenReturn(ValidationResult.success()); - when(transformerRegistry.transform(any(JsonObject.class), eq(NegotiationInitiateRequestDto.class))).thenReturn(Result.failure("test-failure")); + when(transformerRegistry.transform(any(JsonObject.class), any())).thenReturn(Result.failure("test-failure")); baseRequest() .contentType(JSON) @@ -417,11 +388,9 @@ void initiate_invalidRequest() { .post() .then() .statusCode(400); - verify(transformerRegistry).transform(any(JsonObject.class), eq(NegotiationInitiateRequestDto.class)); - verifyNoMoreInteractions(transformerRegistry, service); + verifyNoMoreInteractions(service); } - @Test void cancel() { when(service.cancel(eq("cn1"))).thenReturn(ServiceResult.success(createContractNegotiation("cn1"))); @@ -539,15 +508,4 @@ private ContractNegotiation.Builder createContractNegotiationBuilder(String nego .protocol("protocol"); } - private ContractNegotiationDto.Builder createContractNegotiationDto() { - return ContractNegotiationDto.Builder.newInstance() - .id("test-id") - .contractAgreementId("agreement-id") - .counterPartyAddress("test-counterparty") - .type(ContractNegotiation.Type.PROVIDER) - .protocol("test-protocol") - .callbackAddresses(List.of(new CallbackAddress())) - .state(ContractNegotiationStates.INITIAL.toString()); - - } } diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtensionTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtensionTest.java index 023472e53f6..8165dfe361c 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtensionTest.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtensionTest.java @@ -14,7 +14,7 @@ package org.eclipse.edc.connector.api.management.contractnegotiation; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest; import org.eclipse.edc.junit.extensions.DependencyInjectionExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; @@ -41,6 +41,6 @@ void setUp(ServiceExtensionContext context) { void initiate_shouldRegisterValidator(ServiceExtensionContext context, ContractNegotiationApiExtension extension) { extension.initialize(context); - verify(validatorRegistry).register(eq(NegotiationInitiateRequestDto.TYPE), any()); + verify(validatorRegistry).register(eq(ContractRequest.CONTRACT_REQUEST_TYPE), any()); } } diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiTest.java new file mode 100644 index 00000000000..6b54f79459b --- /dev/null +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiTest.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +package org.eclipse.edc.connector.api.management.contractnegotiation; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.json.JsonObject; +import org.eclipse.edc.api.transformer.JsonObjectToCallbackAddressTransformer; +import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectToContractOfferDescriptionTransformer; +import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectToContractRequestTransformer; +import org.eclipse.edc.connector.api.management.contractnegotiation.validation.ContractRequestValidator; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest; +import org.eclipse.edc.core.transform.TypeTransformerRegistryImpl; +import org.eclipse.edc.core.transform.transformer.OdrlTransformersFactory; +import org.eclipse.edc.jsonld.JsonLdExtension; +import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.util.JacksonJsonLd; +import org.eclipse.edc.transform.spi.TypeTransformerRegistry; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.eclipse.edc.connector.api.management.contractnegotiation.ContractNegotiationApi.ContractAgreementSchema.CONTRACT_AGREEMENT_EXAMPLE; +import static org.eclipse.edc.connector.api.management.contractnegotiation.ContractNegotiationApi.ContractNegotiationSchema.CONTRACT_NEGOTIATION_EXAMPLE; +import static org.eclipse.edc.connector.api.management.contractnegotiation.ContractNegotiationApi.ContractRequestSchema.CONTRACT_REQUEST_EXAMPLE; +import static org.eclipse.edc.connector.api.management.contractnegotiation.ContractNegotiationApi.NegotiationStateSchema.NEGOTIATION_STATE_EXAMPLE; +import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationState.NEGOTIATION_STATE_STATE; +import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationState.NEGOTIATION_STATE_TYPE; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_ASSET_ID; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_CONSUMER_ID; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_POLICY; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_PROVIDER_ID; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_SIGNING_DATE; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_TYPE; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_AGREEMENT_ID; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_CALLBACK_ADDR; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_COUNTERPARTY_ADDR; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_COUNTERPARTY_ID; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_CREATED_AT; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_ERRORDETAIL; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_NEG_TYPE; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_PROTOCOL; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_STATE; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; +import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; +import static org.eclipse.edc.junit.extensions.TestServiceExtensionContext.testServiceExtensionContext; + +class ContractNegotiationApiTest { + + private final ObjectMapper objectMapper = JacksonJsonLd.createObjectMapper(); + private final JsonLd jsonLd = new JsonLdExtension().createJsonLdService(testServiceExtensionContext()); + private final TypeTransformerRegistry transformer = new TypeTransformerRegistryImpl(); + + @BeforeEach + void setUp() { + transformer.register(new JsonObjectToContractRequestTransformer()); + transformer.register(new JsonObjectToContractOfferDescriptionTransformer()); + transformer.register(new JsonObjectToCallbackAddressTransformer()); + OdrlTransformersFactory.jsonObjectToOdrlTransformers().forEach(transformer::register); + } + + @Test + void contractRequestExample() throws JsonProcessingException { + var validator = ContractRequestValidator.instance(); + + var jsonObject = objectMapper.readValue(CONTRACT_REQUEST_EXAMPLE, JsonObject.class); + assertThat(jsonObject).isNotNull(); + + var expanded = jsonLd.expand(jsonObject); + assertThat(expanded).isSucceeded() + .satisfies(exp -> assertThat(validator.validate(exp)).isSucceeded()) + .extracting(e -> transformer.transform(e, ContractRequest.class)) + .satisfies(transformResult -> assertThat(transformResult).isSucceeded() + .satisfies(transformed -> { + assertThat(transformed.getProviderId()).isNotBlank(); + })); + } + + @Test + void contractNegotiationExample() throws JsonProcessingException { + var jsonObject = objectMapper.readValue(CONTRACT_NEGOTIATION_EXAMPLE, JsonObject.class); + var expanded = jsonLd.expand(jsonObject); + + assertThat(expanded).isSucceeded().satisfies(content -> { + assertThat(content.getString(ID)).isNotBlank(); + assertThat(content.getJsonArray(TYPE).getString(0)).isEqualTo(CONTRACT_NEGOTIATION_TYPE); + assertThat(content.getJsonArray(CONTRACT_NEGOTIATION_CREATED_AT).getJsonObject(0).getJsonNumber(VALUE).longValue()).isGreaterThan(0); + assertThat(content.getJsonArray(CONTRACT_NEGOTIATION_NEG_TYPE).getJsonObject(0).getString(VALUE)).isNotBlank(); + assertThat(content.getJsonArray(CONTRACT_NEGOTIATION_PROTOCOL).getJsonObject(0).getString(VALUE)).isNotBlank(); + assertThat(content.getJsonArray(CONTRACT_NEGOTIATION_COUNTERPARTY_ID).getJsonObject(0).getString(VALUE)).isNotBlank(); + assertThat(content.getJsonArray(CONTRACT_NEGOTIATION_COUNTERPARTY_ADDR).getJsonObject(0).getString(VALUE)).isNotBlank(); + assertThat(content.getJsonArray(CONTRACT_NEGOTIATION_STATE).getJsonObject(0).getString(VALUE)).isNotBlank(); + assertThat(content.getJsonArray(CONTRACT_NEGOTIATION_AGREEMENT_ID).getJsonObject(0).getString(VALUE)).isNotBlank(); + assertThat(content.getJsonArray(CONTRACT_NEGOTIATION_ERRORDETAIL).getJsonObject(0).getString(VALUE)).isNotBlank(); + assertThat(content.getJsonArray(CONTRACT_NEGOTIATION_CALLBACK_ADDR)).asList().isNotEmpty(); + }); + } + + @Test + void contractAgreementExample() throws JsonProcessingException { + var jsonObject = objectMapper.readValue(CONTRACT_AGREEMENT_EXAMPLE, JsonObject.class); + var expanded = jsonLd.expand(jsonObject); + + assertThat(expanded).isSucceeded().satisfies(content -> { + assertThat(content.getString(ID)).isNotBlank(); + assertThat(content.getJsonArray(TYPE).getString(0)).isEqualTo(CONTRACT_AGREEMENT_TYPE); + assertThat(content.getJsonArray(CONTRACT_AGREEMENT_ASSET_ID).getJsonObject(0).getString(VALUE)).isNotBlank(); + assertThat(content.getJsonArray(CONTRACT_AGREEMENT_PROVIDER_ID).getJsonObject(0).getString(VALUE)).isNotBlank(); + assertThat(content.getJsonArray(CONTRACT_AGREEMENT_CONSUMER_ID).getJsonObject(0).getString(VALUE)).isNotBlank(); + assertThat(content.getJsonArray(CONTRACT_AGREEMENT_SIGNING_DATE).getJsonObject(0).getJsonNumber(VALUE).longValue()).isGreaterThan(0); + assertThat(content.getJsonArray(CONTRACT_AGREEMENT_POLICY).getJsonObject(0)).isNotNull(); + }); + } + + @Test + void negotiationStateExample() throws JsonProcessingException { + var jsonObject = objectMapper.readValue(NEGOTIATION_STATE_EXAMPLE, JsonObject.class); + var expanded = jsonLd.expand(jsonObject); + + assertThat(expanded).isSucceeded().satisfies(content -> { + assertThat(content.getJsonArray(TYPE).getString(0)).isEqualTo(NEGOTIATION_STATE_TYPE); + assertThat(content.getJsonArray(NEGOTIATION_STATE_STATE).getJsonObject(0).getString(VALUE)).isNotBlank(); + }); + } +} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractAgreementDtoTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractAgreementDtoTest.java deleted file mode 100644 index 78356007fb9..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractAgreementDtoTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2020 - 2022 Microsoft Corporation - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Microsoft Corporation - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.model; - -import com.fasterxml.jackson.core.JsonProcessingException; -import org.eclipse.edc.policy.model.Policy; -import org.eclipse.edc.spi.types.TypeManager; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class ContractAgreementDtoTest { - @Test - void verifySerialization() throws JsonProcessingException { - var om = new TypeManager().getMapper(); - var dto = ContractAgreementDto.Builder.newInstance() - .assetId("test-asset-id") - .id("test-id") - .contractSigningDate(5432L) - .providerId("provider") - .consumerId("consumer") - .policy(Policy.Builder.newInstance().build()) - .build(); - - var json = om.writeValueAsString(dto); - assertThat(json).isNotNull(); - - var deserialized = om.readValue(json, ContractAgreementDto.class); - assertThat(deserialized).usingRecursiveComparison().isEqualTo(dto); - - } -} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractNegotiationDtoTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractNegotiationDtoTest.java deleted file mode 100644 index fb8a8184469..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/model/ContractNegotiationDtoTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022 ZF Friedrichshafen AG - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * ZF Friedrichshafen AG - Initial API and Implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.model; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.Type; -import org.eclipse.edc.spi.types.TypeManager; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class ContractNegotiationDtoTest { - - private ObjectMapper objectMapper; - - @BeforeEach - void setUp() { - objectMapper = new TypeManager().getMapper(); - } - - @Test - void verifySerialization() throws JsonProcessingException { - var dto = ContractNegotiationDto.Builder.newInstance() - .contractAgreementId("test-contract-agreement-id") - .counterPartyAddress("test-counter-party-address") - .errorDetail("test-error-detail") - .id("test-id") - .protocol("test-protocol") - .state("test-state") - .type(Type.PROVIDER) - .build(); - - var str = objectMapper.writeValueAsString(dto); - - assertThat(str).isNotNull(); - - var deserialized = objectMapper.readValue(str, ContractNegotiationDto.class); - assertThat(deserialized).usingRecursiveComparison().isEqualTo(dto); - } -} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/ContractAgreementToContractAgreementDtoTransformerTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/ContractAgreementToContractAgreementDtoTransformerTest.java deleted file mode 100644 index d8764736d47..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/ContractAgreementToContractAgreementDtoTransformerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; - -import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; -import org.eclipse.edc.policy.model.Policy; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -class ContractAgreementToContractAgreementDtoTransformerTest { - - private final ContractAgreementToContractAgreementDtoTransformer transformer = new ContractAgreementToContractAgreementDtoTransformer(); - - @Test - void inputOutputType() { - assertThat(transformer.getInputType()).isNotNull(); - assertThat(transformer.getOutputType()).isNotNull(); - } - - @Test - void transform() { - var context = mock(TransformerContext.class); - var policy = Policy.Builder.newInstance().build(); - var contractAgreement = ContractAgreement.Builder.newInstance() - .id("agreementId") - .consumerId("consumerId") - .providerId("providerId") - .assetId("assetId") - .policy(policy) - .contractSigningDate(2) - .build(); - - var dto = transformer.transform(contractAgreement, context); - - assertThat(dto.getId()).isEqualTo("agreementId"); - assertThat(dto.getAssetId()).isEqualTo("assetId"); - assertThat(dto.getPolicy()).isEqualTo(policy); - assertThat(dto.getContractSigningDate()).isEqualTo(2); - assertThat(dto.getConsumerId()).isEqualTo("consumerId"); - assertThat(dto.getProviderId()).isEqualTo("providerId"); - } - -} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/ContractNegotiationToContractNegotiationDtoTransformerTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/ContractNegotiationToContractNegotiationDtoTransformerTest.java deleted file mode 100644 index ad463168ba0..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/ContractNegotiationToContractNegotiationDtoTransformerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; - -import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; -import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; -import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates; -import org.eclipse.edc.policy.model.Policy; -import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.Type.PROVIDER; -import static org.mockito.Mockito.mock; - -class ContractNegotiationToContractNegotiationDtoTransformerTest { - - private final ContractNegotiationToContractNegotiationDtoTransformer transformer = new ContractNegotiationToContractNegotiationDtoTransformer(); - - @Test - void inputOutputType() { - assertThat(transformer.getInputType()).isNotNull(); - assertThat(transformer.getOutputType()).isNotNull(); - } - - @Test - void transform() { - var context = mock(TransformerContext.class); - var callback = CallbackAddress.Builder.newInstance() - .uri("local://test") - .build(); - var contractNegotiation = ContractNegotiation.Builder.newInstance() - .id("negotiationId") - .type(PROVIDER) - .state(ContractNegotiationStates.INITIAL.code()) - .protocol("protocol") - .counterPartyId("counterPartyId") - .counterPartyAddress("counterPartyAddress") - .contractAgreement(createContractAgreement("agreementId")) - .errorDetail("errorDetail") - .correlationId("correlationId") - .callbackAddresses(List.of(callback)) - .build(); - - var dto = transformer.transform(contractNegotiation, context); - - assertThat(dto.getId()).isEqualTo("negotiationId"); - assertThat(dto.getType()).isEqualTo(PROVIDER); - assertThat(dto.getContractAgreementId()).isEqualTo("agreementId"); - assertThat(dto.getState()).isEqualTo("INITIAL"); - assertThat(dto.getProtocol()).isEqualTo("protocol"); - assertThat(dto.getCounterPartyAddress()).isEqualTo("counterPartyAddress"); - assertThat(dto.getErrorDetail()).isEqualTo("errorDetail"); - assertThat(dto.getUpdatedAt()).isEqualTo(contractNegotiation.getUpdatedAt()); - assertThat(dto.getCreatedAt()).isEqualTo(contractNegotiation.getCreatedAt()); - assertThat(dto.getCallbackAddresses()).usingRecursiveFieldByFieldElementComparator().contains(callback); - } - - private ContractAgreement createContractAgreement(String id) { - return ContractAgreement.Builder.newInstance() - .id(id) - .consumerId("any") - .providerId("any") - .assetId(UUID.randomUUID().toString()) - .policy(Policy.Builder.newInstance().build()) - .build(); - } - -} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementDtoTransformerTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementTransformerTest.java similarity index 52% rename from extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementDtoTransformerTest.java rename to extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementTransformerTest.java index d08b84e7bd1..1611f67bb5e 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementDtoTransformerTest.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementTransformerTest.java @@ -17,6 +17,7 @@ import jakarta.json.Json; import jakarta.json.JsonObject; import jakarta.json.JsonString; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; import org.eclipse.edc.policy.model.Policy; import org.eclipse.edc.transform.spi.TransformerContext; import org.junit.jupiter.api.BeforeEach; @@ -25,28 +26,27 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractAgreementDto.Builder; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractAgreementDto.CONTRACT_AGREEMENT_ASSET_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractAgreementDto.CONTRACT_AGREEMENT_CONSUMER_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractAgreementDto.CONTRACT_AGREEMENT_POLICY; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractAgreementDto.CONTRACT_AGREEMENT_PROVIDER_ID; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_ASSET_ID; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_CONSUMER_ID; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_POLICY; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_PROVIDER_ID; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -class JsonObjectFromContractAgreementDtoTransformerTest { +class JsonObjectFromContractAgreementTransformerTest { - private JsonObjectFromContractAgreementDtoTransformer transformer; + private JsonObjectFromContractAgreementTransformer transformer; @BeforeEach void setUp() { - transformer = new JsonObjectFromContractAgreementDtoTransformer(Json.createBuilderFactory(Map.of())); + transformer = new JsonObjectFromContractAgreementTransformer(Json.createBuilderFactory(Map.of())); } @Test void transform() { - var agreement = Builder.newInstance() + var agreement = ContractAgreement.Builder.newInstance() .id("test-id") .providerId("test-provider") .consumerId("test-consumer") @@ -56,11 +56,12 @@ void transform() { var context = mock(TransformerContext.class); when(context.transform(any(Policy.class), eq(JsonObject.class))).thenReturn(Json.createObjectBuilder().build()); - var jobj = transformer.transform(agreement, context); - assertThat(jobj).isNotNull(); - assertThat(jobj.getJsonString(CONTRACT_AGREEMENT_ASSET_ID)).extracting(JsonString::getString).isEqualTo("test-asset"); - assertThat(jobj.getJsonString(CONTRACT_AGREEMENT_PROVIDER_ID)).extracting(JsonString::getString).isEqualTo("test-provider"); - assertThat(jobj.getJsonString(CONTRACT_AGREEMENT_CONSUMER_ID)).extracting(JsonString::getString).isEqualTo("test-consumer"); - assertThat(jobj.getJsonObject(CONTRACT_AGREEMENT_POLICY)).isNotNull(); + var result = transformer.transform(agreement, context); + + assertThat(result).isNotNull(); + assertThat(result.getJsonString(CONTRACT_AGREEMENT_ASSET_ID)).extracting(JsonString::getString).isEqualTo("test-asset"); + assertThat(result.getJsonString(CONTRACT_AGREEMENT_PROVIDER_ID)).extracting(JsonString::getString).isEqualTo("test-provider"); + assertThat(result.getJsonString(CONTRACT_AGREEMENT_CONSUMER_ID)).extracting(JsonString::getString).isEqualTo("test-consumer"); + assertThat(result.getJsonObject(CONTRACT_AGREEMENT_POLICY)).isNotNull(); } } diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractNegotiationDtoTransformerTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractNegotiationDtoTransformerTest.java deleted file mode 100644 index 8532a6fe22c..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractNegotiationDtoTransformerTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto.Builder; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto.CONTRACT_NEGOTIATION_AGREEMENT_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto.CONTRACT_NEGOTIATION_COUNTERPARTY_ADDR; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto.CONTRACT_NEGOTIATION_NEG_TYPE; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto.CONTRACT_NEGOTIATION_PROTOCOL; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractNegotiationDto.CONTRACT_NEGOTIATION_STATE; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class JsonObjectFromContractNegotiationDtoTransformerTest { - - private JsonObjectFromContractNegotiationDtoTransformer transformer; - private TransformerContext context; - - @BeforeEach - void setUp() { - context = mock(TransformerContext.class); - when(context.transform(any(CallbackAddress.class), eq(JsonObject.class))).thenReturn(Json.createObjectBuilder().build()); - transformer = new JsonObjectFromContractNegotiationDtoTransformer(Json.createBuilderFactory(Map.of())); - } - - @Test - void transform() { - var cn = Builder.newInstance() - .id("test-id") - .counterPartyAddress("address") - .contractAgreementId("test-agreement") - .state("test-state") - .callbackAddresses(List.of( - CallbackAddress.Builder.newInstance() - .uri("local://test") - .build())) - .protocol("protocol").build(); - - var jsonObject = transformer.transform(cn, context); - assertThat(jsonObject).isNotNull(); - assertThat(jsonObject.getJsonString(CONTRACT_NEGOTIATION_STATE).getString()).isEqualTo("test-state"); - assertThat(jsonObject.getJsonString(CONTRACT_NEGOTIATION_COUNTERPARTY_ADDR).getString()).isEqualTo("address"); - assertThat(jsonObject.getJsonString(CONTRACT_NEGOTIATION_AGREEMENT_ID).getString()).isEqualTo("test-agreement"); - assertThat(jsonObject.getJsonString(ID).getString()).isEqualTo("test-id"); - assertThat(jsonObject.getJsonString(CONTRACT_NEGOTIATION_NEG_TYPE).getString()).isEqualTo("CONSUMER"); - assertThat(jsonObject.getJsonString(CONTRACT_NEGOTIATION_PROTOCOL).getString()).isEqualTo("protocol"); - } -} \ No newline at end of file diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractNegotiationTransformerTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractNegotiationTransformerTest.java new file mode 100644 index 00000000000..ddccfa06890 --- /dev/null +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractNegotiationTransformerTest.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +package org.eclipse.edc.connector.api.management.contractnegotiation.transform; + +import jakarta.json.Json; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; +import org.eclipse.edc.policy.model.Policy; +import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_AGREEMENT_ID; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_COUNTERPARTY_ADDR; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_COUNTERPARTY_ID; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_CREATED_AT; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_NEG_TYPE; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_PROTOCOL; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_STATE; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.REQUESTED; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class JsonObjectFromContractNegotiationTransformerTest { + + private final TransformerContext context = mock(); + private final JsonObjectFromContractNegotiationTransformer transformer = new JsonObjectFromContractNegotiationTransformer(Json.createBuilderFactory(Map.of())); + + @Test + void transform() { + when(context.transform(any(CallbackAddress.class), eq(JsonObject.class))).thenReturn(Json.createObjectBuilder().build()); + var cn = ContractNegotiation.Builder.newInstance() + .id("test-id") + .correlationId("correlation-id") + .counterPartyId("counter-party-id") + .counterPartyAddress("address") + .contractAgreement(createContractAgreement("test-agreement")) + .state(REQUESTED.code()) + .type(ContractNegotiation.Type.PROVIDER) + .callbackAddresses(List.of( + CallbackAddress.Builder.newInstance() + .uri("local://test") + .build())) + .protocol("protocol") + .createdAt(1234) + .build(); + + var jsonObject = transformer.transform(cn, context); + + assertThat(jsonObject).isNotNull(); + assertThat(jsonObject.getString(ID)).isEqualTo("test-id"); + assertThat(jsonObject.getString(CONTRACT_NEGOTIATION_STATE)).isEqualTo(REQUESTED.name()); + assertThat(jsonObject.getString(CONTRACT_NEGOTIATION_COUNTERPARTY_ID)).isEqualTo("counter-party-id"); + assertThat(jsonObject.getString(CONTRACT_NEGOTIATION_COUNTERPARTY_ADDR)).isEqualTo("address"); + assertThat(jsonObject.getString(CONTRACT_NEGOTIATION_AGREEMENT_ID)).isEqualTo("test-agreement"); + assertThat(jsonObject.getString(CONTRACT_NEGOTIATION_NEG_TYPE)).isEqualTo("PROVIDER"); + assertThat(jsonObject.getString(CONTRACT_NEGOTIATION_PROTOCOL)).isEqualTo("protocol"); + assertThat(jsonObject.getJsonNumber(CONTRACT_NEGOTIATION_CREATED_AT).longValue()).isEqualTo(1234); + } + + private ContractAgreement createContractAgreement(String id) { + return ContractAgreement.Builder.newInstance() + .id(id) + .providerId("providerId") + .consumerId("consumerId") + .assetId("assetId") + .policy(Policy.Builder.newInstance().build()) + .build(); + } +} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToContractOfferDescriptionTransformerTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToContractOfferDescriptionTransformerTest.java index 03d612f8941..7a371960271 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToContractOfferDescriptionTransformerTest.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToContractOfferDescriptionTransformerTest.java @@ -53,7 +53,7 @@ void setUp() { @Test void transform() { var jsonObject = Json.createObjectBuilder() - .add(TYPE, ContractOfferDescription.TYPE) + .add(TYPE, ContractOfferDescription.CONTRACT_OFFER_DESCRIPTION_TYPE) .add(OFFER_ID, "test-offer-id") .add(ASSET_ID, "test-asset") .add(POLICY, createPolicy()) @@ -88,4 +88,4 @@ private JsonObject getJsonObject(String type) { .add(TYPE, type) .build(); } -} \ No newline at end of file +} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToContractRequestTransformerTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToContractRequestTransformerTest.java new file mode 100644 index 00000000000..341f55bddaa --- /dev/null +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToContractRequestTransformerTest.java @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +package org.eclipse.edc.connector.api.management.contractnegotiation.transform; + +import jakarta.json.Json; +import jakarta.json.JsonArrayBuilder; +import jakarta.json.JsonObject; +import jakarta.json.JsonValue; +import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest; +import org.eclipse.edc.jsonld.TitaniumJsonLd; +import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.policy.model.Policy; +import org.eclipse.edc.spi.monitor.Monitor; +import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Set; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription.ASSET_ID; +import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription.OFFER_ID; +import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription.POLICY; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.CALLBACK_ADDRESSES; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.CONNECTOR_ADDRESS; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.CONNECTOR_ID; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.CONSUMER_ID; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.OFFER; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.PROTOCOL; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.PROVIDER_ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_OBLIGATION_ATTRIBUTE; +import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_PERMISSION_ATTRIBUTE; +import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_POLICY_TYPE_SET; +import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_PROHIBITION_ATTRIBUTE; +import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.EVENTS; +import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.IS_TRANSACTIONAL; +import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.URI; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class JsonObjectToContractRequestTransformerTest { + + private final JsonLd jsonLd = new TitaniumJsonLd(mock(Monitor.class)); + private final TransformerContext context = mock(); + private JsonObjectToContractRequestTransformer transformer; + + @BeforeEach + void setUp() { + transformer = new JsonObjectToContractRequestTransformer(); + } + + @Test + void transform() { + var jsonObject = Json.createObjectBuilder() + .add(TYPE, ContractRequest.CONTRACT_REQUEST_TYPE) + .add(CONNECTOR_ADDRESS, "test-address") + .add(PROTOCOL, "test-protocol") + .add(PROVIDER_ID, "test-provider-id") + .add(CONSUMER_ID, "test-consumer-id") + .add(CALLBACK_ADDRESSES, createCallbackAddress()) + .add(OFFER, Json.createObjectBuilder() + .add(OFFER_ID, "test-offer-id") + .add(ASSET_ID, "test-asset") + .add(POLICY, createPolicy()) + .build()) + .build(); + + var policy = Policy.Builder.newInstance().build(); + var contractOfferDescription = ContractOfferDescription.Builder.newInstance() + .offerId("offerId") + .assetId("assetId") + .policy(policy) + .build(); + when(context.transform(any(JsonValue.class), eq(ContractOfferDescription.class))).thenReturn(contractOfferDescription); + + when(context.transform(any(JsonObject.class), eq(CallbackAddress.class))).thenReturn(CallbackAddress.Builder.newInstance() + .uri("http://test.local") + .events(Set.of("foo", "bar")) + .transactional(true) + .build()); + + var request = transformer.transform(jsonLd.expand(jsonObject).getContent(), context); + + assertThat(request).isNotNull(); + assertThat(request.getProviderId()).isEqualTo("test-provider-id"); + assertThat(request.getCallbackAddresses()).isNotEmpty(); + assertThat(request.getProtocol()).isEqualTo("test-protocol"); + assertThat(request.getCounterPartyAddress()).isEqualTo("test-address"); + assertThat(request.getContractOffer()).isNotNull().satisfies(contractOffer -> { + assertThat(contractOffer.getId()).isEqualTo("offerId"); + assertThat(contractOffer.getAssetId()).isEqualTo("assetId"); + assertThat(contractOffer.getPolicy()).isSameAs(policy); + }); + + } + + @Test + @Deprecated(since = "0.1.3") + void transform_shouldSetProviderIdAsConnectorId_whenProviderIdNotDefined() { + var jsonObject = Json.createObjectBuilder() + .add(TYPE, ContractRequest.CONTRACT_REQUEST_TYPE) + .add(CONNECTOR_ADDRESS, "test-address") + .add(PROTOCOL, "test-protocol") + .add(CONNECTOR_ID, "test-connector-id") + .add(CONSUMER_ID, "test-consumer-id") + .add(OFFER, Json.createObjectBuilder() + .add(OFFER_ID, "test-offer-id") + .add(ASSET_ID, "test-asset") + .add(POLICY, createPolicy()) + .build()) + .build(); + + var policy = Policy.Builder.newInstance().build(); + var contractOfferDescription = ContractOfferDescription.Builder.newInstance() + .offerId("offerId") + .assetId("assetId") + .policy(policy) + .build(); + when(context.transform(any(JsonValue.class), eq(ContractOfferDescription.class))).thenReturn(contractOfferDescription); + + var request = transformer.transform(jsonLd.expand(jsonObject).getContent(), context); + + assertThat(request).isNotNull(); + assertThat(request.getProviderId()).isEqualTo("test-connector-id"); + } + + @Test + void transform_shouldSetProviderIdAsConnectorAddress_whenProviderIdNotDefined() { + var jsonObject = Json.createObjectBuilder() + .add(TYPE, ContractRequest.CONTRACT_REQUEST_TYPE) + .add(CONNECTOR_ADDRESS, "test-address") + .add(PROTOCOL, "test-protocol") + .add(CONSUMER_ID, "test-consumer-id") + .add(OFFER, Json.createObjectBuilder() + .add(OFFER_ID, "test-offer-id") + .add(ASSET_ID, "test-asset") + .add(POLICY, createPolicy()) + .build()) + .build(); + + var policy = Policy.Builder.newInstance().build(); + var contractOfferDescription = ContractOfferDescription.Builder.newInstance() + .offerId("offerId") + .assetId("assetId") + .policy(policy) + .build(); + when(context.transform(any(JsonValue.class), eq(ContractOfferDescription.class))).thenReturn(contractOfferDescription); + + var request = transformer.transform(jsonLd.expand(jsonObject).getContent(), context); + + assertThat(request).isNotNull(); + assertThat(request.getProviderId()).isEqualTo("test-address"); + } + + private JsonArrayBuilder createCallbackAddress() { + var builder = Json.createArrayBuilder(); + return builder.add(Json.createObjectBuilder() + .add(IS_TRANSACTIONAL, true) + .add(URI, "http://test.local/") + .add(EVENTS, Json.createArrayBuilder().build())); + } + + private JsonObject createPolicy() { + var permissionJson = getJsonObject("permission"); + var prohibitionJson = getJsonObject("prohibition"); + var dutyJson = getJsonObject("duty"); + return Json.createObjectBuilder() + .add(TYPE, ODRL_POLICY_TYPE_SET) + .add(ODRL_PERMISSION_ATTRIBUTE, permissionJson) + .add(ODRL_PROHIBITION_ATTRIBUTE, prohibitionJson) + .add(ODRL_OBLIGATION_ATTRIBUTE, dutyJson) + .build(); + } + + private JsonObject getJsonObject(String type) { + return Json.createObjectBuilder() + .add(TYPE, type) + .build(); + } +} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToNegotiationInitiateRequestDtoTransformerTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToNegotiationInitiateRequestDtoTransformerTest.java deleted file mode 100644 index d1c9a358388..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToNegotiationInitiateRequestDtoTransformerTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; - -import jakarta.json.Json; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonObject; -import jakarta.json.JsonValue; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription; -import org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto; -import org.eclipse.edc.jsonld.TitaniumJsonLd; -import org.eclipse.edc.jsonld.spi.JsonLd; -import org.eclipse.edc.spi.monitor.Monitor; -import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.Set; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription.ASSET_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription.OFFER_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription.POLICY; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.CALLBACK_ADDRESSES; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.CONNECTOR_ADDRESS; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.CONNECTOR_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.CONSUMER_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.OFFER; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.PROTOCOL; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.PROVIDER_ID; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; -import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_OBLIGATION_ATTRIBUTE; -import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_PERMISSION_ATTRIBUTE; -import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_POLICY_TYPE_SET; -import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_PROHIBITION_ATTRIBUTE; -import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.EVENTS; -import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.IS_TRANSACTIONAL; -import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.URI; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class JsonObjectToNegotiationInitiateRequestDtoTransformerTest { - - private final JsonLd jsonLd = new TitaniumJsonLd(mock(Monitor.class)); - private JsonObjectToNegotiationInitiateRequestDtoTransformer transformer; - - @BeforeEach - void setUp() { - transformer = new JsonObjectToNegotiationInitiateRequestDtoTransformer(); - } - - @Test - void transform() { - var jsonObject = Json.createObjectBuilder() - .add(TYPE, NegotiationInitiateRequestDto.TYPE) - .add(CONNECTOR_ADDRESS, "test-address") - .add(PROTOCOL, "test-protocol") - .add(CONNECTOR_ID, "test-conn-id") - .add(PROVIDER_ID, "test-provider-id") - .add(CONSUMER_ID, "test-consumer-id") - .add(CALLBACK_ADDRESSES, createCallbackAddress()) - .add(OFFER, Json.createObjectBuilder() - .add(OFFER_ID, "test-offer-id") - .add(ASSET_ID, "test-asset") - .add(POLICY, createPolicy()) - .build()) - .build(); - - var context = mock(TransformerContext.class); - when(context.transform(any(JsonValue.class), eq(ContractOfferDescription.class))).thenReturn(ContractOfferDescription.Builder.newInstance().build()); - - when(context.transform(any(JsonObject.class), eq(CallbackAddress.class))).thenReturn(CallbackAddress.Builder.newInstance() - .uri("http://test.local") - .events(Set.of("foo", "bar")) - .transactional(true) - .build()); - - var dto = transformer.transform(jsonLd.expand(jsonObject).getContent(), context); - - assertThat(dto).isNotNull(); - assertThat(dto.getCallbackAddresses()).isNotEmpty(); - assertThat(dto.getProtocol()).isEqualTo("test-protocol"); - assertThat(dto.getConnectorAddress()).isEqualTo("test-address"); - assertThat(dto.getConnectorId()).isEqualTo("test-conn-id"); - assertThat(dto.getProviderId()).isEqualTo("test-provider-id"); - assertThat(dto.getConsumerId()).isEqualTo("test-consumer-id"); - assertThat(dto.getOffer()).isNotNull(); - - } - - private JsonArrayBuilder createCallbackAddress() { - var builder = Json.createArrayBuilder(); - return builder.add(Json.createObjectBuilder() - .add(IS_TRANSACTIONAL, true) - .add(URI, "http://test.local/") - .add(EVENTS, Json.createArrayBuilder().build())); - } - - private JsonObject createPolicy() { - var permissionJson = getJsonObject("permission"); - var prohibitionJson = getJsonObject("prohibition"); - var dutyJson = getJsonObject("duty"); - return Json.createObjectBuilder() - .add(TYPE, ODRL_POLICY_TYPE_SET) - .add(ODRL_PERMISSION_ATTRIBUTE, permissionJson) - .add(ODRL_PROHIBITION_ATTRIBUTE, prohibitionJson) - .add(ODRL_OBLIGATION_ATTRIBUTE, dutyJson) - .build(); - } - - private JsonObject getJsonObject(String type) { - return Json.createObjectBuilder() - .add(TYPE, type) - .build(); - } -} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/NegotiationInitiateRequestDtoToDataRequestTransformerTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/NegotiationInitiateRequestDtoToDataRequestTransformerTest.java deleted file mode 100644 index 74032873a0d..00000000000 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/NegotiationInitiateRequestDtoToDataRequestTransformerTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; - -import org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto; -import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.junit.jupiter.api.Test; - -import java.time.Clock; -import java.time.Instant; -import java.util.List; - -import static java.time.ZoneOffset.UTC; -import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.edc.connector.api.management.contractnegotiation.TestFunctions.createOffer; -import static org.mockito.Mockito.mock; - -class NegotiationInitiateRequestDtoToDataRequestTransformerTest { - - private static final String DEFAULT_CONSUMER_ID = "urn:connector:test-consumer"; - private final Instant now = Instant.now(); - private final Clock clock = Clock.fixed(now, UTC); - - private final NegotiationInitiateRequestDtoToDataRequestTransformer transformer = new NegotiationInitiateRequestDtoToDataRequestTransformer(clock); - - private final TransformerContext context = mock(TransformerContext.class); - - @Test - void inputOutputType() { - assertThat(transformer.getInputType()).isNotNull(); - assertThat(transformer.getOutputType()).isNotNull(); - } - - @Test - void verify_transform() { - var callback = CallbackAddress.Builder.newInstance() - .uri("local://test") - .build(); - var dto = NegotiationInitiateRequestDto.Builder.newInstance() - .connectorId("connectorId") - .connectorAddress("address") - .protocol("protocol") - .consumerId("test-consumer") - .providerId("test-provider") - .offer(createOffer("offerId", "assetId")) - .callbackAddresses(List.of(callback)) - .build(); - - var request = transformer.transform(dto, context); - - assertThat(request).isNotNull(); - assertThat(request.getRequestData().getConnectorId()).isEqualTo("connectorId"); - assertThat(request.getRequestData().getCounterPartyAddress()).isEqualTo("address"); - assertThat(request.getRequestData().getProtocol()).isEqualTo("protocol"); - assertThat(request.getRequestData().getContractOffer().getId()).isEqualTo("offerId"); - assertThat(request.getRequestData().getContractOffer().getPolicy()).isNotNull(); - assertThat(request.getCallbackAddresses()).hasSize(1); - } - - @Test - void verify_transfor_withNoProviderId() { - var dto = NegotiationInitiateRequestDto.Builder.newInstance() - .connectorId("connectorId") - .connectorAddress("address") - .protocol("protocol") - .consumerId("urn:connector:test-consumer") - // do not set provider ID - .offer(createOffer("offerId", "assetId")) - .build(); - - var request = transformer.transform(dto, context); - - assertThat(request).isNotNull(); - assertThat(request.getRequestData().getContractOffer().getProviderId()).isEqualTo(dto.getConnectorAddress()); - } - - @Test - void verify_transform_withNoConsumerId() { - var dto = NegotiationInitiateRequestDto.Builder.newInstance() - .connectorId("connectorId") - .connectorAddress("address") - .protocol("protocol") - // do not set consumer ID - .providerId("urn:connector:test-provider") - .offer(createOffer("offerId", "assetId")) - .build(); - - var request = transformer.transform(dto, context); - assertThat(request).isNotNull(); - assertThat(request.getRequestData().getContractOffer().getProviderId()).isEqualTo("urn:connector:test-provider"); - } -} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/NegotiationInitiateRequestDtoValidatorTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/ContractRequestValidatorTest.java similarity index 81% rename from extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/NegotiationInitiateRequestDtoValidatorTest.java rename to extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/ContractRequestValidatorTest.java index dba18ceb72a..0e064551ca3 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/NegotiationInitiateRequestDtoValidatorTest.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/ContractRequestValidatorTest.java @@ -29,23 +29,23 @@ import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription.ASSET_ID; import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription.OFFER_ID; import static org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription.POLICY; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.CONNECTOR_ADDRESS; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.CONNECTOR_ID; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.OFFER; -import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationInitiateRequestDto.PROTOCOL; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.CONNECTOR_ADDRESS; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.OFFER; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.PROTOCOL; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.PROVIDER_ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; -class NegotiationInitiateRequestDtoValidatorTest { +class ContractRequestValidatorTest { - private final Validator validator = NegotiationInitiateRequestDtoValidator.instance(); + private final Validator validator = ContractRequestValidator.instance(); @Test void shouldSuccess_whenObjectIsValid() { var input = Json.createObjectBuilder() .add(CONNECTOR_ADDRESS, value("http://connector-address")) .add(PROTOCOL, value("protocol")) - .add(CONNECTOR_ID, value("connector-id")) + .add(PROVIDER_ID, value("connector-id")) .add(OFFER, createArrayBuilder().add(createObjectBuilder() .add(OFFER_ID, value("offerId")) .add(ASSET_ID, value("offerId")) @@ -68,7 +68,6 @@ void shouldFail_whenMandatoryPropertiesAreMissing() { .isNotEmpty() .anySatisfy(violation -> assertThat(violation.path()).isEqualTo(CONNECTOR_ADDRESS)) .anySatisfy(violation -> assertThat(violation.path()).isEqualTo(PROTOCOL)) - .anySatisfy(violation -> assertThat(violation.path()).isEqualTo(CONNECTOR_ID)) .anySatisfy(violation -> assertThat(violation.path()).isEqualTo(OFFER)); } @@ -77,7 +76,7 @@ void shouldFail_whenOfferMandatoryPropertiesAreMissing() { var input = Json.createObjectBuilder() .add(CONNECTOR_ADDRESS, value("http://connector-address")) .add(PROTOCOL, value("protocol")) - .add(CONNECTOR_ID, value("connector-id")) + .add(PROVIDER_ID, value("connector-id")) .add(OFFER, createArrayBuilder().add(createObjectBuilder())) .build(); diff --git a/extensions/control-plane/api/management-api/policy-definition-api/build.gradle.kts b/extensions/control-plane/api/management-api/policy-definition-api/build.gradle.kts index 4ec2f667872..acb85ff748a 100644 --- a/extensions/control-plane/api/management-api/policy-definition-api/build.gradle.kts +++ b/extensions/control-plane/api/management-api/policy-definition-api/build.gradle.kts @@ -31,6 +31,7 @@ dependencies { implementation(libs.jakarta.rsApi) + testImplementation(project(":core:common:transform-core")) testImplementation(project(":core:control-plane:control-plane-core")) testImplementation(project(":core:data-plane-selector:data-plane-selector-core")) testImplementation(project(":extensions:common:http")) diff --git a/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/api/management/policy/PolicyDefinitionApi.java b/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/api/management/policy/PolicyDefinitionApi.java index 3fc483bcd0e..5eef633ed03 100644 --- a/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/api/management/policy/PolicyDefinitionApi.java +++ b/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/api/management/policy/PolicyDefinitionApi.java @@ -109,19 +109,19 @@ record PolicyDefinitionInputSchema( "@context": { "edc": "https://w3id.org/edc/v0.0.1/ns/" }, "@id": "definition-id", "policy": { - "@context": "http://www.w3.org/ns/odrl.jsonld", - "@type": "Set", - "uid": "http://example.com/policy:1010", - "permission": [{ - "target": "http://example.com/asset:9898.movie", - "action": "display", - "constraint": [{ - "leftOperand": "spatial", - "operator": "eq", - "rightOperand": "https://www.wikidata.org/wiki/Q183", - "comment": "i.e Germany" - }] - }] + "@context": "http://www.w3.org/ns/odrl.jsonld", + "@type": "Set", + "uid": "http://example.com/policy:1010", + "permission": [{ + "target": "http://example.com/asset:9898.movie", + "action": "display", + "constraint": [{ + "leftOperand": "spatial", + "operator": "eq", + "rightOperand": "https://www.wikidata.org/wiki/Q183", + "comment": "i.e Germany" + }] + }] } } """; @@ -140,19 +140,19 @@ record PolicyDefinitionOutputSchema( "@context": { "edc": "https://w3id.org/edc/v0.0.1/ns/" }, "@id": "definition-id", "policy": { - "@context": "http://www.w3.org/ns/odrl.jsonld", - "@type": "Set", - "uid": "http://example.com/policy:1010", - "permission": [{ - "target": "http://example.com/asset:9898.movie", - "action": "display", - "constraint": [{ - "leftOperand": "spatial", - "operator": "eq", - "rightOperand": "https://www.wikidata.org/wiki/Q183", - "comment": "i.e Germany" - }] - }] + "@context": "http://www.w3.org/ns/odrl.jsonld", + "@type": "Set", + "uid": "http://example.com/policy:1010", + "permission": [{ + "target": "http://example.com/asset:9898.movie", + "action": "display", + "constraint": [{ + "leftOperand": "spatial", + "operator": "eq", + "rightOperand": "https://www.wikidata.org/wiki/Q183", + "comment": "i.e Germany" + }] + }] }, "createdAt": 1688465655 } diff --git a/extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/api/management/policy/PolicyDefinitionApiTest.java b/extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/api/management/policy/PolicyDefinitionApiTest.java index 350cec64dc5..80164a5c3f4 100644 --- a/extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/api/management/policy/PolicyDefinitionApiTest.java +++ b/extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/api/management/policy/PolicyDefinitionApiTest.java @@ -19,11 +19,11 @@ import jakarta.json.JsonObject; import org.eclipse.edc.connector.api.management.policy.transform.JsonObjectToPolicyDefinitionTransformer; import org.eclipse.edc.connector.api.management.policy.validation.PolicyDefinitionValidator; -import org.eclipse.edc.connector.core.transform.TypeTransformerRegistryImpl; import org.eclipse.edc.connector.policy.spi.PolicyDefinition; +import org.eclipse.edc.core.transform.TypeTransformerRegistryImpl; +import org.eclipse.edc.core.transform.transformer.OdrlTransformersFactory; import org.eclipse.edc.jsonld.JsonLdExtension; import org.eclipse.edc.jsonld.spi.JsonLd; -import org.eclipse.edc.jsonld.transformer.OdrlTransformersFactory; import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.junit.jupiter.api.BeforeEach; diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiExtension.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiExtension.java index 7c04f640942..b0d08f1b933 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiExtension.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiExtension.java @@ -16,6 +16,7 @@ import jakarta.json.Json; import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration; +import org.eclipse.edc.connector.api.management.configuration.transform.ManagementApiTypeTransformerRegistry; import org.eclipse.edc.connector.api.management.transferprocess.transform.DataRequestToDataRequestDtoTransformer; import org.eclipse.edc.connector.api.management.transferprocess.transform.JsonObjectFromDataRequestDtoTransformer; import org.eclipse.edc.connector.api.management.transferprocess.transform.JsonObjectFromTransferProcessDtoTransformer; @@ -32,7 +33,6 @@ import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; import org.eclipse.edc.spi.types.TypeManager; -import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.web.spi.WebService; @@ -53,7 +53,7 @@ public class TransferProcessApiExtension implements ServiceExtension { private ManagementApiConfiguration configuration; @Inject - private TypeTransformerRegistry transformerRegistry; + private ManagementApiTypeTransformerRegistry transformerRegistry; @Inject private TransferProcessService service; diff --git a/resources/openapi/openapi.yaml b/resources/openapi/openapi.yaml index 633c372724c..0dd65957bc3 100644 --- a/resources/openapi/openapi.yaml +++ b/resources/openapi/openapi.yaml @@ -840,7 +840,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/NegotiationInitiateRequestDto' + $ref: '#/components/schemas/ContractRequestSchema' responses: "200": description: The negotiation was successfully initiated. Returns the contract @@ -848,7 +848,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/IdResponseDto' + $ref: '#/components/schemas/IdResponseSchema' links: poll-state: operationId: getNegotiationState @@ -873,7 +873,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/QuerySpecDto' + $ref: '#/components/schemas/QuerySpecSchema' responses: "200": description: The contract negotiations that match the query @@ -883,7 +883,7 @@ paths: type: array example: null items: - $ref: '#/components/schemas/ContractNegotiationDto' + $ref: '#/components/schemas/ContractNegotiationSchema' "400": description: Request was malformed content: @@ -914,7 +914,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ContractNegotiationDto' + $ref: '#/components/schemas/ContractNegotiationSchema' "400": description: "Request was malformed, e.g. id was null" content: @@ -956,7 +956,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ContractAgreementDto' + $ref: '#/components/schemas/ContractAgreementSchema' "400": description: "Request was malformed, e.g. id was null" content: @@ -1997,6 +1997,32 @@ components: type: string example: null example: null + CallbackAddressSchema: + type: object + properties: + '@type': + type: string + example: https://w3id.org/edc/v0.0.1/ns/CallbackAddress + authCodeId: + type: string + example: null + authKey: + type: string + example: null + events: + uniqueItems: true + type: array + example: null + items: + type: string + example: null + transactional: + type: boolean + example: null + uri: + type: string + example: null + example: null Catalog: type: object properties: @@ -2082,6 +2108,48 @@ components: type: string example: null example: null + ContractAgreementSchema: + type: object + properties: + '@id': + type: string + example: null + '@type': + type: string + example: https://w3id.org/edc/v0.0.1/ns/ContractAgreement + assetId: + type: string + example: null + consumerId: + type: string + example: null + contractSigningDate: + type: integer + format: int64 + example: null + policy: + type: object + description: ODRL policy + example: null + providerId: + type: string + example: null + example: + '@context': + edc: https://w3id.org/edc/v0.0.1/ns/ + '@type': https://w3id.org/edc/v0.0.1/ns/ContractAgreement + '@id': negotiation-id + providerId: provider-id + consumerId: consumer-id + assetId: asset-id + contractSigningDate: 1688465655 + policy: + '@context': http://www.w3.org/ns/odrl.jsonld + '@type': Set + '@id': offer-id + permission: + - target: asset-id + action: display ContractDefinitionInputSchema: type: object properties: @@ -2141,32 +2209,28 @@ components: edc:contractPolicyId: contract-policy-id edc:assetsSelector: [] edc:createdAt: 1688465655 - ContractNegotiationDto: + ContractNegotiationSchema: type: object properties: - '@context': - type: object - example: null '@id': type: string example: null '@type': type: string - example: null + example: https://w3id.org/edc/v0.0.1/ns/ContractNegotiation callbackAddresses: type: array example: null items: - $ref: '#/components/schemas/CallbackAddress' + $ref: '#/components/schemas/CallbackAddressSchema' contractAgreementId: type: string example: null counterPartyAddress: type: string example: null - createdAt: - type: integer - format: int64 + counterPartyId: + type: string example: null errorDetail: type: string @@ -2183,11 +2247,27 @@ components: enum: - CONSUMER - PROVIDER - updatedAt: - type: integer - format: int64 - example: null - example: null + example: + '@context': + edc: https://w3id.org/edc/v0.0.1/ns/ + '@type': https://w3id.org/edc/v0.0.1/ns/ContractNegotiation + '@id': negotiation-id + type: PROVIDER + protocol: dataspace-protocol-http + counterPartyId: counter-party-id + counterPartyAddress: http://counter/party/address + state: VERIFIED + contractAgreementId: contract:agreement:id + errorDetail: eventual-error-detail + createdAt: 1688465655 + callbackAddresses: + - transactional: false + uri: http://callback/url + events: + - contract.negotiation + - transfer.process + authKey: auth-key + authCodeId: auth-code-id ContractOffer: type: object properties: @@ -2199,13 +2279,13 @@ components: example: null policy: $ref: '#/components/schemas/Policy' - providerId: - type: string - example: null example: null - ContractOfferDescription: + ContractOfferDescriptionSchema: type: object properties: + '@type': + type: string + example: https://w3id.org/edc/v0.0.1/ns/ContractOfferDescription assetId: type: string example: null @@ -2213,8 +2293,67 @@ components: type: string example: null policy: - $ref: '#/components/schemas/Policy' + type: object + description: ODRL policy + example: null example: null + ContractRequestSchema: + type: object + properties: + '@type': + type: string + example: https://w3id.org/edc/v0.0.1/ns/ContractRequest + callbackAddresses: + type: array + example: null + items: + $ref: '#/components/schemas/CallbackAddressSchema' + connectorAddress: + type: string + example: null + connectorId: + type: string + description: please use providerId instead + example: null + deprecated: true + consumerId: + type: string + description: this field is not used anymore + example: null + deprecated: true + offer: + $ref: '#/components/schemas/ContractOfferDescriptionSchema' + protocol: + type: string + example: null + providerId: + type: string + example: null + example: + '@context': + edc: https://w3id.org/edc/v0.0.1/ns/ + '@type': https://w3id.org/edc/v0.0.1/ns/ContractRequest + connectorAddress: http://provider-address + protocol: dataspace-protocol-http + providerId: provider-id + offer: + offerId: offer-id + assetId: asset-id + policy: + '@context': http://www.w3.org/ns/odrl.jsonld + '@type': Set + '@id': offer-id + permission: + - target: asset-id + action: display + callbackAddresses: + - transactional: false + uri: http://callback/url + events: + - contract.negotiation + - transfer.process + authKey: auth-key + authCodeId: auth-code-id CriterionDto: type: object properties: @@ -2588,38 +2727,6 @@ components: - "FALSE" - "NULL" example: null - NegotiationInitiateRequestDto: - type: object - properties: - '@context': - type: object - example: null - '@type': - type: string - example: null - callbackAddresses: - type: array - example: null - items: - $ref: '#/components/schemas/CallbackAddress' - connectorAddress: - type: string - example: null - connectorId: - type: string - example: null - consumerId: - type: string - example: null - offer: - $ref: '#/components/schemas/ContractOfferDescription' - protocol: - type: string - example: null - providerId: - type: string - example: null - example: null NegotiationState: type: object properties: diff --git a/resources/openapi/yaml/management-api/catalog-api.yaml b/resources/openapi/yaml/management-api/catalog-api.yaml index 05d1702ffd7..5d601bc5049 100644 --- a/resources/openapi/yaml/management-api/catalog-api.yaml +++ b/resources/openapi/yaml/management-api/catalog-api.yaml @@ -100,9 +100,6 @@ components: example: null policy: $ref: '#/components/schemas/Policy' - providerId: - type: string - example: null CriterionDto: type: object example: null diff --git a/resources/openapi/yaml/management-api/contract-negotiation-api.yaml b/resources/openapi/yaml/management-api/contract-negotiation-api.yaml index b863d70d2d8..e3ac141ae42 100644 --- a/resources/openapi/yaml/management-api/contract-negotiation-api.yaml +++ b/resources/openapi/yaml/management-api/contract-negotiation-api.yaml @@ -11,13 +11,13 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/NegotiationInitiateRequestDto' + $ref: '#/components/schemas/ContractRequestSchema' responses: "200": content: application/json: schema: - $ref: '#/components/schemas/IdResponseDto' + $ref: '#/components/schemas/IdResponseSchema' description: The negotiation was successfully initiated. Returns the contract negotiation ID and created timestamp links: @@ -44,7 +44,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/QuerySpecDto' + $ref: '#/components/schemas/QuerySpecSchema' responses: "200": content: @@ -53,7 +53,7 @@ paths: type: array example: null items: - $ref: '#/components/schemas/ContractNegotiationDto' + $ref: '#/components/schemas/ContractNegotiationSchema' description: The contract negotiations that match the query "400": content: @@ -82,7 +82,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ContractNegotiationDto' + $ref: '#/components/schemas/ContractNegotiationSchema' description: The contract negotiation "400": content: @@ -121,7 +121,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ContractAgreementDto' + $ref: '#/components/schemas/ContractAgreementSchema' description: "The contract agreement that is attached to the negotiation,\ \ or null" "400": @@ -266,18 +266,6 @@ paths: - Contract Negotiation components: schemas: - Action: - type: object - example: null - properties: - constraint: - $ref: '#/components/schemas/Constraint' - includedIn: - type: string - example: null - type: - type: string - example: null ApiErrorDetail: type: object example: null @@ -294,10 +282,13 @@ components: type: type: string example: null - CallbackAddress: + CallbackAddressSchema: type: object example: null properties: + '@type': + type: string + example: https://w3id.org/edc/v0.0.1/ns/CallbackAddress authCodeId: type: string example: null @@ -317,21 +308,31 @@ components: uri: type: string example: null - Constraint: + ContractAgreementSchema: type: object - discriminator: - propertyName: edctype - example: null + example: + '@context': + edc: https://w3id.org/edc/v0.0.1/ns/ + '@type': https://w3id.org/edc/v0.0.1/ns/ContractAgreement + '@id': negotiation-id + providerId: provider-id + consumerId: consumer-id + assetId: asset-id + contractSigningDate: 1688465655 + policy: + '@context': http://www.w3.org/ns/odrl.jsonld + '@type': Set + '@id': offer-id + permission: + - target: asset-id + action: display properties: - edctype: + '@id': type: string example: null - required: - - edctype - ContractAgreementDto: - type: object - example: null - properties: + '@type': + type: string + example: https://w3id.org/edc/v0.0.1/ns/ContractAgreement assetId: type: string example: null @@ -342,41 +343,56 @@ components: type: integer format: int64 example: null - id: - type: string - example: null policy: - $ref: '#/components/schemas/Policy' + type: object + description: ODRL policy + example: null providerId: type: string example: null - ContractNegotiationDto: + ContractNegotiationSchema: type: object - example: null - properties: + example: '@context': - type: object - example: null + edc: https://w3id.org/edc/v0.0.1/ns/ + '@type': https://w3id.org/edc/v0.0.1/ns/ContractNegotiation + '@id': negotiation-id + type: PROVIDER + protocol: dataspace-protocol-http + counterPartyId: counter-party-id + counterPartyAddress: http://counter/party/address + state: VERIFIED + contractAgreementId: contract:agreement:id + errorDetail: eventual-error-detail + createdAt: 1688465655 + callbackAddresses: + - transactional: false + uri: http://callback/url + events: + - contract.negotiation + - transfer.process + authKey: auth-key + authCodeId: auth-code-id + properties: '@id': type: string example: null '@type': type: string - example: null + example: https://w3id.org/edc/v0.0.1/ns/ContractNegotiation callbackAddresses: type: array example: null items: - $ref: '#/components/schemas/CallbackAddress' + $ref: '#/components/schemas/CallbackAddressSchema' contractAgreementId: type: string example: null counterPartyAddress: type: string example: null - createdAt: - type: integer - format: int64 + counterPartyId: + type: string example: null errorDetail: type: string @@ -393,14 +409,13 @@ components: - CONSUMER - PROVIDER example: null - updatedAt: - type: integer - format: int64 - example: null - ContractOfferDescription: + ContractOfferDescriptionSchema: type: object example: null properties: + '@type': + type: string + example: https://w3id.org/edc/v0.0.1/ns/ContractOfferDescription assetId: type: string example: null @@ -408,61 +423,96 @@ components: type: string example: null policy: - $ref: '#/components/schemas/Policy' - CriterionDto: - type: object - example: null - properties: - '@context': type: object + description: ODRL policy example: null + ContractRequestSchema: + type: object + example: + '@context': + edc: https://w3id.org/edc/v0.0.1/ns/ + '@type': https://w3id.org/edc/v0.0.1/ns/ContractRequest + connectorAddress: http://provider-address + protocol: dataspace-protocol-http + providerId: provider-id + offer: + offerId: offer-id + assetId: asset-id + policy: + '@context': http://www.w3.org/ns/odrl.jsonld + '@type': Set + '@id': offer-id + permission: + - target: asset-id + action: display + callbackAddresses: + - transactional: false + uri: http://callback/url + events: + - contract.negotiation + - transfer.process + authKey: auth-key + authCodeId: auth-code-id + properties: '@type': type: string + example: https://w3id.org/edc/v0.0.1/ns/ContractRequest + callbackAddresses: + type: array example: null - operandLeft: - type: object - example: null - operandRight: - type: object - example: null - operator: + items: + $ref: '#/components/schemas/CallbackAddressSchema' + connectorAddress: type: string example: null - Duty: - type: object - example: null - properties: - action: - $ref: '#/components/schemas/Action' - assignee: + connectorId: type: string + deprecated: true + description: please use providerId instead example: null - assigner: + consumerId: type: string + deprecated: true + description: this field is not used anymore example: null - consequence: - $ref: '#/components/schemas/Duty' - constraints: - type: array + offer: + $ref: '#/components/schemas/ContractOfferDescriptionSchema' + protocol: + type: string example: null - items: - $ref: '#/components/schemas/Constraint' - parentPermission: - $ref: '#/components/schemas/Permission' - target: + providerId: type: string example: null - IdResponseDto: + CriterionSchema: type: object - example: null - properties: + example: '@context': + edc: https://w3id.org/edc/v0.0.1/ns/ + operandLeft: fieldName + operator: = + operandRight: some value + properties: + '@type': + type: string + example: https://w3id.org/edc/v0.0.1/ns/CriterionDto + operandLeft: type: object example: null - '@id': + operandRight: + type: object + example: null + operator: type: string example: null - '@type': + IdResponseSchema: + type: object + example: + '@context': + edc: https://w3id.org/edc/v0.0.1/ns/ + '@id': id-value + createdAt: 1688465655 + properties: + '@id': type: string example: null createdAt: @@ -524,38 +574,6 @@ components: - "FALSE" - "NULL" example: null - NegotiationInitiateRequestDto: - type: object - example: null - properties: - '@context': - type: object - example: null - '@type': - type: string - example: null - callbackAddresses: - type: array - example: null - items: - $ref: '#/components/schemas/CallbackAddress' - connectorAddress: - type: string - example: null - connectorId: - type: string - example: null - consumerId: - type: string - example: null - offer: - $ref: '#/components/schemas/ContractOfferDescription' - protocol: - type: string - example: null - providerId: - type: string - example: null NegotiationState: type: object example: null @@ -569,110 +587,25 @@ components: state: type: string example: null - Permission: - type: object - example: null - properties: - action: - $ref: '#/components/schemas/Action' - assignee: - type: string - example: null - assigner: - type: string - example: null - constraints: - type: array - example: null - items: - $ref: '#/components/schemas/Constraint' - duties: - type: array - example: null - items: - $ref: '#/components/schemas/Duty' - target: - type: string - example: null - Policy: + QuerySpecSchema: type: object - example: null - properties: - '@type': - type: string - enum: - - SET - - OFFER - - CONTRACT - example: null - assignee: - type: string - example: null - assigner: - type: string - example: null - extensibleProperties: - type: object - additionalProperties: - type: object - example: null - example: null - inheritsFrom: - type: string - example: null - obligations: - type: array - example: null - items: - $ref: '#/components/schemas/Duty' - permissions: - type: array - example: null - items: - $ref: '#/components/schemas/Permission' - prohibitions: - type: array - example: null - items: - $ref: '#/components/schemas/Prohibition' - target: - type: string - example: null - Prohibition: - type: object - example: null - properties: - action: - $ref: '#/components/schemas/Action' - assignee: - type: string - example: null - assigner: - type: string - example: null - constraints: - type: array - example: null - items: - $ref: '#/components/schemas/Constraint' - target: - type: string - example: null - QuerySpecDto: - type: object - example: null - properties: + example: '@context': - type: object - example: null + edc: https://w3id.org/edc/v0.0.1/ns/ + offset: 5 + limit: 10 + sortOrder: DESC + sortField: fieldName + criterion: [] + properties: '@type': type: string - example: null + example: https://w3id.org/edc/v0.0.1/ns/QuerySpecDto filterExpression: type: array example: null items: - $ref: '#/components/schemas/CriterionDto' + $ref: '#/components/schemas/CriterionSchema' limit: type: integer format: int32 diff --git a/settings.gradle.kts b/settings.gradle.kts index 7c9d37c39c9..824a27cd846 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -48,6 +48,7 @@ include(":core:common:jwt-core") include(":core:common:policy-engine") include(":core:common:policy-evaluator") include(":core:common:state-machine") +include(":core:common:transform-core") include(":core:common:validator-core") include(":core:common:util") @@ -76,7 +77,6 @@ include(":data-protocols:dsp:dsp-negotiation:dsp-negotiation-http-dispatcher") include(":data-protocols:dsp:dsp-negotiation:dsp-negotiation-transform") include(":data-protocols:dsp:dsp-http-core") include(":data-protocols:dsp:dsp-http-spi") -include(":data-protocols:dsp:dsp-transform") include(":data-protocols:dsp:dsp-transfer-process") include(":data-protocols:dsp:dsp-transfer-process:dsp-transfer-process-api") include(":data-protocols:dsp:dsp-transfer-process:dsp-transfer-process-http-dispatcher") diff --git a/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/transformer/AbstractJsonLdTransformer.java b/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/transformer/AbstractJsonLdTransformer.java index 3debd627815..2ae86871c1c 100644 --- a/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/transformer/AbstractJsonLdTransformer.java +++ b/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/transformer/AbstractJsonLdTransformer.java @@ -21,6 +21,7 @@ import jakarta.json.JsonObjectBuilder; import jakarta.json.JsonString; import jakarta.json.JsonValue; +import org.eclipse.edc.jsonld.spi.JsonLdKeywords; import org.eclipse.edc.transform.spi.TransformerContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -42,9 +43,6 @@ import static java.lang.String.format; import static java.util.Collections.emptyList; import static java.util.stream.Collectors.toList; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.KEYWORDS; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; /** * Base JSON-LD transformer implementation. @@ -162,7 +160,7 @@ protected void transformProperties(Map properties, JsonObjectBuilder } catch (IllegalArgumentException e) { context.problem() .invalidProperty() - .type(VALUE) + .type(JsonLdKeywords.VALUE) .property(k) .value(v != null ? v.toString() : "null") .error(e.getMessage()) @@ -172,12 +170,12 @@ protected void transformProperties(Map properties, JsonObjectBuilder } protected void visitProperties(JsonObject object, BiConsumer consumer) { - object.entrySet().stream().filter(entry -> !KEYWORDS.contains(entry.getKey())).forEach(entry -> consumer.accept(entry.getKey(), entry.getValue())); + object.entrySet().stream().filter(entry -> !JsonLdKeywords.KEYWORDS.contains(entry.getKey())).forEach(entry -> consumer.accept(entry.getKey(), entry.getValue())); } protected void visitProperties(JsonObject object, Function> consumer) { object.entrySet().stream() - .filter(entry -> !KEYWORDS.contains(entry.getKey())) + .filter(entry -> !JsonLdKeywords.KEYWORDS.contains(entry.getKey())) .forEach(entry -> consumer.apply(entry.getKey()).accept(entry.getValue())); } @@ -260,7 +258,7 @@ protected String transformString(JsonValue value, TransformerContext context) { return ((JsonString) value).getString(); } else if (value instanceof JsonObject) { var object = value.asJsonObject(); - return Stream.of(VALUE, ID).map(object::get) + return Stream.of(JsonLdKeywords.VALUE, JsonLdKeywords.ID).map(object::get) .filter(Objects::nonNull) .findFirst().map(it -> transformString(it, context)) .orElseGet(() -> { @@ -293,7 +291,7 @@ protected int transformInt(JsonValue value, TransformerContext context) { if (value instanceof JsonNumber) { return ((JsonNumber) value).intValue(); } else if (value instanceof JsonObject) { - var jsonNumber = value.asJsonObject().getJsonNumber(VALUE); + var jsonNumber = value.asJsonObject().getJsonNumber(JsonLdKeywords.VALUE); return transformInt(jsonNumber, context); } else if (value instanceof JsonArray) { return transformInt(value.asJsonArray().get(0), context); @@ -320,7 +318,7 @@ protected boolean transformBoolean(JsonValue value, TransformerContext context) return false; } if (value instanceof JsonObject) { - return value.asJsonObject().getBoolean(VALUE); + return value.asJsonObject().getBoolean(JsonLdKeywords.VALUE); } else if (value instanceof JsonArray) { return transformBoolean(value.asJsonArray().get(0), context); } else if (TRUE == value.getValueType()) { @@ -444,7 +442,7 @@ protected String nodeId(JsonValue object) { if (object instanceof JsonArray) { return nodeId(object.asJsonArray().get(0)); } else { - var id = object.asJsonObject().get(ID); + var id = object.asJsonObject().get(JsonLdKeywords.ID); return id instanceof JsonString ? ((JsonString) id).getString() : null; } } @@ -456,7 +454,7 @@ protected String nodeValue(JsonValue object) { if (object instanceof JsonArray) { return nodeValue(object.asJsonArray().get(0)); } else { - var value = object.asJsonObject().get(VALUE); + var value = object.asJsonObject().get(JsonLdKeywords.VALUE); return value instanceof JsonString ? ((JsonString) value).getString() : null; } } diff --git a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/offer/ContractOfferResolver.java b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/offer/ContractOfferResolver.java deleted file mode 100644 index 2251a1a681b..00000000000 --- a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/offer/ContractOfferResolver.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2021 Daimler TSS GmbH - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Daimler TSS GmbH - Initial API and Implementation - * - */ - -package org.eclipse.edc.connector.contract.spi.offer; - -import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer; -import org.eclipse.edc.runtime.metamodel.annotation.ExtensionPoint; -import org.jetbrains.annotations.NotNull; - -import java.util.stream.Stream; - -/** - * Resolves contract offers. - */ - -@ExtensionPoint -public interface ContractOfferResolver { - - /** - * Resolves contract offers. - */ - @NotNull - Stream queryContractOffers(ContractOfferQuery query); - -} diff --git a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/agreement/ContractAgreement.java b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/agreement/ContractAgreement.java index fbc351b011d..a2b1c9208a6 100644 --- a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/agreement/ContractAgreement.java +++ b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/agreement/ContractAgreement.java @@ -25,6 +25,7 @@ import java.util.Objects; import static java.util.Objects.requireNonNull; +import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; /** * {@link ContractAgreement} to regulate data transfer between two parties. @@ -32,6 +33,13 @@ @JsonDeserialize(builder = ContractAgreement.Builder.class) public class ContractAgreement { + public static final String CONTRACT_AGREEMENT_TYPE = EDC_NAMESPACE + "ContractAgreement"; + public static final String CONTRACT_AGREEMENT_ASSET_ID = EDC_NAMESPACE + "assetId"; + public static final String CONTRACT_AGREEMENT_PROVIDER_ID = EDC_NAMESPACE + "providerId"; + public static final String CONTRACT_AGREEMENT_CONSUMER_ID = EDC_NAMESPACE + "consumerId"; + public static final String CONTRACT_AGREEMENT_SIGNING_DATE = EDC_NAMESPACE + "contractSigningDate"; + public static final String CONTRACT_AGREEMENT_POLICY = EDC_NAMESPACE + "policy"; + private String id; private String providerId; private String consumerId; diff --git a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractNegotiation.java b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractNegotiation.java index 239ada22b6d..39d2a1d4eef 100644 --- a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractNegotiation.java +++ b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractNegotiation.java @@ -52,6 +52,7 @@ import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.TERMINATING; import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.VERIFIED; import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.VERIFYING; +import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; /** * Represents a contract negotiation. @@ -62,6 +63,19 @@ @JsonTypeName("dataspaceconnector:contractnegotiation") @JsonDeserialize(builder = ContractNegotiation.Builder.class) public class ContractNegotiation extends StatefulEntity { + + // constants used for JSON-LD transformation + public static final String CONTRACT_NEGOTIATION_TYPE = EDC_NAMESPACE + "ContractNegotiation"; + public static final String CONTRACT_NEGOTIATION_AGREEMENT_ID = EDC_NAMESPACE + "contractAgreementId"; + public static final String CONTRACT_NEGOTIATION_COUNTERPARTY_ID = EDC_NAMESPACE + "counterPartyId"; + public static final String CONTRACT_NEGOTIATION_COUNTERPARTY_ADDR = EDC_NAMESPACE + "counterPartyAddress"; + public static final String CONTRACT_NEGOTIATION_ERRORDETAIL = EDC_NAMESPACE + "errorDetail"; + public static final String CONTRACT_NEGOTIATION_PROTOCOL = EDC_NAMESPACE + "protocol"; + public static final String CONTRACT_NEGOTIATION_STATE = EDC_NAMESPACE + "state"; + public static final String CONTRACT_NEGOTIATION_NEG_TYPE = EDC_NAMESPACE + "type"; + public static final String CONTRACT_NEGOTIATION_CALLBACK_ADDR = EDC_NAMESPACE + "callbackAddresses"; + public static final String CONTRACT_NEGOTIATION_CREATED_AT = EDC_NAMESPACE + "createdAt"; + private List callbackAddresses = new ArrayList<>(); private String correlationId; private String counterPartyId; diff --git a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequest.java b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequest.java index ae8bf24f621..c9698e0c7f7 100644 --- a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequest.java +++ b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequest.java @@ -14,28 +14,56 @@ package org.eclipse.edc.connector.contract.spi.types.negotiation; +import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer; import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; + /** - * Represent a request for contract negotiation on the consumer side. It contains the detail of the request in {@link ContractRequestData} + * Represent a request for contract negotiation on the consumer side. */ public class ContractRequest { - private ContractRequestData requestData; - private List callbackAddresses = new ArrayList<>(); + public static final String CONTRACT_REQUEST_TYPE = EDC_NAMESPACE + "ContractRequest"; + public static final String CONNECTOR_ADDRESS = EDC_NAMESPACE + "connectorAddress"; + public static final String PROTOCOL = EDC_NAMESPACE + "protocol"; + @Deprecated(since = "0.1.3") + public static final String CONNECTOR_ID = EDC_NAMESPACE + "connectorId"; + public static final String PROVIDER_ID = EDC_NAMESPACE + "providerId"; + public static final String CONSUMER_ID = EDC_NAMESPACE + "consumerId"; + public static final String OFFER = EDC_NAMESPACE + "offer"; + public static final String CALLBACK_ADDRESSES = EDC_NAMESPACE + "callbackAddresses"; - public ContractRequestData getRequestData() { - return requestData; - } + private String providerId; + private String protocol; + private String counterPartyAddress; + private ContractOffer contractOffer; + private List callbackAddresses = new ArrayList<>(); public List getCallbackAddresses() { return callbackAddresses; } + public String getProviderId() { + return providerId; + } + + public String getProtocol() { + return protocol; + } + + public String getCounterPartyAddress() { + return counterPartyAddress; + } + + public ContractOffer getContractOffer() { + return contractOffer; + } + public static class Builder { private final ContractRequest contractRequest; @@ -47,18 +75,35 @@ public static Builder newInstance() { return new Builder(); } - public Builder requestData(ContractRequestData requestData) { - contractRequest.requestData = requestData; + public Builder callbackAddresses(List callbackAddresses) { + contractRequest.callbackAddresses = callbackAddresses; return this; } - public Builder callbackAddresses(List callbackAddresses) { - contractRequest.callbackAddresses = callbackAddresses; + public Builder providerId(String providerId) { + contractRequest.providerId = providerId; + return this; + } + + public Builder protocol(String protocol) { + contractRequest.protocol = protocol; + return this; + } + + public Builder counterPartyAddress(String counterPartyAddress) { + contractRequest.counterPartyAddress = counterPartyAddress; + return this; + } + + public Builder contractOffer(ContractOffer contractOffer) { + contractRequest.contractOffer = contractOffer; return this; } public ContractRequest build() { - Objects.requireNonNull(contractRequest.requestData, "requestData"); + Objects.requireNonNull(contractRequest.protocol, "protocol"); + Objects.requireNonNull(contractRequest.counterPartyAddress, "counterPartyAddress"); + Objects.requireNonNull(contractRequest.contractOffer, "contractOffer"); return contractRequest; } } diff --git a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequestData.java b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequestData.java deleted file mode 100644 index bdb95a70df8..00000000000 --- a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequestData.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation - * - */ - -package org.eclipse.edc.connector.contract.spi.types.negotiation; - -import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer; - -import java.util.Objects; - -/** - * Represent the data needed for initiating contract negotiation on the consumer side - */ -public class ContractRequestData { - - private String protocol; - @Deprecated(forRemoval = true) - private String connectorId; - private String counterPartyAddress; - private ContractOffer contractOffer; - private String dataSet; - - public String getProtocol() { - return protocol; - } - - public String getCounterPartyAddress() { - return counterPartyAddress; - } - - @Deprecated - public String getConnectorId() { - return connectorId; - } - - - public ContractOffer getContractOffer() { - return contractOffer; - } - - public String getDataSet() { - return dataSet; - } - - public static class Builder { - private final ContractRequestData contractRequestMessage; - - private Builder() { - contractRequestMessage = new ContractRequestData(); - } - - public static Builder newInstance() { - return new Builder(); - } - - public Builder protocol(String protocol) { - contractRequestMessage.protocol = protocol; - return this; - } - - @Deprecated - public Builder connectorId(String connectorId) { - contractRequestMessage.connectorId = connectorId; - return this; - } - - public Builder counterPartyAddress(String counterPartyAddress) { - contractRequestMessage.counterPartyAddress = counterPartyAddress; - return this; - } - - public Builder contractOffer(ContractOffer contractOffer) { - contractRequestMessage.contractOffer = contractOffer; - return this; - } - - public Builder dataSet(String dataSet) { - contractRequestMessage.dataSet = dataSet; - return this; - } - - public ContractRequestData build() { - Objects.requireNonNull(contractRequestMessage.protocol, "protocol"); - Objects.requireNonNull(contractRequestMessage.counterPartyAddress, "callbackAddress"); - Objects.requireNonNull(contractRequestMessage.contractOffer, "contractOffer"); - return contractRequestMessage; - } - } -} diff --git a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/offer/ContractOffer.java b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/offer/ContractOffer.java index 78b3529ecec..19f90190f44 100644 --- a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/offer/ContractOffer.java +++ b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/offer/ContractOffer.java @@ -19,7 +19,6 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import org.eclipse.edc.policy.model.Policy; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -40,22 +39,12 @@ public class ContractOffer { * The offered asset */ private String assetId; - /** - * The participant who provides the offered data - */ - private String providerId; @NotNull public String getId() { return id; } - @Nullable - public String getProviderId() { - return providerId; - } - - @NotNull public String getAssetId() { return assetId; @@ -68,7 +57,7 @@ public Policy getPolicy() { @Override public int hashCode() { - return Objects.hash(id, policy, assetId, providerId); + return Objects.hash(id, policy, assetId); } @Override @@ -80,7 +69,7 @@ public boolean equals(Object o) { return false; } ContractOffer that = (ContractOffer) o; - return Objects.equals(id, that.id) && Objects.equals(policy, that.policy) && Objects.equals(assetId, that.assetId) && Objects.equals(providerId, that.providerId); + return Objects.equals(id, that.id) && Objects.equals(policy, that.policy) && Objects.equals(assetId, that.assetId); } @JsonPOJOBuilder(withPrefix = "") @@ -102,11 +91,6 @@ public Builder id(String id) { return this; } - public Builder providerId(String providerId) { - contractOffer.providerId = providerId; - return this; - } - public Builder assetId(String assetId) { contractOffer.assetId = assetId; return this; diff --git a/system-tests/e2e-test-fixtures/src/testFixtures/java/org/eclipse/edc/test/system/utils/Participant.java b/system-tests/e2e-test-fixtures/src/testFixtures/java/org/eclipse/edc/test/system/utils/Participant.java index 31193725c9c..eb7170bf6e6 100644 --- a/system-tests/e2e-test-fixtures/src/testFixtures/java/org/eclipse/edc/test/system/utils/Participant.java +++ b/system-tests/e2e-test-fixtures/src/testFixtures/java/org/eclipse/edc/test/system/utils/Participant.java @@ -223,9 +223,7 @@ public JsonObject getDatasetForAsset(Participant provider, String assetId) { public String negotiateContract(Participant provider, String offerId, String assetId, JsonObject policy) { var requestBody = createObjectBuilder() .add(CONTEXT, createObjectBuilder().add(EDC_PREFIX, EDC_NAMESPACE)) - .add(TYPE, "NegotiationInitiateRequestDto") - .add("connectorId", provider.id) - .add("consumerId", id) + .add(TYPE, "ContractRequestDto") .add("providerId", provider.id) .add("connectorAddress", provider.protocolEndpoint.url.toString()) .add("protocol", DSP_PROTOCOL) diff --git a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractNegotiationApiEndToEndTest.java b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractNegotiationApiEndToEndTest.java index 2ad92505b5a..6a116ddf4e9 100644 --- a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractNegotiationApiEndToEndTest.java +++ b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractNegotiationApiEndToEndTest.java @@ -37,6 +37,7 @@ import static jakarta.json.Json.createObjectBuilder; import static java.util.UUID.randomUUID; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.REQUESTED; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; @@ -50,6 +51,8 @@ @EndToEndTest public class ContractNegotiationApiEndToEndTest extends BaseManagementApiEndToEndTest { + private final String protocolUrl = "http://localhost:" + PROTOCOL_PORT + "/protocol"; + @Test void getAll() { var store = controlPlane.getContext().getService(ContractNegotiationStore.class); @@ -65,9 +68,7 @@ void getAll() { .body("size()", is(2)) .extract().jsonPath(); - // must use bracket notation when using keys with a colon - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors - assertThat(jsonPath.getString("[0]['edc:counterPartyAddress']")).isEqualTo("address"); + assertThat(jsonPath.getString("[0]['edc:counterPartyAddress']")).isEqualTo(protocolUrl); assertThat(jsonPath.getString("[0].@id")).isIn("cn1", "cn2"); assertThat(jsonPath.getString("[1].@id")).isIn("cn1", "cn2"); assertThat(jsonPath.getString("[0]['edc:protocol']")).isEqualTo("dataspace-protocol-http"); @@ -130,12 +131,10 @@ void initiateNegotiation() { var requestJson = createObjectBuilder() .add(CONTEXT, createObjectBuilder().add(EDC_PREFIX, EDC_NAMESPACE)) - .add(TYPE, "NegotiationInitiateRequestDto") + .add(TYPE, "ContractRequest") .add("connectorAddress", "test-address") .add("protocol", "test-protocol") - .add("connectorId", "test-conn-id") .add("providerId", "test-provider-id") - .add("consumerId", "test-consumer-id") .add("callbackAddresses", createCallbackAddress()) .add("offer", createObjectBuilder() .add("offerId", "test-offer-id") @@ -197,13 +196,15 @@ private ContractNegotiation createContractNegotiation(String negotiationId) { private ContractNegotiation.Builder createContractNegotiationBuilder(String negotiationId) { return ContractNegotiation.Builder.newInstance() .id(negotiationId) + .correlationId(negotiationId) .counterPartyId(randomUUID().toString()) - .counterPartyAddress("address") + .counterPartyAddress(protocolUrl) .callbackAddresses(List.of(CallbackAddress.Builder.newInstance() .uri("local://test") .events(Set.of("test-event1", "test-event2")) .build())) .protocol("dataspace-protocol-http") + .state(REQUESTED.code()) .contractOffer(contractOfferBuilder().build()); } diff --git a/system-tests/telemetry/telemetry-test-runner/src/test/java/org/eclipse/edc/test/e2e/tracing/TracingEndToEndTest.java b/system-tests/telemetry/telemetry-test-runner/src/test/java/org/eclipse/edc/test/e2e/tracing/TracingEndToEndTest.java index 9febed30fa4..a3984c0d5c9 100644 --- a/system-tests/telemetry/telemetry-test-runner/src/test/java/org/eclipse/edc/test/e2e/tracing/TracingEndToEndTest.java +++ b/system-tests/telemetry/telemetry-test-runner/src/test/java/org/eclipse/edc/test/e2e/tracing/TracingEndToEndTest.java @@ -72,10 +72,9 @@ void transferFile_testTraces() { traceCollectorServer.when(HttpRequest.request()).respond(HttpResponse.response().withStatusCode(200)); var requestJson = Json.createObjectBuilder() - .add(TYPE, EDC_NAMESPACE + "NegotiationInitiateRequestDto") + .add(TYPE, EDC_NAMESPACE + "ContractRequest") .add(EDC_NAMESPACE + "connectorAddress", "test-address") .add(EDC_NAMESPACE + "protocol", "test-protocol") - .add(EDC_NAMESPACE + "connectorId", "test-conn-id") .add(EDC_NAMESPACE + "providerId", "test-provider-id") .add(EDC_NAMESPACE + "consumerId", "test-consumer-id") .add(EDC_NAMESPACE + "offer", Json.createObjectBuilder()