This commit is contained in:
omenem 2020-04-21 14:45:04 +02:00
parent 319629a681
commit 0692f7e2ee
7 changed files with 228 additions and 19 deletions

View file

@ -0,0 +1,45 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude;
import io.swagger.annotations.ApiModelProperty;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
public class Automation {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false, unique = true)
@ApiModelProperty(hidden = true)
private long id;
@OneToMany(mappedBy = "trigger", orphanRemoval = true)
@GsonExclude
private Set<Trigger<?>> triggers = new HashSet<>();
@OneToMany(mappedBy = "scenes", cascade = CascadeType.DETACH)
@GsonExclude
private Set<ScenePriority> scenes = new HashSet<>();
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Set<Trigger<?>> getStates() {
return triggers;
}
public Set<ScenePriority> getScenes() {
return scenes;
}
}

View file

@ -2,8 +2,11 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class BooleanTrigger<D extends Device> extends Trigger<D> {
@Column(name = "switchable_on")

View file

@ -0,0 +1,44 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.validation.constraints.NotNull;
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class RangeTrigger<D extends Device> extends Trigger<D> {
enum Operator {
EQUAL,
LESS,
GREATER,
LESS_EQUAL,
GREATER_EQUAL;
}
@NotNull
@Column(nullable = false)
Operator operator;
@NotNull
@Column(nullable = false)
private Float range;
public Operator getOperator() {
return operator;
}
public void setOperator(Operator operator) {
this.operator = operator;
}
public Float getRange() {
return range;
}
public void setRange(Float range) {
this.range = range;
}
}

View file

@ -25,20 +25,24 @@ public class Scene {
@GsonExclude
private User user;
@OneToMany(mappedBy = "scene", orphanRemoval = true)
@GsonExclude
private Set<State<?>> states = new HashSet<>();
@NotNull
@Column(name = "user_id", nullable = false)
@GsonExclude
private Long userId;
@OneToMany(mappedBy = "states", orphanRemoval = true)
@GsonExclude
private Set<State<?>> states = new HashSet<>();
/** The user given name of this room (e.g. 'Master bedroom') */
@NotNull
@Column(nullable = false)
private String name;
@ManyToMany(mappedBy = "automations", cascade = CascadeType.DETACH)
@GsonExclude
private Set<Automation> automations = new HashSet<>();
public String getName() {
return name;
}
@ -78,4 +82,8 @@ public class Scene {
public void setUserId(Long userId) {
this.userId = userId;
}
public Set<Automation> getAutomations() {
return automations;
}
}

View file

@ -0,0 +1,104 @@
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.PreRemove;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
@Entity
public class ScenePriority {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false, unique = true)
@ApiModelProperty(hidden = true)
private long id;
@ManyToOne
@JoinColumn(name = "automation_id", updatable = false, insertable = false)
@GsonExclude
private Automation automation;
@Column(name = "automation_id", nullable = false)
@NotNull
private Long automationId;
@NotNull
@Min(0)
@Column(nullable = false)
private Integer priority;
@ManyToOne
@JoinColumn(name = "scene_id", updatable = false, insertable = false)
@GsonExclude
private Scene scene;
@Column(name = "scene_id", nullable = false)
@NotNull
private Long sceneId;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Integer getPriority() {
return priority;
}
public void setPriority(Integer priority) {
this.priority = priority;
}
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;
}
public Scene getScene() {
return scene;
}
public void setScene(Scene scene) {
this.scene = scene;
}
public Long getSceneId() {
return sceneId;
}
public void setSceneId(Long sceneId) {
this.sceneId = sceneId;
}
@PreRemove
public void preRemove() {
this.setAutomation(null);
this.setAutomationId(null);
this.setScene(null);
this.setSceneId(null);
}
}

View file

@ -0,0 +1,5 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository;
public interface ScenePriorityRepository extends CrudRepository<ScenePriority, Long> {}

View file

@ -41,13 +41,13 @@ public abstract class Trigger<D extends Device> {
private Long deviceId;
@ManyToOne
@JoinColumn(name = "scene_id", updatable = false, insertable = false)
@JoinColumn(name = "automation_id", updatable = false, insertable = false)
@GsonExclude
private Scene scene;
private Automation automation;
@Column(name = "scene_id", nullable = false)
@Column(name = "automation_id", nullable = false)
@NotNull
private Long sceneId;
private Long automationId;
public long getId() {
return id;
@ -73,28 +73,28 @@ public abstract class Trigger<D extends Device> {
this.deviceId = deviceId;
}
public Scene getScene() {
return scene;
public Automation getAutomation() {
return automation;
}
public void setScene(Scene scene) {
this.scene = scene;
public void setAutomation(Automation automation) {
this.automation = automation;
}
public Long getSceneId() {
return sceneId;
public Long getAutomationId() {
return automationId;
}
public void setSceneId(Long sceneId) {
this.sceneId = sceneId;
public void setAutomationId(Long automationId) {
this.automationId = automationId;
}
@PreRemove
public void removeDeviceAndScene() {
this.setScene(null);
this.setSceneId(null);
this.setDevice(null);
this.setDeviceId(null);
this.setAutomation(null);
this.setAutomationId(null);
}
}