diff --git a/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/main/java/org/eclipse/edc/protocol/dsp/catalog/http/api/DspCatalogApiExtension.java b/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/main/java/org/eclipse/edc/protocol/dsp/catalog/http/api/DspCatalogApiExtension.java index 2bc13120f3b..79d2bfb9b74 100644 --- a/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/main/java/org/eclipse/edc/protocol/dsp/catalog/http/api/DspCatalogApiExtension.java +++ b/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/main/java/org/eclipse/edc/protocol/dsp/catalog/http/api/DspCatalogApiExtension.java @@ -19,6 +19,7 @@ import org.eclipse.edc.connector.controlplane.services.spi.catalog.CatalogProtocolService; import org.eclipse.edc.connector.controlplane.services.spi.protocol.ProtocolVersionRegistry; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.spi.JsonLdNamespace; import org.eclipse.edc.protocol.dsp.catalog.http.api.controller.DspCatalogApiController; import org.eclipse.edc.protocol.dsp.catalog.http.api.controller.DspCatalogApiController20241; import org.eclipse.edc.protocol.dsp.catalog.http.api.decorator.Base64continuationTokenSerDes; @@ -40,7 +41,9 @@ import org.eclipse.edc.web.spi.WebService; import org.eclipse.edc.web.spi.configuration.ApiContext; -import static org.eclipse.edc.protocol.dsp.spi.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_IRI; +import static org.eclipse.edc.protocol.dsp.spi.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_TERM; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_2024_1; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_SCOPE_V_08; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_SCOPE_V_2024_1; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_TRANSFORMER_CONTEXT_V_08; @@ -89,11 +92,12 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - validatorRegistry.register(DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_IRI, CatalogRequestMessageValidator.instance(criterionOperatorRegistry)); var jsonLdMapper = typeManager.getMapper(JSON_LD); + registerValidators(DSP_NAMESPACE_V_08); + registerValidators(DSP_NAMESPACE_V_2024_1); - webService.registerResource(ApiContext.PROTOCOL, new DspCatalogApiController(service, dspRequestHandler, continuationTokenManager(monitor, DSP_TRANSFORMER_CONTEXT_V_08))); - webService.registerResource(ApiContext.PROTOCOL, new DspCatalogApiController20241(service, dspRequestHandler, continuationTokenManager(monitor, DSP_TRANSFORMER_CONTEXT_V_2024_1))); + webService.registerResource(ApiContext.PROTOCOL, new DspCatalogApiController(service, dspRequestHandler, continuationTokenManager(monitor, DSP_TRANSFORMER_CONTEXT_V_08, DSP_NAMESPACE_V_08))); + webService.registerResource(ApiContext.PROTOCOL, new DspCatalogApiController20241(service, dspRequestHandler, continuationTokenManager(monitor, DSP_TRANSFORMER_CONTEXT_V_2024_1, DSP_NAMESPACE_V_2024_1))); webService.registerDynamicResource(ApiContext.PROTOCOL, DspCatalogApiController.class, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, DSP_SCOPE_V_08)); webService.registerDynamicResource(ApiContext.PROTOCOL, DspCatalogApiController20241.class, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, DSP_SCOPE_V_2024_1)); @@ -106,8 +110,12 @@ public void initialize(ServiceExtensionContext context) { versionRegistry.register(V_08); } - private ContinuationTokenManager continuationTokenManager(Monitor monitor, String version) { + private ContinuationTokenManager continuationTokenManager(Monitor monitor, String version, JsonLdNamespace namespace) { var continuationTokenSerDes = new Base64continuationTokenSerDes(transformerRegistry.forContext(version), jsonLd); - return new ContinuationTokenManagerImpl(continuationTokenSerDes, monitor); + return new ContinuationTokenManagerImpl(continuationTokenSerDes, namespace, monitor); + } + + private void registerValidators(JsonLdNamespace namespace) { + validatorRegistry.register(namespace.toIri(DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_TERM), CatalogRequestMessageValidator.instance(criterionOperatorRegistry, namespace)); } } diff --git a/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/main/java/org/eclipse/edc/protocol/dsp/catalog/http/api/decorator/ContinuationTokenManagerImpl.java b/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/main/java/org/eclipse/edc/protocol/dsp/catalog/http/api/decorator/ContinuationTokenManagerImpl.java index b7c6cd56bc9..182358100a7 100644 --- a/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/main/java/org/eclipse/edc/protocol/dsp/catalog/http/api/decorator/ContinuationTokenManagerImpl.java +++ b/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/main/java/org/eclipse/edc/protocol/dsp/catalog/http/api/decorator/ContinuationTokenManagerImpl.java @@ -19,20 +19,23 @@ import jakarta.json.JsonObjectBuilder; import org.eclipse.edc.connector.controlplane.catalog.spi.Catalog; import org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequestMessage; +import org.eclipse.edc.jsonld.spi.JsonLdNamespace; import org.eclipse.edc.protocol.dsp.http.spi.message.ContinuationTokenManager; import org.eclipse.edc.protocol.dsp.http.spi.message.ResponseDecorator; import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.result.Result; -import static org.eclipse.edc.protocol.dsp.spi.type.DspCatalogPropertyAndTypeNames.DSPACE_PROPERTY_FILTER_IRI; +import static org.eclipse.edc.protocol.dsp.spi.type.DspCatalogPropertyAndTypeNames.DSPACE_PROPERTY_FILTER_TERM; public class ContinuationTokenManagerImpl implements ContinuationTokenManager { private final Base64continuationTokenSerDes continuationTokenSerDes; + private final JsonLdNamespace namespace; private final Monitor monitor; - public ContinuationTokenManagerImpl(Base64continuationTokenSerDes continuationTokenSerDes, Monitor monitor) { + public ContinuationTokenManagerImpl(Base64continuationTokenSerDes continuationTokenSerDes, JsonLdNamespace namespace, Monitor monitor) { this.continuationTokenSerDes = continuationTokenSerDes; + this.namespace = namespace; this.monitor = monitor; } @@ -40,7 +43,7 @@ public ContinuationTokenManagerImpl(Base64continuationTokenSerDes continuationTo public Result applyQueryFromToken(JsonObject requestMessage, String continuationToken) { return continuationTokenSerDes.deserialize(continuationToken) .map(query -> Json.createArrayBuilder().add(query)) - .map(filter -> Json.createObjectBuilder(requestMessage).add(DSPACE_PROPERTY_FILTER_IRI, filter)) + .map(filter -> Json.createObjectBuilder(requestMessage).add(namespace.toIri(DSPACE_PROPERTY_FILTER_TERM), filter)) .map(JsonObjectBuilder::build); } diff --git a/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/test/java/org/eclipse/edc/protocol/dsp/catalog/http/api/decorator/ContinuationTokenManagerImplTest.java b/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/test/java/org/eclipse/edc/protocol/dsp/catalog/http/api/decorator/ContinuationTokenManagerImplTest.java index a43399425b1..83e6ec250cd 100644 --- a/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/test/java/org/eclipse/edc/protocol/dsp/catalog/http/api/decorator/ContinuationTokenManagerImplTest.java +++ b/data-protocols/dsp/dsp-catalog/dsp-catalog-http-api/src/test/java/org/eclipse/edc/protocol/dsp/catalog/http/api/decorator/ContinuationTokenManagerImplTest.java @@ -21,6 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; import static org.eclipse.edc.protocol.dsp.spi.type.DspCatalogPropertyAndTypeNames.DSPACE_PROPERTY_FILTER_IRI; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -28,7 +29,7 @@ class ContinuationTokenManagerImplTest { private final Base64continuationTokenSerDes serDes = mock(); - private final ContinuationTokenManagerImpl continuationTokenManager = new ContinuationTokenManagerImpl(serDes, mock()); + private final ContinuationTokenManagerImpl continuationTokenManager = new ContinuationTokenManagerImpl(serDes, DSP_NAMESPACE_V_08, mock()); @Test void apply_shouldReplaceQueryWithTheOnePassedInTheToken() { diff --git a/data-protocols/dsp/dsp-catalog/dsp-catalog-transform/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/DspCatalogTransformExtension.java b/data-protocols/dsp/dsp-catalog/dsp-catalog-transform/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/DspCatalogTransformExtension.java index ff8b3c103be..e5f67602c4b 100644 --- a/data-protocols/dsp/dsp-catalog/dsp-catalog-transform/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/DspCatalogTransformExtension.java +++ b/data-protocols/dsp/dsp-catalog/dsp-catalog-transform/src/main/java/org/eclipse/edc/protocol/dsp/catalog/transform/DspCatalogTransformExtension.java @@ -16,6 +16,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.Json; +import org.eclipse.edc.jsonld.spi.JsonLdNamespace; import org.eclipse.edc.participant.spi.ParticipantIdMapper; import org.eclipse.edc.protocol.dsp.catalog.transform.from.JsonObjectFromCatalogErrorTransformer; import org.eclipse.edc.protocol.dsp.catalog.transform.from.JsonObjectFromCatalogRequestMessageTransformer; @@ -33,6 +34,8 @@ import java.util.Map; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_2024_1; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_TRANSFORMER_CONTEXT_V_08; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_TRANSFORMER_CONTEXT_V_2024_1; import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @@ -63,21 +66,21 @@ public String name() { public void initialize(ServiceExtensionContext context) { var mapper = typeManager.getMapper(JSON_LD); - registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08, mapper); - registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1, mapper); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08, DSP_NAMESPACE_V_08, mapper); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1, DSP_NAMESPACE_V_2024_1, mapper); } - private void registerTransformers(String version, ObjectMapper mapper) { + private void registerTransformers(String version, JsonLdNamespace namespace, ObjectMapper mapper) { var jsonFactory = Json.createBuilderFactory(Map.of()); var dspApiTransformerRegistry = registry.forContext(version); - dspApiTransformerRegistry.register(new JsonObjectFromCatalogRequestMessageTransformer(jsonFactory)); - dspApiTransformerRegistry.register(new JsonObjectToCatalogRequestMessageTransformer()); + dspApiTransformerRegistry.register(new JsonObjectFromCatalogRequestMessageTransformer(jsonFactory, namespace)); + dspApiTransformerRegistry.register(new JsonObjectToCatalogRequestMessageTransformer(namespace)); - dspApiTransformerRegistry.register(new JsonObjectFromCatalogTransformer(jsonFactory, mapper, participantIdMapper)); + dspApiTransformerRegistry.register(new JsonObjectFromCatalogTransformer(jsonFactory, mapper, participantIdMapper, namespace)); dspApiTransformerRegistry.register(new JsonObjectFromDatasetTransformer(jsonFactory, mapper)); dspApiTransformerRegistry.register(new JsonObjectFromDistributionTransformer(jsonFactory)); dspApiTransformerRegistry.register(new JsonObjectFromDataServiceTransformer(jsonFactory)); - dspApiTransformerRegistry.register(new JsonObjectFromCatalogErrorTransformer(jsonFactory)); + dspApiTransformerRegistry.register(new JsonObjectFromCatalogErrorTransformer(jsonFactory, namespace)); } } diff --git a/data-protocols/dsp/dsp-http-api-configuration/src/main/java/org/eclipse/edc/protocol/dsp/http/api/configuration/DspApiConfigurationExtension.java b/data-protocols/dsp/dsp-http-api-configuration/src/main/java/org/eclipse/edc/protocol/dsp/http/api/configuration/DspApiConfigurationExtension.java index d8698ef6fba..0ceb873a1a0 100644 --- a/data-protocols/dsp/dsp-http-api-configuration/src/main/java/org/eclipse/edc/protocol/dsp/http/api/configuration/DspApiConfigurationExtension.java +++ b/data-protocols/dsp/dsp-http-api-configuration/src/main/java/org/eclipse/edc/protocol/dsp/http/api/configuration/DspApiConfigurationExtension.java @@ -21,6 +21,7 @@ import org.eclipse.edc.connector.controlplane.transform.odrl.OdrlTransformersFactory; import org.eclipse.edc.connector.controlplane.transform.odrl.from.JsonObjectFromPolicyTransformer; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.spi.JsonLdNamespace; import org.eclipse.edc.participant.spi.ParticipantIdMapper; import org.eclipse.edc.policy.model.AtomicConstraint; import org.eclipse.edc.policy.model.LiteralExpression; @@ -58,9 +59,10 @@ import static org.eclipse.edc.jsonld.spi.Namespaces.DCT_PREFIX; import static org.eclipse.edc.jsonld.spi.Namespaces.DCT_SCHEMA; import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_PREFIX; -import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA; import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_PREFIX; import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_2024_1; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_SCOPE_V_08; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_SCOPE_V_2024_1; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_TRANSFORMER_CONTEXT_V_08; @@ -124,35 +126,35 @@ public void initialize(ServiceExtensionContext context) { var jsonLdMapper = typeManager.getMapper(JSON_LD); // registers ns for DSP scope - registerNamespaces(DSP_SCOPE_V_08); - registerNamespaces(DSP_SCOPE_V_2024_1); + registerNamespaces(DSP_SCOPE_V_08, DSP_NAMESPACE_V_08); + registerNamespaces(DSP_SCOPE_V_2024_1, DSP_NAMESPACE_V_2024_1); webService.registerResource(ApiContext.PROTOCOL, new ObjectMapperProvider(jsonLdMapper)); var mapper = typeManager.getMapper(JSON_LD); mapper.registerSubtypes(AtomicConstraint.class, LiteralExpression.class); - registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08, mapper); - registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1, mapper); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08, DSP_NAMESPACE_V_08, mapper); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1, DSP_NAMESPACE_V_2024_1, mapper); } - private void registerNamespaces(String scope) { + private void registerNamespaces(String scope, JsonLdNamespace dspNamespace) { jsonLd.registerNamespace(DCAT_PREFIX, DCAT_SCHEMA, scope); jsonLd.registerNamespace(DCT_PREFIX, DCT_SCHEMA, scope); jsonLd.registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, scope); - jsonLd.registerNamespace(DSPACE_PREFIX, DSPACE_SCHEMA, scope); + jsonLd.registerNamespace(DSPACE_PREFIX, dspNamespace.namespace(), scope); jsonLd.registerNamespace(VOCAB, EDC_NAMESPACE, scope); jsonLd.registerNamespace(EDC_PREFIX, EDC_NAMESPACE, scope); } - private void registerTransformers(String version, ObjectMapper mapper) { + private void registerTransformers(String version, JsonLdNamespace dspNamespace, ObjectMapper mapper) { var jsonBuilderFactory = Json.createBuilderFactory(Map.of()); // EDC model to JSON-LD transformers var dspApiTransformerRegistry = transformerRegistry.forContext(version); dspApiTransformerRegistry.register(new JsonObjectFromPolicyTransformer(jsonBuilderFactory, participantIdMapper)); dspApiTransformerRegistry.register(new JsonObjectFromAssetTransformer(jsonBuilderFactory, mapper)); - dspApiTransformerRegistry.register(new JsonObjectFromDataAddressDspaceTransformer(jsonBuilderFactory, mapper)); + dspApiTransformerRegistry.register(new JsonObjectFromDataAddressDspaceTransformer(jsonBuilderFactory, mapper, dspNamespace)); dspApiTransformerRegistry.register(new JsonObjectFromQuerySpecTransformer(jsonBuilderFactory)); dspApiTransformerRegistry.register(new JsonObjectFromCriterionTransformer(jsonBuilderFactory, mapper)); @@ -164,7 +166,7 @@ private void registerTransformers(String version, ObjectMapper mapper) { dspApiTransformerRegistry.register(new JsonObjectToAssetTransformer()); dspApiTransformerRegistry.register(new JsonObjectToQuerySpecTransformer()); dspApiTransformerRegistry.register(new JsonObjectToCriterionTransformer()); - dspApiTransformerRegistry.register(new JsonObjectToDataAddressDspaceTransformer()); + dspApiTransformerRegistry.register(new JsonObjectToDataAddressDspaceTransformer(dspNamespace)); } } diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-http-api/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/http/api/DspNegotiationApiExtension.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-http-api/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/http/api/DspNegotiationApiExtension.java index 955951dcded..7f49640d9b0 100644 --- a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-http-api/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/http/api/DspNegotiationApiExtension.java +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-http-api/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/http/api/DspNegotiationApiExtension.java @@ -17,6 +17,7 @@ import org.eclipse.edc.connector.controlplane.services.spi.contractnegotiation.ContractNegotiationProtocolService; import org.eclipse.edc.connector.controlplane.services.spi.protocol.ProtocolVersionRegistry; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.spi.JsonLdNamespace; import org.eclipse.edc.protocol.dsp.http.spi.message.DspRequestHandler; import org.eclipse.edc.protocol.dsp.negotiation.http.api.controller.DspNegotiationApiController; import org.eclipse.edc.protocol.dsp.negotiation.http.api.controller.DspNegotiationApiController20241; @@ -36,14 +37,16 @@ import org.eclipse.edc.web.spi.WebService; import org.eclipse.edc.web.spi.configuration.ApiContext; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_2024_1; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_SCOPE_V_08; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_SCOPE_V_2024_1; -import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_AGREEMENT_MESSAGE_IRI; -import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_AGREEMENT_VERIFICATION_MESSAGE_IRI; -import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_NEGOTIATION_EVENT_MESSAGE_IRI; -import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_NEGOTIATION_TERMINATION_MESSAGE_IRI; -import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_OFFER_MESSAGE_IRI; -import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE_IRI; +import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_AGREEMENT_MESSAGE_TERM; +import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_AGREEMENT_VERIFICATION_MESSAGE_TERM; +import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_NEGOTIATION_EVENT_MESSAGE_TERM; +import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_NEGOTIATION_TERMINATION_MESSAGE_TERM; +import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_OFFER_MESSAGE_TERM; +import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE_TERM; import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_08; import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_2024_1; import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @@ -82,12 +85,8 @@ public String name() { public void initialize(ServiceExtensionContext context) { var jsonLdMapper = typeManager.getMapper(JSON_LD); - validatorRegistry.register(DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE_IRI, ContractRequestMessageValidator.instance()); - validatorRegistry.register(DSPACE_TYPE_CONTRACT_OFFER_MESSAGE_IRI, ContractOfferMessageValidator.instance()); - validatorRegistry.register(DSPACE_TYPE_CONTRACT_NEGOTIATION_EVENT_MESSAGE_IRI, ContractNegotiationEventMessageValidator.instance()); - validatorRegistry.register(DSPACE_TYPE_CONTRACT_AGREEMENT_MESSAGE_IRI, ContractAgreementMessageValidator.instance()); - validatorRegistry.register(DSPACE_TYPE_CONTRACT_AGREEMENT_VERIFICATION_MESSAGE_IRI, ContractAgreementVerificationMessageValidator.instance()); - validatorRegistry.register(DSPACE_TYPE_CONTRACT_NEGOTIATION_TERMINATION_MESSAGE_IRI, ContractNegotiationTerminationMessageValidator.instance()); + registerValidators(DSP_NAMESPACE_V_08); + registerValidators(DSP_NAMESPACE_V_2024_1); webService.registerResource(ApiContext.PROTOCOL, new DspNegotiationApiController(protocolService, dspRequestHandler)); webService.registerResource(ApiContext.PROTOCOL, new DspNegotiationApiController20241(protocolService, dspRequestHandler)); @@ -97,4 +96,14 @@ public void initialize(ServiceExtensionContext context) { versionRegistry.register(V_2024_1); versionRegistry.register(V_08); } + + + private void registerValidators(JsonLdNamespace namespace) { + validatorRegistry.register(namespace.toIri(DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE_TERM), ContractRequestMessageValidator.instance(namespace)); + validatorRegistry.register(namespace.toIri(DSPACE_TYPE_CONTRACT_OFFER_MESSAGE_TERM), ContractOfferMessageValidator.instance(namespace)); + validatorRegistry.register(namespace.toIri(DSPACE_TYPE_CONTRACT_NEGOTIATION_EVENT_MESSAGE_TERM), ContractNegotiationEventMessageValidator.instance(namespace)); + validatorRegistry.register(namespace.toIri(DSPACE_TYPE_CONTRACT_AGREEMENT_MESSAGE_TERM), ContractAgreementMessageValidator.instance(namespace)); + validatorRegistry.register(namespace.toIri(DSPACE_TYPE_CONTRACT_AGREEMENT_VERIFICATION_MESSAGE_TERM), ContractAgreementVerificationMessageValidator.instance(namespace)); + validatorRegistry.register(namespace.toIri(DSPACE_TYPE_CONTRACT_NEGOTIATION_TERMINATION_MESSAGE_TERM), ContractNegotiationTerminationMessageValidator.instance(namespace)); + } } diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/DspNegotiationTransformExtension.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/DspNegotiationTransformExtension.java index 19fca4fc586..a5991fe9a86 100644 --- a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/DspNegotiationTransformExtension.java +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/DspNegotiationTransformExtension.java @@ -15,6 +15,7 @@ package org.eclipse.edc.protocol.dsp.negotiation.transform; import jakarta.json.Json; +import org.eclipse.edc.jsonld.spi.JsonLdNamespace; import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractAgreementMessageTransformer; import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractAgreementVerificationMessageTransformer; import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractNegotiationErrorTransformer; @@ -38,6 +39,8 @@ import java.util.Map; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_2024_1; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_TRANSFORMER_CONTEXT_V_08; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_TRANSFORMER_CONTEXT_V_2024_1; @@ -59,29 +62,29 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08); - registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08, DSP_NAMESPACE_V_08); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1, DSP_NAMESPACE_V_2024_1); } - private void registerTransformers(String version) { + private void registerTransformers(String version, JsonLdNamespace namespace) { var builderFactory = Json.createBuilderFactory(Map.of()); var dspApiTransformerRegistry = registry.forContext(version); - dspApiTransformerRegistry.register(new JsonObjectFromContractAgreementMessageTransformer(builderFactory)); - dspApiTransformerRegistry.register(new JsonObjectFromContractAgreementVerificationMessageTransformer(builderFactory)); - dspApiTransformerRegistry.register(new JsonObjectFromContractNegotiationEventMessageTransformer(builderFactory)); - dspApiTransformerRegistry.register(new JsonObjectFromContractNegotiationTerminationMessageTransformer(builderFactory)); - dspApiTransformerRegistry.register(new JsonObjectFromContractNegotiationTransformer(builderFactory)); - dspApiTransformerRegistry.register(new JsonObjectFromContractRequestMessageTransformer(builderFactory)); - dspApiTransformerRegistry.register(new JsonObjectFromContractOfferMessageTransformer(builderFactory)); - dspApiTransformerRegistry.register(new JsonObjectFromContractNegotiationErrorTransformer(builderFactory)); + dspApiTransformerRegistry.register(new JsonObjectFromContractAgreementMessageTransformer(builderFactory, namespace)); + dspApiTransformerRegistry.register(new JsonObjectFromContractAgreementVerificationMessageTransformer(builderFactory, namespace)); + dspApiTransformerRegistry.register(new JsonObjectFromContractNegotiationEventMessageTransformer(builderFactory, namespace)); + dspApiTransformerRegistry.register(new JsonObjectFromContractNegotiationTerminationMessageTransformer(builderFactory, namespace)); + dspApiTransformerRegistry.register(new JsonObjectFromContractNegotiationTransformer(builderFactory, namespace)); + dspApiTransformerRegistry.register(new JsonObjectFromContractRequestMessageTransformer(builderFactory, namespace)); + dspApiTransformerRegistry.register(new JsonObjectFromContractOfferMessageTransformer(builderFactory, namespace)); + dspApiTransformerRegistry.register(new JsonObjectFromContractNegotiationErrorTransformer(builderFactory, namespace)); - dspApiTransformerRegistry.register(new JsonObjectToContractAgreementMessageTransformer()); - dspApiTransformerRegistry.register(new JsonObjectToContractAgreementVerificationMessageTransformer()); - dspApiTransformerRegistry.register(new JsonObjectToContractNegotiationEventMessageTransformer()); - dspApiTransformerRegistry.register(new JsonObjectToContractRequestMessageTransformer()); - dspApiTransformerRegistry.register(new JsonObjectToContractNegotiationTerminationMessageTransformer()); - dspApiTransformerRegistry.register(new JsonObjectToContractOfferMessageTransformer()); - dspApiTransformerRegistry.register(new JsonObjectToContractNegotiationAckTransformer()); + dspApiTransformerRegistry.register(new JsonObjectToContractAgreementMessageTransformer(namespace)); + dspApiTransformerRegistry.register(new JsonObjectToContractAgreementVerificationMessageTransformer(namespace)); + dspApiTransformerRegistry.register(new JsonObjectToContractNegotiationEventMessageTransformer(namespace)); + dspApiTransformerRegistry.register(new JsonObjectToContractRequestMessageTransformer(namespace)); + dspApiTransformerRegistry.register(new JsonObjectToContractNegotiationTerminationMessageTransformer(namespace)); + dspApiTransformerRegistry.register(new JsonObjectToContractOfferMessageTransformer(namespace)); + dspApiTransformerRegistry.register(new JsonObjectToContractNegotiationAckTransformer(namespace)); } } \ No newline at end of file diff --git a/data-protocols/dsp/dsp-negotiation/lib/dsp-negotiation-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationTransformer.java b/data-protocols/dsp/dsp-negotiation/lib/dsp-negotiation-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationTransformer.java index d5fe074e41e..d4e1a8d3d83 100644 --- a/data-protocols/dsp/dsp-negotiation/lib/dsp-negotiation-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationTransformer.java +++ b/data-protocols/dsp/dsp-negotiation/lib/dsp-negotiation-transform-lib/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationTransformer.java @@ -27,7 +27,7 @@ import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; -import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_NEGOTIATION_IRI; +import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_NEGOTIATION_TERM; import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_VALUE_NEGOTIATION_STATE_ACCEPTED_TERM; import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_VALUE_NEGOTIATION_STATE_AGREED_TERM; import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_VALUE_NEGOTIATION_STATE_FINALIZED_TERM; @@ -60,7 +60,7 @@ public JsonObjectFromContractNegotiationTransformer(JsonBuilderFactory jsonFacto public @Nullable JsonObject transform(@NotNull ContractNegotiation contractNegotiation, @NotNull TransformerContext context) { return jsonFactory.createObjectBuilder() .add(ID, pidFor(contractNegotiation, contractNegotiation.getType())) - .add(TYPE, DSPACE_TYPE_CONTRACT_NEGOTIATION_IRI) + .add(TYPE, forNamespace(DSPACE_TYPE_CONTRACT_NEGOTIATION_TERM)) .add(forNamespace(DSPACE_PROPERTY_CONSUMER_PID_TERM), pidFor(contractNegotiation, ContractNegotiation.Type.CONSUMER)) .add(forNamespace(DSPACE_PROPERTY_PROVIDER_PID_TERM), pidFor(contractNegotiation, ContractNegotiation.Type.PROVIDER)) .add(forNamespace(DSPACE_PROPERTY_STATE_TERM), state(contractNegotiation.getState(), context)) diff --git a/data-protocols/dsp/dsp-spi/src/main/java/org/eclipse/edc/protocol/dsp/spi/type/DspConstants.java b/data-protocols/dsp/dsp-spi/src/main/java/org/eclipse/edc/protocol/dsp/spi/type/DspConstants.java index 1e2504041fd..1dd107f995b 100644 --- a/data-protocols/dsp/dsp-spi/src/main/java/org/eclipse/edc/protocol/dsp/spi/type/DspConstants.java +++ b/data-protocols/dsp/dsp-spi/src/main/java/org/eclipse/edc/protocol/dsp/spi/type/DspConstants.java @@ -17,6 +17,7 @@ import org.eclipse.edc.jsonld.spi.JsonLdNamespace; import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA; +import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA_2024_1; import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_08_VERSION; import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_2024_1_VERSION; @@ -34,5 +35,5 @@ public interface DspConstants { String DSP_TRANSFORMER_CONTEXT_V_2024_1 = DSP_TRANSFORMER_CONTEXT + DSP_CONTEXT_SEPARATOR + V_2024_1_VERSION; JsonLdNamespace DSP_NAMESPACE_V_08 = new JsonLdNamespace(DSPACE_SCHEMA); - JsonLdNamespace DSP_NAMESPACE_V_2024_1 = new JsonLdNamespace(DSPACE_SCHEMA); + JsonLdNamespace DSP_NAMESPACE_V_2024_1 = new JsonLdNamespace(DSPACE_SCHEMA_2024_1); } diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-http-api/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/http/api/DspTransferProcessApiExtension.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-http-api/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/http/api/DspTransferProcessApiExtension.java index 7b684bd297e..7405509b882 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-http-api/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/http/api/DspTransferProcessApiExtension.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-http-api/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/http/api/DspTransferProcessApiExtension.java @@ -17,6 +17,7 @@ import org.eclipse.edc.connector.controlplane.services.spi.protocol.ProtocolVersionRegistry; import org.eclipse.edc.connector.controlplane.services.spi.transferprocess.TransferProcessProtocolService; import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.jsonld.spi.JsonLdNamespace; import org.eclipse.edc.protocol.dsp.http.spi.message.DspRequestHandler; import org.eclipse.edc.protocol.dsp.transferprocess.http.api.controller.DspTransferProcessApiController; import org.eclipse.edc.protocol.dsp.transferprocess.http.api.controller.DspTransferProcessApiController20241; @@ -34,12 +35,14 @@ import org.eclipse.edc.web.spi.WebService; import org.eclipse.edc.web.spi.configuration.ApiContext; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_2024_1; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_SCOPE_V_08; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_SCOPE_V_2024_1; -import static org.eclipse.edc.protocol.dsp.spi.type.DspTransferProcessPropertyAndTypeNames.DSPACE_TYPE_TRANSFER_COMPLETION_MESSAGE_IRI; -import static org.eclipse.edc.protocol.dsp.spi.type.DspTransferProcessPropertyAndTypeNames.DSPACE_TYPE_TRANSFER_REQUEST_MESSAGE_IRI; -import static org.eclipse.edc.protocol.dsp.spi.type.DspTransferProcessPropertyAndTypeNames.DSPACE_TYPE_TRANSFER_START_MESSAGE_IRI; -import static org.eclipse.edc.protocol.dsp.spi.type.DspTransferProcessPropertyAndTypeNames.DSPACE_TYPE_TRANSFER_TERMINATION_MESSAGE_IRI; +import static org.eclipse.edc.protocol.dsp.spi.type.DspTransferProcessPropertyAndTypeNames.DSPACE_TYPE_TRANSFER_COMPLETION_MESSAGE_TERM; +import static org.eclipse.edc.protocol.dsp.spi.type.DspTransferProcessPropertyAndTypeNames.DSPACE_TYPE_TRANSFER_REQUEST_MESSAGE_TERM; +import static org.eclipse.edc.protocol.dsp.spi.type.DspTransferProcessPropertyAndTypeNames.DSPACE_TYPE_TRANSFER_START_MESSAGE_TERM; +import static org.eclipse.edc.protocol.dsp.spi.type.DspTransferProcessPropertyAndTypeNames.DSPACE_TYPE_TRANSFER_TERMINATION_MESSAGE_TERM; import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_08; import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_2024_1; import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @@ -70,10 +73,8 @@ public class DspTransferProcessApiExtension implements ServiceExtension { public void initialize(ServiceExtensionContext context) { var jsonLdMapper = typeManager.getMapper(JSON_LD); - validatorRegistry.register(DSPACE_TYPE_TRANSFER_REQUEST_MESSAGE_IRI, TransferRequestMessageValidator.instance()); - validatorRegistry.register(DSPACE_TYPE_TRANSFER_START_MESSAGE_IRI, TransferStartMessageValidator.instance()); - validatorRegistry.register(DSPACE_TYPE_TRANSFER_COMPLETION_MESSAGE_IRI, TransferCompletionMessageValidator.instance()); - validatorRegistry.register(DSPACE_TYPE_TRANSFER_TERMINATION_MESSAGE_IRI, TransferTerminationMessageValidator.instance()); + registerValidators(DSP_NAMESPACE_V_08); + registerValidators(DSP_NAMESPACE_V_2024_1); webService.registerResource(ApiContext.PROTOCOL, new DspTransferProcessApiController(transferProcessProtocolService, dspRequestHandler)); webService.registerResource(ApiContext.PROTOCOL, new DspTransferProcessApiController20241(transferProcessProtocolService, dspRequestHandler)); @@ -83,4 +84,11 @@ public void initialize(ServiceExtensionContext context) { versionRegistry.register(V_2024_1); versionRegistry.register(V_08); } + + private void registerValidators(JsonLdNamespace namespace) { + validatorRegistry.register(namespace.toIri(DSPACE_TYPE_TRANSFER_REQUEST_MESSAGE_TERM), TransferRequestMessageValidator.instance(namespace)); + validatorRegistry.register(namespace.toIri(DSPACE_TYPE_TRANSFER_START_MESSAGE_TERM), TransferStartMessageValidator.instance(namespace)); + validatorRegistry.register(namespace.toIri(DSPACE_TYPE_TRANSFER_COMPLETION_MESSAGE_TERM), TransferCompletionMessageValidator.instance(namespace)); + validatorRegistry.register(namespace.toIri(DSPACE_TYPE_TRANSFER_TERMINATION_MESSAGE_TERM), TransferTerminationMessageValidator.instance(namespace)); + } } diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/DspTransferProcessTransformExtension.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/DspTransferProcessTransformExtension.java index fd8b1d6892c..d03e5298e88 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/DspTransferProcessTransformExtension.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transform/DspTransferProcessTransformExtension.java @@ -16,6 +16,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.Json; +import org.eclipse.edc.jsonld.spi.JsonLdNamespace; import org.eclipse.edc.protocol.dsp.transferprocess.transform.type.from.JsonObjectFromTransferCompletionMessageTransformer; import org.eclipse.edc.protocol.dsp.transferprocess.transform.type.from.JsonObjectFromTransferErrorTransformer; import org.eclipse.edc.protocol.dsp.transferprocess.transform.type.from.JsonObjectFromTransferProcessTransformer; @@ -35,10 +36,11 @@ 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.transform.transformer.edc.from.JsonObjectFromDataAddressTransformer; import java.util.Map; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08; +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_2024_1; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_TRANSFORMER_CONTEXT_V_08; import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_TRANSFORMER_CONTEXT_V_2024_1; import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @@ -66,30 +68,29 @@ public String name() { public void initialize(ServiceExtensionContext context) { var objectMapper = typeManager.getMapper(JSON_LD); - registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08, objectMapper); - registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1, objectMapper); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_08, DSP_NAMESPACE_V_08, objectMapper); + registerTransformers(DSP_TRANSFORMER_CONTEXT_V_2024_1, DSP_NAMESPACE_V_2024_1, objectMapper); } - private void registerTransformers(String version, ObjectMapper objectMapper) { + private void registerTransformers(String version, JsonLdNamespace namespace, ObjectMapper objectMapper) { var builderFactory = Json.createBuilderFactory(Map.of()); var dspRegistry = registry.forContext(version); - dspRegistry.register(new JsonObjectFromTransferProcessTransformer(builderFactory)); - dspRegistry.register(new JsonObjectFromTransferStartMessageTransformer(builderFactory)); - dspRegistry.register(new JsonObjectFromTransferCompletionMessageTransformer(builderFactory)); - dspRegistry.register(new JsonObjectFromTransferTerminationMessageTransformer(builderFactory)); - dspRegistry.register(new JsonObjectFromTransferRequestMessageTransformer(builderFactory)); - dspRegistry.register(new JsonObjectFromTransferSuspensionMessageTransformer(builderFactory)); - dspRegistry.register(new JsonObjectFromDataAddressTransformer(builderFactory)); - dspRegistry.register(new JsonObjectFromTransferErrorTransformer(builderFactory)); - - dspRegistry.register(new JsonObjectToTransferRequestMessageTransformer()); - dspRegistry.register(new JsonObjectToTransferCompletionMessageTransformer()); - dspRegistry.register(new JsonObjectToTransferStartMessageTransformer()); - dspRegistry.register(new JsonObjectToTransferTerminationMessageTransformer()); - dspRegistry.register(new JsonObjectToTransferProcessAckTransformer()); - dspRegistry.register(new JsonObjectToTransferSuspensionMessageTransformer(objectMapper)); + dspRegistry.register(new JsonObjectFromTransferProcessTransformer(builderFactory, namespace)); + dspRegistry.register(new JsonObjectFromTransferStartMessageTransformer(builderFactory, namespace)); + dspRegistry.register(new JsonObjectFromTransferCompletionMessageTransformer(builderFactory, namespace)); + dspRegistry.register(new JsonObjectFromTransferTerminationMessageTransformer(builderFactory, namespace)); + dspRegistry.register(new JsonObjectFromTransferRequestMessageTransformer(builderFactory, namespace)); + dspRegistry.register(new JsonObjectFromTransferSuspensionMessageTransformer(builderFactory, namespace)); + dspRegistry.register(new JsonObjectFromTransferErrorTransformer(builderFactory, namespace)); + + dspRegistry.register(new JsonObjectToTransferRequestMessageTransformer(namespace)); + dspRegistry.register(new JsonObjectToTransferCompletionMessageTransformer(namespace)); + dspRegistry.register(new JsonObjectToTransferStartMessageTransformer(namespace)); + dspRegistry.register(new JsonObjectToTransferTerminationMessageTransformer(namespace)); + dspRegistry.register(new JsonObjectToTransferProcessAckTransformer(namespace)); + dspRegistry.register(new JsonObjectToTransferSuspensionMessageTransformer(objectMapper, namespace)); } } \ No newline at end of file diff --git a/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/Namespaces.java b/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/Namespaces.java index 34267bfe79c..25abb70c8e9 100644 --- a/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/Namespaces.java +++ b/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/Namespaces.java @@ -28,5 +28,6 @@ public interface Namespaces { String DCT_SCHEMA = "http://purl.org/dc/terms/"; String DSPACE_PREFIX = "dspace"; - String DSPACE_SCHEMA = "https://w3id.org/dspace/v0.8/"; // TODO to be defined + String DSPACE_SCHEMA = "https://w3id.org/dspace/v0.8/"; + String DSPACE_SCHEMA_2024_1 = "https://w3id.org/dspace/2024/1/"; } diff --git a/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/DspCatalogApiEndToEndTest.java b/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/DspCatalogApiEndToEndTest.java index 7dbeb87a4c8..d7e2e1be23b 100644 --- a/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/DspCatalogApiEndToEndTest.java +++ b/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/DspCatalogApiEndToEndTest.java @@ -21,7 +21,7 @@ import org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractDefinition; import org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition; import org.eclipse.edc.connector.controlplane.policy.spi.store.PolicyDefinitionStore; -import org.eclipse.edc.connector.controlplane.services.spi.protocol.ProtocolVersionRegistry; +import org.eclipse.edc.jsonld.spi.JsonLdNamespace; import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.edc.junit.extensions.EmbeddedRuntime; import org.eclipse.edc.junit.extensions.RuntimeExtension; @@ -29,8 +29,9 @@ import org.eclipse.edc.policy.model.Policy; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.util.io.Ports; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ArgumentsSource; import java.util.Map; import java.util.UUID; @@ -40,14 +41,11 @@ import static jakarta.json.Json.createObjectBuilder; import static java.util.Arrays.stream; import static java.util.stream.IntStream.range; -import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; -import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA; -import static org.eclipse.edc.protocol.dsp.spi.type.DspCatalogPropertyAndTypeNames.DSPACE_PROPERTY_FILTER_IRI; -import static org.eclipse.edc.protocol.dsp.spi.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_IRI; -import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_2024_1; +import static org.eclipse.edc.protocol.dsp.spi.type.DspCatalogPropertyAndTypeNames.DSPACE_PROPERTY_FILTER_TERM; +import static org.eclipse.edc.protocol.dsp.spi.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_TERM; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; @@ -75,9 +73,10 @@ public class DspCatalogApiEndToEndTest { ":core:control-plane:control-plane-core", ":extensions:common:http" )); - - @Test - void shouldExposeVersion2024_1() { + + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void shouldExposeVersion(String basePath, JsonLdNamespace namespace) { given() .port(PROTOCOL_PORT) .basePath("/protocol") @@ -85,22 +84,23 @@ void shouldExposeVersion2024_1() { .header("Authorization", "{\"region\": \"any\", \"audience\": \"any\", \"clientId\":\"any\"}") .body(createObjectBuilder() .add(CONTEXT, createObjectBuilder().add(VOCAB, EDC_NAMESPACE)) - .add(TYPE, DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_IRI) + .add(TYPE, namespace.toIri(DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_TERM)) .build()) - .post("/2024/1/catalog/request") + .post(basePath + "/catalog/request") .then() .log().ifValidationFails() .statusCode(200) .contentType(JSON) - .body("'dspace:participantId'", notNullValue()); + .body("'dspace:participantId'", notNullValue()) + .body("'@context'.dspace", equalTo(namespace.namespace())); - assertThat(runtime.getService(ProtocolVersionRegistry.class).getAll().protocolVersions()) - .contains(V_2024_1); } - @Test - void shouldPermitPaginationWithLinkHeader() { + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void shouldPermitPaginationWithLinkHeader(String basePath, JsonLdNamespace namespace) { var assetIndex = runtime.getService(AssetIndex.class); + range(0, 8) .mapToObj(i -> Asset.Builder.newInstance().id(i + "").dataAddress(DataAddress.Builder.newInstance().type("any").build()).build()) .forEach(assetIndex::create); @@ -118,18 +118,19 @@ void shouldPermitPaginationWithLinkHeader() { .header("Authorization", "{\"region\": \"any\", \"audience\": \"any\", \"clientId\":\"any\"}") .body(createObjectBuilder() .add(CONTEXT, createObjectBuilder().add(VOCAB, EDC_NAMESPACE)) - .add(TYPE, DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_IRI) - .add(DSPACE_PROPERTY_FILTER_IRI, Json.createObjectBuilder() + .add(TYPE, namespace.toIri(DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_TERM)) + .add(namespace.toIri(DSPACE_PROPERTY_FILTER_TERM), Json.createObjectBuilder() .add("offset", 0) .add("limit", 5)) .build()) - .post("/2024/1/catalog/request") + .post(basePath + "/catalog/request") .then() .log().ifValidationFails() .statusCode(200) .contentType(JSON) .body("'dcat:dataset'.size()", equalTo(5)) - .header("Link", containsString("/2024/1/catalog/request")) + .body("'@context'.dspace", equalTo(namespace.namespace())) + .header("Link", containsString(basePath + "/catalog/request")) .header("Link", containsString("next")) .header("Link", not(containsString("prev"))) .extract().header("Link"); @@ -143,22 +144,24 @@ void shouldPermitPaginationWithLinkHeader() { .header("Authorization", "{\"region\": \"any\", \"audience\": \"any\", \"clientId\":\"any\"}") .body(createObjectBuilder() .add(CONTEXT, createObjectBuilder().add(VOCAB, EDC_NAMESPACE)) - .add(TYPE, DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_IRI) + .add(TYPE, namespace.toIri(DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_TERM)) .build() ) .post(nextPageUrl) .then() .log().ifValidationFails() .body("'dcat:dataset'.size()", equalTo(3)) + .body("'@context'.dspace", equalTo(namespace.namespace())) .statusCode(200) .contentType(JSON) - .header("Link", containsString("/2024/1/catalog/request")) + .header("Link", containsString(basePath + "/catalog/request")) .header("Link", containsString("prev")) .header("Link", not(containsString("next"))); } - @Test - void catalogRequest_shouldReturnError_whenNotAuthorized() { + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void catalogRequest_shouldReturnError_whenNotAuthorized(String basePath, JsonLdNamespace namespace) { var authorizationHeader = """ {"region": "any", "audience": "any", "clientId":"faultyClientId"}" @@ -170,9 +173,9 @@ void catalogRequest_shouldReturnError_whenNotAuthorized() { .header("Authorization", authorizationHeader) .body(createObjectBuilder() .add(CONTEXT, createObjectBuilder().add(VOCAB, EDC_NAMESPACE)) - .add(TYPE, DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_IRI) + .add(TYPE, namespace.toIri(DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_TERM)) .build()) - .post("/catalog/request") + .post(basePath + "/catalog/request") .then() .log().ifValidationFails() .statusCode(401) @@ -180,12 +183,13 @@ void catalogRequest_shouldReturnError_whenNotAuthorized() { .body("'@type'", equalTo("dspace:CatalogError")) .body("'dspace:code'", equalTo("401")) .body("'dspace:reason'", equalTo("Unauthorized")) - .body("'@context'.dspace", equalTo(DSPACE_SCHEMA)); + .body("'@context'.dspace", equalTo(namespace.namespace())); } - @Test - void catalogRequest_shouldReturnError_whenMissingToken() { + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void catalogRequest_shouldReturnError_whenMissingToken(String basePath, JsonLdNamespace namespace) { given() .port(PROTOCOL_PORT) @@ -193,9 +197,9 @@ void catalogRequest_shouldReturnError_whenMissingToken() { .contentType(JSON) .body(createObjectBuilder() .add(CONTEXT, createObjectBuilder().add(VOCAB, EDC_NAMESPACE)) - .add(TYPE, DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_IRI) + .add(TYPE, namespace.toIri(DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_TERM)) .build()) - .post("/catalog/request") + .post(basePath + "/catalog/request") .then() .log().ifValidationFails() .statusCode(401) @@ -203,12 +207,13 @@ void catalogRequest_shouldReturnError_whenMissingToken() { .body("'@type'", equalTo("dspace:CatalogError")) .body("'dspace:code'", equalTo("401")) .body("'dspace:reason'", equalTo("Unauthorized.")) - .body("'@context'.dspace", equalTo(DSPACE_SCHEMA)); + .body("'@context'.dspace", equalTo(namespace.namespace())); } - @Test - void catalogRequest_shouldReturnError_whenValidationFails() { + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void catalogRequest_shouldReturnError_whenValidationFails(String basePath, JsonLdNamespace namespace) { var authorizationHeader = """ {"region": "any", "audience": "any", "clientId":"any"}" """; @@ -221,7 +226,7 @@ void catalogRequest_shouldReturnError_whenValidationFails() { .add(CONTEXT, createObjectBuilder().add(VOCAB, EDC_NAMESPACE)) .add(TYPE, "FakeType") .build()) - .post("/catalog/request") + .post(basePath + "/catalog/request") .then() .log().ifValidationFails() .statusCode(400) @@ -229,12 +234,13 @@ void catalogRequest_shouldReturnError_whenValidationFails() { .body("'@type'", equalTo("dspace:CatalogError")) .body("'dspace:code'", equalTo("400")) .body("'dspace:reason'", equalTo("Bad request.")) - .body("'@context'.dspace", equalTo(DSPACE_SCHEMA)); + .body("'@context'.dspace", equalTo(namespace.namespace())); } - @Test - void shouldReturnError_whenDatasetNotFound() { + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void shouldReturnError_whenDatasetNotFound(String basePath, JsonLdNamespace namespace) { var id = UUID.randomUUID().toString(); var authorizationHeader = """ @@ -245,7 +251,7 @@ void shouldReturnError_whenDatasetNotFound() { .basePath("/protocol") .contentType(JSON) .header("Authorization", authorizationHeader) - .get("/catalog/datasets/" + id) + .get(basePath + "/catalog/datasets/" + id) .then() .log().ifValidationFails() .statusCode(404) @@ -253,7 +259,7 @@ void shouldReturnError_whenDatasetNotFound() { .body("'@type'", equalTo("dspace:CatalogError")) .body("'dspace:code'", equalTo("404")) .body("'dspace:reason'", equalTo("Dataset %s does not exist".formatted(id))) - .body("'@context'.dspace", equalTo(DSPACE_SCHEMA)); + .body("'@context'.dspace", equalTo(namespace.namespace())); } } diff --git a/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/DspNegotiationApiEndToEndTest.java b/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/DspNegotiationApiEndToEndTest.java index 6e0727cb728..30edaa4fa1c 100644 --- a/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/DspNegotiationApiEndToEndTest.java +++ b/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/DspNegotiationApiEndToEndTest.java @@ -17,15 +17,16 @@ import org.eclipse.edc.connector.controlplane.contract.spi.negotiation.store.ContractNegotiationStore; import org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractNegotiation; import org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractOffer; -import org.eclipse.edc.connector.controlplane.services.spi.protocol.ProtocolVersionRegistry; +import org.eclipse.edc.jsonld.spi.JsonLdNamespace; import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.edc.junit.extensions.EmbeddedRuntime; import org.eclipse.edc.junit.extensions.RuntimeExtension; import org.eclipse.edc.junit.extensions.RuntimePerClassExtension; import org.eclipse.edc.policy.model.Policy; import org.eclipse.edc.util.io.Ports; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ArgumentsSource; import java.util.Map; import java.util.UUID; @@ -33,15 +34,20 @@ import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.JSON; import static jakarta.json.Json.createObjectBuilder; -import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.edc.connector.controlplane.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; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; -import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA; -import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_2024_1; +import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_ASSIGNER_ATTRIBUTE; +import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_POLICY_TYPE_OFFER; +import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_TARGET_ATTRIBUTE; +import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_OFFER_TERM; +import static org.eclipse.edc.protocol.dsp.spi.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CALLBACK_ADDRESS_TERM; +import static org.eclipse.edc.protocol.dsp.spi.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CONSUMER_PID_TERM; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.notNullValue; @EndToEndTest public class DspNegotiationApiEndToEndTest { @@ -65,8 +71,9 @@ public class DspNegotiationApiEndToEndTest { ":extensions:common:http" )); - @Test - void shouldExposeVersion2024_1() { + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void shouldExposeVersion(String basePath, JsonLdNamespace namespace) { var id = UUID.randomUUID().toString(); var negotiation = ContractNegotiation.Builder.newInstance() .id(id).counterPartyId("any").counterPartyAddress("any").protocol("any").state(REQUESTED.code()) @@ -83,18 +90,21 @@ void shouldExposeVersion2024_1() { .basePath("/protocol") .contentType(JSON) .header("Authorization", "{\"region\": \"any\", \"audience\": \"any\", \"clientId\":\"any\"}") - .get("/2024/1/negotiations/" + id) + .get(basePath + "/negotiations/" + id) .then() .log().ifError() .statusCode(200) - .contentType(JSON); - - assertThat(runtime.getService(ProtocolVersionRegistry.class).getAll().protocolVersions()) - .contains(V_2024_1); + .contentType(JSON) + .body("'@type'", equalTo("dspace:ContractNegotiation")) + .body("'dspace:state'", notNullValue()) + .body("'dspace:consumerPid'", notNullValue()) + .body("'dspace:providerPid'", notNullValue()) + .body("'@context'.dspace", equalTo(namespace.namespace())); } - @Test - void shouldReturnError_whenNotFound() { + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void shouldReturnError_whenNotFound(String basePath, JsonLdNamespace namespace) { var id = UUID.randomUUID().toString(); given() @@ -102,7 +112,7 @@ void shouldReturnError_whenNotFound() { .basePath("/protocol") .contentType(JSON) .header("Authorization", "{\"region\": \"any\", \"audience\": \"any\", \"clientId\":\"any\"}") - .get("/negotiations/" + id) + .get(basePath + "/negotiations/" + id) .then() .log().ifError() .statusCode(404) @@ -110,18 +120,51 @@ void shouldReturnError_whenNotFound() { .body("'@type'", equalTo("dspace:ContractNegotiationError")) .body("'dspace:code'", equalTo("404")) .body("'dspace:reason'", equalTo("No negotiation with id %s found".formatted(id))) - .body("'@context'.dspace", equalTo(DSPACE_SCHEMA)); + .body("'@context'.dspace", equalTo(namespace.namespace())); + } + + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void shouldReturnError_whenValidationFails(String basePath, JsonLdNamespace namespace) { + + given() + .port(PROTOCOL_PORT) + .basePath("/protocol") + .contentType(JSON) + .body(createObjectBuilder() + .add(CONTEXT, createObjectBuilder().add(VOCAB, EDC_NAMESPACE)) + .add(TYPE, "WrongType") + .add(namespace.toIri(DSPACE_PROPERTY_CONSUMER_PID_TERM), "any") + .add(namespace.toIri(DSPACE_PROPERTY_CALLBACK_ADDRESS_TERM), "any") + .add(namespace.toIri(DSPACE_PROPERTY_OFFER_TERM), createObjectBuilder() + .add("@type", ODRL_POLICY_TYPE_OFFER) + .add(ID, "offerId") + .add(ODRL_TARGET_ATTRIBUTE, "target") + .add(ODRL_ASSIGNER_ATTRIBUTE, "assigner") + .build()) + .build()) + .header("Authorization", "{\"region\": \"any\", \"audience\": \"any\", \"clientId\":\"any\"}") + .post(basePath + "/negotiations/request") + .then() + .log().ifError() + .statusCode(400) + .contentType(JSON) + .body("'@type'", equalTo("dspace:ContractNegotiationError")) + .body("'dspace:code'", equalTo("400")) + .body("'dspace:reason'", equalTo("Bad request.")) + .body("'@context'.dspace", equalTo(namespace.namespace())); } - @Test - void terminate_ShouldReturnError_whenMissingToken() { + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void terminate_ShouldReturnError_whenMissingToken(String basePath, JsonLdNamespace namespace) { var id = UUID.randomUUID().toString(); given() .port(PROTOCOL_PORT) .basePath("/protocol") .contentType(JSON) - .post("/negotiations/" + id + "/termination") + .post(basePath + "/negotiations/" + id + "/termination") .then() .log().ifError() .statusCode(401) @@ -129,11 +172,12 @@ void terminate_ShouldReturnError_whenMissingToken() { .body("'@type'", equalTo("dspace:ContractNegotiationError")) .body("'dspace:code'", equalTo("401")) .body("'dspace:reason'", equalTo("Unauthorized.")) - .body("'@context'.dspace", equalTo(DSPACE_SCHEMA)); + .body("'@context'.dspace", equalTo(namespace.namespace())); } - @Test - void terminate_ShouldReturnError_whenValidationFails() { + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void terminate_ShouldReturnError_whenValidationFails(String basePath, JsonLdNamespace namespace) { var id = UUID.randomUUID().toString(); given() @@ -145,7 +189,7 @@ void terminate_ShouldReturnError_whenValidationFails() { .add(CONTEXT, createObjectBuilder().add(VOCAB, EDC_NAMESPACE)) .add(TYPE, "FakeType") .build()) - .post("/negotiations/" + id + "/termination") + .post(basePath + "/negotiations/" + id + "/termination") .then() .log().ifError() @@ -154,7 +198,7 @@ void terminate_ShouldReturnError_whenValidationFails() { .body("'@type'", equalTo("dspace:ContractNegotiationError")) .body("'dspace:code'", equalTo("400")) .body("'dspace:reason'", equalTo("Bad request.")) - .body("'@context'.dspace", equalTo(DSPACE_SCHEMA)); + .body("'@context'.dspace", equalTo(namespace.namespace())); } } diff --git a/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/DspTransferApiEndToEndTest.java b/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/DspTransferApiEndToEndTest.java index 8a9b498a771..45f68e9abd3 100644 --- a/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/DspTransferApiEndToEndTest.java +++ b/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/DspTransferApiEndToEndTest.java @@ -19,9 +19,9 @@ import org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractNegotiation; import org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractNegotiationStates; import org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractOffer; -import org.eclipse.edc.connector.controlplane.services.spi.protocol.ProtocolVersionRegistry; import org.eclipse.edc.connector.controlplane.transfer.spi.store.TransferProcessStore; import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcess; +import org.eclipse.edc.jsonld.spi.JsonLdNamespace; import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.edc.junit.extensions.EmbeddedRuntime; import org.eclipse.edc.junit.extensions.RuntimeExtension; @@ -29,19 +29,27 @@ import org.eclipse.edc.policy.model.Policy; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.util.io.Ports; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ArgumentsSource; import java.util.Map; import java.util.UUID; import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.JSON; -import static org.assertj.core.api.Assertions.assertThat; +import static jakarta.json.Json.createObjectBuilder; import static org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates.REQUESTED; -import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA; -import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_2024_1; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; +import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCT_FORMAT_ATTRIBUTE; +import static org.eclipse.edc.protocol.dsp.spi.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CALLBACK_ADDRESS_TERM; +import static org.eclipse.edc.protocol.dsp.spi.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CONSUMER_PID_TERM; +import static org.eclipse.edc.protocol.dsp.spi.type.DspTransferProcessPropertyAndTypeNames.DSPACE_PROPERTY_CONTRACT_AGREEMENT_ID_TERM; +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.notNullValue; @EndToEndTest public class DspTransferApiEndToEndTest { @@ -83,8 +91,9 @@ private static ContractNegotiation createNegotiationWithAgreement(String contrac .build(); } - @Test - void shouldExposeVersion2024_1() { + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void shouldExposeVersion(String basePath, JsonLdNamespace namespace) { var id = UUID.randomUUID().toString(); var contractId = UUID.randomUUID().toString(); var transfer = TransferProcess.Builder.newInstance() @@ -101,18 +110,49 @@ void shouldExposeVersion2024_1() { .basePath("/protocol") .contentType(JSON) .header("Authorization", "{\"region\": \"any\", \"audience\": \"any\", \"clientId\":\"any\"}") - .get("/2024/1/transfers/" + id) + .get(basePath + "/transfers/" + id) .then() .log().ifError() .statusCode(200) - .contentType(JSON); + .contentType(JSON) + .body("'@type'", equalTo("dspace:TransferProcess")) + .body("'dspace:state'", notNullValue()) + .body("'dspace:consumerPid'", notNullValue()) + .body("'@context'.dspace", equalTo(namespace.namespace())); + + } + + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void shouldReturnError_whenValidationFails(String basePath, JsonLdNamespace namespace) { - assertThat(runtime.getService(ProtocolVersionRegistry.class).getAll().protocolVersions()) - .contains(V_2024_1); + given() + .port(PROTOCOL_PORT) + .basePath("/protocol") + .contentType(JSON) + .body(createObjectBuilder() + .add(CONTEXT, createObjectBuilder().add(VOCAB, EDC_NAMESPACE)) + .add(TYPE, "WrongType") + .add(namespace.toIri(DSPACE_PROPERTY_CONSUMER_PID_TERM), "any") + .add(namespace.toIri(DSPACE_PROPERTY_CONTRACT_AGREEMENT_ID_TERM), "any") + .add(namespace.toIri(DSPACE_PROPERTY_CALLBACK_ADDRESS_TERM), "any") + .add(DCT_FORMAT_ATTRIBUTE, "any") + .build()) + .header("Authorization", "{\"region\": \"any\", \"audience\": \"any\", \"clientId\":\"any\"}") + .post(basePath + "/transfers/request") + .then() + .log().ifError() + .statusCode(400) + .contentType(JSON) + .body("'@type'", equalTo("dspace:TransferError")) + .body("'dspace:code'", equalTo("400")) + .body("'dspace:reason'", equalTo("Bad request.")) + .body("'@context'.dspace", equalTo(namespace.namespace())); } - @Test - void shouldReturnError_whenNotFound() { + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void shouldReturnError_whenNotFound(String basePath, JsonLdNamespace namespace) { var id = UUID.randomUUID().toString(); given() @@ -120,7 +160,7 @@ void shouldReturnError_whenNotFound() { .basePath("/protocol") .contentType(JSON) .header("Authorization", "{\"region\": \"any\", \"audience\": \"any\", \"clientId\":\"any\"}") - .get("/transfers/" + id) + .get(basePath + "/transfers/" + id) .then() .log().ifError() .statusCode(404) @@ -128,19 +168,20 @@ void shouldReturnError_whenNotFound() { .body("'@type'", equalTo("dspace:TransferError")) .body("'dspace:code'", equalTo("404")) .body("'dspace:reason'", equalTo("No transfer process with id %s found".formatted(id))) - .body("'@context'.dspace", equalTo(DSPACE_SCHEMA)); + .body("'@context'.dspace", equalTo(namespace.namespace())); } - @Test - void shouldReturnError_whenTokenIsMissing() { + @ParameterizedTest + @ArgumentsSource(ProtocolVersionProvider.class) + void shouldReturnError_whenTokenIsMissing(String basePath, JsonLdNamespace namespace) { var id = UUID.randomUUID().toString(); given() .port(PROTOCOL_PORT) .basePath("/protocol") .contentType(JSON) - .get("/transfers/" + id) + .get(basePath + "/transfers/" + id) .then() .log().ifError() .statusCode(401) @@ -148,7 +189,7 @@ void shouldReturnError_whenTokenIsMissing() { .body("'@type'", equalTo("dspace:TransferError")) .body("'dspace:code'", equalTo("401")) .body("'dspace:reason'", equalTo("Unauthorized.")) - .body("'@context'.dspace", equalTo(DSPACE_SCHEMA)); + .body("'@context'.dspace", equalTo(namespace.namespace())); } diff --git a/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/ProtocolVersionProvider.java b/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/ProtocolVersionProvider.java new file mode 100644 index 00000000000..f04ded300ab --- /dev/null +++ b/system-tests/protocol-test/src/test/java/org/eclipse/edc/test/e2e/protocol/ProtocolVersionProvider.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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.test.e2e.protocol; + +import org.eclipse.edc.protocol.dsp.spi.type.DspConstants; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; + +import java.util.stream.Stream; + +import static org.eclipse.edc.protocol.dsp.spi.version.DspVersions.V_2024_1_PATH; + +public class ProtocolVersionProvider implements ArgumentsProvider { + @Override + public Stream provideArguments(ExtensionContext context) throws Exception { + return Stream.of( + Arguments.of("", DspConstants.DSP_NAMESPACE_V_08), + Arguments.of(V_2024_1_PATH, DspConstants.DSP_NAMESPACE_V_2024_1) + ); + } +}