Skip to content

Commit

Permalink
Merge pull request #91 from dcsaorg/DT-798
Browse files Browse the repository at this point in the history
DT-798 added minimum shipper request fields
  • Loading branch information
preetamnpr authored May 22, 2024
2 parents b003159 + b2d3dc1 commit 352f466
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.JsonPointer;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.NonNull;
import lombok.experimental.UtilityClass;
import org.dcsa.conformance.core.check.*;
import org.dcsa.conformance.core.traffic.HttpMessageType;
Expand Down Expand Up @@ -306,31 +307,17 @@ private static Consumer<MultiAttributeValidator> allDg(Consumer<MultiAttributeVa
"Validate shipmentLocations",
body -> {
var issues = new LinkedHashSet<String>();
var shipmentLocations = body.path("shipmentLocations");
var receiptTypeAtOrigin = body.path("receiptTypeAtOrigin").asText("");
var polNode =
StreamSupport.stream(shipmentLocations.spliterator(), false)
.filter(o -> o.path("locationTypeCode").asText("").equals("POL")
|| o.path("locationTypeCode").asText("").equals("PRE") )
.findFirst()
.orElse(null);
var podNode =
StreamSupport.stream(shipmentLocations.spliterator(), false)
.filter(o -> o.path("locationTypeCode").asText("").equals("POD")
|| o.path("locationTypeCode").asText("").equals("PDE") )
.findFirst()
.orElse(null);

var ielNode =
StreamSupport.stream(shipmentLocations.spliterator(), false)
.filter(o -> o.path("locationTypeCode").asText("").equals("IEL"))
.findFirst()
.orElse(null);

if (podNode == null || podNode.isEmpty() ) {
var polNode = getShipmenLocationTypeCode(body,"POL");
var preNode = getShipmenLocationTypeCode(body,"PRE");
var pdeNode = getShipmenLocationTypeCode(body,"PDE");
var podNode = getShipmenLocationTypeCode(body,"POD");
var ielNode = getShipmenLocationTypeCode(body,"IEL");

if ((pdeNode == null || pdeNode.isEmpty()) && (podNode == null || podNode.isEmpty()) ) {
issues.add("Port of Discharge/Place of Delivery value must be provided");
}
if (polNode == null || polNode.isEmpty()) {
if ((preNode == null || preNode.isEmpty()) && (polNode == null || polNode.isEmpty())) {
issues.add("Port of Load/Place of Receipt values must be provided");
}
if(!"SD".equals(receiptTypeAtOrigin) && ielNode != null) {
Expand All @@ -339,6 +326,47 @@ private static Consumer<MultiAttributeValidator> allDg(Consumer<MultiAttributeVa
return issues;
});

private static final JsonContentCheck VALIDATE_SHIPPER_MINIMUM_REQUEST_FIELDS = JsonAttribute.customValidator(
"Validate shipper's minimum request fields",
body -> {
var issues = new LinkedHashSet<String>();
var vesselName = body.path("vessel").path("name").asText("");
var carrierExportVoyageNumber = body.path("carrierExportVoyageNumber").asText("");
var carrierServiceCode = body.path("carrierServiceCode").asText("");
var carrierServiceName = body.path("carrierServiceName").asText("");
var expectedDepartureDate = body.path("expectedDepartureDate").asText("");

var polNode = getShipmenLocationTypeCode(body,"POL");
var preNode = getShipmenLocationTypeCode(body,"PRE");
var pdeNode = getShipmenLocationTypeCode(body,"PDE");
var podNode = getShipmenLocationTypeCode(body,"POD");

String providedArrivalStartDate = body.path("expectedArrivalAtPlaceOfDeliveryStartDate").asText("");
String providedArrivalEndDate = body.path("expectedArrivalAtPlaceOfDeliveryEndDate").asText("");

var isPodAbsent = (pdeNode == null || pdeNode.isEmpty()) && (podNode == null || podNode.isEmpty());
var isPolAbsent = (preNode == null || preNode.isEmpty()) && (polNode == null || polNode.isEmpty());

var poldServiceCodeAbsent = (isPolAbsent && isPodAbsent && vesselName.isEmpty() && carrierExportVoyageNumber.isEmpty())
|| (isPolAbsent && isPodAbsent && carrierServiceCode.isEmpty() && carrierExportVoyageNumber.isEmpty())
|| (isPolAbsent && isPodAbsent && carrierServiceName.isEmpty() && carrierExportVoyageNumber.isEmpty());

var poldExpectedDepartureDateAbsent = isPolAbsent && isPodAbsent && expectedDepartureDate.isEmpty() ;

var poldArrivalStartEndDateAbsent = isPolAbsent && isPodAbsent && providedArrivalStartDate.isEmpty() && providedArrivalEndDate.isEmpty();

if ( poldServiceCodeAbsent || poldExpectedDepartureDateAbsent || poldArrivalStartEndDateAbsent ) {
issues.add("The minimum options to provide shipper's requested fields are missing.");
}
return issues;
});
private static JsonNode getShipmenLocationTypeCode(JsonNode body, @NonNull String locationTypeCode) {
var shipmentLocations = body.path("shipmentLocations");
return StreamSupport.stream(shipmentLocations.spliterator(), false)
.filter(o -> o.path("locationTypeCode").asText("").equals(locationTypeCode))
.findFirst()
.orElse(null);
}

private static final JsonContentCheck REQUESTED_CHANGES_PRESENCE = JsonAttribute.customValidator(
"Requested changes must be present for the selected Booking Status ",
Expand Down Expand Up @@ -546,6 +574,7 @@ private static void generateScenarioRelatedChecks(List<JsonContentCheck> checks,
VALIDATE_SHIPMENT_CUTOFF_TIME_CODE,
VALIDATE_ALLOWED_SHIPMENT_CUTOFF_CODE,
COUNTRY_CODE_VALIDATIONS,
VALIDATE_SHIPPER_MINIMUM_REQUEST_FIELDS,
JsonAttribute.atLeastOneOf(
JsonPointer.compile("/expectedDepartureDate"),
JsonPointer.compile("/expectedArrivalAtPlaceOfDeliveryStartDate"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"isImportLicenseRequired": true,
"communicationChannelCode": "AO",
"isEquipmentSubstitutionAllowed": true,
"carrierServiceCode": "TA1",
"vessel": {
"name": "King of the Seas"
},
"requestedEquipments": [
{
"ISOEquipmentCode": "22GP",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"isImportLicenseRequired": false,
"communicationChannelCode": "AO",
"isEquipmentSubstitutionAllowed": true,
"carrierServiceCode": "TA1",
"vessel": {
"name": "King of the Seas"
},
"requestedEquipments": [
{
"ISOEquipmentCode": "42R0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"isImportLicenseRequired": true,
"communicationChannelCode": "AO",
"isEquipmentSubstitutionAllowed": true,
"vessel": {
"name": "King of the Seas"
},
"requestedEquipments": [
{
"ISOEquipmentCode": "42R0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"isImportLicenseRequired": true,
"communicationChannelCode": "AO",
"isEquipmentSubstitutionAllowed": true,
"carrierServiceCode": "TA1",
"vessel": {
"name": "King of the Seas"
},
"requestedEquipments": [
{
"ISOEquipmentCode": "22GP",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"isImportLicenseRequired": true,
"communicationChannelCode": "AO",
"isEquipmentSubstitutionAllowed": true,
"carrierServiceCode": "TA1",
"vessel": {
"name": "King of the Seas"
},
"requestedEquipments": [
{
"ISOEquipmentCode": "22GP",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"isImportLicenseRequired": true,
"communicationChannelCode": "AO",
"isEquipmentSubstitutionAllowed": true,
"carrierServiceCode": "TA1",
"vessel": {
"name": "King of the Seas"
},
"requestedEquipments": [
{
"ISOEquipmentCode": "22GP",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"isImportLicenseRequired": false,
"communicationChannelCode": "AO",
"isEquipmentSubstitutionAllowed": true,
"carrierServiceCode": "TA1",
"vessel": {
"name": "King of the Seas"
},
"requestedEquipments": [
{
"ISOEquipmentCode": "22GP",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"isImportLicenseRequired": false,
"communicationChannelCode": "AO",
"isEquipmentSubstitutionAllowed": true,
"carrierServiceCode": "TA1",
"vessel": {
"name": "King of the Seas"
},
"requestedEquipments": [
{
"ISOEquipmentCode": "42R0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"isImportLicenseRequired": false,
"communicationChannelCode": "AO",
"isEquipmentSubstitutionAllowed": true,
"carrierServiceCode": "TA1",
"vessel": {
"name": "King of the Seas"
},
"requestedEquipments": [
{
"ISOEquipmentCode": "45G1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"isImportLicenseRequired": true,
"communicationChannelCode": "AO",
"isEquipmentSubstitutionAllowed": true,
"carrierServiceCode": "TA1",
"vessel": {
"name": "King of the Seas"
},
"requestedEquipments": [
{
"ISOEquipmentCode": "22GP",
Expand Down

0 comments on commit 352f466

Please sign in to comment.