diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/BooleanConditionController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/BooleanConditionController.java index ddcb880..e605043 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/BooleanConditionController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/BooleanConditionController.java @@ -1,6 +1,6 @@ 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.models.BooleanCondition; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanConditionRepository; @@ -29,7 +29,7 @@ public class BooleanConditionController { return booleanConditionRepository.findAllByAutomationId(automationId); } - private BooleanCondition save(BooleanCondition newRL, BooleanConditionSaveRequest s) { + private BooleanCondition save(BooleanCondition newRL, BooleanConditionOrTriggerSaveRequest s) { newRL.setDeviceId(s.getDeviceId()); newRL.setAutomationId(s.getAutomationId()); newRL.setOn(s.isOn()); @@ -39,13 +39,13 @@ public class BooleanConditionController { @PostMapping public BooleanCondition create( - @Valid @RequestBody BooleanConditionSaveRequest booleanTriggerSaveRequest) { + @Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest) { return save(new BooleanCondition(), booleanTriggerSaveRequest); } @PutMapping public BooleanCondition update( - @Valid @RequestBody BooleanConditionSaveRequest booleanTriggerSaveRequest) + @Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest) throws NotFoundException { return save( booleanConditionRepository diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/BooleanTriggerController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/BooleanTriggerController.java index 46af99e..d31b8e2 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/BooleanTriggerController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/BooleanTriggerController.java @@ -1,6 +1,6 @@ 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.models.BooleanTrigger; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTriggerRepository; @@ -29,7 +29,7 @@ public class BooleanTriggerController { return booleanTriggerRepository.findAllByAutomationId(automationId); } - private BooleanTrigger save(BooleanTrigger newRL, BooleanTriggerSaveRequest s) { + private BooleanTrigger save(BooleanTrigger newRL, BooleanConditionOrTriggerSaveRequest s) { newRL.setDeviceId(s.getDeviceId()); newRL.setAutomationId(s.getAutomationId()); newRL.setOn(s.isOn()); @@ -39,13 +39,13 @@ public class BooleanTriggerController { @PostMapping public BooleanTrigger create( - @Valid @RequestBody BooleanTriggerSaveRequest booleanTriggerSaveRequest) { + @Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest) { return save(new BooleanTrigger(), booleanTriggerSaveRequest); } @PutMapping public BooleanTrigger update( - @Valid @RequestBody BooleanTriggerSaveRequest booleanTriggerSaveRequest) + @Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest) throws NotFoundException { return save( booleanTriggerRepository diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/CurtainsController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/CurtainsController.java index 9fbf704..5e01f9a 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/CurtainsController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/CurtainsController.java @@ -18,7 +18,7 @@ public class CurtainsController { @Autowired private DeviceService deviceService; @Autowired private CurtainsRepository curtainsService; @Autowired private SceneRepository sceneRepository; - @Autowired private StateRepository> stateRepository; + @Autowired private StateRepository stateRepository; private Curtains save(Curtains newRL, DimmableSaveRequest s, final Principal principal) { newRL.setName(s.getName()); @@ -53,7 +53,7 @@ public class CurtainsController { } @PostMapping("/{id}/state") - public State sceneBinding( + public State sceneBinding( @PathVariable("id") long deviceId, @RequestParam long sceneId, final Principal principal) @@ -63,7 +63,7 @@ public class CurtainsController { curtainsService .findByIdAndUsername(deviceId, principal.getName()) .orElseThrow(NotFoundException::new); - State s = c.cloneState(); + State s = c.cloneState(); final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new); s.setSceneId(sc.getId()); if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java index 990c105..e251d7c 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java @@ -18,7 +18,7 @@ public class DimmableLightController extends GuestEnabledController> stateRepository; + private final StateRepository stateRepository; private final DeviceService deviceService; @Autowired @@ -26,7 +26,7 @@ public class DimmableLightController extends GuestEnabledController> stateRepository, + StateRepository stateRepository, DeviceService deviceService) { super(userRepository, dimmableLightRepository); this.dimmableLightRepository = dimmableLightRepository; @@ -87,7 +87,7 @@ public class DimmableLightController extends GuestEnabledController sceneBinding( + public State sceneBinding( @PathVariable("id") long deviceId, @RequestParam long sceneId, final Principal principal) @@ -97,7 +97,7 @@ public class DimmableLightController extends GuestEnabledController s = d.cloneState(); + State s = d.cloneState(); final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new); s.setSceneId(sc.getId()); if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableStateController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableStateController.java index d866d78..83ffb53 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableStateController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableStateController.java @@ -17,9 +17,9 @@ public class DimmableStateController { @Autowired private DimmableStateRepository dimmableStateRepository; @PutMapping - public DimmableState update(@Valid @RequestBody DimmableStateSaveRequest ss) + public DimmableState update(@Valid @RequestBody DimmableStateSaveRequest ss) throws NotFoundException { - final DimmableState initial = + final DimmableState initial = dimmableStateRepository.findById(ss.getId()).orElseThrow(NotFoundException::new); initial.setIntensity(ss.getIntensity()); dimmableStateRepository.save(initial); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RangeConditionController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RangeConditionController.java index 5055c61..ea9a911 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RangeConditionController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RangeConditionController.java @@ -1,6 +1,6 @@ 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.models.RangeCondition; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeConditionRepository; @@ -29,7 +29,7 @@ public class RangeConditionController { return rangeConditionRepository.findAllByAutomationId(automationId); } - private RangeCondition save(RangeCondition newRL, RangeConditionSaveRequest s) { + private RangeCondition save(RangeCondition newRL, RangeConditionOrTriggerSaveRequest s) { newRL.setDeviceId(s.getDeviceId()); newRL.setAutomationId(s.getAutomationId()); newRL.setOperator(s.getOperator()); @@ -40,13 +40,13 @@ public class RangeConditionController { @PostMapping public RangeCondition create( - @Valid @RequestBody RangeConditionSaveRequest booleanTriggerSaveRequest) { + @Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest) { return save(new RangeCondition(), booleanTriggerSaveRequest); } @PutMapping public RangeCondition update( - @Valid @RequestBody RangeConditionSaveRequest booleanTriggerSaveRequest) + @Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest) throws NotFoundException { return save( rangeConditionRepository diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RangeTriggerController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RangeTriggerController.java index a86a386..c8c5589 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RangeTriggerController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RangeTriggerController.java @@ -1,6 +1,6 @@ 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.models.RangeTrigger; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTriggerRepository; @@ -29,7 +29,7 @@ public class RangeTriggerController { return rangeTriggerRepository.findAllByAutomationId(automationId); } - private RangeTrigger save(RangeTrigger newRL, RangeTriggerSaveRequest s) { + private RangeTrigger save(RangeTrigger newRL, RangeConditionOrTriggerSaveRequest s) { newRL.setDeviceId(s.getDeviceId()); newRL.setAutomationId(s.getAutomationId()); newRL.setOperator(s.getOperator()); @@ -40,13 +40,13 @@ public class RangeTriggerController { @PostMapping public RangeTrigger create( - @Valid @RequestBody RangeTriggerSaveRequest booleanTriggerSaveRequest) { + @Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest) { return save(new RangeTrigger(), booleanTriggerSaveRequest); } @PutMapping public RangeTrigger update( - @Valid @RequestBody RangeTriggerSaveRequest booleanTriggerSaveRequest) + @Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest) throws NotFoundException { return save( rangeTriggerRepository diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java index c3bdc8b..6da88d8 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java @@ -29,7 +29,7 @@ public class RegularLightController extends GuestEnabledController private RegularLightRepository regularLightRepository; private SceneRepository sceneRepository; - private StateRepository> stateRepository; + private StateRepository stateRepository; private DeviceService deviceService; @Autowired @@ -37,7 +37,7 @@ public class RegularLightController extends GuestEnabledController UserRepository userRepository, RegularLightRepository regularLightRepository, SceneRepository sceneRepository, - StateRepository> stateRepository, + StateRepository stateRepository, DeviceService deviceService) { super(userRepository, regularLightRepository); this.regularLightRepository = regularLightRepository; @@ -98,7 +98,7 @@ public class RegularLightController extends GuestEnabledController } @PostMapping("/{id}/state") - public State sceneBinding( + public State sceneBinding( @PathVariable("id") long deviceId, @RequestParam long sceneId, final Principal principal) @@ -107,7 +107,7 @@ public class RegularLightController extends GuestEnabledController regularLightRepository .findByIdAndUsername(deviceId, principal.getName()) .orElseThrow(NotFoundException::new); - State s = d.cloneState(); + State s = d.cloneState(); final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new); s.setSceneId(sc.getId()); if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SceneController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SceneController.java index f2d0795..4db036f 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SceneController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SceneController.java @@ -22,7 +22,7 @@ public class SceneController { @Autowired private SceneRepository sceneRepository; @Autowired private UserRepository userRepository; @Autowired private SceneService sceneService; - @Autowired private StateRepository> stateRepository; + @Autowired private StateRepository stateRepository; @GetMapping public List findAll( @@ -78,7 +78,7 @@ public class SceneController { } @PostMapping("/{id}/copyFrom/{copyId}") - public @ResponseBody List> copy( + public @ResponseBody List copy( @PathVariable("id") long id, @PathVariable("copyId") long copyId, final Principal principal) @@ -126,8 +126,8 @@ public class SceneController { * id). */ @GetMapping(path = "/{sceneId}/states") - public List> getDevices(@PathVariable("sceneId") long sceneId) { - Iterable> states = stateRepository.findBySceneId(sceneId); + public List getStates(@PathVariable("sceneId") long sceneId) { + Iterable states = stateRepository.findBySceneId(sceneId); return toList(states); } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SecurityCameraController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SecurityCameraController.java index d006879..781b46a 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SecurityCameraController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SecurityCameraController.java @@ -26,7 +26,7 @@ public class SecurityCameraController { private final DeviceService deviceService; private final SecurityCameraRepository securityCameraService; private final SceneRepository sceneRepository; - private final StateRepository> stateRepository; + private final StateRepository stateRepository; private final CameraConfigurationService cameraConfigurationService; @Autowired @@ -34,7 +34,7 @@ public class SecurityCameraController { DeviceService deviceService, SecurityCameraRepository securityCameraService, SceneRepository sceneRepository, - StateRepository> stateRepository, + StateRepository stateRepository, CameraConfigurationService cameraConfigurationService) { this.deviceService = deviceService; this.securityCameraService = securityCameraService; @@ -80,7 +80,7 @@ public class SecurityCameraController { } @PostMapping("/{id}/state") - public State sceneBinding( + public State sceneBinding( @PathVariable("id") long deviceId, @RequestParam long sceneId, final Principal principal) @@ -90,7 +90,7 @@ public class SecurityCameraController { securityCameraService .findByIdAndUsername(deviceId, principal.getName()) .orElseThrow(NotFoundException::new); - State s = d.cloneState(); + State s = d.cloneState(); final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new); s.setSceneId(sc.getId()); if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java index 88a78f6..43d659b 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java @@ -19,7 +19,7 @@ public class SmartPlugController { @Autowired private DeviceService deviceService; @Autowired private SmartPlugRepository smartPlugRepository; @Autowired private SceneRepository sceneRepository; - @Autowired private StateRepository> stateRepository; + @Autowired private StateRepository stateRepository; private SmartPlug save(SmartPlug newSP, SwitchableSaveRequest sp, final Principal principal) { newSP.setOn(sp.isOn()); @@ -67,7 +67,7 @@ public class SmartPlugController { } @PostMapping("/{id}/state") - public State sceneBinding( + public State sceneBinding( @PathVariable("id") long deviceId, @RequestParam long sceneId, final Principal principal) @@ -77,7 +77,7 @@ public class SmartPlugController { smartPlugRepository .findByIdAndUsername(deviceId, principal.getName()) .orElseThrow(NotFoundException::new); - State s = d.cloneState(); + State s = d.cloneState(); final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new); s.setSceneId(sc.getId()); if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchableStateController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchableStateController.java index ed6f30c..2fc9f18 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchableStateController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchableStateController.java @@ -22,9 +22,9 @@ public class SwitchableStateController { @Autowired private SwitchableStateRepository switchableStateRepository; @PutMapping - public SwitchableState update(@Valid @RequestBody SwitchableStateSaveRequest ss) + public SwitchableState update(@Valid @RequestBody SwitchableStateSaveRequest ss) throws NotFoundException { - final SwitchableState initial = + final SwitchableState initial = switchableStateRepository.findById(ss.getId()).orElseThrow(NotFoundException::new); initial.setOn(ss.isOn()); switchableStateRepository.save(initial); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java index 0696822..72b4934 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java @@ -21,7 +21,7 @@ public class ThermostatController { @Autowired private ThermostatRepository thermostatRepository; @Autowired private ThermostatPopulationService thermostatService; @Autowired private SceneRepository sceneRepository; - @Autowired private StateRepository> stateRepository; + @Autowired private StateRepository stateRepository; private Thermostat save(Thermostat newT, ThermostatSaveRequest t, final Principal principal) { newT.setTargetTemperature(t.getTargetTemperature()); @@ -63,7 +63,7 @@ public class ThermostatController { } @PostMapping("/{id}/state") - public State sceneBinding( + public State sceneBinding( @PathVariable("id") long deviceId, @RequestParam long sceneId, final Principal principal) @@ -73,7 +73,7 @@ public class ThermostatController { thermostatRepository .findByIdAndUsername(deviceId, principal.getName()) .orElseThrow(NotFoundException::new); - State s = d.cloneState(); + State s = d.cloneState(); final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new); s.setSceneId(sc.getId()); if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserAccountController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserAccountController.java index fe5d6fd..b1648ed 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserAccountController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserAccountController.java @@ -158,7 +158,7 @@ public class UserAccountController { final ConfirmationToken token = confirmationTokenRepository.findByConfirmToken(resetRequest.getConfirmationToken()); - if (token == null || !token.getResetPassword()) { + if (token == null || !token.isResetPassword()) { throw new EmailTokenNotFoundException(); } @@ -186,7 +186,7 @@ public class UserAccountController { final ConfirmationToken token = confirmationTokenRepository.findByConfirmToken(confirmationToken); - if (token != null && !token.getResetPassword()) { + if (token != null && !token.isResetPassword()) { token.getUser().setEnabled(true); userRepository.save(token.getUser()); response.sendRedirect(emailConfig.getRegistrationRedirect()); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/AutomationFastUpdateRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/AutomationFastUpdateRequest.java index 0861429..4217761 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/AutomationFastUpdateRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/AutomationFastUpdateRequest.java @@ -1,14 +1,6 @@ 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.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 ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import java.util.List; import javax.validation.constraints.Min; import javax.validation.constraints.NotEmpty; @@ -36,7 +28,7 @@ public class AutomationFastUpdateRequest { } public static class RangeTriggerDTO extends TriggerDTO { - @NotNull RangeTrigger.Operator operator; + @NotNull Operator operator; @NotNull double range; @Override @@ -85,7 +77,7 @@ public class AutomationFastUpdateRequest { public static class RangeConditionDTO extends ConditionDTO { - @NotNull RangeCondition.Operator operator; + @NotNull Operator operator; @NotNull double range; @Override diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/BooleanTriggerSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/BooleanConditionOrTriggerSaveRequest.java similarity index 82% rename from src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/BooleanTriggerSaveRequest.java rename to src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/BooleanConditionOrTriggerSaveRequest.java index 8f57b22..de5b4c6 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/BooleanTriggerSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/BooleanConditionOrTriggerSaveRequest.java @@ -4,7 +4,7 @@ import javax.validation.constraints.NotNull; import lombok.Data; @Data -public class BooleanTriggerSaveRequest { +public class BooleanConditionOrTriggerSaveRequest { private long id; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/BooleanConditionSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/BooleanConditionSaveRequest.java deleted file mode 100644 index 2abf6e0..0000000 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/BooleanConditionSaveRequest.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RangeTriggerSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RangeConditionOrTriggerSaveRequest.java similarity index 62% rename from src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RangeTriggerSaveRequest.java rename to src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RangeConditionOrTriggerSaveRequest.java index 0df49a5..a222202 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RangeTriggerSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RangeConditionOrTriggerSaveRequest.java @@ -1,11 +1,11 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Operator; import javax.validation.constraints.NotNull; import lombok.Data; @Data -public class RangeTriggerSaveRequest { +public class RangeConditionOrTriggerSaveRequest { private long id; @@ -13,7 +13,7 @@ public class RangeTriggerSaveRequest { @NotNull private Long automationId; - @NotNull private RangeTrigger.Operator operator; + @NotNull private Operator operator; @NotNull private double range; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RangeConditionSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RangeConditionSaveRequest.java deleted file mode 100644 index 8cf4bf6..0000000 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RangeConditionSaveRequest.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java index 8566bde..bd86cd3 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java @@ -5,9 +5,11 @@ import java.math.BigDecimal; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Data; @Data +@AllArgsConstructor public class SensorSaveRequest { /** The type of this sensor */ @NotNull diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Automation.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Automation.java index f711c93..cb04e9d 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Automation.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Automation.java @@ -6,8 +6,9 @@ import java.util.HashSet; import java.util.Set; import javax.persistence.*; import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; +import lombok.Data; +@Data @Entity public class Automation { @@ -22,7 +23,6 @@ public class Automation { @GsonExclude private User user; - @NotNull @Column(name = "user_id", nullable = false) @GsonExclude private Long userId; @@ -36,49 +36,5 @@ public class Automation { @OneToMany(mappedBy = "automation", orphanRemoval = true, cascade = CascadeType.REMOVE) private Set> conditions = new HashSet<>(); - @NotNull @NotEmpty private String name; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public Set getScenes() { - return scenes; - } - - public Set> 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> getConditions() { - return conditions; - } + @NotEmpty private String name; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanCondition.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanCondition.java index 22ac7a2..4097c26 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanCondition.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanCondition.java @@ -2,10 +2,14 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Column; import javax.persistence.Entity; +import lombok.Getter; +import lombok.Setter; @Entity public class BooleanCondition extends Condition { + @Getter + @Setter @Column(name = "switchable_on") private boolean on; @@ -13,14 +17,6 @@ public class BooleanCondition extends Condition { super("booleanCondition"); } - public boolean isOn() { - return on; - } - - public void setOn(boolean on) { - this.on = on; - } - @Override public boolean triggered() { return this.getDevice().readTriggerState() == isOn(); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTrigger.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTrigger.java index 6eeb69e..50a86b1 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTrigger.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTrigger.java @@ -2,29 +2,21 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Column; import javax.persistence.Entity; +import lombok.Getter; +import lombok.Setter; @Entity public class BooleanTrigger extends Trigger { @Column(name = "switchable_on") + @Getter + @Setter private boolean on; public 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 public boolean triggered() { return getDevice().readTriggerState() == isOn(); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java index e41265a..9759251 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java @@ -1,5 +1,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + import javax.persistence.Entity; /** diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Condition.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Condition.java index 08b2db8..a063ca6 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Condition.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Condition.java @@ -10,7 +10,9 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Transient; +import lombok.Data; +@Data @Entity public abstract class Condition { @@ -52,42 +54,6 @@ public abstract class Condition { 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 setAutomationId(Long automationId) { this.automationId = automationId; return this; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ConfirmationToken.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ConfirmationToken.java index a661aa0..0bc1213 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ConfirmationToken.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ConfirmationToken.java @@ -12,7 +12,9 @@ import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import lombok.Data; +@Data @Entity public class ConfirmationToken { @@ -40,47 +42,4 @@ public class ConfirmationToken { confirmToken = UUID.randomUUID().toString(); 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; - } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java index ebaf4b0..0f99d0d 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java @@ -6,9 +6,11 @@ import com.google.gson.annotations.SerializedName; import io.swagger.annotations.ApiModelProperty; import java.util.Set; import javax.persistence.*; +import lombok.Data; /** Generic abstraction for a smart home device */ @Entity +@Data @Inheritance(strategy = InheritanceType.JOINED) public abstract class Device { @@ -65,7 +67,7 @@ public abstract class Device { @OneToMany(mappedBy = "device", orphanRemoval = true) @GsonExclude @SocketGsonExclude - private Set> states; + private Set states; @Transient @GsonExclude private Long fromHostId = null; @@ -73,88 +75,8 @@ public abstract class Device { @Transient @GsonExclude private boolean deleted = false; - public Device(String kind, FlowType flowType) { + protected Device(String kind, FlowType flowType) { this.kind = kind; 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> getTriggers() { - return triggers; - } - - public void setTriggers(Set> 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> getStates() { - return states; - } - - public void setStates(Set> 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; - } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmable.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmable.java index e72cbf6..26d60de 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmable.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmable.java @@ -7,7 +7,8 @@ import java.util.Set; import javax.persistence.*; import javax.validation.constraints.Max; import javax.validation.constraints.Min; -import javax.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @@ -23,20 +24,17 @@ public class Dimmable extends Switchable implements RangeTriggerable { private Set dimmers = new HashSet<>(); /** The light intensity value. Goes from 0 (off) to 100 (on) */ - @NotNull @Column(nullable = false) @Min(0) @Max(100) + @Getter private Integer intensity = 0; - @NotNull @Column(nullable = false) + @Getter + @Setter 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 * extremums. An intensity level of 0 turns the light off, but keeps the old intensity level @@ -66,19 +64,13 @@ public class Dimmable extends Switchable implements RangeTriggerable { intensity = on ? oldIntensity : 0; } - public Set getDimmers() { - return this.dimmers; - } - - public void readStateAndSet(DimmableState state) { + public void readStateAndSet(DimmableState state) { setIntensity(state.getIntensity()); } - @Override - public State cloneState() { - final DimmableState newState = new DimmableState<>(); + public State cloneState() { + final DimmableState newState = new DimmableState(); newState.setDeviceId(getId()); - newState.setDevice(this); newState.setIntensity(getIntensity()); return newState; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableState.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableState.java index dff0143..c9cceec 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableState.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableState.java @@ -3,32 +3,32 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Entity; import javax.validation.constraints.Max; import javax.validation.constraints.Min; +import lombok.Getter; +import lombok.Setter; /** Represent a state for an IDimmable device */ @Entity -public class DimmableState extends State { +public class DimmableState extends State { + + public void setDevice(Dimmable device) { + setInnerDevice(device); + } /** The light intensity value. Goes from 0 (off) to 100 (on) */ @Min(0) @Max(100) + @Getter + @Setter private int intensity = 0; - public int getIntensity() { - return intensity; - } - - public void setIntensity(int dimAmount) { - this.intensity = dimAmount; - } - @Override public void apply() { - getDevice().readStateAndSet(this); + ((Dimmable) getDevice()).readStateAndSet(this); } @Override - protected State copy() { - final DimmableState d = new DimmableState<>(); + protected DimmableState copy() { + final DimmableState d = new DimmableState(); d.setIntensity(intensity); return d; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableStateRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableStateRepository.java index 00edb96..8cced24 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableStateRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableStateRepository.java @@ -1,3 +1,3 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -public interface DimmableStateRepository extends StateRepository> {} +public interface DimmableStateRepository extends StateRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java index cd3ee64..109e13e 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java @@ -10,7 +10,7 @@ import javax.persistence.*; @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class Dimmer extends InputDevice implements Connectable { - public Dimmer(String kind) { + protected Dimmer(String kind) { super(kind); } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java index 4998922..122a608 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java @@ -2,22 +2,18 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Column; import javax.persistence.Entity; +import lombok.Getter; +import lombok.Setter; /** Represents a motion sensor device */ @Entity public class MotionSensor extends InputDevice implements BooleanTriggerable { + @Getter + @Setter @Column(nullable = false) private boolean detected; - public boolean isDetected() { - return detected; - } - - public void setDetected(boolean detected) { - this.detected = detected; - } - public MotionSensor() { super("motionSensor"); } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Operator.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Operator.java new file mode 100644 index 0000000..3c255f2 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Operator.java @@ -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(); + } + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java index ba1813e..4147fba 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java @@ -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 - * this device's state + * Creates a State object initialized to point at this device and with values copied from this + * device's state * - * @return a new State object + * @return a new State object */ - public abstract State cloneState(); + public abstract State cloneState(); } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeCondition.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeCondition.java index f3e4bce..f79cd94 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeCondition.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeCondition.java @@ -1,10 +1,9 @@ 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.Entity; -import javax.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; @Entity public class RangeCondition extends Condition { @@ -13,57 +12,18 @@ public class RangeCondition extends Condition { super("rangeCondition"); } - public enum Operator { - @SerializedName("EQUAL") - EQUAL, - @SerializedName("LESS") - LESS, - @SerializedName("GREATER") - GREATER, - @SerializedName("LESS_EQUAL") - LESS_EQUAL, - @SerializedName("GREATER_EQUAL") - GREATER_EQUAL - } - + @Getter + @Setter @Column(nullable = false) - private RangeCondition.Operator operator; + private Operator operator; - @NotNull + @Getter + @Setter @Column(nullable = false) 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 public boolean triggered() { - 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(); + return operator.checkAgainst(getDevice().readTriggerState(), range); } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTrigger.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTrigger.java index 0d926ae..2450616 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTrigger.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTrigger.java @@ -1,8 +1,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import com.google.gson.annotations.SerializedName; import javax.persistence.Column; import javax.persistence.Entity; +import lombok.Getter; +import lombok.Setter; @Entity public class RangeTrigger extends Trigger { @@ -11,56 +12,18 @@ public class RangeTrigger extends Trigger { super("rangeTrigger"); } - @Override - public boolean triggered() { - 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 - } - + @Getter + @Setter @Column(nullable = false) private Operator operator; + @Getter + @Setter @Column(nullable = false) private double range; - 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; + @Override + public boolean triggered() { + return operator.checkAgainst(getDevice().readTriggerState(), range); } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLight.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLight.java index 2d06c59..feac0fb 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLight.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLight.java @@ -2,7 +2,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Column; import javax.persistence.Entity; -import javax.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; /** Represents a standard non-dimmable light */ @Entity @@ -10,22 +11,12 @@ public class RegularLight extends Switchable implements BooleanTriggerable { /** Whether the light is on or not */ @Column(name = "light_on", nullable = false) - @NotNull + @Getter + @Setter boolean on; public RegularLight() { super("regularLight"); - this.on = false; - } - - @Override - public boolean isOn() { - return on; - } - - @Override - public void setOn(boolean on) { - this.on = on; } @Override diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java index 9e3ebc9..6785d90 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java @@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModelProperty; import java.util.HashSet; import java.util.Set; import javax.persistence.*; -import javax.validation.constraints.NotNull; /** Represents a room in the house owned by the user */ @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 * inserting from a REST call. */ - @NotNull @Column(name = "user_id", nullable = false) private Long userId; /** The user given name of this room (e.g. 'Master bedroom') */ - @NotNull @Column(nullable = false) private String name; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Scene.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Scene.java index 83a9367..b9d80de 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Scene.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Scene.java @@ -5,12 +5,13 @@ import io.swagger.annotations.ApiModelProperty; import java.util.HashSet; import java.util.Set; 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 * same user */ +@Data @Entity public class Scene { @@ -25,80 +26,21 @@ public class Scene { @GsonExclude private User user; - @NotNull @Column(name = "user_id", nullable = false) @GsonExclude private Long userId; @OneToMany(mappedBy = "scene", orphanRemoval = true) @GsonExclude - private Set> states = new HashSet<>(); + private Set states = new HashSet<>(); /** The user given name of this room (e.g. 'Master bedroom') */ - @NotNull @Column(nullable = false) private String name; @Column(nullable = false) - @NotNull private Icon icon; /** Determines whether a guest can access this scene */ @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> getStates() { - return states; - } - - public void setStates(Set> states) { - this.states = states; - } - - public Long getUserId() { - return userId; - } - - public void setUserId(Long userId) { - this.userId = userId; - } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ScenePriority.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ScenePriority.java index e975d08..8363853 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ScenePriority.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ScenePriority.java @@ -11,7 +11,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.PreRemove; import javax.validation.constraints.Min; -import javax.validation.constraints.NotNull; @Entity public class ScenePriority { @@ -30,7 +29,6 @@ public class ScenePriority { @Column(name = "automation_id", nullable = false) private Long automationId; - @NotNull @Min(0) @Column(nullable = false) private Integer priority; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SecurityCamera.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SecurityCamera.java index 218ba4a..ccb1224 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SecurityCamera.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SecurityCamera.java @@ -2,7 +2,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Column; import javax.persistence.Entity; -import javax.validation.constraints.NotNull; @Entity public class SecurityCamera extends Switchable implements BooleanTriggerable { @@ -13,7 +12,6 @@ public class SecurityCamera extends Switchable implements BooleanTriggerable { } @Column(name = "camera_on", nullable = false) - @NotNull private boolean on; @Column(name = "video", nullable = false) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java index 10fcacf..b69e3e7 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java @@ -3,7 +3,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import java.math.BigDecimal; import javax.persistence.Column; import javax.persistence.Entity; -import javax.validation.constraints.NotNull; /** A smart plug that can be turned either on or off */ @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 */ @Column(precision = 13, scale = 3) - @NotNull private BigDecimal totalConsumption = BigDecimal.ZERO; /** Whether the smart plug is on */ diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/State.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/State.java index 31cd69c..ae737ab 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/State.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/State.java @@ -3,7 +3,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude; import io.swagger.annotations.ApiModelProperty; 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 @@ -12,95 +13,66 @@ import javax.validation.constraints.NotNull; @Entity @Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"device_id", "scene_id"})}) @Inheritance(strategy = InheritanceType.SINGLE_TABLE) -public abstract class State { +public abstract class State { + + @ManyToOne(targetEntity = OutputDevice.class) + @JoinColumn(name = "device_id", updatable = false, insertable = false) + @GsonExclude + @Getter + private OutputDevice device; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id", updatable = false, nullable = false, unique = true) @ApiModelProperty(hidden = true) + @Getter 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 * from a REST call. */ @Column(name = "device_id", nullable = false) - @NotNull + @Getter + @Setter private Long deviceId; @ManyToOne @JoinColumn(name = "scene_id", updatable = false, insertable = false) @GsonExclude + @Getter + @Setter private Scene scene; @Column(name = "scene_id", nullable = false) - @NotNull + @Getter + @Setter 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. */ public abstract void apply(); /** Creates a perfect copy of this state, except for the id field and the sceneId/scene */ - protected abstract State copy(); + protected abstract State copy(); - public State copyToSceneId(Long sceneId) { - final State s = copy(); + public State copyToSceneId(Long sceneId) { + final State s = copy(); s.setDeviceId(this.deviceId); + s.device = this.device; s.setSceneId(sceneId); + s.setScene(this.scene); 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 public void removeDeviceAndScene() { - this.setScene(null); this.setSceneId(null); - - this.setDevice(null); + this.setScene(null); this.setDeviceId(null); + this.device = null; } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/StateRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/StateRepository.java index d2d1278..b3195b7 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/StateRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/StateRepository.java @@ -5,7 +5,7 @@ import javax.transaction.Transactional; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.query.Param; -public interface StateRepository> extends CrudRepository { +public interface StateRepository extends CrudRepository { @Transactional void deleteAllBySceneId(long roomId); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switchable.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switchable.java index a1a5366..f2d2c44 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switchable.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switchable.java @@ -45,15 +45,13 @@ public abstract class Switchable extends OutputDevice { return inputs; } - public void readStateAndSet(SwitchableState state) { + public void readStateAndSet(SwitchableState state) { setOn(state.isOn()); } - @Override - public State cloneState() { - final SwitchableState newState = new SwitchableState<>(); + public State cloneState() { + final SwitchableState newState = new SwitchableState(); newState.setDeviceId(getId()); - newState.setDevice(this); newState.setOn(isOn()); return newState; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableState.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableState.java index be21b6e..38307af 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableState.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableState.java @@ -2,30 +2,30 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Column; import javax.persistence.Entity; +import lombok.Getter; +import lombok.Setter; /** Represents a state for a Switchable device */ @Entity -public class SwitchableState extends State { +public class SwitchableState extends State { + + public void setDevice(Switchable device) { + setInnerDevice(device); + } @Column(name = "switchable_on") + @Getter + @Setter private boolean on; - public boolean isOn() { - return on; - } - - public void setOn(boolean on) { - this.on = on; - } - @Override public void apply() { - getDevice().readStateAndSet(this); + ((Switchable) getDevice()).readStateAndSet(this); } @Override - protected State copy() { - final SwitchableState d = new SwitchableState<>(); + protected SwitchableState copy() { + final SwitchableState d = new SwitchableState(); d.setOn(on); return d; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableStateRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableStateRepository.java index 933ac6c..5c9850b 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableStateRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableStateRepository.java @@ -1,3 +1,3 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -public interface SwitchableStateRepository extends StateRepository> {} +public interface SwitchableStateRepository extends StateRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java index abcc1cb..a2a71a1 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java @@ -5,7 +5,6 @@ import java.math.BigDecimal; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Transient; -import javax.validation.constraints.NotNull; /** A thermostat capable of controlling cooling and heating. */ @Entity @@ -72,7 +71,7 @@ public class Thermostat extends Switchable implements BooleanTriggerable { Sensor.TYPICAL_VALUES.get(Sensor.SensorType.TEMPERATURE); /** State of this thermostat */ - @Column @NotNull private Thermostat.Mode mode; + @Column private Thermostat.Mode mode; @Transient private BigDecimal measuredTemperature; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/SceneService.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/SceneService.java index 824ea7e..711a94d 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/SceneService.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/SceneService.java @@ -11,7 +11,7 @@ public class SceneService { private final DevicePopulationService devicePopulationService; private final DevicePropagationService devicePropagationService; - private final StateRepository> stateRepository; + private final StateRepository stateRepository; private final SceneRepository sceneRepository; public Scene findByValidatedId(Long id) { @@ -22,7 +22,7 @@ public class SceneService { public SceneService( DevicePopulationService devicePopulationService, DevicePropagationService devicePropagationService, - StateRepository> stateRepository, + StateRepository stateRepository, SceneRepository sceneRepository) { this.devicePopulationService = devicePopulationService; this.devicePropagationService = devicePropagationService; @@ -33,7 +33,7 @@ public class SceneService { private List copyStatesToDevices(Scene fromScene) { final List updated = new ArrayList<>(fromScene.getStates().size()); - for (final State s : fromScene.getStates()) { + for (final State s : fromScene.getStates()) { s.apply(); updated.add(s.getDevice()); } @@ -54,9 +54,9 @@ public class SceneService { return updated; } - public List> copyStates(Scene to, Scene from) { - final ArrayList> states = new ArrayList<>(); - for (final State s : from.getStates()) { + public List copyStates(Scene to, Scene from) { + final ArrayList states = new ArrayList<>(); + for (final State s : from.getStates()) { states.add(stateRepository.save(s.copyToSceneId(to.getId()))); } return states; diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorControllerTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorControllerTests.java new file mode 100644 index 0000000..6ef3158 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorControllerTests.java @@ -0,0 +1,77 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SensorSaveRequest; +import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor; +import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService; +import java.math.BigDecimal; +import java.security.Principal; +import lombok.SneakyThrows; +import org.junit.jupiter.api.*; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +@DisplayName("The sensor controller") +@ExtendWith(MockitoExtension.class) +@WithMockUser(username = "user") +public class SensorControllerTests { + @InjectMocks private SensorController sensorController; + + @Mock private DeviceService deviceService; + + @Mock private Principal mockPrincipal; + + @BeforeEach + public void setup() { + when(mockPrincipal.getName()).thenReturn("user"); + } + + private void checkSensorAgainstRequest(final Sensor toCheck, final SensorSaveRequest request) { + assertThat(toCheck).isNotNull(); + assertThat(toCheck.getSensor()).isEqualTo(request.getSensor()); + assertThat(toCheck.getValue()).isEqualTo(request.getValue()); + assertThat(toCheck.getName()).isEqualTo(request.getName()); + assertThat(toCheck.getRoomId()).isEqualTo(request.getRoomId()); + } + + @DisplayName("when creating should return the same object") + @Test + @SneakyThrows(NotFoundException.class) + public void testCreate() { + doNothing().when(deviceService).throwIfRoomNotOwned(anyLong(), eq("user")); + when(deviceService.saveAsOwner(any(Sensor.class), eq("user"))) + .thenAnswer(i -> i.getArguments()[0]); + + MockHttpServletRequest request = new MockHttpServletRequest(); + RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); + + final SensorSaveRequest toSend = + new SensorSaveRequest( + Sensor.SensorType.TEMPERATURE, BigDecimal.ZERO, 42L, "Test sensor"); + final Sensor created = sensorController.create(toSend, mockPrincipal); + + checkSensorAgainstRequest(created, toSend); + } + + @DisplayName("when deleting an existant id should succeed") + @Test + @SneakyThrows(NotFoundException.class) + public void testDelete() { + doNothing().when(deviceService).deleteByIdAsOwner(eq(42L), eq("user")); + + MockHttpServletRequest request = new MockHttpServletRequest(); + RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); + + sensorController.deleteById(42L, mockPrincipal); + } +}