made a couple of tests
This commit is contained in:
commit
00452d5295
84 changed files with 692 additions and 1361 deletions
|
@ -4,6 +4,7 @@ plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'jacoco'
|
id 'jacoco'
|
||||||
id "org.sonarqube" version "2.8"
|
id "org.sonarqube" version "2.8"
|
||||||
|
id 'io.freefair.lombok' version '5.0.1'
|
||||||
}
|
}
|
||||||
group = 'ch.usi.inf.sa4.sanmarinoes'
|
group = 'ch.usi.inf.sa4.sanmarinoes'
|
||||||
version = '0.0.1-SNAPSHOT'
|
version = '0.0.1-SNAPSHOT'
|
||||||
|
|
3
lombok.config
Normal file
3
lombok.config
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# This file is generated by the 'io.freefair.lombok' Gradle plugin
|
||||||
|
config.stopBubbling = true
|
||||||
|
lombok.addLombokGeneratedAnnotation = true
|
|
@ -1,6 +1,6 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
||||||
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.BooleanConditionSaveRequest;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.BooleanConditionOrTriggerSaveRequest;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanCondition;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanCondition;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanConditionRepository;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanConditionRepository;
|
||||||
|
@ -29,7 +29,7 @@ public class BooleanConditionController {
|
||||||
return booleanConditionRepository.findAllByAutomationId(automationId);
|
return booleanConditionRepository.findAllByAutomationId(automationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BooleanCondition save(BooleanCondition newRL, BooleanConditionSaveRequest s) {
|
private BooleanCondition save(BooleanCondition newRL, BooleanConditionOrTriggerSaveRequest s) {
|
||||||
newRL.setDeviceId(s.getDeviceId());
|
newRL.setDeviceId(s.getDeviceId());
|
||||||
newRL.setAutomationId(s.getAutomationId());
|
newRL.setAutomationId(s.getAutomationId());
|
||||||
newRL.setOn(s.isOn());
|
newRL.setOn(s.isOn());
|
||||||
|
@ -39,13 +39,13 @@ public class BooleanConditionController {
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public BooleanCondition create(
|
public BooleanCondition create(
|
||||||
@Valid @RequestBody BooleanConditionSaveRequest booleanTriggerSaveRequest) {
|
@Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest) {
|
||||||
return save(new BooleanCondition(), booleanTriggerSaveRequest);
|
return save(new BooleanCondition(), booleanTriggerSaveRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public BooleanCondition update(
|
public BooleanCondition update(
|
||||||
@Valid @RequestBody BooleanConditionSaveRequest booleanTriggerSaveRequest)
|
@Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest)
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
return save(
|
return save(
|
||||||
booleanConditionRepository
|
booleanConditionRepository
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
||||||
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.BooleanTriggerSaveRequest;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.BooleanConditionOrTriggerSaveRequest;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTriggerRepository;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTriggerRepository;
|
||||||
|
@ -29,7 +29,7 @@ public class BooleanTriggerController {
|
||||||
return booleanTriggerRepository.findAllByAutomationId(automationId);
|
return booleanTriggerRepository.findAllByAutomationId(automationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BooleanTrigger save(BooleanTrigger newRL, BooleanTriggerSaveRequest s) {
|
private BooleanTrigger save(BooleanTrigger newRL, BooleanConditionOrTriggerSaveRequest s) {
|
||||||
newRL.setDeviceId(s.getDeviceId());
|
newRL.setDeviceId(s.getDeviceId());
|
||||||
newRL.setAutomationId(s.getAutomationId());
|
newRL.setAutomationId(s.getAutomationId());
|
||||||
newRL.setOn(s.isOn());
|
newRL.setOn(s.isOn());
|
||||||
|
@ -39,13 +39,13 @@ public class BooleanTriggerController {
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public BooleanTrigger create(
|
public BooleanTrigger create(
|
||||||
@Valid @RequestBody BooleanTriggerSaveRequest booleanTriggerSaveRequest) {
|
@Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest) {
|
||||||
return save(new BooleanTrigger(), booleanTriggerSaveRequest);
|
return save(new BooleanTrigger(), booleanTriggerSaveRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public BooleanTrigger update(
|
public BooleanTrigger update(
|
||||||
@Valid @RequestBody BooleanTriggerSaveRequest booleanTriggerSaveRequest)
|
@Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest)
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
return save(
|
return save(
|
||||||
booleanTriggerRepository
|
booleanTriggerRepository
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class CurtainsController {
|
||||||
@Autowired private DeviceService deviceService;
|
@Autowired private DeviceService deviceService;
|
||||||
@Autowired private CurtainsRepository curtainsService;
|
@Autowired private CurtainsRepository curtainsService;
|
||||||
@Autowired private SceneRepository sceneRepository;
|
@Autowired private SceneRepository sceneRepository;
|
||||||
@Autowired private StateRepository<State<?>> stateRepository;
|
@Autowired private StateRepository<State> stateRepository;
|
||||||
|
|
||||||
private Curtains save(Curtains newRL, DimmableSaveRequest s, final Principal principal) {
|
private Curtains save(Curtains newRL, DimmableSaveRequest s, final Principal principal) {
|
||||||
newRL.setName(s.getName());
|
newRL.setName(s.getName());
|
||||||
|
@ -53,7 +53,7 @@ public class CurtainsController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/state")
|
@PostMapping("/{id}/state")
|
||||||
public State<? extends Dimmable> sceneBinding(
|
public State sceneBinding(
|
||||||
@PathVariable("id") long deviceId,
|
@PathVariable("id") long deviceId,
|
||||||
@RequestParam long sceneId,
|
@RequestParam long sceneId,
|
||||||
final Principal principal)
|
final Principal principal)
|
||||||
|
@ -63,7 +63,7 @@ public class CurtainsController {
|
||||||
curtainsService
|
curtainsService
|
||||||
.findByIdAndUsername(deviceId, principal.getName())
|
.findByIdAndUsername(deviceId, principal.getName())
|
||||||
.orElseThrow(NotFoundException::new);
|
.orElseThrow(NotFoundException::new);
|
||||||
State<? extends Dimmable> s = c.cloneState();
|
State s = c.cloneState();
|
||||||
final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new);
|
final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new);
|
||||||
s.setSceneId(sc.getId());
|
s.setSceneId(sc.getId());
|
||||||
if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0)
|
if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0)
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class DimmableLightController extends GuestEnabledController<DimmableLigh
|
||||||
|
|
||||||
private final DimmableLightRepository dimmableLightRepository;
|
private final DimmableLightRepository dimmableLightRepository;
|
||||||
private final SceneRepository sceneRepository;
|
private final SceneRepository sceneRepository;
|
||||||
private final StateRepository<State<?>> stateRepository;
|
private final StateRepository<State> stateRepository;
|
||||||
private final DeviceService deviceService;
|
private final DeviceService deviceService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -26,7 +26,7 @@ public class DimmableLightController extends GuestEnabledController<DimmableLigh
|
||||||
UserRepository userRepository,
|
UserRepository userRepository,
|
||||||
DimmableLightRepository dimmableLightRepository,
|
DimmableLightRepository dimmableLightRepository,
|
||||||
SceneRepository sceneRepository,
|
SceneRepository sceneRepository,
|
||||||
StateRepository<State<?>> stateRepository,
|
StateRepository<State> stateRepository,
|
||||||
DeviceService deviceService) {
|
DeviceService deviceService) {
|
||||||
super(userRepository, dimmableLightRepository);
|
super(userRepository, dimmableLightRepository);
|
||||||
this.dimmableLightRepository = dimmableLightRepository;
|
this.dimmableLightRepository = dimmableLightRepository;
|
||||||
|
@ -87,7 +87,7 @@ public class DimmableLightController extends GuestEnabledController<DimmableLigh
|
||||||
* necessary to specify the query in the mapping
|
* necessary to specify the query in the mapping
|
||||||
*/
|
*/
|
||||||
@PostMapping("/{id}/state")
|
@PostMapping("/{id}/state")
|
||||||
public State<? extends Dimmable> sceneBinding(
|
public State sceneBinding(
|
||||||
@PathVariable("id") long deviceId,
|
@PathVariable("id") long deviceId,
|
||||||
@RequestParam long sceneId,
|
@RequestParam long sceneId,
|
||||||
final Principal principal)
|
final Principal principal)
|
||||||
|
@ -97,7 +97,7 @@ public class DimmableLightController extends GuestEnabledController<DimmableLigh
|
||||||
dimmableLightRepository
|
dimmableLightRepository
|
||||||
.findByIdAndUsername(deviceId, principal.getName())
|
.findByIdAndUsername(deviceId, principal.getName())
|
||||||
.orElseThrow(NotFoundException::new);
|
.orElseThrow(NotFoundException::new);
|
||||||
State<? extends Dimmable> s = d.cloneState();
|
State s = d.cloneState();
|
||||||
final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new);
|
final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new);
|
||||||
s.setSceneId(sc.getId());
|
s.setSceneId(sc.getId());
|
||||||
if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0)
|
if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0)
|
||||||
|
|
|
@ -17,9 +17,9 @@ public class DimmableStateController {
|
||||||
@Autowired private DimmableStateRepository dimmableStateRepository;
|
@Autowired private DimmableStateRepository dimmableStateRepository;
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public DimmableState<?> update(@Valid @RequestBody DimmableStateSaveRequest ss)
|
public DimmableState update(@Valid @RequestBody DimmableStateSaveRequest ss)
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
final DimmableState<?> initial =
|
final DimmableState initial =
|
||||||
dimmableStateRepository.findById(ss.getId()).orElseThrow(NotFoundException::new);
|
dimmableStateRepository.findById(ss.getId()).orElseThrow(NotFoundException::new);
|
||||||
initial.setIntensity(ss.getIntensity());
|
initial.setIntensity(ss.getIntensity());
|
||||||
dimmableStateRepository.save(initial);
|
dimmableStateRepository.save(initial);
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class GuestController {
|
||||||
@PutMapping("/guests")
|
@PutMapping("/guests")
|
||||||
public List<User> setGuests(
|
public List<User> setGuests(
|
||||||
@RequestBody @Valid GuestsUpdateRequest g, final Principal principal) {
|
@RequestBody @Valid GuestsUpdateRequest g, final Principal principal) {
|
||||||
Iterable<User> guests = userRepository.findAllById(g.ids);
|
Iterable<User> guests = userRepository.findAllById(g.getIds());
|
||||||
User host = userRepository.findByUsername(principal.getName());
|
User host = userRepository.findByUsername(principal.getName());
|
||||||
|
|
||||||
for (final User oldGuest : host.getGuests()) {
|
for (final User oldGuest : host.getGuests()) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
||||||
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.RangeConditionSaveRequest;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.RangeConditionOrTriggerSaveRequest;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeConditionRepository;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeConditionRepository;
|
||||||
|
@ -29,7 +29,7 @@ public class RangeConditionController {
|
||||||
return rangeConditionRepository.findAllByAutomationId(automationId);
|
return rangeConditionRepository.findAllByAutomationId(automationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RangeCondition save(RangeCondition newRL, RangeConditionSaveRequest s) {
|
private RangeCondition save(RangeCondition newRL, RangeConditionOrTriggerSaveRequest s) {
|
||||||
newRL.setDeviceId(s.getDeviceId());
|
newRL.setDeviceId(s.getDeviceId());
|
||||||
newRL.setAutomationId(s.getAutomationId());
|
newRL.setAutomationId(s.getAutomationId());
|
||||||
newRL.setOperator(s.getOperator());
|
newRL.setOperator(s.getOperator());
|
||||||
|
@ -40,13 +40,13 @@ public class RangeConditionController {
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public RangeCondition create(
|
public RangeCondition create(
|
||||||
@Valid @RequestBody RangeConditionSaveRequest booleanTriggerSaveRequest) {
|
@Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest) {
|
||||||
return save(new RangeCondition(), booleanTriggerSaveRequest);
|
return save(new RangeCondition(), booleanTriggerSaveRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public RangeCondition update(
|
public RangeCondition update(
|
||||||
@Valid @RequestBody RangeConditionSaveRequest booleanTriggerSaveRequest)
|
@Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest)
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
return save(
|
return save(
|
||||||
rangeConditionRepository
|
rangeConditionRepository
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
||||||
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.RangeTriggerSaveRequest;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.RangeConditionOrTriggerSaveRequest;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTriggerRepository;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTriggerRepository;
|
||||||
|
@ -29,7 +29,7 @@ public class RangeTriggerController {
|
||||||
return rangeTriggerRepository.findAllByAutomationId(automationId);
|
return rangeTriggerRepository.findAllByAutomationId(automationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RangeTrigger save(RangeTrigger newRL, RangeTriggerSaveRequest s) {
|
private RangeTrigger save(RangeTrigger newRL, RangeConditionOrTriggerSaveRequest s) {
|
||||||
newRL.setDeviceId(s.getDeviceId());
|
newRL.setDeviceId(s.getDeviceId());
|
||||||
newRL.setAutomationId(s.getAutomationId());
|
newRL.setAutomationId(s.getAutomationId());
|
||||||
newRL.setOperator(s.getOperator());
|
newRL.setOperator(s.getOperator());
|
||||||
|
@ -40,13 +40,13 @@ public class RangeTriggerController {
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public RangeTrigger create(
|
public RangeTrigger create(
|
||||||
@Valid @RequestBody RangeTriggerSaveRequest booleanTriggerSaveRequest) {
|
@Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest) {
|
||||||
return save(new RangeTrigger(), booleanTriggerSaveRequest);
|
return save(new RangeTrigger(), booleanTriggerSaveRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public RangeTrigger update(
|
public RangeTrigger update(
|
||||||
@Valid @RequestBody RangeTriggerSaveRequest booleanTriggerSaveRequest)
|
@Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest)
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
return save(
|
return save(
|
||||||
rangeTriggerRepository
|
rangeTriggerRepository
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class RegularLightController extends GuestEnabledController<RegularLight>
|
||||||
|
|
||||||
private RegularLightRepository regularLightRepository;
|
private RegularLightRepository regularLightRepository;
|
||||||
private SceneRepository sceneRepository;
|
private SceneRepository sceneRepository;
|
||||||
private StateRepository<State<?>> stateRepository;
|
private StateRepository<State> stateRepository;
|
||||||
private DeviceService deviceService;
|
private DeviceService deviceService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -37,7 +37,7 @@ public class RegularLightController extends GuestEnabledController<RegularLight>
|
||||||
UserRepository userRepository,
|
UserRepository userRepository,
|
||||||
RegularLightRepository regularLightRepository,
|
RegularLightRepository regularLightRepository,
|
||||||
SceneRepository sceneRepository,
|
SceneRepository sceneRepository,
|
||||||
StateRepository<State<?>> stateRepository,
|
StateRepository<State> stateRepository,
|
||||||
DeviceService deviceService) {
|
DeviceService deviceService) {
|
||||||
super(userRepository, regularLightRepository);
|
super(userRepository, regularLightRepository);
|
||||||
this.regularLightRepository = regularLightRepository;
|
this.regularLightRepository = regularLightRepository;
|
||||||
|
@ -98,7 +98,7 @@ public class RegularLightController extends GuestEnabledController<RegularLight>
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/state")
|
@PostMapping("/{id}/state")
|
||||||
public State<? extends Switchable> sceneBinding(
|
public State sceneBinding(
|
||||||
@PathVariable("id") long deviceId,
|
@PathVariable("id") long deviceId,
|
||||||
@RequestParam long sceneId,
|
@RequestParam long sceneId,
|
||||||
final Principal principal)
|
final Principal principal)
|
||||||
|
@ -107,7 +107,7 @@ public class RegularLightController extends GuestEnabledController<RegularLight>
|
||||||
regularLightRepository
|
regularLightRepository
|
||||||
.findByIdAndUsername(deviceId, principal.getName())
|
.findByIdAndUsername(deviceId, principal.getName())
|
||||||
.orElseThrow(NotFoundException::new);
|
.orElseThrow(NotFoundException::new);
|
||||||
State<? extends Switchable> s = d.cloneState();
|
State s = d.cloneState();
|
||||||
final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new);
|
final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new);
|
||||||
s.setSceneId(sc.getId());
|
s.setSceneId(sc.getId());
|
||||||
if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0)
|
if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0)
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class SceneController {
|
||||||
@Autowired private SceneRepository sceneRepository;
|
@Autowired private SceneRepository sceneRepository;
|
||||||
@Autowired private UserRepository userRepository;
|
@Autowired private UserRepository userRepository;
|
||||||
@Autowired private SceneService sceneService;
|
@Autowired private SceneService sceneService;
|
||||||
@Autowired private StateRepository<State<?>> stateRepository;
|
@Autowired private StateRepository<State> stateRepository;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public List<Scene> findAll(
|
public List<Scene> findAll(
|
||||||
|
@ -78,7 +78,7 @@ public class SceneController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/copyFrom/{copyId}")
|
@PostMapping("/{id}/copyFrom/{copyId}")
|
||||||
public @ResponseBody List<State<?>> copy(
|
public @ResponseBody List<State> copy(
|
||||||
@PathVariable("id") long id,
|
@PathVariable("id") long id,
|
||||||
@PathVariable("copyId") long copyId,
|
@PathVariable("copyId") long copyId,
|
||||||
final Principal principal)
|
final Principal principal)
|
||||||
|
@ -126,8 +126,8 @@ public class SceneController {
|
||||||
* id).
|
* id).
|
||||||
*/
|
*/
|
||||||
@GetMapping(path = "/{sceneId}/states")
|
@GetMapping(path = "/{sceneId}/states")
|
||||||
public List<State<?>> getDevices(@PathVariable("sceneId") long sceneId) {
|
public List<State> getStates(@PathVariable("sceneId") long sceneId) {
|
||||||
Iterable<State<?>> states = stateRepository.findBySceneId(sceneId);
|
Iterable<State> states = stateRepository.findBySceneId(sceneId);
|
||||||
return toList(states);
|
return toList(states);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class SecurityCameraController {
|
||||||
private final DeviceService deviceService;
|
private final DeviceService deviceService;
|
||||||
private final SecurityCameraRepository securityCameraService;
|
private final SecurityCameraRepository securityCameraService;
|
||||||
private final SceneRepository sceneRepository;
|
private final SceneRepository sceneRepository;
|
||||||
private final StateRepository<State<?>> stateRepository;
|
private final StateRepository<State> stateRepository;
|
||||||
private final CameraConfigurationService cameraConfigurationService;
|
private final CameraConfigurationService cameraConfigurationService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -34,7 +34,7 @@ public class SecurityCameraController {
|
||||||
DeviceService deviceService,
|
DeviceService deviceService,
|
||||||
SecurityCameraRepository securityCameraService,
|
SecurityCameraRepository securityCameraService,
|
||||||
SceneRepository sceneRepository,
|
SceneRepository sceneRepository,
|
||||||
StateRepository<State<?>> stateRepository,
|
StateRepository<State> stateRepository,
|
||||||
CameraConfigurationService cameraConfigurationService) {
|
CameraConfigurationService cameraConfigurationService) {
|
||||||
this.deviceService = deviceService;
|
this.deviceService = deviceService;
|
||||||
this.securityCameraService = securityCameraService;
|
this.securityCameraService = securityCameraService;
|
||||||
|
@ -80,7 +80,7 @@ public class SecurityCameraController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/state")
|
@PostMapping("/{id}/state")
|
||||||
public State<? extends Switchable> sceneBinding(
|
public State sceneBinding(
|
||||||
@PathVariable("id") long deviceId,
|
@PathVariable("id") long deviceId,
|
||||||
@RequestParam long sceneId,
|
@RequestParam long sceneId,
|
||||||
final Principal principal)
|
final Principal principal)
|
||||||
|
@ -90,7 +90,7 @@ public class SecurityCameraController {
|
||||||
securityCameraService
|
securityCameraService
|
||||||
.findByIdAndUsername(deviceId, principal.getName())
|
.findByIdAndUsername(deviceId, principal.getName())
|
||||||
.orElseThrow(NotFoundException::new);
|
.orElseThrow(NotFoundException::new);
|
||||||
State<? extends Switchable> s = d.cloneState();
|
State s = d.cloneState();
|
||||||
final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new);
|
final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new);
|
||||||
s.setSceneId(sc.getId());
|
s.setSceneId(sc.getId());
|
||||||
if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0)
|
if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0)
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class SmartPlugController {
|
||||||
@Autowired private DeviceService deviceService;
|
@Autowired private DeviceService deviceService;
|
||||||
@Autowired private SmartPlugRepository smartPlugRepository;
|
@Autowired private SmartPlugRepository smartPlugRepository;
|
||||||
@Autowired private SceneRepository sceneRepository;
|
@Autowired private SceneRepository sceneRepository;
|
||||||
@Autowired private StateRepository<State<?>> stateRepository;
|
@Autowired private StateRepository<State> stateRepository;
|
||||||
|
|
||||||
private SmartPlug save(SmartPlug newSP, SwitchableSaveRequest sp, final Principal principal) {
|
private SmartPlug save(SmartPlug newSP, SwitchableSaveRequest sp, final Principal principal) {
|
||||||
newSP.setOn(sp.isOn());
|
newSP.setOn(sp.isOn());
|
||||||
|
@ -67,7 +67,7 @@ public class SmartPlugController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/state")
|
@PostMapping("/{id}/state")
|
||||||
public State<? extends Switchable> sceneBinding(
|
public State sceneBinding(
|
||||||
@PathVariable("id") long deviceId,
|
@PathVariable("id") long deviceId,
|
||||||
@RequestParam long sceneId,
|
@RequestParam long sceneId,
|
||||||
final Principal principal)
|
final Principal principal)
|
||||||
|
@ -77,7 +77,7 @@ public class SmartPlugController {
|
||||||
smartPlugRepository
|
smartPlugRepository
|
||||||
.findByIdAndUsername(deviceId, principal.getName())
|
.findByIdAndUsername(deviceId, principal.getName())
|
||||||
.orElseThrow(NotFoundException::new);
|
.orElseThrow(NotFoundException::new);
|
||||||
State<? extends Switchable> s = d.cloneState();
|
State s = d.cloneState();
|
||||||
final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new);
|
final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new);
|
||||||
s.setSceneId(sc.getId());
|
s.setSceneId(sc.getId());
|
||||||
if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0)
|
if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0)
|
||||||
|
|
|
@ -22,9 +22,9 @@ public class SwitchableStateController {
|
||||||
@Autowired private SwitchableStateRepository switchableStateRepository;
|
@Autowired private SwitchableStateRepository switchableStateRepository;
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public SwitchableState<?> update(@Valid @RequestBody SwitchableStateSaveRequest ss)
|
public SwitchableState update(@Valid @RequestBody SwitchableStateSaveRequest ss)
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
final SwitchableState<?> initial =
|
final SwitchableState initial =
|
||||||
switchableStateRepository.findById(ss.getId()).orElseThrow(NotFoundException::new);
|
switchableStateRepository.findById(ss.getId()).orElseThrow(NotFoundException::new);
|
||||||
initial.setOn(ss.isOn());
|
initial.setOn(ss.isOn());
|
||||||
switchableStateRepository.save(initial);
|
switchableStateRepository.save(initial);
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class ThermostatController {
|
||||||
@Autowired private ThermostatRepository thermostatRepository;
|
@Autowired private ThermostatRepository thermostatRepository;
|
||||||
@Autowired private ThermostatPopulationService thermostatService;
|
@Autowired private ThermostatPopulationService thermostatService;
|
||||||
@Autowired private SceneRepository sceneRepository;
|
@Autowired private SceneRepository sceneRepository;
|
||||||
@Autowired private StateRepository<State<?>> stateRepository;
|
@Autowired private StateRepository<State> stateRepository;
|
||||||
|
|
||||||
private Thermostat save(Thermostat newT, ThermostatSaveRequest t, final Principal principal) {
|
private Thermostat save(Thermostat newT, ThermostatSaveRequest t, final Principal principal) {
|
||||||
newT.setTargetTemperature(t.getTargetTemperature());
|
newT.setTargetTemperature(t.getTargetTemperature());
|
||||||
|
@ -63,7 +63,7 @@ public class ThermostatController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/state")
|
@PostMapping("/{id}/state")
|
||||||
public State<? extends Switchable> sceneBinding(
|
public State sceneBinding(
|
||||||
@PathVariable("id") long deviceId,
|
@PathVariable("id") long deviceId,
|
||||||
@RequestParam long sceneId,
|
@RequestParam long sceneId,
|
||||||
final Principal principal)
|
final Principal principal)
|
||||||
|
@ -73,7 +73,7 @@ public class ThermostatController {
|
||||||
thermostatRepository
|
thermostatRepository
|
||||||
.findByIdAndUsername(deviceId, principal.getName())
|
.findByIdAndUsername(deviceId, principal.getName())
|
||||||
.orElseThrow(NotFoundException::new);
|
.orElseThrow(NotFoundException::new);
|
||||||
State<? extends Switchable> s = d.cloneState();
|
State s = d.cloneState();
|
||||||
final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new);
|
final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new);
|
||||||
s.setSceneId(sc.getId());
|
s.setSceneId(sc.getId());
|
||||||
if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0)
|
if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0)
|
||||||
|
|
|
@ -158,7 +158,7 @@ public class UserAccountController {
|
||||||
final ConfirmationToken token =
|
final ConfirmationToken token =
|
||||||
confirmationTokenRepository.findByConfirmToken(resetRequest.getConfirmationToken());
|
confirmationTokenRepository.findByConfirmToken(resetRequest.getConfirmationToken());
|
||||||
|
|
||||||
if (token == null || !token.getResetPassword()) {
|
if (token == null || !token.isResetPassword()) {
|
||||||
throw new EmailTokenNotFoundException();
|
throw new EmailTokenNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ public class UserAccountController {
|
||||||
final ConfirmationToken token =
|
final ConfirmationToken token =
|
||||||
confirmationTokenRepository.findByConfirmToken(confirmationToken);
|
confirmationTokenRepository.findByConfirmToken(confirmationToken);
|
||||||
|
|
||||||
if (token != null && !token.getResetPassword()) {
|
if (token != null && !token.isResetPassword()) {
|
||||||
token.getUser().setEnabled(true);
|
token.getUser().setEnabled(true);
|
||||||
userRepository.save(token.getUser());
|
userRepository.save(token.getUser());
|
||||||
response.sendRedirect(emailConfig.getRegistrationRedirect());
|
response.sendRedirect(emailConfig.getRegistrationRedirect());
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanCondition;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger;
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Condition;
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition;
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger;
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ScenePriority;
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Thermostat;
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ThermostatCondition;
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Trigger;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class AutomationFastUpdateRequest {
|
public class AutomationFastUpdateRequest {
|
||||||
public abstract static class TriggerDTO {
|
public abstract static class TriggerDTO {
|
||||||
@NotNull public long deviceId;
|
@NotNull public long deviceId;
|
||||||
|
@ -34,7 +28,7 @@ public class AutomationFastUpdateRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RangeTriggerDTO extends TriggerDTO {
|
public static class RangeTriggerDTO extends TriggerDTO {
|
||||||
@NotNull RangeTrigger.Operator operator;
|
@NotNull Operator operator;
|
||||||
@NotNull double range;
|
@NotNull double range;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -83,7 +77,7 @@ public class AutomationFastUpdateRequest {
|
||||||
|
|
||||||
public static class RangeConditionDTO extends ConditionDTO {
|
public static class RangeConditionDTO extends ConditionDTO {
|
||||||
|
|
||||||
@NotNull RangeCondition.Operator operator;
|
@NotNull Operator operator;
|
||||||
@NotNull double range;
|
@NotNull double range;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -117,44 +111,4 @@ public class AutomationFastUpdateRequest {
|
||||||
@NotNull private long id;
|
@NotNull private long id;
|
||||||
|
|
||||||
@NotNull @NotEmpty private String name;
|
@NotNull @NotEmpty private String name;
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ScenePriorityDTO> getScenes() {
|
|
||||||
return scenes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setScenes(List<ScenePriorityDTO> scenes) {
|
|
||||||
this.scenes = scenes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TriggerDTO> getTriggers() {
|
|
||||||
return triggers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTriggers(List<TriggerDTO> triggers) {
|
|
||||||
this.triggers = triggers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ConditionDTO> getConditions() {
|
|
||||||
return conditions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConditions(List<ConditionDTO> conditions) {
|
|
||||||
this.conditions = conditions;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,22 +2,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class AutomationSaveRequest {
|
public class AutomationSaveRequest {
|
||||||
|
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
@NotNull @NotEmpty private String name;
|
@NotNull @NotEmpty private String name;
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BooleanConditionOrTriggerSaveRequest {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
@NotNull private Long deviceId;
|
||||||
|
|
||||||
|
@NotNull private Long automationId;
|
||||||
|
|
||||||
|
private boolean on;
|
||||||
|
}
|
|
@ -1,42 +0,0 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
public class BooleanConditionSaveRequest {
|
|
||||||
|
|
||||||
@NotNull private long id;
|
|
||||||
|
|
||||||
@NotNull private Long deviceId;
|
|
||||||
|
|
||||||
@NotNull private Long automationId;
|
|
||||||
|
|
||||||
@NotNull private boolean on;
|
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getDeviceId() {
|
|
||||||
return deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceId(Long deviceId) {
|
|
||||||
this.deviceId = deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getAutomationId() {
|
|
||||||
return automationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAutomationId(Long automationId) {
|
|
||||||
this.automationId = automationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOn() {
|
|
||||||
return on;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOn(boolean on) {
|
|
||||||
this.on = on;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
public class BooleanTriggerSaveRequest {
|
|
||||||
|
|
||||||
private long id;
|
|
||||||
|
|
||||||
@NotNull private Long deviceId;
|
|
||||||
|
|
||||||
@NotNull private Long automationId;
|
|
||||||
|
|
||||||
private boolean on;
|
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getDeviceId() {
|
|
||||||
return deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceId(Long deviceId) {
|
|
||||||
this.deviceId = deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getAutomationId() {
|
|
||||||
return automationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAutomationId(Long automationId) {
|
|
||||||
this.automationId = automationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOn() {
|
|
||||||
return on;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOn(boolean on) {
|
|
||||||
this.on = on;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +1,10 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/** A 'dim' event from a button dimmer. */
|
/** A 'dim' event from a button dimmer. */
|
||||||
|
@Data
|
||||||
public class ButtonDimmerDimRequest {
|
public class ButtonDimmerDimRequest {
|
||||||
|
|
||||||
/** The device id */
|
/** The device id */
|
||||||
|
@ -15,20 +17,4 @@ public class ButtonDimmerDimRequest {
|
||||||
|
|
||||||
/** Whether the dim is up or down */
|
/** Whether the dim is up or down */
|
||||||
@NotNull private DimType dimType;
|
@NotNull private DimType dimType;
|
||||||
|
|
||||||
public DimType getDimType() {
|
|
||||||
return dimType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDimType(DimType dimType) {
|
|
||||||
this.dimType = dimType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class DeviceSaveRequest {
|
public class DeviceSaveRequest {
|
||||||
/** Device identifier */
|
/** Device identifier */
|
||||||
private long id;
|
private long id;
|
||||||
|
@ -15,28 +17,4 @@ public class DeviceSaveRequest {
|
||||||
|
|
||||||
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
|
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
|
||||||
@NotNull @NotEmpty private String name;
|
@NotNull @NotEmpty private String name;
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getRoomId() {
|
|
||||||
return roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRoomId(Long roomId) {
|
|
||||||
this.roomId = roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
import javax.validation.constraints.Max;
|
import javax.validation.constraints.Max;
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class DimmableSaveRequest {
|
public class DimmableSaveRequest {
|
||||||
|
|
||||||
/** Device id (used only for update requests) */
|
/** Device id (used only for update requests) */
|
||||||
|
@ -23,36 +25,4 @@ public class DimmableSaveRequest {
|
||||||
|
|
||||||
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
|
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
|
||||||
@NotNull private String name;
|
@NotNull private String name;
|
||||||
|
|
||||||
public void setRoomId(Long roomId) {
|
|
||||||
this.roomId = roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getRoomId() {
|
|
||||||
return roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getIntensity() {
|
|
||||||
return intensity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIntensity(Integer intensity) {
|
|
||||||
this.intensity = intensity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
import javax.validation.constraints.Max;
|
import javax.validation.constraints.Max;
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class DimmableStateSaveRequest {
|
public class DimmableStateSaveRequest {
|
||||||
|
|
||||||
/** Device id (used only for update requests) */
|
/** Device id (used only for update requests) */
|
||||||
|
@ -13,16 +15,4 @@ public class DimmableStateSaveRequest {
|
||||||
@Min(0)
|
@Min(0)
|
||||||
@Max(100)
|
@Max(100)
|
||||||
private Integer intensity = 0;
|
private Integer intensity = 0;
|
||||||
|
|
||||||
public Integer getIntensity() {
|
|
||||||
return intensity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIntensity(Integer intensity) {
|
|
||||||
this.intensity = intensity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class GenericDeviceSaveReguest {
|
public class GenericDeviceSaveReguest {
|
||||||
/**
|
/**
|
||||||
* The room this device belongs in, as a foreign key id. To use when updating and inserting from
|
* The room this device belongs in, as a foreign key id. To use when updating and inserting from
|
||||||
|
@ -11,20 +13,4 @@ public class GenericDeviceSaveReguest {
|
||||||
|
|
||||||
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
|
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
|
||||||
@NotNull private String name;
|
@NotNull private String name;
|
||||||
|
|
||||||
public void setRoomId(Long roomId) {
|
|
||||||
this.roomId = roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getRoomId() {
|
|
||||||
return roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class GuestPermissionsRequest {
|
public class GuestPermissionsRequest {
|
||||||
private boolean cameraEnabled;
|
private boolean cameraEnabled;
|
||||||
|
|
||||||
public boolean isCameraEnabled() {
|
|
||||||
return cameraEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCameraEnabled(boolean cameraEnabled) {
|
|
||||||
this.cameraEnabled = cameraEnabled;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class GuestsUpdateRequest {
|
public class GuestsUpdateRequest {
|
||||||
@NotNull public List<Long> ids;
|
@NotNull private List<Long> ids;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
import javax.validation.constraints.Email;
|
import javax.validation.constraints.Email;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.Pattern;
|
import javax.validation.constraints.Pattern;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/** DTO for password reset request */
|
/** DTO for password reset request */
|
||||||
|
@Data
|
||||||
public class InitPasswordResetRequest {
|
public class InitPasswordResetRequest {
|
||||||
/**
|
/**
|
||||||
* The user's email (validated according to criteria used in <code>>input type="email"<>
|
* The user's email (validated according to criteria used in <code>>input type="email"<>
|
||||||
|
@ -14,12 +16,4 @@ public class InitPasswordResetRequest {
|
||||||
@Email(message = "Please provide a valid email address")
|
@Email(message = "Please provide a valid email address")
|
||||||
@Pattern(regexp = ".+@.+\\..+", message = "Please provide a valid email address")
|
@Pattern(regexp = ".+@.+\\..+", message = "Please provide a valid email address")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +1,10 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class JWTRequest {
|
public class JWTRequest {
|
||||||
@NotNull private String usernameOrEmail;
|
@NotNull private String usernameOrEmail;
|
||||||
@NotNull private String password;
|
@NotNull private String password;
|
||||||
|
|
||||||
public String getUsernameOrEmail() {
|
|
||||||
return this.usernameOrEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsernameOrEmail(String usernameOrEmail) {
|
|
||||||
this.usernameOrEmail = usernameOrEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return this.password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "JWTRequest{"
|
|
||||||
+ "usernameOrEmail='"
|
|
||||||
+ usernameOrEmail
|
|
||||||
+ '\''
|
|
||||||
+ ", password='"
|
|
||||||
+ password
|
|
||||||
+ '\''
|
|
||||||
+ '}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
public class JWTResponse {
|
public class JWTResponse {
|
||||||
private final String jwttoken;
|
private final String jwttoken;
|
||||||
|
|
||||||
public JWTResponse(String jwttoken) {
|
|
||||||
this.jwttoken = jwttoken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getToken() {
|
|
||||||
return this.jwttoken;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
import javax.validation.constraints.Max;
|
import javax.validation.constraints.Max;
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class KnobDimmerDimRequest {
|
public class KnobDimmerDimRequest {
|
||||||
|
|
||||||
/** The device id */
|
/** The device id */
|
||||||
|
@ -14,20 +16,4 @@ public class KnobDimmerDimRequest {
|
||||||
@Min(0)
|
@Min(0)
|
||||||
@Max(100)
|
@Max(100)
|
||||||
private Integer intensity;
|
private Integer intensity;
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getIntensity() {
|
|
||||||
return intensity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIntensity(Integer intensity) {
|
|
||||||
this.intensity = intensity;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import javax.validation.constraints.*;
|
import javax.validation.constraints.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/** DTO for password reset request */
|
/** DTO for password reset request */
|
||||||
|
@Data
|
||||||
public class PasswordResetRequest {
|
public class PasswordResetRequest {
|
||||||
|
|
||||||
@NotNull private String confirmationToken;
|
@NotNull private String confirmationToken;
|
||||||
|
@ -15,20 +17,4 @@ public class PasswordResetRequest {
|
||||||
max = 255,
|
max = 255,
|
||||||
message = "Your password should be at least 6 characters long and up to 255 chars long")
|
message = "Your password should be at least 6 characters long and up to 255 chars long")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
public String getConfirmationToken() {
|
|
||||||
return confirmationToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConfirmationToken(String confirmationToken) {
|
|
||||||
this.confirmationToken = confirmationToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Operator;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class RangeConditionOrTriggerSaveRequest {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
@NotNull private Long deviceId;
|
||||||
|
|
||||||
|
@NotNull private Long automationId;
|
||||||
|
|
||||||
|
@NotNull private Operator operator;
|
||||||
|
|
||||||
|
@NotNull private double range;
|
||||||
|
}
|
|
@ -1,54 +0,0 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
|
||||||
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition;
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition.Operator;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
public class RangeConditionSaveRequest {
|
|
||||||
|
|
||||||
@NotNull private long id;
|
|
||||||
|
|
||||||
@NotNull private Long deviceId;
|
|
||||||
|
|
||||||
@NotNull private Long automationId;
|
|
||||||
|
|
||||||
@NotNull private RangeCondition.Operator operator;
|
|
||||||
|
|
||||||
@NotNull private double range;
|
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getDeviceId() {
|
|
||||||
return deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceId(Long deviceId) {
|
|
||||||
this.deviceId = deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getAutomationId() {
|
|
||||||
return automationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAutomationId(Long automationId) {
|
|
||||||
this.automationId = automationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Operator getOperator() {
|
|
||||||
return operator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperator(Operator operator) {
|
|
||||||
this.operator = operator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getRange() {
|
|
||||||
return range;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRange(double range) {
|
|
||||||
this.range = range;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
|
||||||
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
public class RangeTriggerSaveRequest {
|
|
||||||
|
|
||||||
private long id;
|
|
||||||
|
|
||||||
@NotNull private Long deviceId;
|
|
||||||
|
|
||||||
@NotNull private Long automationId;
|
|
||||||
|
|
||||||
@NotNull private RangeTrigger.Operator operator;
|
|
||||||
|
|
||||||
@NotNull private double range;
|
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getDeviceId() {
|
|
||||||
return deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceId(Long deviceId) {
|
|
||||||
this.deviceId = deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getAutomationId() {
|
|
||||||
return automationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAutomationId(Long automationId) {
|
|
||||||
this.automationId = automationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RangeTrigger.Operator getOperator() {
|
|
||||||
return operator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperator(RangeTrigger.Operator operator) {
|
|
||||||
this.operator = operator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getRange() {
|
|
||||||
return range;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRange(Double range) {
|
|
||||||
this.range = range;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,7 +3,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Icon;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Icon;
|
||||||
import javax.persistence.Lob;
|
import javax.persistence.Lob;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class RoomSaveRequest {
|
public class RoomSaveRequest {
|
||||||
|
|
||||||
/** Room identifier */
|
/** Room identifier */
|
||||||
|
@ -21,36 +23,4 @@ public class RoomSaveRequest {
|
||||||
|
|
||||||
/** The user given name of this room (e.g. 'Master bedroom') */
|
/** The user given name of this room (e.g. 'Master bedroom') */
|
||||||
@NotNull private String name;
|
@NotNull private String name;
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Icon getIcon() {
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIcon(Icon icon) {
|
|
||||||
this.icon = icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getImage() {
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImage(String image) {
|
|
||||||
this.image = image;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class ScenePrioritySaveRequest {
|
public class ScenePrioritySaveRequest {
|
||||||
|
|
||||||
@NotNull private Long automationId;
|
@NotNull private Long automationId;
|
||||||
|
@ -11,28 +13,4 @@ public class ScenePrioritySaveRequest {
|
||||||
private Integer priority;
|
private Integer priority;
|
||||||
|
|
||||||
@NotNull private Long sceneId;
|
@NotNull private Long sceneId;
|
||||||
|
|
||||||
public Long getAutomationId() {
|
|
||||||
return automationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAutomationId(Long automationId) {
|
|
||||||
this.automationId = automationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getPriority() {
|
|
||||||
return priority;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPriority(Integer priority) {
|
|
||||||
this.priority = priority;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getSceneId() {
|
|
||||||
return sceneId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSceneId(Long sceneId) {
|
|
||||||
this.sceneId = sceneId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Icon;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Icon;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class SceneSaveRequest {
|
public class SceneSaveRequest {
|
||||||
|
|
||||||
/** Room identifier */
|
/** Room identifier */
|
||||||
|
@ -16,32 +18,4 @@ public class SceneSaveRequest {
|
||||||
|
|
||||||
/** Determines whether a guest can access this scene */
|
/** Determines whether a guest can access this scene */
|
||||||
@Column @NotNull private boolean guestAccessEnabled;
|
@Column @NotNull private boolean guestAccessEnabled;
|
||||||
|
|
||||||
public boolean isGuestAccessEnabled() {
|
|
||||||
return guestAccessEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGuestAccessEnabled(boolean guestAccessEnabled) {
|
|
||||||
this.guestAccessEnabled = guestAccessEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Icon getIcon() {
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIcon(Icon icon) {
|
|
||||||
this.icon = icon;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +1,14 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor;
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import javax.persistence.EnumType;
|
import javax.persistence.EnumType;
|
||||||
import javax.persistence.Enumerated;
|
import javax.persistence.Enumerated;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class SensorSaveRequest {
|
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 type of this sensor */
|
/** The type of this sensor */
|
||||||
@NotNull
|
@NotNull
|
||||||
@Enumerated(value = EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
|
@ -39,36 +24,4 @@ public class SensorSaveRequest {
|
||||||
|
|
||||||
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
|
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
|
||||||
@NotNull private String name;
|
@NotNull private String name;
|
||||||
|
|
||||||
public void setRoomId(Long roomId) {
|
|
||||||
this.roomId = roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 BigDecimal getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(BigDecimal value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/** An on/off/toggle operation on a switch */
|
/** An on/off/toggle operation on a switch */
|
||||||
|
@Data
|
||||||
public class SwitchOperationRequest {
|
public class SwitchOperationRequest {
|
||||||
|
|
||||||
/** The device id */
|
/** The device id */
|
||||||
|
@ -16,20 +18,4 @@ public class SwitchOperationRequest {
|
||||||
|
|
||||||
/** The type of switch operation */
|
/** The type of switch operation */
|
||||||
@NotNull private SwitchOperationRequest.OperationType type;
|
@NotNull private SwitchOperationRequest.OperationType type;
|
||||||
|
|
||||||
public OperationType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(OperationType type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class SwitchableSaveRequest {
|
public class SwitchableSaveRequest {
|
||||||
/** The state of this switch */
|
/** The state of this switch */
|
||||||
private boolean on;
|
private boolean on;
|
||||||
|
@ -17,36 +19,4 @@ public class SwitchableSaveRequest {
|
||||||
|
|
||||||
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
|
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
|
||||||
@NotNull private String name;
|
@NotNull private String name;
|
||||||
|
|
||||||
public void setRoomId(Long roomId) {
|
|
||||||
this.roomId = roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getRoomId() {
|
|
||||||
return roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOn() {
|
|
||||||
return on;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOn(boolean on) {
|
|
||||||
this.on = on;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,13 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class SwitchableStateSaveRequest {
|
public class SwitchableStateSaveRequest {
|
||||||
|
|
||||||
/** Device id (used only for update requests) */
|
/** Device id (used only for update requests) */
|
||||||
@NotNull private Long id;
|
@NotNull private Long id;
|
||||||
|
|
||||||
@NotNull private boolean on;
|
@NotNull private boolean on;
|
||||||
|
|
||||||
public boolean isOn() {
|
|
||||||
return on;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOn(boolean on) {
|
|
||||||
this.on = on;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class ThermostatSaveRequest {
|
public class ThermostatSaveRequest {
|
||||||
|
|
||||||
/** Device identifier */
|
/** Device identifier */
|
||||||
|
@ -24,52 +26,4 @@ public class ThermostatSaveRequest {
|
||||||
|
|
||||||
/** State of this thermostat */
|
/** State of this thermostat */
|
||||||
@NotNull private boolean turnOn;
|
@NotNull private boolean turnOn;
|
||||||
|
|
||||||
public boolean isTurnOn() {
|
|
||||||
return turnOn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTurnOn(boolean turnOn) {
|
|
||||||
this.turnOn = turnOn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isUseExternalSensors() {
|
|
||||||
return useExternalSensors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUseExternalSensors(boolean useExternalSensors) {
|
|
||||||
this.useExternalSensors = useExternalSensors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigDecimal getTargetTemperature() {
|
|
||||||
return this.targetTemperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTargetTemperature(BigDecimal targetTemperature) {
|
|
||||||
this.targetTemperature = targetTemperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRoomId(Long roomId) {
|
|
||||||
this.roomId = roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getRoomId() {
|
|
||||||
return roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import javax.validation.constraints.*;
|
import javax.validation.constraints.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class UserRegistrationRequest {
|
public class UserRegistrationRequest {
|
||||||
|
|
||||||
/** The full name of the user */
|
/** The full name of the user */
|
||||||
|
@ -35,36 +37,4 @@ public class UserRegistrationRequest {
|
||||||
@Email(message = "Please provide a valid email address")
|
@Email(message = "Please provide a valid email address")
|
||||||
@Pattern(regexp = ".+@.+\\..+", message = "Please provide a valid email address")
|
@Pattern(regexp = ".+@.+\\..+", message = "Please provide a valid email address")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String username) {
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class UserResponse {
|
public class UserResponse {
|
||||||
private Long id;
|
private Long id;
|
||||||
private String username;
|
private String username;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private UserResponse() {}
|
|
||||||
|
|
||||||
public static UserResponse fromUser(User u) {
|
public static UserResponse fromUser(User u) {
|
||||||
final UserResponse us = new UserResponse();
|
final UserResponse us = new UserResponse();
|
||||||
us.name = u.getName();
|
us.name = u.getName();
|
||||||
|
@ -16,16 +16,4 @@ public class UserResponse {
|
||||||
us.username = u.getUsername();
|
us.username = u.getUsername();
|
||||||
return us;
|
return us;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
|
||||||
|
|
||||||
import javax.validation.constraints.Email;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import javax.validation.constraints.Pattern;
|
|
||||||
|
|
||||||
public class UserUpdateRequest {
|
|
||||||
/** The full name of the user */
|
|
||||||
@NotEmpty(message = "Please provide a full name")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/** A non-salted password */
|
|
||||||
@NotEmpty(message = "Please provide a password")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The user's email (validated according to criteria used in <code>>input type="email"<>
|
|
||||||
* </code>, technically not RFC 5322 compliant
|
|
||||||
*/
|
|
||||||
@NotEmpty(message = "Please provide an email")
|
|
||||||
@Email(message = "Please provide a valid email address")
|
|
||||||
@Pattern(regexp = ".+@.+\\..+", message = "Please provide a valid email address")
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,8 +6,9 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
public class Automation {
|
public class Automation {
|
||||||
|
|
||||||
|
@ -22,7 +23,6 @@ public class Automation {
|
||||||
@GsonExclude
|
@GsonExclude
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Column(name = "user_id", nullable = false)
|
@Column(name = "user_id", nullable = false)
|
||||||
@GsonExclude
|
@GsonExclude
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
@ -36,49 +36,5 @@ public class Automation {
|
||||||
@OneToMany(mappedBy = "automation", orphanRemoval = true, cascade = CascadeType.REMOVE)
|
@OneToMany(mappedBy = "automation", orphanRemoval = true, cascade = CascadeType.REMOVE)
|
||||||
private Set<Condition<?>> conditions = new HashSet<>();
|
private Set<Condition<?>> conditions = new HashSet<>();
|
||||||
|
|
||||||
@NotNull @NotEmpty private String name;
|
@NotEmpty private String name;
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<ScenePriority> getScenes() {
|
|
||||||
return scenes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Trigger<?>> getTriggers() {
|
|
||||||
return triggers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUser(User user) {
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getUserId() {
|
|
||||||
return userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserId(Long userId) {
|
|
||||||
this.userId = userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Condition<?>> getConditions() {
|
|
||||||
return conditions;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,14 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class BooleanCondition extends Condition<BooleanTriggerable> {
|
public class BooleanCondition extends Condition<BooleanTriggerable> {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
@Column(name = "switchable_on")
|
@Column(name = "switchable_on")
|
||||||
private boolean on;
|
private boolean on;
|
||||||
|
|
||||||
|
@ -13,14 +17,6 @@ public class BooleanCondition extends Condition<BooleanTriggerable> {
|
||||||
super("booleanCondition");
|
super("booleanCondition");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOn() {
|
|
||||||
return on;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOn(boolean on) {
|
|
||||||
this.on = on;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean triggered() {
|
public boolean triggered() {
|
||||||
return this.getDevice().readTriggerState() == isOn();
|
return this.getDevice().readTriggerState() == isOn();
|
||||||
|
|
|
@ -2,29 +2,21 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class BooleanTrigger extends Trigger<BooleanTriggerable> {
|
public class BooleanTrigger extends Trigger<BooleanTriggerable> {
|
||||||
|
|
||||||
@Column(name = "switchable_on")
|
@Column(name = "switchable_on")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
private boolean on;
|
private boolean on;
|
||||||
|
|
||||||
public BooleanTrigger() {
|
public BooleanTrigger() {
|
||||||
super("booleanTrigger");
|
super("booleanTrigger");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOn() {
|
|
||||||
return on;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOn(boolean on) {
|
|
||||||
this.on = on;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean check(boolean on) {
|
|
||||||
return this.on == on;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean triggered() {
|
public boolean triggered() {
|
||||||
return getDevice().readTriggerState() == isOn();
|
return getDevice().readTriggerState() == isOn();
|
||||||
|
|
|
@ -10,7 +10,9 @@ import javax.persistence.Id;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.Transient;
|
import javax.persistence.Transient;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
public abstract class Condition<D> {
|
public abstract class Condition<D> {
|
||||||
|
|
||||||
|
@ -52,42 +54,6 @@ public abstract class Condition<D> {
|
||||||
|
|
||||||
public abstract boolean triggered();
|
public abstract boolean triggered();
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public D getDevice() {
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDevice(D device) {
|
|
||||||
this.device = device;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getDeviceId() {
|
|
||||||
return deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceId(Long deviceId) {
|
|
||||||
this.deviceId = deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Automation getAutomation() {
|
|
||||||
return automation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAutomation(Automation automation) {
|
|
||||||
this.automation = automation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getAutomationId() {
|
|
||||||
return automationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Condition<D> setAutomationId(Long automationId) {
|
public Condition<D> setAutomationId(Long automationId) {
|
||||||
this.automationId = automationId;
|
this.automationId = automationId;
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -12,7 +12,9 @@ import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
public class ConfirmationToken {
|
public class ConfirmationToken {
|
||||||
|
|
||||||
|
@ -40,47 +42,4 @@ public class ConfirmationToken {
|
||||||
confirmToken = UUID.randomUUID().toString();
|
confirmToken = UUID.randomUUID().toString();
|
||||||
resetPassword = false;
|
resetPassword = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Constructor for hibernate reflective stuff things whatever */
|
|
||||||
public ConfirmationToken() {}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConfirmToken() {
|
|
||||||
return confirmToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getCreatedDate() {
|
|
||||||
return (Date) createdDate.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
public User getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConfirmToken(String confirmToken) {
|
|
||||||
this.confirmToken = confirmToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCreatedDate(Date createdDate) {
|
|
||||||
this.createdDate = (Date) createdDate.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUser(User user) {
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getResetPassword() {
|
|
||||||
return resetPassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResetPassword(boolean resetPassword) {
|
|
||||||
this.resetPassword = resetPassword;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,11 @@ import com.google.gson.annotations.SerializedName;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/** Generic abstraction for a smart home device */
|
/** Generic abstraction for a smart home device */
|
||||||
@Entity
|
@Entity
|
||||||
|
@Data
|
||||||
@Inheritance(strategy = InheritanceType.JOINED)
|
@Inheritance(strategy = InheritanceType.JOINED)
|
||||||
public abstract class Device {
|
public abstract class Device {
|
||||||
|
|
||||||
|
@ -65,7 +67,7 @@ public abstract class Device {
|
||||||
@OneToMany(mappedBy = "device", orphanRemoval = true)
|
@OneToMany(mappedBy = "device", orphanRemoval = true)
|
||||||
@GsonExclude
|
@GsonExclude
|
||||||
@SocketGsonExclude
|
@SocketGsonExclude
|
||||||
private Set<State<?>> states;
|
private Set<State> states;
|
||||||
|
|
||||||
@Transient @GsonExclude private Long fromHostId = null;
|
@Transient @GsonExclude private Long fromHostId = null;
|
||||||
|
|
||||||
|
@ -73,88 +75,8 @@ public abstract class Device {
|
||||||
|
|
||||||
@Transient @GsonExclude private boolean deleted = false;
|
@Transient @GsonExclude private boolean deleted = false;
|
||||||
|
|
||||||
public Device(String kind, FlowType flowType) {
|
protected Device(String kind, FlowType flowType) {
|
||||||
this.kind = kind;
|
this.kind = kind;
|
||||||
this.flowType = flowType;
|
this.flowType = flowType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Room getRoom() {
|
|
||||||
return room;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRoom(Room room) {
|
|
||||||
this.room = room;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Trigger<? extends Device>> getTriggers() {
|
|
||||||
return triggers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTriggers(Set<Trigger<? extends Device>> triggers) {
|
|
||||||
this.triggers = triggers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getRoomId() {
|
|
||||||
return roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRoomId(Long roomId) {
|
|
||||||
this.roomId = roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getKind() {
|
|
||||||
return kind;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FlowType getFlowType() {
|
|
||||||
return flowType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<State<?>> getStates() {
|
|
||||||
return states;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStates(Set<State<?>> states) {
|
|
||||||
this.states = states;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getFromHostId() {
|
|
||||||
return fromHostId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFromHostId(Long fromHostId) {
|
|
||||||
this.fromHostId = fromHostId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFromGuest() {
|
|
||||||
return fromGuest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFromGuest(boolean fromGuest) {
|
|
||||||
this.fromGuest = fromGuest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDeleted() {
|
|
||||||
return deleted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeleted(boolean deleted) {
|
|
||||||
this.deleted = deleted;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@ import java.util.Set;
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.Max;
|
import javax.validation.constraints.Max;
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotNull;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||||
|
@ -19,23 +20,22 @@ public class Dimmable extends Switchable implements RangeTriggerable {
|
||||||
@ManyToMany(mappedBy = "dimmables", cascade = CascadeType.DETACH)
|
@ManyToMany(mappedBy = "dimmables", cascade = CascadeType.DETACH)
|
||||||
@GsonExclude
|
@GsonExclude
|
||||||
@SocketGsonExclude
|
@SocketGsonExclude
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
private Set<Dimmer> dimmers;
|
private Set<Dimmer> dimmers;
|
||||||
|
|
||||||
/** The light intensity value. Goes from 0 (off) to 100 (on) */
|
/** The light intensity value. Goes from 0 (off) to 100 (on) */
|
||||||
@NotNull
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@Min(0)
|
@Min(0)
|
||||||
@Max(100)
|
@Max(100)
|
||||||
|
@Getter
|
||||||
private Integer intensity = 0;
|
private Integer intensity = 0;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
private Integer oldIntensity = 100;
|
private Integer oldIntensity = 100;
|
||||||
|
|
||||||
public Integer getIntensity() {
|
|
||||||
return intensity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the intensity to a certain level. Out of bound values are corrected to the respective
|
* Sets the intensity to a certain level. Out of bound values are corrected to the respective
|
||||||
* extremums. An intensity level of 0 turns the light off, but keeps the old intensity level
|
* extremums. An intensity level of 0 turns the light off, but keeps the old intensity level
|
||||||
|
@ -65,19 +65,13 @@ public class Dimmable extends Switchable implements RangeTriggerable {
|
||||||
intensity = on ? oldIntensity : 0;
|
intensity = on ? oldIntensity : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Dimmer> getDimmers() {
|
public void readStateAndSet(DimmableState state) {
|
||||||
return this.dimmers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readStateAndSet(DimmableState<? extends Dimmable> state) {
|
|
||||||
setIntensity(state.getIntensity());
|
setIntensity(state.getIntensity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public State cloneState() {
|
||||||
public State<? extends Dimmable> cloneState() {
|
final DimmableState newState = new DimmableState();
|
||||||
final DimmableState<Dimmable> newState = new DimmableState<>();
|
|
||||||
newState.setDeviceId(getId());
|
newState.setDeviceId(getId());
|
||||||
newState.setDevice(this);
|
|
||||||
newState.setIntensity(getIntensity());
|
newState.setIntensity(getIntensity());
|
||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,32 +3,32 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.validation.constraints.Max;
|
import javax.validation.constraints.Max;
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
/** Represent a state for an IDimmable device */
|
/** Represent a state for an IDimmable device */
|
||||||
@Entity
|
@Entity
|
||||||
public class DimmableState<T extends Dimmable> extends State<T> {
|
public class DimmableState extends State {
|
||||||
|
|
||||||
|
public void setDevice(Dimmable device) {
|
||||||
|
setInnerDevice(device);
|
||||||
|
}
|
||||||
|
|
||||||
/** The light intensity value. Goes from 0 (off) to 100 (on) */
|
/** The light intensity value. Goes from 0 (off) to 100 (on) */
|
||||||
@Min(0)
|
@Min(0)
|
||||||
@Max(100)
|
@Max(100)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
private int intensity = 0;
|
private int intensity = 0;
|
||||||
|
|
||||||
public int getIntensity() {
|
|
||||||
return intensity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIntensity(int dimAmount) {
|
|
||||||
this.intensity = dimAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
getDevice().readStateAndSet(this);
|
((Dimmable) getDevice()).readStateAndSet(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected State<T> copy() {
|
protected DimmableState copy() {
|
||||||
final DimmableState<T> d = new DimmableState<>();
|
final DimmableState d = new DimmableState();
|
||||||
d.setIntensity(intensity);
|
d.setIntensity(intensity);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
public interface DimmableStateRepository extends StateRepository<DimmableState<?>> {}
|
public interface DimmableStateRepository extends StateRepository<DimmableState> {}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import javax.persistence.*;
|
||||||
@Entity
|
@Entity
|
||||||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||||
public abstract class Dimmer extends InputDevice implements Connectable<Dimmable> {
|
public abstract class Dimmer extends InputDevice implements Connectable<Dimmable> {
|
||||||
public Dimmer(String kind) {
|
protected Dimmer(String kind) {
|
||||||
super(kind);
|
super(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,22 +2,18 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
/** Represents a motion sensor device */
|
/** Represents a motion sensor device */
|
||||||
@Entity
|
@Entity
|
||||||
public class MotionSensor extends InputDevice implements BooleanTriggerable {
|
public class MotionSensor extends InputDevice implements BooleanTriggerable {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private boolean detected;
|
private boolean detected;
|
||||||
|
|
||||||
public boolean isDetected() {
|
|
||||||
return detected;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDetected(boolean detected) {
|
|
||||||
this.detected = detected;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MotionSensor() {
|
public MotionSensor() {
|
||||||
super("motionSensor");
|
super("motionSensor");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
public enum Operator {
|
||||||
|
@SerializedName("EQUAL")
|
||||||
|
EQUAL,
|
||||||
|
@SerializedName("LESS")
|
||||||
|
LESS,
|
||||||
|
@SerializedName("GREATER")
|
||||||
|
GREATER,
|
||||||
|
@SerializedName("LESS_EQUAL")
|
||||||
|
LESS_EQUAL,
|
||||||
|
@SerializedName("GREATER_EQUAL")
|
||||||
|
GREATER_EQUAL;
|
||||||
|
|
||||||
|
boolean checkAgainst(double value, double range) {
|
||||||
|
switch (this) {
|
||||||
|
case EQUAL:
|
||||||
|
return value == range;
|
||||||
|
case LESS:
|
||||||
|
return value < range;
|
||||||
|
case GREATER:
|
||||||
|
return value > range;
|
||||||
|
case GREATER_EQUAL:
|
||||||
|
return value >= range;
|
||||||
|
case LESS_EQUAL:
|
||||||
|
return value <= range;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,10 +14,10 @@ public abstract class OutputDevice extends Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a State<?> object initialized to point at this device and with values copied from
|
* Creates a State object initialized to point at this device and with values copied from this
|
||||||
* this device's state
|
* device's state
|
||||||
*
|
*
|
||||||
* @return a new State<?> object
|
* @return a new State object
|
||||||
*/
|
*/
|
||||||
public abstract State<? extends OutputDevice> cloneState();
|
public abstract State cloneState();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger.Operator;
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.validation.constraints.NotNull;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class RangeCondition extends Condition<RangeTriggerable> {
|
public class RangeCondition extends Condition<RangeTriggerable> {
|
||||||
|
@ -13,57 +12,18 @@ public class RangeCondition extends Condition<RangeTriggerable> {
|
||||||
super("rangeCondition");
|
super("rangeCondition");
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Operator {
|
@Getter
|
||||||
@SerializedName("EQUAL")
|
@Setter
|
||||||
EQUAL,
|
|
||||||
@SerializedName("LESS")
|
|
||||||
LESS,
|
|
||||||
@SerializedName("GREATER")
|
|
||||||
GREATER,
|
|
||||||
@SerializedName("LESS_EQUAL")
|
|
||||||
LESS_EQUAL,
|
|
||||||
@SerializedName("GREATER_EQUAL")
|
|
||||||
GREATER_EQUAL
|
|
||||||
}
|
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private RangeCondition.Operator operator;
|
private Operator operator;
|
||||||
|
|
||||||
@NotNull
|
@Getter
|
||||||
|
@Setter
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private double range;
|
private double range;
|
||||||
|
|
||||||
public RangeCondition.Operator getOperator() {
|
|
||||||
return operator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperator(RangeCondition.Operator operator) {
|
|
||||||
this.operator = operator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getRange() {
|
|
||||||
return range;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRange(Double range) {
|
|
||||||
this.range = range;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean triggered() {
|
public boolean triggered() {
|
||||||
double value = getDevice().readTriggerState();
|
return operator.checkAgainst(getDevice().readTriggerState(), range);
|
||||||
switch (operator) {
|
|
||||||
case EQUAL:
|
|
||||||
return value == range;
|
|
||||||
case LESS:
|
|
||||||
return value < range;
|
|
||||||
case GREATER:
|
|
||||||
return value > range;
|
|
||||||
case GREATER_EQUAL:
|
|
||||||
return value >= range;
|
|
||||||
case LESS_EQUAL:
|
|
||||||
return value <= range;
|
|
||||||
}
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class RangeTrigger extends Trigger<RangeTriggerable> {
|
public class RangeTrigger extends Trigger<RangeTriggerable> {
|
||||||
|
@ -11,56 +12,18 @@ public class RangeTrigger extends Trigger<RangeTriggerable> {
|
||||||
super("rangeTrigger");
|
super("rangeTrigger");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Getter
|
||||||
public boolean triggered() {
|
@Setter
|
||||||
double value = getDevice().readTriggerState();
|
|
||||||
switch (operator) {
|
|
||||||
case EQUAL:
|
|
||||||
return value == range;
|
|
||||||
case LESS:
|
|
||||||
return value < range;
|
|
||||||
case GREATER:
|
|
||||||
return value > range;
|
|
||||||
case GREATER_EQUAL:
|
|
||||||
return value >= range;
|
|
||||||
case LESS_EQUAL:
|
|
||||||
return value <= range;
|
|
||||||
}
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Operator {
|
|
||||||
@SerializedName("EQUAL")
|
|
||||||
EQUAL,
|
|
||||||
@SerializedName("LESS")
|
|
||||||
LESS,
|
|
||||||
@SerializedName("GREATER")
|
|
||||||
GREATER,
|
|
||||||
@SerializedName("LESS_EQUAL")
|
|
||||||
LESS_EQUAL,
|
|
||||||
@SerializedName("GREATER_EQUAL")
|
|
||||||
GREATER_EQUAL
|
|
||||||
}
|
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Operator operator;
|
private Operator operator;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private double range;
|
private double range;
|
||||||
|
|
||||||
public Operator getOperator() {
|
@Override
|
||||||
return operator;
|
public boolean triggered() {
|
||||||
}
|
return operator.checkAgainst(getDevice().readTriggerState(), range);
|
||||||
|
|
||||||
public void setOperator(Operator operator) {
|
|
||||||
this.operator = operator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getRange() {
|
|
||||||
return range;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRange(Double range) {
|
|
||||||
this.range = range;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.validation.constraints.NotNull;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
/** Represents a standard non-dimmable light */
|
/** Represents a standard non-dimmable light */
|
||||||
@Entity
|
@Entity
|
||||||
|
@ -10,22 +11,12 @@ public class RegularLight extends Switchable implements BooleanTriggerable {
|
||||||
|
|
||||||
/** Whether the light is on or not */
|
/** Whether the light is on or not */
|
||||||
@Column(name = "light_on", nullable = false)
|
@Column(name = "light_on", nullable = false)
|
||||||
@NotNull
|
@Getter
|
||||||
|
@Setter
|
||||||
boolean on;
|
boolean on;
|
||||||
|
|
||||||
public RegularLight() {
|
public RegularLight() {
|
||||||
super("regularLight");
|
super("regularLight");
|
||||||
this.on = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isOn() {
|
|
||||||
return on;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setOn(boolean on) {
|
|
||||||
this.on = on;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModelProperty;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
/** Represents a room in the house owned by the user */
|
/** Represents a room in the house owned by the user */
|
||||||
@Entity
|
@Entity
|
||||||
|
@ -42,12 +41,10 @@ public class Room {
|
||||||
* User that owns the house this room is in as a foreign key id. To use when updating and
|
* User that owns the house this room is in as a foreign key id. To use when updating and
|
||||||
* inserting from a REST call.
|
* inserting from a REST call.
|
||||||
*/
|
*/
|
||||||
@NotNull
|
|
||||||
@Column(name = "user_id", nullable = false)
|
@Column(name = "user_id", nullable = false)
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
/** The user given name of this room (e.g. 'Master bedroom') */
|
/** The user given name of this room (e.g. 'Master bedroom') */
|
||||||
@NotNull
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,13 @@ import io.swagger.annotations.ApiModelProperty;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotNull;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represent a collection of state changes to devices even in different rooms but belonging to the
|
* Represent a collection of state changes to devices even in different rooms but belonging to the
|
||||||
* same user
|
* same user
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
public class Scene {
|
public class Scene {
|
||||||
|
|
||||||
|
@ -25,80 +26,21 @@ public class Scene {
|
||||||
@GsonExclude
|
@GsonExclude
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Column(name = "user_id", nullable = false)
|
@Column(name = "user_id", nullable = false)
|
||||||
@GsonExclude
|
@GsonExclude
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "scene", orphanRemoval = true)
|
@OneToMany(mappedBy = "scene", orphanRemoval = true)
|
||||||
@GsonExclude
|
@GsonExclude
|
||||||
private Set<State<?>> states = new HashSet<>();
|
private Set<State> states = new HashSet<>();
|
||||||
|
|
||||||
/** The user given name of this room (e.g. 'Master bedroom') */
|
/** The user given name of this room (e.g. 'Master bedroom') */
|
||||||
@NotNull
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@NotNull
|
|
||||||
private Icon icon;
|
private Icon icon;
|
||||||
|
|
||||||
/** Determines whether a guest can access this scene */
|
/** Determines whether a guest can access this scene */
|
||||||
@Column private boolean guestAccessEnabled;
|
@Column private boolean guestAccessEnabled;
|
||||||
|
|
||||||
public Icon getIcon() {
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIcon(Icon icon) {
|
|
||||||
this.icon = icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isGuestAccessEnabled() {
|
|
||||||
return guestAccessEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGuestAccessEnabled(boolean guestAccessEnabled) {
|
|
||||||
this.guestAccessEnabled = guestAccessEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUser(User user) {
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<State<?>> getStates() {
|
|
||||||
return states;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStates(Set<State<?>> states) {
|
|
||||||
this.states = states;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getUserId() {
|
|
||||||
return userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserId(Long userId) {
|
|
||||||
this.userId = userId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.PreRemove;
|
import javax.persistence.PreRemove;
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class ScenePriority {
|
public class ScenePriority {
|
||||||
|
@ -30,7 +29,6 @@ public class ScenePriority {
|
||||||
@Column(name = "automation_id", nullable = false)
|
@Column(name = "automation_id", nullable = false)
|
||||||
private Long automationId;
|
private Long automationId;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Min(0)
|
@Min(0)
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Integer priority;
|
private Integer priority;
|
||||||
|
|
|
@ -2,7 +2,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class SecurityCamera extends Switchable implements BooleanTriggerable {
|
public class SecurityCamera extends Switchable implements BooleanTriggerable {
|
||||||
|
@ -13,7 +12,6 @@ public class SecurityCamera extends Switchable implements BooleanTriggerable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Column(name = "camera_on", nullable = false)
|
@Column(name = "camera_on", nullable = false)
|
||||||
@NotNull
|
|
||||||
private boolean on;
|
private boolean on;
|
||||||
|
|
||||||
@Column(name = "video", nullable = false)
|
@Column(name = "video", nullable = false)
|
||||||
|
|
|
@ -3,7 +3,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
/** A smart plug that can be turned either on or off */
|
/** A smart plug that can be turned either on or off */
|
||||||
@Entity
|
@Entity
|
||||||
|
@ -14,7 +13,6 @@ public class SmartPlug extends Switchable implements BooleanTriggerable {
|
||||||
|
|
||||||
/** The total amount of power that the smart plug has consumed represented in W/h */
|
/** The total amount of power that the smart plug has consumed represented in W/h */
|
||||||
@Column(precision = 13, scale = 3)
|
@Column(precision = 13, scale = 3)
|
||||||
@NotNull
|
|
||||||
private BigDecimal totalConsumption = BigDecimal.ZERO;
|
private BigDecimal totalConsumption = BigDecimal.ZERO;
|
||||||
|
|
||||||
/** Whether the smart plug is on */
|
/** Whether the smart plug is on */
|
||||||
|
|
|
@ -3,7 +3,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotNull;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents instructions on how to change the state of a particular device. Many states (plus
|
* Represents instructions on how to change the state of a particular device. Many states (plus
|
||||||
|
@ -12,95 +13,66 @@ import javax.validation.constraints.NotNull;
|
||||||
@Entity
|
@Entity
|
||||||
@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"device_id", "scene_id"})})
|
@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"device_id", "scene_id"})})
|
||||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||||
public abstract class State<D extends OutputDevice> {
|
public abstract class State {
|
||||||
|
|
||||||
|
@ManyToOne(targetEntity = OutputDevice.class)
|
||||||
|
@JoinColumn(name = "device_id", updatable = false, insertable = false)
|
||||||
|
@GsonExclude
|
||||||
|
@Getter
|
||||||
|
private OutputDevice device;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
@Column(name = "id", updatable = false, nullable = false, unique = true)
|
@Column(name = "id", updatable = false, nullable = false, unique = true)
|
||||||
@ApiModelProperty(hidden = true)
|
@ApiModelProperty(hidden = true)
|
||||||
|
@Getter
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
@ManyToOne(targetEntity = OutputDevice.class)
|
|
||||||
@JoinColumn(name = "device_id", updatable = false, insertable = false)
|
|
||||||
@GsonExclude
|
|
||||||
private D device;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The device this state belongs in, as a foreign key id. To use when updating and inserting
|
* The device this state belongs in, as a foreign key id. To use when updating and inserting
|
||||||
* from a REST call.
|
* from a REST call.
|
||||||
*/
|
*/
|
||||||
@Column(name = "device_id", nullable = false)
|
@Column(name = "device_id", nullable = false)
|
||||||
@NotNull
|
@Getter
|
||||||
|
@Setter
|
||||||
private Long deviceId;
|
private Long deviceId;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "scene_id", updatable = false, insertable = false)
|
@JoinColumn(name = "scene_id", updatable = false, insertable = false)
|
||||||
@GsonExclude
|
@GsonExclude
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
private Scene scene;
|
private Scene scene;
|
||||||
|
|
||||||
@Column(name = "scene_id", nullable = false)
|
@Column(name = "scene_id", nullable = false)
|
||||||
@NotNull
|
@Getter
|
||||||
|
@Setter
|
||||||
private Long sceneId;
|
private Long sceneId;
|
||||||
|
|
||||||
|
protected void setInnerDevice(OutputDevice device) {
|
||||||
|
this.device = device;
|
||||||
|
}
|
||||||
|
|
||||||
/** Sets the state of the connected device to the state represented by this object. */
|
/** Sets the state of the connected device to the state represented by this object. */
|
||||||
public abstract void apply();
|
public abstract void apply();
|
||||||
|
|
||||||
/** Creates a perfect copy of this state, except for the id field and the sceneId/scene */
|
/** Creates a perfect copy of this state, except for the id field and the sceneId/scene */
|
||||||
protected abstract State<D> copy();
|
protected abstract State copy();
|
||||||
|
|
||||||
public State<D> copyToSceneId(Long sceneId) {
|
public State copyToSceneId(Long sceneId) {
|
||||||
final State<D> s = copy();
|
final State s = copy();
|
||||||
s.setDeviceId(this.deviceId);
|
s.setDeviceId(this.deviceId);
|
||||||
|
s.device = this.device;
|
||||||
s.setSceneId(sceneId);
|
s.setSceneId(sceneId);
|
||||||
|
s.setScene(this.scene);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public D getDevice() {
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDevice(D device) {
|
|
||||||
this.device = device;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getDeviceId() {
|
|
||||||
return deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceId(Long deviceId) {
|
|
||||||
this.deviceId = deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Scene getScene() {
|
|
||||||
return scene;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setScene(Scene scene) {
|
|
||||||
this.scene = scene;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getSceneId() {
|
|
||||||
return sceneId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSceneId(Long sceneId) {
|
|
||||||
this.sceneId = sceneId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreRemove
|
@PreRemove
|
||||||
public void removeDeviceAndScene() {
|
public void removeDeviceAndScene() {
|
||||||
this.setScene(null);
|
|
||||||
this.setSceneId(null);
|
this.setSceneId(null);
|
||||||
|
this.setScene(null);
|
||||||
this.setDevice(null);
|
|
||||||
this.setDeviceId(null);
|
this.setDeviceId(null);
|
||||||
|
this.device = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import javax.transaction.Transactional;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
public interface StateRepository<T extends State<?>> extends CrudRepository<T, Long> {
|
public interface StateRepository<T extends State> extends CrudRepository<T, Long> {
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
void deleteAllBySceneId(long roomId);
|
void deleteAllBySceneId(long roomId);
|
||||||
|
|
|
@ -45,15 +45,13 @@ public abstract class Switchable extends OutputDevice {
|
||||||
return inputs;
|
return inputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readStateAndSet(SwitchableState<? extends Switchable> state) {
|
public void readStateAndSet(SwitchableState state) {
|
||||||
setOn(state.isOn());
|
setOn(state.isOn());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public State cloneState() {
|
||||||
public State<? extends Switchable> cloneState() {
|
final SwitchableState newState = new SwitchableState();
|
||||||
final SwitchableState<Switchable> newState = new SwitchableState<>();
|
|
||||||
newState.setDeviceId(getId());
|
newState.setDeviceId(getId());
|
||||||
newState.setDevice(this);
|
|
||||||
newState.setOn(isOn());
|
newState.setOn(isOn());
|
||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,30 +2,30 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
/** Represents a state for a Switchable device */
|
/** Represents a state for a Switchable device */
|
||||||
@Entity
|
@Entity
|
||||||
public class SwitchableState<T extends Switchable> extends State<T> {
|
public class SwitchableState extends State {
|
||||||
|
|
||||||
|
public void setDevice(Switchable device) {
|
||||||
|
setInnerDevice(device);
|
||||||
|
}
|
||||||
|
|
||||||
@Column(name = "switchable_on")
|
@Column(name = "switchable_on")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
private boolean on;
|
private boolean on;
|
||||||
|
|
||||||
public boolean isOn() {
|
|
||||||
return on;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOn(boolean on) {
|
|
||||||
this.on = on;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
getDevice().readStateAndSet(this);
|
((Switchable) getDevice()).readStateAndSet(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected State<T> copy() {
|
protected SwitchableState copy() {
|
||||||
final SwitchableState<T> d = new SwitchableState<>();
|
final SwitchableState d = new SwitchableState();
|
||||||
d.setOn(on);
|
d.setOn(on);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
public interface SwitchableStateRepository extends StateRepository<SwitchableState<?>> {}
|
public interface SwitchableStateRepository extends StateRepository<SwitchableState> {}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import java.math.BigDecimal;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Transient;
|
import javax.persistence.Transient;
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
/** A thermostat capable of controlling cooling and heating. */
|
/** A thermostat capable of controlling cooling and heating. */
|
||||||
@Entity
|
@Entity
|
||||||
|
@ -72,7 +71,7 @@ public class Thermostat extends Switchable implements BooleanTriggerable {
|
||||||
Sensor.TYPICAL_VALUES.get(Sensor.SensorType.TEMPERATURE);
|
Sensor.TYPICAL_VALUES.get(Sensor.SensorType.TEMPERATURE);
|
||||||
|
|
||||||
/** State of this thermostat */
|
/** State of this thermostat */
|
||||||
@Column @NotNull private Thermostat.Mode mode;
|
@Column private Thermostat.Mode mode;
|
||||||
|
|
||||||
@Transient private BigDecimal measuredTemperature;
|
@Transient private BigDecimal measuredTemperature;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ public class SceneService {
|
||||||
|
|
||||||
private final DevicePopulationService devicePopulationService;
|
private final DevicePopulationService devicePopulationService;
|
||||||
private final DevicePropagationService devicePropagationService;
|
private final DevicePropagationService devicePropagationService;
|
||||||
private final StateRepository<State<?>> stateRepository;
|
private final StateRepository<State> stateRepository;
|
||||||
private final SceneRepository sceneRepository;
|
private final SceneRepository sceneRepository;
|
||||||
|
|
||||||
public Scene findByValidatedId(Long id) {
|
public Scene findByValidatedId(Long id) {
|
||||||
|
@ -22,7 +22,7 @@ public class SceneService {
|
||||||
public SceneService(
|
public SceneService(
|
||||||
DevicePopulationService devicePopulationService,
|
DevicePopulationService devicePopulationService,
|
||||||
DevicePropagationService devicePropagationService,
|
DevicePropagationService devicePropagationService,
|
||||||
StateRepository<State<?>> stateRepository,
|
StateRepository<State> stateRepository,
|
||||||
SceneRepository sceneRepository) {
|
SceneRepository sceneRepository) {
|
||||||
this.devicePopulationService = devicePopulationService;
|
this.devicePopulationService = devicePopulationService;
|
||||||
this.devicePropagationService = devicePropagationService;
|
this.devicePropagationService = devicePropagationService;
|
||||||
|
@ -33,7 +33,7 @@ public class SceneService {
|
||||||
private List<Device> copyStatesToDevices(Scene fromScene) {
|
private List<Device> copyStatesToDevices(Scene fromScene) {
|
||||||
final List<Device> updated = new ArrayList<>(fromScene.getStates().size());
|
final List<Device> updated = new ArrayList<>(fromScene.getStates().size());
|
||||||
|
|
||||||
for (final State<?> s : fromScene.getStates()) {
|
for (final State s : fromScene.getStates()) {
|
||||||
s.apply();
|
s.apply();
|
||||||
updated.add(s.getDevice());
|
updated.add(s.getDevice());
|
||||||
}
|
}
|
||||||
|
@ -54,9 +54,9 @@ public class SceneService {
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<State<?>> copyStates(Scene to, Scene from) {
|
public List<State> copyStates(Scene to, Scene from) {
|
||||||
final ArrayList<State<?>> states = new ArrayList<>();
|
final ArrayList<State> states = new ArrayList<>();
|
||||||
for (final State<?> s : from.getStates()) {
|
for (final State s : from.getStates()) {
|
||||||
states.add(stateRepository.save(s.copyToSceneId(to.getId())));
|
states.add(stateRepository.save(s.copyToSceneId(to.getId())));
|
||||||
}
|
}
|
||||||
return states;
|
return states;
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@DisplayName("automation tests")
|
||||||
|
public class AutomationTests {
|
||||||
|
private Automation automation;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
private void createAutomation() {
|
||||||
|
this.automation = new Automation();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setName")
|
||||||
|
public void testSetName() {
|
||||||
|
automation.setName("Automation1");
|
||||||
|
assertEquals("Automation1", automation.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setId")
|
||||||
|
public void testSetId() {
|
||||||
|
automation.setId(34l);
|
||||||
|
assertEquals(34l, automation.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setUserId")
|
||||||
|
public void testSetUserId() {
|
||||||
|
automation.setUserId(43l);
|
||||||
|
assertEquals(43l, automation.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setUser")
|
||||||
|
public void testSetUser() {
|
||||||
|
User user = new User();
|
||||||
|
automation.setUser(user);
|
||||||
|
user.setUsername("xXcoolNameXx");
|
||||||
|
user.setId(42l);
|
||||||
|
user.setName("John RealName");
|
||||||
|
assertTrue(user.equals(automation.getUser()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setTriggers")
|
||||||
|
public void testSetTrigger() {
|
||||||
|
BooleanTrigger trigger1 = new BooleanTrigger();
|
||||||
|
BooleanTrigger trigger2 = new BooleanTrigger();
|
||||||
|
automation.getTriggers().add(trigger1);
|
||||||
|
automation.getTriggers().add(trigger2);
|
||||||
|
assertEquals(2, automation.getTriggers().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setScene")
|
||||||
|
public void testSetScene() {
|
||||||
|
ScenePriority priority1 = new ScenePriority();
|
||||||
|
priority1.setPriority(1);
|
||||||
|
ScenePriority priority2 = new ScenePriority();
|
||||||
|
priority2.setPriority(2);
|
||||||
|
ScenePriority priority3 = new ScenePriority();
|
||||||
|
priority3.setPriority(3);
|
||||||
|
automation.getScenes().add(priority1);
|
||||||
|
automation.getScenes().add(priority2);
|
||||||
|
automation.getScenes().add(priority3);
|
||||||
|
assertEquals(3, automation.getScenes().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setCondition")
|
||||||
|
public void testSetCondition() {
|
||||||
|
BooleanCondition bool = new BooleanCondition();
|
||||||
|
RangeCondition range = new RangeCondition();
|
||||||
|
bool.setOn(true);
|
||||||
|
range.setRange(10l);
|
||||||
|
automation.getConditions().add(bool);
|
||||||
|
automation.getConditions().add(range);
|
||||||
|
assertEquals(2, automation.getConditions().size());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanCondition;
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Switch;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@DisplayName("BooleanCondition tests")
|
||||||
|
public class BooleanConditionTests {
|
||||||
|
private BooleanCondition condition;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
private void createCondition() {
|
||||||
|
condition = new BooleanCondition();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setOnFalse")
|
||||||
|
public void testSetOnFalse() {
|
||||||
|
condition.setOn(false);
|
||||||
|
assertFalse(condition.isOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setOnTrue")
|
||||||
|
public void testSetOnTrue() {
|
||||||
|
condition.setOn(true);
|
||||||
|
assertTrue(condition.isOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test triggeredTrue")
|
||||||
|
public void testTriggeredTrue() {
|
||||||
|
Switch a = new Switch();
|
||||||
|
a.setOn(true);
|
||||||
|
condition.setOn(true);
|
||||||
|
condition.setDevice(a);
|
||||||
|
assertTrue(condition.triggered());
|
||||||
|
condition.setOn(false);
|
||||||
|
assertFalse(condition.triggered());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test triggeredFalse")
|
||||||
|
public void testTriggeredFalse() {
|
||||||
|
Switch a = new Switch();
|
||||||
|
a.setOn(false);
|
||||||
|
condition.setOn(false);
|
||||||
|
condition.setDevice(a);
|
||||||
|
assertTrue(condition.triggered());
|
||||||
|
condition.setOn(true);
|
||||||
|
assertFalse(condition.triggered());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger;
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Switch;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@DisplayName("booleantrigger test")
|
||||||
|
public class BooleanTriggerTests {
|
||||||
|
private BooleanTrigger trigger;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
private void createTrigger() {
|
||||||
|
trigger = new BooleanTrigger();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setOnFalse")
|
||||||
|
public void testSetOnFalse() {
|
||||||
|
trigger.setOn(false);
|
||||||
|
assertFalse(trigger.isOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setOnTrue")
|
||||||
|
public void testSetOnTrue() {
|
||||||
|
trigger.setOn(true);
|
||||||
|
assertTrue(trigger.isOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test triggeredTrue")
|
||||||
|
public void testTriggeredTrue() {
|
||||||
|
Switch a = new Switch();
|
||||||
|
a.setOn(true);
|
||||||
|
trigger.setOn(true);
|
||||||
|
trigger.setDevice(a);
|
||||||
|
assertTrue(trigger.triggered());
|
||||||
|
trigger.setOn(false);
|
||||||
|
assertFalse(trigger.triggered());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test triggeredFalse")
|
||||||
|
public void testTriggeredFalse() {
|
||||||
|
Switch a = new Switch();
|
||||||
|
a.setOn(false);
|
||||||
|
trigger.setOn(false);
|
||||||
|
trigger.setDevice(a);
|
||||||
|
assertTrue(trigger.triggered());
|
||||||
|
trigger.setOn(true);
|
||||||
|
assertFalse(trigger.triggered());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanCondition;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@DisplayName("Condition tests")
|
||||||
|
public class ConditionTests {
|
||||||
|
private BooleanCondition condition;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
private void createCondition() {
|
||||||
|
this.condition = new BooleanCondition();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test automationId")
|
||||||
|
public void testSetAutomationId() {
|
||||||
|
condition.setAutomationId(32l);
|
||||||
|
assertEquals(32l, condition.getAutomationId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test getKind")
|
||||||
|
public void testGetKind() {
|
||||||
|
assertEquals("booleanCondition", condition.getKind());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setId")
|
||||||
|
public void testSetId() {
|
||||||
|
condition.setId(11);
|
||||||
|
assertEquals(11, condition.getId());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ConfirmationToken;
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@DisplayName("ConfirmationToken tests")
|
||||||
|
public class ConfirmationTokenTests {
|
||||||
|
private ConfirmationToken token;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
private void createToke() {
|
||||||
|
User user = new User();
|
||||||
|
user.setName("Tizio Sempronio");
|
||||||
|
user.setId(42l);
|
||||||
|
user.setUsername("xXCoolUserNameXx");
|
||||||
|
user.setEmail("realMail@service.ext");
|
||||||
|
user.setPassword("alpaca");
|
||||||
|
this.token = new ConfirmationToken(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setId")
|
||||||
|
public void testSetId() {
|
||||||
|
this.token.setId(34l);
|
||||||
|
assertEquals(34l, token.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test getUSerId")
|
||||||
|
public void testGetUserId() {
|
||||||
|
assertEquals(42l, token.getUser().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setResetPassword")
|
||||||
|
public void testSetResetPassword() {
|
||||||
|
assertFalse(token.isResetPassword());
|
||||||
|
token.setResetPassword(true);
|
||||||
|
assertTrue(token.isResetPassword());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setTimeStamp")
|
||||||
|
public void testSetTimeStamp() {
|
||||||
|
Date date = new Date();
|
||||||
|
date.setTime(86400000l);
|
||||||
|
token.setCreatedDate(date);
|
||||||
|
assertEquals(date, token.getCreatedDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setConfirmToken")
|
||||||
|
public void testSetConfirmTOken() {
|
||||||
|
assertNotEquals(null, token.getConfirmToken());
|
||||||
|
String newToken = "newConfirmationToken";
|
||||||
|
token.setConfirmToken(newToken);
|
||||||
|
assertEquals(newToken, token.getConfirmToken());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@DisplayName("Dimmable tests")
|
||||||
|
public class DimmableTests {
|
||||||
|
private DimmableLight dimmable;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
private void createDimmable() {
|
||||||
|
dimmable = new DimmableLight();
|
||||||
|
dimmable.setId(42l);
|
||||||
|
KnobDimmer dimmer1 = new KnobDimmer();
|
||||||
|
dimmer1.setLightIntensity(75);
|
||||||
|
ButtonDimmer dimmer2 = new ButtonDimmer();
|
||||||
|
dimmer2.setName("button");
|
||||||
|
Set<Dimmer> set = new HashSet<Dimmer>();
|
||||||
|
set.add(dimmer1);
|
||||||
|
set.add(dimmer2);
|
||||||
|
dimmable.setDimmers(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test getDimmers")
|
||||||
|
public void testGetDimmers() {
|
||||||
|
assertEquals(2, dimmable.getDimmers().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test intensity and old Intensity")
|
||||||
|
public void testIntensities() {
|
||||||
|
assertEquals(0, dimmable.getIntensity());
|
||||||
|
dimmable.setIntensity(13);
|
||||||
|
dimmable.setIntensity(24);
|
||||||
|
assertEquals(24, dimmable.getIntensity());
|
||||||
|
assertEquals(24, dimmable.getOldIntensity());
|
||||||
|
dimmable.setOldIntensity(99);
|
||||||
|
assertEquals(99, dimmable.getOldIntensity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test setOn")
|
||||||
|
public void testIsOn() {
|
||||||
|
assertFalse(dimmable.isOn());
|
||||||
|
dimmable.setOn(true);
|
||||||
|
assertTrue(dimmable.isOn());
|
||||||
|
assertNotEquals(0, dimmable.getIntensity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test readStateAndSet")
|
||||||
|
public void testReadStateAndSet() {
|
||||||
|
DimmableState state = new DimmableState();
|
||||||
|
state.setIntensity(78);
|
||||||
|
dimmable.readStateAndSet(state);
|
||||||
|
assertEquals(78, dimmable.getIntensity());
|
||||||
|
assertEquals(78, dimmable.getOldIntensity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test cloneState")
|
||||||
|
public void testCloneState() {
|
||||||
|
dimmable.setId(27);
|
||||||
|
DimmableState state = (DimmableState) dimmable.cloneState();
|
||||||
|
assertEquals(state.getDeviceId(), dimmable.getId());
|
||||||
|
assertEquals(state.getIntensity(), dimmable.getIntensity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test readTriggerState")
|
||||||
|
public void testReadTriggerState() {
|
||||||
|
dimmable.setIntensity(84);
|
||||||
|
assertEquals(84, dimmable.readTriggerState());
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ public class SwitchableStateSaveRequestTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("test isOn()")
|
@DisplayName("test isOn()")
|
||||||
public void inOnTest() {
|
public void isOnTest() {
|
||||||
assertFalse(saveRequest.isOn());
|
assertFalse(saveRequest.isOn());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
|
||||||
|
|
||||||
public class UserUpdateRequestTests {}
|
|
Loading…
Reference in a new issue