Skip to content

Commit

Permalink
feat: fix dataset case according to DSP specs (#3351)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt committed Aug 4, 2023
1 parent 56bab11 commit f9f4bfb
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 50 deletions.
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ maven/mavencentral/org.junit.jupiter/junit-jupiter-params/5.10.0, EPL-2.0, appro
maven/mavencentral/org.junit.platform/junit-platform-commons/1.10.0, EPL-2.0, approved, #9715
maven/mavencentral/org.junit.platform/junit-platform-engine/1.10.0, EPL-2.0, approved, #9709
maven/mavencentral/org.junit.platform/junit-platform-launcher/1.10.0, EPL-2.0, approved, #9704
maven/mavencentral/org.junit/junit-bom/5.10.0, , restricted, clearlydefined
maven/mavencentral/org.junit/junit-bom/5.10.0, EPL-2.0, approved, #9844
maven/mavencentral/org.junit/junit-bom/5.9.2, EPL-2.0, approved, #4711
maven/mavencentral/org.jvnet.mimepull/mimepull/1.9.15, CDDL-1.1 OR GPL-2.0-only WITH Classpath-exception-2.0, approved, CQ21484
maven/mavencentral/org.latencyutils/LatencyUtils/2.0.3, BSD-2-Clause, approved, CQ17408
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void transform_catalogWithAdditionalProperty_returnCatalog() {

@Test
void transform_filledCatalog_returnCatalog() {
var dataSetJson = getJsonObject("dataset");
var datasetJson = getJsonObject("dataset");
var dataServiceJson = getJsonObject("dataService");

var dataset = Dataset.Builder.newInstance()
Expand All @@ -120,7 +120,7 @@ void transform_filledCatalog_returnCatalog() {
var catalog = jsonFactory.createObjectBuilder()
.add(ID, CATALOG_ID)
.add(TYPE, DCAT_CATALOG_TYPE)
.add(DCAT_DATASET_ATTRIBUTE, dataSetJson)
.add(DCAT_DATASET_ATTRIBUTE, datasetJson)
.add(DCAT_DATA_SERVICE_ATTRIBUTE, dataServiceJson)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static ContractRequestMessage contractRequestMessage() {
.processId("testId")
.counterPartyAddress("http://connector")
.callbackAddress("http://connector")
.dataSet("dataSet")
.dataset("dataset")
.contractOffer(contractOffer())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.jetbrains.annotations.Nullable;

import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_DATA_SET;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_DATASET;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_OFFER;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_OFFER_ID;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE;
Expand Down Expand Up @@ -58,7 +58,7 @@ public JsonObjectFromContractRequestMessageTransformer(JsonBuilderFactory jsonFa
}

if (requestMessage.getContractOffer() != null) {
builder.add(DSPACE_PROPERTY_DATA_SET, requestMessage.getContractOffer().getAssetId());
builder.add(DSPACE_PROPERTY_DATASET, requestMessage.getContractOffer().getAssetId());
var policy = context.transform(requestMessage.getContractOffer().getPolicy(), JsonObject.class);
if (policy == null) {
context.problem()
Expand All @@ -76,8 +76,8 @@ public JsonObjectFromContractRequestMessageTransformer(JsonBuilderFactory jsonFa

} else {
builder.add(DSPACE_PROPERTY_OFFER_ID, requestMessage.getContractOfferId());
if (requestMessage.getDataSet() != null) {
builder.add(DSPACE_PROPERTY_DATA_SET, requestMessage.getDataSet());
if (requestMessage.getDataset() != null) {
builder.add(DSPACE_PROPERTY_DATASET, requestMessage.getDataset());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_DATASET;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_DATA_SET;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_OFFER;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_OFFER_ID;
Expand Down Expand Up @@ -57,9 +60,12 @@ public JsonObjectToContractRequestMessageTransformer() {
builder.callbackAddress(transformString(callback, context));
}

var dataset = requestObject.get(DSPACE_PROPERTY_DATA_SET);
var dataset = Optional.of(requestObject)
.map(it -> it.get(DSPACE_PROPERTY_DATASET))
.orElseGet(() -> requestObject.get(DSPACE_PROPERTY_DATA_SET));

if (dataset != null) {
builder.dataSet(transformString(dataset, context));
builder.dataset(transformString(dataset, context));
}

var contractOffer = returnJsonObject(requestObject.get(DSPACE_PROPERTY_OFFER), context, DSPACE_PROPERTY_OFFER, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import static org.assertj.core.api.Assertions.assertThat;
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.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_DATA_SET;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_DATASET;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_OFFER;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_OFFER_ID;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE;
Expand Down Expand Up @@ -76,7 +76,7 @@ void verify_contractOffer() {
assertThat(result.getJsonString(ID).getString()).isNotEmpty();
assertThat(result.getJsonString(TYPE).getString()).isEqualTo(DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE);
assertThat(result.getJsonString(DSPACE_PROPERTY_PROCESS_ID).getString()).isEqualTo(PROCESS_ID);
assertThat(result.getJsonString(DSPACE_PROPERTY_DATA_SET).getString()).isEqualTo(DATASET_ID);
assertThat(result.getJsonString(DSPACE_PROPERTY_DATASET).getString()).isEqualTo(DATASET_ID);
assertThat(result.getJsonString(DSPACE_PROPERTY_CALLBACK_ADDRESS).getString()).isEqualTo(CALLBACK_ADDRESS);
assertThat(result.getJsonObject(DSPACE_PROPERTY_OFFER)).isNotNull();
assertThat(result.getJsonObject(DSPACE_PROPERTY_OFFER).getString(ID)).isEqualTo(CONTRACT_OFFER_ID);
Expand All @@ -90,7 +90,7 @@ void verify_contractOfferId() {
.protocol(PROTOCOL)
.processId(PROCESS_ID)
.callbackAddress(CALLBACK_ADDRESS)
.dataSet(DATASET_ID)
.dataset(DATASET_ID)
.contractOfferId(CONTRACT_OFFER_ID)
.build();

Expand All @@ -100,7 +100,7 @@ void verify_contractOfferId() {
assertThat(result.getJsonString(ID).getString()).isNotEmpty();
assertThat(result.getJsonString(TYPE).getString()).isEqualTo(DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE);
assertThat(result.getJsonString(DSPACE_PROPERTY_PROCESS_ID).getString()).isEqualTo(PROCESS_ID);
assertThat(result.getJsonString(DSPACE_PROPERTY_DATA_SET).getString()).isEqualTo(DATASET_ID);
assertThat(result.getJsonString(DSPACE_PROPERTY_DATASET).getString()).isEqualTo(DATASET_ID);
assertThat(result.getJsonString(DSPACE_PROPERTY_CALLBACK_ADDRESS).getString()).isEqualTo(CALLBACK_ADDRESS);
assertThat(result.getJsonString(DSPACE_PROPERTY_OFFER_ID)).isNotNull();

Expand All @@ -123,7 +123,7 @@ private ContractRequestMessage requestMessage() {
.protocol(PROTOCOL)
.processId(PROCESS_ID)
.callbackAddress(CALLBACK_ADDRESS)
.dataSet(DATASET_ID)
.dataset(DATASET_ID)
.contractOffer(contractOffer())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_POLICY_TYPE_OFFER;
import static org.eclipse.edc.protocol.dsp.negotiation.transform.to.TestInput.getExpanded;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_DATASET;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_DATA_SET;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_OFFER;
import static org.eclipse.edc.protocol.dsp.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_OFFER_ID;
Expand All @@ -56,7 +57,7 @@ class JsonObjectToContractRequestMessageTransformerTest {
private static final String CONTRACT_OFFER_ID = "contractOfferId";

private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of());
private final TransformerContext context = mock(TransformerContext.class);
private final TransformerContext context = mock();

private JsonObjectToContractRequestMessageTransformer transformer;

Expand All @@ -72,7 +73,7 @@ void verify_usingOffer() {
.add(JsonLdKeywords.ID, OBJECT_ID)
.add(JsonLdKeywords.TYPE, DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE)
.add(DSPACE_PROPERTY_PROCESS_ID, PROCESS_ID)
.add(DSPACE_PROPERTY_DATA_SET, DATASET_ID)
.add(DSPACE_PROPERTY_DATASET, DATASET_ID)
.add(DSPACE_PROPERTY_CALLBACK_ADDRESS, CALLBACK)
.add(DSPACE_PROPERTY_OFFER, contractOffer())
.build();
Expand All @@ -85,7 +86,7 @@ void verify_usingOffer() {
assertThat(result.getProtocol()).isNotEmpty();
assertThat(result.getProcessId()).isEqualTo(PROCESS_ID);
assertThat(result.getCallbackAddress()).isEqualTo(CALLBACK);
assertThat(result.getDataSet()).isEqualTo(DATASET_ID);
assertThat(result.getDataset()).isEqualTo(DATASET_ID);

var contractOffer = result.getContractOffer();
assertThat(contractOffer).isNotNull();
Expand All @@ -97,13 +98,32 @@ void verify_usingOffer() {
}

@Test
void verify_usingOfferId() {
void shouldDeserialize_whenDatasetIsWrittenWithTheWrongCase_deprecated() {
var message = jsonFactory.createObjectBuilder()
.add(JsonLdKeywords.ID, OBJECT_ID)
.add(JsonLdKeywords.TYPE, DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE)
.add(DSPACE_PROPERTY_PROCESS_ID, PROCESS_ID)
.add(DSPACE_PROPERTY_DATA_SET, DATASET_ID)
.add(DSPACE_PROPERTY_CALLBACK_ADDRESS, CALLBACK)
.add(DSPACE_PROPERTY_OFFER, contractOffer())
.build();

when(context.transform(any(JsonObject.class), eq(Policy.class))).thenReturn(policy());

var result = transformer.transform(getExpanded(message), context);

assertThat(result).isNotNull();
assertThat(result.getDataset()).isEqualTo(DATASET_ID);
}

@Test
void verify_usingOfferId() {
var message = jsonFactory.createObjectBuilder()
.add(JsonLdKeywords.ID, OBJECT_ID)
.add(JsonLdKeywords.TYPE, DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE)
.add(DSPACE_PROPERTY_PROCESS_ID, PROCESS_ID)
.add(DSPACE_PROPERTY_DATASET, DATASET_ID)
.add(DSPACE_PROPERTY_CALLBACK_ADDRESS, CALLBACK)
.add(DSPACE_PROPERTY_OFFER_ID, CONTRACT_OFFER_ID)
.build();

Expand All @@ -113,7 +133,7 @@ void verify_usingOfferId() {
assertThat(result.getProtocol()).isNotEmpty();
assertThat(result.getProcessId()).isEqualTo(PROCESS_ID);
assertThat(result.getCallbackAddress()).isEqualTo(CALLBACK);
assertThat(result.getDataSet()).isEqualTo(DATASET_ID);
assertThat(result.getDataset()).isEqualTo(DATASET_ID);

assertThat(result.getContractOfferId()).isNotNull();

Expand Down Expand Up @@ -165,7 +185,7 @@ void transform_nullPolicyFails() {
.add(JsonLdKeywords.ID, OBJECT_ID)
.add(JsonLdKeywords.TYPE, DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE)
.add(DSPACE_PROPERTY_PROCESS_ID, PROCESS_ID)
.add(DSPACE_PROPERTY_DATA_SET, DATASET_ID)
.add(DSPACE_PROPERTY_DATASET, DATASET_ID)
.add(DSPACE_PROPERTY_CALLBACK_ADDRESS, CALLBACK)
.add(DSPACE_PROPERTY_OFFER, contractOffer())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public interface DspNegotiationPropertyAndTypeNames {
String DSPACE_PROPERTY_AGREEMENT = DSPACE_SCHEMA + "agreement";
String DSPACE_PROPERTY_OFFER = DSPACE_SCHEMA + "offer";
String DSPACE_PROPERTY_OFFER_ID = DSPACE_SCHEMA + "offerId";
String DSPACE_PROPERTY_DATASET = DSPACE_SCHEMA + "dataset";
@Deprecated(since = "0.2.0")
String DSPACE_PROPERTY_DATA_SET = DSPACE_SCHEMA + "dataSet";
String DSPACE_PROPERTY_TIMESTAMP = DSPACE_SCHEMA + "timestamp";
String DSPACE_PROPERTY_CONSUMER_ID = DSPACE_SCHEMA + "consumerId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ContractRequestMessage implements ContractRemoteMessage {
private String processId;
private ContractOffer contractOffer;
private String contractOfferId;
private String dataSet;
private String dataset;

@NotNull
@Override
Expand Down Expand Up @@ -83,8 +83,8 @@ public String getContractOfferId() {
return contractOfferId;
}

public String getDataSet() {
return dataSet;
public String getDataset() {
return dataset;
}

public String getCallbackAddress() {
Expand All @@ -102,72 +102,72 @@ public enum Type {
}

public static class Builder {
private final ContractRequestMessage contractRequestMessage;
private final ContractRequestMessage message;

private Builder() {
contractRequestMessage = new ContractRequestMessage();
message = new ContractRequestMessage();
}

public static Builder newInstance() {
return new Builder();
}

public Builder id(String id) {
this.contractRequestMessage.id = id;
this.message.id = id;
return this;
}

public Builder protocol(String protocol) {
contractRequestMessage.protocol = protocol;
message.protocol = protocol;
return this;
}

public Builder callbackAddress(String callbackAddress) {
contractRequestMessage.callbackAddress = callbackAddress;
message.callbackAddress = callbackAddress;
return this;
}

public Builder counterPartyAddress(String counterPartyAddress) {
contractRequestMessage.counterPartyAddress = counterPartyAddress;
message.counterPartyAddress = counterPartyAddress;
return this;
}

public Builder processId(String processId) {
contractRequestMessage.processId = processId;
message.processId = processId;
return this;
}

public Builder contractOffer(ContractOffer contractOffer) {
contractRequestMessage.contractOffer = contractOffer;
message.contractOffer = contractOffer;
return this;
}

public Builder contractOfferId(String id) {
contractRequestMessage.contractOfferId = id;
message.contractOfferId = id;
return this;
}

public Builder type(Type type) {
contractRequestMessage.type = type;
message.type = type;
return this;
}

public Builder dataSet(String dataSet) {
contractRequestMessage.dataSet = dataSet;
public Builder dataset(String dataset) {
message.dataset = dataset;
return this;
}

public ContractRequestMessage build() {
if (contractRequestMessage.id == null) {
contractRequestMessage.id = randomUUID().toString();
if (message.id == null) {
message.id = randomUUID().toString();
}
requireNonNull(contractRequestMessage.processId, "processId");
if (contractRequestMessage.contractOfferId == null) {
requireNonNull(contractRequestMessage.contractOffer, "contractOffer");
requireNonNull(message.processId, "processId");
if (message.contractOfferId == null) {
requireNonNull(message.contractOffer, "contractOffer");
} else {
requireNonNull(contractRequestMessage.contractOfferId, "contractOfferId");
requireNonNull(message.contractOfferId, "contractOfferId");
}
return contractRequestMessage;
return message;
}
}
}
Loading

0 comments on commit f9f4bfb

Please sign in to comment.