Skip to content

Commit

Permalink
re-add id to SimulationSpecificAdapterConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
DC2-DanielKrueger committed Nov 26, 2024
1 parent eb9f6a6 commit f2358d6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ public SimulationProtocolAdapterFactory(
legacySimulationAdapterConfig.getPollingIntervalMillis(),
legacySimulationAdapterConfig.getMaxPollingErrorsBeforeRemoval());

final SimulationSpecificAdapterConfig simulationSpecificAdapterConfig =
new SimulationSpecificAdapterConfig(simulationToMqttConfig,
final SimulationSpecificAdapterConfig simulationSpecificAdapterConfig = new SimulationSpecificAdapterConfig(
legacySimulationAdapterConfig.getId(),
simulationToMqttConfig,
legacySimulationAdapterConfig.getMinValue(),
legacySimulationAdapterConfig.getMaxValue(),
legacySimulationAdapterConfig.getMinDelay(),
legacySimulationAdapterConfig.getMaxDelay());
return new ConfigTagsTuple(legacySimulationAdapterConfig.getId(),
simulationSpecificAdapterConfig,
List.of(), simulationToMqttMappings);
List.of(),
simulationToMqttMappings);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
public class SimulationSpecificAdapterConfig
implements ProtocolSpecificAdapterConfig, AdapterConfigWithPollingContexts {

private static final @NotNull String ID_REGEX = "^([a-zA-Z_0-9-_])*$";

@JsonProperty(value = "id", required = true)
@ModuleConfigField(title = "Identifier",
description = "Unique identifier for this protocol adapter",
format = ModuleConfigField.FieldType.IDENTIFIER,
required = true,
stringPattern = ID_REGEX,
stringMinLength = 1,
stringMaxLength = 1024)
private final @NotNull String id;

@JsonProperty(value = "simulationToMqtt")
@ModuleConfigField(title = "simulationToMqtt",
description = "Define Simulations to create MQTT messages.",
Expand Down Expand Up @@ -69,11 +81,13 @@ public class SimulationSpecificAdapterConfig

@JsonCreator
public SimulationSpecificAdapterConfig(
@JsonProperty(value = "id", required = true) final @NotNull String id,
@JsonProperty(value = "simulationToMqtt") final @Nullable SimulationToMqttConfig simulationToMqttConfig,
@JsonProperty("minValue") final @Nullable Integer minValue,
@JsonProperty("maxValue") final @Nullable Integer maxValue,
@JsonProperty("minDelay") final @Nullable Integer minDelay,
@JsonProperty("maxDelay") final @Nullable Integer maxDelay) {
this.id = id;
this.simulationToMqttConfig =
Objects.requireNonNullElse(simulationToMqttConfig, SimulationToMqttConfig.DEFAULT);
this.minValue = Objects.requireNonNullElse(minValue, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void unconvertConfigObject_full_valid() {
List.of(new MqttUserProperty("my-name", "my-value")));

final SimulationSpecificAdapterConfig simulationAdapterConfig =
new SimulationSpecificAdapterConfig(new SimulationToMqttConfig(List.of(pollingContext), 11, 12),
new SimulationSpecificAdapterConfig("someId", new SimulationToMqttConfig(List.of(pollingContext), 11, 12),
12,
13,
14,
Expand All @@ -190,7 +190,7 @@ public void unconvertConfigObject_defaults_valid() {
new SimulationToMqttMapping("my/destination", null, null, null, null, null);

final SimulationSpecificAdapterConfig simulationAdapterConfig =
new SimulationSpecificAdapterConfig(new SimulationToMqttConfig(List.of(pollingContext), null, null),
new SimulationSpecificAdapterConfig("id", new SimulationToMqttConfig(List.of(pollingContext), null, null),
null,
null,
null,
Expand Down

0 comments on commit f2358d6

Please sign in to comment.