Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DT-622: Add UC10 Decline entire booking #8

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ on:
push:
branches:
- dev
- test
- master
pull_request:
branches: [ "dev" ]
branches:
- dev
- test
- master

jobs:
build:
Expand Down
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 @@ -32,9 +33,11 @@ public static BookingScenarioListBuilder buildTree(
uc5_carrier_confirmBookingRequest()
.then(
shipper_GetBooking(CONFIRMED)
.then(
.thenEither(
uc11_carrier_confirmBookingCompleted()
.then(shipper_GetBooking(COMPLETED)))),
.then(shipper_GetBooking(COMPLETED)),
uc10_carrier_declineBooking()
.then(shipper_GetBooking(DECLINED)))),
uc4_carrier_rejectBookingRequest()
.then(shipper_GetBooking(REJECTED)),
uc2_carrier_requestUpdateToBookingRequest()
Expand Down Expand Up @@ -168,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 @@ -235,21 +223,11 @@ private static BookingScenarioListBuilder uc9_shipper_cancelBookingAmendment() {
}

private static BookingScenarioListBuilder uc10_carrier_declineBooking() {
return tbdCarrierAction();
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 @@ -291,4 +269,13 @@ public String getHumanReadablePrompt() {
}
}) {};
}

private interface CarrierNotificationUseCase {
BookingAction newInstance(
String carrierPartyName,
String shipperPartyName,
BookingAction previousAction,
JsonSchemaValidator requestSchemaValidator
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.dcsa.conformance.standards.booking.action;

import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Getter;
import org.dcsa.conformance.core.check.*;
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.booking.party.BookingRole;

import java.util.stream.Stream;

@Getter
public class UC10_Carrier_RejectBookingAction extends BookingAction {
private final JsonSchemaValidator requestSchemaValidator;

public UC10_Carrier_RejectBookingAction(
String carrierPartyName,
String shipperPartyName,
BookingAction previousAction,
JsonSchemaValidator requestSchemaValidator) {
super(carrierPartyName, shipperPartyName, previousAction, "UC10", 204);
this.requestSchemaValidator = requestSchemaValidator;
}

@Override
public String getHumanReadablePrompt() {
return ("UC10: Reject the booking request with CBR %s"
.formatted(getDspSupplier().get().carrierBookingReference()));
}

@Override
public ObjectNode asJsonNode() {
ObjectNode jsonNode = super.asJsonNode();
var dsp = getDspSupplier().get();
return jsonNode.put("cbr", dsp.carrierBookingReference())
.put("cbrr", dsp.carrierBookingRequestReference() );
}

@Override
public ConformanceCheck createCheck(String expectedApiVersion) {
return new ConformanceCheck(getActionTitle()) {
@Override
protected Stream<? extends ConformanceCheck> createSubChecks() {
return Stream.of(
new UrlPathCheck(
BookingRole::isCarrier, getMatchedExchangeUuid(), "/v2/booking-notifications"),
new ResponseStatusCheck(
BookingRole::isShipper, getMatchedExchangeUuid(), expectedStatus),
new ApiHeaderCheck(
BookingRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
expectedApiVersion),
new ApiHeaderCheck(
BookingRole::isShipper,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
expectedApiVersion),
new JsonSchemaCheck(
BookingRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
requestSchemaValidator));
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.fasterxml.jackson.databind.node.ValueNode;
import org.dcsa.conformance.core.check.ActionCheck;
import org.dcsa.conformance.core.check.ConformanceCheck;
import org.dcsa.conformance.core.traffic.ConformanceExchange;
Expand All @@ -25,7 +24,8 @@ public class CarrierGetBookingPayloadResponseConformanceCheck extends ActionChec

private static final Set<BookingState> CONFIRMED_BOOKING_STATES = Set.of(
BookingState.CONFIRMED,
BookingState.COMPLETED
BookingState.COMPLETED,
BookingState.DECLINED
);

private static final Set<String> MANDATORY_ON_CONFIRMED_BOOKING = Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ protected Map<Class<? extends ConformanceAction>, Consumer<JsonNode>> getActionP
Map.entry(UC2_Carrier_RequestUpdateToBookingRequestAction.class, this::requestUpdateToBookingRequest),
Map.entry(UC4_Carrier_RejectBookingRequestAction.class, this::rejectBookingRequest),
Map.entry(UC5_Carrier_ConfirmBookingRequestAction.class, this::confirmBookingRequest),
Map.entry(UC10_Carrier_RejectBookingAction.class, this::declineBooking),
Map.entry(UC11_Carrier_ConfirmBookingCompletedAction.class, this::confirmBookingCompleted));
}

Expand Down Expand Up @@ -157,6 +158,23 @@ private void rejectBookingRequest(JsonNode actionPrompt) {
addOperatorLogEntry("Rejected the booking request with CBRR '%s'".formatted(cbrr));
}

private void declineBooking(JsonNode actionPrompt) {
log.info("Carrier.declineBooking(%s)".formatted(actionPrompt.toPrettyString()));

String cbr = actionPrompt.get("cbr").asText();

processAndEmitNotificationForStateTransition(
actionPrompt,
BookingState.DECLINED,
Set.of(
BookingState.CONFIRMED,
BookingState.PENDING_AMENDMENT,
BookingState.PENDING_AMENDMENT_APPROVAL),
ReferenceState.PROVIDE_IF_EXIST,
false);
addOperatorLogEntry("Declined the booking with CBR '%s'".formatted(cbr));
}

private void requestUpdateToBookingRequest(JsonNode actionPrompt) {
log.info("Carrier.rejectBookingRequest(%s)".formatted(actionPrompt.toPrettyString()));

Expand Down Expand Up @@ -204,6 +222,7 @@ private void processAndEmitNotificationForStateTransition(
null
);
}

private void processAndEmitNotificationForStateTransition(
JsonNode actionPrompt,
BookingState targetState,
Expand Down
Loading