Merge branch 'tests' into 'dev'

fixed stuff

See merge request sa4-2020/the-sanmarinoes/backend!149
This commit is contained in:
Claudio Maggioni 2020-05-18 17:59:56 +02:00
commit c0da4c6f57
44 changed files with 253 additions and 286 deletions

View file

@ -1,11 +1,7 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.config; package ch.usi.inf.sa4.sanmarinoes.smarthut.config;
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.Condition; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
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 com.google.gson.*; import com.google.gson.*;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -34,30 +30,16 @@ public class GsonConfig {
RuntimeTypeAdapterFactory.of(State.class, "kind") RuntimeTypeAdapterFactory.of(State.class, "kind")
.registerSubtype(SwitchableState.class, "switchableState") .registerSubtype(SwitchableState.class, "switchableState")
.registerSubtype(DimmableState.class, "dimmableState"); .registerSubtype(DimmableState.class, "dimmableState");
RuntimeTypeAdapterFactory<AutomationFastUpdateRequest.TriggerDTO> RuntimeTypeAdapterFactory<TriggerDTO> runtimeTypeAdapterFactoryII =
runtimeTypeAdapterFactoryII = RuntimeTypeAdapterFactory.of(TriggerDTO.class, "kind")
RuntimeTypeAdapterFactory.of( .registerSubtype(BooleanTriggerDTO.class, "booleanTrigger")
AutomationFastUpdateRequest.TriggerDTO.class, "kind") .registerSubtype(RangeTriggerDTO.class, "rangeTrigger");
.registerSubtype(
AutomationFastUpdateRequest.BooleanTriggerDTO.class,
"booleanTrigger")
.registerSubtype(
AutomationFastUpdateRequest.RangeTriggerDTO.class,
"rangeTrigger");
RuntimeTypeAdapterFactory<AutomationFastUpdateRequest.ConditionDTO> RuntimeTypeAdapterFactory<ConditionDTO> runtimeTypeAdapterFactoryIII =
runtimeTypeAdapterFactoryIII = RuntimeTypeAdapterFactory.of(ConditionDTO.class, "kind")
RuntimeTypeAdapterFactory.of( .registerSubtype(BooleanConditionDTO.class, "booleanCondition")
AutomationFastUpdateRequest.ConditionDTO.class, "kind") .registerSubtype(RangeConditionDTO.class, "rangeCondition")
.registerSubtype( .registerSubtype(ThermostatConditionDTO.class, "thermostatCondition");
AutomationFastUpdateRequest.BooleanConditionDTO.class,
"booleanCondition")
.registerSubtype(
AutomationFastUpdateRequest.RangeConditionDTO.class,
"rangeCondition")
.registerSubtype(
AutomationFastUpdateRequest.ThermostatConditionDTO.class,
"thermostatCondition");
builder.registerTypeAdapterFactory(runtimeTypeAdapterFactory); builder.registerTypeAdapterFactory(runtimeTypeAdapterFactory);
builder.registerTypeAdapterFactory(runtimeTypeAdapterFactoryII); builder.registerTypeAdapterFactory(runtimeTypeAdapterFactoryII);

View file

@ -1,12 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.config; package ch.usi.inf.sa4.sanmarinoes.smarthut.config;
import com.google.gson.Gson; import com.google.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.internal.Streams; import com.google.gson.internal.Streams;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonReader;

View file

@ -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.dto.JWTResponse;
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.UnauthorizedException; 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.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 ch.usi.inf.sa4.sanmarinoes.smarthut.service.JWTUserDetailsService;
import java.security.Principal; import java.security.Principal;
import javax.validation.Valid; import javax.validation.Valid;

View file

@ -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.AutomationFastUpdateRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.AutomationSaveRequest; 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.error.NotFoundException;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.security.Principal; import java.security.Principal;
@ -10,15 +13,7 @@ import java.util.stream.Collectors;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
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;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration
@ -93,21 +88,21 @@ public class AutomationController {
triggerRepository.saveAll( triggerRepository.saveAll(
req.getTriggers() req.getTriggers()
.stream() .stream()
.map(AutomationFastUpdateRequest.TriggerDTO::toModel) .map(TriggerDTO::toModel)
.map(t -> t.setAutomationId(a.getId())) .map(t -> t.setAutomationId(a.getId()))
.collect(Collectors.toList())); .collect(Collectors.toList()));
Iterable<ScenePriority> ss = Iterable<ScenePriority> ss =
sceneRepository.saveAll( sceneRepository.saveAll(
req.getScenes() req.getScenes()
.stream() .stream()
.map(AutomationFastUpdateRequest.ScenePriorityDTO::toModel) .map(ScenePriorityDTO::toModel)
.collect(Collectors.toList())); .collect(Collectors.toList()));
Iterable<Condition<?>> cc = Iterable<Condition<?>> cc =
conditionRepository.saveAll( conditionRepository.saveAll(
req.getConditions() req.getConditions()
.stream() .stream()
.map(AutomationFastUpdateRequest.ConditionDTO::toModel) .map(ConditionDTO::toModel)
.map(t -> t.setAutomationId(a.getId())) .map(t -> t.setAutomationId(a.getId()))
.collect(Collectors.toList())); .collect(Collectors.toList()));

View file

@ -8,14 +8,7 @@ import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
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;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration

View file

@ -8,14 +8,7 @@ import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
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;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration

View file

@ -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.ButtonDimmerDimRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.GenericDeviceSaveReguest; 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.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 ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService;
import java.security.Principal; import java.security.Principal;
import java.util.Set; import java.util.Set;

View file

@ -3,7 +3,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.returnIfGuest; 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.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; import java.security.Principal;
public abstract class GuestEnabledController<T extends Device> { public abstract class GuestEnabledController<T extends Device> {

View file

@ -3,7 +3,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList; 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.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 ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService;
import java.security.Principal; import java.security.Principal;
import java.util.ArrayList; import java.util.ArrayList;

View file

@ -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.GenericDeviceSaveReguest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.KnobDimmerDimRequest; 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.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 ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService;
import java.security.Principal; import java.security.Principal;
import java.util.Set; import java.util.Set;

View file

@ -8,14 +8,7 @@ import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
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;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration

View file

@ -8,14 +8,7 @@ import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
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;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration

View file

@ -12,15 +12,7 @@ import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
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;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration

View file

@ -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.service.DeviceService;
import ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils; import ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils;
import java.security.Principal; import java.security.Principal;
import java.util.*; import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.*; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@RestController @RestController

View file

@ -8,14 +8,7 @@ import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
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;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration

View file

@ -10,14 +10,7 @@ import java.security.Principal;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
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;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration

View file

@ -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.dto.SensorSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; 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.DeviceService;
import ch.usi.inf.sa4.sanmarinoes.smarthut.service.SensorService; import ch.usi.inf.sa4.sanmarinoes.smarthut.service.SensorService;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.security.Principal; import java.security.Principal;
import java.util.*;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.*; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@RestController @RestController

View file

@ -8,7 +8,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService;
import java.security.Principal; import java.security.Principal;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.*; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@RestController @RestController

View file

@ -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.GenericDeviceSaveReguest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SwitchOperationRequest; 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.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 ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService;
import java.security.Principal; import java.security.Principal;
import java.util.List; import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.*; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@RestController @RestController

View file

@ -7,12 +7,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.models.SwitchableStateRepository;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
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;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration

View file

@ -8,14 +8,7 @@ import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
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;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration

View file

@ -9,7 +9,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.service.ThermostatPopulationService;
import java.security.Principal; import java.security.Principal;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.*; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@RestController @RestController

View file

@ -1,116 +1,18 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; 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 java.util.List;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
import lombok.Getter;
import lombok.Setter;
@Data @Data
public class AutomationFastUpdateRequest { 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<ScenePriorityDTO> scenes; @NotNull private List<ScenePriorityDTO> scenes;
@NotNull private List<TriggerDTO> triggers; @NotNull private List<TriggerDTO> triggers;
@NotNull private List<ConditionDTO> conditions; @NotNull private List<ConditionDTO> conditions;
@NotNull private long id; @NotNull private long id;
@NotNull @NotEmpty private String name; @NotNull @NotEmpty private String name;
} }

View file

@ -1,6 +1,8 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; 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; import lombok.Data;
/** DTO for password reset request */ /** DTO for password reset request */

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -2,14 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude; import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import javax.persistence.Column; import javax.persistence.*;
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 lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;

View file

@ -2,16 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
import javax.persistence.Column; import javax.persistence.*;
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 lombok.Data; import lombok.Data;
@Data @Data

View file

@ -1,6 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models; package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.*; import javax.persistence.Entity;
/** Represent a dimmable light */ /** Represent a dimmable light */
@Entity @Entity

View file

@ -1,6 +1,8 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models; 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, * Represents a generic output device, i.e. something that causes some behaviour (light, smartPlugs,

View file

@ -2,14 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude; import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import javax.persistence.Column; import javax.persistence.*;
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.validation.constraints.Min; import javax.validation.constraints.Min;
@Entity @Entity

View file

@ -1,6 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models; package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import java.util.*; import java.util.Optional;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
public interface UserRepository extends CrudRepository<User, Long> { public interface UserRepository extends CrudRepository<User, Long> {

View file

@ -1,6 +1,9 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.service; 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 java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View file

@ -3,7 +3,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.service;
import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList; 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.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 ch.usi.inf.sa4.sanmarinoes.smarthut.socket.SensorSocketEndpoint;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;

View file

@ -4,7 +4,6 @@ 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.models.UserRepository;
import java.util.Set; import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired; 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.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.core.userdetails.UsernameNotFoundException;

View file

@ -12,7 +12,9 @@ import com.google.common.collect.Multimaps;
import com.google.gson.Gson; import com.google.gson.Gson;
import java.io.IOException; import java.io.IOException;
import java.util.*; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View file

@ -2,7 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut;
import static org.junit.jupiter.api.Assertions.*; 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 ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -10,17 +10,10 @@ import org.junit.jupiter.api.Test;
@DisplayName("Automation Update DTO") @DisplayName("Automation Update DTO")
public class AutomationFastUpdateRequestTest { public class AutomationFastUpdateRequestTest {
AutomationFastUpdateRequest.BooleanTriggerDTO booleanTriggerDTO;
AutomationFastUpdateRequest.RangeTriggerDTO rangeTriggerDTO;
AutomationFastUpdateRequest.ScenePriorityDTO scenePriorityDTO;
AutomationFastUpdateRequest.BooleanConditionDTO booleanConditionDTO;
AutomationFastUpdateRequest.RangeConditionDTO rangeConditionDTO;
AutomationFastUpdateRequest.ThermostatConditionDTO thermostatConditionDTO;
@Test @Test
@DisplayName(" checking boolean trigger ") @DisplayName(" checking boolean trigger ")
public void booleanTriggerDTOTest() { public void booleanTriggerDTOTest() {
booleanTriggerDTO = new AutomationFastUpdateRequest.BooleanTriggerDTO(); BooleanTriggerDTO booleanTriggerDTO = new BooleanTriggerDTO();
booleanTriggerDTO.setOn(true); booleanTriggerDTO.setOn(true);
booleanTriggerDTO.setDeviceId(42); booleanTriggerDTO.setDeviceId(42);
BooleanTrigger booleanTrigger = (BooleanTrigger) booleanTriggerDTO.toModel(); BooleanTrigger booleanTrigger = (BooleanTrigger) booleanTriggerDTO.toModel();
@ -31,7 +24,7 @@ public class AutomationFastUpdateRequestTest {
@Test @Test
@DisplayName(" checking range trigger ") @DisplayName(" checking range trigger ")
public void rangeTriggerDTOTest() { public void rangeTriggerDTOTest() {
rangeTriggerDTO = new AutomationFastUpdateRequest.RangeTriggerDTO(); RangeTriggerDTO rangeTriggerDTO = new RangeTriggerDTO();
rangeTriggerDTO.setOperator(Operator.EQUAL); rangeTriggerDTO.setOperator(Operator.EQUAL);
rangeTriggerDTO.setDeviceId(420); rangeTriggerDTO.setDeviceId(420);
rangeTriggerDTO.setRange(12); rangeTriggerDTO.setRange(12);
@ -45,7 +38,7 @@ public class AutomationFastUpdateRequestTest {
@Test @Test
@DisplayName(" checking scene priority ") @DisplayName(" checking scene priority ")
public void scenePriorityDTOTest() { public void scenePriorityDTOTest() {
scenePriorityDTO = new AutomationFastUpdateRequest.ScenePriorityDTO(); ScenePriorityDTO scenePriorityDTO = new ScenePriorityDTO();
scenePriorityDTO.setPriority(67); scenePriorityDTO.setPriority(67);
scenePriorityDTO.setSceneId(21); scenePriorityDTO.setSceneId(21);
@ -57,7 +50,7 @@ public class AutomationFastUpdateRequestTest {
@Test @Test
@DisplayName(" checking boolean condition ") @DisplayName(" checking boolean condition ")
public void booleanConditionDTOTest() { public void booleanConditionDTOTest() {
booleanConditionDTO = new AutomationFastUpdateRequest.BooleanConditionDTO(); BooleanConditionDTO booleanConditionDTO = new BooleanConditionDTO();
booleanConditionDTO.setOn(true); booleanConditionDTO.setOn(true);
booleanConditionDTO.setDeviceId(17); booleanConditionDTO.setDeviceId(17);
@ -69,7 +62,7 @@ public class AutomationFastUpdateRequestTest {
@Test @Test
@DisplayName(" checking range condition ") @DisplayName(" checking range condition ")
public void rangeConditionDTOTest() { public void rangeConditionDTOTest() {
rangeConditionDTO = new AutomationFastUpdateRequest.RangeConditionDTO(); RangeConditionDTO rangeConditionDTO = new RangeConditionDTO();
rangeConditionDTO.setOperator(Operator.LESS); rangeConditionDTO.setOperator(Operator.LESS);
rangeConditionDTO.setRange(82.01); rangeConditionDTO.setRange(82.01);
rangeConditionDTO.setDeviceId(13); rangeConditionDTO.setDeviceId(13);
@ -83,7 +76,7 @@ public class AutomationFastUpdateRequestTest {
@Test @Test
@DisplayName(" checking thermostat condition ") @DisplayName(" checking thermostat condition ")
public void thermostatConditionDTOTest() { public void thermostatConditionDTOTest() {
thermostatConditionDTO = new AutomationFastUpdateRequest.ThermostatConditionDTO(); ThermostatConditionDTO thermostatConditionDTO = new ThermostatConditionDTO();
thermostatConditionDTO.setDeviceId(25); thermostatConditionDTO.setDeviceId(25);
thermostatConditionDTO.setOperator(ThermostatCondition.Operator.EQUAL); thermostatConditionDTO.setOperator(ThermostatCondition.Operator.EQUAL);
thermostatConditionDTO.setMode(Thermostat.Mode.HEATING); thermostatConditionDTO.setMode(Thermostat.Mode.HEATING);

View file

@ -3,6 +3,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.config;
import static org.assertj.core.api.Assertions.assertThat; 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.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 ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -26,16 +28,15 @@ public class GsonTests {
assertThat(o.get("kind").getAsString()).isEqualTo("booleanTrigger"); assertThat(o.get("kind").getAsString()).isEqualTo("booleanTrigger");
AutomationFastUpdateRequest a = new AutomationFastUpdateRequest(); AutomationFastUpdateRequest a = new AutomationFastUpdateRequest();
AutomationFastUpdateRequest.BooleanTriggerDTO bt = BooleanTriggerDTO bt = new BooleanTriggerDTO();
new AutomationFastUpdateRequest.BooleanTriggerDTO();
bt.setDeviceId(42L); bt.setDeviceId(42L);
a.setTriggers(List.of(bt)); a.setTriggers(List.of(bt));
AutomationFastUpdateRequest a2 = AutomationFastUpdateRequest a2 =
gson.fromJson(gson.toJson(a), AutomationFastUpdateRequest.class); 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); assertThat(t.getDeviceId()).isEqualTo(42L);
} }
} }