From eb6e935892672792238bb5a5096216783d8fb9ab Mon Sep 17 00:00:00 2001 From: tommi27 Date: Mon, 2 Mar 2020 14:44:01 +0100 Subject: [PATCH] all controllers updated with DTOs (needs review) --- .../controller/ButtonDimmerController.java | 4 + .../controller/DimmableLightController.java | 4 + .../controller/KnobDimmerController.java | 4 + .../controller/MotionSensorController.java | 18 ++-- .../controller/RegularLightController.java | 12 ++- .../smarthut/controller/SensorController.java | 18 +++- .../controller/SmartPlugController.java | 12 ++- .../smarthut/controller/SwitchController.java | 12 ++- .../smarthut/dto/ButtonDimmerSaveRequest.java | 51 +++++++++- .../dto/DimmableLightSaveRequest.java | 48 +++++++++ .../smarthut/dto/KnobDimmerSaveRequest.java | 49 ++++++++++ .../smarthut/dto/MotionSensorSaveRequest.java | 63 ++++++++++++ .../smarthut/dto/RegularLightSaveRequest.java | 64 ++++++++++++ .../smarthut/dto/SensorSaveRequest.java | 97 +++++++++++++++++++ .../smarthut/dto/SmartPlugSaveRequest.java | 64 ++++++++++++ .../smarthut/dto/SwitchSaveRequest.java | 64 ++++++++++++ .../smarthut/models/MotionSensor.java | 13 +++ .../sanmarinoes/smarthut/models/Switch.java | 6 +- 18 files changed, 582 insertions(+), 21 deletions(-) create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/MotionSensorSaveRequest.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RegularLightSaveRequest.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SmartPlugSaveRequest.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SwitchSaveRequest.java 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 caeac2a..404d5ac 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,6 +34,10 @@ public class ButtonDimmerController { public ButtonDimmer create(final ButtonDimmerSaveRequest bd) { ButtonDimmer newBD = new ButtonDimmer(); 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 597a899..a7f6d1a 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,6 +35,10 @@ public class DimmableLightController { public DimmableLight create(DimmableLightSaveRequest dl) { DimmableLight newDL = new DimmableLight(); 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 a42af17..a317826 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,6 +35,10 @@ public class KnobDimmerController { public KnobDimmer create(KnobDimmerSaveRequest kd) { KnobDimmer newKD = new KnobDimmer(); 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 15c964f..2aa37de 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 @@ -1,9 +1,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.MotionSensorSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.MotionSensor; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.MotionSensorRepository; import java.util.Optional; -import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.DeleteMapping; @@ -11,7 +11,6 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -33,13 +32,20 @@ public class MotionSensorController { } @PostMapping - public MotionSensor save(@Valid @RequestBody MotionSensor ms) { - return motionSensorService.save(ms); + public MotionSensor create(MotionSensorSaveRequest ms) { + MotionSensor newMS = new MotionSensor(); + newMS.setDetected(ms.isDetected()); + newMS.setId(ms.getId()); + newMS.setName(ms.getName()); + newMS.setRoom(ms.getRoom()); + newMS.setRoomId(ms.getRoomId()); + + return motionSensorService.save(newMS); } @PutMapping - public MotionSensor update(@Valid @RequestBody MotionSensor ms) { - return motionSensorService.save(ms); + public MotionSensor update(MotionSensorSaveRequest ms) { + return this.create(ms); } @DeleteMapping("/{id}") 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 2ec1453..e2a2f49 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 @@ -1,5 +1,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.RegularLightSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RegularLight; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RegularLightRepository; import java.util.Optional; @@ -33,8 +34,15 @@ public class RegularLightController { } @PostMapping - public RegularLight save(@Valid @RequestBody RegularLight rl) { - return regularLightService.save(rl); + public RegularLight save(RegularLightSaveRequest rl) { + RegularLight newRL = new RegularLight(); + newRL.setId(rl.getId()); + newRL.setName(rl.getName()); + newRL.setRoom(rl.getRoom()); + newRL.setRoomId(rl.getRoomId()); + newRL.setOn(rl.isOn()); + + return regularLightService.save(newRL); } @PutMapping 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 957328e..fab5d85 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 @@ -1,8 +1,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SensorSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import java.util.*; -import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.*; import org.springframework.web.bind.annotation.*; @@ -25,13 +25,21 @@ public class SensorController { } @PostMapping - public Sensor save(@Valid @RequestBody Sensor s) { - return sensorRepository.save(s); + public Sensor create(SensorSaveRequest s) { + Sensor newSensor = new Sensor(); + newSensor.setSensor(s.getSensor()); + newSensor.setValue(s.getValue()); + newSensor.setId(s.getId()); + newSensor.setName(s.getName()); + newSensor.setRoom(s.getRoom()); + newSensor.setRoomId(s.getRoomId()); + + return sensorRepository.save(newSensor); } @PutMapping - public Sensor update(@Valid @RequestBody Sensor s) { - return sensorRepository.save(s); + public Sensor update(SensorSaveRequest s) { + return this.create(s); } @DeleteMapping("/{id}") 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 a0aee71..0761532 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 @@ -1,5 +1,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SmartPlugSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import java.util.*; import javax.validation.Valid; @@ -25,8 +26,15 @@ public class SmartPlugController { } @PostMapping - public SmartPlug save(@Valid @RequestBody SmartPlug sp) { - return smartPlugRepository.save(sp); + public SmartPlug create(SmartPlugSaveRequest sp) { + SmartPlug newSP = new SmartPlug(); + newSP.setOn(sp.isOn()); + newSP.setId(sp.getId()); + newSP.setName(sp.getName()); + newSP.setRoom(sp.getRoom()); + newSP.setRoomId(sp.getRoomId()); + + return smartPlugRepository.save(newSP); } @PutMapping 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 7eb83a0..50c2b50 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 @@ -1,5 +1,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SwitchSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import java.util.*; import javax.validation.Valid; @@ -25,8 +26,15 @@ public class SwitchController { } @PostMapping - public Switch save(@Valid @RequestBody Switch s) { - return switchRepository.save(s); + public Switch save(SwitchSaveRequest s) { + Switch newSwitch = new Switch(); + newSwitch.setId(s.getId()); + newSwitch.setName(s.getName()); + newSwitch.setRoom(s.getRoom()); + newSwitch.setRoomId(s.getRoomId()); + newSwitch.setOn(s.isOn()); + + return switchRepository.save(newSwitch); } @PutMapping diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/ButtonDimmerSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/ButtonDimmerSaveRequest.java index f611090..ce49970 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/ButtonDimmerSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/ButtonDimmerSaveRequest.java @@ -1,13 +1,30 @@ 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; +import javax.persistence.*; +import javax.validation.constraints.NotNull; public class ButtonDimmerSaveRequest { @Lob private Set lights = new HashSet(); + /** 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. + */ + @NotNull private Long roomId; + + /** The name of the device as assigned by the user (e.g. 'Master bedroom light') */ + @NotNull private String name; + public Set getLights() { return this.lights; } @@ -15,4 +32,36 @@ public class ButtonDimmerSaveRequest { public void setLights(Set newLights) { this.lights = newLights; } + + public void setId(long id) { + this.id = id; + } + + public void setRoom(Room room) { + this.room = room; + } + + public void setRoomId(Long roomId) { + this.roomId = roomId; + } + + public void setName(String name) { + this.name = name; + } + + public long getId() { + return id; + } + + public Room getRoom() { + return room; + } + + public Long getRoomId() { + return roomId; + } + + public String getName() { + return name; + } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/DimmableLightSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/DimmableLightSaveRequest.java index 1d3a8e2..43b5a97 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/DimmableLightSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/DimmableLightSaveRequest.java @@ -1,5 +1,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Room; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; @@ -12,6 +13,53 @@ public class DimmableLightSaveRequest { @Max(100) private Integer intensity = 0; + /** 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. + */ + @NotNull private Long roomId; + + /** The name of the device as assigned by the user (e.g. 'Master bedroom light') */ + @NotNull private String name; + + public void setId(long id) { + this.id = id; + } + + public void setRoom(Room room) { + this.room = room; + } + + public void setRoomId(Long roomId) { + this.roomId = roomId; + } + + public void setName(String name) { + this.name = name; + } + + public long getId() { + return id; + } + + public Room getRoom() { + return room; + } + + public Long getRoomId() { + return roomId; + } + + public String getName() { + return name; + } + public Integer getIntensity() { return intensity; } 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 c7d5193..530ab90 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,13 +1,62 @@ 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; +import javax.validation.constraints.NotNull; public class KnobDimmerSaveRequest { @Lob private Set lights = new HashSet(); + /** 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. + */ + @NotNull private Long roomId; + + /** The name of the device as assigned by the user (e.g. 'Master bedroom light') */ + @NotNull private String name; + + public void setId(long id) { + this.id = id; + } + + public void setRoom(Room room) { + this.room = room; + } + + public void setRoomId(Long roomId) { + this.roomId = roomId; + } + + public void setName(String name) { + this.name = name; + } + + public long getId() { + return id; + } + + public Room getRoom() { + return room; + } + + public Long getRoomId() { + return roomId; + } + + public String getName() { + return name; + } + public void setLights(Set lights) { this.lights = lights; } 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 new file mode 100644 index 0000000..9fa3c7e --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/MotionSensorSaveRequest.java @@ -0,0 +1,63 @@ +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 { + private boolean detected; + + /** 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. + */ + @NotNull private Long roomId; + + /** The name of the device as assigned by the user (e.g. 'Master bedroom light') */ + @NotNull private String name; + + public void setId(long id) { + this.id = id; + } + + public void setRoom(Room room) { + this.room = room; + } + + public void setRoomId(Long roomId) { + this.roomId = roomId; + } + + public void setName(String name) { + this.name = name; + } + + public long getId() { + return id; + } + + public Room getRoom() { + return room; + } + + public Long getRoomId() { + return roomId; + } + + public String getName() { + return name; + } + + public boolean isDetected() { + return detected; + } + + public void setDetected(boolean detected) { + this.detected = detected; + } +} 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 new file mode 100644 index 0000000..fb7fc78 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RegularLightSaveRequest.java @@ -0,0 +1,64 @@ +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 { + /** The state of this switch */ + private boolean on; + + /** 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. + */ + @NotNull private Long roomId; + + /** The name of the device as assigned by the user (e.g. 'Master bedroom light') */ + @NotNull private String name; + + public void setId(long id) { + this.id = id; + } + + public void setRoom(Room room) { + this.room = room; + } + + public void setRoomId(Long roomId) { + this.roomId = roomId; + } + + public void setName(String name) { + this.name = name; + } + + public long getId() { + return id; + } + + public Room getRoom() { + return room; + } + + public Long getRoomId() { + return roomId; + } + + public String getName() { + return name; + } + + public boolean isOn() { + return on; + } + + public void setOn(boolean on) { + this.on = on; + } +} 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 new file mode 100644 index 0000000..cbc29b0 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java @@ -0,0 +1,97 @@ +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; +import javax.persistence.Enumerated; +import javax.validation.constraints.NotNull; + +public class SensorSaveRequest { + + /** Type of sensor, i.e. of the thing the sensor measures. */ + public enum SensorType { + /** A sensor that measures temperature in degrees celsius */ + @SerializedName("TEMPERATURE") + TEMPERATURE, + + /** A sensor that measures relative humidity in percentage points */ + @SerializedName("HUMIDITY") + HUMIDITY, + + /** A sensor that measures light in degrees */ + @SerializedName("LIGHT") + LIGHT + } + + /** The value of this sensor according to its sensor type */ + private int value; + + /** The type of this sensor */ + @NotNull + @Enumerated(value = EnumType.STRING) + private Sensor.SensorType sensor; + + /** 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. + */ + @NotNull private Long roomId; + + /** The name of the device as assigned by the user (e.g. 'Master bedroom light') */ + @NotNull private String name; + + public void setId(long id) { + this.id = id; + } + + public void setRoom(Room room) { + this.room = room; + } + + public void setRoomId(Long roomId) { + this.roomId = roomId; + } + + public void setName(String name) { + this.name = name; + } + + public long getId() { + return id; + } + + public Room getRoom() { + return room; + } + + public Long getRoomId() { + return roomId; + } + + public String getName() { + return name; + } + + public Sensor.SensorType getSensor() { + return sensor; + } + + public void setSensor(Sensor.SensorType sensor) { + this.sensor = sensor; + } + + public int getValue() { + return this.value; + } + + public void setValue(int newValue) { + this.value = newValue; + } +} 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 new file mode 100644 index 0000000..3dbb72b --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SmartPlugSaveRequest.java @@ -0,0 +1,64 @@ +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 { + /** Whether the smart plug is on */ + @NotNull private boolean on; + + /** 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. + */ + @NotNull private Long roomId; + + /** The name of the device as assigned by the user (e.g. 'Master bedroom light') */ + @NotNull private String name; + + public void setId(long id) { + this.id = id; + } + + public void setRoom(Room room) { + this.room = room; + } + + public void setRoomId(Long roomId) { + this.roomId = roomId; + } + + public void setName(String name) { + this.name = name; + } + + public long getId() { + return id; + } + + public Room getRoom() { + return room; + } + + public Long getRoomId() { + return roomId; + } + + public String getName() { + return name; + } + + public boolean isOn() { + return on; + } + + public void setOn(boolean on) { + this.on = on; + } +} 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 new file mode 100644 index 0000000..ff365fc --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SwitchSaveRequest.java @@ -0,0 +1,64 @@ +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 { + /** The state of this switch */ + private boolean on; + + /** 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. + */ + @NotNull private Long roomId; + + /** The name of the device as assigned by the user (e.g. 'Master bedroom light') */ + @NotNull private String name; + + public void setId(long id) { + this.id = id; + } + + public void setRoom(Room room) { + this.room = room; + } + + public void setRoomId(Long roomId) { + this.roomId = roomId; + } + + public void setName(String name) { + this.name = name; + } + + public long getId() { + return id; + } + + public Room getRoom() { + return room; + } + + public Long getRoomId() { + return roomId; + } + + public String getName() { + return name; + } + + public boolean isOn() { + return on; + } + + public void setOn(boolean on) { + this.on = on; + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java index d1c47b3..50d2206 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java @@ -1,10 +1,23 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; +import javax.persistence.Column; import javax.persistence.Entity; /** Represents a motion sensor device */ @Entity public class MotionSensor extends InputDevice { + + @Column(nullable = false) + private boolean detected; + + public boolean isDetected() { + return detected; + } + + public void setDetected(boolean detected) { + this.detected = detected; + } + public MotionSensor() { super("motion-sensor"); } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java index 6f0eb99..2576d38 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java @@ -3,7 +3,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Column; import javax.persistence.Entity; -/** A switch input device TODO: define switch behaviour (push button vs on/off state) */ +/** A switch input device */ @Entity public class Switch extends InputDevice { @@ -20,7 +20,7 @@ public class Switch extends InputDevice { * * @param state The state to be set */ - void setState(boolean state) { + public void setOn(boolean state) { on = state; } @@ -29,7 +29,7 @@ public class Switch extends InputDevice { * * @return This Switch on state */ - boolean getState() { + public boolean isOn() { return on; } }