Skip to content

Commit

Permalink
SD-1699 Endpoint URI override support (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
gj0dcsa authored Nov 17, 2024
1 parent a687faf commit aed92f0
Show file tree
Hide file tree
Showing 24 changed files with 752 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import java.util.*;
import org.dcsa.conformance.core.AbstractComponentFactory;
import org.dcsa.conformance.core.AbstractStandard;
import org.dcsa.conformance.standards.adoption.party.AdoptionRole;

public class AdoptionStandard extends AbstractStandard {
public static final AdoptionStandard INSTANCE = new AdoptionStandard();
public static final String ADOPTION_STATS_EXAMPLE = "/standards/adoption/messages/adoption-%s-example.json";
public static final String SCENARIO_SUITE_CONFORMANCE = "Conformance";
public static final String ADOPTION_STATS_EXAMPLE =
"/standards/adoption/messages/adoption-%s-example.json";

private AdoptionStandard() {
super("Adoption");
Expand All @@ -15,8 +18,26 @@ private AdoptionStandard() {
@Override
public SortedMap<String, SortedSet<String>> getScenarioSuitesByStandardVersion() {
return new TreeMap<>(
Map.ofEntries(
Map.entry("1.0.0", new TreeSet<>(Set.of("Conformance")))));
Map.ofEntries(Map.entry("1.0.0", new TreeSet<>(Set.of(SCENARIO_SUITE_CONFORMANCE)))));
}

@Override
public Map<String, Map<String, SortedMap<String, SortedSet<String>>>>
getEndpointUrisAndMethodsByScenarioSuiteAndRoleName() {
return Map.ofEntries(
Map.entry(
SCENARIO_SUITE_CONFORMANCE,
Map.ofEntries(
Map.entry(
AdoptionRole.ADOPTER.getConfigName(),
new TreeMap<>(
Map.ofEntries(
Map.entry("/v1/adoption-stats", new TreeSet<>(Set.of("GET")))))),
Map.entry(
AdoptionRole.DCSA.getConfigName(),
new TreeMap<>(
Map.ofEntries(
Map.entry("/v1/adoption-stats", new TreeSet<>(Set.of("GET")))))))));
}

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

import org.dcsa.conformance.core.AbstractComponentFactory;
import org.dcsa.conformance.core.AbstractStandard;
import org.dcsa.conformance.standards.booking.party.BookingRole;

import java.util.*;

Expand All @@ -24,6 +25,31 @@ public SortedMap<String, SortedSet<String>> getScenarioSuitesByStandardVersion()
BookingScenarioListBuilder.SCENARIO_SUITE_RI)))));
}

@Override
public Map<String, Map<String, SortedMap<String, SortedSet<String>>>>
getEndpointUrisAndMethodsByScenarioSuiteAndRoleName() {
Map<String, SortedMap<String, SortedSet<String>>> endpointUrisAndMethodsByRoleName =
Map.ofEntries(
Map.entry(
BookingRole.CARRIER.getConfigName(),
new TreeMap<>(
Map.ofEntries(
Map.entry("/v2/bookings", new TreeSet<>(Set.of("POST"))),
Map.entry(
"/v2/bookings/{bookingReference}",
new TreeSet<>(Set.of("PUT", "GET", "PATCH")))))),
Map.entry(
BookingRole.SHIPPER.getConfigName(),
new TreeMap<>(
Map.ofEntries(
Map.entry("/v2/booking-notifications", new TreeSet<>(Set.of("POST")))))));
return Map.ofEntries(
Map.entry(
BookingScenarioListBuilder.SCENARIO_SUITE_CONFORMANCE,
endpointUrisAndMethodsByRoleName),
Map.entry(BookingScenarioListBuilder.SCENARIO_SUITE_RI, endpointUrisAndMethodsByRoleName));
}

@Override
protected AbstractComponentFactory doCreateComponentFactory(
String standardVersion, String scenarioSuite) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,37 @@
import java.util.*;
import org.dcsa.conformance.core.AbstractComponentFactory;
import org.dcsa.conformance.core.AbstractStandard;
import org.dcsa.conformance.standards.cs.party.CsRole;

