Skip to content

Commit 97161d3

Browse files
committed
feat (dispatcher): read vhost topology from TopologyRegistry
ConversionUtils, ConversionRulesCommand, MessagePersistencePolicy and Dispatcher now resolve model versions and the NexSIS vhost target via HubConfiguration.getTopologyRegistry() instead of hardcoded constants.
1 parent bb1953c commit 97161d3

5 files changed

Lines changed: 45 additions & 23 deletions

File tree

hub/dispatcher/src/main/java/com/hubsante/hub/utils/ConversionRulesCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
*/
1616
package com.hubsante.hub.utils;
1717

18-
import static com.hubsante.hub.config.Constants.CONVERSION_VHOST_MODEL;
19-
2018
import com.hubsante.hub.config.HubConfiguration;
19+
import com.hubsante.hub.service.TopologyRegistry;
2120
import com.hubsante.model.edxl.EdxlMessage;
2221

2322
public class ConversionRulesCommand {
@@ -65,10 +64,11 @@ public EdxlMessage getEdxlMessage() {
6564
}
6665

6766
public String getVHostMatchingModelVersion(String vHost) {
68-
if (CONVERSION_VHOST_MODEL.get(vHost) == null) {
67+
String modelVersion = TopologyRegistry.getInstance().getMajorModelVersion(vHost);
68+
if (modelVersion == null) {
6969
throw new IllegalArgumentException(
7070
"There is no model version associated with the host " + vHost);
7171
}
72-
return CONVERSION_VHOST_MODEL.get(vHost);
72+
return modelVersion;
7373
}
7474
}

hub/dispatcher/src/main/java/com/hubsante/hub/utils/ConversionUtils.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static com.hubsante.hub.utils.MessageUtils.*;
2121

2222
import com.hubsante.hub.config.HubConfiguration;
23+
import com.hubsante.hub.service.TopologyRegistry;
2324
import com.hubsante.model.edxl.EdxlMessage;
2425
import java.util.Arrays;
2526
import lombok.extern.slf4j.Slf4j;
@@ -54,7 +55,7 @@ public static boolean requiresVersionConversion(
5455
}
5556

5657
public static boolean isConversionAvailable(String vhost) {
57-
return CONVERSION_VHOST_MODEL.get(vhost) != null;
58+
return TopologyRegistry.getInstance().getMajorModelVersion(vhost) != null;
5859
}
5960

6061
public static String getSourceVHost(HubConfiguration hubConfig) {
@@ -72,7 +73,9 @@ public static String[] getTargetVHosts(HubConfiguration hubConfig, EdxlMessage e
7273
boolean isNexsisRecipient =
7374
recipientId.startsWith(FR_FIRE_PREFIX) || recipientId.startsWith(FR_CISU_PREFIX);
7475
if (isNexsisRecipient) {
75-
return new String[] {NEXSIS_VHOST}; // ["15-nexsis_v1.9"]
76+
return new String[] {
77+
TopologyRegistry.getInstance().getVhostTarget(NEXSIS_HUBEX_PARTNER)
78+
};
7679
}
7780
boolean isCisuSender = !senderId.startsWith(FR_HEALTH_PREFIX);
7881
boolean isDirectCisu = isDirectCisuForHealthActor(hubConfig, edxlMessage);
@@ -119,7 +122,8 @@ public static boolean isAlreadyCisuConverted(String currentVHost, String recipie
119122
if (recipient.startsWith(FR_HEALTH_PREFIX)) {
120123
return currentVHost.startsWith(HEALTH_VHOST_PREFIX);
121124
} else {
122-
return currentVHost.startsWith(NEXSIS_VHOST);
125+
return currentVHost.startsWith(
126+
TopologyRegistry.getInstance().getVhostTarget(NEXSIS_HUBEX_PARTNER));
123127
}
124128
}
125129

hub/dispatcher/src/main/java/com/hubsante/hub/utils/MessagePersistencePolicy.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
package com.hubsante.hub.utils;
1717

1818
import static com.hubsante.hub.config.Constants.HEALTH_VHOST_PREFIX;
19-
import static com.hubsante.hub.config.Constants.NEXSIS_VHOST;
19+
import static com.hubsante.hub.config.Constants.NEXSIS_HUBEX_PARTNER;
2020

21+
import com.hubsante.hub.service.TopologyRegistry;
22+
import java.util.Objects;
2123
import java.util.Set;
2224

2325
/**
@@ -46,7 +48,8 @@ private MessagePersistencePolicy() {}
4648
* Returns true if the message with the given useCase from the given vhost should be persisted.
4749
*/
4850
public static boolean shouldPersist(String vhost, String useCase) {
49-
if (NEXSIS_VHOST.equals(vhost)) {
51+
String nexsisVhost = TopologyRegistry.getInstance().getVhostTarget(NEXSIS_HUBEX_PARTNER);
52+
if (Objects.equals(nexsisVhost, vhost)) {
5053
return NEXSIS_PERSISTED_USE_CASES.contains(useCase);
5154
}
5255
if (vhost != null && vhost.startsWith(HEALTH_VHOST_PREFIX)) {

hub/dispatcher/src/test/java/com/hubsante/hub/service/ConversionUtilsTest.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package com.hubsante.hub.service;
1717

18-
import static com.hubsante.hub.utils.ConversionUtils.isAlreadyCisuConverted;
19-
import static com.hubsante.hub.utils.ConversionUtils.trimVersionSuffix;
2018
import static org.junit.jupiter.api.Assertions.*;
2119
import static org.mockito.ArgumentMatchers.anyString;
2220
import static org.mockito.Mockito.mockStatic;
@@ -29,6 +27,7 @@
2927
import java.util.Arrays;
3028
import java.util.List;
3129
import java.util.stream.Stream;
30+
import org.junit.jupiter.api.BeforeAll;
3231
import org.junit.jupiter.api.BeforeEach;
3332
import org.junit.jupiter.api.Test;
3433
import org.junit.jupiter.params.ParameterizedTest;
@@ -38,6 +37,7 @@
3837
import org.mockito.Mock;
3938
import org.mockito.MockedStatic;
4039
import org.mockito.MockitoAnnotations;
40+
import org.springframework.core.io.ClassPathResource;
4141

4242
public class ConversionUtilsTest {
4343

@@ -50,6 +50,11 @@ public class ConversionUtilsTest {
5050
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
5151
private EdxlMessage edxlMessage;
5252

53+
@BeforeAll
54+
static void setUpTopologyRegistry() {
55+
new TopologyRegistry(new ClassPathResource("config/clients.yaml"));
56+
}
57+
5358
@BeforeEach
5459
void setUp() {
5560
MockitoAnnotations.openMocks(this);
@@ -443,22 +448,24 @@ void testBuildExchange() {
443448

444449
@Test
445450
public void isAlreadyCisuConvertedTest() {
446-
assertTrue(isAlreadyCisuConverted("15-15_v1.5", "fr.health.something"));
447-
assertTrue(isAlreadyCisuConverted("15-nexsis_v1.9", "fr.fire.something-else"));
448-
449-
assertFalse(isAlreadyCisuConverted("15-15_v1.5", "fr.fire.something-else"));
450-
assertFalse(isAlreadyCisuConverted("15-nexsis_v1.9", "fr.health.something"));
451-
assertFalse(isAlreadyCisuConverted("15-smur_v1.7", "fr.health.something"));
451+
assertTrue(ConversionUtils.isAlreadyCisuConverted("15-15_v1.5", "fr.health.something"));
452+
assertTrue(
453+
ConversionUtils.isAlreadyCisuConverted("15-nexsis_v1.9", "fr.fire.something-else"));
454+
455+
assertFalse(ConversionUtils.isAlreadyCisuConverted("15-15_v1.5", "fr.fire.something-else"));
456+
assertFalse(
457+
ConversionUtils.isAlreadyCisuConverted("15-nexsis_v1.9", "fr.health.something"));
458+
assertFalse(ConversionUtils.isAlreadyCisuConverted("15-smur_v1.7", "fr.health.something"));
452459
}
453460

454461
@Test
455462
public void testTrimVersionSuffix() {
456-
assertEquals("15-15", trimVersionSuffix("15-15_v1.3"));
457-
assertEquals("15-nexsis", trimVersionSuffix("15-nexsis_v2"));
458-
assertEquals("backup", trimVersionSuffix("backup_v2.0.1"));
459-
assertEquals("no-version-here", trimVersionSuffix("no-version-here"));
460-
assertNull(trimVersionSuffix(null));
461-
assertEquals("", trimVersionSuffix(""));
463+
assertEquals("15-15", ConversionUtils.trimVersionSuffix("15-15_v1.3"));
464+
assertEquals("15-nexsis", ConversionUtils.trimVersionSuffix("15-nexsis_v2"));
465+
assertEquals("backup", ConversionUtils.trimVersionSuffix("backup_v2.0.1"));
466+
assertEquals("no-version-here", ConversionUtils.trimVersionSuffix("no-version-here"));
467+
assertNull(ConversionUtils.trimVersionSuffix(null));
468+
assertEquals("", ConversionUtils.trimVersionSuffix(""));
462469
}
463470

464471
@Test

hub/dispatcher/src/test/java/com/hubsante/hub/utils/MessagePersistencePolicyTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,21 @@
1818
import static org.junit.jupiter.api.Assertions.assertFalse;
1919
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

21+
import com.hubsante.hub.service.TopologyRegistry;
22+
import org.junit.jupiter.api.BeforeAll;
2123
import org.junit.jupiter.api.DisplayName;
2224
import org.junit.jupiter.api.Test;
2325
import org.junit.jupiter.params.ParameterizedTest;
2426
import org.junit.jupiter.params.provider.ValueSource;
27+
import org.springframework.core.io.ClassPathResource;
2528

2629
public class MessagePersistencePolicyTest {
2730

31+
@BeforeAll
32+
static void setUpTopologyRegistry() {
33+
new TopologyRegistry(new ClassPathResource("config/clients.yaml"));
34+
}
35+
2836
// ─── Nexsis vhost (18 → 15) ───────────────────────────────────────────────
2937

3038
@Test

0 commit comments

Comments
 (0)