Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply even more lombok #129

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions src/main/java/telraam/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration;
import jakarta.servlet.DispatcherType;
import jakarta.servlet.FilterRegistration;
import lombok.Getter;
import lombok.Setter;
import org.eclipse.jetty.servlets.CrossOriginFilter;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
import org.jdbi.v3.core.Jdbi;
Expand All @@ -33,10 +35,18 @@
import java.util.logging.Logger;

public class App extends Application<AppConfiguration> {
private static Logger logger = Logger.getLogger(App.class.getName());
private static final Logger logger = Logger.getLogger(App.class.getName());

@Getter
private AppConfiguration config;

@Getter
private Environment environment;

@Getter
private Jdbi database;

@Setter
private boolean testing;

public static void main(String[] args) throws Exception {
Expand All @@ -49,10 +59,6 @@ public App() {
testing = true;
}

public void setTesting(boolean testing) {
this.testing = testing;
}

@Override
public String getName() {
return "hello-world";
Expand All @@ -72,7 +78,7 @@ protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(AppConfigurat
}

@Override
public void run(AppConfiguration configuration, Environment environment) throws IOException {
public void run(AppConfiguration configuration, Environment environment) {
this.config = configuration;
this.environment = environment;
// Add database
Expand Down Expand Up @@ -122,9 +128,6 @@ public void run(AppConfiguration configuration, Environment environment) throws
// Set up lapper algorithms
Set<Lapper> lappers = new HashSet<>();

// Old viterbi lapper is disabled
//lappers.add(new ViterbiLapper(this.database));

lappers.add(new ExternalLapper(this.database));
lappers.add(new RobustLapper(this.database));

Expand All @@ -147,16 +150,4 @@ public void run(AppConfiguration configuration, Environment environment) throws

logger.info("Up and running!");
}

public AppConfiguration getConfig() {
return config;
}

public Environment getEnvironment() {
return environment;
}

public Jdbi getDatabase() {
return database;
}
}
46 changes: 9 additions & 37 deletions src/main/java/telraam/AppConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,25 @@
import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import telraam.api.responses.Template;

public class AppConfiguration extends Configuration {
@NotNull
@Getter @Setter
private String template;

@NotNull
@Getter @Setter
private String defaultName = "Stranger";

@JsonProperty("swagger")
public SwaggerBundleConfiguration swaggerBundleConfiguration;

@Valid
@NotNull
private DataSourceFactory database = new DataSourceFactory();

@JsonProperty
public String getTemplate() {
return template;
}

@JsonProperty
public void setTemplate(String template) {
this.template = template;
}

public Template buildTemplate() {
return new Template(template, defaultName);
}

@JsonProperty
public String getDefaultName() {
return defaultName;
}

@JsonProperty
public void setDefaultName(String name) {
this.defaultName = name;
}

@JsonProperty("database")
public DataSourceFactory getDataSourceFactory() {
return database;
}

@Getter @Setter
@JsonProperty("database")
public void setDataSourceFactory(DataSourceFactory factory) {
this.database = factory;
}

@JsonProperty("swagger")
public SwaggerBundleConfiguration swaggerBundleConfiguration;
private DataSourceFactory dataSourceFactory = new DataSourceFactory();
}
26 changes: 6 additions & 20 deletions src/main/java/telraam/api/responses/Saying.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
package telraam.api.responses;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Saying {
private long id;

@Length(max = 3)
private String content;

public Saying() {
// Jackson deserialization
}

public Saying(long id, String content) {
this.id = id;
this.content = content;
}

@JsonProperty
public long getId() {
return id;
}

@JsonProperty
public String getContent() {
return content;
}
}
8 changes: 3 additions & 5 deletions src/main/java/telraam/api/responses/Template.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package telraam.api.responses;

import lombok.AllArgsConstructor;

import java.util.Optional;

import static java.lang.String.format;

@AllArgsConstructor
public class Template {
private final String content;
private final String defaultName;

public Template(String content, String defaultName) {
this.content = content;
this.defaultName = defaultName;
}

public String render(Optional<String> name) {
return format(content, name.orElse(defaultName));
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/telraam/monitoring/BatonDetectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import java.util.Map;

public class BatonDetectionManager {
private DetectionDAO detectionDAO;
private TeamDAO teamDAO;
private BatonSwitchoverDAO batonSwitchoverDAO;
private final DetectionDAO detectionDAO;
private final TeamDAO teamDAO;
private final BatonSwitchoverDAO batonSwitchoverDAO;

// Map of a baton id to it's detections
private Map<Integer, List<BatonDetection>> batonDetectionMap = new HashMap<>();
private final Map<Integer, List<BatonDetection>> batonDetectionMap = new HashMap<>();
private Integer handledDetectionId = 0;

public BatonDetectionManager(DetectionDAO detectionDAO, TeamDAO teamDAO, BatonSwitchoverDAO batonSwitchoverDAO) {
Expand Down Expand Up @@ -60,7 +60,7 @@ public Map<Integer, List<BatonDetection>> getBatonDetections() {
}
var batonDetections = batonDetectionMap.get(batonId);
var team = teamMap.get(batonTeamMap.get(batonId));
var batonDetection = new BatonDetection(Math.toIntExact(d.getTimestamp().getTime() / 1000), d.getRssi(), d.getStationId(), batonId, team.getName());
var batonDetection = new BatonDetection(Math.toIntExact(d.getTimestamp().getTime() / 1000), d.getRssi(), batonId /* FIXME: BatonDetection expects a teamId here? */, d.getStationId(), team.getName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to make an issue ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I have: #130

batonDetections.add(batonDetection);
});
return batonDetectionMap;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/telraam/monitoring/BatonStatusHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

public class BatonStatusHolder {
// Map from batonMac to batonStatus
private HashMap<String, BatonStatus> batonStatusMap = new HashMap<>();
private HashMap<Integer, String> batonIdToMac = new HashMap<>();
private final HashMap<String, BatonStatus> batonStatusMap = new HashMap<>();
private final HashMap<Integer, String> batonIdToMac = new HashMap<>();

private BatonDAO batonDAO;
private DetectionDAO detectionDAO;
private final BatonDAO batonDAO;
private final DetectionDAO detectionDAO;

public BatonStatusHolder(BatonDAO BDAO, DetectionDAO DDAO) {
batonDAO = BDAO;
detectionDAO = DDAO;
public BatonStatusHolder(BatonDAO batonDAO, DetectionDAO detectionDAO) {
this.batonDAO = batonDAO;
this.detectionDAO = detectionDAO;
}

private BatonStatus getStatusForBaton(String batonMac) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/telraam/monitoring/StationDetectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import java.util.Optional;

public class StationDetectionManager {
private DetectionDAO detectionDAO;
private final DetectionDAO detectionDAO;

private StationDAO stationDAO;
private final StationDAO stationDAO;

public StationDetectionManager(DetectionDAO detectionDAO, StationDAO stationDAO) {
this.detectionDAO = detectionDAO;
Expand All @@ -27,7 +27,7 @@ public Map<String, Long> timeSinceLastDetectionPerStation() {
Optional<Detection> maybeDetection = this.detectionDAO.latestDetectionByStationId(stationId);
Optional<Station> maybeStation = this.stationDAO.getById(stationId);
if (maybeDetection.isPresent() && maybeStation.isPresent()) {
Long time = maybeDetection.get().getTimestamp().getTime();
long time = maybeDetection.get().getTimestamp().getTime();
stationIdToTimeSinceLatestDetection.put(maybeStation.get().getName(), (System.currentTimeMillis() - time) / 1000);
}
}
Expand Down
54 changes: 6 additions & 48 deletions src/main/java/telraam/monitoring/models/BatonDetection.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package telraam.monitoring.models;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
@AllArgsConstructor
public class BatonDetection {
@JsonProperty("detected_time")
private Integer detectionTime;
Expand All @@ -13,52 +19,4 @@ public class BatonDetection {
private Integer stationId;
@JsonProperty("team_name")
private String teamName;

public BatonDetection(Integer detectionTime, Integer rssi, Integer stationId, Integer teamId, String teamName) {
this.detectionTime = detectionTime;
this.rssi = rssi;
this.stationId = stationId;
this.teamId = teamId;
this.teamName = teamName;
}

public Integer getDetectionTime() {
return detectionTime;
}

public void setDetectionTime(Integer detectionTime) {
this.detectionTime = detectionTime;
}

public Integer getRssi() {
return rssi;
}

public void setRssi(Integer rssi) {
this.rssi = rssi;
}

public Integer getTeamId() {
return teamId;
}

public void setTeamId(Integer teamId) {
this.teamId = teamId;
}

public Integer getStationId() {
return stationId;
}

public void setStationId(Integer stationId) {
this.stationId = stationId;
}

public String getTeamName() {
return teamName;
}

public void setTeamName(String teamName) {
this.teamName = teamName;
}
}
Loading
Loading