public class CsStandard extends AbstractStandard {
public static final CsStandard INSTANCE = new CsStandard();
public static final String SCENARIO_SUITE_CONFORMANCE = "Conformance";

private CsStandard() {
super("CS");
}

@Override
public SortedMap<String, SortedSet<String>> getScenarioSuitesByStandardVersion() {
return new TreeMap<>(Map.ofEntries(Map.entry("1.0.0", new TreeSet<>(Set.of("Conformance")))));
return new TreeMap<>(
Map.ofEntries(Map.entry("1.0.0", new TreeSet<>(Set.of(SCENARIO_SUITE_CONFORMANCE)))));
}

@Override
public Map<String, Map<String, SortedMap<String, SortedSet<String>>>>
getEndpointUrisAndMethodsByScenarioSuiteAndRoleName() {
return Map.ofEntries(
Map.entry(
SCENARIO_SUITE_CONFORMANCE,
Map.ofEntries(
Map.entry(
CsRole.PUBLISHER.getConfigName(),
new TreeMap<>(
Map.ofEntries(
Map.entry("/v1/point-to-point-routes", new TreeSet<>(Set.of("GET"))),
Map.entry("/v1/port-schedules", new TreeSet<>(Set.of("GET"))),
Map.entry("/v1/vessel-schedules", new TreeSet<>(Set.of("GET")))))),
Map.entry(CsRole.SUBSCRIBER.getConfigName(), new TreeMap<>()))));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dcsa.conformance.core;

import java.util.Map;
import java.util.SortedMap;
import java.util.SortedSet;
import lombok.Getter;
Expand All @@ -14,6 +15,9 @@ protected AbstractStandard(String name) {

public abstract SortedMap<String, SortedSet<String>> getScenarioSuitesByStandardVersion();

public abstract Map<String, Map<String, SortedMap<String, SortedSet<String>>>>
getEndpointUrisAndMethodsByScenarioSuiteAndRoleName();

protected abstract AbstractComponentFactory doCreateComponentFactory(
String standardVersion, String scenarioSuite);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private ConformanceRequest _createConformanceRequest(
withFullApiVersionHeader ? apiVersion : apiVersion.split("\\.")[0];
return new ConformanceRequest(
method,
counterpartConfiguration.getUrl() + path,
_getCounterpartUrl(counterpartConfiguration, method, path),
queryParams,
new ConformanceMessage(
partyConfiguration.getName(),
Expand Down Expand Up @@ -267,6 +267,27 @@ private ConformanceRequest _createConformanceRequest(
System.currentTimeMillis()));
}

private String _getCounterpartUrl(
CounterpartConfiguration counterpartConfiguration, String method, String path) {
var url = counterpartConfiguration.getUrl() + path;
EndpointUriOverrideConfiguration[] endpointUriOverrideConfigurations =
counterpartConfiguration.getEndpointUriOverrideConfigurations();
if (endpointUriOverrideConfigurations != null) {
for (EndpointUriOverrideConfiguration endpointUriOverrideConfiguration :
endpointUriOverrideConfigurations) {
if (method.equals(endpointUriOverrideConfiguration.getMethod())) {
int baseUriIndex = url.indexOf(endpointUriOverrideConfiguration.getEndpointBaseUri());
if (baseUriIndex > -1) {
return url.replace(
endpointUriOverrideConfiguration.getEndpointBaseUri(),
endpointUriOverrideConfiguration.getBaseUriOverride());
}
}
}
}
return url;
}

public abstract ConformanceResponse handleRequest(ConformanceRequest request);

public void handleNotification() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class CounterpartConfiguration {
private String authHeaderName = "";
private String authHeaderValue = "";
private HttpHeaderConfiguration[] externalPartyAdditionalHeaders;
private EndpointUriOverrideConfiguration[] endpointUriOverrideConfigurations;

public static void validateUrl(String url, boolean allowHttpLocalhost) throws UserFacingException {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.dcsa.conformance.core.party;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class EndpointUriOverrideConfiguration {
private String method;
private String endpointBaseUri;
private String endpointSuffix;
private String baseUriOverride;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.util.*;
import org.dcsa.conformance.core.AbstractComponentFactory;
import org.dcsa.conformance.core.AbstractStandard;
import org.dcsa.conformance.standards.eblissuance.party.EblIssuanceRole;

public class EblIssuanceStandard extends AbstractStandard {
public static final EblIssuanceStandard INSTANCE = new EblIssuanceStandard();
public static final String SCENARIO_SUITE_CONFORMANCE = "Conformance";

private EblIssuanceStandard() {
super("eBL Issuance");
Expand All @@ -14,8 +16,28 @@ private EblIssuanceStandard() {
@Override
public SortedMap<String, SortedSet<String>> getScenarioSuitesByStandardVersion() {
return new TreeMap<>(
Map.ofEntries(
Map.entry("3.0.0", new TreeSet<>(Set.of("Conformance")))));
Map.ofEntries(Map.entry("3.0.0", new TreeSet<>(Set.of(SCENARIO_SUITE_CONFORMANCE)))));
}

@Override
public Map<String, Map<String, SortedMap<String, SortedSet<String>>>>
getEndpointUrisAndMethodsByScenarioSuiteAndRoleName() {
return Map.ofEntries(
Map.entry(
SCENARIO_SUITE_CONFORMANCE,
Map.ofEntries(
Map.entry(
EblIssuanceRole.CARRIER.getConfigName(),
new TreeMap<>(
Map.ofEntries(
Map.entry(
"/v3/ebl-issuance-responses", new TreeSet<>(Set.of("POST")))))),
Map.entry(
EblIssuanceRole.PLATFORM.getConfigName(),
new TreeMap<>(
Map.ofEntries(
Map.entry(
"/v3/ebl-issuance-requests", new TreeSet<>(Set.of("PUT")))))))));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,41 @@
import java.util.*;
import org.dcsa.conformance.core.AbstractComponentFactory;
import org.dcsa.conformance.core.AbstractStandard;
import org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderRole;

public class EblSurrenderStandard extends AbstractStandard {
public static final EblSurrenderStandard INSTANCE = new EblSurrenderStandard();
public static final String SCENARIO_SUITE_CONFORMANCE = "Conformance";

private EblSurrenderStandard() {
super("eBL Surrender");
}

@Override
public SortedMap<String, SortedSet<String>> getScenarioSuitesByStandardVersion() {
return new TreeMap<>(Map.ofEntries(Map.entry("3.0.0", new TreeSet<>(Set.of("Conformance")))));
return new TreeMap<>(
Map.ofEntries(Map.entry("3.0.0", new TreeSet<>(Set.of(SCENARIO_SUITE_CONFORMANCE)))));
}

@Override
public Map<String, Map<String, SortedMap<String, SortedSet<String>>>>
getEndpointUrisAndMethodsByScenarioSuiteAndRoleName() {
return Map.ofEntries(
Map.entry(
SCENARIO_SUITE_CONFORMANCE,
Map.ofEntries(
Map.entry(
EblSurrenderRole.CARRIER.getConfigName(),
new TreeMap<>(
Map.ofEntries(
Map.entry(
"/v3/ebl-surrender-requests", new TreeSet<>(Set.of("POST")))))),
Map.entry(
EblSurrenderRole.PLATFORM.getConfigName(),
new TreeMap<>(
Map.ofEntries(
Map.entry(
"/v3/ebl-surrender-responses", new TreeSet<>(Set.of("POST")))))))));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.*;
import org.dcsa.conformance.core.AbstractComponentFactory;
import org.dcsa.conformance.core.AbstractStandard;
import org.dcsa.conformance.standards.ebl.party.EblRole;

public class EblStandard extends AbstractStandard {
public static final EblStandard INSTANCE = new EblStandard();
Expand All @@ -14,10 +15,49 @@ private EblStandard() {
@Override
public SortedMap<String, SortedSet<String>> getScenarioSuitesByStandardVersion() {
return new TreeMap<>(
Map.ofEntries(
Map.entry(
"3.0.0",
new TreeSet<>(EblScenarioListBuilder.SCENARIOS))));
Map.ofEntries(Map.entry("3.0.0", new TreeSet<>(EblScenarioListBuilder.SCENARIOS))));
}

@Override
public Map<String, Map<String, SortedMap<String, SortedSet<String>>>>
getEndpointUrisAndMethodsByScenarioSuiteAndRoleName() {
return Map.ofEntries(
Map.entry(
EblScenarioListBuilder.SCENARIO_SUITE_CONFORMANCE_SI_ONLY,
Map.ofEntries(
Map.entry(EblRole.CARRIER.getConfigName(), new TreeMap<>(Map.ofEntries(Map.entry("/v3/shipping-instructions", new TreeSet<>(Set.of("POST"))),
Map.entry(
"/v3/shipping-instructions/{documentReference}",
new TreeSet<>(Set.of("PUT", "GET", "PATCH")))))),
Map.entry(EblRole.SHIPPER.getConfigName(), new TreeMap<>(Map.ofEntries(Map.entry(
"/v3/shipping-instructions-notifications",
new TreeSet<>(Set.of("POST")))))))),
Map.entry(
EblScenarioListBuilder.SCENARIO_SUITE_CONFORMANCE_TD_ONLY,
Map.ofEntries(
Map.entry(EblRole.CARRIER.getConfigName(), new TreeMap<>(Map.ofEntries(Map.entry(
"/v3/transport-documents/{transportDocumentReference}",
new TreeSet<>(Set.of("GET", "PATCH")))))),
Map.entry(EblRole.SHIPPER.getConfigName(), new TreeMap<>(Map.ofEntries(Map.entry(
"/v3/transport-document-notifications",
new TreeSet<>(Set.of("POST")))))))),
Map.entry(
EblScenarioListBuilder.SCENARIO_SUITE_RI,
Map.ofEntries(
Map.entry(EblRole.CARRIER.getConfigName(), new TreeMap<>(Map.ofEntries(Map.entry("/v3/shipping-instructions", new TreeSet<>(Set.of("POST"))),
Map.entry(
"/v3/shipping-instructions/{documentReference}",
new TreeSet<>(Set.of("PUT", "GET", "PATCH"))),
Map.entry(
"/v3/transport-documents/{transportDocumentReference}",
new TreeSet<>(Set.of("GET", "PATCH")))))),
Map.entry(EblRole.SHIPPER.getConfigName(), new TreeMap<>(Map.ofEntries(
Map.entry(
"/v3/shipping-instructions-notifications",
new TreeSet<>(Set.of("POST"))),
Map.entry(
"/v3/transport-document-notifications",
new TreeSet<>(Set.of("POST")))))))));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.util.*;
import org.dcsa.conformance.core.AbstractComponentFactory;
import org.dcsa.conformance.core.AbstractStandard;
import org.dcsa.conformance.standards.jit.party.JitRole;

public class JitStandard extends AbstractStandard {
public static final JitStandard INSTANCE = new JitStandard();
public static final String SCENARIO_SUITE_CONFORMANCE = "Conformance";

private JitStandard() {
super("JIT");
Expand All @@ -14,8 +16,24 @@ private JitStandard() {
@Override
public SortedMap<String, SortedSet<String>> getScenarioSuitesByStandardVersion() {
return new TreeMap<>(
Map.ofEntries(
Map.entry("1.2.0", new TreeSet<>(Set.of("Conformance")))));
Map.ofEntries(Map.entry("1.2.0", new TreeSet<>(Set.of(SCENARIO_SUITE_CONFORMANCE)))));
}

@Override
public Map<String, Map<String, SortedMap<String, SortedSet<String>>>>
getEndpointUrisAndMethodsByScenarioSuiteAndRoleName() {
return Map.ofEntries(
Map.entry(
SCENARIO_SUITE_CONFORMANCE,
Map.ofEntries(
Map.entry(
JitRole.PUBLISHER.getConfigName(),
new TreeMap<>(
Map.ofEntries(
Map.entry(
"/v2/port-call-services/{portCallServiceID}",
new TreeSet<>(Set.of("GET")))))),
Map.entry(JitRole.SUBSCRIBER.getConfigName(), new TreeMap<>()))));
}

@Override
Expand Down
Loading

0 comments on commit aed92f0

Please sign in to comment.