From 4ea2cc360184ee3ec2ce4b25739cac246f748dfc Mon Sep 17 00:00:00 2001 From: NuttyShrimp Date: Mon, 25 Mar 2024 23:35:05 +0100 Subject: [PATCH 1/3] feat: introduce lombok to models --- build.gradle | 7 ++ .../java/telraam/database/models/Baton.java | 33 ++----- .../database/models/BatonSwitchover.java | 49 ++--------- .../telraam/database/models/Detection.java | 88 ++----------------- .../java/telraam/database/models/Lap.java | 48 ++-------- .../telraam/database/models/LapSource.java | 25 ++---- .../database/models/LapSourceSwitchover.java | 33 ++----- .../java/telraam/database/models/Station.java | 62 ++----------- .../java/telraam/database/models/Team.java | 32 ++----- .../telraam/database/models/TeamLapCount.java | 30 ++----- .../telraam/logic/simple/SimpleLapper.java | 2 +- 11 files changed, 57 insertions(+), 352 deletions(-) diff --git a/build.gradle b/build.gradle index d1a3b42..db65596 100644 --- a/build.gradle +++ b/build.gradle @@ -74,6 +74,13 @@ dependencies { // Swagger-UI implementation 'com.smoketurner:dropwizard-swagger:2.0.0-1' + + // Getter & Setter via annotations + compileOnly 'org.projectlombok:lombok:1.18.32' + annotationProcessor 'org.projectlombok:lombok:1.18.32' + + testCompileOnly 'org.projectlombok:lombok:1.18.32' + testAnnotationProcessor 'org.projectlombok:lombok:1.18.32' } test { diff --git a/src/main/java/telraam/database/models/Baton.java b/src/main/java/telraam/database/models/Baton.java index 525b95b..f5889c0 100644 --- a/src/main/java/telraam/database/models/Baton.java +++ b/src/main/java/telraam/database/models/Baton.java @@ -1,16 +1,17 @@ package telraam.database.models; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + import java.util.Objects; +@Getter @Setter @NoArgsConstructor public class Baton { private Integer id; private String name; private String mac; - // DO NOT REMOVE - public Baton() { - } - public Baton(String name) { this.name = name; } @@ -20,30 +21,6 @@ public Baton(String name, String mac) { this.mac = mac; } - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getMac() { - return mac; - } - - public void setMac(String mac) { - this.mac = mac; - } - @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/telraam/database/models/BatonSwitchover.java b/src/main/java/telraam/database/models/BatonSwitchover.java index 358446e..d888870 100644 --- a/src/main/java/telraam/database/models/BatonSwitchover.java +++ b/src/main/java/telraam/database/models/BatonSwitchover.java @@ -1,8 +1,13 @@ package telraam.database.models; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + import java.sql.Timestamp; import java.util.Objects; +@Getter @Setter @NoArgsConstructor public class BatonSwitchover { private Integer id; private Integer teamId; @@ -10,10 +15,6 @@ public class BatonSwitchover { private Integer newBatonId; private Timestamp timestamp; - // DO NOT REMOVE - public BatonSwitchover() { - } - public BatonSwitchover(Integer teamId, Integer previousBatonId, Integer newBatonId, Timestamp timestamp) { this.teamId = teamId; this.previousBatonId = previousBatonId; @@ -21,46 +22,6 @@ public BatonSwitchover(Integer teamId, Integer previousBatonId, Integer newBaton this.timestamp = timestamp; } - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Integer getTeamId() { - return teamId; - } - - public void setTeamId(Integer teamId) { - this.teamId = teamId; - } - - public Integer getPreviousBatonId() { - return previousBatonId; - } - - public void setPreviousBatonId(Integer previousBatonId) { - this.previousBatonId = previousBatonId; - } - - public Integer getNewBatonId() { - return newBatonId; - } - - public void setNewBatonId(Integer newBatonId) { - this.newBatonId = newBatonId; - } - - public Timestamp getTimestamp() { - return timestamp; - } - - public void setTimestamp(Timestamp timestamp) { - this.timestamp = timestamp; - } - @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/telraam/database/models/Detection.java b/src/main/java/telraam/database/models/Detection.java index 6a7c916..23a4067 100644 --- a/src/main/java/telraam/database/models/Detection.java +++ b/src/main/java/telraam/database/models/Detection.java @@ -1,7 +1,12 @@ package telraam.database.models; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + import java.sql.Timestamp; +@Setter @Getter @NoArgsConstructor public class Detection { private Integer id; private Integer batonId; @@ -14,9 +19,6 @@ public class Detection { private Timestamp timestampIngestion; private Integer teamId; - public Detection() { - } - public Detection(Integer batonId, Integer stationId, Integer rssi, Float battery, Long uptimeMs, Integer remoteId, Timestamp timestamp, Timestamp timestampIngestion) { this.batonId = batonId; this.stationId = stationId; @@ -27,84 +29,4 @@ public Detection(Integer batonId, Integer stationId, Integer rssi, Float battery this.timestamp = timestamp; this.timestampIngestion = timestampIngestion; } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Integer getBatonId() { - return batonId; - } - - public void setBatonId(Integer batonId) { - this.batonId = batonId; - } - - public Integer getStationId() { - return stationId; - } - - public void setStationId(Integer stationId) { - this.stationId = stationId; - } - - public Integer getRssi() { - return rssi; - } - - public void setRssi(Integer rssi) { - this.rssi = rssi; - } - - public Float getBattery() { - return battery; - } - - public void setBattery(Float battery) { - this.battery = battery; - } - - public Long getUptimeMs() { - return uptimeMs; - } - - public void setUptimeMs(Long uptimeMs) { - this.uptimeMs = uptimeMs; - } - - public Integer getRemoteId() { - return remoteId; - } - - public void setRemoteId(Integer remoteId) { - this.remoteId = remoteId; - } - - public Timestamp getTimestamp() { - return timestamp; - } - - public void setTimestamp(Timestamp timestamp) { - this.timestamp = timestamp; - } - - public Timestamp getTimestampIngestion() { - return timestampIngestion; - } - - public void setTimestampIngestion(Timestamp timestampIngestion) { - this.timestampIngestion = timestampIngestion; - } - - public Integer getTeamId() { - return teamId; - } - - public void setTeamId(Integer teamId) { - this.teamId = teamId; - } } diff --git a/src/main/java/telraam/database/models/Lap.java b/src/main/java/telraam/database/models/Lap.java index f084c9c..7573562 100644 --- a/src/main/java/telraam/database/models/Lap.java +++ b/src/main/java/telraam/database/models/Lap.java @@ -1,7 +1,12 @@ package telraam.database.models; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + import java.sql.Timestamp; +@Getter @Setter @NoArgsConstructor public class Lap { private Integer id; private Integer teamId; @@ -10,52 +15,9 @@ public class Lap { private Boolean manual; private Timestamp timestamp; - public Lap() { - } - public Lap(Integer teamId, Integer lapSourceId, Timestamp timestamp) { this.teamId = teamId; this.lapSourceId = lapSourceId; this.timestamp = timestamp; } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Integer getTeamId() { - return teamId; - } - - public void setTeamId(Integer teamId) { - this.teamId = teamId; - } - - public Integer getLapSourceId() { - return lapSourceId; - } - - public void setLapSourceId(Integer lapSourceId) { - this.lapSourceId = lapSourceId; - } - - public Boolean getManual() { - return manual; - } - - public void setManual(Boolean manual) { - this.manual = manual; - } - - public Timestamp getTimestamp() { - return timestamp; - } - - public void setTimestamp(Timestamp timestamp) { - this.timestamp = timestamp; - } } diff --git a/src/main/java/telraam/database/models/LapSource.java b/src/main/java/telraam/database/models/LapSource.java index 82ff02f..aa39fa3 100644 --- a/src/main/java/telraam/database/models/LapSource.java +++ b/src/main/java/telraam/database/models/LapSource.java @@ -1,33 +1,18 @@ package telraam.database.models; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + /** * The lap source tells you where the lap comes from. */ +@Getter @Setter @NoArgsConstructor public class LapSource { private Integer id; private String name; - public LapSource() { - - } - public LapSource(String name) { this.name = name; } - - public Integer getId() { - return id; - } - - public String getName() { - return name; - } - - public void setId(Integer id) { - this.id = id; - } - - public void setName(String name) { - this.name = name; - } } diff --git a/src/main/java/telraam/database/models/LapSourceSwitchover.java b/src/main/java/telraam/database/models/LapSourceSwitchover.java index ceef17d..4b3a445 100644 --- a/src/main/java/telraam/database/models/LapSourceSwitchover.java +++ b/src/main/java/telraam/database/models/LapSourceSwitchover.java @@ -1,46 +1,23 @@ package telraam.database.models; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + import java.sql.Timestamp; import java.util.Objects; +@Getter @Setter @NoArgsConstructor public class LapSourceSwitchover { private Integer id; private Integer newLapSource; private Timestamp timestamp; - // DO NOT REMOVE - public LapSourceSwitchover() { - } - public LapSourceSwitchover(Integer newLapSource, Timestamp timestamp) { this.newLapSource = newLapSource; this.timestamp = timestamp; } - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Integer getNewLapSource() { - return newLapSource; - } - - public void setNewLapSource(Integer newLapSource) { - this.newLapSource = newLapSource; - } - - public Timestamp getTimestamp() { - return timestamp; - } - - public void setTimestamp(Timestamp timestamp) { - this.timestamp = timestamp; - } - @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/telraam/database/models/Station.java b/src/main/java/telraam/database/models/Station.java index b84d338..fa55451 100644 --- a/src/main/java/telraam/database/models/Station.java +++ b/src/main/java/telraam/database/models/Station.java @@ -1,5 +1,9 @@ package telraam.database.models; +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter public class Station { private Integer id; private String name; @@ -31,61 +35,11 @@ public Station(String name, boolean isBroken) { this.isBroken = isBroken; } - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Double getDistanceFromStart() { - return distanceFromStart; - } - - public void setDistanceFromStart(Double distanceFromStart) { - this.distanceFromStart = distanceFromStart; - } - - public Boolean getIsBroken() { - return isBroken; - } - - public void setBroken(Boolean isBroken) { + // These are overridden, otherwise the updateDoesUpdate test fails for some reason? + public void setIsBroken(boolean isBroken) { this.isBroken = isBroken; } - - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } - - public Double getCoordX() { - return this.coordX; - } - - ; - - public void setCoordX(Double coordX) { - this.coordX = coordX; - } - - public Double getCoordY() { - return this.coordY; - } - - public void setCoordY(Double coordY) { - this.coordY = coordY; + public void setBroken(boolean isBroken) { + this.isBroken = isBroken; } } diff --git a/src/main/java/telraam/database/models/Team.java b/src/main/java/telraam/database/models/Team.java index 3ed784e..94db208 100644 --- a/src/main/java/telraam/database/models/Team.java +++ b/src/main/java/telraam/database/models/Team.java @@ -1,13 +1,15 @@ package telraam.database.models; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter @Setter @NoArgsConstructor public class Team { private Integer id; private String name; private Integer batonId; - public Team() { - } - public Team(String name) { this.name = name; } @@ -16,28 +18,4 @@ public Team(String name, int batonId) { this.name = name; this.batonId = batonId; } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Integer getBatonId() { - return batonId; - } - - public void setBatonId(Integer batonId) { - this.batonId = batonId; - } } diff --git a/src/main/java/telraam/database/models/TeamLapCount.java b/src/main/java/telraam/database/models/TeamLapCount.java index d7d3015..797c659 100644 --- a/src/main/java/telraam/database/models/TeamLapCount.java +++ b/src/main/java/telraam/database/models/TeamLapCount.java @@ -1,30 +1,12 @@ package telraam.database.models; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter @Setter @NoArgsConstructor @AllArgsConstructor public class TeamLapCount { private Integer lapSourceId; private Integer lapCount; - - public TeamLapCount() { - } - - public TeamLapCount(Integer lapTeamId, Integer lapCount) { - this.lapSourceId = lapTeamId; - this.lapCount = lapCount; - } - - public Integer getLapSourceId() { - return lapSourceId; - } - - public void setLapSourceId(Integer lapSourceId) { - this.lapSourceId = lapSourceId; - } - - public Integer getLapCount() { - return lapCount; - } - - public void setLapCount(Integer lapCount) { - this.lapCount = lapCount; - } } diff --git a/src/main/java/telraam/logic/simple/SimpleLapper.java b/src/main/java/telraam/logic/simple/SimpleLapper.java index 15c1265..9b26f9b 100644 --- a/src/main/java/telraam/logic/simple/SimpleLapper.java +++ b/src/main/java/telraam/logic/simple/SimpleLapper.java @@ -14,7 +14,7 @@ public class SimpleLapper implements Lapper { // Needs to be the same as in the lap_source database table. - static final String SOURCE_NAME = "simple-lapper"; + public static final String SOURCE_NAME = "simple-lapper"; private static final int MAX_SPEED = 50; private final LapSource source; From ab84635f81021f3f60191ffde894da3369652743 Mon Sep 17 00:00:00 2001 From: FKD13 <44001949+FKD13@users.noreply.github.com> Date: Wed, 27 Mar 2024 17:26:30 +0100 Subject: [PATCH 2/3] fix test with Station.setBroken -> Station.setIsBroken --- src/main/java/telraam/database/models/Station.java | 8 -------- src/test/java/telraam/database/daos/StationDAOTest.java | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main/java/telraam/database/models/Station.java b/src/main/java/telraam/database/models/Station.java index fa55451..888a21e 100644 --- a/src/main/java/telraam/database/models/Station.java +++ b/src/main/java/telraam/database/models/Station.java @@ -34,12 +34,4 @@ public Station(String name, boolean isBroken) { this.name = name; this.isBroken = isBroken; } - - // These are overridden, otherwise the updateDoesUpdate test fails for some reason? - public void setIsBroken(boolean isBroken) { - this.isBroken = isBroken; - } - public void setBroken(boolean isBroken) { - this.isBroken = isBroken; - } } diff --git a/src/test/java/telraam/database/daos/StationDAOTest.java b/src/test/java/telraam/database/daos/StationDAOTest.java index 64dceca..64b5c6f 100644 --- a/src/test/java/telraam/database/daos/StationDAOTest.java +++ b/src/test/java/telraam/database/daos/StationDAOTest.java @@ -83,7 +83,7 @@ void testUpdateDoesUpdate() { testStation.setId(testid); testStation.setName("postUpdate"); testStation.setDistanceFromStart(2d); - testStation.setBroken(true); + testStation.setIsBroken(true); testStation.setUrl("localhost:8001"); int updatedRows = stationDAO.update(testid, testStation); assertEquals(1, updatedRows); From 5878e2a65095206a023f71ee101124bd9c44ca74 Mon Sep 17 00:00:00 2001 From: FKD13 <44001949+FKD13@users.noreply.github.com> Date: Thu, 28 Mar 2024 00:35:21 +0100 Subject: [PATCH 3/3] feat: fix test locally --- src/main/java/telraam/database/daos/StationDAO.java | 4 ++-- src/main/java/telraam/database/models/Station.java | 11 ++++++----- .../java/telraam/database/daos/StationDAOTest.java | 8 +++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/telraam/database/daos/StationDAO.java b/src/main/java/telraam/database/daos/StationDAO.java index cd73051..983eecf 100644 --- a/src/main/java/telraam/database/daos/StationDAO.java +++ b/src/main/java/telraam/database/daos/StationDAO.java @@ -19,7 +19,7 @@ public interface StationDAO extends DAO { List getAll(); @Override - @SqlUpdate("INSERT INTO station (name, distance_from_start, broken, url, coord_x, coord_y) VALUES (:name, :distanceFromStart, :isBroken, :url, :coordX, :coordY)") + @SqlUpdate("INSERT INTO station (name, distance_from_start, broken, url, coord_x, coord_y) VALUES (:name, :distanceFromStart, :broken, :url, :coordX, :coordY)") @GetGeneratedKeys({"id"}) int insert(@BindBean Station station); @@ -33,6 +33,6 @@ public interface StationDAO extends DAO { int deleteById(@Bind("id") int id); @Override - @SqlUpdate("UPDATE station SET name = :name, distance_from_start = :distanceFromStart, broken = :isBroken, url = :url, coord_x = :coordX, coord_y = :coordY WHERE id = :id") + @SqlUpdate("UPDATE station SET name = :name, distance_from_start = :distanceFromStart, broken = :broken, url = :url, coord_x = :coordX, coord_y = :coordY WHERE id = :id") int update(@Bind("id") int id, @BindBean Station station); } diff --git a/src/main/java/telraam/database/models/Station.java b/src/main/java/telraam/database/models/Station.java index 888a21e..442e412 100644 --- a/src/main/java/telraam/database/models/Station.java +++ b/src/main/java/telraam/database/models/Station.java @@ -8,30 +8,31 @@ public class Station { private Integer id; private String name; private Double distanceFromStart; - private Boolean isBroken; + @Getter @Setter + private Boolean broken; private String url; private Double coordX; private Double coordY; public Station() { - this.isBroken = false; + this.broken = false; } public Station(String name, String url) { this.name = name; - this.isBroken = false; + this.broken = false; this.url = url; } public Station(String name, Double distanceFromStart, String url) { this.name = name; - this.isBroken = false; + this.broken = false; this.distanceFromStart = distanceFromStart; this.url = url; } public Station(String name, boolean isBroken) { this.name = name; - this.isBroken = isBroken; + this.broken = isBroken; } } diff --git a/src/test/java/telraam/database/daos/StationDAOTest.java b/src/test/java/telraam/database/daos/StationDAOTest.java index 64b5c6f..2bd64bc 100644 --- a/src/test/java/telraam/database/daos/StationDAOTest.java +++ b/src/test/java/telraam/database/daos/StationDAOTest.java @@ -34,7 +34,7 @@ void createStation() { Station station = stationOptional.get(); assertEquals("teststation", station.getName()); assertEquals(1d, station.getDistanceFromStart()); - assertEquals(false, station.getIsBroken()); + assertEquals(false, station.getBroken()); assertEquals("localhost:8000", station.getUrl()); } @@ -83,7 +83,8 @@ void testUpdateDoesUpdate() { testStation.setId(testid); testStation.setName("postUpdate"); testStation.setDistanceFromStart(2d); - testStation.setIsBroken(true); + testStation.setCoordY(0.69); + testStation.setBroken(true); testStation.setUrl("localhost:8001"); int updatedRows = stationDAO.update(testid, testStation); assertEquals(1, updatedRows); @@ -92,7 +93,8 @@ void testUpdateDoesUpdate() { assertFalse(dbStation.isEmpty()); assertEquals("postUpdate", dbStation.get().getName()); assertEquals(2d, dbStation.get().getDistanceFromStart()); - assertEquals(true, dbStation.get().getIsBroken()); + assertEquals(true, dbStation.get().getBroken()); + assertEquals(0.69, dbStation.get().getCoordY()); assertEquals("localhost:8001", dbStation.get().getUrl()); }