From 618c1524668a52aa2d3281ab2b8180236b69f2f3 Mon Sep 17 00:00:00 2001 From: omenem Date: Tue, 21 Apr 2020 15:21:47 +0200 Subject: [PATCH] wip --- .../smarthut/models/BooleanTriggerRepository.java | 4 ++++ .../inf/sa4/sanmarinoes/smarthut/models/Device.java | 5 ----- .../smarthut/models/RangeTriggerRepository.java | 3 +++ .../inf/sa4/sanmarinoes/smarthut/models/Trigger.java | 2 ++ .../sanmarinoes/smarthut/models/TriggerRepository.java | 10 ++++++++++ .../sanmarinoes/smarthut/service/DeviceService.java | 7 ++++++- 6 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTriggerRepository.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTriggerRepository.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/TriggerRepository.java diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTriggerRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTriggerRepository.java new file mode 100644 index 0000000..932f4c8 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTriggerRepository.java @@ -0,0 +1,4 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public interface BooleanTriggerRepository + extends TriggerRepository> {} 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 7fd7b80..0114ac3 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 com.google.gson.annotations.SerializedName; import io.swagger.annotations.ApiModelProperty; import java.util.HashSet; -import java.util.List; import java.util.Set; import javax.persistence.*; import javax.validation.constraints.NotNull; @@ -92,8 +91,4 @@ public abstract class Device { this.kind = kind; this.flowType = flowType; } - - public List> triggeredTriggers() { - return List.of(); - } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTriggerRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTriggerRepository.java new file mode 100644 index 0000000..084a70f --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTriggerRepository.java @@ -0,0 +1,3 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public interface RangeTriggerRepository extends TriggerRepository> {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Trigger.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Trigger.java index 22aac95..f42658d 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Trigger.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Trigger.java @@ -89,6 +89,8 @@ public abstract class Trigger { this.automationId = automationId; } + public abstract boolean check(T d); + @PreRemove public void removeDeviceAndScene() { this.setDevice(null); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/TriggerRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/TriggerRepository.java new file mode 100644 index 0000000..a506ce6 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/TriggerRepository.java @@ -0,0 +1,10 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import java.util.List; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; + +public interface TriggerRepository> extends CrudRepository { + + List findAllByDeviceId(@Param("deviceId") long deviceId); +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DeviceService.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DeviceService.java index c843c42..f248356 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DeviceService.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DeviceService.java @@ -3,6 +3,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.service; 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.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; @@ -23,9 +24,13 @@ public class DeviceService { */ @Autowired DeviceRepository deviceRepository; + @Autowired TriggerRepository> triggerRepository; public T save(T device) { - List> activated = device.triggeredTriggers(); + + final Long deviceId = device.getId(); + + List> triggers = triggerRepository.findAllByDeviceId(deviceId); // map activated -> automations // remove duplicates