Skip to content

Commit

Permalink
feat(dsp): remove offerId property (#3847)
Browse files Browse the repository at this point in the history
feat(dsp): remove offerId property
  • Loading branch information
ndr-brt authored Feb 13, 2024
1 parent aed00a4 commit 1324429
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.result.ServiceResult;
import org.eclipse.edc.spi.telemetry.Telemetry;
import org.eclipse.edc.spi.types.domain.offer.ContractOffer;
import org.eclipse.edc.transaction.spi.TransactionContext;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -215,9 +214,7 @@ private ServiceResult<ValidatedConsumerOffer> validateOffer(ClaimToken claimToke

@NotNull
private ServiceResult<ValidatableConsumerOffer> fetchValidatableOffer(ContractRequestMessage message) {
var offerId = Optional.ofNullable(message.getContractOffer())
.map(ContractOffer::getId)
.orElseGet(message::getContractOfferId);
var offerId = message.getContractOffer().getId();

var result = consumerOfferResolver.resolveOffer(offerId);
if (result.failed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
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;
import static org.eclipse.edc.protocol.dsp.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CALLBACK_ADDRESS;
import static org.eclipse.edc.protocol.dsp.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CONSUMER_PID;
Expand Down Expand Up @@ -75,9 +74,6 @@ public JsonObjectFromContractRequestMessageTransformer(JsonBuilderFactory jsonFa
.build();
builder.add(DSPACE_PROPERTY_OFFER, enrichedPolicy);

} else {
builder.add(DSPACE_PROPERTY_OFFER_ID, requestMessage.getContractOfferId());
addIfNotNull(requestMessage.getDataset(), DSPACE_PROPERTY_DATASET, builder);
}

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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_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;
import static org.eclipse.edc.protocol.dsp.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CALLBACK_ADDRESS;
import static org.eclipse.edc.protocol.dsp.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CONSUMER_PID;
Expand Down Expand Up @@ -100,14 +99,12 @@ public JsonObjectToContractRequestMessageTransformer() {
} else if (context.hasProblems()) {
return null;
} else {
if (!transformMandatoryString(requestObject.get(DSPACE_PROPERTY_OFFER_ID), builder::contractOfferId, context)) {
context.problem()
.missingProperty()
.type(DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE)
.property(DSPACE_PROPERTY_OFFER)
.report();
return null;
}
context.problem()
.missingProperty()
.type(DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE)
.property(DSPACE_PROPERTY_OFFER)
.report();
return null;
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
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;
import static org.eclipse.edc.protocol.dsp.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CALLBACK_ADDRESS;
import static org.eclipse.edc.protocol.dsp.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CONSUMER_PID;
Expand Down Expand Up @@ -94,25 +93,7 @@ void verify_contractOffer() {
}

@Test
void verify_contractOfferId() {
var message = contractRequestMessageBuilder()
.processId("processId")
.consumerPid(CONSUMER_PID)
.contractOfferId(CONTRACT_OFFER_ID)
.build();

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

assertThat(result).isNotNull();
assertThat(result.getJsonString(ID).getString()).isNotEmpty();
assertThat(result.getJsonString(TYPE).getString()).isEqualTo(DSPACE_TYPE_CONTRACT_REQUEST_MESSAGE);
assertThat(result.getString(DSPACE_PROPERTY_OFFER_ID)).isEqualTo(CONTRACT_OFFER_ID);

verify(context, never()).reportProblem(anyString());
}

@Test
void verify_nullPolicyFails() {
void shouldFail_whenPolicyCannotBeTransformed() {
var message = contractRequestMessageBuilder()
.processId("processId")
.consumerPid(CONSUMER_PID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
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_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;
import static org.eclipse.edc.protocol.dsp.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CALLBACK_ADDRESS;
import static org.eclipse.edc.protocol.dsp.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CONSUMER_PID;
Expand Down Expand Up @@ -100,32 +99,6 @@ void verify_usingOffer() {
verify(context, never()).reportProblem(anyString());
}

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

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

assertThat(result).isNotNull();
assertThat(result.getProtocol()).isNotEmpty();
assertThat(result.getConsumerPid()).isEqualTo("consumerPid");
assertThat(result.getProviderPid()).isEqualTo("providerPid");
assertThat(result.getCallbackAddress()).isEqualTo(CALLBACK);
assertThat(result.getDataset()).isEqualTo(DATASET_ID);

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

verify(context, never()).reportProblem(anyString());
}

@Deprecated(since = "0.4.1")
@Test
void verify_processId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public interface DspNegotiationPropertyAndTypeNames {
String DSPACE_PROPERTY_EVENT_TYPE = DSPACE_SCHEMA + "eventType";
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";
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 @@ -18,7 +18,7 @@
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.spi.types.domain.message.ProcessRemoteMessage;
import org.eclipse.edc.spi.types.domain.offer.ContractOffer;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;

import static java.util.Objects.requireNonNull;

Expand All @@ -32,23 +32,17 @@ public class ContractRequestMessage extends ContractRemoteMessage {
private String callbackAddress;

private ContractOffer contractOffer;
private String contractOfferId;
private String dataset;

public Type getType() {
return type;
}

@Nullable
@NotNull
public ContractOffer getContractOffer() {
return contractOffer;
}

@Nullable
public String getContractOfferId() {
return contractOfferId;
}

public String getDataset() {
return dataset;
}
Expand Down Expand Up @@ -87,11 +81,6 @@ public Builder contractOffer(ContractOffer contractOffer) {
return this;
}

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

public Builder type(Type type) {
message.type = type;
return this;
Expand All @@ -103,11 +92,7 @@ public Builder dataset(String dataset) {
}

public ContractRequestMessage build() {
if (message.contractOfferId == null) {
requireNonNull(message.contractOffer, "contractOffer");
} else {
requireNonNull(message.contractOfferId, "contractOfferId");
}
requireNonNull(message.contractOffer, "contractOffer");
return super.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,17 @@ void verify_noCallbackNeededForCounterOffer() {
.consumerPid("consumerPid")
.providerPid("providerPid")
.protocol(PROTOCOL)
.contractOfferId(OFFER_ID)
.contractOffer(ContractOffer.Builder.newInstance()
.id(ID)
.assetId(ASSET_ID)
.policy(Policy.Builder.newInstance().build())
.build())
.dataset(DATASET)
.build();
}

@Test
void verify_contractOfferIdOrContractOffer() {
ContractRequestMessage.Builder.newInstance()
.type(INITIAL)
.consumerPid("consumerPid")
.providerPid("providerPid")
.protocol(PROTOCOL)
.contractOfferId(OFFER_ID)
.dataset(DATASET)
.counterPartyAddress(CALLBACK_ADDRESS)
.build();

ContractRequestMessage.Builder.newInstance()
.type(INITIAL)
.consumerPid("consumerPid")
Expand All @@ -68,7 +62,7 @@ void verify_contractOfferIdOrContractOffer() {
.counterPartyAddress(CALLBACK_ADDRESS)
.build();

// verify no contract offer or contract offer id set
// verify no contract offer is set
assertThatThrownBy(() -> ContractRequestMessage.Builder.newInstance()
.type(INITIAL)
.consumerPid("consumerPid")
Expand Down

0 comments on commit 1324429

Please sign in to comment.