Skip to content

Commit

Permalink
SD-1895 Add JIT 2.0 GET actions (#266)
Browse files Browse the repository at this point in the history
* Relates to SD-160 which adds JIT 2.0
  • Loading branch information
jkosternl authored Feb 4, 2025
1 parent c32d038 commit c8bd38b
Show file tree
Hide file tree
Showing 18 changed files with 1,114 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void importJsonState(JsonNode jsonState) {

protected abstract void importPartyJsonState(ObjectNode sourceObjectNode);

protected void addOperatorLogEntry(String logEntry) {
public void addOperatorLogEntry(String logEntry) {
operatorLog.addFirst(logEntry);
if (operatorLog.size() > MAX_OPERATOR_LOG_RECORDS - 1) {
operatorLog.removeLast();
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class JitStandard extends AbstractStandard {
public static final String PORT_CALL_SERVICE_ID = "{portCallServiceID}";
public static final String PORT_CALL_ID = "{portCallID}";
public static final String TERMINAL_CALL_ID = "{terminalCallID}";
public static final String TIMESTAMP_ID = "{timestampID}";

private JitStandard() {
super("JIT");
Expand Down Expand Up @@ -54,17 +55,17 @@ public SortedMap<String, SortedSet<String>> getScenarioSuitesByStandardVersion()
createEntry(PORT_CALL_URL, GET),
createEntry(TERMINAL_CALL_URL, GET),
createEntry(PORT_CALL_SERVICES_URL, GET),
createEntry(TIMESTAMP_URL + "${timestampID}", PUT),
createEntry(TIMESTAMP_URL + TIMESTAMP_ID, PUT),
createEntry(TIMESTAMP_URL, GET),
createEntry(VESSEL_STATUS_URL, GET)))),
Map.entry(
JitRole.CONSUMER.getConfigName(),
new TreeMap<>(
Map.ofEntries(
createEntry(PORT_CALL_URL + "{portCallID}", PUT),
createEntry(PORT_CALL_URL + "{portCallID}/omit", POST),
createEntry(TERMINAL_CALL_URL + "{terminalCallId}", PUT),
createEntry(TERMINAL_CALL_URL + "{terminalCallId}/omit", POST),
createEntry(PORT_CALL_URL + PORT_CALL_ID, PUT),
createEntry(PORT_CALL_URL + PORT_CALL_ID + "/omit", POST),
createEntry(TERMINAL_CALL_URL + TERMINAL_CALL_ID, PUT),
createEntry(TERMINAL_CALL_URL + TERMINAL_CALL_ID + "/omit", POST),
createEntry(PORT_CALL_SERVICES_URL + PORT_CALL_SERVICE_ID, PUT),
createEntry(
PORT_CALL_SERVICES_URL + PORT_CALL_SERVICE_ID + "/cancel", POST),
Expand All @@ -73,7 +74,7 @@ public SortedMap<String, SortedSet<String>> getScenarioSuitesByStandardVersion()
createEntry(PORT_CALL_URL, GET),
createEntry(TERMINAL_CALL_URL, GET),
createEntry(PORT_CALL_SERVICES_URL, GET),
createEntry(TIMESTAMP_URL + "${timestampID}", PUT),
createEntry(TIMESTAMP_URL + TIMESTAMP_ID, PUT),
createEntry(TIMESTAMP_URL, GET),
createEntry(VESSEL_STATUS_URL, GET)))))));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package org.dcsa.conformance.standards.jit.action;

import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.List;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import org.dcsa.conformance.core.check.ActionCheck;
import org.dcsa.conformance.core.check.ApiHeaderCheck;
import org.dcsa.conformance.core.check.ConformanceCheck;
import org.dcsa.conformance.core.check.HttpMethodCheck;
import org.dcsa.conformance.core.check.JsonSchemaCheck;
import org.dcsa.conformance.core.check.JsonSchemaValidator;
import org.dcsa.conformance.core.check.ResponseStatusCheck;
import org.dcsa.conformance.core.check.UrlPathCheck;
import org.dcsa.conformance.core.scenario.ConformanceAction;
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.jit.JitScenarioContext;
import org.dcsa.conformance.standards.jit.JitStandard;
import org.dcsa.conformance.standards.jit.checks.JitChecks;
import org.dcsa.conformance.standards.jit.model.JitGetType;
import org.dcsa.conformance.standards.jit.party.JitRole;

@Slf4j
public class JitGetAction extends JitAction {
public static final String GET_TYPE = "getType";
public static final String FILTERS = "filters";

private final JitGetType getType;
private final JsonSchemaValidator validator;
private final boolean requestedByProvider;
private final List<String> urlFilters;

public JitGetAction(
JitScenarioContext context,
ConformanceAction previousAction,
JitGetType getType,
List<String> urlFilters,
boolean requestedByProvider) {
super(
requestedByProvider ? context.providerPartyName() : context.consumerPartyName(),
requestedByProvider ? context.consumerPartyName() : context.providerPartyName(),
previousAction,
requestedByProvider
? "Send GET %s by %s".formatted(getType.getName(), urlFilters)
: "Receive GET %s by %s".formatted(getType.getName(), urlFilters));
this.getType = getType;
this.urlFilters = urlFilters;
this.requestedByProvider = requestedByProvider;
validator = context.componentFactory().getMessageSchemaValidator(getType.getJitSchema());
}

@Override
public ObjectNode asJsonNode() {
ObjectNode jsonNode = super.asJsonNode();
jsonNode.put(GET_TYPE, getType.name());
jsonNode.putPOJO(FILTERS, urlFilters);
return jsonNode;
}

@Override
public String getHumanReadablePrompt() {
return "Get %s (GET) request".formatted(getType);
}

@Override
public ConformanceCheck createCheck(String expectedApiVersion) {
return new ConformanceCheck(getActionTitle()) {
@Override
protected Stream<? extends ConformanceCheck> createSubChecks() {
if (dsp == null) return Stream.of();
ActionCheck checksForTimestamp =
JitChecks.createChecksForTimestamp(
JitRole::isProvider, getMatchedExchangeUuid(), expectedApiVersion, dsp);
if (requestedByProvider) {
return Stream.of(
new UrlPathCheck(JitRole::isProvider, getMatchedExchangeUuid(), getType.getUrlPath()),
new HttpMethodCheck(JitRole::isProvider, getMatchedExchangeUuid(), JitStandard.GET),
new ResponseStatusCheck(JitRole::isConsumer, getMatchedExchangeUuid(), 200),
new ApiHeaderCheck(
JitRole::isProvider,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
expectedApiVersion),
new ApiHeaderCheck(
JitRole::isConsumer,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
expectedApiVersion),
new JsonSchemaCheck(
JitRole::isConsumer,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
validator),
checksForTimestamp);
}
// Consumer sends request
return Stream.of(
new UrlPathCheck(JitRole::isConsumer, getMatchedExchangeUuid(), getType.getUrlPath()),
new HttpMethodCheck(JitRole::isConsumer, getMatchedExchangeUuid(), JitStandard.GET),
new ResponseStatusCheck(JitRole::isProvider, getMatchedExchangeUuid(), 200),
new ApiHeaderCheck(
JitRole::isConsumer,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
expectedApiVersion),
new ApiHeaderCheck(
JitRole::isProvider,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
expectedApiVersion),
new JsonSchemaCheck(
JitRole::isProvider, getMatchedExchangeUuid(), HttpMessageType.RESPONSE, validator),
checksForTimestamp);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
if (dsp == null) return Stream.of();
return Stream.of(
new UrlPathCheck(
JitRole::isProvider, getMatchedExchangeUuid(), JitStandard.PORT_CALL_URL + dsp.portCallID()),
JitRole::isProvider,
getMatchedExchangeUuid(),
JitStandard.PORT_CALL_URL + dsp.portCallID()),
new HttpMethodCheck(JitRole::isProvider, getMatchedExchangeUuid(), JitStandard.PUT),
new ResponseStatusCheck(JitRole::isConsumer, getMatchedExchangeUuid(), 204),
new ApiHeaderCheck(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public String getHumanReadablePrompt() {
yield "Send a Port Call Service (PUT) for the %s".formatted(dsp.selector().getFullName());
case GIVEN:
yield "Send a Port Call Service (PUT) for %s".formatted(serviceType.name());
case ANY:
yield "Send a Port Call Service (PUT) for a service you supply";
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class JitChecks {
public static final String TERMINAL_CALL_ID = "terminalCallID";
public static final String PORT_CALL_ID = "portCallID";
public static final String PORT_CALL_SERVICE_ID = "portCallServiceID";
public static final String TIMESTAMP_ID = "timestampID";
public static final String CLASSIFIER_CODE = "classifierCode";

static final JsonRebaseableContentCheck IS_FYI_TRUE =
JsonAttribute.mustEqual(
Expand All @@ -49,7 +51,9 @@ public static ActionCheck createChecksForPortCallService(
if (serviceType != null) {
checks.add(checkPortCallService(serviceType));
}
if (dsp != null && dsp.selector() != JitServiceTypeSelector.GIVEN) {
if (dsp != null
&& dsp.selector() != JitServiceTypeSelector.GIVEN
&& dsp.selector() != JitServiceTypeSelector.ANY) {
checks.add(checkPortCallServiceRightType(dsp));
}
checks.add(JitChecks.checkIDsMatchesPreviousCall(dsp));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.dcsa.conformance.standards.jit.model;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;

public record JitGetPortCallFilters(
String portCallID,
String portVisitReference,
String UNLocationCode,
String vesselIMONumber,
String vesselName,
String MMSINumber) {

public static List<String> props() {
return Arrays.stream(JitGetPortCallFilters.class.getDeclaredFields())
.map(Field::getName)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.dcsa.conformance.standards.jit.model;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;

public record JitGetPortServiceCallFilters(
String terminalCallID, String portCallServiceID, String portCallServiceType) {

public static List<String> props() {
return Arrays.stream(JitGetPortServiceCallFilters.class.getDeclaredFields())
.map(Field::getName)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.dcsa.conformance.standards.jit.model;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;

public record JitGetTerminalCallFilters(
String portCallID,
String terminalCallID,
String carrierServiceName,
String carrierServiceCode,
String universalServiceReference,
String terminalCallReference,
String carrierImportVoyageNumber,
String carrierExportVoyageNumber,
String universalImportVoyageReference,
String universalExportVoyageReference) {

public static List<String> props() {
return Arrays.stream(JitGetTerminalCallFilters.class.getDeclaredFields())
.map(Field::getName)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.dcsa.conformance.standards.jit.model;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;

public record JitGetTimestampCallFilters(
String timestampID_Estimated,
String timestampID_Requested,
String timestampID_Planned,
String timestampID_Actual,
String portCallServiceID,
String classifierCode) {

public static List<String> props() {
return Arrays.stream(JitGetTimestampCallFilters.class.getDeclaredFields())
.map(Field::getName)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.dcsa.conformance.standards.jit.model;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.dcsa.conformance.standards.jit.JitStandard;

@Getter
@RequiredArgsConstructor
public enum JitGetType {
PORT_CALLS(
"Port Calls",
JitSchema.PORT_CALLS,
JitStandard.PORT_CALL_URL.substring(0, JitStandard.PORT_CALL_URL.length() - 1)),
TERMINAL_CALLS(
"Terminal Calls",
JitSchema.TERMINAL_CALLS,
JitStandard.TERMINAL_CALL_URL.substring(0, JitStandard.TERMINAL_CALL_URL.length() - 1)),
PORT_CALL_SERVICES(
"Port Call Services",
JitSchema.PORT_CALL_SERVICES,
JitStandard.PORT_CALL_SERVICES_URL.substring(
0, JitStandard.PORT_CALL_SERVICES_URL.length() - 1)),
TIMESTAMPS(
"Timestamps",
JitSchema.TIMESTAMPS,
JitStandard.TIMESTAMP_URL.substring(0, JitStandard.TIMESTAMP_URL.length() - 1)),
VESSEL_STATUSES(
"Vessel Statuses",
JitSchema.VESSEL_STATUSES,
JitStandard.VESSEL_STATUS_URL.substring(0, JitStandard.VESSEL_STATUS_URL.length() - 1));

private final String name;
private final JitSchema jitSchema;
private final String urlPath;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public enum JitSchema {
MOVES("Moves"),
OMIT_PORT_CALL("OmitPortCall"),
OMIT_TERMINAL_CALL("OmitTerminalCall"),
// GET actions
PORT_CALLS("PortCalls"),
TERMINAL_CALLS("TerminalCalls"),
PORT_CALL_SERVICES("PortCallServices"),
TIMESTAMPS("Timestamps"),
VESSEL_STATUSES("VesselStatuses"),
;

private final String schemaName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum JitServiceTypeSelector {
GIVEN("Given"),
FULL_ERP("full ERP"),
S_A_PATTERN("S-A pattern"),
ANY("Any")
;

private final String fullName;
Expand Down
Loading

0 comments on commit c8bd38b

Please sign in to comment.