Skip to content

Commit

Permalink
refactor: add DspNamespace usage (#4562)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood authored Oct 18, 2024
1 parent 900ddc5 commit 2bf8b0a
Show file tree
Hide file tree
Showing 52 changed files with 223 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
import org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequestMessage;
import org.eclipse.edc.connector.controlplane.catalog.spi.Dataset;
import org.eclipse.edc.connector.controlplane.services.spi.catalog.CatalogProtocolService;
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.DspRequestHandler;
import org.eclipse.edc.protocol.dsp.http.spi.message.GetDspRequest;
import org.eclipse.edc.protocol.dsp.http.spi.message.PostDspRequest;
import org.eclipse.edc.protocol.dsp.spi.type.DspNamespace;

import static jakarta.ws.rs.core.HttpHeaders.AUTHORIZATION;
import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
Expand All @@ -59,13 +59,13 @@ public class DspCatalogApiController {
private final DspRequestHandler dspRequestHandler;
private final ContinuationTokenManager continuationTokenManager;
private final String protocol;
private final DspNamespace namespace;
private final JsonLdNamespace namespace;

public DspCatalogApiController(CatalogProtocolService service, DspRequestHandler dspRequestHandler, ContinuationTokenManager continuationTokenManager) {
this(service, dspRequestHandler, continuationTokenManager, DATASPACE_PROTOCOL_HTTP, DSP_NAMESPACE_V_08);
}

public DspCatalogApiController(CatalogProtocolService service, DspRequestHandler dspRequestHandler, ContinuationTokenManager continuationTokenManager, String protocol, DspNamespace namespace) {
public DspCatalogApiController(CatalogProtocolService service, DspRequestHandler dspRequestHandler, ContinuationTokenManager continuationTokenManager, String protocol, JsonLdNamespace namespace) {
this.service = service;
this.dspRequestHandler = dspRequestHandler;
this.continuationTokenManager = continuationTokenManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
import org.eclipse.edc.connector.controlplane.catalog.spi.Dataset;
import org.eclipse.edc.connector.controlplane.services.spi.catalog.CatalogProtocolService;
import org.eclipse.edc.jsonld.spi.JsonLdKeywords;
import org.eclipse.edc.jsonld.spi.JsonLdNamespace;
import org.eclipse.edc.junit.annotations.ApiTest;
import org.eclipse.edc.protocol.dsp.http.spi.message.ContinuationTokenManager;
import org.eclipse.edc.protocol.dsp.http.spi.message.DspRequestHandler;
import org.eclipse.edc.protocol.dsp.http.spi.message.GetDspRequest;
import org.eclipse.edc.protocol.dsp.http.spi.message.PostDspRequest;
import org.eclipse.edc.protocol.dsp.http.spi.message.ResponseDecorator;
import org.eclipse.edc.protocol.dsp.spi.type.DspNamespace;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.eclipse.edc.web.jersey.testfixtures.RestControllerTestBase;
Expand Down Expand Up @@ -90,7 +90,7 @@ void getDataset_shouldGetResource() {

protected abstract String basePath();

protected abstract DspNamespace namespace();
protected abstract JsonLdNamespace namespace();

private RequestSpecification baseRequest() {
return given()
Expand Down Expand Up @@ -183,7 +183,7 @@ protected String basePath() {
}

@Override
protected DspNamespace namespace() {
protected JsonLdNamespace namespace() {
return DSP_NAMESPACE_V_08;
}

Expand All @@ -203,7 +203,7 @@ protected String basePath() {
}

@Override
protected DspNamespace namespace() {
protected JsonLdNamespace namespace() {
return DSP_NAMESPACE_V_2024_1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
import jakarta.json.JsonBuilderFactory;
import jakarta.json.JsonObject;
import org.eclipse.edc.connector.controlplane.catalog.spi.CatalogError;
import org.eclipse.edc.jsonld.spi.JsonLdNamespace;
import org.eclipse.edc.jsonld.spi.transformer.AbstractNamespaceAwareJsonLdTransformer;
import org.eclipse.edc.transform.spi.TransformerContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA;
import static org.eclipse.edc.protocol.dsp.spi.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_ERROR_TERM;
import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08;
import static org.eclipse.edc.protocol.dsp.spi.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CODE_TERM;
import static org.eclipse.edc.protocol.dsp.spi.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_REASON_TERM;

Expand All @@ -36,11 +37,11 @@ public class JsonObjectFromCatalogErrorTransformer extends AbstractNamespaceAwar
private final JsonBuilderFactory jsonFactory;

public JsonObjectFromCatalogErrorTransformer(JsonBuilderFactory jsonFactory) {
this(jsonFactory, DSPACE_SCHEMA);
this(jsonFactory, DSP_NAMESPACE_V_08);
}

public JsonObjectFromCatalogErrorTransformer(JsonBuilderFactory jsonFactory, String schema) {
super(CatalogError.class, JsonObject.class, schema);
public JsonObjectFromCatalogErrorTransformer(JsonBuilderFactory jsonFactory, JsonLdNamespace namespace) {
super(CatalogError.class, JsonObject.class, namespace);
this.jsonFactory = jsonFactory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
import jakarta.json.JsonBuilderFactory;
import jakarta.json.JsonObject;
import org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequestMessage;
import org.eclipse.edc.jsonld.spi.JsonLdNamespace;
import org.eclipse.edc.jsonld.spi.transformer.AbstractNamespaceAwareJsonLdTransformer;
import org.eclipse.edc.transform.spi.TransformerContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA;
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.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08;

/**
* Transforms a {@link CatalogRequestMessage} to a {@link JsonObject} in JSON-LD expanded form.
Expand All @@ -35,11 +36,11 @@ public class JsonObjectFromCatalogRequestMessageTransformer extends AbstractName
private final JsonBuilderFactory jsonFactory;

public JsonObjectFromCatalogRequestMessageTransformer(JsonBuilderFactory jsonFactory) {
this(jsonFactory, DSPACE_SCHEMA);
this(jsonFactory, DSP_NAMESPACE_V_08);
}

public JsonObjectFromCatalogRequestMessageTransformer(JsonBuilderFactory jsonFactory, String schema) {
super(CatalogRequestMessage.class, JsonObject.class, schema);
public JsonObjectFromCatalogRequestMessageTransformer(JsonBuilderFactory jsonFactory, JsonLdNamespace namespace) {
super(CatalogRequestMessage.class, JsonObject.class, namespace);
this.jsonFactory = jsonFactory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import jakarta.json.JsonBuilderFactory;
import jakarta.json.JsonObject;
import org.eclipse.edc.connector.controlplane.catalog.spi.Catalog;
import org.eclipse.edc.jsonld.spi.JsonLdNamespace;
import org.eclipse.edc.jsonld.spi.transformer.AbstractNamespaceAwareJsonLdTransformer;
import org.eclipse.edc.spi.agent.ParticipantIdMapper;
import org.eclipse.edc.transform.spi.TransformerContext;
Expand All @@ -28,12 +29,12 @@
import static java.util.Optional.ofNullable;
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.Namespaces.DSPACE_SCHEMA;
import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_CATALOG_TYPE;
import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_DATASET_ATTRIBUTE;
import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_DATA_SERVICE_ATTRIBUTE;
import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_DISTRIBUTION_ATTRIBUTE;
import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DSPACE_PROPERTY_PARTICIPANT_ID_TERM;
import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08;

/**
* Converts from a {@link Catalog} to a DCAT catalog as a {@link JsonObject} in JSON-LD expanded form.
Expand All @@ -44,10 +45,10 @@ public class JsonObjectFromCatalogTransformer extends AbstractNamespaceAwareJson
private final ParticipantIdMapper participantIdMapper;

public JsonObjectFromCatalogTransformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper, ParticipantIdMapper participantIdMapper) {
this(jsonFactory, mapper, participantIdMapper, DSPACE_SCHEMA);
this(jsonFactory, mapper, participantIdMapper, DSP_NAMESPACE_V_08);
}

public JsonObjectFromCatalogTransformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper, ParticipantIdMapper participantIdMapper, String namespace) {
public JsonObjectFromCatalogTransformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper, ParticipantIdMapper participantIdMapper, JsonLdNamespace namespace) {
super(Catalog.class, JsonObject.class, namespace);
this.jsonFactory = jsonFactory;
this.mapper = mapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import jakarta.json.JsonObject;
import org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequestMessage;
import org.eclipse.edc.jsonld.spi.JsonLdNamespace;
import org.eclipse.edc.jsonld.spi.transformer.AbstractNamespaceAwareJsonLdTransformer;
import org.eclipse.edc.spi.query.QuerySpec;
import org.eclipse.edc.transform.spi.TransformerContext;
Expand All @@ -24,19 +25,19 @@

import java.util.Optional;

import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA;
import static org.eclipse.edc.protocol.dsp.spi.type.DspCatalogPropertyAndTypeNames.DSPACE_PROPERTY_FILTER_TERM;
import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08;

/**
* Transforms a {@link JsonObject} in JSON-LD expanded form to a {@link CatalogRequestMessage}.
*/
public class JsonObjectToCatalogRequestMessageTransformer extends AbstractNamespaceAwareJsonLdTransformer<JsonObject, CatalogRequestMessage> {

public JsonObjectToCatalogRequestMessageTransformer() {
this(DSPACE_SCHEMA);
this(DSP_NAMESPACE_V_08);
}

public JsonObjectToCatalogRequestMessageTransformer(String namespace) {
public JsonObjectToCatalogRequestMessageTransformer(JsonLdNamespace namespace) {
super(JsonObject.class, CatalogRequestMessage.class, namespace);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,29 @@
package org.eclipse.edc.protocol.dsp.catalog.validation;

import jakarta.json.JsonObject;
import org.eclipse.edc.jsonld.spi.JsonLdNamespace;
import org.eclipse.edc.spi.query.CriterionOperatorRegistry;
import org.eclipse.edc.validator.jsonobject.JsonObjectValidator;
import org.eclipse.edc.validator.jsonobject.validators.TypeIs;
import org.eclipse.edc.validator.jsonobject.validators.model.QuerySpecValidator;
import org.eclipse.edc.validator.spi.Validator;

import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA;
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.protocol.dsp.spi.type.DspConstants.DSP_NAMESPACE_V_08;

/**
* Validator for {@link CatalogRequestMessageValidator} Json-LD representation
*/
public class CatalogRequestMessageValidator {
public static Validator<JsonObject> instance(CriterionOperatorRegistry criterionOperatorRegistry) {
return instance(criterionOperatorRegistry, DSPACE_SCHEMA);
return instance(criterionOperatorRegistry, DSP_NAMESPACE_V_08);
}

public static Validator<JsonObject> instance(CriterionOperatorRegistry criterionOperatorRegistry, String schema) {
public static Validator<JsonObject> instance(CriterionOperatorRegistry criterionOperatorRegistry, JsonLdNamespace namespace) {
return JsonObjectValidator.newValidator()
.verify(path -> new TypeIs(path, schema + DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_TERM))
.verifyObject(schema + DSPACE_PROPERTY_FILTER_TERM, path -> QuerySpecValidator.instance(path, criterionOperatorRegistry))
.verify(path -> new TypeIs(path, namespace.toIri(DSPACE_TYPE_CATALOG_REQUEST_MESSAGE_TERM)))
.verifyObject(namespace.toIri(DSPACE_PROPERTY_FILTER_TERM), path -> QuerySpecValidator.instance(path, criterionOperatorRegistry))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
import org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractOfferMessage;
import org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequestMessage;
import org.eclipse.edc.connector.controlplane.services.spi.contractnegotiation.ContractNegotiationProtocolService;
import org.eclipse.edc.jsonld.spi.JsonLdNamespace;
import org.eclipse.edc.protocol.dsp.http.spi.message.DspRequestHandler;
import org.eclipse.edc.protocol.dsp.http.spi.message.GetDspRequest;
import org.eclipse.edc.protocol.dsp.http.spi.message.PostDspRequest;
import org.eclipse.edc.protocol.dsp.spi.type.DspNamespace;

import static jakarta.ws.rs.core.HttpHeaders.AUTHORIZATION;
import static org.eclipse.edc.protocol.dsp.http.spi.types.HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP;
Expand Down Expand Up @@ -68,7 +68,7 @@ public class DspNegotiationApiController {

private final DspRequestHandler dspRequestHandler;
private final String protocol;
private final DspNamespace namespace;
private final JsonLdNamespace namespace;
private final ContractNegotiationProtocolService protocolService;

public DspNegotiationApiController(ContractNegotiationProtocolService protocolService,
Expand All @@ -80,7 +80,7 @@ public DspNegotiationApiController(ContractNegotiationProtocolService protocolSe
public DspNegotiationApiController(ContractNegotiationProtocolService protocolService,
DspRequestHandler dspRequestHandler,
String protocol,
DspNamespace namespace) {
JsonLdNamespace namespace) {
this.protocolService = protocolService;
this.dspRequestHandler = dspRequestHandler;
this.protocol = protocol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractOfferMessage;
import org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequestMessage;
import org.eclipse.edc.connector.controlplane.services.spi.contractnegotiation.ContractNegotiationProtocolService;
import org.eclipse.edc.jsonld.spi.JsonLdNamespace;
import org.eclipse.edc.junit.annotations.ApiTest;
import org.eclipse.edc.protocol.dsp.http.spi.message.DspRequestHandler;
import org.eclipse.edc.protocol.dsp.http.spi.message.GetDspRequest;
import org.eclipse.edc.protocol.dsp.http.spi.message.PostDspRequest;
import org.eclipse.edc.protocol.dsp.spi.type.DspNamespace;
import org.eclipse.edc.web.jersey.testfixtures.RestControllerTestBase;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -178,7 +178,7 @@ void callEndpoint_shouldUpdateResource(String path, Class<?> messageClass, Strin

protected abstract String basePath();

protected abstract DspNamespace namespace();
protected abstract JsonLdNamespace namespace();

private RequestSpecification baseRequest() {
var authHeader = "auth";
Expand Down Expand Up @@ -232,7 +232,7 @@ protected String basePath() {
}

@Override
protected DspNamespace namespace() {
protected JsonLdNamespace namespace() {
return DSP_NAMESPACE_V_08;
}

Expand All @@ -252,7 +252,7 @@ protected String basePath() {
}

@Override
protected DspNamespace namespace() {
protected JsonLdNamespace namespace() {
return DSP_NAMESPACE_V_2024_1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import jakarta.json.JsonBuilderFactory;
import jakarta.json.JsonObject;
import org.eclipse.edc.connector.controlplane.contract.spi.types.agreement.ContractAgreementMessage;
import org.eclipse.edc.jsonld.spi.JsonLdNamespace;
import org.eclipse.edc.jsonld.spi.transformer.AbstractNamespaceAwareJsonLdTransformer;
import org.eclipse.edc.transform.spi.TransformerContext;
import org.jetbrains.annotations.NotNull;
Expand All @@ -26,9 +27,9 @@
import static java.time.Instant.ofEpochSecond;
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.Namespaces.DSPACE_SCHEMA;
import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_ASSIGNEE_ATTRIBUTE;
import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_ASSIGNER_ATTRIBUTE;
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_PROPERTY_AGREEMENT_TERM;
import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_TIMESTAMP_TERM;
import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_AGREEMENT_MESSAGE_TERM;
Expand All @@ -44,10 +45,10 @@ public class JsonObjectFromContractAgreementMessageTransformer extends AbstractN
private final JsonBuilderFactory jsonFactory;

public JsonObjectFromContractAgreementMessageTransformer(JsonBuilderFactory jsonFactory) {
this(jsonFactory, DSPACE_SCHEMA);
this(jsonFactory, DSP_NAMESPACE_V_08);
}

public JsonObjectFromContractAgreementMessageTransformer(JsonBuilderFactory jsonFactory, String namespace) {
public JsonObjectFromContractAgreementMessageTransformer(JsonBuilderFactory jsonFactory, JsonLdNamespace namespace) {
super(ContractAgreementMessage.class, JsonObject.class, namespace);
this.jsonFactory = jsonFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
import jakarta.json.JsonBuilderFactory;
import jakarta.json.JsonObject;
import org.eclipse.edc.connector.controlplane.contract.spi.types.agreement.ContractAgreementVerificationMessage;
import org.eclipse.edc.jsonld.spi.JsonLdNamespace;
import org.eclipse.edc.jsonld.spi.transformer.AbstractNamespaceAwareJsonLdTransformer;
import org.eclipse.edc.transform.spi.TransformerContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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.Namespaces.DSPACE_SCHEMA;
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_AGREEMENT_VERIFICATION_MESSAGE_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.DspPropertyAndTypeNames.DSPACE_PROPERTY_PROVIDER_PID_TERM;
Expand All @@ -37,10 +38,10 @@ public class JsonObjectFromContractAgreementVerificationMessageTransformer exten
private final JsonBuilderFactory jsonFactory;

public JsonObjectFromContractAgreementVerificationMessageTransformer(JsonBuilderFactory jsonFactory) {
this(jsonFactory, DSPACE_SCHEMA);
this(jsonFactory, DSP_NAMESPACE_V_08);
}

public JsonObjectFromContractAgreementVerificationMessageTransformer(JsonBuilderFactory jsonFactory, String namespace) {
public JsonObjectFromContractAgreementVerificationMessageTransformer(JsonBuilderFactory jsonFactory, JsonLdNamespace namespace) {
super(ContractAgreementVerificationMessage.class, JsonObject.class, namespace);
this.jsonFactory = jsonFactory;
}
Expand Down
Loading

0 comments on commit 2bf8b0a

Please sign in to comment.