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-718 changes for reefer #30

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -17,7 +17,6 @@ public class BookingScenarioListBuilder extends ScenarioListBuilder<BookingScena
new ThreadLocal<>();
private static final ThreadLocal<String> threadLocalCarrierPartyName = new ThreadLocal<>();
private static final ThreadLocal<String> threadLocalShipperPartyName = new ThreadLocal<>();

private static final String BOOKING_API = "api";
private static final String BOOKING_NOTIFICATIONS_API = "notification";
private static final String POST_SCHEMA_NAME = "postBooking";
Expand All @@ -26,6 +25,7 @@ public class BookingScenarioListBuilder extends ScenarioListBuilder<BookingScena
private static final String BOOKING_REF_STATUS_SCHEMA = "bookingRefStatus";
private static final String CANCEL_SCHEMA_NAME = "bookings_bookingReference_body";
private static final String BOOKING_NOTIFICATION_SCHEMA_NAME = "BookingNotification";
private static final String BOOKING_WITH_REEFER = "reefer";

public static BookingScenarioListBuilder buildTree(
BookingComponentFactory componentFactory, String carrierPartyName, String shipperPartyName) {
Expand All @@ -35,8 +35,17 @@ public static BookingScenarioListBuilder buildTree(
if (System.currentTimeMillis() > 0) { // FIXME remove this
// This is what's been implemented so far and should still work on PR.
return carrier_SupplyScenarioParameters()
.then(
uc1_shipper_SubmitBookingRequest()
.thenEither(
uc1_shipper_SubmitBookingRequest(BOOKING_WITH_REEFER).then(
shipper_GetBooking(RECEIVED)
.then(
uc5_carrier_confirmBookingRequest()
.then(
shipper_GetBooking(CONFIRMED)
.then(
uc11_carrier_confirmBookingCompleted()
.then(shipper_GetBooking(COMPLETED)))))),
uc1_shipper_SubmitBookingRequest(null)
.then(
shipper_GetBooking(RECEIVED)
.thenEither(
Expand Down Expand Up @@ -149,7 +158,9 @@ private BookingScenarioListBuilder thenAllPathsFrom(
uc4_carrier_rejectBookingRequest().thenAllPathsFrom(REJECTED),
uc5_carrier_confirmBookingRequest().thenAllPathsFrom(CONFIRMED),
uc12_shipper_cancelBooking().thenAllPathsFrom(CANCELLED)));
case START -> then(uc1_shipper_SubmitBookingRequest().thenAllPathsFrom(RECEIVED));
case START -> thenEither(
uc1_shipper_SubmitBookingRequest(null).thenAllPathsFrom(RECEIVED),
uc1_shipper_SubmitBookingRequest(BOOKING_WITH_REEFER).thenHappyPathFrom(RECEIVED));
case PENDING_AMENDMENT -> then(
shipper_GetBooking(bookingState)
.thenEither(
Expand Down Expand Up @@ -182,7 +193,7 @@ private BookingScenarioListBuilder thenHappyPathFrom(BookingState bookingState)
uc3_shipper_submitUpdatedBookingRequest().thenHappyPathFrom(PENDING_UPDATE_CONFIRMATION));
case PENDING_UPDATE_CONFIRMATION, RECEIVED -> then(
uc5_carrier_confirmBookingRequest().thenHappyPathFrom(CONFIRMED));
case START -> then(uc1_shipper_SubmitBookingRequest().thenHappyPathFrom(RECEIVED));
case START -> then(uc1_shipper_SubmitBookingRequest(null).thenHappyPathFrom(RECEIVED));
};
}

Expand Down Expand Up @@ -237,22 +248,25 @@ private static BookingScenarioListBuilder shipper_GetAmendedBooking404() {
(BookingAction) previousAction));
}

private static BookingScenarioListBuilder uc1_shipper_SubmitBookingRequest() {
private static BookingScenarioListBuilder uc1_shipper_SubmitBookingRequest(String bookingVariant) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you prefer a single value instead of a mix of two booleans (isReeferBooking and isDGBooking), then judging by the way you use this value perhaps an enum BookingVariang { REGULAR, REEFER, DG } would help?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather use the Enums than the Booleans

BookingComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new BookingScenarioListBuilder(
previousAction ->
new UC1_Shipper_SubmitBookingRequestAction(
carrierPartyName,
shipperPartyName,
(BookingAction) previousAction,
componentFactory.getMessageSchemaValidator(BOOKING_API, POST_SCHEMA_NAME),
componentFactory.getMessageSchemaValidator(BOOKING_API, BOOKING_REF_STATUS_SCHEMA),
componentFactory.getMessageSchemaValidator(
BOOKING_NOTIFICATIONS_API, BOOKING_NOTIFICATION_SCHEMA_NAME)));
previousAction ->
new UC1_Shipper_SubmitBookingRequestAction(
carrierPartyName,
shipperPartyName,
(BookingAction) previousAction,
componentFactory.getMessageSchemaValidator(BOOKING_API, POST_SCHEMA_NAME),
componentFactory.getMessageSchemaValidator(BOOKING_API, BOOKING_REF_STATUS_SCHEMA),
componentFactory.getMessageSchemaValidator(
BOOKING_NOTIFICATIONS_API, BOOKING_NOTIFICATION_SCHEMA_NAME),
bookingVariant));
}



private static BookingScenarioListBuilder carrierStateChange(
CarrierNotificationUseCase constructor) {
BookingComponentFactory componentFactory = threadLocalComponentFactory.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
import org.dcsa.conformance.core.traffic.ConformanceExchange;

public abstract class StateChangingBookingAction extends BookingAction {
public StateChangingBookingAction(String sourcePartyName, String targetPartyName, BookingAction previousAction, String actionTitle, int expectedStatus) {

protected final String bookingVariant;
public StateChangingBookingAction(String sourcePartyName, String targetPartyName, BookingAction previousAction,
String actionTitle, int expectedStatus) {
super(sourcePartyName, targetPartyName, previousAction, actionTitle, expectedStatus);
bookingVariant = null;
}

public StateChangingBookingAction(String sourcePartyName, String targetPartyName, BookingAction previousAction,
String actionTitle, int expectedStatus, String bookingVariant) {
super(sourcePartyName, targetPartyName, previousAction, actionTitle, expectedStatus);
this.bookingVariant = bookingVariant;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.stream.Stream;

import com.fasterxml.jackson.databind.node.TextNode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.dcsa.conformance.core.check.*;
Expand All @@ -25,22 +27,24 @@ public UC1_Shipper_SubmitBookingRequestAction(
BookingAction previousAction,
JsonSchemaValidator requestSchemaValidator,
JsonSchemaValidator responseSchemaValidator,
JsonSchemaValidator notificationSchemaValidator) {
super(shipperPartyName, carrierPartyName, previousAction, "UC1", 201);
JsonSchemaValidator notificationSchemaValidator,
String bookingVariant) {
super(shipperPartyName, carrierPartyName, previousAction, "UC1(%s)".formatted( bookingVariant!= null? bookingVariant : "normal"), 201,bookingVariant);
this.requestSchemaValidator = requestSchemaValidator;
this.responseSchemaValidator = responseSchemaValidator;
this.notificationSchemaValidator = notificationSchemaValidator;
}

@Override
public String getHumanReadablePrompt() {
return ("UC1: Submit a booking request using the following parameters:");
return ("UC1: Submit a booking %s request using the following parameters:".formatted( bookingVariant != null? bookingVariant : "normal"));
}

@Override
public ObjectNode asJsonNode() {
ObjectNode jsonNode = super.asJsonNode();
jsonNode.set("csp", getCspSupplier().get().toJson());
jsonNode.set("bookingVariant", new TextNode(bookingVariant));
return jsonNode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ protected Set<String> reeferChecks(JsonNode payload) {
"the ISOEquipmentCode implies that the container is a reefer container"
);
if (node != null && node.isBoolean()) {
var isNOR = node.asBoolean();
if (isNOR) {
var isNOR = node.booleanValue();
if (!isNOR) {
nt-gt marked this conversation as resolved.
Show resolved Hide resolved
fieldRequired(
requestedEquipment,
ACTIVE_REEFER_SETTINGS_FIELD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ 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 FILE_SUFFIX_REEFER = "-reefer";
public Shipper(
String apiVersion,
PartyConfiguration partyConfiguration,
Expand Down Expand Up @@ -85,7 +86,6 @@ private void sendBookingRequest(JsonNode actionPrompt) {
CarrierScenarioParameters carrierScenarioParameters =
CarrierScenarioParameters.fromJson(actionPrompt.get("csp"));


JsonNode jsonRequestBody = replaceBookingPlaceHolders(actionPrompt);

asyncCounterpartPost(
Expand All @@ -111,10 +111,11 @@ private JsonNode replaceBookingPlaceHolders(JsonNode actionPrompt) {

CarrierScenarioParameters carrierScenarioParameters =
CarrierScenarioParameters.fromJson(actionPrompt.get("csp"));
String bookingVariant = actionPrompt.get("bookingVariant").asText();

JsonNode jsonRequestBody =
JsonToolkit.templateFileToJsonNode(
"/standards/booking/messages/booking-api-v20-request.json",
String fileSuffix = bookingVariant.equals("reefer") ? FILE_SUFFIX_REEFER: "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably put this logic into the enum as each case has its own payload in the booking case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For simplicity, you could rename the regular one so they all have suffixes and use bookingVariant.toLower() to determine the suffix (probably how I would have done it) but other approaches work too (where the enum has a field for this purpose, etc.)

return JsonToolkit.templateFileToJsonNode(
"/standards/booking/messages/booking-api-v20%s-request.json".formatted(fileSuffix),
Map.ofEntries(
Map.entry(
"CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
Expand All @@ -131,8 +132,6 @@ private JsonNode replaceBookingPlaceHolders(JsonNode actionPrompt) {
"POL_UNLOCATION_CODE_PLACEHOLDER", carrierScenarioParameters.polUNLocationCode()),
Map.entry(
"POD_UNLOCATION_CODE_PLACEHOLDER", carrierScenarioParameters.podUNLocationCode()) ));

return jsonRequestBody;
}

private void sendCancelEntireBooking(JsonNode actionPrompt) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"receiptTypeAtOrigin": "CY",
"deliveryTypeAtDestination": "CY",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
"isPartialLoadAllowed": false,
"isExportDeclarationRequired": false,
"isImportLicenseRequired": false,
"communicationChannelCode": "AO",
"isEquipmentSubstitutionAllowed": true,
"requestedEquipments": [
{
"ISOEquipmentCode": "22RT",
"units": 1,
"isShipperOwned": false,
"commodities": [
{
"HSCodes": ["COMMODITY_HS_CODE"],
"commodityType": "COMMODITY_TYPE_PLACEHOLDER",
"cargoGrossWeight": 323.32,
"cargoGrossWeightUnit": "KGM"
}
],
"isNonOperatingReefer": false,
"activeReeferSettings": {
"temperatureSetpoint": -18,
"temperatureUnit": "CEL"
}
}
],
"documentParties": [
{
"party": {
"partyName": "DCSA Conformance Toolkit",
"address": {
"name": "Mustermann",
"street": "Strawinskylaan",
"streetNumber": "4117",
"floor": "6",
"postCode": "1077 ZX",
"city": "Amsterdam",
"country": "Netherlands"
},
"partyContactDetails": [
{
"name": "Henrik",
"phone": "+31611444666"
}
]
},
"partyFunction": "BA",
"isToBeNotified": false
}
],
"shipmentLocations": [
{
"location": {
"locationType": "UNLO",
"UNLocationCode": "POL_UNLOCATION_CODE_PLACEHOLDER"
},
"locationTypeCode": "POL"
},
{
"location": {
"locationType": "UNLO",
"UNLocationCode": "POD_UNLOCATION_CODE_PLACEHOLDER"
},
"locationTypeCode": "POD"
}
]
}
Loading