Skip to content

Commit

Permalink
add version to config
Browse files Browse the repository at this point in the history
  • Loading branch information
DC2-DanielKrueger committed Dec 17, 2024
1 parent 71f1300 commit fa64519
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* @author Dominik Obermaier
Expand All @@ -44,6 +45,11 @@
@SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"})
public class HiveMQConfigEntity {

public static final int CURRENT_CONFIG_VERSION = 1;

@XmlElement(name = "config-version", defaultValue = "" + CURRENT_CONFIG_VERSION)
private int version = CURRENT_CONFIG_VERSION;

@XmlElementWrapper(name = "mqtt-listeners", required = true)
@XmlElementRef(required = false)
private @NotNull List<ListenerEntity> mqttListeners = new ArrayList<>();
Expand Down Expand Up @@ -95,11 +101,12 @@ public class HiveMQConfigEntity {
private final @NotNull InternalConfigEntity internal = new InternalConfigEntity();

// no-arg constructor as JaxB does need one
public HiveMQConfigEntity(){
public HiveMQConfigEntity() {

}

public HiveMQConfigEntity(
final @NotNull Integer version,
final @NotNull AdminApiEntity api,
final @NotNull DynamicConfigEntity gateway,
final @NotNull Map<String, Object> moduleConfigs,
Expand All @@ -114,6 +121,7 @@ public HiveMQConfigEntity(
final @NotNull SecurityConfigEntity security,
final @NotNull UnsConfigEntity uns,
final @NotNull UsageTrackingConfigEntity usageTracking) {
this.version = Objects.requireNonNullElse(version, CURRENT_CONFIG_VERSION);
this.api = api;
this.gateway = gateway;
this.moduleConfigs = moduleConfigs;
Expand Down Expand Up @@ -174,9 +182,13 @@ public HiveMQConfigEntity(
return moduleConfigs;
}

public @NotNull UnsConfigEntity getUns() { return uns; }
public @NotNull UnsConfigEntity getUns() {
return uns;
}

public @NotNull DynamicConfigEntity getGatewayConfig() { return gateway;}
public @NotNull DynamicConfigEntity getGatewayConfig() {
return gateway;
}

public @NotNull UsageTrackingConfigEntity getUsageTracking() {
return usageTracking;
Expand All @@ -185,4 +197,8 @@ public HiveMQConfigEntity(
public @NotNull InternalConfigEntity getInternal() {
return internal;
}

public int getVersion() {
return version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import java.util.List;
import java.util.Map;

import static com.hivemq.configuration.entity.HiveMQConfigEntity.CURRENT_CONFIG_VERSION;

/**
* @author Dominik Obermaier
* @author Lukas brandl
Expand Down Expand Up @@ -165,7 +167,8 @@ public class LegacyHiveMQConfigEntity {

final @NotNull HiveMQConfigEntity to(
final @NotNull List<ProtocolAdapterEntity> adapterEntities) {
return new HiveMQConfigEntity(this.getApiConfig(),
return new HiveMQConfigEntity(CURRENT_CONFIG_VERSION,
this.getApiConfig(),
this.getGatewayConfig(),
this.getModuleConfigs(),
this.getMqttConfig(),
Expand Down

0 comments on commit fa64519

Please sign in to comment.