Skip to content

Commit

Permalink
Add time zone to configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
bertrik committed Jan 26, 2024
1 parent cbaa9e9 commit fe28566
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
2 changes: 2 additions & 0 deletions configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
ndw:
host: "https://opendata.ndw.nu/"
timeout: 30
traffic:
timeZone: "Europe/Amsterdam"
logging: !<default>
level: "INFO"
loggers: {}
Expand Down
2 changes: 2 additions & 0 deletions docker/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
ndw:
host: "https://opendata.ndw.nu/"
timeout: 30
traffic:
timeZone: "Europe/Amsterdam"
logging: !<default>
level: "INFO"
loggers: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void initialize(Bootstrap<VerkeersDrukteAppConfig> bootstrap) {
@Override
public void run(VerkeersDrukteAppConfig configuration, Environment environment) {
TrafficHandler ndwHandler = new TrafficHandler(configuration.getNdwConfig());
VerkeersDrukteResource resource = new VerkeersDrukteResource(ndwHandler);
VerkeersDrukteResource resource = new VerkeersDrukteResource(ndwHandler, configuration.getTrafficConfig());
environment.healthChecks().register("ndw", new VerkeersDrukteHealthCheck(ndwHandler));
environment.jersey().register(resource);
environment.lifecycle().manage(ndwHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.core.Configuration;
import nl.bertriksikken.verkeersdrukte.ndw.NdwConfig;
import nl.bertriksikken.verkeersdrukte.traffic.TrafficConfig;

@JsonIgnoreProperties(ignoreUnknown = true)
final class VerkeersDrukteAppConfig extends Configuration {

@JsonProperty("ndw")
public final NdwConfig ndwConfig = new NdwConfig();
private final NdwConfig ndwConfig = new NdwConfig();
@JsonProperty("traffic")
private TrafficConfig trafficConfig;

public NdwConfig getNdwConfig() {
return ndwConfig;
}

public TrafficConfig getTrafficConfig() {
return trafficConfig;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import jakarta.ws.rs.sse.SseEventSink;
import nl.bertriksikken.verkeersdrukte.traffic.AggregateMeasurement;
import nl.bertriksikken.verkeersdrukte.traffic.ITrafficHandler;
import nl.bertriksikken.verkeersdrukte.traffic.TrafficConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -43,10 +44,10 @@ public final class VerkeersDrukteResource {

private final ZoneId zoneId;

VerkeersDrukteResource(ITrafficHandler handler) {
VerkeersDrukteResource(ITrafficHandler handler, TrafficConfig config) {
this.handler = handler;
mapper.findAndRegisterModules();
zoneId = ZoneId.of("Europe/Amsterdam");
zoneId = config.getTimeZone();
}

@GET
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package nl.bertriksikken.verkeersdrukte.traffic;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.time.ZoneId;
import java.util.TimeZone;

@JsonAutoDetect(getterVisibility = JsonAutoDetect.Visibility.NONE)
public final class TrafficConfig {

@JsonProperty("timeZone")
private String timeZone = "Europe/Amsterdam";

public ZoneId getTimeZone() {
return ZoneId.of(timeZone);
}
}

0 comments on commit fe28566

Please sign in to comment.