Skip to content

Commit

Permalink
DT-618: Add UC6 - Request Update to Confirmed Booking
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 22, 2023
1 parent 1cd09dd commit 2059312
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public static BookingScenarioListBuilder buildTree(
.thenEither(
uc11_carrier_confirmBookingCompleted()
.then(shipper_GetBooking(COMPLETED)),
uc6_carrier_requestUpdateToConfirmedBooking()
.then(shipper_GetBooking(PENDING_AMENDMENT)),
uc10_carrier_declineBooking()
.then(shipper_GetBooking(DECLINED)))),
uc4_carrier_rejectBookingRequest()
Expand Down Expand Up @@ -212,6 +214,10 @@ private static BookingScenarioListBuilder uc5_carrier_confirmBookingRequest() {
return carrierStateChange(UC5_Carrier_ConfirmBookingRequestAction::new);
}

private static BookingScenarioListBuilder uc6_carrier_requestUpdateToConfirmedBooking() {
return carrierStateChange(UC6_Carrier_RequestUpdateToConfirmedBookingAction::new);
}

private static BookingScenarioListBuilder uc6_carrier_requestBookingAmendment() {
return tbdCarrierAction();
}
Expand Down
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 UC6_Carrier_RequestUpdateToConfirmedBookingAction extends BookingAction {
private final JsonSchemaValidator requestSchemaValidator;

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

@Override
public String getHumanReadablePrompt() {
return ("UC6: Request update to the confirmed booking 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 @@ -19,7 +19,8 @@ public class CarrierGetBookingPayloadResponseConformanceCheck extends ActionChec


private static final Set<BookingState> PENDING_CHANGES_STATES = Set.of(
BookingState.PENDING_UPDATE
BookingState.PENDING_UPDATE,
BookingState.PENDING_AMENDMENT
);

private static final Set<BookingState> CONFIRMED_BOOKING_STATES = Set.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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(UC6_Carrier_RequestUpdateToConfirmedBookingAction.class, this::requestUpdateToConfirmedBooking),
Map.entry(UC10_Carrier_RejectBookingAction.class, this::declineBooking),
Map.entry(UC11_Carrier_ConfirmBookingCompletedAction.class, this::confirmBookingCompleted));
}
Expand Down Expand Up @@ -323,7 +324,7 @@ private void declineBooking(JsonNode actionPrompt) {
}

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

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

Expand Down Expand Up @@ -354,6 +355,23 @@ private void confirmBookingCompleted(JsonNode actionPrompt) {
addOperatorLogEntry("Completed the booking request with CBR '%s'".formatted(cbr));
}

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

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

processAndEmitNotificationForStateTransition(
actionPrompt,
BookingState.PENDING_AMENDMENT,
Set.of(BookingState.CONFIRMED, BookingState.PENDING_AMENDMENT),
ReferenceState.PROVIDE_IF_EXIST,
true,
booking -> booking.putArray("requestedChanges")
.addObject()
.put("message", "Please perform the changes requested by the Conformance orchestrator"));
addOperatorLogEntry("Requested update to the booking with CBR '%s'".formatted(cbr));
}

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

0 comments on commit 2059312

Please sign in to comment.