wip
This commit is contained in:
parent
0692f7e2ee
commit
618c152466
6 changed files with 25 additions and 6 deletions
|
@ -0,0 +1,4 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
|
public interface BooleanTriggerRepository
|
||||||
|
extends TriggerRepository<BooleanTrigger<? extends Device>> {}
|
|
@ -4,7 +4,6 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
@ -92,8 +91,4 @@ public abstract class Device {
|
||||||
this.kind = kind;
|
this.kind = kind;
|
||||||
this.flowType = flowType;
|
this.flowType = flowType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Trigger<? extends Device>> triggeredTriggers() {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
|
public interface RangeTriggerRepository extends TriggerRepository<RangeTrigger<? extends Device>> {}
|
|
@ -89,6 +89,8 @@ public abstract class Trigger<D extends Device> {
|
||||||
this.automationId = automationId;
|
this.automationId = automationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract <T extends Device> boolean check(T d);
|
||||||
|
|
||||||
@PreRemove
|
@PreRemove
|
||||||
public void removeDeviceAndScene() {
|
public void removeDeviceAndScene() {
|
||||||
this.setDevice(null);
|
this.setDevice(null);
|
||||||
|
|
|
@ -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<T extends Trigger<?>> extends CrudRepository<T, Long> {
|
||||||
|
|
||||||
|
List<T> findAllByDeviceId(@Param("deviceId") long deviceId);
|
||||||
|
}
|
|
@ -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.Device;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DeviceRepository;
|
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.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;
|
||||||
|
@ -23,9 +24,13 @@ public class DeviceService {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Autowired DeviceRepository<Device> deviceRepository;
|
@Autowired DeviceRepository<Device> deviceRepository;
|
||||||
|
@Autowired TriggerRepository<Trigger<? extends Device>> triggerRepository;
|
||||||
|
|
||||||
public <T extends Device> T save(T device) {
|
public <T extends Device> T save(T device) {
|
||||||
List<Trigger<? extends Device>> activated = device.triggeredTriggers();
|
|
||||||
|
final Long deviceId = device.getId();
|
||||||
|
|
||||||
|
List<Trigger<? extends Device>> triggers = triggerRepository.findAllByDeviceId(deviceId);
|
||||||
|
|
||||||
// map activated -> automations
|
// map activated -> automations
|
||||||
// remove duplicates
|
// remove duplicates
|
||||||
|
|
Loading…
Reference in a new issue