From 6060e627ddcdf240c42e10845aa125137af058ff Mon Sep 17 00:00:00 2001 From: omenem Date: Thu, 7 May 2020 10:01:51 +0200 Subject: [PATCH] wip --- .../smarthut/models/BooleanCondition.java | 28 ++++ .../smarthut/models/Condition.java | 133 ++++++++++++++++++ .../smarthut/models/RangeCondition.java | 52 +++++++ 3 files changed, 213 insertions(+) create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanCondition.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Condition.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeCondition.java diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanCondition.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanCondition.java new file mode 100644 index 0000000..0957ce1 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanCondition.java @@ -0,0 +1,28 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import javax.persistence.Column; +import javax.persistence.Entity; + +@Entity +public class BooleanCondition + extends Condition { // TODO add interface to type constraints + + @Column(name = "switchable_on") + private boolean on; + + public BooleanCondition() { + super("booleanCondition"); + } + + public boolean isOn() { + return on; + } + + public void setOn(boolean on) { + this.on = on; + } + + public boolean check(boolean on) { + return this.on == on; + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Condition.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Condition.java new file mode 100644 index 0000000..9366e90 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Condition.java @@ -0,0 +1,133 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude; +import io.swagger.annotations.ApiModelProperty; +import javax.persistence.Column; +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 javax.validation.constraints.NotNull; + +@Entity +public class Condition { + + @Transient private String kind; + + protected Condition(String kind) { + this.kind = kind; + } + + public String getKind() { + return kind; + } + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", updatable = false, nullable = false, unique = true) + @ApiModelProperty(hidden = true) + private long id; + + @ManyToOne + @JoinColumn(name = "user_id", updatable = false, insertable = false) + @GsonExclude + private User user; + + @NotNull + @Column(name = "user_id", nullable = false) + @GsonExclude + private Long userId; + + @NotNull + @Column(nullable = false) + private String name; + + @ManyToOne(targetEntity = Device.class) + @JoinColumn(name = "device_id", updatable = false, insertable = false) + @GsonExclude + private D device; + + /** + * The device this condition belongs to, as a foreign key id. To use when updating and inserting + * from a REST call. + */ + @Column(name = "device_id", nullable = false) + @NotNull + private Long deviceId; + + @ManyToOne + @JoinColumn(name = "automation_id", updatable = false, insertable = false) + @GsonExclude + private Automation automation; + + @Column(name = "automation_id", nullable = false) + @NotNull + private Long automationId; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public D getDevice() { + return device; + } + + public void setDevice(D device) { + this.device = device; + } + + public Long getDeviceId() { + return deviceId; + } + + public void setDeviceId(Long deviceId) { + this.deviceId = deviceId; + } + + public Automation getAutomation() { + return automation; + } + + public void setAutomation(Automation automation) { + this.automation = automation; + } + + public Long getAutomationId() { + return automationId; + } + + public void setAutomationId(Long automationId) { + this.automationId = automationId; + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeCondition.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeCondition.java new file mode 100644 index 0000000..8283245 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeCondition.java @@ -0,0 +1,52 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger.Operator; +import com.google.gson.annotations.SerializedName; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.validation.constraints.NotNull; + +@Entity +public class RangeCondition extends Condition { + + protected RangeCondition(String kind) { + super(kind); + } + + public enum Operator { + @SerializedName("EQUAL") + EQUAL, + @SerializedName("LESS") + LESS, + @SerializedName("GREATER") + GREATER, + @SerializedName("LESS_EQUAL") + LESS_EQUAL, + @SerializedName("GREATER_EQUAL") + GREATER_EQUAL + } + + @NotNull + @Column(nullable = false) + private RangeTrigger.Operator operator; + + @NotNull + @Column(nullable = false) + private double range; + + public RangeTrigger.Operator getOperator() { + return operator; + } + + public void setOperator(RangeTrigger.Operator operator) { + this.operator = operator; + } + + public double getRange() { + return range; + } + + public void setRange(Double range) { + this.range = range; + } +}