Skip to content

Commit

Permalink
BookingScenarioListBuilder: Refactor some code for carrier use cases
Browse files Browse the repository at this point in the history
Signed-off-by: Niels Thykier <[email protected]>
  • Loading branch information
nt-gt committed Nov 17, 2023
1 parent 4a7fc00 commit 8f8da55
Showing 1 changed file with 22 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.function.Function;
import lombok.extern.slf4j.Slf4j;
import org.dcsa.conformance.core.check.JsonSchemaValidator;
import org.dcsa.conformance.core.scenario.ConformanceAction;
import org.dcsa.conformance.core.scenario.ScenarioListBuilder;
import org.dcsa.conformance.standards.booking.action.*;
Expand Down Expand Up @@ -170,50 +171,35 @@ private static BookingScenarioListBuilder uc1_shipper_SubmitBookingRequest() {
BookingRole.SHIPPER.getConfigName(), true)));
}

private static BookingScenarioListBuilder uc2_carrier_requestUpdateToBookingRequest() {
private static BookingScenarioListBuilder carrierStateChange(CarrierNotificationUseCase constructor) {
BookingComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new BookingScenarioListBuilder(
previousAction ->
new UC2_Carrier_RequestUpdateToBookingRequestAction(
constructor.newInstance(
carrierPartyName,
shipperPartyName,
(BookingAction) previousAction,
componentFactory.getMessageSchemaValidator(
BookingRole.CARRIER.getConfigName(), true)));
BookingRole.CARRIER.getConfigName(), true))
);
}

private static BookingScenarioListBuilder uc2_carrier_requestUpdateToBookingRequest() {
return carrierStateChange(UC2_Carrier_RequestUpdateToBookingRequestAction::new);
}

private static BookingScenarioListBuilder uc3_shipper_submitUpdatedBookingRequest() {
return tbdShipperAction();
}

private static BookingScenarioListBuilder uc4_carrier_rejectBookingRequest() {
BookingComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new BookingScenarioListBuilder(
previousAction ->
new UC4_Carrier_RejectBookingRequestAction(
carrierPartyName,
shipperPartyName,
(BookingAction) previousAction,
componentFactory.getMessageSchemaValidator(
BookingRole.CARRIER.getConfigName(), true)));
return carrierStateChange(UC4_Carrier_RejectBookingRequestAction::new);
}

private static BookingScenarioListBuilder uc5_carrier_confirmBookingRequest() {
BookingComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new BookingScenarioListBuilder(
previousAction ->
new UC5_Carrier_ConfirmBookingRequestAction(
carrierPartyName,
shipperPartyName,
(BookingAction) previousAction,
componentFactory.getMessageSchemaValidator(
BookingRole.CARRIER.getConfigName(), true)));
return carrierStateChange(UC5_Carrier_ConfirmBookingRequestAction::new);
}

private static BookingScenarioListBuilder uc6_carrier_requestBookingAmendment() {
Expand All @@ -237,31 +223,11 @@ private static BookingScenarioListBuilder uc9_shipper_cancelBookingAmendment() {
}

private static BookingScenarioListBuilder uc10_carrier_declineBooking() {
BookingComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new BookingScenarioListBuilder(
previousAction ->
new UC10_Carrier_RejectBookingAction(
carrierPartyName,
shipperPartyName,
(BookingAction) previousAction,
componentFactory.getMessageSchemaValidator(
BookingRole.CARRIER.getConfigName(), true)));
return carrierStateChange(UC10_Carrier_RejectBookingAction::new);
}

private static BookingScenarioListBuilder uc11_carrier_confirmBookingCompleted() {
BookingComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new BookingScenarioListBuilder(
previousAction ->
new UC11_Carrier_ConfirmBookingCompletedAction(
carrierPartyName,
shipperPartyName,
(BookingAction) previousAction,
componentFactory.getMessageSchemaValidator(
BookingRole.CARRIER.getConfigName(), true)));
return carrierStateChange(UC11_Carrier_ConfirmBookingCompletedAction::new);
}

private static BookingScenarioListBuilder uc12_shipper_cancelBooking() {
Expand Down Expand Up @@ -303,4 +269,13 @@ public String getHumanReadablePrompt() {
}
}) {};
}

private interface CarrierNotificationUseCase {
BookingAction newInstance(
String carrierPartyName,
String shipperPartyName,
BookingAction previousAction,
JsonSchemaValidator requestSchemaValidator
);
}
}

0 comments on commit 8f8da55

Please sign in to comment.