From 4fde95231b22405909dfe068826525b9e3409e87 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Mon, 18 May 2020 17:58:38 +0200 Subject: [PATCH] fixed stuff --- .../smarthut/config/GsonConfig.java | 40 ++----- .../config/RuntimeTypeAdapterFactory.java | 8 +- .../controller/AuthenticationController.java | 3 +- .../controller/AutomationController.java | 19 ++-- .../BooleanConditionController.java | 9 +- .../controller/BooleanTriggerController.java | 9 +- .../controller/ButtonDimmerController.java | 5 +- .../controller/GuestEnabledController.java | 4 +- .../InputDeviceConnectionController.java | 5 +- .../controller/KnobDimmerController.java | 5 +- .../controller/RangeConditionController.java | 9 +- .../controller/RangeTriggerController.java | 9 +- .../controller/RegularLightController.java | 10 +- .../smarthut/controller/RoomController.java | 4 +- .../controller/ScenePriorityController.java | 9 +- .../controller/SecurityCameraController.java | 9 +- .../smarthut/controller/SensorController.java | 6 +- .../controller/SmartPlugController.java | 2 +- .../smarthut/controller/SwitchController.java | 7 +- .../controller/SwitchableStateController.java | 7 +- .../ThermostatConditionController.java | 9 +- .../controller/ThermostatController.java | 2 +- .../dto/AutomationFastUpdateRequest.java | 104 +----------------- .../smarthut/dto/PasswordResetRequest.java | 4 +- .../dto/automation/BooleanConditionDTO.java | 20 ++++ .../dto/automation/BooleanTriggerDTO.java | 19 ++++ .../smarthut/dto/automation/ConditionDTO.java | 12 ++ .../dto/automation/RangeConditionDTO.java | 23 ++++ .../dto/automation/RangeTriggerDTO.java | 22 ++++ .../dto/automation/ScenePriorityDTO.java | 22 ++++ .../automation/ThermostatConditionDTO.java | 29 +++++ .../smarthut/dto/automation/TriggerDTO.java | 12 ++ .../smarthut/models/Condition.java | 9 +- .../smarthut/models/ConfirmationToken.java | 11 +- .../smarthut/models/DimmableLight.java | 2 +- .../smarthut/models/OutputDevice.java | 4 +- .../smarthut/models/ScenePriority.java | 9 +- .../smarthut/models/UserRepository.java | 2 +- .../smarthut/service/AutomationService.java | 5 +- .../service/DevicePropagationService.java | 5 +- .../service/JWTUserDetailsService.java | 1 - .../smarthut/socket/SensorSocketEndpoint.java | 4 +- .../AutomationFastUpdateRequestTest.java | 21 ++-- .../smarthut/config/GsonTests.java | 9 +- 44 files changed, 253 insertions(+), 286 deletions(-) create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/BooleanConditionDTO.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/BooleanTriggerDTO.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/ConditionDTO.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/RangeConditionDTO.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/RangeTriggerDTO.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/ScenePriorityDTO.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/ThermostatConditionDTO.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/TriggerDTO.java diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonConfig.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonConfig.java index d3c0c50..2e5e9f9 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonConfig.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonConfig.java @@ -1,11 +1,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.config; -import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.AutomationFastUpdateRequest; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Condition; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableState; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.State; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.SwitchableState; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Trigger; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation.*; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import com.google.gson.*; import java.lang.reflect.Type; import org.springframework.context.annotation.Bean; @@ -34,30 +30,16 @@ public class GsonConfig { RuntimeTypeAdapterFactory.of(State.class, "kind") .registerSubtype(SwitchableState.class, "switchableState") .registerSubtype(DimmableState.class, "dimmableState"); - RuntimeTypeAdapterFactory - runtimeTypeAdapterFactoryII = - RuntimeTypeAdapterFactory.of( - AutomationFastUpdateRequest.TriggerDTO.class, "kind") - .registerSubtype( - AutomationFastUpdateRequest.BooleanTriggerDTO.class, - "booleanTrigger") - .registerSubtype( - AutomationFastUpdateRequest.RangeTriggerDTO.class, - "rangeTrigger"); + RuntimeTypeAdapterFactory runtimeTypeAdapterFactoryII = + RuntimeTypeAdapterFactory.of(TriggerDTO.class, "kind") + .registerSubtype(BooleanTriggerDTO.class, "booleanTrigger") + .registerSubtype(RangeTriggerDTO.class, "rangeTrigger"); - RuntimeTypeAdapterFactory - runtimeTypeAdapterFactoryIII = - RuntimeTypeAdapterFactory.of( - AutomationFastUpdateRequest.ConditionDTO.class, "kind") - .registerSubtype( - AutomationFastUpdateRequest.BooleanConditionDTO.class, - "booleanCondition") - .registerSubtype( - AutomationFastUpdateRequest.RangeConditionDTO.class, - "rangeCondition") - .registerSubtype( - AutomationFastUpdateRequest.ThermostatConditionDTO.class, - "thermostatCondition"); + RuntimeTypeAdapterFactory runtimeTypeAdapterFactoryIII = + RuntimeTypeAdapterFactory.of(ConditionDTO.class, "kind") + .registerSubtype(BooleanConditionDTO.class, "booleanCondition") + .registerSubtype(RangeConditionDTO.class, "rangeCondition") + .registerSubtype(ThermostatConditionDTO.class, "thermostatCondition"); builder.registerTypeAdapterFactory(runtimeTypeAdapterFactory); builder.registerTypeAdapterFactory(runtimeTypeAdapterFactoryII); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/RuntimeTypeAdapterFactory.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/RuntimeTypeAdapterFactory.java index aa33517..c0245d1 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/RuntimeTypeAdapterFactory.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/RuntimeTypeAdapterFactory.java @@ -1,12 +1,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.config; -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.TypeAdapter; -import com.google.gson.TypeAdapterFactory; +import com.google.gson.*; import com.google.gson.internal.Streams; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AuthenticationController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AuthenticationController.java index 7179130..da84571 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AuthenticationController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AuthenticationController.java @@ -5,7 +5,8 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.JWTRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.JWTResponse; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.UnauthorizedException; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.UserNotFoundException; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.UserRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.service.JWTUserDetailsService; import java.security.Principal; import javax.validation.Valid; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AutomationController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AutomationController.java index e82bce2..d05c955 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AutomationController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AutomationController.java @@ -2,6 +2,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.AutomationFastUpdateRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.AutomationSaveRequest; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation.ConditionDTO; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation.ScenePriorityDTO; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation.TriggerDTO; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import java.security.Principal; @@ -10,15 +13,7 @@ import java.util.stream.Collectors; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration @@ -93,21 +88,21 @@ public class AutomationController { triggerRepository.saveAll( req.getTriggers() .stream() - .map(AutomationFastUpdateRequest.TriggerDTO::toModel) + .map(TriggerDTO::toModel) .map(t -> t.setAutomationId(a.getId())) .collect(Collectors.toList())); Iterable ss = sceneRepository.saveAll( req.getScenes() .stream() - .map(AutomationFastUpdateRequest.ScenePriorityDTO::toModel) + .map(ScenePriorityDTO::toModel) .collect(Collectors.toList())); Iterable> cc = conditionRepository.saveAll( req.getConditions() .stream() - .map(AutomationFastUpdateRequest.ConditionDTO::toModel) + .map(ConditionDTO::toModel) .map(t -> t.setAutomationId(a.getId())) .collect(Collectors.toList())); 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 e605043..c776a70 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 @@ -8,14 +8,7 @@ import java.util.List; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration 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 d31b8e2..3147fb8 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 @@ -8,14 +8,7 @@ import java.util.List; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java index 54ea066..8e3b313 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java @@ -3,7 +3,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.ButtonDimmerDimRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.GenericDeviceSaveReguest; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ButtonDimmer; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ButtonDimmerRepository; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Dimmable; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService; import java.security.Principal; import java.util.Set; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/GuestEnabledController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/GuestEnabledController.java index 1aa2e7c..6336a4e 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/GuestEnabledController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/GuestEnabledController.java @@ -3,7 +3,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.returnIfGuest; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Device; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DeviceRepository; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.UserRepository; import java.security.Principal; public abstract class GuestEnabledController { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/InputDeviceConnectionController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/InputDeviceConnectionController.java index 4b92125..efde6e5 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/InputDeviceConnectionController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/InputDeviceConnectionController.java @@ -3,7 +3,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Connectable; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DeviceRepository; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.InputDevice; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.OutputDevice; import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService; import java.security.Principal; import java.util.ArrayList; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java index f80e1fd..c91144e 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java @@ -3,7 +3,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.GenericDeviceSaveReguest; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.KnobDimmerDimRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Dimmable; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableRepository; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmer; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmerRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService; import java.security.Principal; import java.util.Set; 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 ea9a911..5ac5f0b 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 @@ -8,14 +8,7 @@ import java.util.List; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration 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 c8c5589..e04aada 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 @@ -8,14 +8,7 @@ import java.util.List; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration 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 6da88d8..29364a1 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 @@ -12,15 +12,7 @@ import java.util.List; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java index 79b61d2..2bba6c2 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java @@ -8,10 +8,10 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService; import ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils; import java.security.Principal; -import java.util.*; +import java.util.List; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.*; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.*; @RestController diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ScenePriorityController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ScenePriorityController.java index 98ead6a..230e396 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ScenePriorityController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ScenePriorityController.java @@ -8,14 +8,7 @@ import java.util.List; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration 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 781b46a..fe29bf7 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 @@ -10,14 +10,7 @@ import java.security.Principal; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java index ff1677d..62581b3 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java @@ -2,15 +2,15 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; 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.*; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.SensorRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService; import ch.usi.inf.sa4.sanmarinoes.smarthut.service.SensorService; import java.math.BigDecimal; import java.security.Principal; -import java.util.*; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.*; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.*; @RestController 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 43d659b..04e1dd2 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 @@ -8,7 +8,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService; import java.security.Principal; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.*; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.*; @RestController diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java index 299c7e5..87368db 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java @@ -3,13 +3,16 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.GenericDeviceSaveReguest; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SwitchOperationRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Switch; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.SwitchRepository; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Switchable; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.SwitchableRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService; import java.security.Principal; import java.util.List; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.*; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.*; @RestController 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 2fc9f18..64bb8cb 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 @@ -7,12 +7,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.models.SwitchableStateRepository; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatConditionController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatConditionController.java index a6d118a..5852c9f 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatConditionController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatConditionController.java @@ -8,14 +8,7 @@ import java.util.List; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration 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 72b4934..d45ba96 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 @@ -9,7 +9,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.service.ThermostatPopulationService; import java.security.Principal; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.*; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.*; @RestController 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 667645e..b2c90d4 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,116 +1,18 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation.ConditionDTO; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation.ScenePriorityDTO; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation.TriggerDTO; import java.util.List; -import javax.validation.constraints.Min; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import lombok.Data; -import lombok.Getter; -import lombok.Setter; @Data public class AutomationFastUpdateRequest { - public abstract static class TriggerDTO { - @NotNull @Getter @Setter private long deviceId; - - public abstract Trigger toModel(); - } - - public static class BooleanTriggerDTO extends TriggerDTO { - @NotNull @Getter @Setter private boolean on; - - @Override - public Trigger toModel() { - BooleanTrigger t = new BooleanTrigger(); - t.setDeviceId(this.getDeviceId()); - t.setOn(this.on); - return t; - } - } - - public static class RangeTriggerDTO extends TriggerDTO { - @NotNull @Getter @Setter private Operator operator; - @NotNull @Getter @Setter private double range; - - @Override - public Trigger toModel() { - RangeTrigger t = new RangeTrigger(); - t.setDeviceId(this.getDeviceId()); - t.setOperator(this.operator); - t.setRange(this.range); - return t; - } - } - - public static class ScenePriorityDTO { - @NotNull @Getter @Setter private long sceneId; - - @NotNull - @Min(0) - private @Getter @Setter Integer priority; - - public ScenePriority toModel() { - ScenePriority s = new ScenePriority(); - s.setSceneId(sceneId); - s.setPriority(priority); - return s; - } - } - - public abstract static class ConditionDTO { - @NotNull @Getter @Setter private long deviceId; - - public abstract Condition toModel(); - } - - public static class BooleanConditionDTO extends ConditionDTO { - - @NotNull @Getter @Setter private boolean on; - - @Override - public Condition toModel() { - BooleanCondition t = new BooleanCondition(); - t.setDeviceId(this.getDeviceId()); - t.setOn(this.on); - return t; - } - } - - public static class RangeConditionDTO extends ConditionDTO { - - @NotNull @Getter @Setter private Operator operator; - @NotNull @Getter @Setter private double range; - - @Override - public Condition toModel() { - RangeCondition t = new RangeCondition(); - t.setDeviceId(this.getDeviceId()); - t.setOperator(this.operator); - t.setRange(this.range); - return t; - } - } - - public static class ThermostatConditionDTO extends ConditionDTO { - - @NotNull @Getter @Setter private ThermostatCondition.Operator operator; - @NotNull @Getter @Setter private Thermostat.Mode mode; - - @Override - public Condition toModel() { - ThermostatCondition t = new ThermostatCondition(); - t.setDeviceId(this.getDeviceId()); - t.setOperator(this.operator); - t.setMode(this.mode); - return t; - } - } - @NotNull private List scenes; @NotNull private List triggers; @NotNull private List conditions; @NotNull private long id; - @NotNull @NotEmpty private String name; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/PasswordResetRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/PasswordResetRequest.java index 871b95c..3d9ad7e 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/PasswordResetRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/PasswordResetRequest.java @@ -1,6 +1,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; -import javax.validation.constraints.*; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; import lombok.Data; /** DTO for password reset request */ diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/BooleanConditionDTO.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/BooleanConditionDTO.java new file mode 100644 index 0000000..eb3dbdb --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/BooleanConditionDTO.java @@ -0,0 +1,20 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanCondition; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Condition; +import javax.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; + +public class BooleanConditionDTO extends ConditionDTO { + + @NotNull @Getter @Setter private boolean on; + + @Override + public Condition toModel() { + BooleanCondition t = new BooleanCondition(); + t.setDeviceId(this.getDeviceId()); + t.setOn(this.on); + return t; + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/BooleanTriggerDTO.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/BooleanTriggerDTO.java new file mode 100644 index 0000000..43a3950 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/BooleanTriggerDTO.java @@ -0,0 +1,19 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Trigger; +import javax.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; + +public class BooleanTriggerDTO extends TriggerDTO { + @NotNull @Getter @Setter private boolean on; + + @Override + public Trigger toModel() { + BooleanTrigger t = new BooleanTrigger(); + t.setDeviceId(this.getDeviceId()); + t.setOn(this.on); + return t; + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/ConditionDTO.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/ConditionDTO.java new file mode 100644 index 0000000..6a5b6b6 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/ConditionDTO.java @@ -0,0 +1,12 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Condition; +import javax.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; + +public abstract class ConditionDTO { + @NotNull @Getter @Setter private long deviceId; + + public abstract Condition toModel(); +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/RangeConditionDTO.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/RangeConditionDTO.java new file mode 100644 index 0000000..f3cb7d6 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/RangeConditionDTO.java @@ -0,0 +1,23 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Condition; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Operator; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition; +import javax.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; + +public class RangeConditionDTO extends ConditionDTO { + + @NotNull @Getter @Setter private Operator operator; + @NotNull @Getter @Setter private double range; + + @Override + public Condition toModel() { + RangeCondition t = new RangeCondition(); + t.setDeviceId(this.getDeviceId()); + t.setOperator(this.operator); + t.setRange(this.range); + return t; + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/RangeTriggerDTO.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/RangeTriggerDTO.java new file mode 100644 index 0000000..0cab1f9 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/RangeTriggerDTO.java @@ -0,0 +1,22 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Operator; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Trigger; +import javax.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; + +public class RangeTriggerDTO extends TriggerDTO { + @NotNull @Getter @Setter private Operator operator; + @NotNull @Getter @Setter private double range; + + @Override + public Trigger toModel() { + RangeTrigger t = new RangeTrigger(); + t.setDeviceId(this.getDeviceId()); + t.setOperator(this.operator); + t.setRange(this.range); + return t; + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/ScenePriorityDTO.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/ScenePriorityDTO.java new file mode 100644 index 0000000..4d4b251 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/ScenePriorityDTO.java @@ -0,0 +1,22 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ScenePriority; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; + +public class ScenePriorityDTO { + @NotNull @Getter @Setter private long sceneId; + + @NotNull + @Min(0) + private @Getter @Setter Integer priority; + + public ScenePriority toModel() { + ScenePriority s = new ScenePriority(); + s.setSceneId(sceneId); + s.setPriority(priority); + return s; + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/ThermostatConditionDTO.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/ThermostatConditionDTO.java new file mode 100644 index 0000000..4ef455b --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/ThermostatConditionDTO.java @@ -0,0 +1,29 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Condition; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Thermostat; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ThermostatCondition; +import javax.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; + +public class ThermostatConditionDTO extends ConditionDTO { + + @NotNull @Getter @Setter private ThermostatCondition.Operator operator; + + @NotNull @Getter @Setter private Thermostat.Mode mode; + + @Override + public Condition toModel() { + + ThermostatCondition t = new ThermostatCondition(); + + t.setDeviceId(this.getDeviceId()); + + t.setOperator(this.operator); + + t.setMode(this.mode); + + return t; + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/TriggerDTO.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/TriggerDTO.java new file mode 100644 index 0000000..2a212b9 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/automation/TriggerDTO.java @@ -0,0 +1,12 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Trigger; +import javax.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; + +public abstract class TriggerDTO { + @NotNull @Getter @Setter private long deviceId; + + public abstract Trigger toModel(); +} 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 476fefc..7cec0be 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 @@ -2,14 +2,7 @@ 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.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Transient; +import javax.persistence.*; import lombok.Data; import lombok.EqualsAndHashCode; 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 0bc1213..5271a83 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 @@ -2,16 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import java.util.Date; import java.util.UUID; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToOne; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; +import javax.persistence.*; import lombok.Data; @Data diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java index 89806a7..e4fa18d 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java @@ -1,6 +1,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import javax.persistence.*; +import javax.persistence.Entity; /** Represent a dimmable light */ @Entity 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 4147fba..1e8cde9 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 @@ -1,6 +1,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import javax.persistence.*; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; /** * Represents a generic output device, i.e. something that causes some behaviour (light, smartPlugs, 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 8363853..d6f7ef5 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 @@ -2,14 +2,7 @@ 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.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.PreRemove; +import javax.persistence.*; import javax.validation.constraints.Min; @Entity diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java index bd93385..253c0ea 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java @@ -1,6 +1,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import java.util.*; +import java.util.Optional; import org.springframework.data.repository.CrudRepository; public interface UserRepository extends CrudRepository { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/AutomationService.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/AutomationService.java index 8668e1a..08c0bf6 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/AutomationService.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/AutomationService.java @@ -1,6 +1,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.service; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Automation; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.AutomationRepository; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Trigger; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.TriggerRepository; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DevicePropagationService.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DevicePropagationService.java index edba584..7fa0adb 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DevicePropagationService.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DevicePropagationService.java @@ -3,7 +3,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.service; import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Device; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DeviceRepository; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.EagerUserRepository; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User; import ch.usi.inf.sa4.sanmarinoes.smarthut.socket.SensorSocketEndpoint; import java.util.List; import java.util.Set; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/JWTUserDetailsService.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/JWTUserDetailsService.java index f8c8e5b..3312613 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/JWTUserDetailsService.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/JWTUserDetailsService.java @@ -4,7 +4,6 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.UserRepository; import java.util.Set; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.*; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/socket/SensorSocketEndpoint.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/socket/SensorSocketEndpoint.java index 009dfab..c924db4 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/socket/SensorSocketEndpoint.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/socket/SensorSocketEndpoint.java @@ -12,7 +12,9 @@ import com.google.common.collect.Multimaps; import com.google.gson.Gson; import java.io.IOException; import java.util.*; -import javax.websocket.*; +import javax.websocket.Endpoint; +import javax.websocket.EndpointConfig; +import javax.websocket.Session; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/AutomationFastUpdateRequestTest.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/AutomationFastUpdateRequestTest.java index 4f10fc6..b9bb68a 100644 --- a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/AutomationFastUpdateRequestTest.java +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/AutomationFastUpdateRequestTest.java @@ -2,7 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut; import static org.junit.jupiter.api.Assertions.*; -import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.AutomationFastUpdateRequest; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation.*; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -10,17 +10,10 @@ import org.junit.jupiter.api.Test; @DisplayName("Automation Update DTO") public class AutomationFastUpdateRequestTest { - AutomationFastUpdateRequest.BooleanTriggerDTO booleanTriggerDTO; - AutomationFastUpdateRequest.RangeTriggerDTO rangeTriggerDTO; - AutomationFastUpdateRequest.ScenePriorityDTO scenePriorityDTO; - AutomationFastUpdateRequest.BooleanConditionDTO booleanConditionDTO; - AutomationFastUpdateRequest.RangeConditionDTO rangeConditionDTO; - AutomationFastUpdateRequest.ThermostatConditionDTO thermostatConditionDTO; - @Test @DisplayName(" checking boolean trigger ") public void booleanTriggerDTOTest() { - booleanTriggerDTO = new AutomationFastUpdateRequest.BooleanTriggerDTO(); + BooleanTriggerDTO booleanTriggerDTO = new BooleanTriggerDTO(); booleanTriggerDTO.setOn(true); booleanTriggerDTO.setDeviceId(42); BooleanTrigger booleanTrigger = (BooleanTrigger) booleanTriggerDTO.toModel(); @@ -31,7 +24,7 @@ public class AutomationFastUpdateRequestTest { @Test @DisplayName(" checking range trigger ") public void rangeTriggerDTOTest() { - rangeTriggerDTO = new AutomationFastUpdateRequest.RangeTriggerDTO(); + RangeTriggerDTO rangeTriggerDTO = new RangeTriggerDTO(); rangeTriggerDTO.setOperator(Operator.EQUAL); rangeTriggerDTO.setDeviceId(420); rangeTriggerDTO.setRange(12); @@ -45,7 +38,7 @@ public class AutomationFastUpdateRequestTest { @Test @DisplayName(" checking scene priority ") public void scenePriorityDTOTest() { - scenePriorityDTO = new AutomationFastUpdateRequest.ScenePriorityDTO(); + ScenePriorityDTO scenePriorityDTO = new ScenePriorityDTO(); scenePriorityDTO.setPriority(67); scenePriorityDTO.setSceneId(21); @@ -57,7 +50,7 @@ public class AutomationFastUpdateRequestTest { @Test @DisplayName(" checking boolean condition ") public void booleanConditionDTOTest() { - booleanConditionDTO = new AutomationFastUpdateRequest.BooleanConditionDTO(); + BooleanConditionDTO booleanConditionDTO = new BooleanConditionDTO(); booleanConditionDTO.setOn(true); booleanConditionDTO.setDeviceId(17); @@ -69,7 +62,7 @@ public class AutomationFastUpdateRequestTest { @Test @DisplayName(" checking range condition ") public void rangeConditionDTOTest() { - rangeConditionDTO = new AutomationFastUpdateRequest.RangeConditionDTO(); + RangeConditionDTO rangeConditionDTO = new RangeConditionDTO(); rangeConditionDTO.setOperator(Operator.LESS); rangeConditionDTO.setRange(82.01); rangeConditionDTO.setDeviceId(13); @@ -83,7 +76,7 @@ public class AutomationFastUpdateRequestTest { @Test @DisplayName(" checking thermostat condition ") public void thermostatConditionDTOTest() { - thermostatConditionDTO = new AutomationFastUpdateRequest.ThermostatConditionDTO(); + ThermostatConditionDTO thermostatConditionDTO = new ThermostatConditionDTO(); thermostatConditionDTO.setDeviceId(25); thermostatConditionDTO.setOperator(ThermostatCondition.Operator.EQUAL); thermostatConditionDTO.setMode(Thermostat.Mode.HEATING); diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonTests.java index dd48ae5..9d3e97e 100644 --- a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonTests.java +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonTests.java @@ -3,6 +3,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.config; import static org.assertj.core.api.Assertions.assertThat; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.AutomationFastUpdateRequest; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation.BooleanTriggerDTO; +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.automation.TriggerDTO; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -26,16 +28,15 @@ public class GsonTests { assertThat(o.get("kind").getAsString()).isEqualTo("booleanTrigger"); AutomationFastUpdateRequest a = new AutomationFastUpdateRequest(); - AutomationFastUpdateRequest.BooleanTriggerDTO bt = - new AutomationFastUpdateRequest.BooleanTriggerDTO(); + BooleanTriggerDTO bt = new BooleanTriggerDTO(); bt.setDeviceId(42L); a.setTriggers(List.of(bt)); AutomationFastUpdateRequest a2 = gson.fromJson(gson.toJson(a), AutomationFastUpdateRequest.class); - AutomationFastUpdateRequest.TriggerDTO t = a2.getTriggers().get(0); + TriggerDTO t = a2.getTriggers().get(0); - assertThat(t).isExactlyInstanceOf(AutomationFastUpdateRequest.BooleanTriggerDTO.class); + assertThat(t).isExactlyInstanceOf(BooleanTriggerDTO.class); assertThat(t.getDeviceId()).isEqualTo(42L); } }