Skip to content

Commit

Permalink
add logic to resolve legacy protocol ids
Browse files Browse the repository at this point in the history
  • Loading branch information
DC2-DanielKrueger committed Dec 16, 2024
1 parent 71f1300 commit ecc39e1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ public ProtocolAdapterFactoryManager(
}

public @NotNull Map<String, ProtocolAdapterInformation> getAllAvailableAdapterTypes() {
return factoryMap.values()
.stream()
.map(ProtocolAdapterFactory::getInformation)
.collect(Collectors.toMap(ProtocolAdapterInformation::getProtocolId, o -> o));
final Map<String, ProtocolAdapterInformation> protocolIdToInformation = new HashMap<>();
for (final ProtocolAdapterFactory<?> factory : factoryMap.values()) {
final ProtocolAdapterInformation information = factory.getInformation();
protocolIdToInformation.put(information.getProtocolId(), information);
for (final String legacyProtocolId : information.getLegacyProtocolIds()) {
protocolIdToInformation.put(legacyProtocolId, information);
}
}
return protocolIdToInformation;
}

public void writingEnabledChanged(final boolean writingEnabled) {
Expand All @@ -75,7 +80,7 @@ public static Map<String, ProtocolAdapterFactory<?>> findAllAdapters(
final @NotNull ModuleLoader moduleLoader,
final @NotNull EventService eventService,
final boolean writingEnabled) {
Map<String, ProtocolAdapterFactory<?>> factoryMap = new HashMap<>();
final Map<String, ProtocolAdapterFactory<?>> factoryMap = new HashMap<>();
final List<Class<? extends ProtocolAdapterFactory>> implementations =
moduleLoader.findImplementations(ProtocolAdapterFactory.class);

Expand All @@ -90,6 +95,9 @@ public static Map<String, ProtocolAdapterFactory<?>> findAllAdapters(
}
final ProtocolAdapterInformation information = protocolAdapterFactory.getInformation();
factoryMap.put(information.getProtocolId(), protocolAdapterFactory);
for (final String legacyProtocolId : information.getLegacyProtocolIds()) {
factoryMap.put(legacyProtocolId, protocolAdapterFactory);
}
} catch (final InvocationTargetException | InstantiationException | IllegalAccessException |
NoSuchMethodException e) {
log.error("Not able to load module, reason: {}.", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ private EipProtocolAdapterInformation() {
return PROTOCOL_ID;
}

@Override
public @NotNull List<String> getLegacyProtocolIds() {
return List.of("ethernet-ip");
}

@Override
public @NotNull String getDisplayName() {
return "Ethernet IP Protocol Adapter";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ protected FileProtocolAdapterInformation() {
return "File Protocol";
}

@Override
public @NotNull List<String> getLegacyProtocolIds() {
return List.of("file_input", "file_polling_protocol");
}

@Override
public @NotNull String getProtocolId() {
return PROTOCOL_ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ private OpcUaProtocolAdapterInformation() {
return PROTOCOL_ID;
}

@Override
public @NotNull List<String> getLegacyProtocolIds() {
return List.of("opc-ua-client");
}

@Override
public @NotNull String getDisplayName() {
return "OPC UA Protocol Adapter";
Expand Down

0 comments on commit ecc39e1

Please sign in to comment.