From eecee30841f7dc5e1457f0233b973cb8ae704222 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Mon, 2 Mar 2020 21:59:49 +0100 Subject: [PATCH] Redoing all @tommi27 work on model since git merge is now sentient and trying to delete stuff from our project --- .../smarthut/controller/ButtonDimmerController.java | 1 - .../smarthut/controller/DimmableLightController.java | 1 - .../smarthut/controller/KnobDimmerController.java | 1 - .../smarthut/controller/MotionSensorController.java | 1 - .../smarthut/controller/RegularLightController.java | 1 - .../smarthut/controller/SensorController.java | 1 - .../smarthut/controller/SmartPlugController.java | 1 - .../smarthut/controller/SwitchController.java | 1 - .../smarthut/dto/KnobDimmerSaveRequest.java | 12 ------------ .../smarthut/dto/MotionSensorSaveRequest.java | 12 ------------ .../smarthut/dto/RegularLightSaveRequest.java | 12 ------------ .../sanmarinoes/smarthut/dto/SensorSaveRequest.java | 12 ------------ .../smarthut/dto/SmartPlugSaveRequest.java | 12 ------------ .../sanmarinoes/smarthut/dto/SwitchSaveRequest.java | 12 ------------ .../sanmarinoes/smarthut/models/ButtonDimmer.java | 6 ++++++ .../sanmarinoes/smarthut/models/DimmableLight.java | 3 +++ .../sa4/sanmarinoes/smarthut/models/KnobDimmer.java | 5 +++++ 17 files changed, 14 insertions(+), 80 deletions(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java index 34e536b..aa8cfa4 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java @@ -34,7 +34,6 @@ public class ButtonDimmerController { newBD.setLights(bd.getLights()); newBD.setId(bd.getId()); newBD.setName(bd.getName()); - newBD.setRoom(bd.getRoom()); newBD.setRoomId(bd.getRoomId()); return buttonDimmerService.save(newBD); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java index 9ab5f29..b02a519 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java @@ -35,7 +35,6 @@ public class DimmableLightController { newDL.setIntensity(dl.getIntensity()); newDL.setId(dl.getId()); newDL.setName(dl.getName()); - newDL.setRoom(dl.getRoom()); newDL.setRoomId(dl.getRoomId()); return dimmableLightService.save(newDL); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java index 49c889b..bd02d02 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java @@ -35,7 +35,6 @@ public class KnobDimmerController { newKD.setLights(kd.getLights()); newKD.setId(kd.getId()); newKD.setName(kd.getName()); - newKD.setRoom(kd.getRoom()); newKD.setRoomId(kd.getRoomId()); return knobDimmerService.save(newKD); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java index d4bfb2a..4f9fc27 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java @@ -35,7 +35,6 @@ public class MotionSensorController { newMS.setDetected(ms.isDetected()); newMS.setId(ms.getId()); newMS.setName(ms.getName()); - newMS.setRoom(ms.getRoom()); newMS.setRoomId(ms.getRoomId()); return motionSensorService.save(newMS); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java index de00240..bc86686 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java @@ -41,7 +41,6 @@ public class RegularLightController { RegularLight newRL = new RegularLight(); newRL.setId(rl.getId()); newRL.setName(rl.getName()); - newRL.setRoom(rl.getRoom()); newRL.setRoomId(rl.getRoomId()); newRL.setOn(rl.isOn()); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java index fd4437b..3c16272 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java @@ -35,7 +35,6 @@ public class SensorController { newSensor.setValue(s.getValue()); newSensor.setId(s.getId()); newSensor.setName(s.getName()); - newSensor.setRoom(s.getRoom()); newSensor.setRoomId(s.getRoomId()); return sensorRepository.save(newSensor); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java index c50ddc3..9a45b32 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java @@ -34,7 +34,6 @@ public class SmartPlugController { newSP.setOn(sp.isOn()); newSP.setId(sp.getId()); newSP.setName(sp.getName()); - newSP.setRoom(sp.getRoom()); newSP.setRoomId(sp.getRoomId()); return smartPlugRepository.save(newSP); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java index 5207710..e7d9eef 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java @@ -33,7 +33,6 @@ public class SwitchController { Switch newSwitch = new Switch(); newSwitch.setId(s.getId()); newSwitch.setName(s.getName()); - newSwitch.setRoom(s.getRoom()); newSwitch.setRoomId(s.getRoomId()); newSwitch.setOn(s.isOn()); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/KnobDimmerSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/KnobDimmerSaveRequest.java index 530ab90..bfc3ba8 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/KnobDimmerSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/KnobDimmerSaveRequest.java @@ -1,7 +1,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLight; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Room; import java.util.HashSet; import java.util.Set; import javax.persistence.Lob; @@ -13,9 +12,6 @@ public class KnobDimmerSaveRequest { /** Device identifier */ private long id; - /** The room this device belongs in */ - private Room room; - /** * The room this device belongs in, as a foreign key id. To use when updating and inserting from * a REST call. @@ -29,10 +25,6 @@ public class KnobDimmerSaveRequest { this.id = id; } - public void setRoom(Room room) { - this.room = room; - } - public void setRoomId(Long roomId) { this.roomId = roomId; } @@ -45,10 +37,6 @@ public class KnobDimmerSaveRequest { return id; } - public Room getRoom() { - return room; - } - public Long getRoomId() { return roomId; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/MotionSensorSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/MotionSensorSaveRequest.java index 9fa3c7e..50976b6 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/MotionSensorSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/MotionSensorSaveRequest.java @@ -1,6 +1,5 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Room; import javax.validation.constraints.NotNull; public class MotionSensorSaveRequest { @@ -9,9 +8,6 @@ public class MotionSensorSaveRequest { /** Device identifier */ private long id; - /** The room this device belongs in */ - private Room room; - /** * The room this device belongs in, as a foreign key id. To use when updating and inserting from * a REST call. @@ -25,10 +21,6 @@ public class MotionSensorSaveRequest { this.id = id; } - public void setRoom(Room room) { - this.room = room; - } - public void setRoomId(Long roomId) { this.roomId = roomId; } @@ -41,10 +33,6 @@ public class MotionSensorSaveRequest { return id; } - public Room getRoom() { - return room; - } - public Long getRoomId() { return roomId; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RegularLightSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RegularLightSaveRequest.java index fb7fc78..34695e2 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RegularLightSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RegularLightSaveRequest.java @@ -1,6 +1,5 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Room; import javax.validation.constraints.NotNull; public class RegularLightSaveRequest { @@ -10,9 +9,6 @@ public class RegularLightSaveRequest { /** Device identifier */ private long id; - /** The room this device belongs in */ - private Room room; - /** * The room this device belongs in, as a foreign key id. To use when updating and inserting from * a REST call. @@ -26,10 +22,6 @@ public class RegularLightSaveRequest { this.id = id; } - public void setRoom(Room room) { - this.room = room; - } - public void setRoomId(Long roomId) { this.roomId = roomId; } @@ -42,10 +34,6 @@ public class RegularLightSaveRequest { return id; } - public Room getRoom() { - return room; - } - public Long getRoomId() { return roomId; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java index cbc29b0..47ca739 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java @@ -1,6 +1,5 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Room; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor; import com.google.gson.annotations.SerializedName; import javax.persistence.EnumType; @@ -35,9 +34,6 @@ public class SensorSaveRequest { /** Device identifier */ private long id; - /** The room this device belongs in */ - private Room room; - /** * The room this device belongs in, as a foreign key id. To use when updating and inserting from * a REST call. @@ -51,10 +47,6 @@ public class SensorSaveRequest { this.id = id; } - public void setRoom(Room room) { - this.room = room; - } - public void setRoomId(Long roomId) { this.roomId = roomId; } @@ -67,10 +59,6 @@ public class SensorSaveRequest { return id; } - public Room getRoom() { - return room; - } - public Long getRoomId() { return roomId; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SmartPlugSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SmartPlugSaveRequest.java index 3dbb72b..7511341 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SmartPlugSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SmartPlugSaveRequest.java @@ -1,6 +1,5 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Room; import javax.validation.constraints.NotNull; public class SmartPlugSaveRequest { @@ -10,9 +9,6 @@ public class SmartPlugSaveRequest { /** Device identifier */ private long id; - /** The room this device belongs in */ - private Room room; - /** * The room this device belongs in, as a foreign key id. To use when updating and inserting from * a REST call. @@ -26,10 +22,6 @@ public class SmartPlugSaveRequest { this.id = id; } - public void setRoom(Room room) { - this.room = room; - } - public void setRoomId(Long roomId) { this.roomId = roomId; } @@ -42,10 +34,6 @@ public class SmartPlugSaveRequest { return id; } - public Room getRoom() { - return room; - } - public Long getRoomId() { return roomId; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SwitchSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SwitchSaveRequest.java index ff365fc..84142ec 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SwitchSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SwitchSaveRequest.java @@ -1,6 +1,5 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Room; import javax.validation.constraints.NotNull; public class SwitchSaveRequest { @@ -10,9 +9,6 @@ public class SwitchSaveRequest { /** Device identifier */ private long id; - /** The room this device belongs in */ - private Room room; - /** * The room this device belongs in, as a foreign key id. To use when updating and inserting from * a REST call. @@ -26,10 +22,6 @@ public class SwitchSaveRequest { this.id = id; } - public void setRoom(Room room) { - this.room = room; - } - public void setRoomId(Long roomId) { this.roomId = roomId; } @@ -42,10 +34,6 @@ public class SwitchSaveRequest { return id; } - public Room getRoom() { - return room; - } - public Long getRoomId() { return roomId; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java index 9ff5af2..1e5f702 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java @@ -1,6 +1,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import java.util.Set; import javax.persistence.Entity; +import javax.persistence.OneToMany; /** * Represents a dimmer that can only instruct an increase or decrease of intensity (i.e. like a @@ -12,6 +15,9 @@ public class ButtonDimmer extends Dimmer { super("button-dimmer"); } + @OneToMany(mappedBy = "dimmer") + private Set lights; + /** Increases the current intensity level of the dimmable light by 1 */ public void increaseIntensity() { for (DimmableLight dl : lights) { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java index 6a35248..a71afbc 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java @@ -2,6 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.ManyToOne; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; @@ -14,6 +15,8 @@ public class DimmableLight extends Light { super("light"); } + @ManyToOne private Dimmer dimmer; + /** The light intensity value. Goes from 0 (off) to 100 (on) */ @NotNull @Column(nullable = false) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java index d14e099..0a90998 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java @@ -1,6 +1,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; +import java.util.Set; import javax.persistence.Entity; +import javax.persistence.OneToMany; /** * Represents a dimmer able to set absolute intensity values (i.e. knowing the absolute intensity @@ -12,6 +14,9 @@ public class KnobDimmer extends Dimmer { super("knob-dimmer"); } + @OneToMany(mappedBy = "dimmer") + private Set lights; + /** * Increases or decreases the current intensity level by 5, moving between absolute multiples of * 5 between 0 and 100, of all dimmable lights mapped to this knob