Skip to content

Commit

Permalink
feat: introduces dspace namespace 2024/1 (#4573)
Browse files Browse the repository at this point in the history
feat: introduces dspace schema 2024/1
  • Loading branch information
wolf4ood authored Oct 23, 2024
1 parent 95c5ca8 commit a6c7855
Show file tree
Hide file tree
Showing 16 changed files with 337 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));

Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,31 @@
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;
}

@Override
public Result<JsonObject> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
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;

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand All @@ -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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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));
}
}
Loading

0 comments on commit a6c7855

Please sign in to comment.