diff --git a/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessEventDispatchTest.java b/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessEventDispatchTest.java index f2b2a8af1a7..1475ea2b8e8 100644 --- a/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessEventDispatchTest.java +++ b/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessEventDispatchTest.java @@ -224,7 +224,7 @@ private TransferRequest createTransferRequest() { .assetId("assetId") .dataDestination(DataAddress.Builder.newInstance().type("any").build()) .protocol("test") - .connectorAddress("http://an/address") + .counterPartyAddress("http://an/address") .contractId("contractId") .build(); } diff --git a/core/control-plane/transfer-core/src/main/java/org/eclipse/edc/connector/transfer/process/TransferProcessManagerImpl.java b/core/control-plane/transfer-core/src/main/java/org/eclipse/edc/connector/transfer/process/TransferProcessManagerImpl.java index f148d7dfb4a..01e56a04d45 100644 --- a/core/control-plane/transfer-core/src/main/java/org/eclipse/edc/connector/transfer/process/TransferProcessManagerImpl.java +++ b/core/control-plane/transfer-core/src/main/java/org/eclipse/edc/connector/transfer/process/TransferProcessManagerImpl.java @@ -132,7 +132,7 @@ public StatusResult initiateConsumerRequest(TransferRequest tra .assetId(transferRequest.getAssetId()) .connectorId(transferRequest.getConnectorId()) .dataDestination(transferRequest.getDataDestination()) - .connectorAddress(transferRequest.getConnectorAddress()) + .connectorAddress(transferRequest.getCounterPartyAddress()) .contractId(transferRequest.getContractId()) .destinationType(transferRequest.getDataDestination().getType()) .protocol(transferRequest.getProtocol()) 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 4b5078f1a02..ad3de7c9eef 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 @@ -58,12 +58,12 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - transformerRegistry.register(new JsonObjectToCatalogRequestTransformer(context.getMonitor())); + transformerRegistry.register(new JsonObjectToCatalogRequestTransformer()); transformerRegistry.register(new JsonObjectToDatasetRequestTransformer()); webService.registerResource(config.getContextAlias(), new CatalogApiController(service, transformerRegistry, validatorRegistry)); - validatorRegistry.register(CATALOG_REQUEST_TYPE, CatalogRequestValidator.instance()); + validatorRegistry.register(CATALOG_REQUEST_TYPE, CatalogRequestValidator.instance(context.getMonitor())); validatorRegistry.register(DATASET_REQUEST_TYPE, DatasetRequestValidator.instance()); } } diff --git a/extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/api/management/catalog/transform/JsonObjectToCatalogRequestTransformer.java b/extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/api/management/catalog/transform/JsonObjectToCatalogRequestTransformer.java index 1da549348f4..fe68ae67976 100644 --- a/extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/api/management/catalog/transform/JsonObjectToCatalogRequestTransformer.java +++ b/extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/api/management/catalog/transform/JsonObjectToCatalogRequestTransformer.java @@ -17,7 +17,6 @@ import jakarta.json.JsonObject; import org.eclipse.edc.catalog.spi.CatalogRequest; import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; -import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.query.QuerySpec; import org.eclipse.edc.transform.spi.TransformerContext; import org.jetbrains.annotations.NotNull; @@ -25,31 +24,22 @@ import java.util.Optional; -import static java.lang.String.format; import static org.eclipse.edc.catalog.spi.CatalogRequest.CATALOG_REQUEST_COUNTER_PARTY_ADDRESS; import static org.eclipse.edc.catalog.spi.CatalogRequest.CATALOG_REQUEST_PROTOCOL; import static org.eclipse.edc.catalog.spi.CatalogRequest.CATALOG_REQUEST_PROVIDER_URL; import static org.eclipse.edc.catalog.spi.CatalogRequest.CATALOG_REQUEST_QUERY_SPEC; -import static org.eclipse.edc.catalog.spi.CatalogRequest.CATALOG_REQUEST_TYPE; public class JsonObjectToCatalogRequestTransformer extends AbstractJsonLdTransformer { - private final Monitor monitor; - - public JsonObjectToCatalogRequestTransformer(Monitor monitor) { + public JsonObjectToCatalogRequestTransformer() { super(JsonObject.class, CatalogRequest.class); - this.monitor = monitor; } @Override public @Nullable CatalogRequest transform(@NotNull JsonObject object, @NotNull TransformerContext context) { var counterPartyAddress = Optional.of(object) .map(it -> it.get(CATALOG_REQUEST_COUNTER_PARTY_ADDRESS)) - .orElseGet(() -> { - monitor.warning(format("The attribute %s has been deprecated in type %s, please use %s", - CATALOG_REQUEST_PROVIDER_URL, CATALOG_REQUEST_TYPE, CATALOG_REQUEST_COUNTER_PARTY_ADDRESS)); - return object.get(CATALOG_REQUEST_PROVIDER_URL); - }); + .orElseGet(() -> object.get(CATALOG_REQUEST_PROVIDER_URL)); var querySpec = Optional.of(object) .map(it -> it.get(CATALOG_REQUEST_QUERY_SPEC)) diff --git a/extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/api/management/catalog/validation/CatalogRequestValidator.java b/extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/api/management/catalog/validation/CatalogRequestValidator.java index aa9ab642a42..2605e42935f 100644 --- a/extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/api/management/catalog/validation/CatalogRequestValidator.java +++ b/extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/api/management/catalog/validation/CatalogRequestValidator.java @@ -15,6 +15,7 @@ package org.eclipse.edc.connector.api.management.catalog.validation; import jakarta.json.JsonObject; +import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.validator.jsonobject.JsonLdPath; import org.eclipse.edc.validator.jsonobject.JsonObjectValidator; import org.eclipse.edc.validator.jsonobject.validators.MandatoryValue; @@ -22,36 +23,42 @@ import org.eclipse.edc.validator.spi.ValidationResult; import org.eclipse.edc.validator.spi.Validator; +import static java.lang.String.format; import static org.eclipse.edc.catalog.spi.CatalogRequest.CATALOG_REQUEST_COUNTER_PARTY_ADDRESS; import static org.eclipse.edc.catalog.spi.CatalogRequest.CATALOG_REQUEST_PROTOCOL; import static org.eclipse.edc.catalog.spi.CatalogRequest.CATALOG_REQUEST_PROVIDER_URL; import static org.eclipse.edc.catalog.spi.CatalogRequest.CATALOG_REQUEST_QUERY_SPEC; +import static org.eclipse.edc.catalog.spi.CatalogRequest.CATALOG_REQUEST_TYPE; public class CatalogRequestValidator { - public static Validator instance() { + public static Validator instance(Monitor monitor) { return JsonObjectValidator.newValidator() - .verify(MandatoryCounterPartyAddressOrProviderUrl::new) + .verify(path -> new MandatoryCounterPartyAddressOrProviderUrl(path, monitor)) .verify(CATALOG_REQUEST_PROTOCOL, MandatoryValue::new) .verifyObject(CATALOG_REQUEST_QUERY_SPEC, QuerySpecValidator::instance) .build(); } - private record MandatoryCounterPartyAddressOrProviderUrl(JsonLdPath path) implements Validator { - + /** + * This custom validator can be removed once `providerUrl` is deleted and exists only for legacy reasons + */ + private record MandatoryCounterPartyAddressOrProviderUrl(JsonLdPath path, Monitor monitor) implements Validator { @Override public ValidationResult validate(JsonObject input) { var counterPartyAddress = new MandatoryValue(path.append(CATALOG_REQUEST_COUNTER_PARTY_ADDRESS)); - var providerUrl = new MandatoryValue(path.append(CATALOG_REQUEST_PROVIDER_URL)); - var validateCounterParty = counterPartyAddress.validate(input); + if (validateCounterParty.succeeded()) { + return ValidationResult.success(); + } + var providerUrl = new MandatoryValue(path.append(CATALOG_REQUEST_PROVIDER_URL)); var validateProviderUrl = providerUrl.validate(input); - - if (validateCounterParty.succeeded() || validateProviderUrl.succeeded()) { + if (validateProviderUrl.succeeded()) { + monitor.warning(format("The attribute %s has been deprecated in type %s, please use %s", + CATALOG_REQUEST_PROVIDER_URL, CATALOG_REQUEST_TYPE, CATALOG_REQUEST_COUNTER_PARTY_ADDRESS)); return ValidationResult.success(); - } else { - return validateCounterParty; } + return validateCounterParty; } } } diff --git a/extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/api/management/catalog/CatalogApiTest.java b/extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/api/management/catalog/CatalogApiTest.java index a98d7108a61..1332e70b99f 100644 --- a/extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/api/management/catalog/CatalogApiTest.java +++ b/extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/api/management/catalog/CatalogApiTest.java @@ -28,6 +28,7 @@ import org.eclipse.edc.jsonld.JsonLdExtension; import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.jsonld.util.JacksonJsonLd; +import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -55,14 +56,14 @@ class CatalogApiTest { @BeforeEach void setUp() { - transformer.register(new JsonObjectToCatalogRequestTransformer(mock())); + transformer.register(new JsonObjectToCatalogRequestTransformer()); transformer.register(new JsonObjectToDatasetRequestTransformer()); transformer.register(new JsonObjectToQuerySpecTransformer()); } @Test void catalogRequestExample() throws JsonProcessingException { - var validator = CatalogRequestValidator.instance(); + var validator = CatalogRequestValidator.instance(mock(Monitor.class)); var jsonObject = objectMapper.readValue(CATALOG_REQUEST_EXAMPLE, JsonObject.class); assertThat(jsonObject).isNotNull(); diff --git a/extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/api/management/catalog/transform/JsonObjectToCatalogRequestTransformerTest.java b/extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/api/management/catalog/transform/JsonObjectToCatalogRequestTransformerTest.java index 413895496ed..aa6b6727af5 100644 --- a/extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/api/management/catalog/transform/JsonObjectToCatalogRequestTransformerTest.java +++ b/extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/api/management/catalog/transform/JsonObjectToCatalogRequestTransformerTest.java @@ -17,7 +17,6 @@ import jakarta.json.Json; import jakarta.json.JsonObject; import org.eclipse.edc.catalog.spi.CatalogRequest; -import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.query.QuerySpec; import org.eclipse.edc.transform.spi.TransformerContext; import org.junit.jupiter.api.Test; @@ -30,7 +29,6 @@ import static org.eclipse.edc.catalog.spi.CatalogRequest.CATALOG_REQUEST_TYPE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -40,8 +38,7 @@ class JsonObjectToCatalogRequestTransformerTest { private final TransformerContext context = mock(); - private final Monitor monitor = mock(); - private final JsonObjectToCatalogRequestTransformer transformer = new JsonObjectToCatalogRequestTransformer(monitor); + private final JsonObjectToCatalogRequestTransformer transformer = new JsonObjectToCatalogRequestTransformer(); @Test void types() { @@ -89,7 +86,6 @@ void transform_shouldUseProviderId_whenCounterPartyAddressIsMissing() { assertThat(result.getCounterPartyAddress()).isEqualTo("http://provider/url"); assertThat(result.getQuerySpec()).isEqualTo(querySpec); verify(context).transform(querySpecJson, QuerySpec.class); - verify(monitor).warning(anyString()); } @Test diff --git a/extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/api/management/catalog/validation/CatalogRequestValidatorTest.java b/extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/api/management/catalog/validation/CatalogRequestValidatorTest.java index cbeba1f0fd5..02e8c00492b 100644 --- a/extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/api/management/catalog/validation/CatalogRequestValidatorTest.java +++ b/extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/api/management/catalog/validation/CatalogRequestValidatorTest.java @@ -17,6 +17,7 @@ import jakarta.json.Json; import jakarta.json.JsonArrayBuilder; import jakarta.json.JsonObject; +import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.validator.spi.ValidationFailure; import org.eclipse.edc.validator.spi.Validator; import org.eclipse.edc.validator.spi.Violation; @@ -33,10 +34,14 @@ import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; import static org.eclipse.edc.spi.query.QuerySpec.EDC_QUERY_SPEC_SORT_FIELD; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; class CatalogRequestValidatorTest { - private final Validator validator = CatalogRequestValidator.instance(); + private final Monitor monitor = mock(); + private final Validator validator = CatalogRequestValidator.instance(monitor); @Test void shouldSucceed_whenInputIsValid() { @@ -60,6 +65,7 @@ void shouldSucceed_whenDeprecatedProviderUrlIsUsed() { var result = validator.validate(input); assertThat(result).isSucceeded(); + verify(monitor).warning(anyString()); } @Test 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 10055bb7582..967e011a5d2 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 @@ -127,9 +127,12 @@ record ContractRequestSchema( String type, @Schema(requiredMode = REQUIRED) String protocol, - @Schema(requiredMode = REQUIRED) + @Deprecated(since = "0.3.2") + @Schema(deprecated = true, description = "please use counterPartyAddress instead") String connectorAddress, @Schema(requiredMode = REQUIRED) + String counterPartyAddress, + @Schema(requiredMode = REQUIRED) String providerId, ContractOfferDescriptionSchema offer, List callbackAddresses) { @@ -139,7 +142,7 @@ record ContractRequestSchema( { "@context": { "@vocab": "https://w3id.org/edc/v0.0.1/ns/" }, "@type": "https://w3id.org/edc/v0.0.1/ns/ContractRequest", - "connectorAddress": "http://provider-address", + "counterPartyAddress": "http://provider-address", "protocol": "dataspace-protocol-http", "providerId": "provider-id", "offer": { 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 a9cc1526a63..c758abbb8b0 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 @@ -72,7 +72,7 @@ public void initialize(ServiceExtensionContext context) { transformerRegistry.register(new JsonObjectFromContractNegotiationTransformer(factory)); transformerRegistry.register(new JsonObjectFromNegotiationStateTransformer(factory)); - validatorRegistry.register(CONTRACT_REQUEST_TYPE, ContractRequestValidator.instance()); + validatorRegistry.register(CONTRACT_REQUEST_TYPE, ContractRequestValidator.instance(context.getMonitor())); validatorRegistry.register(TERMINATE_NEGOTIATION_TYPE, TerminateNegotiationValidator.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/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 index c0924e17f21..1e3c85d583e 100644 --- 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 @@ -28,6 +28,7 @@ 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.CONTRACT_REQUEST_COUNTER_PARTY_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; @@ -42,7 +43,7 @@ public JsonObjectToContractRequestTransformer() { 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)) + .counterPartyAddress(counterPartyAddressOrConnectorAddress(jsonObject, context)) .protocol(transformString(jsonObject.get(PROTOCOL), context)); var contractOfferDescription = transformObject(jsonObject.get(OFFER), ContractOfferDescription.class, context); @@ -69,8 +70,15 @@ private String getProviderId(@NotNull JsonObject jsonObject, @NotNull Transforme return transformString(providerId, context); } - return transformString(jsonObject.get(CONNECTOR_ADDRESS), context); + return counterPartyAddressOrConnectorAddress(jsonObject, context); } + /** + * This method can be removed once `connectorAddress` is deleted and exists only for legacy reasons + */ + private String counterPartyAddressOrConnectorAddress(@NotNull JsonObject jsonObject, @NotNull TransformerContext context) { + var counterPartyAddress = transformString(jsonObject.get(CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS), context); + return counterPartyAddress != null ? counterPartyAddress : 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/validation/ContractRequestValidator.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/ContractRequestValidator.java index db1da5fdcb2..eb702e6e56f 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/ContractRequestValidator.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/ContractRequestValidator.java @@ -15,22 +15,28 @@ package org.eclipse.edc.connector.api.management.contractnegotiation.validation; import jakarta.json.JsonObject; +import org.eclipse.edc.spi.monitor.Monitor; +import org.eclipse.edc.validator.jsonobject.JsonLdPath; import org.eclipse.edc.validator.jsonobject.JsonObjectValidator; import org.eclipse.edc.validator.jsonobject.validators.MandatoryObject; import org.eclipse.edc.validator.jsonobject.validators.MandatoryValue; +import org.eclipse.edc.validator.spi.ValidationResult; import org.eclipse.edc.validator.spi.Validator; +import static java.lang.String.format; 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.CONNECTOR_ADDRESS; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.CONTRACT_REQUEST_TYPE; 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 ContractRequestValidator { - public static Validator instance() { + public static Validator instance(Monitor monitor) { return JsonObjectValidator.newValidator() - .verify(CONNECTOR_ADDRESS, MandatoryValue::new) + .verify(path -> new MandatoryCounterPartyAddressOrConnectorAddress(path, monitor)) .verify(PROTOCOL, MandatoryValue::new) .verify(OFFER, MandatoryObject::new) .verifyObject(OFFER, v -> v @@ -40,4 +46,27 @@ public static Validator instance() { ) .build(); } + + /** + * This custom validator can be removed once `connectorAddress` is deleted and exists only for legacy reasons + */ + private record MandatoryCounterPartyAddressOrConnectorAddress(JsonLdPath path, Monitor monitor) implements Validator { + + @Override + public ValidationResult validate(JsonObject input) { + var counterPartyAddress = new MandatoryValue(path.append(CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS)); + var validateCounterParty = counterPartyAddress.validate(input); + if (validateCounterParty.succeeded()) { + return ValidationResult.success(); + } + var connectorAddress = new MandatoryValue(path.append(CONNECTOR_ADDRESS)); + var validateConnectorAddress = connectorAddress.validate(input); + if (validateConnectorAddress.succeeded()) { + monitor.warning(format("The attribute %s has been deprecated in type %s, please use %s", + CONNECTOR_ADDRESS, CONTRACT_REQUEST_TYPE, CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS)); + return ValidationResult.success(); + } + return validateCounterParty; + } + } } 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 index 5d35d3e832c..0b341626480 100644 --- 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 @@ -30,6 +30,7 @@ import org.eclipse.edc.jsonld.JsonLdExtension; import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.jsonld.util.JacksonJsonLd; +import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -44,6 +45,7 @@ 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; +import static org.mockito.Mockito.mock; class ContractNegotiationApiTest { @@ -62,7 +64,7 @@ void setUp() { @Test void contractRequestExample() throws JsonProcessingException { - var validator = ContractRequestValidator.instance(); + var validator = ContractRequestValidator.instance(mock(Monitor.class)); var jsonObject = objectMapper.readValue(CONTRACT_REQUEST_EXAMPLE, JsonObject.class); assertThat(jsonObject).isNotNull(); @@ -72,9 +74,7 @@ void contractRequestExample() throws JsonProcessingException { .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(); - })); + .satisfies(transformed -> assertThat(transformed.getProviderId()).isNotBlank())); } @Test 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 index 67b456bd6ed..b78e5211ae8 100644 --- 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 @@ -36,7 +36,7 @@ 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.CONTRACT_REQUEST_COUNTER_PARTY_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; @@ -68,7 +68,7 @@ void setUp() { void transform() { var jsonObject = Json.createObjectBuilder() .add(TYPE, ContractRequest.CONTRACT_REQUEST_TYPE) - .add(CONNECTOR_ADDRESS, "test-address") + .add(CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS, "test-address") .add(PROTOCOL, "test-protocol") .add(PROVIDER_ID, "test-provider-id") .add(CALLBACK_ADDRESSES, createCallbackAddress()) @@ -109,10 +109,10 @@ void transform() { } @Test - void transform_shouldSetProviderIdAsConnectorAddress_whenProviderIdNotDefined() { + void transform_shouldSetProviderIdAsCounterPartyAddress_whenProviderIdNotDefined() { var jsonObject = Json.createObjectBuilder() .add(TYPE, ContractRequest.CONTRACT_REQUEST_TYPE) - .add(CONNECTOR_ADDRESS, "test-address") + .add(CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS, "test-address") .add(PROTOCOL, "test-protocol") .add(OFFER, Json.createObjectBuilder() .add(OFFER_ID, "test-offer-id") diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/ContractRequestValidatorTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/ContractRequestValidatorTest.java index 0e064551ca3..1d5c9d4d4cc 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/ContractRequestValidatorTest.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/validation/ContractRequestValidatorTest.java @@ -17,6 +17,7 @@ import jakarta.json.Json; import jakarta.json.JsonArrayBuilder; import jakarta.json.JsonObject; +import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.validator.spi.ValidationFailure; import org.eclipse.edc.validator.spi.Validator; import org.eclipse.edc.validator.spi.Violation; @@ -30,20 +31,25 @@ 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.CONNECTOR_ADDRESS; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest.CONTRACT_REQUEST_COUNTER_PARTY_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; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; class ContractRequestValidatorTest { - private final Validator validator = ContractRequestValidator.instance(); + private final Monitor monitor = mock(); + private final Validator validator = ContractRequestValidator.instance(monitor); @Test void shouldSuccess_whenObjectIsValid() { var input = Json.createObjectBuilder() - .add(CONNECTOR_ADDRESS, value("http://connector-address")) + .add(CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS, value("http://connector-address")) .add(PROTOCOL, value("protocol")) .add(PROVIDER_ID, value("connector-id")) .add(OFFER, createArrayBuilder().add(createObjectBuilder() @@ -66,7 +72,7 @@ void shouldFail_whenMandatoryPropertiesAreMissing() { assertThat(result).isFailed().extracting(ValidationFailure::getViolations).asInstanceOf(list(Violation.class)) .isNotEmpty() - .anySatisfy(violation -> assertThat(violation.path()).isEqualTo(CONNECTOR_ADDRESS)) + .anySatisfy(violation -> assertThat(violation.path()).isEqualTo(CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS)) .anySatisfy(violation -> assertThat(violation.path()).isEqualTo(PROTOCOL)) .anySatisfy(violation -> assertThat(violation.path()).isEqualTo(OFFER)); } @@ -74,7 +80,7 @@ void shouldFail_whenMandatoryPropertiesAreMissing() { @Test void shouldFail_whenOfferMandatoryPropertiesAreMissing() { var input = Json.createObjectBuilder() - .add(CONNECTOR_ADDRESS, value("http://connector-address")) + .add(CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS, value("http://connector-address")) .add(PROTOCOL, value("protocol")) .add(PROVIDER_ID, value("connector-id")) .add(OFFER, createArrayBuilder().add(createObjectBuilder())) @@ -89,6 +95,24 @@ void shouldFail_whenOfferMandatoryPropertiesAreMissing() { .anySatisfy(violation -> assertThat(violation.path()).isEqualTo(OFFER + "/" + POLICY)); } + @Test + void shouldSucceed_whenDeprecatedConnectorAddressIsUsed() { + var input = Json.createObjectBuilder() + .add(CONNECTOR_ADDRESS, value("http://connector-address")) + .add(PROTOCOL, value("protocol")) + .add(PROVIDER_ID, value("connector-id")) + .add(OFFER, createArrayBuilder().add(createObjectBuilder() + .add(OFFER_ID, value("offerId")) + .add(ASSET_ID, value("offerId")) + .add(POLICY, createArrayBuilder().add(createObjectBuilder())) + )) + .build(); + + var result = validator.validate(input); + assertThat(result).isSucceeded(); + verify(monitor).warning(anyString()); + } + private JsonArrayBuilder value(String value) { return createArrayBuilder().add(createObjectBuilder().add(VALUE, value)); } diff --git a/extensions/control-plane/api/management-api/management-api-test-fixtures/src/testFixtures/java/org/eclipse/edc/test/system/utils/Participant.java b/extensions/control-plane/api/management-api/management-api-test-fixtures/src/testFixtures/java/org/eclipse/edc/test/system/utils/Participant.java index 0f14707474f..2d6d308bcc2 100644 --- a/extensions/control-plane/api/management-api/management-api-test-fixtures/src/testFixtures/java/org/eclipse/edc/test/system/utils/Participant.java +++ b/extensions/control-plane/api/management-api/management-api-test-fixtures/src/testFixtures/java/org/eclipse/edc/test/system/utils/Participant.java @@ -247,7 +247,7 @@ public String negotiateContract(Participant provider, String offerId, String ass .add(CONTEXT, createObjectBuilder().add(VOCAB, EDC_NAMESPACE)) .add(TYPE, "ContractRequestDto") .add("providerId", provider.id) - .add("connectorAddress", provider.protocolEndpoint.url.toString()) + .add("counterPartyAddress", provider.protocolEndpoint.url.toString()) .add("protocol", DSP_PROTOCOL) .add("offer", createObjectBuilder() .add("offerId", offerId) @@ -292,7 +292,7 @@ public String initiateTransfer(Participant provider, String contractAgreementId, .add("assetId", assetId) .add("contractId", contractAgreementId) .add("connectorId", provider.id) - .add("connectorAddress", provider.protocolEndpoint.url.toString()) + .add("counterPartyAddress", provider.protocolEndpoint.url.toString()) .add("privateProperties", privateProperties) .build(); diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApi.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApi.java index 52674d7b0d6..6d15bbbcb8b 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApi.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApi.java @@ -128,9 +128,12 @@ record TransferRequestSchema( String type, @Schema(requiredMode = REQUIRED) String protocol, - @Schema(requiredMode = REQUIRED) + @Deprecated(since = "0.3.2") + @Schema(deprecated = true, description = "please use counterPartyAddress instead") String connectorAddress, @Schema(requiredMode = REQUIRED) + String counterPartyAddress, + @Schema(requiredMode = REQUIRED) String connectorId, @Schema(requiredMode = REQUIRED) String contractId, @@ -149,7 +152,7 @@ record TransferRequestSchema( "@context": { "@vocab": "https://w3id.org/edc/v0.0.1/ns/" }, "@type": "https://w3id.org/edc/v0.0.1/ns/TransferRequest", "protocol": "dataspace-protocol-http", - "connectorAddress": "http://provider-address", + "counterPartyAddress": "http://provider-address", "connectorId": "provider-id", "contractId": "contract-id", "assetId": "asset-id", 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 5252d16236d..20df11c1509 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 @@ -69,7 +69,7 @@ public void initialize(ServiceExtensionContext context) { transformerRegistry.register(new JsonObjectToTerminateTransferTransformer()); transformerRegistry.register(new JsonObjectToTransferRequestTransformer()); - validatorRegistry.register(TRANSFER_REQUEST_TYPE, TransferRequestValidator.instance()); + validatorRegistry.register(TRANSFER_REQUEST_TYPE, TransferRequestValidator.instance(context.getMonitor())); validatorRegistry.register(TERMINATE_TRANSFER_TYPE, TerminateTransferValidator.instance()); var newController = new TransferProcessApiController(context.getMonitor(), service, transformerRegistry, validatorRegistry); diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestTransformer.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestTransformer.java index d56a53b438d..433fd61d13d 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestTransformer.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestTransformer.java @@ -37,6 +37,7 @@ import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_CONNECTOR_ADDRESS; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_CONNECTOR_ID; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_CONTRACT_ID; +import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_COUNTER_PARTY_ADDRESS; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_DATA_DESTINATION; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_PRIVATE_PROPERTIES; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_PROPERTIES; @@ -54,7 +55,7 @@ public JsonObjectToTransferRequestTransformer() { builder.id(nodeId(input)); visitProperties(input, k -> switch (k) { - case TRANSFER_REQUEST_CONNECTOR_ADDRESS -> v -> builder.connectorAddress(transformString(v, context)); + case TRANSFER_REQUEST_CONNECTOR_ADDRESS, TRANSFER_REQUEST_COUNTER_PARTY_ADDRESS -> v -> builder.counterPartyAddress(transformString(v, context)); case TRANSFER_REQUEST_CONTRACT_ID -> (v) -> builder.contractId(transformString(v, context)); case TRANSFER_REQUEST_DATA_DESTINATION -> v -> builder.dataDestination(transformObject(v, DataAddress.class, context)); @@ -91,9 +92,7 @@ private void transformProperties(JsonValue jsonValue, Consumer(); - visitProperties(jsonObject, (k, v) -> { - properties.put(k, transformString(v, context)); - }); + visitProperties(jsonObject, (k, v) -> properties.put(k, transformString(v, context))); consumer.accept(properties); } @@ -114,9 +113,7 @@ private void transformStringProperties(JsonValue jsonValue, Consumer(); - visitProperties(jsonObject, (k, v) -> { - properties.put(k, transformString(v, context)); - }); + visitProperties(jsonObject, (k, v) -> properties.put(k, transformString(v, context))); consumer.accept(properties); } } diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/validation/TransferRequestValidator.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/validation/TransferRequestValidator.java index 08474d68656..5b7bfb18b38 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/validation/TransferRequestValidator.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/validation/TransferRequestValidator.java @@ -16,25 +16,31 @@ import jakarta.json.JsonObject; import org.eclipse.edc.api.validation.DataAddressValidator; +import org.eclipse.edc.spi.monitor.Monitor; +import org.eclipse.edc.validator.jsonobject.JsonLdPath; import org.eclipse.edc.validator.jsonobject.JsonObjectValidator; import org.eclipse.edc.validator.jsonobject.validators.MandatoryObject; import org.eclipse.edc.validator.jsonobject.validators.MandatoryValue; import org.eclipse.edc.validator.jsonobject.validators.OptionalIdNotBlank; +import org.eclipse.edc.validator.spi.ValidationResult; import org.eclipse.edc.validator.spi.Validator; +import static java.lang.String.format; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_ASSET_ID; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_CONNECTOR_ADDRESS; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_CONNECTOR_ID; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_CONTRACT_ID; +import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_COUNTER_PARTY_ADDRESS; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_DATA_DESTINATION; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_PROTOCOL; +import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_TYPE; public class TransferRequestValidator { - public static Validator instance() { + public static Validator instance(Monitor monitor) { return JsonObjectValidator.newValidator() .verifyId(OptionalIdNotBlank::new) - .verify(TRANSFER_REQUEST_CONNECTOR_ADDRESS, MandatoryValue::new) + .verify(path -> new MandatoryCounterPartyAddressOrConnectorAddress(path, monitor)) .verify(TRANSFER_REQUEST_CONTRACT_ID, MandatoryValue::new) .verify(TRANSFER_REQUEST_PROTOCOL, MandatoryValue::new) .verify(TRANSFER_REQUEST_CONNECTOR_ID, MandatoryValue::new) @@ -43,4 +49,28 @@ public static Validator instance() { .verifyObject(TRANSFER_REQUEST_DATA_DESTINATION, DataAddressValidator::instance) .build(); } + + /** + * This custom validator can be removed once `connectorAddress` is deleted and exists only for legacy reasons + */ + private record MandatoryCounterPartyAddressOrConnectorAddress(JsonLdPath path, Monitor monitor) implements Validator { + + @Override + public ValidationResult validate(JsonObject input) { + var counterPartyAddress = new MandatoryValue(path.append(TRANSFER_REQUEST_COUNTER_PARTY_ADDRESS)); + var validateCounterParty = counterPartyAddress.validate(input); + if (validateCounterParty.succeeded()) { + return ValidationResult.success(); + } + var connectorAddress = new MandatoryValue(path.append(TRANSFER_REQUEST_CONNECTOR_ADDRESS)); + var validateConnectorAddress = connectorAddress.validate(input); + if (validateConnectorAddress.succeeded()) { + monitor.warning(format("The attribute %s has been deprecated in type %s, please use %s", + TRANSFER_REQUEST_CONNECTOR_ADDRESS, TRANSFER_REQUEST_TYPE, TRANSFER_REQUEST_COUNTER_PARTY_ADDRESS)); + return ValidationResult.success(); + } + return validateCounterParty; + } + } + } diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiTest.java b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiTest.java index 581b5394a20..11dc63f6e1f 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiTest.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiTest.java @@ -30,6 +30,7 @@ import org.eclipse.edc.jsonld.JsonLdExtension; import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.jsonld.util.JacksonJsonLd; +import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -60,6 +61,7 @@ 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; +import static org.mockito.Mockito.mock; class TransferProcessApiTest { @@ -78,7 +80,7 @@ void setUp() { @Test void transferRequestExample() throws JsonProcessingException { - var validator = TransferRequestValidator.instance(); + var validator = TransferRequestValidator.instance(mock(Monitor.class)); var jsonObject = objectMapper.readValue(TRANSFER_REQUEST_EXAMPLE, JsonObject.class); assertThat(jsonObject).isNotNull(); @@ -89,7 +91,7 @@ void transferRequestExample() throws JsonProcessingException { .extracting(e -> transformer.transform(e, TransferRequest.class)) .satisfies(transformResult -> assertThat(transformResult).isSucceeded() .satisfies(transformed -> { - assertThat(transformed.getConnectorAddress()).isNotBlank(); + assertThat(transformed.getCounterPartyAddress()).isNotBlank(); assertThat(transformed.getContractId()).isNotBlank(); assertThat(transformed.getProtocol()).isNotBlank(); assertThat(transformed.getConnectorId()).isNotBlank(); @@ -112,9 +114,7 @@ void terminateTransferExample() throws JsonProcessingException { .satisfies(exp -> assertThat(validator.validate(exp)).isSucceeded()) .extracting(e -> transformer.transform(e, TerminateTransfer.class)) .satisfies(transformResult -> assertThat(transformResult).isSucceeded() - .satisfies(transformed -> { - assertThat(transformed.reason()).isNotBlank(); - })); + .satisfies(transformed -> assertThat(transformed.reason()).isNotBlank())); } @Test diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestTransformerTest.java b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestTransformerTest.java index 22acd559a0d..232a00fea83 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestTransformerTest.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestTransformerTest.java @@ -26,9 +26,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_ASSET_ID; -import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_CONNECTOR_ADDRESS; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_CONNECTOR_ID; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_CONTRACT_ID; +import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_COUNTER_PARTY_ADDRESS; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_DATA_DESTINATION; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_PRIVATE_PROPERTIES; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_PROPERTIES; @@ -68,7 +68,7 @@ void transform() { var json = Json.createObjectBuilder() .add(TYPE, TRANSFER_REQUEST_TYPE) .add(ID, "id") - .add(TRANSFER_REQUEST_CONNECTOR_ADDRESS, "address") + .add(TRANSFER_REQUEST_COUNTER_PARTY_ADDRESS, "address") .add(TRANSFER_REQUEST_CONTRACT_ID, "contractId") .add(TRANSFER_REQUEST_DATA_DESTINATION, dataDestinationJson) .add(TRANSFER_REQUEST_PROPERTIES, propertiesJson) @@ -82,7 +82,7 @@ void transform() { assertThat(result).isNotNull(); assertThat(result.getId()).isEqualTo("id"); - assertThat(result.getConnectorAddress()).isEqualTo("address"); + assertThat(result.getCounterPartyAddress()).isEqualTo("address"); assertThat(result.getContractId()).isEqualTo("contractId"); assertThat(result.getDataDestination()).isSameAs(dataDestination); assertThat(result.getProperties()).containsAllEntriesOf(properties); diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/validation/TransferRequestValidatorTest.java b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/validation/TransferRequestValidatorTest.java index 2391a5399fc..09cbd7de4f9 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/validation/TransferRequestValidatorTest.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/validation/TransferRequestValidatorTest.java @@ -17,6 +17,7 @@ import jakarta.json.Json; import jakarta.json.JsonArrayBuilder; import jakarta.json.JsonObject; +import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.validator.spi.ValidationFailure; import org.eclipse.edc.validator.spi.Validator; import org.eclipse.edc.validator.spi.Violation; @@ -30,19 +31,42 @@ import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_CONNECTOR_ADDRESS; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_CONNECTOR_ID; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_CONTRACT_ID; +import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_COUNTER_PARTY_ADDRESS; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_DATA_DESTINATION; import static org.eclipse.edc.connector.transfer.spi.types.TransferRequest.TRANSFER_REQUEST_PROTOCOL; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; import static org.eclipse.edc.spi.types.domain.DataAddress.EDC_DATA_ADDRESS_TYPE_PROPERTY; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; class TransferRequestValidatorTest { - private final Validator validator = TransferRequestValidator.instance(); + private final Monitor monitor = mock(); + private final Validator validator = TransferRequestValidator.instance(monitor); @Test void shouldSucceed_whenObjectIsValid() { + var input = Json.createObjectBuilder() + .add(TRANSFER_REQUEST_COUNTER_PARTY_ADDRESS, value("http://connector-address")) + .add(TRANSFER_REQUEST_CONTRACT_ID, value("contract-id")) + .add(TRANSFER_REQUEST_PROTOCOL, value("protocol")) + .add(TRANSFER_REQUEST_CONNECTOR_ID, value("connectorId")) + .add(TRANSFER_REQUEST_ASSET_ID, value("assetId")) + .add(TRANSFER_REQUEST_DATA_DESTINATION, createArrayBuilder().add(createObjectBuilder() + .add(EDC_DATA_ADDRESS_TYPE_PROPERTY, value("type")) + )) + .build(); + + var result = validator.validate(input); + + assertThat(result).isSucceeded(); + } + + @Test + void shouldSucceed_whenDeprecatedConnectorAddressIsUsed() { var input = Json.createObjectBuilder() .add(TRANSFER_REQUEST_CONNECTOR_ADDRESS, value("http://connector-address")) .add(TRANSFER_REQUEST_CONTRACT_ID, value("contract-id")) @@ -57,6 +81,7 @@ void shouldSucceed_whenObjectIsValid() { var result = validator.validate(input); assertThat(result).isSucceeded(); + verify(monitor).warning(anyString()); } @Test @@ -81,7 +106,7 @@ void shouldFail_whenMandatoryPropertiesAreMissing() { assertThat(result).isFailed().extracting(ValidationFailure::getViolations).asInstanceOf(list(Violation.class)) .isNotEmpty() - .anySatisfy(violation -> assertThat(violation.path()).isEqualTo(TRANSFER_REQUEST_CONNECTOR_ADDRESS)) + .anySatisfy(violation -> assertThat(violation.path()).isEqualTo(TRANSFER_REQUEST_COUNTER_PARTY_ADDRESS)) .anySatisfy(violation -> assertThat(violation.path()).isEqualTo(TRANSFER_REQUEST_CONTRACT_ID)) .anySatisfy(violation -> assertThat(violation.path()).isEqualTo(TRANSFER_REQUEST_PROTOCOL)) .anySatisfy(violation -> assertThat(violation.path()).isEqualTo(TRANSFER_REQUEST_CONNECTOR_ID)) 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 98d66709fd9..14ab7a5360e 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 @@ -29,7 +29,9 @@ public class ContractRequest { public static final String CONTRACT_REQUEST_TYPE = EDC_NAMESPACE + "ContractRequest"; + @Deprecated(since = "0.3.2") public static final String CONNECTOR_ADDRESS = EDC_NAMESPACE + "connectorAddress"; + public static final String CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS = EDC_NAMESPACE + "counterPartyAddress"; public static final String PROTOCOL = EDC_NAMESPACE + "protocol"; public static final String PROVIDER_ID = EDC_NAMESPACE + "providerId"; public static final String OFFER = EDC_NAMESPACE + "offer"; diff --git a/spi/control-plane/transfer-spi/src/main/java/org/eclipse/edc/connector/transfer/spi/types/TransferRequest.java b/spi/control-plane/transfer-spi/src/main/java/org/eclipse/edc/connector/transfer/spi/types/TransferRequest.java index 9c6152d001b..b99e15ebd3f 100644 --- a/spi/control-plane/transfer-spi/src/main/java/org/eclipse/edc/connector/transfer/spi/types/TransferRequest.java +++ b/spi/control-plane/transfer-spi/src/main/java/org/eclipse/edc/connector/transfer/spi/types/TransferRequest.java @@ -27,7 +27,9 @@ public class TransferRequest { public static final String TRANSFER_REQUEST_TYPE = EDC_NAMESPACE + "TransferRequest"; + @Deprecated(since = "0.3.2") public static final String TRANSFER_REQUEST_CONNECTOR_ADDRESS = EDC_NAMESPACE + "connectorAddress"; + public static final String TRANSFER_REQUEST_COUNTER_PARTY_ADDRESS = EDC_NAMESPACE + "counterPartyAddress"; public static final String TRANSFER_REQUEST_CONTRACT_ID = EDC_NAMESPACE + "contractId"; public static final String TRANSFER_REQUEST_DATA_DESTINATION = EDC_NAMESPACE + "dataDestination"; @Deprecated(since = "0.2.0") @@ -40,7 +42,7 @@ public class TransferRequest { private String id; private String protocol; - private String connectorAddress; + private String counterPartyAddress; private String connectorId; private String contractId; private String assetId; @@ -50,8 +52,8 @@ public class TransferRequest { private Map privateProperties = new HashMap<>(); private List callbackAddresses = new ArrayList<>(); - public String getConnectorAddress() { - return connectorAddress; + public String getCounterPartyAddress() { + return counterPartyAddress; } public String getId() { @@ -102,8 +104,8 @@ public static Builder newInstance() { return new Builder(); } - public Builder connectorAddress(String connectorAddress) { - request.connectorAddress = connectorAddress; + public Builder counterPartyAddress(String counterPartyAddress) { + request.counterPartyAddress = counterPartyAddress; return this; }