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-713 first set of changes #18

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public static BookingScenarioListBuilder buildTree(
.then(
shipper_GetBooking(CONFIRMED)
.thenEither(
uc5_shipper_repostConfirmedBooking()
.then(
shipper_GetBooking(CONFIRMED)
.then (
uc11_carrier_confirmBookingCompleted()
.then(shipper_GetBooking(COMPLETED)))),
uc11_carrier_confirmBookingCompleted()
.then(shipper_GetBooking(COMPLETED)),
uc6_carrier_requestUpdateToConfirmedBooking()
Expand Down Expand Up @@ -110,6 +116,7 @@ private BookingScenarioListBuilder thenAllPathsFrom(
case CONFIRMED -> then(
shipper_GetBooking(bookingState)
.thenEither(
uc5_shipper_repostConfirmedBooking().thenHappyPathFrom(COMPLETED),
uc6_carrier_requestBookingAmendment().thenAllPathsFrom(PENDING_AMENDMENT),
uc7_shipper_submitBookingAmendment()
.thenAllPathsFrom(AMENDMENT_RECEIVED, CONFIRMED),
Expand Down Expand Up @@ -289,6 +296,20 @@ private static BookingScenarioListBuilder uc5_carrier_confirmBookingRequest() {
return carrierStateChange(UC5_Carrier_ConfirmBookingRequestAction::new);
}

private static BookingScenarioListBuilder uc5_shipper_repostConfirmedBooking() {
BookingComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new BookingScenarioListBuilder(
previousAction ->
new UC5_Shipper_RepostConfirmedBooking(
carrierPartyName,
shipperPartyName,
(BookingAction) previousAction,
componentFactory.getMessageSchemaValidator(BOOKING_API, PUT_SCHEMA_NAME),
componentFactory.getMessageSchemaValidator(BOOKING_API, BOOKING_REF_STATUS_SCHEMA)));
}

private static BookingScenarioListBuilder uc6_carrier_requestUpdateToConfirmedBooking() {
return carrierStateChange(UC6_Carrier_RequestUpdateToConfirmedBookingAction::new);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.dcsa.conformance.standards.booking.action;

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

import java.util.stream.Stream;

@Getter
@Slf4j
public class UC5_Shipper_RepostConfirmedBooking extends StateChangingBookingAction {
private final JsonSchemaValidator requestSchemaValidator;
private final JsonSchemaValidator responseSchemaValidator;

public UC5_Shipper_RepostConfirmedBooking(
String carrierPartyName,
String shipperPartyName,
BookingAction previousAction,
JsonSchemaValidator requestSchemaValidator,
JsonSchemaValidator responseSchemaValidator) {
super(shipperPartyName, carrierPartyName, previousAction, "UC5", 200);
this.requestSchemaValidator = requestSchemaValidator;
this.responseSchemaValidator = responseSchemaValidator;
}


@Override
protected boolean expectsNotificationExchange() {
return true;
}

@Override
public String getHumanReadablePrompt() {
return ("UC5: Repost confirmed booking");
}

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

@Override
public ConformanceCheck createCheck(String expectedApiVersion) {
return new ConformanceCheck(getActionTitle()) {
@Override
protected Stream<? extends ConformanceCheck> createSubChecks() {
var cbrr = getDspSupplier().get().carrierBookingRequestReference();
return
Stream.of(
new HttpMethodCheck(BookingRole::isShipper, getMatchedExchangeUuid(), "PUT"),
new UrlPathCheck(
BookingRole::isShipper,
getMatchedExchangeUuid(),
"/v2/bookings/%s".formatted(cbrr)),
new ResponseStatusCheck(
BookingRole::isCarrier, getMatchedExchangeUuid(), expectedStatus),
new ApiHeaderCheck(
BookingRole::isShipper,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
expectedApiVersion),
new ApiHeaderCheck(
BookingRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
expectedApiVersion),
new JsonSchemaCheck(
BookingRole::isShipper,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
requestSchemaValidator),
new JsonSchemaCheck(
BookingRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator));
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,27 +228,33 @@ private void removeRequestedChanges() {

public void putBooking(String bookingReference, ObjectNode newBookingData) {
var currentState = getBookingState();
boolean isAmendment =
currentState.equals(BookingState.CONFIRMED)
|| currentState.equals(BookingState.PENDING_AMENDMENT);

checkState(
bookingReference,
currentState,
(isAmendment ? MAY_AMEND_STATES : MAY_UPDATE_REQUEST_STATES)::contains
);
if (isAmendment) {
changeState(AMENDED_BOOKING_STATUS, BookingState.AMENDMENT_RECEIVED);
} else {
changeState(BOOKING_STATUS, BookingState.PENDING_UPDATE_CONFIRMATION);
}
copyMetadataFields(getBooking(), newBookingData);
if (isAmendment) {
setAmendedBooking(newBookingData);
} else {
setBooking(newBookingData);
String requestBookingStatus = newBookingData.get("bookingStatus").asText();
boolean sameState = requestBookingStatus.equals(currentState.wireName());
if (sameState) {
setBooking(getBooking());
}else {
boolean isAmendment =
currentState.equals(BookingState.CONFIRMED)
|| currentState.equals(BookingState.PENDING_AMENDMENT);

checkState(
bookingReference,
currentState,
(isAmendment ? MAY_AMEND_STATES : MAY_UPDATE_REQUEST_STATES)::contains
);
if (isAmendment) {
changeState(AMENDED_BOOKING_STATUS, BookingState.AMENDMENT_RECEIVED);
} else {
changeState(BOOKING_STATUS, BookingState.PENDING_UPDATE_CONFIRMATION);
}
copyMetadataFields(getBooking(), newBookingData);
if (isAmendment) {
setAmendedBooking(newBookingData);
} else {
setBooking(newBookingData);
}
removeRequestedChanges();
}
removeRequestedChanges();
}

public BookingState getBookingState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class Shipper extends ConformanceParty {

private static final String SERVICE_CONTRACT_REF = "serviceContractReference";
private static final String SERVICE_REF_PUT = "serviceRefPut";
private static final String BOOKING_STATUS = "bookingStatus";

public Shipper(
String apiVersion,
PartyConfiguration partyConfiguration,
Expand Down Expand Up @@ -61,6 +63,7 @@ protected Map<Class<? extends ConformanceAction>, Consumer<JsonNode>> getActionP
Map.entry(Shipper_GetBookingAction.class, this::getBookingRequest),
Map.entry(Shipper_GetAmendedBooking404Action.class, this::getBookingRequest),
Map.entry(UC3_Shipper_SubmitUpdatedBookingRequestAction.class, this::sendUpdatedBooking),
Map.entry(UC5_Shipper_RepostConfirmedBooking.class, this::sendReConfirmedBooking),
Map.entry(UC7_Shipper_SubmitBookingAmendment.class, this::sendUpdatedConfirmedBooking),
Map.entry(UC9_Shipper_CancelBookingAmendment.class, this::sendCancelBookingAmendment),
Map.entry(UC12_Shipper_CancelEntireBookingAction.class, this::sendCancelEntireBooking));
Expand Down Expand Up @@ -171,6 +174,22 @@ private void sendUpdatedConfirmedBooking(JsonNode actionPrompt) {
}


private void sendReConfirmedBooking(JsonNode actionPrompt) {
log.info("Shipper.sendReConfirmedBooking(%s)".formatted(actionPrompt.toPrettyString()));
String cbrr = actionPrompt.get("cbrr").asText();

var bookingData = persistentMap.load(cbrr);
((ObjectNode) bookingData).put(SERVICE_CONTRACT_REF, SERVICE_REF_PUT)
.put(BOOKING_STATUS,BookingState.CONFIRMED.wireName());

asyncCounterpartPut(
"/v2/bookings/%s".formatted(cbrr),bookingData);

addOperatorLogEntry(
"Sent a reconfirmed booking with the parameters: %s"
.formatted(cbrr));
}

@Override
public ConformanceResponse handleRequest(ConformanceRequest request) {
log.info("Shipper.handleRequest(%s)".formatted(request));
Expand Down
Loading