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 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 @@ -9,6 +9,7 @@
import org.dcsa.conformance.core.scenario.ScenarioListBuilder;
import org.dcsa.conformance.standards.booking.action.*;
import org.dcsa.conformance.standards.booking.party.BookingState;
import org.dcsa.conformance.standards.booking.party.BookingVariant;

@Slf4j
public class BookingScenarioListBuilder extends ScenarioListBuilder<BookingScenarioListBuilder> {
Expand All @@ -17,7 +18,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 @@ -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(BookingVariant.REEFER).then(
shipper_GetBooking(RECEIVED)
.then(
uc5_carrier_confirmBookingRequest()
.then(
shipper_GetBooking(CONFIRMED)
.then(
uc11_carrier_confirmBookingCompleted()
.then(shipper_GetBooking(COMPLETED)))))),
uc1_shipper_SubmitBookingRequest(BookingVariant.REGULAR)
.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(BookingVariant.REGULAR).thenAllPathsFrom(RECEIVED),
uc1_shipper_SubmitBookingRequest(BookingVariant.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(BookingVariant.REGULAR).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(BookingVariant variant) {
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),
variant));
}



private static BookingScenarioListBuilder carrierStateChange(
CarrierNotificationUseCase constructor) {
BookingComponentFactory componentFactory = threadLocalComponentFactory.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
package org.dcsa.conformance.standards.booking.action;

import org.dcsa.conformance.core.traffic.ConformanceExchange;
import org.dcsa.conformance.standards.booking.party.BookingVariant;

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

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

public StateChangingBookingAction(String sourcePartyName, String targetPartyName, BookingAction previousAction,
String actionTitle, int expectedStatus, BookingVariant 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 @@ -11,6 +13,7 @@
import org.dcsa.conformance.standards.booking.checks.ShipperBookingContentConformanceCheck;
import org.dcsa.conformance.standards.booking.party.BookingRole;
import org.dcsa.conformance.standards.booking.party.BookingState;
import org.dcsa.conformance.standards.booking.party.BookingVariant;

@Getter
@Slf4j
Expand All @@ -25,22 +28,24 @@ public UC1_Shipper_SubmitBookingRequestAction(
BookingAction previousAction,
JsonSchemaValidator requestSchemaValidator,
JsonSchemaValidator responseSchemaValidator,
JsonSchemaValidator notificationSchemaValidator) {
super(shipperPartyName, carrierPartyName, previousAction, "UC1", 201);
JsonSchemaValidator notificationSchemaValidator,
BookingVariant bookingVariant) {
super(shipperPartyName, carrierPartyName, previousAction, "UC1(%s)".formatted( bookingVariant.getValue()), 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.getValue()));
}

@Override
public ObjectNode asJsonNode() {
ObjectNode jsonNode = super.asJsonNode();
jsonNode.set("csp", getCspSupplier().get().toJson());
jsonNode.set("bookingVariant", new TextNode(bookingVariant.getValue()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use jsonNode.put in this case rather than manually constructing a text node.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

jsonNode.put("csp", getCspSupplier().get().toJson()); is deprecated. hence used .set for csp and bookingVariant. If you would like I will change it .

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was not challenging the use set for the csp. I was challenging the use of set for a regular string for which .put is a much better (and not deprecated) option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.. I will change it.. done !

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
@@ -0,0 +1,17 @@
package org.dcsa.conformance.standards.booking.party;

import lombok.Getter;

@Getter
public enum BookingVariant {
REGULAR("Regular"),
REEFER("Reefer"),
DG("Dangerous Goods");

private final String value;

BookingVariant(String value) {
this.value = value;
}

}
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