Degenerified Conditions
This commit is contained in:
parent
c003bd1e87
commit
c6041e0e0f
8 changed files with 24 additions and 36 deletions
|
@ -25,11 +25,11 @@ public class BooleanConditionController {
|
|||
@Autowired BooleanConditionRepository booleanConditionRepository;
|
||||
|
||||
@GetMapping("/{automationId}")
|
||||
public List<BooleanCondition<?>> getAll(@PathVariable long automationId) {
|
||||
public List<BooleanCondition> getAll(@PathVariable long automationId) {
|
||||
return booleanConditionRepository.findAllByAutomationId(automationId);
|
||||
}
|
||||
|
||||
private BooleanCondition<?> save(BooleanCondition<?> newRL, BooleanConditionSaveRequest s) {
|
||||
private BooleanCondition save(BooleanCondition newRL, BooleanConditionSaveRequest s) {
|
||||
newRL.setDeviceId(s.getDeviceId());
|
||||
newRL.setAutomationId(s.getAutomationId());
|
||||
newRL.setOn(s.isOn());
|
||||
|
@ -38,13 +38,13 @@ public class BooleanConditionController {
|
|||
}
|
||||
|
||||
@PostMapping
|
||||
public BooleanCondition<?> create(
|
||||
public BooleanCondition create(
|
||||
@Valid @RequestBody BooleanConditionSaveRequest booleanTriggerSaveRequest) {
|
||||
return save(new BooleanCondition<>(), booleanTriggerSaveRequest);
|
||||
return save(new BooleanCondition(), booleanTriggerSaveRequest);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public BooleanCondition<?> update(
|
||||
public BooleanCondition update(
|
||||
@Valid @RequestBody BooleanConditionSaveRequest booleanTriggerSaveRequest)
|
||||
throws NotFoundException {
|
||||
return save(
|
||||
|
|
|
@ -25,11 +25,11 @@ public class RangeConditionController {
|
|||
@Autowired RangeConditionRepository rangeConditionRepository;
|
||||
|
||||
@GetMapping("/{automationId}")
|
||||
public List<RangeCondition<?>> getAll(@PathVariable long automationId) {
|
||||
public List<RangeCondition> getAll(@PathVariable long automationId) {
|
||||
return rangeConditionRepository.findAllByAutomationId(automationId);
|
||||
}
|
||||
|
||||
private RangeCondition<?> save(RangeCondition<?> newRL, RangeConditionSaveRequest s) {
|
||||
private RangeCondition save(RangeCondition newRL, RangeConditionSaveRequest s) {
|
||||
newRL.setDeviceId(s.getDeviceId());
|
||||
newRL.setAutomationId(s.getAutomationId());
|
||||
newRL.setOperator(s.getOperator());
|
||||
|
@ -39,13 +39,13 @@ public class RangeConditionController {
|
|||
}
|
||||
|
||||
@PostMapping
|
||||
public RangeCondition<?> create(
|
||||
public RangeCondition create(
|
||||
@Valid @RequestBody RangeConditionSaveRequest booleanTriggerSaveRequest) {
|
||||
return save(new RangeCondition<>(), booleanTriggerSaveRequest);
|
||||
return save(new RangeCondition(), booleanTriggerSaveRequest);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public RangeCondition<?> update(
|
||||
public RangeCondition update(
|
||||
@Valid @RequestBody RangeConditionSaveRequest booleanTriggerSaveRequest)
|
||||
throws NotFoundException {
|
||||
return save(
|
||||
|
|
|
@ -62,33 +62,33 @@ public class AutomationFastUpdateRequest {
|
|||
}
|
||||
}
|
||||
|
||||
public abstract class ConditionDTO {
|
||||
public abstract static class ConditionDTO {
|
||||
@NotNull public long deviceId;
|
||||
|
||||
public abstract Condition<?> toModel();
|
||||
}
|
||||
|
||||
public class BooleanConditionDTO extends ConditionDTO {
|
||||
public static class BooleanConditionDTO extends ConditionDTO {
|
||||
|
||||
@NotNull public boolean on;
|
||||
|
||||
@Override
|
||||
public Condition<?> toModel() {
|
||||
BooleanCondition<?> t = new BooleanCondition<>();
|
||||
BooleanCondition t = new BooleanCondition();
|
||||
t.setDeviceId(this.deviceId);
|
||||
t.setOn(this.on);
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
public class RangeConditionDTO extends ConditionDTO {
|
||||
public static class RangeConditionDTO extends ConditionDTO {
|
||||
|
||||
@NotNull RangeCondition.Operator operator;
|
||||
@NotNull double range;
|
||||
|
||||
@Override
|
||||
public Condition<?> toModel() {
|
||||
RangeCondition<?> t = new RangeCondition<>();
|
||||
RangeCondition t = new RangeCondition();
|
||||
t.setDeviceId(this.deviceId);
|
||||
t.setOperator(this.operator);
|
||||
t.setRange(this.range);
|
||||
|
@ -96,7 +96,7 @@ public class AutomationFastUpdateRequest {
|
|||
}
|
||||
}
|
||||
|
||||
public class ThermostatConditionDTO extends ConditionDTO {
|
||||
public static class ThermostatConditionDTO extends ConditionDTO {
|
||||
|
||||
@NotNull ThermostatCondition.Operator operator;
|
||||
@NotNull private Thermostat.Mode mode;
|
||||
|
|
|
@ -4,8 +4,7 @@ import javax.persistence.Column;
|
|||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class BooleanCondition<D extends Device & BooleanTriggerable>
|
||||
extends Condition<D> { // TODO add interface to type constraints
|
||||
public class BooleanCondition extends Condition<BooleanTriggerable> {
|
||||
|
||||
@Column(name = "switchable_on")
|
||||
private boolean on;
|
||||
|
@ -22,10 +21,6 @@ public class BooleanCondition<D extends Device & BooleanTriggerable>
|
|||
this.on = on;
|
||||
}
|
||||
|
||||
public boolean check(boolean on) {
|
||||
return this.on == on;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean triggered() {
|
||||
return this.getDevice().readTriggerState() == isOn();
|
||||
|
|
|
@ -3,8 +3,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
|||
import java.util.List;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
public interface BooleanConditionRepository
|
||||
extends ConditionRepository<BooleanCondition<? extends Device>> {
|
||||
public interface BooleanConditionRepository extends ConditionRepository<BooleanCondition> {
|
||||
|
||||
List<BooleanCondition<?>> findAllByAutomationId(@Param("automationId") long automationId);
|
||||
List<BooleanCondition> findAllByAutomationId(@Param("automationId") long automationId);
|
||||
}
|
||||
|
|
|
@ -10,10 +10,9 @@ import javax.persistence.Id;
|
|||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Transient;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
public abstract class Condition<D extends Device> {
|
||||
public abstract class Condition<D> {
|
||||
|
||||
@Transient private String kind;
|
||||
|
||||
|
@ -41,7 +40,6 @@ public abstract class Condition<D extends Device> {
|
|||
* from a REST call.
|
||||
*/
|
||||
@Column(name = "device_id", nullable = false)
|
||||
@NotNull
|
||||
private Long deviceId;
|
||||
|
||||
@ManyToOne
|
||||
|
@ -50,7 +48,6 @@ public abstract class Condition<D extends Device> {
|
|||
private Automation automation;
|
||||
|
||||
@Column(name = "automation_id", nullable = false)
|
||||
@NotNull
|
||||
private Long automationId;
|
||||
|
||||
public abstract boolean triggered();
|
||||
|
|
|
@ -7,10 +7,10 @@ import javax.persistence.Entity;
|
|||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
public class RangeCondition<D extends Device & RangeTriggerable> extends Condition<D> {
|
||||
public class RangeCondition extends Condition<RangeTriggerable> {
|
||||
|
||||
public RangeCondition() {
|
||||
super("booleanCondition");
|
||||
super("rangeCondition");
|
||||
}
|
||||
|
||||
public enum Operator {
|
||||
|
@ -26,7 +26,6 @@ public class RangeCondition<D extends Device & RangeTriggerable> extends Conditi
|
|||
GREATER_EQUAL
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Column(nullable = false)
|
||||
private RangeCondition.Operator operator;
|
||||
|
||||
|
|
|
@ -3,8 +3,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
|||
import java.util.List;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
public interface RangeConditionRepository
|
||||
extends ConditionRepository<RangeCondition<? extends Device>> {
|
||||
|
||||
List<RangeCondition<?>> findAllByAutomationId(@Param("automationId") long automationId);
|
||||
public interface RangeConditionRepository extends ConditionRepository<RangeCondition> {
|
||||
List<RangeCondition> findAllByAutomationId(@Param("automationId") long automationId);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue