Skip to content

Commit

Permalink
refactor: cleanup 0.4.x deprecations (#4354)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt authored Jul 11, 2024
1 parent 376ed9b commit 0fcb727
Show file tree
Hide file tree
Showing 44 changed files with 113 additions and 762 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ public <T> Result<T> execute(Request request, List<FallbackFactory> fallbacks, F
}
}

@Override
public <T> CompletableFuture<T> executeAsync(Request request, Function<Response, T> mappingFunction) {
return executeAsync(request, emptyList(), mappingFunction);
}

@Override
public CompletableFuture<Response> executeAsync(Request request, List<FallbackFactory> fallbacks) {
var call = okHttpClient.newCall(request);
Expand All @@ -89,16 +84,6 @@ public CompletableFuture<Response> executeAsync(Request request, List<FallbackFa
.executeAsync();
}

@Override
public <T> CompletableFuture<T> executeAsync(Request request, List<FallbackFactory> fallbacks, Function<Response, T> mappingFunction) {
return executeAsync(request, fallbacks)
.thenApply(response -> {
try (response) {
return mappingFunction.apply(response);
}
});
}

@Override
public EdcHttpClient withDns(String dnsServer) {
var url = requireNonNull(HttpUrl.get(dnsServer));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,6 @@ private ServiceResult<ContractNegotiation> terminatedAction(ContractNegotiationT

private ServiceResult<ContractNegotiation> getAndLeaseNegotiation(String negotiationId) {
return store.findByIdAndLease(negotiationId)
// recover needed to maintain backward compatibility when there was no distinction between providerPid and consumerPid
.recover(it -> store.findByCorrelationIdAndLease(negotiationId))
.flatMap(ServiceResult::from);
}

Expand All @@ -326,8 +324,6 @@ private ServiceResult<ParticipantAgent> verifyRequest(TokenRepresentation tokenR

private ServiceResult<ContractNegotiation> getNegotiation(String negotiationId) {
return Optional.ofNullable(store.findById(negotiationId))
// recover needed to maintain backward compatibility when there was no distinction between providerPid and consumerPid
.or(() -> Optional.ofNullable(store.findForCorrelationId(negotiationId)))
.map(ServiceResult::success)
.orElseGet(() -> ServiceResult.notFound("No negotiation with id %s found".formatted(negotiationId)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@ private ServiceResult<TransferProcess> validateCounterParty(ParticipantAgent par
private ServiceResult<TransferProcess> findAndLease(TransferRemoteMessage remoteMessage) {
return transferProcessStore
.findByIdAndLease(remoteMessage.getProcessId())
// recover needed to maintain backward compatibility when there was no distinction between providerPid and consumerPid
.recover(it -> transferProcessStore.findByCorrelationIdAndLease(remoteMessage.getProcessId()))
.flatMap(ServiceResult::from);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ <M extends RemoteMessage> void notify_shouldReturnNotFound_whenNotFound(MethodCa
when(protocolTokenValidator.verify(eq(tokenRepresentation), eq(CONTRACT_NEGOTIATION_REQUEST_SCOPE), any(), eq(message)))
.thenReturn(ServiceResult.success(participantAgent()));
when(store.findByIdAndLease(any())).thenReturn(StoreResult.notFound("not found"));
when(store.findByCorrelationIdAndLease(any())).thenReturn(StoreResult.notFound("not found"));

// currently ContractRequestMessage cannot happen on an already existing negotiation
if (!(message instanceof ContractRequestMessage)) {
Expand Down Expand Up @@ -708,7 +707,6 @@ void shouldReturnNotFound_whenOfferNotFound() {
when(protocolTokenValidator.verify(eq(tokenRepresentation), eq(CONTRACT_NEGOTIATION_REQUEST_SCOPE), any(), eq(message)))
.thenReturn(ServiceResult.success(participantAgent()));
when(store.findByIdAndLease(any())).thenReturn(StoreResult.notFound("not found"));
when(store.findByCorrelationIdAndLease(any())).thenReturn(StoreResult.notFound("not found"));

var result = service.notifyOffered(message, tokenRepresentation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ <M extends RemoteMessage> void notify_shouldFail_whenTransferProcessNotFound(Met

when(protocolTokenValidator.verify(eq(tokenRepresentation), eq(TRANSFER_PROCESS_REQUEST_SCOPE), any())).thenReturn(ServiceResult.success(participantAgent));
when(store.findByIdAndLease(any())).thenReturn(StoreResult.notFound("not found"));
when(store.findByCorrelationIdAndLease(any())).thenReturn(StoreResult.notFound("not found"));

var result = methodCall.call(service, message, tokenRepresentation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

package org.eclipse.edc.connector.controlplane.contract.negotiation;

import org.eclipse.edc.connector.controlplane.contract.observe.ContractNegotiationObservableImpl;
import org.eclipse.edc.connector.controlplane.contract.spi.ContractOfferId;
import org.eclipse.edc.connector.controlplane.contract.spi.offer.ConsumerOfferResolver;
import org.eclipse.edc.connector.controlplane.contract.spi.types.agreement.ContractAgreement;
Expand All @@ -35,7 +34,6 @@
import org.eclipse.edc.connector.controlplane.contract.spi.validation.ValidatableConsumerOffer;
import org.eclipse.edc.connector.controlplane.contract.spi.validation.ValidatedConsumerOffer;
import org.eclipse.edc.connector.controlplane.defaults.storage.contractnegotiation.InMemoryContractNegotiationStore;
import org.eclipse.edc.connector.controlplane.policy.spi.store.PolicyDefinitionStore;
import org.eclipse.edc.connector.controlplane.services.contractnegotiation.ContractNegotiationProtocolServiceImpl;
import org.eclipse.edc.connector.controlplane.services.spi.contractnegotiation.ContractNegotiationProtocolService;
import org.eclipse.edc.connector.controlplane.services.spi.protocol.ProtocolTokenValidator;
Expand Down Expand Up @@ -75,6 +73,7 @@
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Stream;

import static java.util.UUID.randomUUID;
Expand Down Expand Up @@ -122,6 +121,8 @@ class ContractNegotiationIntegrationTest {
protected ParticipantAgent participantAgent = new ParticipantAgent(Collections.emptyMap(), Collections.emptyMap());
protected TokenRepresentation tokenRepresentation = TokenRepresentation.Builder.newInstance().build();
private String consumerNegotiationId;
private final AtomicReference<String> providerNegotiationId = new AtomicReference<>(null);
private final NoopTransactionContext transactionContext = new NoopTransactionContext();

private ProviderContractNegotiationManagerImpl providerManager;
private ConsumerContractNegotiationManagerImpl consumerManager;
Expand All @@ -137,25 +138,25 @@ void init() {
.dispatcherRegistry(providerDispatcherRegistry)
.monitor(monitor)
.waitStrategy(() -> 1000)
.observable(new ContractNegotiationObservableImpl())
.observable(mock())
.store(providerStore)
.policyStore(mock(PolicyDefinitionStore.class))
.policyStore(mock())
.protocolWebhook(protocolWebhook)
.build();

consumerManager = ConsumerContractNegotiationManagerImpl.Builder.newInstance()
.participantId(CONSUMER_ID)
.dispatcherRegistry(consumerDispatcherRegistry)
.monitor(monitor).waitStrategy(() -> 1000)
.observable(new ContractNegotiationObservableImpl())
.observable(mock())
.store(consumerStore)
.policyStore(mock(PolicyDefinitionStore.class))
.policyStore(mock())
.protocolWebhook(protocolWebhook)
.build();

when(protocolTokenValidator.verify(eq(tokenRepresentation), any(), any(), any())).thenReturn(ServiceResult.success(participantAgent));
consumerService = new ContractNegotiationProtocolServiceImpl(consumerStore, new NoopTransactionContext(), validationService, offerResolver, protocolTokenValidator, new ContractNegotiationObservableImpl(), monitor, mock());
providerService = new ContractNegotiationProtocolServiceImpl(providerStore, new NoopTransactionContext(), validationService, offerResolver, protocolTokenValidator, new ContractNegotiationObservableImpl(), monitor, mock());
consumerService = new ContractNegotiationProtocolServiceImpl(consumerStore, transactionContext, validationService, offerResolver, protocolTokenValidator, mock(), monitor, mock());
providerService = new ContractNegotiationProtocolServiceImpl(providerStore, transactionContext, validationService, offerResolver, protocolTokenValidator, mock(), monitor, mock());
}

@AfterEach
Expand Down Expand Up @@ -197,9 +198,10 @@ void testNegotiation_initialOfferAccepted() {
await().atMost(DEFAULT_TEST_TIMEOUT).pollInterval(DEFAULT_POLL_INTERVAL).untilAsserted(() -> {
assertThat(consumerNegotiationId).isNotNull();
var consumerNegotiation = consumerStore.findById(consumerNegotiationId);
var providerNegotiation = providerStore.findForCorrelationId(consumerNegotiationId);
var maybeProviderNegotiation = providerStore.findAll().filter(it -> it.getCorrelationId().equals(consumerNegotiationId)).findAny();
assertThat(consumerNegotiation).isNotNull();
assertThat(providerNegotiation).isNotNull();
assertThat(maybeProviderNegotiation).isPresent();
var providerNegotiation = maybeProviderNegotiation.get();

// Assert that the consumer has the callbacks
assertThat(consumerNegotiation.getCallbackAddresses()).hasSize(1);
Expand Down Expand Up @@ -279,9 +281,10 @@ void testNegotiation_agreementDeclined() {
await().atMost(DEFAULT_TEST_TIMEOUT).pollInterval(DEFAULT_POLL_INTERVAL).untilAsserted(() -> {
assertThat(consumerNegotiationId).isNotNull();
var consumerNegotiation = consumerStore.findById(consumerNegotiationId);
var providerNegotiation = providerStore.findForCorrelationId(consumerNegotiationId);
var maybeProviderNegotiation = providerStore.findAll().filter(it -> it.getCorrelationId().equals(consumerNegotiationId)).findAny();
assertThat(consumerNegotiation).isNotNull();
assertThat(providerNegotiation).isNotNull();
assertThat(maybeProviderNegotiation).isPresent();
var providerNegotiation = maybeProviderNegotiation.get();

// Assert that the consumer has the callbacks
assertThat(consumerNegotiation.getCallbackAddresses()).hasSize(1);
Expand Down Expand Up @@ -323,6 +326,7 @@ private Answer<Object> onConsumerSentTermination() {
private Answer<Object> onProviderSentAgreementRequest() {
return i -> {
ContractAgreementMessage request = i.getArgument(1);
providerNegotiationId.set(request.getProviderPid());
var result = consumerService.notifyAgreed(request, tokenRepresentation);
return toFuture(result, "Success!");
};
Expand All @@ -341,6 +345,7 @@ private Answer<Object> onProviderSentNegotiationEventMessage() {
private Answer<Object> onConsumerSentAgreementVerification() {
return i -> {
ContractAgreementVerificationMessage request = i.getArgument(1);
request.setProcessId(providerNegotiationId.get());
var result = providerService.notifyVerified(request, tokenRepresentation);
return toFuture(result, "Success!");
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.edc.spi.query.CriterionOperatorRegistry;
import org.eclipse.edc.spi.query.QueryResolver;
import org.eclipse.edc.spi.query.QuerySpec;
import org.eclipse.edc.spi.result.StoreResult;
import org.eclipse.edc.store.InMemoryStatefulEntityStore;
import org.eclipse.edc.store.ReflectionBasedQueryResolver;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -86,16 +85,6 @@ public void delete(String negotiationId) {
return agreementQueryResolver.query(getAgreements(), querySpec);
}

@Override
public StoreResult<ContractNegotiation> findByCorrelationIdAndLease(String correlationId) {
var negotiation = findForCorrelationId(correlationId);
if (negotiation == null) {
return StoreResult.notFound(format("ContractNegotiation with correlationId %s not found", correlationId));
}

return findByIdAndLease(negotiation.getId());
}

@NotNull
private Stream<ContractAgreement> getAgreements() {
return super.findAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcess;
import org.eclipse.edc.spi.query.CriterionOperatorRegistry;
import org.eclipse.edc.spi.query.QuerySpec;
import org.eclipse.edc.spi.result.StoreResult;
import org.eclipse.edc.store.InMemoryStatefulEntityStore;
import org.jetbrains.annotations.Nullable;

import java.time.Clock;
import java.util.UUID;
import java.util.stream.Stream;

import static java.lang.String.format;
import static org.eclipse.edc.spi.query.Criterion.criterion;

/**
Expand Down Expand Up @@ -59,14 +57,4 @@ public Stream<TransferProcess> findAll(QuerySpec querySpec) {
return super.findAll(querySpec);
}

@Override
public StoreResult<TransferProcess> findByCorrelationIdAndLease(String correlationId) {
var transferProcess = findForCorrelationId(correlationId);
if (transferProcess == null) {
return StoreResult.notFound(format("TransferProcess with correlationId %s not found", correlationId));
}

return findByIdAndLease(transferProcess.getId());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_PROPERTY_TIMESTAMP;
import static org.eclipse.edc.protocol.dsp.spi.type.DspNegotiationPropertyAndTypeNames.DSPACE_TYPE_CONTRACT_AGREEMENT_MESSAGE;
import static org.eclipse.edc.protocol.dsp.spi.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CONSUMER_PID;
import static org.eclipse.edc.protocol.dsp.spi.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_PROCESS_ID;
import static org.eclipse.edc.protocol.dsp.spi.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_PROVIDER_PID;

/**
Expand All @@ -52,30 +51,21 @@ public JsonObjectToContractAgreementMessageTransformer() {
@Override
public @Nullable ContractAgreementMessage transform(@NotNull JsonObject object, @NotNull TransformerContext context) {
var messageBuilder = ContractAgreementMessage.Builder.newInstance();
var processId = object.get(DSPACE_PROPERTY_PROCESS_ID);
if (!transformMandatoryString(object.get(DSPACE_PROPERTY_CONSUMER_PID), messageBuilder::consumerPid, context)) {
if (processId == null) {
context.problem()
.missingProperty()
.type(DSPACE_TYPE_CONTRACT_AGREEMENT_MESSAGE)
.property(DSPACE_PROPERTY_CONSUMER_PID)
.report();
return null;
} else {
messageBuilder.consumerPid(transformString(processId, context));
}
context.problem()
.missingProperty()
.type(DSPACE_TYPE_CONTRACT_AGREEMENT_MESSAGE)
.property(DSPACE_PROPERTY_CONSUMER_PID)
.report();
return null;
}
if (!transformMandatoryString(object.get(DSPACE_PROPERTY_PROVIDER_PID), messageBuilder::providerPid, context)) {
if (processId == null) {
context.problem()
.missingProperty()
.type(DSPACE_TYPE_CONTRACT_AGREEMENT_MESSAGE)
.property(DSPACE_PROPERTY_PROVIDER_PID)
.report();
return null;
} else {
messageBuilder.providerPid(transformString(processId, context));
}
context.problem()
.missingProperty()
.type(DSPACE_TYPE_CONTRACT_AGREEMENT_MESSAGE)
.property(DSPACE_PROPERTY_PROVIDER_PID)
.report();
return null;
}

var jsonAgreement = returnMandatoryJsonObject(object.get(DSPACE_PROPERTY_AGREEMENT), context, DSPACE_PROPERTY_AGREEMENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.jetbrains.annotations.Nullable;

import static org.eclipse.edc.protocol.dsp.spi.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CONSUMER_PID;
import static org.eclipse.edc.protocol.dsp.spi.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_PROCESS_ID;
import static org.eclipse.edc.protocol.dsp.spi.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_PROVIDER_PID;
import static org.eclipse.edc.protocol.dsp.spi.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_STATE;

Expand All @@ -38,14 +37,9 @@ public JsonObjectToContractNegotiationAckTransformer() {
@Override
public @Nullable ContractNegotiationAck transform(@NotNull JsonObject jsonObject, @NotNull TransformerContext context) {
var builder = ContractNegotiationAck.Builder.newInstance();
var processId = transformString(jsonObject.get(DSPACE_PROPERTY_PROCESS_ID), context);
if (!transformMandatoryString(jsonObject.get(DSPACE_PROPERTY_CONSUMER_PID), builder::consumerPid, context)) {
builder.consumerPid(processId);
}

if (!transformMandatoryString(jsonObject.get(DSPACE_PROPERTY_PROVIDER_PID), builder::providerPid, context)) {
builder.providerPid(processId);
}

transformMandatoryString(jsonObject.get(DSPACE_PROPERTY_CONSUMER_PID), builder::consumerPid, context);
transformMandatoryString(jsonObject.get(DSPACE_PROPERTY_PROVIDER_PID), builder::providerPid, context);

return builder
.state(transformString(jsonObject.get(DSPACE_PROPERTY_STATE), context))
Expand Down
Loading

0 comments on commit 0fcb727

Please sign in to comment.