Merge branch 'device-unification' into 'dev'

Device unification

See merge request sa4-2020/the-sanmarinoes/backend!17
This commit is contained in:
Claudio Maggioni 2020-03-02 22:05:05 +01:00
commit eede89b7be
32 changed files with 123 additions and 176 deletions

View file

@ -50,6 +50,16 @@ public class SpringFoxConfig {
return List.of(new ApiKey("Bearer", "Authorization", "header"));
}
/**
* Return a Java functional API predicate for regex matches
*
* @param regex the regex to match on
* @return a Java functional API predicate
*/
private Predicate<String> regexPredicate(final String regex) {
return regex(regex)::apply;
}
/**
* Configures the paths the documentation must be generated for. Add a path here only when the
* spec has been totally defined.
@ -57,7 +67,9 @@ public class SpringFoxConfig {
* @return A predicate that tests whether a path must be included or not
*/
private Predicate<String> paths() {
return ((Predicate<String>) regex("/auth.*")::apply).or(regex("/register.*")::apply);
return regexPredicate("/auth.*")
.or(regexPredicate("/room.*"))
.or(regexPredicate("/register.*"));
}
/**

View file

@ -1,8 +1,11 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.ButtonDimmerSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ButtonDimmer;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ButtonDimmerRepository;
import java.util.List;
import java.util.Optional;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
@ -16,8 +19,8 @@ public class ButtonDimmerController {
@Autowired private ButtonDimmerRepository buttonDimmerService;
@GetMapping
public Iterable<ButtonDimmer> findAll() {
return buttonDimmerService.findAll();
public List<ButtonDimmer> findAll() {
return toList(buttonDimmerService.findAll());
}
@GetMapping("/{id}")
@ -31,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);

View file

@ -1,8 +1,11 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.DimmableLightSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLight;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLightRepository;
import java.util.List;
import java.util.Optional;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,8 +20,8 @@ public class DimmableLightController {
@Autowired private DimmableLightRepository dimmableLightService;
@GetMapping
public Iterable<DimmableLight> findAll() {
return dimmableLightService.findAll();
public List<DimmableLight> findAll() {
return toList(dimmableLightService.findAll());
}
@GetMapping("/{id}")
@ -32,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);

View file

@ -1,8 +1,11 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.KnobDimmerSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmer;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmerRepository;
import java.util.List;
import java.util.Optional;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,8 +20,8 @@ public class KnobDimmerController {
@Autowired private KnobDimmerRepository knobDimmerService;
@GetMapping
public Iterable<KnobDimmer> findAll() {
return knobDimmerService.findAll();
public List<KnobDimmer> findAll() {
return toList(knobDimmerService.findAll());
}
@GetMapping("/{id}")
@ -32,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);

View file

@ -1,8 +1,11 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList;
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.List;
import java.util.Optional;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,8 +20,8 @@ public class MotionSensorController {
@Autowired private MotionSensorRepository motionSensorService;
@GetMapping
public Iterable<MotionSensor> findAll() {
return motionSensorService.findAll();
public List<MotionSensor> findAll() {
return toList(motionSensorService.findAll());
}
@GetMapping("/{id}")
@ -32,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);

View file

@ -1,8 +1,11 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList;
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.List;
import java.util.Optional;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
@ -24,8 +27,8 @@ public class RegularLightController {
@Autowired private RegularLightRepository regularLightService;
@GetMapping
public Iterable<RegularLight> findAll() {
return regularLightService.findAll();
public List<RegularLight> findAll() {
return toList(regularLightService.findAll());
}
@GetMapping("/{id}")
@ -38,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());

View file

@ -1,5 +1,7 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.RoomSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.security.Principal;
@ -19,13 +21,15 @@ public class RoomController {
@Autowired private UserRepository userRepository;
@Autowired private DeviceRepository<Device> deviceRepository;
@GetMapping
public Iterable<Room> findAll() {
return roomRepository.findAll();
public List<Room> findAll() {
return toList(roomRepository.findAll());
}
@GetMapping("/{id}")
public Optional<Room> findById(@PathVariable("id") long id) {
public @ResponseBody Optional<Room> findById(@PathVariable("id") long id) {
return roomRepository.findById(id);
}
@ -38,7 +42,6 @@ public class RoomController {
final String icon = r.getIcon();
newRoom.setUserId(userId);
newRoom.setUser(null);
if (img != null) {
newRoom.setImage(img.getBytes());
} else if (setWhenNull) {
@ -54,12 +57,14 @@ public class RoomController {
}
@PostMapping
public Room create(@Valid @RequestBody RoomSaveRequest r, final Principal principal) {
public @ResponseBody Room create(
@Valid @RequestBody RoomSaveRequest r, final Principal principal) {
return this.save(r, principal, true);
}
@PutMapping
public Room update(@Valid @RequestBody RoomSaveRequest r, final Principal principal) {
public @ResponseBody Room update(
@Valid @RequestBody RoomSaveRequest r, final Principal principal) {
return this.save(r, principal, false);
}
@ -67,4 +72,13 @@ public class RoomController {
public void deleteById(@PathVariable("id") long id) {
roomRepository.deleteById(id);
}
/**
* Returns a List<Device> of all Devices that are present in a given room (identified by its
* id).
*/
@GetMapping(path = "/{roomId}/devices")
public @ResponseBody List<? extends Device> getDevices(@PathVariable("roomId") long roomid) {
return deviceRepository.findByRoomId(roomid);
}
}

