Skip to content

Commit f4169cf

Browse files
authored
refactor: remove control-plane address parse/validation (#5830)
1 parent 693936e commit f4169cf

6 files changed

Lines changed: 7 additions & 102 deletions

File tree

core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/controlplane/services/ControlPlaneServicesExtension.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
import org.eclipse.edc.connector.controlplane.services.transferprocess.TransferProcessProviderFactory;
6464
import org.eclipse.edc.connector.controlplane.services.transferprocess.TransferProcessServiceImpl;
6565
import org.eclipse.edc.connector.controlplane.transfer.spi.flow.DataFlowController;
66-
import org.eclipse.edc.connector.controlplane.transfer.spi.flow.TransferTypeParser;
6766
import org.eclipse.edc.connector.controlplane.transfer.spi.observe.TransferProcessObservable;
6867
import org.eclipse.edc.connector.controlplane.transfer.spi.store.TransferProcessStore;
6968
import org.eclipse.edc.connector.controlplane.transfer.spi.types.DataAddressStore;
@@ -89,7 +88,6 @@
8988
import org.eclipse.edc.spi.system.ServiceExtensionContext;
9089
import org.eclipse.edc.spi.telemetry.Telemetry;
9190
import org.eclipse.edc.transaction.spi.TransactionContext;
92-
import org.eclipse.edc.validator.spi.DataAddressValidatorRegistry;
9391

9492
import java.time.Clock;
9593

@@ -146,8 +144,6 @@ public class ControlPlaneServicesExtension implements ServiceExtension {
146144
@Inject
147145
private CommandHandlerRegistry commandHandlerRegistry;
148146
@Inject
149-
private DataAddressValidatorRegistry dataAddressValidator;
150-
@Inject
151147
private IdentityService identityService;
152148
@Inject
153149
private PolicyEngine policyEngine;
@@ -156,8 +152,6 @@ public class ControlPlaneServicesExtension implements ServiceExtension {
156152
@Inject
157153
private DataspaceProfileContextRegistry dataspaceProfileContextRegistry;
158154
@Inject
159-
private TransferTypeParser transferTypeParser;
160-
@Inject
161155
private ParticipantIdentityResolver identityResolver;
162156
@Inject
163157
private DataFlowController dataFlowController;
@@ -238,15 +232,15 @@ public PolicyDefinitionService policyDefinitionService() {
238232
@Provider
239233
public TransferProcessService transferProcessService() {
240234
return new TransferProcessServiceImpl(transferProcessStore, transactionContext,
241-
dataAddressValidator, commandHandlerRegistry, transferTypeParser, contractNegotiationStore,
235+
commandHandlerRegistry, contractNegotiationStore,
242236
QueryValidators.transferProcess());
243237
}
244238

245239
@Provider
246240
public TransferProcessProtocolService transferProcessProtocolService() {
247241
var factory = new TransferProcessProviderFactory(clock, telemetry, assetIndex);
248242
return new TransferProcessProtocolServiceImpl(transferProcessStore, transactionContext, contractNegotiationStore,
249-
contractValidationService, protocolTokenValidator(), dataAddressValidator, transferProcessObservable,
243+
contractValidationService, protocolTokenValidator(), transferProcessObservable,
250244
monitor, dataFlowController, dataAddressStore, factory);
251245
}
252246

core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/controlplane/services/transferprocess/TransferProcessProtocolServiceImpl.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.eclipse.edc.spi.result.StoreResult;
4747
import org.eclipse.edc.spi.types.domain.message.RemoteMessage;
4848
import org.eclipse.edc.transaction.spi.TransactionContext;
49-
import org.eclipse.edc.validator.spi.DataAddressValidatorRegistry;
5049
import org.jetbrains.annotations.NotNull;
5150

5251
import java.util.Optional;
@@ -65,7 +64,6 @@ public class TransferProcessProtocolServiceImpl implements TransferProcessProtoc
6564
private final TransactionContext transactionContext;
6665
private final ContractNegotiationStore negotiationStore;
6766
private final ContractValidationService contractValidationService;
68-
private final DataAddressValidatorRegistry dataAddressValidator;
6967
private final TransferProcessObservable observable;
7068
private final ProtocolTokenValidator protocolTokenValidator;
7169
private final Monitor monitor;
@@ -78,7 +76,6 @@ public TransferProcessProtocolServiceImpl(TransferProcessStore transferProcessSt
7876
ContractNegotiationStore negotiationStore,
7977
ContractValidationService contractValidationService,
8078
ProtocolTokenValidator protocolTokenValidator,
81-
DataAddressValidatorRegistry dataAddressValidator,
8279
TransferProcessObservable observable,
8380
Monitor monitor,
8481
DataFlowController dataFlowController, DataAddressStore dataAddressStore,
@@ -88,7 +85,6 @@ public TransferProcessProtocolServiceImpl(TransferProcessStore transferProcessSt
8885
this.negotiationStore = negotiationStore;
8986
this.contractValidationService = contractValidationService;
9087
this.protocolTokenValidator = protocolTokenValidator;
91-
this.dataAddressValidator = dataAddressValidator;
9288
this.observable = observable;
9389
this.monitor = monitor;
9490
this.dataFlowController = dataFlowController;
@@ -158,14 +154,6 @@ public ServiceResult<TransferProcess> findById(ParticipantContext participantCon
158154

159155
@NotNull
160156
private ServiceResult<TransferProcess> requestedAction(ParticipantContext participantContext, TransferRequestMessage message, ClaimTokenContext context) {
161-
var destination = message.getDataAddress();
162-
if (destination != null) {
163-
var validDestination = dataAddressValidator.validateDestination(destination);
164-
if (validDestination.failed()) {
165-
return ServiceResult.badRequest(validDestination.getFailureMessages());
166-
}
167-
}
168-
169157
var transferType = message.getTransferType();
170158
var supportedTransferTypes = dataFlowController.transferTypesFor(context.agreement().getAssetId());
171159
if (!supportedTransferTypes.contains(transferType)) {

core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/controlplane/services/transferprocess/TransferProcessServiceImpl.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.eclipse.edc.connector.controlplane.contract.spi.negotiation.store.ContractNegotiationStore;
1919
import org.eclipse.edc.connector.controlplane.services.query.QueryValidator;
2020
import org.eclipse.edc.connector.controlplane.services.spi.transferprocess.TransferProcessService;
21-
import org.eclipse.edc.connector.controlplane.transfer.spi.flow.TransferTypeParser;
2221
import org.eclipse.edc.connector.controlplane.transfer.spi.store.TransferProcessStore;
2322
import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcess;
2423
import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates;
@@ -35,9 +34,7 @@
3534
import org.eclipse.edc.spi.command.EntityCommand;
3635
import org.eclipse.edc.spi.query.QuerySpec;
3736
import org.eclipse.edc.spi.result.ServiceResult;
38-
import org.eclipse.edc.spi.types.domain.transfer.FlowType;
3937
import org.eclipse.edc.transaction.spi.TransactionContext;
40-
import org.eclipse.edc.validator.spi.DataAddressValidatorRegistry;
4138
import org.jetbrains.annotations.NotNull;
4239
import org.jetbrains.annotations.Nullable;
4340

@@ -50,20 +47,16 @@ public class TransferProcessServiceImpl implements TransferProcessService {
5047
private final TransferProcessStore transferProcessStore;
5148
private final TransactionContext transactionContext;
5249
private final QueryValidator queryValidator;
53-
private final DataAddressValidatorRegistry dataAddressValidator;
5450
private final CommandHandlerRegistry commandHandlerRegistry;
55-
private final TransferTypeParser transferTypeParser;
5651
private final ContractNegotiationStore contractNegotiationStore;
5752

5853
public TransferProcessServiceImpl(TransferProcessStore transferProcessStore,
59-
TransactionContext transactionContext, DataAddressValidatorRegistry dataAddressValidator,
60-
CommandHandlerRegistry commandHandlerRegistry, TransferTypeParser transferTypeParser,
54+
TransactionContext transactionContext,
55+
CommandHandlerRegistry commandHandlerRegistry,
6156
ContractNegotiationStore contractNegotiationStore, QueryValidator queryValidator) {
6257
this.transferProcessStore = transferProcessStore;
6358
this.transactionContext = transactionContext;
64-
this.dataAddressValidator = dataAddressValidator;
6559
this.commandHandlerRegistry = commandHandlerRegistry;
66-
this.transferTypeParser = transferTypeParser;
6760
this.contractNegotiationStore = contractNegotiationStore;
6861
this.queryValidator = queryValidator;
6962
}
@@ -112,25 +105,11 @@ public ServiceResult<List<TransferProcess>> search(QuerySpec query) {
112105

113106
@Override
114107
public @NotNull ServiceResult<TransferProcess> initiateTransfer(ParticipantContext participantContext, TransferRequest request) {
115-
var transferTypeParse = transferTypeParser.parse(request.getTransferType());
116-
if (transferTypeParse.failed()) {
117-
return ServiceResult.badRequest("Property transferType not valid: " + transferTypeParse.getFailureDetail());
118-
}
119-
120108
var agreement = contractNegotiationStore.findContractAgreement(request.getContractId());
121109
if (agreement == null) {
122110
return ServiceResult.badRequest("Contract agreement with id %s not found".formatted(request.getContractId()));
123111
}
124112

125-
var flowType = transferTypeParse.getContent().flowType();
126-
127-
if (flowType == FlowType.PUSH && request.getDataDestination() != null) {
128-
var validDestination = dataAddressValidator.validateDestination(request.getDataDestination());
129-
if (validDestination.failed()) {
130-
return ServiceResult.badRequest(validDestination.getFailureMessages());
131-
}
132-
}
133-
134113
return transactionContext.execute(() -> commandHandlerRegistry
135114
.execute(new InitiateTransferCommand(participantContext, request))
136115
.flatMap(result -> {

core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/controlplane/services/transferprocess/TransferProcessProtocolServiceImplTest.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
import org.eclipse.edc.spi.types.domain.message.RemoteMessage;
4949
import org.eclipse.edc.transaction.spi.NoopTransactionContext;
5050
import org.eclipse.edc.transaction.spi.TransactionContext;
51-
import org.eclipse.edc.validator.spi.DataAddressValidatorRegistry;
52-
import org.eclipse.edc.validator.spi.ValidationResult;
5351
import org.junit.jupiter.api.BeforeEach;
5452
import org.junit.jupiter.api.Nested;
5553
import org.junit.jupiter.api.Test;
@@ -86,7 +84,6 @@
8684
import static org.eclipse.edc.spi.result.ServiceFailure.Reason.BAD_REQUEST;
8785
import static org.eclipse.edc.spi.result.ServiceFailure.Reason.CONFLICT;
8886
import static org.eclipse.edc.spi.result.ServiceFailure.Reason.NOT_FOUND;
89-
import static org.eclipse.edc.validator.spi.Violation.violation;
9087
import static org.junit.jupiter.params.provider.Arguments.arguments;
9188
import static org.mockito.ArgumentMatchers.any;
9289
import static org.mockito.ArgumentMatchers.anyString;
@@ -107,7 +104,6 @@ class TransferProcessProtocolServiceImplTest {
107104
private final TransactionContext transactionContext = spy(new NoopTransactionContext());
108105
private final ContractNegotiationStore negotiationStore = mock();
109106
private final ContractValidationService validationService = mock();
110-
private final DataAddressValidatorRegistry dataAddressValidator = mock();
111107
private final TransferProcessListener listener = mock();
112108
private final ProtocolTokenValidator protocolTokenValidator = mock();
113109
private final DataAddressStore dataAddressStore = mock();
@@ -124,7 +120,7 @@ void setUp() {
124120
var observable = new TransferProcessObservableImpl();
125121
observable.registerListener(listener);
126122
service = new TransferProcessProtocolServiceImpl(store, transactionContext, negotiationStore, validationService,
127-
protocolTokenValidator, dataAddressValidator, observable, mock(), dataFlowController,
123+
protocolTokenValidator, observable, mock(), dataFlowController,
128124
dataAddressStore, transferProcessProviderFactory);
129125
when(store.save(any())).thenReturn(StoreResult.success());
130126
}
@@ -340,7 +336,6 @@ void validAgreement_shouldInitiateTransfer() {
340336
when(validationService.validateRequest(any(), isA(ContractAgreement.class))).thenReturn(Result.success());
341337
when(negotiationStore.queryAgreements(any())).thenReturn(Stream.of(contractAgreement()));
342338
when(validationService.validateAgreement(any(ParticipantAgent.class), any())).thenReturn(Result.success(null));
343-
when(dataAddressValidator.validateDestination(any())).thenReturn(ValidationResult.success());
344339
when(dataFlowController.transferTypesFor(anyString())).thenReturn(Set.of("transferType"));
345340
when(dataAddressStore.store(any(), any())).thenReturn(StoreResult.success());
346341
var transferProcess = transferProcess(INITIAL, "transferProcessId");
@@ -374,7 +369,6 @@ void shouldFail_whenInvalidRequest() {
374369
when(validationService.validateRequest(any(), isA(ContractAgreement.class))).thenReturn(Result.failure("invalid credentials"));
375370
when(negotiationStore.queryAgreements(any())).thenReturn(Stream.of(contractAgreement()));
376371
when(validationService.validateAgreement(any(ParticipantAgent.class), any())).thenReturn(Result.success(null));
377-
when(dataAddressValidator.validateDestination(any())).thenReturn(ValidationResult.success());
378372
var transferProcess = transferProcess(INITIAL, "transferProcessId");
379373
when(transferProcessProviderFactory.create(any(), any(), any(), any())).thenReturn(ServiceResult.success(transferProcess));
380374

@@ -404,7 +398,6 @@ void shouldFail_whenDataAddressStorageFails() {
404398
when(validationService.validateRequest(any(), isA(ContractAgreement.class))).thenReturn(Result.success());
405399
when(negotiationStore.queryAgreements(any())).thenReturn(Stream.of(contractAgreement()));
406400
when(validationService.validateAgreement(any(ParticipantAgent.class), any())).thenReturn(Result.success(null));
407-
when(dataAddressValidator.validateDestination(any())).thenReturn(ValidationResult.success());
408401
when(dataFlowController.transferTypesFor(anyString())).thenReturn(Set.of("transferType"));
409402
when(dataAddressStore.store(any(), any())).thenReturn(StoreResult.generalError("error"));
410403
when(transferProcessProviderFactory.create(any(), any(), any(), any())).thenReturn(ServiceResult.success(transferProcess(INITIAL, "transferProcessId")));
@@ -433,7 +426,6 @@ void shouldFail_whenTransferProcessCreationFails() {
433426
when(validationService.validateRequest(any(), isA(ContractAgreement.class))).thenReturn(Result.success());
434427
when(negotiationStore.queryAgreements(any())).thenReturn(Stream.of(contractAgreement()));
435428
when(validationService.validateAgreement(any(ParticipantAgent.class), any())).thenReturn(Result.success(null));
436-
when(dataAddressValidator.validateDestination(any())).thenReturn(ValidationResult.success());
437429
when(dataFlowController.transferTypesFor(anyString())).thenReturn(Set.of("transferType"));
438430
when(transferProcessProviderFactory.create(any(), any(), any(), any())).thenReturn(ServiceResult.badRequest("cannot create transfer process"));
439431

@@ -464,7 +456,6 @@ void doNothingIfProcessAlreadyExist() {
464456
when(validationService.validateRequest(any(), isA(ContractAgreement.class))).thenReturn(Result.success());
465457
when(negotiationStore.queryAgreements(any())).thenReturn(Stream.of(contractAgreement()));
466458
when(validationService.validateAgreement(any(ParticipantAgent.class), any())).thenReturn(Result.success(null));
467-
when(dataAddressValidator.validateDestination(any())).thenReturn(ValidationResult.success());
468459
when(store.findForCorrelationId(any())).thenReturn(transferProcess(REQUESTED, "transferProcessId"));
469460
when(dataFlowController.transferTypesFor(anyString())).thenReturn(Set.of("transferType"));
470461

@@ -492,7 +483,6 @@ void invalidAgreement_shouldNotInitiateTransfer() {
492483
when(validationService.validateRequest(any(), isA(ContractAgreement.class))).thenReturn(Result.success());
493484
when(negotiationStore.queryAgreements(any())).thenReturn(Stream.of(contractAgreement()));
494485
when(validationService.validateAgreement(any(ParticipantAgent.class), any())).thenReturn(Result.failure("error"));
495-
when(dataAddressValidator.validateDestination(any())).thenReturn(ValidationResult.success());
496486
when(dataFlowController.transferTypesFor(anyString())).thenReturn(Set.of("transferType"));
497487

498488
var result = service.notifyRequested(participantContext, message, tokenRepresentation);
@@ -517,7 +507,6 @@ void invalidDestination_shouldNotInitiateTransfer() {
517507
when(negotiationStore.queryAgreements(any())).thenReturn(Stream.of(contractAgreement()));
518508
when(protocolTokenValidator.verify(eq(participantContext), eq(tokenRepresentation), any(), any(), eq(message))).thenReturn(ServiceResult.success(participantAgent));
519509
when(validationService.validateRequest(any(), isA(ContractAgreement.class))).thenReturn(Result.success());
520-
when(dataAddressValidator.validateDestination(any())).thenReturn(ValidationResult.failure(violation("invalid data address", "path")));
521510

522511
var result = service.notifyRequested(participantContext, message, tokenRepresentation);
523512

@@ -544,7 +533,6 @@ void shouldReturnBadRequest_whenTransferTypeNotSupported() {
544533
when(validationService.validateRequest(any(), isA(ContractAgreement.class))).thenReturn(Result.success());
545534
when(negotiationStore.queryAgreements(any())).thenReturn(Stream.of(contractAgreement));
546535
when(validationService.validateAgreement(any(ParticipantAgent.class), any())).thenReturn(Result.success(contractAgreement));
547-
when(dataAddressValidator.validateDestination(any())).thenReturn(ValidationResult.success());
548536
when(dataFlowController.transferTypesFor(anyString())).thenReturn(Set.of("supported-transfer-type"));
549537

550538
var result = service.notifyRequested(participantContext, message, tokenRepresentation);

0 commit comments

Comments
 (0)