Skip to content

Commit

Permalink
refactor: adapt CN states names to the DSP specification
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt committed Apr 4, 2023
1 parent c1bb923 commit e63fad7
Show file tree
Hide file tree
Showing 41 changed files with 517 additions and 541 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation;
import org.eclipse.edc.spi.event.EventEnvelope;
import org.eclipse.edc.spi.event.EventRouter;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationConsumerAgreed;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationConsumerRequested;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationConsumerVerified;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationAccepted;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationAgreed;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationDeclined;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationEvent;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationFailed;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationFinalized;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationInitiated;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationProviderAgreed;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationProviderFinalized;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationProviderOffered;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationOffered;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationRequested;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationTerminated;
import org.eclipse.edc.spi.event.contractnegotiation.ContractNegotiationVerified;

import java.time.Clock;

Expand All @@ -51,26 +51,26 @@ public void initiated(ContractNegotiation negotiation) {
}

@Override
public void consumerRequested(ContractNegotiation negotiation) {
var event = ContractNegotiationConsumerRequested.Builder.newInstance()
public void requested(ContractNegotiation negotiation) {
var event = ContractNegotiationRequested.Builder.newInstance()
.contractNegotiationId(negotiation.getId())
.build();

publish(event);
}

@Override
public void providerOffered(ContractNegotiation negotiation) {
var event = ContractNegotiationProviderOffered.Builder.newInstance()
public void offered(ContractNegotiation negotiation) {
var event = ContractNegotiationOffered.Builder.newInstance()
.contractNegotiationId(negotiation.getId())
.build();

publish(event);
}

@Override
public void consumerAgreed(ContractNegotiation negotiation) {
var event = ContractNegotiationConsumerAgreed.Builder.newInstance()
public void accepted(ContractNegotiation negotiation) {
var event = ContractNegotiationAccepted.Builder.newInstance()
.contractNegotiationId(negotiation.getId())
.build();

Expand All @@ -96,26 +96,26 @@ public void declined(ContractNegotiation negotiation) {
}

@Override
public void providerAgreed(ContractNegotiation negotiation) {
var event = ContractNegotiationProviderAgreed.Builder.newInstance()
public void agreed(ContractNegotiation negotiation) {
var event = ContractNegotiationAgreed.Builder.newInstance()
.contractNegotiationId(negotiation.getId())
.build();

publish(event);
}

@Override
public void consumerVerified(ContractNegotiation negotiation) {
var event = ContractNegotiationConsumerVerified.Builder.newInstance()
public void verified(ContractNegotiation negotiation) {
var event = ContractNegotiationVerified.Builder.newInstance()
.contractNegotiationId(negotiation.getId())
.build();

publish(event);
}

@Override
public void providerFinalized(ContractNegotiation negotiation) {
var event = ContractNegotiationProviderFinalized.Builder.newInstance()
public void finalized(ContractNegotiation negotiation) {
var event = ContractNegotiationFinalized.Builder.newInstance()
.contractNegotiationId(negotiation.getId())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,84 +62,77 @@ public abstract class AbstractContractNegotiationManager {
protected EntityRetryProcessFactory entityRetryProcessFactory;
protected EntityRetryProcessConfiguration entityRetryProcessConfiguration = defaultEntityRetryProcessConfiguration();

/**
* Gives the type of the manager
*
* @return "Provider" for provider, "Consumer" for consumer
*/
protected abstract String getType();

protected void transitionToInitial(ContractNegotiation negotiation) {
negotiation.transitionInitial();
update(negotiation);
observable.invokeForEach(l -> l.initiated(negotiation));
}

protected void transitionToConsumerRequesting(ContractNegotiation negotiation) {
negotiation.transitionConsumerRequesting();
protected void transitionToRequesting(ContractNegotiation negotiation) {
negotiation.transitionRequesting();
update(negotiation);
}

protected void transitionToConsumerRequested(ContractNegotiation negotiation) {
negotiation.transitionConsumerRequested();
protected void transitionToRequested(ContractNegotiation negotiation) {
negotiation.transitionRequested();
update(negotiation);
observable.invokeForEach(l -> l.consumerRequested(negotiation));
observable.invokeForEach(l -> l.requested(negotiation));
}

protected void transitionToConsumerAgreeing(ContractNegotiation negotiation) {
negotiation.transitionConsumerAgreeing();
protected void transitionToAccepting(ContractNegotiation negotiation) {
negotiation.transitionAccepting();
update(negotiation);
}

protected void transitionToConsumerAgreed(ContractNegotiation negotiation) {
negotiation.transitionConsumerAgreed();
protected void transitionToAccepted(ContractNegotiation negotiation) {
negotiation.transitionAccepted();
update(negotiation);
observable.invokeForEach(l -> l.consumerAgreed(negotiation));
observable.invokeForEach(l -> l.accepted(negotiation));
}

protected void transitionToProviderOffering(ContractNegotiation negotiation) {
negotiation.transitionProviderOffering();
protected void transitionToOffering(ContractNegotiation negotiation) {
negotiation.transitionOffering();
update(negotiation);
}

protected void transitionToProviderOffered(ContractNegotiation negotiation) {
negotiation.transitionProviderOffered();
protected void transitionToOffered(ContractNegotiation negotiation) {
negotiation.transitionOffered();
update(negotiation);
observable.invokeForEach(l -> l.providerOffered(negotiation));
observable.invokeForEach(l -> l.offered(negotiation));
}

protected void transitionToProviderAgreeing(ContractNegotiation negotiation) {
negotiation.transitionProviderAgreeing();
protected void transitionToAgreeing(ContractNegotiation negotiation) {
negotiation.transitionAgreeing();
update(negotiation);
}

protected void transitionToProviderAgreed(ContractNegotiation negotiation, ContractAgreement agreement) {
protected void transitionToAgreed(ContractNegotiation negotiation, ContractAgreement agreement) {
negotiation.setContractAgreement(agreement);
negotiation.transitionProviderAgreed();
negotiation.transitionAgreed();
update(negotiation);
observable.invokeForEach(l -> l.providerAgreed(negotiation));
observable.invokeForEach(l -> l.agreed(negotiation));
}

protected void transitionToConsumerVerifying(ContractNegotiation negotiation) {
negotiation.transitionConsumerVerifying();
protected void transitionToVerifying(ContractNegotiation negotiation) {
negotiation.transitionVerifying();
update(negotiation);
}

protected void transitionToConsumerVerified(ContractNegotiation negotiation) {
negotiation.transitionConsumerVerified();
protected void transitionToVerified(ContractNegotiation negotiation) {
negotiation.transitionVerified();
update(negotiation);
observable.invokeForEach(l -> l.consumerVerified(negotiation));
observable.invokeForEach(l -> l.verified(negotiation));
}

protected void transitionToProviderFinalizing(ContractNegotiation negotiation) {
negotiation.transitionProviderFinalizing();
protected void transitionToFinalizing(ContractNegotiation negotiation) {
negotiation.transitionFinalizing();
update(negotiation);
}

protected void transitionToProviderFinalized(ContractNegotiation negotiation) {
negotiation.transitionProviderFinalized();
protected void transitionToFinalized(ContractNegotiation negotiation) {
negotiation.transitionFinalized();
update(negotiation);
observable.invokeForEach(l -> l.providerFinalized(negotiation));
observable.invokeForEach(l -> l.finalized(negotiation));
}

protected void transitionToTerminating(ContractNegotiation negotiation, String message) {
Expand All @@ -166,7 +159,7 @@ protected void transitionToTerminated(ContractNegotiation negotiation) {
private void update(ContractNegotiation negotiation) {
negotiationStore.save(negotiation);
monitor.debug(String.format("[%s] ContractNegotiation %s is now in state %s.",
getType(), negotiation.getId(), ContractNegotiationStates.from(negotiation.getState())));
negotiation.getType(), negotiation.getId(), ContractNegotiationStates.from(negotiation.getState())));
}

public static class Builder<T extends AbstractContractNegotiationManager> {
Expand Down
Loading

0 comments on commit e63fad7

Please sign in to comment.