View file

@ -1,8 +1,11 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SensorSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.util.*;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.*;
@ -16,8 +19,8 @@ public class SensorController {
@Autowired private SensorRepository sensorRepository;
@GetMapping
public Iterable<Sensor> findAll() {
return sensorRepository.findAll();
public List<Sensor> findAll() {
return toList(sensorRepository.findAll());
}
@GetMapping("/{id}")
@ -32,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);

View file

@ -1,8 +1,11 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SmartPlugSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.util.*;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.*;
@ -16,8 +19,8 @@ public class SmartPlugController {
@Autowired private SmartPlugRepository smartPlugRepository;
@GetMapping
public Iterable<SmartPlug> findAll() {
return smartPlugRepository.findAll();
public List<SmartPlug> findAll() {
return toList(smartPlugRepository.findAll());
}
@GetMapping("/{id}")
@ -31,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);

View file

@ -1,8 +1,11 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SwitchSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.util.*;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.*;
@ -16,8 +19,8 @@ public class SwitchController {
@Autowired private SwitchRepository switchRepository;
@GetMapping
public Iterable<Switch> findAll() {
return switchRepository.findAll();
public List<Switch> findAll() {
return toList(switchRepository.findAll());
}
@GetMapping("/{id}")
@ -30,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());

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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<DimmableLight> lights;
/** Increases the current intensity level of the dimmable light by 1 */
public void increaseIntensity() {
for (DimmableLight dl : lights) {

View file

@ -1,5 +1,3 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository;
public interface ButtonDimmerRepository extends CrudRepository<ButtonDimmer, Long> {}
public interface ButtonDimmerRepository extends DeviceRepository<ButtonDimmer> {}

View file

@ -26,12 +26,6 @@ public abstract class Device {
@ApiModelProperty(hidden = true)
private long id;
/** The room this device belongs in */
@ManyToOne
@JoinColumn(name = "room_id", nullable = false, updatable = false, insertable = false)
@ApiModelProperty(hidden = true)
private Room room;
/**
* The room this device belongs in, as a foreign key id. To use when updating and inserting from
* a REST call.
@ -69,14 +63,6 @@ public abstract class Device {
this.id = id;
}
public Room getRoom() {
return room;
}
public void setRoom(Room room) {
this.room = room;
}
public String getName() {
return name;
}

View file

@ -0,0 +1,13 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
/**
* DeviceRepository acts as a superclass for the other repositories so to mirror in the database the
* class inheritance present among the various devices.
*/
public interface DeviceRepository<T extends Device> extends CrudRepository<T, Long> {
List<T> findByRoomId(@Param("roomId") long roomId);
}

View file

@ -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)

View file

@ -1,5 +1,3 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository;
public interface DimmableLightRepository extends CrudRepository<DimmableLight, Long> {}
public interface DimmableLightRepository extends DeviceRepository<DimmableLight> {}

View file

@ -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<DimmableLight> 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

View file

@ -1,5 +1,3 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository;
public interface KnobDimmerRepository extends CrudRepository<KnobDimmer, Long> {}
public interface KnobDimmerRepository extends DeviceRepository<KnobDimmer> {}

View file

@ -1,5 +1,3 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository;
public interface MotionSensorRepository extends CrudRepository<MotionSensor, Long> {}
public interface MotionSensorRepository extends DeviceRepository<MotionSensor> {}

View file

@ -1,5 +1,3 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository;
public interface RegularLightRepository extends CrudRepository<RegularLight, Long> {}
public interface RegularLightRepository extends DeviceRepository<RegularLight> {}

View file

@ -1,7 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import io.swagger.annotations.ApiModelProperty;
import java.util.Set;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
@ -42,17 +41,6 @@ public class Room {
@Column(nullable = false)
private String name;
/** Collection of devices present in this room */
@ApiModelProperty(hidden = true)
@OneToMany(mappedBy = "room")
private Set<Device> devices;
/** User that owns the house this room is in */
@ManyToOne
@JoinColumn(name = "user_id", nullable = false, updatable = false, insertable = false)
@ApiModelProperty(hidden = true)
private User user;
public Long getId() {
return id;
}
@ -69,14 +57,6 @@ public class Room {
this.userId = userId;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getName() {
return name;
}
@ -85,10 +65,6 @@ public class Room {
this.name = name;
}
public Set<Device> getDevices() {
return devices;
}
public byte[] getIcon() {
return icon;
}
@ -107,6 +83,6 @@ public class Room {
@Override
public String toString() {
return "Room{" + "id=" + id + ", user=" + user + ", name='" + name + "\'}";
return "Room{" + "id=" + id + ", name='" + name + "\'}";
}
}

View file

@ -1,5 +1,3 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository;
public interface SensorRepository extends CrudRepository<Sensor, Long> {}
public interface SensorRepository extends DeviceRepository<Sensor> {}

View file

@ -1,5 +1,3 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository;
public interface SmartPlugRepository extends CrudRepository<SmartPlug, Long> {}
public interface SmartPlugRepository extends DeviceRepository<SmartPlug> {}

View file

@ -1,5 +1,3 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository;
public interface SwitchRepository extends CrudRepository<Switch, Long> {}
public interface SwitchRepository extends DeviceRepository<Switch> {}

View file

@ -1,7 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import io.swagger.annotations.ApiModelProperty;
import java.util.Set;
import javax.persistence.*;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
@ -52,11 +51,6 @@ public class User {
@Pattern(regexp = ".+@.+\\..+", message = "Please provide a valid email address")
private String email;
/** All rooms in the user's house */
@OneToMany(mappedBy = "user")
@ApiModelProperty(hidden = true)
private Set<Room> rooms;
@Column(nullable = false)
@ApiModelProperty(hidden = true)
private Boolean isEnabled = false;
@ -101,10 +95,6 @@ public class User {
this.password = password;
}
public Set<Room> getRooms() {
return rooms;
}
public Boolean getEnabled() {
return isEnabled;
}

View file

@ -0,0 +1,14 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.utils;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
/** A class with a bunch of useful static methods */
public class Utils {
private Utils() {}
public static <T> List<T> toList(Iterable<T> iterable) {
return StreamSupport.stream(iterable.spliterator(), false).collect(Collectors.toList());
}
}