diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/JWTTokenUtils.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/JWTTokenUtils.java index f6943a8..9d2d939 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/JWTTokenUtils.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/JWTTokenUtils.java @@ -14,7 +14,7 @@ import org.springframework.stereotype.Component; @Component public class JWTTokenUtils { /** The duration in seconds of the validity of a single token */ - private static final long JWT_TOKEN_VALIDITY = 5 * 60 * 60; + private static final long JWT_TOKEN_VALIDITY = (long) 5 * 60 * 60; /** The secret key used to encrypt all JWTs */ @Value("${jwt.secret}") diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java index 6fcd7ca..660387a 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java @@ -6,7 +6,6 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.models.MotionSensor; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.MotionSensorRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService; import ch.usi.inf.sa4.sanmarinoes.smarthut.service.MotionSensorService; -import ch.usi.inf.sa4.sanmarinoes.smarthut.socket.SensorSocketEndpoint; import java.security.Principal; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; @@ -21,7 +20,6 @@ public class MotionSensorController { @Autowired private DeviceService deviceService; @Autowired private MotionSensorService motionSensorService; @Autowired private MotionSensorRepository motionSensorRepository; - @Autowired private SensorSocketEndpoint sensorSocketEndpoint; @PostMapping public MotionSensor create( 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 1554f0a..1bbc750 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 @@ -76,8 +76,8 @@ public class SecurityCameraController { .findByIdAndUsername(deviceId, principal.getName()) .orElseThrow(NotFoundException::new); State s = d.cloneState(); - sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new); - s.setSceneId(sceneId); + final Scene sc = sceneRepository.findById(sceneId).orElseThrow(NotFoundException::new); + s.setSceneId(sc.getId()); if (stateRepository.countByDeviceIdAndSceneId(deviceId, sceneId) > 0) throw new DuplicateStateException(); return stateRepository.save(s); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java index aa88d09..be6f897 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java @@ -4,7 +4,6 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude; import ch.usi.inf.sa4.sanmarinoes.smarthut.config.SocketGsonExclude; import com.google.gson.annotations.SerializedName; import io.swagger.annotations.ApiModelProperty; -import java.util.HashSet; import java.util.Set; import javax.persistence.*; @@ -13,6 +12,14 @@ import javax.persistence.*; @Inheritance(strategy = InheritanceType.JOINED) public abstract class Device { + public Set> getTriggers() { + return triggers; + } + + public Set> getStates() { + return states; + } + /** Ways a device can behave in the automation flow. For now only input/output */ public enum FlowType { @SerializedName("INPUT") @@ -38,7 +45,7 @@ public abstract class Device { @OneToMany(mappedBy = "device", orphanRemoval = true) @GsonExclude @SocketGsonExclude - private Set> triggers = new HashSet<>(); + private Set> triggers; /** * The room this device belongs in, as a foreign key id. To use when updating and inserting from @@ -66,7 +73,7 @@ public abstract class Device { @OneToMany(mappedBy = "device", orphanRemoval = true) @GsonExclude @SocketGsonExclude - private Set> states = new HashSet<>(); + private Set> states; @Transient @GsonExclude private Long fromHostId = null; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTrigger.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTrigger.java index 5fdc119..c4d5836 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTrigger.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTrigger.java @@ -3,7 +3,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import com.google.gson.annotations.SerializedName; import javax.persistence.Column; import javax.persistence.Entity; -import javax.validation.constraints.NotNull; @Entity public class RangeTrigger extends Trigger { @@ -46,7 +45,6 @@ public class RangeTrigger extends Trigger { private Automation automation; @Column(name = "automation_id", nullable = false) - @NotNull private Long automationId; public long getId() {