From 132442934cdcf291ad5e7478bb45bbf6f38f847f Mon Sep 17 00:00:00 2001 From: ndr_brt Date: Tue, 13 Feb 2024 13:40:10 +0100 Subject: [PATCH] feat(dsp): remove `offerId` property (#3847) feat(dsp): remove offerId property --- ...ontractNegotiationProtocolServiceImpl.java | 5 +--- ...FromContractRequestMessageTransformer.java | 4 --- ...ctToContractRequestMessageTransformer.java | 15 +++++------ ...ContractRequestMessageTransformerTest.java | 21 +-------------- ...ContractRequestMessageTransformerTest.java | 27 ------------------- .../DspNegotiationPropertyAndTypeNames.java | 1 - .../negotiation/ContractRequestMessage.java | 21 +++------------ .../ContractRequestMessageTest.java | 18 +++++-------- 8 files changed, 17 insertions(+), 95 deletions(-) diff --git a/core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationProtocolServiceImpl.java b/core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationProtocolServiceImpl.java index 2f699435c47..d71f5d25566 100644 --- a/core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationProtocolServiceImpl.java +++ b/core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/service/contractnegotiation/ContractNegotiationProtocolServiceImpl.java @@ -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; @@ -215,9 +214,7 @@ private ServiceResult validateOffer(ClaimToken claimToke @NotNull private ServiceResult 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()) { diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractRequestMessageTransformer.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractRequestMessageTransformer.java index 71f5fe1218d..33fc6c8600e 100644 --- a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractRequestMessageTransformer.java +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractRequestMessageTransformer.java @@ -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; @@ -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(); diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractRequestMessageTransformer.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractRequestMessageTransformer.java index 2cabeb420fc..9a5ffa570dc 100644 --- a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractRequestMessageTransformer.java +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractRequestMessageTransformer.java @@ -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; @@ -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(); } diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractRequestMessageTransformerTest.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractRequestMessageTransformerTest.java index 08ecffe327e..3b1130ba4ea 100644 --- a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractRequestMessageTransformerTest.java +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractRequestMessageTransformerTest.java @@ -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; @@ -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) diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractRequestMessageTransformerTest.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractRequestMessageTransformerTest.java index d67e0aa7438..1383789eaaa 100644 --- a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractRequestMessageTransformerTest.java +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractRequestMessageTransformerTest.java @@ -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; @@ -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() { diff --git a/data-protocols/dsp/dsp-spi/src/main/java/org/eclipse/edc/protocol/dsp/type/DspNegotiationPropertyAndTypeNames.java b/data-protocols/dsp/dsp-spi/src/main/java/org/eclipse/edc/protocol/dsp/type/DspNegotiationPropertyAndTypeNames.java index 1bdb3a23f7f..64fc6187f60 100644 --- a/data-protocols/dsp/dsp-spi/src/main/java/org/eclipse/edc/protocol/dsp/type/DspNegotiationPropertyAndTypeNames.java +++ b/data-protocols/dsp/dsp-spi/src/main/java/org/eclipse/edc/protocol/dsp/type/DspNegotiationPropertyAndTypeNames.java @@ -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"; diff --git a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequestMessage.java b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequestMessage.java index 8bfbc233cc8..645913307da 100644 --- a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequestMessage.java +++ b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequestMessage.java @@ -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; @@ -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; } @@ -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; @@ -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(); } } diff --git a/spi/control-plane/contract-spi/src/test/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequestMessageTest.java b/spi/control-plane/contract-spi/src/test/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequestMessageTest.java index c0a00d17ba6..10bb3402202 100644 --- a/spi/control-plane/contract-spi/src/test/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequestMessageTest.java +++ b/spi/control-plane/contract-spi/src/test/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractRequestMessageTest.java @@ -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") @@ -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")